@@ -21,34 +21,6 @@ using Test, LinearMaps, LinearAlgebra, SparseArrays, BenchmarkTools
2121 @test length (M) == length (A)
2222 end
2323
24- Av = A * v
25- AV = A * V
26-
27- @testset " mul! and *" begin
28- for w in (vec (u), u)
29- @test M * v == Av
30- @test N * v == Av
31- @test @inferred mul! (copy (w), M, v) == mul! (copy (w), A, v)
32- b = @benchmarkable mul! ($ w, $ M, $ v)
33- @test run (b, samples= 3 ). allocs == 0
34- @test @inferred mul! (copy (w), N, v) == mul! (copy (w), A, v)
35-
36- # mat-vec-mul
37- @test @inferred mul! (copy (w), M, v, 0 , 0 ) == zero (w)
38- @test @inferred mul! (copy (w), M, v, 0 , 1 ) == w
39- @test @inferred mul! (copy (w), M, v, 0 , β) == β * w
40- @test @inferred mul! (copy (w), M, v, 1 , 1 ) ≈ Av + w
41- @test @inferred mul! (copy (w), M, v, 1 , β) ≈ Av + β * w
42- @test @inferred mul! (copy (w), M, v, α, 1 ) ≈ α * Av + w
43- @test @inferred mul! (copy (w), M, v, α, β) ≈ α * Av + β * w
44- end
45-
46- # test mat-mat-mul!
47- @test @inferred mul! (copy (W), M, V, α, β) ≈ α * AV + β * W
48- @test @inferred mul! (copy (W), M, V) ≈ AV
49- @test typeof (M * V) <: LinearMap
50- end
51-
5224 @testset " dimension checking" begin
5325 w = vec (u)
5426 @test_throws DimensionMismatch M * similar (v, length (v) + 1 )
@@ -70,7 +42,7 @@ struct SimpleComplexFunctionMap <: LinearMap{Complex{Float64}}
7042 N:: Int
7143end
7244Base. size (A:: Union{SimpleFunctionMap,SimpleComplexFunctionMap} ) = (A. N, A. N)
73- Base.:(* )(A:: Union{SimpleFunctionMap,SimpleComplexFunctionMap} , v:: Vector ) = A. f (v)
45+ Base.:(* )(A:: Union{SimpleFunctionMap,SimpleComplexFunctionMap} , v:: AbstractVector ) = A. f (v)
7446LinearAlgebra. mul! (y:: AbstractVector , A:: Union{SimpleFunctionMap,SimpleComplexFunctionMap} , x:: AbstractVector ) = copyto! (y, * (A, x))
7547
7648@testset " new LinearMap type" begin
@@ -83,10 +55,12 @@ LinearAlgebra.mul!(y::AbstractVector, A::Union{SimpleFunctionMap,SimpleComplexFu
8355 @test @inferred ! ishermitian (F)
8456 @test @inferred ! ishermitian (FC)
8557 @test @inferred ! isposdef (F)
86- v = rand (ComplexF64, 10 )
87- w = similar (v)
88- mul! (w, F, v)
89- @test w == F * v
58+ @test occursin (" 10×10 SimpleFunctionMap{Float64}" , sprint ((t, s) -> show (t, " text/plain" , s), F))
59+ @test occursin (" 10×10 SimpleComplexFunctionMap{Complex{Float64}}" , sprint ((t, s) -> show (t, " text/plain" , s), FC))
60+ α = rand (ComplexF64); β = rand (ComplexF64)
61+ v = rand (ComplexF64, 10 ); V = rand (ComplexF64, 10 , 3 )
62+ w = rand (ComplexF64, 10 ); W = rand (ComplexF64, 10 , 3 )
63+ @test mul! (w, F, v) === w == F * v
9064 @test_throws ErrorException F' * v
9165 @test_throws ErrorException transpose (F) * v
9266 @test_throws ErrorException mul! (w, adjoint (FC), v)
@@ -95,6 +69,11 @@ LinearAlgebra.mul!(y::AbstractVector, A::Union{SimpleFunctionMap,SimpleComplexFu
9569 L = LowerTriangular (ones (10 , 10 ))
9670 @test FM == L
9771 @test F * v ≈ L * v
72+ # generic 5-arg mul! and matrix-mul!
73+ @test mul! (copy (w), F, v, α, β) ≈ L* v* α + w* β
74+ @test mul! (copy (W), F, V) ≈ L* V
75+ @test mul! (copy (W), F, V, α, β) ≈ L* V* α + W* β
76+
9877 Fs = sparse (F)
9978 @test SparseMatrixCSC (F) == Fs == L
10079 @test Fs isa SparseMatrixCSC
0 commit comments