@@ -99,3 +99,37 @@ LinearAlgebra.mul!(y::AbstractVector, A::Union{SimpleFunctionMap,SimpleComplexFu
9999 @test SparseMatrixCSC (F) == Fs == L
100100 @test Fs isa SparseMatrixCSC
101101end
102+
103+ struct MyFillMap{T} <: LinearMaps.LinearMap{T}
104+ λ:: T
105+ size:: Dims{2}
106+ function MyFillMap (λ:: T , dims:: Dims{2} ) where {T}
107+ all (d -> d >= 0 , dims) || throw (ArgumentError (" dims of MyFillMap must be non-negative" ))
108+ promote_type (T, typeof (λ)) == T || throw (InexactError ())
109+ return new {T} (λ, dims)
110+ end
111+ end
112+ Base. size (A:: MyFillMap ) = A. size
113+ function LinearAlgebra. mul! (y:: AbstractVecOrMat , A:: MyFillMap , x:: AbstractVector )
114+ LinearMaps. check_dim_mul (y, A, x)
115+ return fill! (y, iszero (A. λ) ? zero (eltype (y)) : A. λ* sum (x))
116+ end
117+ function LinearAlgebra. mul! (y:: AbstractVecOrMat , transA:: LinearMaps.TransposeMap{<:Any,<:MyFillMap} , x:: AbstractVector )
118+ LinearMaps. check_dim_mul (y, transA, x)
119+ λ = transA. lmap. λ
120+ return fill! (y, iszero (λ) ? zero (eltype (y)) : transpose (λ)* sum (x))
121+ end
122+
123+ @testset " transpose of new LinearMap type" begin
124+ A = MyFillMap (5.0 , (3 , 3 ))
125+ x = ones (3 )
126+ @test A * x == fill (15.0 , 3 )
127+ @test mul! (zeros (3 ), A, x) == mul! (zeros (3 ), A, x, 1 , 0 ) == fill (15.0 , 3 )
128+ @test mul! (ones (3 ), A, x, 2 , 2 ) == fill (32.0 , 3 )
129+ @test mul! (ones (3 ,3 ), A, reshape (collect (1 : 9 ), 3 , 3 ), 2 , 2 )[:,1 ] == fill (62.0 , 3 )
130+ @test A' x == mul! (zeros (3 ), A' , x)
131+ for α in (true , false , 0 , 1 , randn ()), β in (true , false , 0 , 1 , randn ())
132+ @test mul! (ones (3 ), A' , x, α, β) == fill (β, 3 ) + fill (15 α, 3 )
133+ @test mul! (ones (3 , 2 ), A' , [x x], α, β) == fill (β, 3 , 2 ) + fill (15 α, 3 , 2 )
134+ end
135+ end
0 commit comments