Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 59 additions & 35 deletions test/testsuite/linalg.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@testsuite "linalg" (AT, eltypes)->begin
@testsuite "linalg/core " (AT, eltypes)->begin
@testset "adjoint and transpose" begin
@test compare(adjoint, AT, rand(Float32, 32, 32))
@test compare(adjoint!, AT, rand(Float32, 32, 32), rand(Float32, 32, 32))
Expand All @@ -22,12 +22,14 @@
@test compare(x -> permutedims(x, (2, 1)), AT, rand(Float32, 2, 3))
@test compare(x -> permutedims(x, (2, 1, 3)), AT, rand(Float32, 4, 5, 6))
@test compare(x -> permutedims(x, (3, 1, 2)), AT, rand(Float32, 4, 5, 6))
@test compare(x -> permutedims(x, [2,1,4,3]), AT, randn(ComplexF32,3,4,5,1))
# test UInt64 version to make sure it works properly when array length is larger than typemax of UInt32.
AT <: GPUArrays.AbstractGPUArray && @test let
x = randn(ComplexF32,3,4,5,1)
y = permutedims(x, (2,1,4,3))
Array(GPUArrays._permutedims!(UInt64, AT(zero(y)), AT(x), (2,1,4,3))) ≈ y
if ComplexF32 in eltypes
@test compare(x -> permutedims(x, [2,1,4,3]), AT, randn(ComplexF32,3,4,5,1))
# test UInt64 version to make sure it works properly when array length is larger than typemax of UInt32.
AT <: GPUArrays.AbstractGPUArray && @test let
x = randn(ComplexF32,3,4,5,1)
y = permutedims(x, (2,1,4,3))
Array(GPUArrays._permutedims!(UInt64, AT(zero(y)), AT(x), (2,1,4,3))) ≈ y
end
end
# high dimensional tensor
@test compare(x -> permutedims(x, 18:-1:1), AT, rand(Float32, 4, [2 for _ = 2:18]...))
Expand Down Expand Up @@ -70,12 +72,12 @@
@testset "triangular" begin
@testset "copytri!" begin
@testset for eltya in (Float32, Float64, ComplexF32, ComplexF64), uplo in ('U', 'L'), conjugate in (true, false)
n = 128
areal = randn(n,n)/2
aimg = randn(n,n)/2
if !(eltya in eltypes)
continue
end
n = 128
areal = randn(n,n)/2
aimg = randn(n,n)/2
a = convert(Matrix{eltya}, eltya <: Complex ? complex.(areal, aimg) : areal)
@test compare(x -> LinearAlgebra.copytri!(x, uplo, conjugate), AT, a)
end
Expand Down Expand Up @@ -146,6 +148,9 @@

@testset "mul! + Triangular" begin
@testset "trimatmul! ($TR x $T, $f)" for T in (Float32, ComplexF32), TR in (UpperTriangular, LowerTriangular, UnitUpperTriangular, UnitLowerTriangular), f in (identity, transpose, adjoint)
if !(T in eltypes)
continue
end
n = 128
A = AT(rand(T, n,n))
b = AT(rand(T, n))
Expand All @@ -164,6 +169,9 @@
end

@testset "mattrimul ($TR x $T, $f)" for T in (Float32, ComplexF32), TR in (UpperTriangular, LowerTriangular, UnitUpperTriangular, UnitLowerTriangular), f in (identity, transpose, adjoint)
if !(T in eltypes)
continue
end
n = 128
A = AT(rand(T, n,n))
B = AT(rand(T, n, n))
Expand Down Expand Up @@ -226,7 +234,10 @@
end

@testset "mul! + Diagonal" begin
for elty in (Float32, ComplexF32)
@testset "$elty" for elty in (Float32, ComplexF32)
if !(elty in eltypes)
continue
end
n = 128
d = AT(rand(elty, n))
D = Diagonal(d)
Expand Down Expand Up @@ -304,7 +315,10 @@
end

@testset "mul! + UniformScaling" begin
for elty in (Float32, ComplexF32)
@testset "$elty" for elty in (Float32, ComplexF32)
if !(elty in eltypes)
continue
end
n = 128
s = rand(elty)
I_s = UniformScaling(s)
Expand Down Expand Up @@ -339,43 +353,53 @@
end
end

@testset "lmul! and rmul!" for (a,b) in [((3,4),(4,3)), ((3,), (1,3)), ((1,3), (3))], T in eltypes
@test compare(rmul!, AT, rand(T, a), Ref(rand(T)))
@test compare(lmul!, AT, Ref(rand(T)), rand(T, b))
@testset "lmul! and rmul!" begin
@testset "$T ($a,$b)" for (a,b) in [((3,4),(4,3)), ((3,), (1,3)), ((1,3), (3))], T in eltypes
@test compare(rmul!, AT, rand(T, a), Ref(rand(T)))
@test compare(lmul!, AT, Ref(rand(T)), rand(T, b))
end
end

@testset "axp{b}y" for T in eltypes
@test compare(axpby!, AT, Ref(rand(T)), rand(T,5), Ref(rand(T)), rand(T,5))
@test compare(axpy!, AT, Ref(rand(T)), rand(T,5), rand(T,5))
@testset "axp{b}y" begin
@testset "$T" for T in eltypes
@test compare(axpby!, AT, Ref(rand(T)), rand(T,5), Ref(rand(T)), rand(T,5))
@test compare(axpy!, AT, Ref(rand(T)), rand(T,5), rand(T,5))
end
end

@testset "dot" for T in eltypes
@test compare(dot, AT, rand(T,5), rand(T, 5))
@testset "dot" begin
@testset "$T" for T in eltypes
@test compare(dot, AT, rand(T,5), rand(T, 5))
end
end

@testset "rotate!" for T in eltypes
@test compare(rotate!, AT, rand(T,5), rand(T,5), Ref(rand(real(T))), Ref(rand(T)))
@testset "rotate!" begin
@testset "$T" for T in eltypes
@test compare(rotate!, AT, rand(T,5), rand(T,5), Ref(rand(real(T))), Ref(rand(T)))
end
end

@testset "reflect!" for T in eltypes
@test compare(reflect!, AT, rand(T,5), rand(T,5), Ref(rand(real(T))), Ref(rand(T)))
@testset "reflect!" begin
@testset "$T" for T in eltypes
@test compare(reflect!, AT, rand(T,5), rand(T,5), Ref(rand(real(T))), Ref(rand(T)))
end
end

@testset "iszero and isone" for T in eltypes
A = one(AT(rand(T, 2, 2)))
@test isone(A)
@test iszero(A) == false
@testset "iszero and isone" begin
@testset "$T" for T in eltypes
A = one(AT(rand(T, 2, 2)))
@test isone(A)
@test iszero(A) == false

A = zero(AT(rand(T, 2, 2)))
@test iszero(A)
@test isone(A) == false
A = zero(AT(rand(T, 2, 2)))
@test iszero(A)
@test isone(A) == false
end
end

@testset "kron" begin
for T in eltypes
for opa in (vec, identity, transpose, adjoint), opb in (vec, identity, transpose, adjoint)
@test compare(kron, AT, opa(rand(T, 32, 64)), opb(rand(T, 128, 16)))
end
@testset "$T, $opa, $opb" for T in eltypes, opa in (vec, identity, transpose, adjoint), opb in (vec, identity, transpose, adjoint)
@test compare(kron, AT, opa(rand(T, 32, 64)), opb(rand(T, 128, 16)))
end
end
end
Expand Down
Loading