Skip to content

Commit e9ec23c

Browse files
committed
Add more dimension error check
1 parent 8c7039d commit e9ec23c

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

test/linalg.jl

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,26 +1049,38 @@ end
10491049
@test C expected
10501050
ElType = eltype(C)
10511051
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
1052+
for α in vs, β in vs
1053+
C .= rand.(ElType)
1054+
expected′ = expected .* α .+ C .* β
1055+
@test mul!(C, A, B, α, β) === C
1056+
@test C expected′
10591057
end
10601058
end
10611059

10621060
for ElType in [Int, Float64, ComplexF64, BigFloat]
10631061
SP = sprand(ElType, 10, 10, 0.3)
10641062
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
1063+
fs = [identity, adjoint, transpose]
1064+
for f1 in fs, f2 in fs
1065+
test_mul(f1(SP), f2(D))
1066+
test_mul(f1(D), f2(SP))
10701067
end
10711068
end
10721069
end
10731070

1071+
@testset "dimension mismatch error" begin
1072+
fs = [rand, (x, y)->adjoint(rand(y, x)), (x, y)->transpose(rand(y, x)),
1073+
(x, y)->sprand(x, y, 0.5), (x, y)->adjoint(sprand(y, x, 0.5)),
1074+
(x, y)->transpose(sprand(y, x, 0.5))]
1075+
for fA in fs, fB in fs
1076+
mul!(zeros(6, 10), fA(6, 8), fB(8, 10))
1077+
@test_throws DimensionMismatch mul!(zeros(7, 10), fA(6, 8), fB(8, 10))
1078+
@test_throws DimensionMismatch mul!(zeros(6, 11), fA(6, 8), fB(8, 10))
1079+
@test_throws DimensionMismatch mul!(zeros(6, 10), fA(5, 8), fB(8, 10))
1080+
@test_throws DimensionMismatch mul!(zeros(6, 10), fA(6, 9), fB(8, 10))
1081+
@test_throws DimensionMismatch mul!(zeros(6, 10), fA(6, 8), fB(7, 10))
1082+
@test_throws DimensionMismatch mul!(zeros(6, 10), fA(6, 8), fB(8, 9))
1083+
end
1084+
end
1085+
10741086
end

0 commit comments

Comments
 (0)