|
1 | | -@testsuite "linalg" (AT, eltypes)->begin |
| 1 | +@testsuite "linalg/core " (AT, eltypes)->begin |
2 | 2 | @testset "adjoint and transpose" begin |
3 | 3 | @test compare(adjoint, AT, rand(Float32, 32, 32)) |
4 | 4 | @test compare(adjoint!, AT, rand(Float32, 32, 32), rand(Float32, 32, 32)) |
|
22 | 22 | @test compare(x -> permutedims(x, (2, 1)), AT, rand(Float32, 2, 3)) |
23 | 23 | @test compare(x -> permutedims(x, (2, 1, 3)), AT, rand(Float32, 4, 5, 6)) |
24 | 24 | @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 |
31 | 33 | end |
32 | 34 | # high dimensional tensor |
33 | 35 | @test compare(x -> permutedims(x, 18:-1:1), AT, rand(Float32, 4, [2 for _ = 2:18]...)) |
|
70 | 72 | @testset "triangular" begin |
71 | 73 | @testset "copytri!" begin |
72 | 74 | @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 |
76 | 75 | if !(eltya in eltypes) |
77 | 76 | continue |
78 | 77 | end |
| 78 | + n = 128 |
| 79 | + areal = randn(n,n)/2 |
| 80 | + aimg = randn(n,n)/2 |
79 | 81 | a = convert(Matrix{eltya}, eltya <: Complex ? complex.(areal, aimg) : areal) |
80 | 82 | @test compare(x -> LinearAlgebra.copytri!(x, uplo, conjugate), AT, a) |
81 | 83 | end |
|
146 | 148 |
|
147 | 149 | @testset "mul! + Triangular" begin |
148 | 150 | @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 |
149 | 154 | n = 128 |
150 | 155 | A = AT(rand(T, n,n)) |
151 | 156 | b = AT(rand(T, n)) |
|
164 | 169 | end |
165 | 170 |
|
166 | 171 | @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 |
167 | 175 | n = 128 |
168 | 176 | A = AT(rand(T, n,n)) |
169 | 177 | B = AT(rand(T, n, n)) |
|
226 | 234 | end |
227 | 235 |
|
228 | 236 | @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 |
230 | 241 | n = 128 |
231 | 242 | d = AT(rand(elty, n)) |
232 | 243 | D = Diagonal(d) |
|
304 | 315 | end |
305 | 316 |
|
306 | 317 | @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 |
308 | 322 | n = 128 |
309 | 323 | s = rand(elty) |
310 | 324 | I_s = UniformScaling(s) |
|
339 | 353 | end |
340 | 354 | end |
341 | 355 |
|
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 |
345 | 361 | end |
346 | 362 |
|
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 |
350 | 368 | end |
351 | 369 |
|
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 |
354 | 374 | end |
355 | 375 |
|
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 |
358 | 380 | end |
359 | 381 |
|
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 |
362 | 386 | end |
363 | 387 |
|
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 |
368 | 393 |
|
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 |
372 | 398 | end |
373 | 399 |
|
374 | 400 | @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))) |
379 | 403 | end |
380 | 404 | end |
381 | 405 | end |
|
0 commit comments