@@ -33,20 +33,20 @@ using Test, LinearMaps, LinearAlgebra, SparseArrays
33
33
end
34
34
end
35
35
36
- # new type
37
- struct SimpleFunctionMap <: LinearMap{Float64}
38
- f:: Function
39
- N:: Int
40
- end
41
- struct SimpleComplexFunctionMap <: LinearMap{Complex{Float64}}
42
- f:: Function
43
- N:: Int
44
- end
45
- Base. size (A:: Union{SimpleFunctionMap,SimpleComplexFunctionMap} ) = (A. N, A. N)
46
- Base.:(* )(A:: Union{SimpleFunctionMap,SimpleComplexFunctionMap} , v:: AbstractVector ) = A. f (v)
47
- LinearAlgebra. mul! (y:: AbstractVector , A:: Union{SimpleFunctionMap,SimpleComplexFunctionMap} , x:: AbstractVector ) = copyto! (y, * (A, x))
48
-
49
36
@testset " new LinearMap type" begin
37
+ # new type
38
+ struct SimpleFunctionMap <: LinearMap{Float64}
39
+ f:: Function
40
+ N:: Int
41
+ end
42
+ struct SimpleComplexFunctionMap <: LinearMap{Complex{Float64}}
43
+ f:: Function
44
+ N:: Int
45
+ end
46
+ Base. size (A:: Union{SimpleFunctionMap,SimpleComplexFunctionMap} ) = (A. N, A. N)
47
+ Base.:(* )(A:: Union{SimpleFunctionMap,SimpleComplexFunctionMap} , v:: AbstractVector ) = A. f (v)
48
+ LinearAlgebra. mul! (y:: AbstractVector , A:: Union{SimpleFunctionMap,SimpleComplexFunctionMap} , x:: AbstractVector ) = copyto! (y, * (A, x))
49
+
50
50
F = SimpleFunctionMap (cumsum, 10 )
51
51
FC = SimpleComplexFunctionMap (cumsum, 10 )
52
52
@test @inferred ndims (F) == 2
@@ -84,27 +84,27 @@ LinearAlgebra.mul!(y::AbstractVector, A::Union{SimpleFunctionMap,SimpleComplexFu
84
84
@test Fs isa SparseMatrixCSC
85
85
end
86
86
87
- struct MyFillMap{T} <: LinearMaps.LinearMap{T}
88
- λ:: T
89
- size:: Dims{2}
90
- function MyFillMap (λ:: T , dims:: Dims{2} ) where {T}
91
- all (d -> d >= 0 , dims) || throw (ArgumentError (" dims of MyFillMap must be non-negative" ))
92
- promote_type (T, typeof (λ)) == T || throw (InexactError ())
93
- return new {T} (λ, dims)
87
+ @testset " transpose of new LinearMap type" begin
88
+ struct MyFillMap{T} <: LinearMaps.LinearMap{T}
89
+ λ:: T
90
+ size:: Dims{2}
91
+ function MyFillMap (λ:: T , dims:: Dims{2} ) where {T}
92
+ all (d -> d >= 0 , dims) || throw (ArgumentError (" dims of MyFillMap must be non-negative" ))
93
+ promote_type (T, typeof (λ)) == T || throw (InexactError ())
94
+ return new {T} (λ, dims)
95
+ end
96
+ end
97
+ Base. size (A:: MyFillMap ) = A. size
98
+ function LinearAlgebra. mul! (y:: AbstractVecOrMat , A:: MyFillMap , x:: AbstractVector )
99
+ LinearMaps. check_dim_mul (y, A, x)
100
+ return fill! (y, iszero (A. λ) ? zero (eltype (y)) : A. λ* sum (x))
101
+ end
102
+ function LinearAlgebra. mul! (y:: AbstractVecOrMat , transA:: LinearMaps.TransposeMap{<:Any,<:MyFillMap} , x:: AbstractVector )
103
+ LinearMaps. check_dim_mul (y, transA, x)
104
+ λ = transA. lmap. λ
105
+ return fill! (y, iszero (λ) ? zero (eltype (y)) : transpose (λ)* sum (x))
94
106
end
95
- end
96
- Base. size (A:: MyFillMap ) = A. size
97
- function LinearAlgebra. mul! (y:: AbstractVecOrMat , A:: MyFillMap , x:: AbstractVector )
98
- LinearMaps. check_dim_mul (y, A, x)
99
- return fill! (y, iszero (A. λ) ? zero (eltype (y)) : A. λ* sum (x))
100
- end
101
- function LinearAlgebra. mul! (y:: AbstractVecOrMat , transA:: LinearMaps.TransposeMap{<:Any,<:MyFillMap} , x:: AbstractVector )
102
- LinearMaps. check_dim_mul (y, transA, x)
103
- λ = transA. lmap. λ
104
- return fill! (y, iszero (λ) ? zero (eltype (y)) : transpose (λ)* sum (x))
105
- end
106
107
107
- @testset " transpose of new LinearMap type" begin
108
108
A = MyFillMap (5.0 , (3 , 3 ))
109
109
x = ones (3 )
110
110
@test A * x == fill (15.0 , 3 )
0 commit comments