Skip to content

Commit 1901868

Browse files
Minor test improvements (#638)
* Improve output when erroring * Guard against testing unsupported types
1 parent ace8c16 commit 1901868

File tree

1 file changed

+59
-35
lines changed

1 file changed

+59
-35
lines changed

test/testsuite/linalg.jl

Lines changed: 59 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@testsuite "linalg" (AT, eltypes)->begin
1+
@testsuite "linalg/core " (AT, eltypes)->begin
22
@testset "adjoint and transpose" begin
33
@test compare(adjoint, AT, rand(Float32, 32, 32))
44
@test compare(adjoint!, AT, rand(Float32, 32, 32), rand(Float32, 32, 32))
@@ -22,12 +22,14 @@
2222
@test compare(x -> permutedims(x, (2, 1)), AT, rand(Float32, 2, 3))
2323
@test compare(x -> permutedims(x, (2, 1, 3)), AT, rand(Float32, 4, 5, 6))
2424
@test compare(x -> permutedims(x, (3, 1, 2)), AT, rand(Float32, 4, 5, 6))
25-
@test compare(x -> permutedims(x, [2,1,4,3]), AT, randn(ComplexF32,3,4,5,1))
26-
# test UInt64 version to make sure it works properly when array length is larger than typemax of UInt32.
27-
AT <: GPUArrays.AbstractGPUArray && @test let
28-
x = randn(ComplexF32,3,4,5,1)
29-
y = permutedims(x, (2,1,4,3))
30-
Array(GPUArrays._permutedims!(UInt64, AT(zero(y)), AT(x), (2,1,4,3))) y
25+
if ComplexF32 in eltypes
26+
@test compare(x -> permutedims(x, [2,1,4,3]), AT, randn(ComplexF32,3,4,5,1))
27+
# test UInt64 version to make sure it works properly when array length is larger than typemax of UInt32.
28+
AT <: GPUArrays.AbstractGPUArray && @test let
29+
x = randn(ComplexF32,3,4,5,1)
30+
y = permutedims(x, (2,1,4,3))
31+
Array(GPUArrays._permutedims!(UInt64, AT(zero(y)), AT(x), (2,1,4,3))) y
32+
end
3133
end
3234
# high dimensional tensor
3335
@test compare(x -> permutedims(x, 18:-1:1), AT, rand(Float32, 4, [2 for _ = 2:18]...))
@@ -70,12 +72,12 @@
7072
@testset "triangular" begin
7173
@testset "copytri!" begin
7274
@testset for eltya in (Float32, Float64, ComplexF32, ComplexF64), uplo in ('U', 'L'), conjugate in (true, false)
73-
n = 128
74-
areal = randn(n,n)/2
75-
aimg = randn(n,n)/2
7675
if !(eltya in eltypes)
7776
continue
7877
end
78+
n = 128
79+
areal = randn(n,n)/2
80+
aimg = randn(n,n)/2
7981
a = convert(Matrix{eltya}, eltya <: Complex ? complex.(areal, aimg) : areal)
8082
@test compare(x -> LinearAlgebra.copytri!(x, uplo, conjugate), AT, a)
8183
end
@@ -146,6 +148,9 @@
146148

147149
@testset "mul! + Triangular" begin
148150
@testset "trimatmul! ($TR x $T, $f)" for T in (Float32, ComplexF32), TR in (UpperTriangular, LowerTriangular, UnitUpperTriangular, UnitLowerTriangular), f in (identity, transpose, adjoint)
151+
if !(T in eltypes)
152+
continue
153+
end
149154
n = 128
150155
A = AT(rand(T, n,n))
151156
b = AT(rand(T, n))
@@ -164,6 +169,9 @@
164169
end
165170

166171
@testset "mattrimul ($TR x $T, $f)" for T in (Float32, ComplexF32), TR in (UpperTriangular, LowerTriangular, UnitUpperTriangular, UnitLowerTriangular), f in (identity, transpose, adjoint)
172+
if !(T in eltypes)
173+
continue
174+
end
167175
n = 128
168176
A = AT(rand(T, n,n))
169177
B = AT(rand(T, n, n))
@@ -226,7 +234,10 @@
226234
end
227235

228236
@testset "mul! + Diagonal" begin
229-
for elty in (Float32, ComplexF32)
237+
@testset "$elty" for elty in (Float32, ComplexF32)
238+
if !(elty in eltypes)
239+
continue
240+
end
230241
n = 128
231242
d = AT(rand(elty, n))
232243
D = Diagonal(d)
@@ -304,7 +315,10 @@
304315
end
305316

306317
@testset "mul! + UniformScaling" begin
307-
for elty in (Float32, ComplexF32)
318+
@testset "$elty" for elty in (Float32, ComplexF32)
319+
if !(elty in eltypes)
320+
continue
321+
end
308322
n = 128
309323
s = rand(elty)
310324
I_s = UniformScaling(s)
@@ -339,43 +353,53 @@
339353
end
340354
end
341355

342-
@testset "lmul! and rmul!" for (a,b) in [((3,4),(4,3)), ((3,), (1,3)), ((1,3), (3))], T in eltypes
343-
@test compare(rmul!, AT, rand(T, a), Ref(rand(T)))
344-
@test compare(lmul!, AT, Ref(rand(T)), rand(T, b))
356+
@testset "lmul! and rmul!" begin
357+
@testset "$T ($a,$b)" for (a,b) in [((3,4),(4,3)), ((3,), (1,3)), ((1,3), (3))], T in eltypes
358+
@test compare(rmul!, AT, rand(T, a), Ref(rand(T)))
359+
@test compare(lmul!, AT, Ref(rand(T)), rand(T, b))
360+
end
345361
end
346362

347-
@testset "axp{b}y" for T in eltypes
348-
@test compare(axpby!, AT, Ref(rand(T)), rand(T,5), Ref(rand(T)), rand(T,5))
349-
@test compare(axpy!, AT, Ref(rand(T)), rand(T,5), rand(T,5))
363+
@testset "axp{b}y" begin
364+
@testset "$T" for T in eltypes
365+
@test compare(axpby!, AT, Ref(rand(T)), rand(T,5), Ref(rand(T)), rand(T,5))
366+
@test compare(axpy!, AT, Ref(rand(T)), rand(T,5), rand(T,5))
367+
end
350368
end
351369

352-
@testset "dot" for T in eltypes
353-
@test compare(dot, AT, rand(T,5), rand(T, 5))
370+
@testset "dot" begin
371+
@testset "$T" for T in eltypes
372+
@test compare(dot, AT, rand(T,5), rand(T, 5))
373+
end
354374
end
355375

356-
@testset "rotate!" for T in eltypes
357-
@test compare(rotate!, AT, rand(T,5), rand(T,5), Ref(rand(real(T))), Ref(rand(T)))
376+
@testset "rotate!" begin
377+
@testset "$T" for T in eltypes
378+
@test compare(rotate!, AT, rand(T,5), rand(T,5), Ref(rand(real(T))), Ref(rand(T)))
379+
end
358380
end
359381

360-
@testset "reflect!" for T in eltypes
361-
@test compare(reflect!, AT, rand(T,5), rand(T,5), Ref(rand(real(T))), Ref(rand(T)))
382+
@testset "reflect!" begin
383+
@testset "$T" for T in eltypes
384+
@test compare(reflect!, AT, rand(T,5), rand(T,5), Ref(rand(real(T))), Ref(rand(T)))
385+
end
362386
end
363387

364-
@testset "iszero and isone" for T in eltypes
365-
A = one(AT(rand(T, 2, 2)))
366-
@test isone(A)
367-
@test iszero(A) == false
388+
@testset "iszero and isone" begin
389+
@testset "$T" for T in eltypes
390+
A = one(AT(rand(T, 2, 2)))
391+
@test isone(A)
392+
@test iszero(A) == false
368393

369-
A = zero(AT(rand(T, 2, 2)))
370-
@test iszero(A)
371-
@test isone(A) == false
394+
A = zero(AT(rand(T, 2, 2)))
395+
@test iszero(A)
396+
@test isone(A) == false
397+
end
372398
end
373399

374400
@testset "kron" begin
375-
for T in eltypes
376-
for opa in (vec, identity, transpose, adjoint), opb in (vec, identity, transpose, adjoint)
377-
@test compare(kron, AT, opa(rand(T, 32, 64)), opb(rand(T, 128, 16)))
378-
end
401+
@testset "$T, $opa, $opb" for T in eltypes, opa in (vec, identity, transpose, adjoint), opb in (vec, identity, transpose, adjoint)
402+
@test compare(kron, AT, opa(rand(T, 32, 64)), opb(rand(T, 128, 16)))
379403
end
380404
end
381405
end

0 commit comments

Comments
 (0)