Skip to content

Commit 036e4a8

Browse files
committed
polish tests
1 parent 5688bcf commit 036e4a8

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

test/linearmaps.jl

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,20 @@ using Test, LinearMaps, LinearAlgebra, SparseArrays
3333
end
3434
end
3535

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-
4936
@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+
5050
F = SimpleFunctionMap(cumsum, 10)
5151
FC = SimpleComplexFunctionMap(cumsum, 10)
5252
@test @inferred ndims(F) == 2
@@ -84,27 +84,27 @@ LinearAlgebra.mul!(y::AbstractVector, A::Union{SimpleFunctionMap,SimpleComplexFu
8484
@test Fs isa SparseMatrixCSC
8585
end
8686

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))
94106
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
106107

107-
@testset "transpose of new LinearMap type" begin
108108
A = MyFillMap(5.0, (3, 3))
109109
x = ones(3)
110110
@test A * x == fill(15.0, 3)

0 commit comments

Comments
 (0)