diff --git a/test/runtests.jl b/test/runtests.jl index 89911d45..b43820e8 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -64,39 +64,6 @@ if isdefined(Test, :detect_closure_boxes) end end -# BLAS 1 calls that released back-ends' own methods take and get wrong; these move to the test -# suite once back-ends rely on GPUArrays' methods -testsuite["JLArray/blas1"] = quote - using LinearAlgebra - import ..TestSuite: compare - @testset "dot, $T" for T in (Float32, ComplexF32, Float16, Int64) - @test_throws DimensionMismatch dot(Diagonal(JLArray(rand(T, 4))), JLArray(rand(T, 16, 1))) - A, B = rand(T, 4, 6), rand(T, 4, 6) - @test compare((A, B) -> dot(A', B'), JLArray, A, B) - x, y = rand(T, 12), rand(T, 12) - @test compare((x, y) -> dot(view(x, 1:2:12), view(y, 1:2:12)), JLArray, x, y) - @test compare((A, x) -> dot(A, x[1:12]), JLArray, A[:, 1:3], x) - @test compare(x -> (r = Base.ReshapedArray(x, (3, 4), ()); dot(r, r)), JLArray, x) - - S, R = rand(T, 4, 4), rand(T, 4, 4) - @test compare((S, R) -> dot(Hermitian(S), Hermitian(R, :L)), JLArray, S, R) - # the dot product of Hermitian matrices is real, also in type with Julia 1.11 and later - H(S) = Hermitian(JLArray(S)) - @test typeof(dot(H(S), H(R))) == typeof(dot(Hermitian(S), Hermitian(R))) - @test dot(H(S[1:0, 1:0]), H(R[1:0, 1:0])) === zero(typeof(dot(Hermitian(S), Hermitian(R)))) - end - @test compare(B -> dot(Hermitian(B), Hermitian(B)), JLArray, rand(Bool, 4, 4)) - @test compare((x, d) -> rdiv!(x, Diagonal(d)), JLArray, rand(Float32, 3), rand(Float32, 1) .+ 1) - @test compare((x, d) -> x / Diagonal(d), JLArray, rand(Float32, 3), rand(Float32, 1) .+ 1) - @testset "operands of different shapes, $T" for T in (Float32, ComplexF32) - A, x = rand(T, 4, 3), rand(T, 6) - @test compare((A, x) -> axpy!(T(2), view(A, 1:2, :), x), JLArray, A, x) - @test compare((x, A) -> axpy!(T(2), x, view(A, 1:2, :)), JLArray, x, A) - @test compare((A, x) -> axpby!(T(2), view(A, 1:2, :), T(3), x), JLArray, A, x) - @test compare((A, x) -> axpby!(T(2), view(A, 1:2, :), false, x), JLArray, A, x) - end -end - # a type without a COO counterpart must hit a MethodError, not recurse (#780) testsuite["sparse/coo_type"] = quote import GPUArrays diff --git a/test/testsuite/linalg.jl b/test/testsuite/linalg.jl index 89a47f52..5066eb23 100644 --- a/test/testsuite/linalg.jl +++ b/test/testsuite/linalg.jl @@ -1211,12 +1211,9 @@ end end @test compare(x -> rmul!(v(x), T(2)), AT, x) - # back-ends' own methods may not support dot products of stepped views yet - if !(rows isa StepRange) - @test compare((x, y) -> dot(v(x), v(y)), AT, x, y) - @test compare((x, y) -> v(x)' * v(y), AT, x, y) - T <: Complex && @test compare((x, y) -> transpose(v(x)) * v(y), AT, x, y) - end + @test compare((x, y) -> dot(v(x), v(y)), AT, x, y) + @test compare((x, y) -> v(x)' * v(y), AT, x, y) + T <: Complex && @test compare((x, y) -> transpose(v(x)) * v(y), AT, x, y) @test compare(x -> norm(v(x)), AT, x) @test compare(x -> norm(v(x), 1), AT, x) @test compare(x -> LinearAlgebra.BLAS.asum(v(x)), AT, x) @@ -1231,6 +1228,15 @@ end @test_throws DimensionMismatch axpy!(T(1), v(AT(x)), AT(rand(T, n + 1))) end + @testset "operands of different shapes, $T" for T in (Float32, ComplexF32) + T in eltypes || continue + A, x = rand(T, 4, 3), rand(T, 6) + @test compare((A, x) -> axpy!(T(2), view(A, 1:2, :), x), AT, A, x) + @test compare((x, A) -> axpy!(T(2), x, view(A, 1:2, :)), AT, x, A) + @test compare((A, x) -> axpby!(T(2), view(A, 1:2, :), T(3), x), AT, A, x) + @test compare((A, x) -> axpby!(T(2), view(A, 1:2, :), false, x), AT, A, x) + end + @testset "columns of a padded matrix" begin T = Float32 T in eltypes || return @@ -1241,9 +1247,12 @@ end @test compare((A, B) -> dot(v(A), v(B)), AT, A, B) end - @testset "dot of wrapped arrays, $T" for T in (Float32, ComplexF32, Int64) + @testset "dot of wrapped arrays, $T" for T in (Float32, ComplexF32, Float16, Int64) T in eltypes || continue A, B = rand(T, 4, 6), rand(T, 4, 6) + @test compare((A, B) -> dot(A', B'), AT, A, B) + @test compare((A, B) -> dot(A, B[:, 1:3][:]), AT, A[:, 1:3], B) + @test compare(A -> (r = Base.ReshapedArray(A, (3, 8), ()); dot(r, r)), AT, A) @test compare((A, B) -> dot(PermutedDimsArray(A, (2, 1)), PermutedDimsArray(B, (2, 1))), AT, A, B) @test compare((A, B) -> dot(PermutedDimsArray(A, (2, 1)), copy(B')), AT, A, B) @test compare((A, B) -> dot(view(A, 1:2:3, :), view(B, 1:2:3, :)), AT, A, B) @@ -1257,20 +1266,26 @@ end @test compare((S, R) -> dot(UpperTriangular(S), LowerTriangular(R)), AT, S, R) @test compare((S, R) -> dot(Symmetric(S), Symmetric(R, :L)), AT, S, R) @test compare((S, R) -> dot(Symmetric(S), R), AT, S, R) + @test compare((S, R) -> dot(Hermitian(S), Hermitian(R, :L)), AT, S, R) + # the dot product of Hermitian matrices is real, also in type with Julia 1.11 and later + H(S) = Hermitian(AT(S)) + @test typeof(dot(H(S), H(R))) == typeof(dot(Hermitian(S), Hermitian(R))) + @test dot(H(S[1:0, 1:0]), H(R[1:0, 1:0])) === zero(typeof(dot(Hermitian(S), Hermitian(R)))) d, e = rand(T, 4), rand(T, 4) + @test_throws DimensionMismatch dot(Diagonal(AT(d)), AT(rand(T, 16, 1))) @test compare((d, e) -> dot(Diagonal(d), Diagonal(e)), AT, d, e) @test compare((d, S) -> dot(Diagonal(d), S), AT, d, S) @test compare((d, S) -> dot(S, Diagonal(d)), AT, d, S) @test compare((d, S) -> dot(Diagonal(d), UpperTriangular(S)), AT, d, S) @test compare((d, S) -> dot(Symmetric(S), Diagonal(d)), AT, d, S) - # stepped views of element types LinearAlgebra doesn't pass to BLAS - if !(T <: LinearAlgebra.BlasFloat) - x, y = rand(T, 12), rand(T, 12) - @test compare((x, y) -> dot(view(x, 1:2:12), view(y, 1:2:12)), AT, x, y) - @test compare((x, y) -> dot(view(x, 12:-2:1), y[1:6]), AT, x, y) - end + x, y = rand(T, 12), rand(T, 12) + @test compare((x, y) -> dot(view(x, 1:2:12), view(y, 1:2:12)), AT, x, y) + @test compare((x, y) -> dot(view(x, 12:-2:1), y[1:6]), AT, x, y) + end + if Bool in eltypes + @test compare(B -> dot(Hermitian(B), Hermitian(B)), AT, rand(Bool, 4, 4)) end @testset "Givens rotations" begin @@ -1319,6 +1334,8 @@ end @test compare((d, A) -> rdiv!(copy(A'), Diagonal(d)), AT, d, A) @test Array(Diagonal(AT(d))) == Matrix(Diagonal(d)) @test compare((e, W) -> Diagonal(e) * W, AT, rand(T, 0), rand(T, 0, 3)) + @test compare((x, e) -> rdiv!(x, Diagonal(e)), AT, rand(T, 3), rand(T, 1) .+ 1) + @test compare((x, e) -> x / Diagonal(e), AT, rand(T, 3), rand(T, 1) .+ 1) end end end