diff --git a/test/testsuite.jl b/test/testsuite.jl index be533f7e..e957c597 100644 --- a/test/testsuite.jl +++ b/test/testsuite.jl @@ -1,4 +1,6 @@ # test suite that can be used for all packages inheriting from GPUArrays +# +# use this by either calling `test`, or inspecting the dictionary `tests` module TestSuite @@ -28,12 +30,25 @@ function supported_eltypes() (Float32, Float64, Int32, Int64, ComplexF32, ComplexF64) end +# list of tests +const tests = Dict() +macro testsuite(name, ex) + safe_name = lowercase(replace(name, " "=>"_")) + fn = Symbol("test_$(safe_name)") + quote + $fn(AT) = $(esc(ex))(AT) + + @assert !haskey(tests, $name) + tests[$name] = $fn + end +end + include("testsuite/construction.jl") include("testsuite/gpuinterface.jl") include("testsuite/indexing.jl") include("testsuite/io.jl") include("testsuite/base.jl") -include("testsuite/vector.jl") +#include("testsuite/vector.jl") include("testsuite/mapreduce.jl") include("testsuite/broadcasting.jl") include("testsuite/linalg.jl") @@ -42,23 +57,16 @@ include("testsuite/fft.jl") include("testsuite/random.jl") include("testsuite/uniformscaling.jl") - """ Runs the entire GPUArrays test suite on array type `AT` """ function test(AT::Type{<:AbstractGPUArray}) - TestSuite.test_construction(AT) - TestSuite.test_gpuinterface(AT) - TestSuite.test_indexing(AT) - TestSuite.test_io(AT) - TestSuite.test_base(AT) - TestSuite.test_mapreduce(AT) - TestSuite.test_broadcasting(AT) - TestSuite.test_linalg(AT) - TestSuite.test_math(AT) - TestSuite.test_fft(AT) - TestSuite.test_random(AT) - TestSuite.test_uniformscaling(AT) + for (name, fun) in tests + code = quote + $fun($AT) + end + @eval @testset $name $code + end end end diff --git a/test/testsuite/base.jl b/test/testsuite/base.jl index e208aa4d..702e8399 100644 --- a/test/testsuite/base.jl +++ b/test/testsuite/base.jl @@ -25,142 +25,140 @@ function ntuple_closure(ctx, result, ::Val{N}, testval) where N return end -function test_base(AT) - @testset "base functionality" begin - @testset "copyto!" begin - x = fill(0f0, (10, 10)) - y = rand(Float32, (20, 10)) - a = AT(x) - b = AT(y) - r1 = CartesianIndices((1:7, 3:8)) - r2 = CartesianIndices((4:10, 3:8)) - copyto!(x, r1, y, r2) - copyto!(a, r1, b, r2) - @test x == Array(a) - r2 = CartesianIndices((4:11, 3:8)) - @test_throws DimensionMismatch copyto!(a, r1, b, r2) - - r2 = CartesianIndices((4:10, 3:8)) - x2 = fill(0f0, (10, 10)) - copyto!(x2, r1, b, r2) - @test x2 == x - - fill!(a, 0f0) - copyto!(a, r1, y, r2) - @test Array(a) == x - - x = fill(0f0, (10,)) - y = rand(Float32, (20,)) - a = AT(x) - b = AT(y) - r1 = CartesianIndices((1:7,)) - r2 = CartesianIndices((4:10,)) - copyto!(x, r1, y, r2) - copyto!(a, r1, b, r2) - @test x == Array(a) - r2 = CartesianIndices((4:11,)) - @test_throws ArgumentError copyto!(a, r1, b, r2) - - x = fill(0f0, (10,)) - y = rand(Float32, (20,)) - a = AT(x) - b = AT(y) - r1 = (1:7,) - r2 = (4:10,) - copyto!(x, r1[1], y, r2[1]) - copyto!(a, r1, b, r2) - @test x == Array(a) - - x = fill(0., (10,)) - y = fill(1, (10,)) - a = AT(x) - b = AT(y) - copyto!(a, b) - @test Float64.(y) == Array(a) - end - - @testset "vcat + hcat" begin - @test compare(vcat, AT, fill(0f0, (10, 10)), rand(Float32, 20, 10)) - @test compare(hcat, AT, fill(0f0, (10, 10)), rand(Float32, 10, 10)) - - @test compare(hcat, AT, rand(Float32, 3, 3), rand(Float32, 3, 3)) - @test compare(vcat, AT, rand(Float32, 3, 3), rand(Float32, 3, 3)) - @test compare((a,b) -> cat(a, b; dims=4), AT, rand(Float32, 3, 4), rand(Float32, 3, 4)) - end - - @testset "reshape" begin - @test compare(reshape, AT, rand(10), Ref((10,))) - @test compare(reshape, AT, rand(10), Ref((10,1))) - @test compare(reshape, AT, rand(10), Ref((1,10))) - - @test reshape(AT(rand(10)), (10,1)) isa AT - @test_throws Exception reshape(AT(rand(10)), (10,2)) - end - - @testset "reinterpret" begin - a = rand(ComplexF32, 22) - A = AT(a) - af0 = reinterpret(Float32, a) - Af0 = reinterpret(Float32, A) - @test Array(Af0) == af0 - a = rand(ComplexF32, 4, 4) - A = AT(a) - @test_throws ArgumentError reinterpret(Int8, A) - - a = rand(ComplexF32, 10 * 10) - A = AT(a) - af0 = reshape(reinterpret(Float32, vec(a)), (20, 10)) - Af0 = reshape(reinterpret(Float32, vec(A)), (20, 10)) - @test Array(Af0) == af0 - end - - @testset "ntuple test" begin - result = AT(Vector{NTuple{3, Float32}}(undef, 1)) - gpu_call(ntuple_test, result, Val(3)) - @test Array(result)[1] == (77, 2*77, 3*77) - x = 88f0 - gpu_call(ntuple_closure, result, Val(3), x) - @test Array(result)[1] == (x, 2*x, 3*x) - end - - @testset "cartesian iteration" begin - Ac = rand(Float32, 32, 32) - A = AT(Ac) - result = fill!(copy(A), 0.0) - gpu_call(cartesian_iter, result, A, size(A)) - Array(result) == Ac - end - - @testset "Custom kernel from Julia function" begin - x = AT(rand(Float32, 100)) - y = AT(rand(Float32, 100)) - gpu_call(clmap!, -, x, y; target=x) - jy = Array(y) - @test map!(-, jy, jy) ≈ Array(x) - end - - @testset "map" begin - @test compare((a, b)-> map(+, a, b), AT, rand(Float32, 10), rand(Float32, 10)) - @test compare((a, b)-> map!(-, a, b), AT, rand(Float32, 10), rand(Float32, 10)) - @test compare((a, b, c, d)-> map!(*, a, b, c, d), AT, rand(Float32, 10), rand(Float32, 10), rand(Float32, 10), rand(Float32, 10)) - end - - @testset "repeat" begin - @test compare(a-> repeat(a, 5, 6), AT, rand(Float32, 10)) - @test compare(a-> repeat(a, 5), AT, rand(Float32, 10)) - @test compare(a-> repeat(a, 5), AT, rand(Float32, 5, 4)) - @test compare(a-> repeat(a, 4, 3), AT, rand(Float32, 10, 15)) - end - - @testset "permutedims" begin - @test compare(x->permutedims(x, [1, 2]), AT, rand(4, 4)) - - inds = rand(1:100, 150, 150) - @test compare(x->permutedims(view(x, inds, :), (3, 2, 1)), AT, rand(100, 100)) - end - - @testset "circshift" begin - @test compare(x->circshift(x, (0,1)), AT, reshape(Vector(1:16), (4,4))) - end +@testsuite "base" AT->begin + @testset "copyto!" begin + x = fill(0f0, (10, 10)) + y = rand(Float32, (20, 10)) + a = AT(x) + b = AT(y) + r1 = CartesianIndices((1:7, 3:8)) + r2 = CartesianIndices((4:10, 3:8)) + copyto!(x, r1, y, r2) + copyto!(a, r1, b, r2) + @test x == Array(a) + r2 = CartesianIndices((4:11, 3:8)) + @test_throws DimensionMismatch copyto!(a, r1, b, r2) + + r2 = CartesianIndices((4:10, 3:8)) + x2 = fill(0f0, (10, 10)) + copyto!(x2, r1, b, r2) + @test x2 == x + + fill!(a, 0f0) + copyto!(a, r1, y, r2) + @test Array(a) == x + + x = fill(0f0, (10,)) + y = rand(Float32, (20,)) + a = AT(x) + b = AT(y) + r1 = CartesianIndices((1:7,)) + r2 = CartesianIndices((4:10,)) + copyto!(x, r1, y, r2) + copyto!(a, r1, b, r2) + @test x == Array(a) + r2 = CartesianIndices((4:11,)) + @test_throws ArgumentError copyto!(a, r1, b, r2) + + x = fill(0f0, (10,)) + y = rand(Float32, (20,)) + a = AT(x) + b = AT(y) + r1 = (1:7,) + r2 = (4:10,) + copyto!(x, r1[1], y, r2[1]) + copyto!(a, r1, b, r2) + @test x == Array(a) + + x = fill(0., (10,)) + y = fill(1, (10,)) + a = AT(x) + b = AT(y) + copyto!(a, b) + @test Float64.(y) == Array(a) + end + + @testset "vcat + hcat" begin + @test compare(vcat, AT, fill(0f0, (10, 10)), rand(Float32, 20, 10)) + @test compare(hcat, AT, fill(0f0, (10, 10)), rand(Float32, 10, 10)) + + @test compare(hcat, AT, rand(Float32, 3, 3), rand(Float32, 3, 3)) + @test compare(vcat, AT, rand(Float32, 3, 3), rand(Float32, 3, 3)) + @test compare((a,b) -> cat(a, b; dims=4), AT, rand(Float32, 3, 4), rand(Float32, 3, 4)) + end + + @testset "reshape" begin + @test compare(reshape, AT, rand(10), Ref((10,))) + @test compare(reshape, AT, rand(10), Ref((10,1))) + @test compare(reshape, AT, rand(10), Ref((1,10))) + + @test reshape(AT(rand(10)), (10,1)) isa AT + @test_throws Exception reshape(AT(rand(10)), (10,2)) + end + + @testset "reinterpret" begin + a = rand(ComplexF32, 22) + A = AT(a) + af0 = reinterpret(Float32, a) + Af0 = reinterpret(Float32, A) + @test Array(Af0) == af0 + a = rand(ComplexF32, 4, 4) + A = AT(a) + @test_throws ArgumentError reinterpret(Int8, A) + + a = rand(ComplexF32, 10 * 10) + A = AT(a) + af0 = reshape(reinterpret(Float32, vec(a)), (20, 10)) + Af0 = reshape(reinterpret(Float32, vec(A)), (20, 10)) + @test Array(Af0) == af0 + end + + @testset "ntuple test" begin + result = AT(Vector{NTuple{3, Float32}}(undef, 1)) + gpu_call(ntuple_test, result, Val(3)) + @test Array(result)[1] == (77, 2*77, 3*77) + x = 88f0 + gpu_call(ntuple_closure, result, Val(3), x) + @test Array(result)[1] == (x, 2*x, 3*x) + end + + @testset "cartesian iteration" begin + Ac = rand(Float32, 32, 32) + A = AT(Ac) + result = fill!(copy(A), 0.0) + gpu_call(cartesian_iter, result, A, size(A)) + Array(result) == Ac + end + + @testset "Custom kernel from Julia function" begin + x = AT(rand(Float32, 100)) + y = AT(rand(Float32, 100)) + gpu_call(clmap!, -, x, y; target=x) + jy = Array(y) + @test map!(-, jy, jy) ≈ Array(x) + end + + @testset "map" begin + @test compare((a, b)-> map(+, a, b), AT, rand(Float32, 10), rand(Float32, 10)) + @test compare((a, b)-> map!(-, a, b), AT, rand(Float32, 10), rand(Float32, 10)) + @test compare((a, b, c, d)-> map!(*, a, b, c, d), AT, rand(Float32, 10), rand(Float32, 10), rand(Float32, 10), rand(Float32, 10)) + end + + @testset "repeat" begin + @test compare(a-> repeat(a, 5, 6), AT, rand(Float32, 10)) + @test compare(a-> repeat(a, 5), AT, rand(Float32, 10)) + @test compare(a-> repeat(a, 5), AT, rand(Float32, 5, 4)) + @test compare(a-> repeat(a, 4, 3), AT, rand(Float32, 10, 15)) + end + + @testset "permutedims" begin + @test compare(x->permutedims(x, [1, 2]), AT, rand(4, 4)) + + inds = rand(1:100, 150, 150) + @test compare(x->permutedims(view(x, inds, :), (3, 2, 1)), AT, rand(100, 100)) + end + + @testset "circshift" begin + @test compare(x->circshift(x, (0,1)), AT, reshape(Vector(1:16), (4,4))) end end diff --git a/test/testsuite/broadcasting.jl b/test/testsuite/broadcasting.jl index 419d1c76..5f21e7bb 100644 --- a/test/testsuite/broadcasting.jl +++ b/test/testsuite/broadcasting.jl @@ -1,8 +1,6 @@ -function test_broadcasting(AT) - @testset "broadcast" begin - broadcasting(AT) - vec3(AT) - end +@testsuite "broadcasting" AT->begin + broadcasting(AT) + vec3(AT) end test_idx(idx, A::AbstractArray{T}) where T = A[idx] * T(2) diff --git a/test/testsuite/construction.jl b/test/testsuite/construction.jl index 19441265..97bc6526 100644 --- a/test/testsuite/construction.jl +++ b/test/testsuite/construction.jl @@ -1,13 +1,4 @@ -function test_construction(AT) - @testset "construction" begin - constructors(AT) - conversion(AT) - value_constructor(AT) - iterator_constructors(AT) - end -end - -function constructors(AT) +@testsuite "constructors" AT->begin @testset "constructors + similar" begin for T in supported_eltypes() B = AT{T}(undef, 10) @@ -101,104 +92,99 @@ function constructors(AT) end end -function conversion(AT) - @testset "conversion" begin - for T in supported_eltypes() - Bc = round.(rand(10, 10) .* 10.0) - B = AT{T}(Bc) - @test size(B) == (10, 10) - @test eltype(B) == T - @test Array(B) ≈ Bc - - Bc = rand(T, 10) - B = AT(Bc) - @test size(B) == (10,) - @test eltype(B) == T - @test Array(B) ≈ Bc - - Bc = rand(T, 10, 10) - B = AT{T, 2}(Bc) - @test size(B) == (10, 10) - @test eltype(B) == T - @test Array(B) ≈ Bc - - Bc = rand(Int32, 3, 3, 3) - B = convert(AT{T, 3}, Bc) - @test size(B) == (3, 3, 3) - @test eltype(B) == T - @test Array(B) ≈ Bc - end +@testsuite "conversions" AT->begin + for T in supported_eltypes() + Bc = round.(rand(10, 10) .* 10.0) + B = AT{T}(Bc) + @test size(B) == (10, 10) + @test eltype(B) == T + @test Array(B) ≈ Bc + + Bc = rand(T, 10) + B = AT(Bc) + @test size(B) == (10,) + @test eltype(B) == T + @test Array(B) ≈ Bc + + Bc = rand(T, 10, 10) + B = AT{T, 2}(Bc) + @test size(B) == (10, 10) + @test eltype(B) == T + @test Array(B) ≈ Bc + + Bc = rand(Int32, 3, 3, 3) + B = convert(AT{T, 3}, Bc) + @test size(B) == (3, 3, 3) + @test eltype(B) == T + @test Array(B) ≈ Bc end end -function value_constructor(AT) - @testset "value constructors" begin - for T in supported_eltypes() - x = fill(zero(T), (2, 2)) - x1 = fill(AT{T}, T(0), (2, 2)) - x2 = fill(AT{T}, T(0), (2, 2)) - x3 = fill(AT{T, 2}, T(0), (2, 2)) - @test Array(x1) ≈ x - @test Array(x2) ≈ x - @test Array(x3) ≈ x - - x = fill(T(1), (2, 2)) - x1 = fill(AT{T}, T(1), (2, 2)) - x2 = fill(AT{T}, T(1), (2, 2)) - x3 = fill(AT{T, 2}, T(1), (2, 2)) - @test Array(x1) ≈ x - @test Array(x2) ≈ x - @test Array(x3) ≈ x - - fill!(x, 0) - - x1 = fill(AT{T}, 0f0, (2, 2)) - x2 = fill(AT{T}, T(0), (2, 2)) - x3 = fill(AT{T, 2}, T(0), (2, 2)) - @test Array(x1) ≈ x - @test Array(x2) ≈ x - @test Array(x3) ≈ x - - fill!(x1, 2f0) - x2 = fill!(AT{Int32}(undef, (4, 4, 4)), 77f0) - @test all(x-> x == 2f0, Array(x1)) - @test all(x-> x == Int32(77), Array(x2)) - - x = Matrix{T}(I, 4, 2) - - x1 = AT{T, 2}(I, 4, 2) - x2 = AT{T}(I, (4, 2)) - x3 = AT{T, 2}(I, (4, 2)) - - @test Array(x1) ≈ x - @test Array(x2) ≈ x - @test Array(x3) ≈ x - - x = Matrix(T(3) * I, 2, 4) - x1 = AT(T(3) * I, 2, 4) - @test eltype(x1) == T - @test Array(x1) ≈ x - - x = fill(T(3), (2, 4)) - x1 = fill(AT{T}, T(3), (2, 4)) - copyto!(x, 2I) - copyto!(x1, 2I) - @test Array(x1) ≈ x - end +@testsuite "value constructors" AT->begin + for T in supported_eltypes() + x = fill(zero(T), (2, 2)) + x1 = fill(AT{T}, T(0), (2, 2)) + x2 = fill(AT{T}, T(0), (2, 2)) + x3 = fill(AT{T, 2}, T(0), (2, 2)) + @test Array(x1) ≈ x + @test Array(x2) ≈ x + @test Array(x3) ≈ x + + x = fill(T(1), (2, 2)) + x1 = fill(AT{T}, T(1), (2, 2)) + x2 = fill(AT{T}, T(1), (2, 2)) + x3 = fill(AT{T, 2}, T(1), (2, 2)) + @test Array(x1) ≈ x + @test Array(x2) ≈ x + @test Array(x3) ≈ x + + fill!(x, 0) + + x1 = fill(AT{T}, 0f0, (2, 2)) + x2 = fill(AT{T}, T(0), (2, 2)) + x3 = fill(AT{T, 2}, T(0), (2, 2)) + @test Array(x1) ≈ x + @test Array(x2) ≈ x + @test Array(x3) ≈ x + + fill!(x1, 2f0) + x2 = fill!(AT{Int32}(undef, (4, 4, 4)), 77f0) + @test all(x-> x == 2f0, Array(x1)) + @test all(x-> x == Int32(77), Array(x2)) + + x = Matrix{T}(I, 4, 2) + + x1 = AT{T, 2}(I, 4, 2) + x2 = AT{T}(I, (4, 2)) + x3 = AT{T, 2}(I, (4, 2)) + + @test Array(x1) ≈ x + @test Array(x2) ≈ x + @test Array(x3) ≈ x + + x = Matrix(T(3) * I, 2, 4) + x1 = AT(T(3) * I, 2, 4) + @test eltype(x1) == T + @test Array(x1) ≈ x + + x = fill(T(3), (2, 4)) + x1 = fill(AT{T}, T(3), (2, 4)) + copyto!(x, 2I) + copyto!(x1, 2I) + @test Array(x1) ≈ x end end -function iterator_constructors(AT) - @testset "iterator constructors" begin - for T in supported_eltypes() - @test AT(Fill(T(0), (10,))) == fill(AT{T}, T(0), (10,)) - @test AT(Fill(T(0), (10, 10))) == fill(AT{T}, T(0), (10, 10)) - if T <: Real - x = AT{Float32}(Fill(T(0), (10, 10))) - @test eltype(x) == Float32 - @test AT(Eye{T}((10))) == AT{T}(I, 10, 10) - x = AT{Float32}(Eye{T}(10)) - @test eltype(x) == Float32 - end + +@testsuite "iterator constructors" AT->begin + for T in supported_eltypes() + @test AT(Fill(T(0), (10,))) == fill(AT{T}, T(0), (10,)) + @test AT(Fill(T(0), (10, 10))) == fill(AT{T}, T(0), (10, 10)) + if T <: Real + x = AT{Float32}(Fill(T(0), (10, 10))) + @test eltype(x) == Float32 + @test AT(Eye{T}((10))) == AT{T}(I, 10, 10) + x = AT{Float32}(Eye{T}(10)) + @test eltype(x) == Float32 end end end diff --git a/test/testsuite/fft.jl b/test/testsuite/fft.jl index 2bcb667d..9074b96f 100644 --- a/test/testsuite/fft.jl +++ b/test/testsuite/fft.jl @@ -1,4 +1,4 @@ -function test_fft(AT) +@testsuite "fft" AT->begin for n = 1:3 @testset "FFT with ND = $n" begin dims = ntuple(i -> 40, n) diff --git a/test/testsuite/gpuinterface.jl b/test/testsuite/gpuinterface.jl index 8baf4ad6..89930622 100644 --- a/test/testsuite/gpuinterface.jl +++ b/test/testsuite/gpuinterface.jl @@ -1,47 +1,45 @@ -function test_gpuinterface(AT) - @testset "parallel execution interface" begin - N = 10 - x = AT(Vector{Int}(undef, N)) - x .= 0 - gpu_call(x) do ctx, x - x[linear_index(ctx)] = 2 - return - end - @test all(x-> x == 2, Array(x)) +@testsuite "interface" AT->begin + N = 10 + x = AT(Vector{Int}(undef, N)) + x .= 0 + gpu_call(x) do ctx, x + x[linear_index(ctx)] = 2 + return + end + @test all(x-> x == 2, Array(x)) - gpu_call(x; total_threads=N) do ctx, x - x[linear_index(ctx)] = 2 - return - end - @test all(x-> x == 2, Array(x)) - gpu_call(x; threads=2, blocks=(N ÷ 2)) do ctx, x - x[linear_index(ctx)] = threadidx(ctx) - return - end - @test Array(x) == [1,2,1,2,1,2,1,2,1,2] + gpu_call(x; total_threads=N) do ctx, x + x[linear_index(ctx)] = 2 + return + end + @test all(x-> x == 2, Array(x)) + gpu_call(x; threads=2, blocks=(N ÷ 2)) do ctx, x + x[linear_index(ctx)] = threadidx(ctx) + return + end + @test Array(x) == [1,2,1,2,1,2,1,2,1,2] - gpu_call(x; threads=2, blocks=(N ÷ 2)) do ctx, x - x[linear_index(ctx)] = blockidx(ctx) - return - end - @test Array(x) == [1, 1, 2, 2, 3, 3, 4, 4, 5, 5] - x2 = AT([0]) - gpu_call(x2; threads=2, blocks=(N ÷ 2), target=x) do ctx, x - x[1] = blockdim(ctx) - return - end - @test Array(x2) == [2] + gpu_call(x; threads=2, blocks=(N ÷ 2)) do ctx, x + x[linear_index(ctx)] = blockidx(ctx) + return + end + @test Array(x) == [1, 1, 2, 2, 3, 3, 4, 4, 5, 5] + x2 = AT([0]) + gpu_call(x2; threads=2, blocks=(N ÷ 2), target=x) do ctx, x + x[1] = blockdim(ctx) + return + end + @test Array(x2) == [2] - gpu_call(x2; threads=2, blocks=(N ÷ 2), target=x) do ctx, x - x[1] = griddim(ctx) - return - end - @test Array(x2) == [5] + gpu_call(x2; threads=2, blocks=(N ÷ 2), target=x) do ctx, x + x[1] = griddim(ctx) + return + end + @test Array(x2) == [5] - gpu_call(x2; threads=2, blocks=(N ÷ 2), target=x) do ctx, x - x[1] = global_size(ctx) - return - end - @test Array(x2) == [10] + gpu_call(x2; threads=2, blocks=(N ÷ 2), target=x) do ctx, x + x[1] = global_size(ctx) + return end + @test Array(x2) == [10] end diff --git a/test/testsuite/indexing.jl b/test/testsuite/indexing.jl index dac4c5d4..92904e21 100644 --- a/test/testsuite/indexing.jl +++ b/test/testsuite/indexing.jl @@ -1,135 +1,133 @@ -function test_indexing(AT) - @testset "indexing" begin - @allowscalar @testset "errors and warnings" begin - x = AT([0]) - - allowscalar(true, false) - x[1] = 1 - @test x[1] == 1 - - @disallowscalar begin - @test_throws ErrorException x[1] - @test_throws ErrorException x[1] = 1 - end +@testsuite "indexing" AT->begin + @allowscalar @testset "errors and warnings" begin + x = AT([0]) - x[1] = 2 - @test x[1] == 2 + allowscalar(true, false) + x[1] = 1 + @test x[1] == 1 - allowscalar(false) + @disallowscalar begin @test_throws ErrorException x[1] @test_throws ErrorException x[1] = 1 + end - @allowscalar begin - x[1] = 3 - @test x[1] == 3 - end + x[1] = 2 + @test x[1] == 2 - allowscalar() do - x[1] = 4 - @test x[1] == 4 - end + allowscalar(false) + @test_throws ErrorException x[1] + @test_throws ErrorException x[1] = 1 - @test_throws ErrorException x[1] - @test_throws ErrorException x[1] = 1 + @allowscalar begin + x[1] = 3 + @test x[1] == 3 + end - allowscalar(true, false) - x[1] + allowscalar() do + x[1] = 4 + @test x[1] == 4 + end - allowscalar(true, true) - @test_logs (:warn, r"Performing scalar operations on GPU arrays: .*") x[1] - @test_logs x[1] + @test_throws ErrorException x[1] + @test_throws ErrorException x[1] = 1 - # NOTE: this inner testset _needs_ to be wrapped with allowscalar - # to make sure its original value is restored. - end + allowscalar(true, false) + x[1] - @allowscalar for T in (Float32, Int32) - @testset "Indexing with $T" begin - x = rand(T, 32) - src = AT(x) - for (i, xi) in enumerate(x) - @test src[i] == xi - end - @test Array(src[1:3]) == x[1:3] - @test Array(src[3:end]) == x[3:end] - end - @testset "multi dim, sliced setindex" begin - x = fill(AT{T}, T(0), (10, 10, 10, 10)) - y = AT{T}(undef, 5, 5, 10, 10) - rand!(y) - x[2:6, 2:6, :, :] = y - x[2:6, 2:6, :, :] == y - end - @testset "multi dim, sliced setindex, CPU source" begin - x = fill(AT{T}, T(0), (2,3,4)) - y = Array{T}(undef, 2,3) - rand!(y) - x[:, :, 2] = y - x[:, :, 2] == y + allowscalar(true, true) + @test_logs (:warn, r"Performing scalar operations on GPU arrays: .*") x[1] + @test_logs x[1] + + # NOTE: this inner testset _needs_ to be wrapped with allowscalar + # to make sure its original value is restored. + end + + @allowscalar for T in (Float32, Int32) + @testset "Indexing with $T" begin + x = rand(T, 32) + src = AT(x) + for (i, xi) in enumerate(x) + @test src[i] == xi end + @test Array(src[1:3]) == x[1:3] + @test Array(src[3:end]) == x[3:end] end + @testset "multi dim, sliced setindex" begin + x = fill(AT{T}, T(0), (10, 10, 10, 10)) + y = AT{T}(undef, 5, 5, 10, 10) + rand!(y) + x[2:6, 2:6, :, :] = y + x[2:6, 2:6, :, :] == y + end + @testset "multi dim, sliced setindex, CPU source" begin + x = fill(AT{T}, T(0), (2,3,4)) + y = Array{T}(undef, 2,3) + rand!(y) + x[:, :, 2] = y + x[:, :, 2] == y + end + end - @allowscalar for T in (Float32, Int32) - @testset "Indexing with $T" begin - x = fill(zero(T), 7) - src = AT(x) - for i = 1:7 - src[i] = i - end - @test Array(src) == T[1:7;] - src[1:3] = T[77, 22, 11] - @test Array(src[1:3]) == T[77, 22, 11] - src[1] = T(0) - src[2:end] = T(77) - @test Array(src) == T[0, 77, 77, 77, 77, 77, 77] + @allowscalar for T in (Float32, Int32) + @testset "Indexing with $T" begin + x = fill(zero(T), 7) + src = AT(x) + for i = 1:7 + src[i] = i end + @test Array(src) == T[1:7;] + src[1:3] = T[77, 22, 11] + @test Array(src[1:3]) == T[77, 22, 11] + src[1] = T(0) + src[2:end] = T(77) + @test Array(src) == T[0, 77, 77, 77, 77, 77, 77] end + end - @allowscalar for T in (Float32, Int32) - @testset "issue #42 with $T" begin - Ac = rand(Float32, 2, 2) - A = AT(Ac) - @test A[1] == Ac[1] - @test A[end] == Ac[end] - @test A[1, 1] == Ac[1, 1] - end + @allowscalar for T in (Float32, Int32) + @testset "issue #42 with $T" begin + Ac = rand(Float32, 2, 2) + A = AT(Ac) + @test A[1] == Ac[1] + @test A[end] == Ac[end] + @test A[1, 1] == Ac[1, 1] end - @allowscalar for T in (Float32, Int32) - @testset "Colon() $T" begin - Ac = rand(T, 10) - A = AT(Ac) - A[:] = T(1) - @test all(x-> x == 1, A) - A[:] = AT(Ac) - @test Array(A) == Ac - end + end + @allowscalar for T in (Float32, Int32) + @testset "Colon() $T" begin + Ac = rand(T, 10) + A = AT(Ac) + A[:] = T(1) + @test all(x-> x == 1, A) + A[:] = AT(Ac) + @test Array(A) == Ac end + end - @allowscalar @testset "get/setindex!" begin - # literal calls to get/setindex! have different return types - @test compare(x->getindex(x,1), AT, zeros(Int, 2)) - @test compare(x->setindex!(x,1,1), AT, zeros(Int, 2)) - end + @allowscalar @testset "get/setindex!" begin + # literal calls to get/setindex! have different return types + @test compare(x->getindex(x,1), AT, zeros(Int, 2)) + @test compare(x->setindex!(x,1,1), AT, zeros(Int, 2)) + end - @allowscalar @testset "Index with empty array" begin + @allowscalar @testset "Index with empty array" begin - @testset "1D" begin - Ac = zeros(Float32, 10) - A = AT(Ac) - @test typeof(A[[]]) == typeof(AT(Ac[[]])) - @test size(A[[]]) == size(Ac[[]]) - end + @testset "1D" begin + Ac = zeros(Float32, 10) + A = AT(Ac) + @test typeof(A[[]]) == typeof(AT(Ac[[]])) + @test size(A[[]]) == size(Ac[[]]) + end - @testset "2D with other index $other" for other in (Colon(), 1:5, 5) - Ac = zeros(Float32, 10, 10) - A = AT(Ac) + @testset "2D with other index $other" for other in (Colon(), 1:5, 5) + Ac = zeros(Float32, 10, 10) + A = AT(Ac) - @test typeof(A[[], other]) == typeof(AT(Ac[[], other])) - @test size(A[[], other]) == size(Ac[[], other]) + @test typeof(A[[], other]) == typeof(AT(Ac[[], other])) + @test size(A[[], other]) == size(Ac[[], other]) - @test typeof(A[other, []]) == typeof(AT(Ac[other, []])) - @test size(A[other, []]) == size(Ac[other, []]) - end + @test typeof(A[other, []]) == typeof(AT(Ac[other, []])) + @test size(A[other, []]) == size(Ac[other, []]) end end end diff --git a/test/testsuite/io.jl b/test/testsuite/io.jl index bec2d20a..6ebe775d 100644 --- a/test/testsuite/io.jl +++ b/test/testsuite/io.jl @@ -1,36 +1,34 @@ -function test_io(AT) - @testset "input/output" begin - @testset "showing" begin - io = IOBuffer() - A = AT(Int64[1]) - B = AT(Int64[1 2;3 4]) # vectors and non-vector arrays showing - # are handled differently in base/arrayshow.jl +@testsuite "input output" AT->begin + @testset "showing" begin + io = IOBuffer() + A = AT(Int64[1]) + B = AT(Int64[1 2;3 4]) # vectors and non-vector arrays showing + # are handled differently in base/arrayshow.jl - show(io, MIME("text/plain"), A) - seekstart(io) - @test occursin(Regex("^1-element $AT{Int64,1.*}:\n 1\$"), String(take!(io))) + show(io, MIME("text/plain"), A) + seekstart(io) + @test occursin(Regex("^1-element $AT{Int64,1.*}:\n 1\$"), String(take!(io))) - show(io, A) - seekstart(io) - msg = String(take!(io)) # result of e.g. `print` differs on 32bit and 64bit machines - # due to different definition of `Int` type - # print([1]) shows as [1] on 64bit but Int64[1] on 32bit - @test msg == "[1]" || msg == "Int64[1]" + show(io, A) + seekstart(io) + msg = String(take!(io)) # result of e.g. `print` differs on 32bit and 64bit machines + # due to different definition of `Int` type + # print([1]) shows as [1] on 64bit but Int64[1] on 32bit + @test msg == "[1]" || msg == "Int64[1]" - show(io, MIME("text/plain"), B) - seekstart(io) - @test occursin(Regex("^2×2 $AT{Int64,2.*}:\n 1 2\n 3 4\$"), String(take!(io))) + show(io, MIME("text/plain"), B) + seekstart(io) + @test occursin(Regex("^2×2 $AT{Int64,2.*}:\n 1 2\n 3 4\$"), String(take!(io))) - show(io, B) - seekstart(io) - msg = String(take!(io)) - @test msg == "[1 2; 3 4]" || msg == "Int64[1 2; 3 4]" + show(io, B) + seekstart(io) + msg = String(take!(io)) + @test msg == "[1 2; 3 4]" || msg == "Int64[1 2; 3 4]" - show(io, MIME("text/plain"), A') - seekstart(io) - msg = String(take!(io)) # the printing of Adjoint depends on global state - @test occursin(Regex("^1×1 Adjoint{Int64,$AT{Int64,1.*}}:\n 1\$"), msg) || - occursin(Regex("^1×1 LinearAlgebra.Adjoint{Int64,$AT{Int64,1.*}}:\n 1\$"), msg) - end + show(io, MIME("text/plain"), A') + seekstart(io) + msg = String(take!(io)) # the printing of Adjoint depends on global state + @test occursin(Regex("^1×1 Adjoint{Int64,$AT{Int64,1.*}}:\n 1\$"), msg) || + occursin(Regex("^1×1 LinearAlgebra.Adjoint{Int64,$AT{Int64,1.*}}:\n 1\$"), msg) end end diff --git a/test/testsuite/linalg.jl b/test/testsuite/linalg.jl index c5a64d2d..55e9e071 100644 --- a/test/testsuite/linalg.jl +++ b/test/testsuite/linalg.jl @@ -1,119 +1,117 @@ -function test_linalg(AT) - @testset "linear algebra" 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)) - @test compare(transpose, AT, rand(Float32, 32, 32)) - @test compare(transpose!, AT, rand(Float32, 32, 32), rand(Float32, 32, 32)) - @test compare((x,y)->copyto!(x, adjoint(y)), AT, rand(Float32, 32, 32), rand(Float32, 32, 32)) - @test compare((x,y)->copyto!(x, transpose(y)), AT, rand(Float32, 32, 32), rand(Float32, 32, 32)) - @test compare(transpose!, AT, Array{Float32}(undef, 32, 32), rand(Float32, 32, 32)) - @test compare(transpose!, AT, Array{Float32}(undef, 128, 32), rand(Float32, 32, 128)) - end +@testsuite "linear algebra" AT->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)) + @test compare(transpose, AT, rand(Float32, 32, 32)) + @test compare(transpose!, AT, rand(Float32, 32, 32), rand(Float32, 32, 32)) + @test compare((x,y)->copyto!(x, adjoint(y)), AT, rand(Float32, 32, 32), rand(Float32, 32, 32)) + @test compare((x,y)->copyto!(x, transpose(y)), AT, rand(Float32, 32, 32), rand(Float32, 32, 32)) + @test compare(transpose!, AT, Array{Float32}(undef, 32, 32), rand(Float32, 32, 32)) + @test compare(transpose!, AT, Array{Float32}(undef, 128, 32), rand(Float32, 32, 128)) + end - @testset "copytri!" begin - @testset for uplo in ('U', 'L') - @test compare(x -> LinearAlgebra.copytri!(x, uplo), AT, rand(Float32, 128, 128)) - end + @testset "copytri!" begin + @testset for uplo in ('U', 'L') + @test compare(x -> LinearAlgebra.copytri!(x, uplo), AT, rand(Float32, 128, 128)) end + end + + @testset "copyto! for triangular" begin + for TR in (UpperTriangular, LowerTriangular) + @test compare(transpose!, AT, Array{Float32}(undef, 128, 32), rand(Float32, 32, 128)) - @testset "copyto! for triangular" begin - for TR in (UpperTriangular, LowerTriangular) - @test compare(transpose!, AT, Array{Float32}(undef, 128, 32), rand(Float32, 32, 128)) - - cpu_a = Array{Float32}(undef, 128, 128) - gpu_a = AT{Float32}(undef, 128, 128) - gpu_b = AT{Float32}(undef, 128, 128) - - rand!(gpu_a) - copyto!(cpu_a, TR(gpu_a)) - @test cpu_a == Array(collect(TR(gpu_a))) - - rand!(gpu_a) - gpu_c = copyto!(gpu_b, TR(gpu_a)) - @test all(gpu_b .== TR(gpu_a)) - @test gpu_c isa AT - end - - for TR in (UpperTriangular, LowerTriangular, UnitUpperTriangular, UnitLowerTriangular) - gpu_a = AT{Float32}(undef, 128, 128) |> rand! |> TR - gpu_b = AT{Float32}(undef, 128, 128) |> TR - - gpu_c = copyto!(gpu_b, gpu_a) - @test all(gpu_b .== gpu_a) - @test all(gpu_c .== gpu_a) - @test gpu_c isa TR - end + cpu_a = Array{Float32}(undef, 128, 128) + gpu_a = AT{Float32}(undef, 128, 128) + gpu_b = AT{Float32}(undef, 128, 128) + + rand!(gpu_a) + copyto!(cpu_a, TR(gpu_a)) + @test cpu_a == Array(collect(TR(gpu_a))) + + rand!(gpu_a) + gpu_c = copyto!(gpu_b, TR(gpu_a)) + @test all(gpu_b .== TR(gpu_a)) + @test gpu_c isa AT end @testset "inv for triangular" for TR in (UpperTriangular, LowerTriangular, UnitUpperTriangular, UnitLowerTriangular) @test compare(x -> inv(TR(x)), AT, rand(Float32, 32, 32)) end - @testset "permutedims" begin - @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(ComplexF64,3,4,5,1)) - end + for TR in (UpperTriangular, LowerTriangular, UnitUpperTriangular, UnitLowerTriangular) + gpu_a = AT{Float32}(undef, 128, 128) |> rand! |> TR + gpu_b = AT{Float32}(undef, 128, 128) |> TR - @testset "issymmetric/ishermitian" begin - n = 128 - areal = randn(n,n)/2 - aimg = randn(n,n)/2 - - @testset for eltya in (Float32, Float64, ComplexF32, ComplexF64) - a = convert(Matrix{eltya}, eltya <: Complex ? complex.(areal, aimg) : areal) - asym = transpose(a) + a # symmetric indefinite - aherm = a' + a # Hermitian indefinite - @test issymmetric(asym) - @test ishermitian(aherm) - end - end - @testset "Array + Diagonal" begin - n = 128 - A = AT{Float32}(undef, n, n) - d = AT{Float32}(undef, n) - rand!(A) - rand!(d) - D = Diagonal(d) - B = A + D - @test collect(B) ≈ collect(A) + collect(D) + gpu_c = copyto!(gpu_b, gpu_a) + @test all(gpu_b .== gpu_a) + @test all(gpu_c .== gpu_a) + @test gpu_c isa TR end + end + + @testset "permutedims" begin + @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(ComplexF64,3,4,5,1)) + end - @testset "$f! with diagonal $d" for (f, f!) in ((triu, triu!), (tril, tril!)), - d in -2:2 - A = randn(10, 10) - @test f(A, d) == Array(f!(AT(A), d)) + @testset "issymmetric/ishermitian" begin + n = 128 + areal = randn(n,n)/2 + aimg = randn(n,n)/2 + + @testset for eltya in (Float32, Float64, ComplexF32, ComplexF64) + a = convert(Matrix{eltya}, eltya <: Complex ? complex.(areal, aimg) : areal) + asym = transpose(a) + a # symmetric indefinite + aherm = a' + a # Hermitian indefinite + @test issymmetric(asym) + @test ishermitian(aherm) end + end + @testset "Array + Diagonal" begin + n = 128 + A = AT{Float32}(undef, n, n) + d = AT{Float32}(undef, n) + rand!(A) + rand!(d) + D = Diagonal(d) + B = A + D + @test collect(B) ≈ collect(A) + collect(D) + end - @testset "$T gemv y := $f(A) * x * a + y * b" for f in (identity, transpose, adjoint), T in supported_eltypes() - y, A, x = rand(T, 4), rand(T, 4, 4), rand(T, 4) + @testset "$f! with diagonal $d" for (f, f!) in ((triu, triu!), (tril, tril!)), + d in -2:2 + A = randn(10, 10) + @test f(A, d) == Array(f!(AT(A), d)) + end - # workaround for https://github.com/JuliaLang/julia/issues/35163#issue-584248084 - T <: Integer && (y .%= T(10); A .%= T(10); x .%= T(10)) - - @test compare(*, AT, f(A), x) - @test compare(mul!, AT, y, f(A), x) - @test compare(mul!, AT, y, f(A), x, Ref(T(4)), Ref(T(5))) - @test typeof(AT(rand(3, 3)) * AT(rand(3))) <: AbstractVector - end + @testset "$T gemv y := $f(A) * x * a + y * b" for f in (identity, transpose, adjoint), T in supported_eltypes() + y, A, x = rand(T, 4), rand(T, 4, 4), rand(T, 4) - @testset "$T gemm C := $f(A) * $g(B) * a + C * b" for f in (identity, transpose, adjoint), g in (identity, transpose, adjoint), T in supported_eltypes() - A, B, C = rand(T, 4, 4), rand(T, 4, 4), rand(T, 4, 4) + # workaround for https://github.com/JuliaLang/julia/issues/35163#issue-584248084 + T <: Integer && (y .%= T(10); A .%= T(10); x .%= T(10)) - # workaround for https://github.com/JuliaLang/julia/issues/35163#issue-584248084 - T <: Integer && (A .%= T(10); B .%= T(10); C .%= T(10)) - - @test compare(*, AT, f(A), g(B)) - @test compare(mul!, AT, C, f(A), g(B)) - @test compare(mul!, AT, C, f(A), g(B), Ref(T(4)), Ref(T(5))) - @test typeof(AT(rand(3, 3)) * AT(rand(3, 3))) <: AbstractMatrix - end + @test compare(*, AT, f(A), x) + @test compare(mul!, AT, y, f(A), x) + @test compare(mul!, AT, y, f(A), x, Ref(T(4)), Ref(T(5))) + @test typeof(AT(rand(3, 3)) * AT(rand(3))) <: AbstractVector + end - @testset "lmul! and rmul!" for (a,b) in [((3,4),(4,3)), ((3,), (1,3)), ((1,3), (3))], T in supported_eltypes() - @test compare(rmul!, AT, rand(T, a), Ref(rand(T))) - @test compare(lmul!, AT, Ref(rand(T)), rand(T, b)) - end + @testset "$T gemm C := $f(A) * $g(B) * a + C * b" for f in (identity, transpose, adjoint), g in (identity, transpose, adjoint), T in supported_eltypes() + A, B, C = rand(T, 4, 4), rand(T, 4, 4), rand(T, 4, 4) + + # workaround for https://github.com/JuliaLang/julia/issues/35163#issue-584248084 + T <: Integer && (A .%= T(10); B .%= T(10); C .%= T(10)) + + @test compare(*, AT, f(A), g(B)) + @test compare(mul!, AT, C, f(A), g(B)) + @test compare(mul!, AT, C, f(A), g(B), Ref(T(4)), Ref(T(5))) + @test typeof(AT(rand(3, 3)) * AT(rand(3, 3))) <: AbstractMatrix + end + + @testset "lmul! and rmul!" for (a,b) in [((3,4),(4,3)), ((3,), (1,3)), ((1,3), (3))], T in supported_eltypes() + @test compare(rmul!, AT, rand(T, a), Ref(rand(T))) + @test compare(lmul!, AT, Ref(rand(T)), rand(T, b)) end end diff --git a/test/testsuite/mapreduce.jl b/test/testsuite/mapreduce.jl index 47615e5c..7add8d8b 100644 --- a/test/testsuite/mapreduce.jl +++ b/test/testsuite/mapreduce.jl @@ -1,4 +1,4 @@ -function test_mapreduce(AT) +@testsuite "mapreduce essentials" AT->begin @testset "mapreducedim! $ET" for ET in supported_eltypes() begin T = AT{ET} range = ET <: Real ? (ET(1):ET(10)) : ET @@ -50,7 +50,9 @@ function test_mapreduce(AT) end end end +end +@testsuite "mapreduce derivatives" AT->begin @testset "sum prod minimum maximum $ET" for ET in supported_eltypes() begin T = AT{ET} range = ET <: Real ? (ET(1):ET(10)) : ET @@ -114,7 +116,9 @@ function test_mapreduce(AT) @test A != B end end +end +@testsuite "mapreduce (old tests)" AT->begin # old tests: can be removed, but left in here for a while to ensure the new impl works @testset "mapreduce" begin for ET in supported_eltypes() diff --git a/test/testsuite/math.jl b/test/testsuite/math.jl index 1b1104c9..edf72780 100644 --- a/test/testsuite/math.jl +++ b/test/testsuite/math.jl @@ -1,18 +1,16 @@ -function test_math(AT) - @testset "math functionality" begin - for ET in supported_eltypes() - # Skip complex numbers - ET in (Complex, ComplexF32, ComplexF64) && continue +@testsuite "math" AT->begin + for ET in supported_eltypes() + # Skip complex numbers + ET in (Complex, ComplexF32, ComplexF64) && continue - T = AT{ET} - @testset "$ET" begin - range = ET <: Integer ? (ET(-2):ET(2)) : ET - low = ET(-1) - high = ET(1) - @testset "clamp!" begin - for N in (2, 10) - @test compare(x -> clamp!(x, low, high), AT, rand(range, N, N)) - end + T = AT{ET} + @testset "$ET" begin + range = ET <: Integer ? (ET(-2):ET(2)) : ET + low = ET(-1) + high = ET(1) + @testset "clamp!" begin + for N in (2, 10) + @test compare(x -> clamp!(x, low, high), AT, rand(range, N, N)) end end end diff --git a/test/testsuite/random.jl b/test/testsuite/random.jl index 53e4884d..ddd5c649 100644 --- a/test/testsuite/random.jl +++ b/test/testsuite/random.jl @@ -1,23 +1,21 @@ -function test_random(AT) - @testset "Random" begin - @testset "rand" begin # uniform - for T in (Float32, Float64, Int64, Int32, - Complex{Float32}, Complex{Float64}, - Complex{Int64}, Complex{Int32}), d in (2, (2,2)) - A = AT{T}(undef, d) - B = copy(A) - rand!(A) - rand!(B) - @test !any(A .== B) +@testsuite "random" AT->begin + @testset "rand" begin # uniform + for T in (Float32, Float64, Int64, Int32, + Complex{Float32}, Complex{Float64}, + Complex{Int64}, Complex{Int32}), d in (2, (2,2)) + A = AT{T}(undef, d) + B = copy(A) + rand!(A) + rand!(B) + @test !any(A .== B) - rng = GPUArrays.global_rng(A) - Random.seed!(rng) - Random.seed!(rng, 1) - rand!(rng, A) - Random.seed!(rng, 1) - rand!(rng, B) - @test all(A .== B) - end + rng = GPUArrays.global_rng(A) + Random.seed!(rng) + Random.seed!(rng, 1) + rand!(rng, A) + Random.seed!(rng, 1) + rand!(rng, B) + @test all(A .== B) end end end diff --git a/test/testsuite/uniformscaling.jl b/test/testsuite/uniformscaling.jl index b35a8b38..61793fbc 100644 --- a/test/testsuite/uniformscaling.jl +++ b/test/testsuite/uniformscaling.jl @@ -1,5 +1,4 @@ -function test_uniformscaling(AT) - +@testsuite "uniformscaling" AT->begin eltypes = (ComplexF32, Float32) wrappers = (identity, UnitLowerTriangular, UnitUpperTriangular, LowerTriangular, UpperTriangular, Hermitian, Symmetric) diff --git a/test/testsuite/vector.jl b/test/testsuite/vector.jl index e42133d6..c5f8bf40 100644 --- a/test/testsuite/vector.jl +++ b/test/testsuite/vector.jl @@ -1,33 +1,31 @@ -function test_vectors(AT) - @testset "vector interface" begin - a = Float32[] - x = AT(a) - @test length(x) == 0 - push!(x, 12f0) - @test length(x) == 1 - @test x[1] == 12f0 +@testsuite "vectors" AT->begin + a = Float32[] + x = AT(a) + @test length(x) == 0 + push!(x, 12f0) + @test length(x) == 1 + @test x[1] == 12f0 - a = Float32[0] - x = AT(a) - @test length(x) == 1 - @test length(GPUArrays.buffer(x)) == 1 - push!(x, 12) - @test length(GPUArrays.buffer(x)) == GPUArrays.grow_dimensions(0, 1, 1) - resize!(x, 5) - @test length(x) == 5 - @test length(GPUArrays.buffer(x)) == 5 + a = Float32[0] + x = AT(a) + @test length(x) == 1 + @test length(GPUArrays.buffer(x)) == 1 + push!(x, 12) + @test length(GPUArrays.buffer(x)) == GPUArrays.grow_dimensions(0, 1, 1) + resize!(x, 5) + @test length(x) == 5 + @test length(GPUArrays.buffer(x)) == 5 - resize!(x, 3) - @test length(x) == 3 - # we don't shrink buffers yet... TODO shrink them... or should we? - @test length(GPUArrays.buffer(x)) == 5 + resize!(x, 3) + @test length(x) == 3 + # we don't shrink buffers yet... TODO shrink them... or should we? + @test length(GPUArrays.buffer(x)) == 5 - x = AT(Array{Float32}(undef, 16)) - reshape!(x, (2, 2, 2, 2)) - @test size(x) == (2, 2, 2, 2) - x = AT(Array{Float32}(undef, 16)) - y = AT(rand(Float32, 32)) - update!(x, y) - @test size(x) == (32,) - end + x = AT(Array{Float32}(undef, 16)) + reshape!(x, (2, 2, 2, 2)) + @test size(x) == (2, 2, 2, 2) + x = AT(Array{Float32}(undef, 16)) + y = AT(rand(Float32, 32)) + update!(x, y) + @test size(x) == (32,) end