Skip to content

Commit 433577d

Browse files
authored
Merge pull request #167 from kshyatt/ksh/test5
More error throwing tests
2 parents 63faacc + 31186f4 commit 433577d

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

test/matrix_multiply.jl

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
@testset "Matrix-vector" begin
33
m = @SMatrix [1 2; 3 4]
44
v = @SVector [1, 2]
5+
v_bad = @SVector [1, 2, 3]
56
@test m*v === @SVector [5, 11]
7+
@test_throws DimensionMismatch m*v_bad
68
# More complicated eltype inference
79
v2 = @SVector [CartesianIndex((1,3)), CartesianIndex((3,1))]
810
x = @inferred(m*v2)
@@ -17,6 +19,8 @@
1719

1820
v3 = [1, 2]
1921
@test m*v3 === @SVector [5, 11]
22+
v3_bad = [1, 2, 3]
23+
@test_throws DimensionMismatch m*v3_bad
2024

2125
m2 = @MMatrix [1 2; 3 4]
2226
v4 = @MVector [1, 2]
@@ -141,6 +145,48 @@
141145
m = MMatrix{16,16}(m_array)
142146
n = MMatrix{16,16}(n_array)
143147
@test m*n::MMatrix a_array
148+
149+
# Complex numbers
150+
m_array = randn(4, 4)
151+
n_array = im*randn(4, 4)
152+
a_array = m_array*n_array
153+
154+
m = MMatrix{4,4}(m_array)
155+
n = MMatrix{4,4}(n_array)
156+
@test m*n::MMatrix a_array
157+
158+
m_array = randn(10, 10)
159+
n_array = im*randn(10, 10)
160+
a_array = m_array*n_array
161+
162+
m = MMatrix{10,10}(m_array)
163+
n = MMatrix{10,10}(n_array)
164+
@test m*n::MMatrix a_array
165+
166+
m_array = randn(16, 16)
167+
n_array = im*randn(16, 16)
168+
a_array = m_array*n_array
169+
170+
m = MMatrix{16,16}(m_array)
171+
n = MMatrix{16,16}(n_array)
172+
@test m*n::MMatrix a_array
173+
174+
# Bad dimensions
175+
m_array = randn(16, 16)
176+
n_array = randn(17, 17)
177+
m = MMatrix{16,16}(m_array)
178+
n = MMatrix{17,17}(n_array)
179+
@test_throws DimensionMismatch m*n
180+
m_array = randn(10, 10)
181+
n_array = randn(11, 11)
182+
m = MMatrix{10,10}(m_array)
183+
n = MMatrix{11,11}(n_array)
184+
@test_throws DimensionMismatch m*n
185+
m_array = randn(4, 4)
186+
n_array = randn(3, 3)
187+
m = MMatrix{4,4}(m_array)
188+
n = MMatrix{3,3}(n_array)
189+
@test_throws DimensionMismatch m*n
144190
end
145191

146192
@testset "A_mul_B!" begin
@@ -156,10 +202,15 @@
156202
A_mul_B!(outvec2, m, v2)
157203
@test outvec2 == [10,22]
158204

205+
# Bad dimensions
206+
outvec_bad = MVector{3,Int}()
207+
@test_throws DimensionMismatch A_mul_B!(outvec_bad, m, v)
208+
159209
a = MMatrix{2,2,Int,4}()
160210
A_mul_B!(a, m, n)
161211
@test a::MMatrix{2,2,Int,4} == @MMatrix [10 13; 22 29]
162212

213+
a = MMatrix{2,2,Int,4}()
163214
Ac_mul_B!(a, m, n)
164215
@test a::MMatrix{2,2,Int,4} == @MMatrix [14 18; 20 26]
165216
A_mul_Bc!(a, m, n)

0 commit comments

Comments
 (0)