Skip to content

Commit cb5de3e

Browse files
committed
Add more complete multiplication tests
1 parent e3f6255 commit cb5de3e

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

test/linalg.jl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,4 +1040,35 @@ end
10401040
@test_throws DimensionMismatch D1 * S * D1
10411041
end
10421042

1043+
@testset "multiplication of sparse and dense matrices" begin
1044+
function test_mul(A, B)
1045+
expected = Matrix(A) * Matrix(B)
1046+
@test A * B expected
1047+
C = similar(expected)
1048+
@test mul!(C, A, B) === C
1049+
@test C expected
1050+
ElType = eltype(C)
1051+
vs = Any[false, true, zero(ElType), one(ElType), one(ElType) + one(ElType)]
1052+
for α in vs
1053+
for β in vs
1054+
C .= rand.(ElType)
1055+
expected′ = expected .* α .+ C .* β
1056+
@test mul!(C, A, B, α, β) === C
1057+
@test C expected′
1058+
end
1059+
end
1060+
end
1061+
1062+
for ElType in [Int, Float64, ComplexF64, BigFloat]
1063+
SP = sprand(ElType, 10, 10, 0.3)
1064+
D = rand(ElType, 10, 10)
1065+
for f1 in [identity, adjoint, transpose]
1066+
for f2 in [identity, adjoint, transpose]
1067+
test_mul(f1(SP), f2(D))
1068+
test_mul(f1(D), f2(SP))
1069+
end
1070+
end
1071+
end
1072+
end
1073+
10431074
end

0 commit comments

Comments
 (0)