diff --git a/src/host/abstractarray.jl b/src/host/abstractarray.jl index 0c3e9910..d9e5ff9b 100644 --- a/src/host/abstractarray.jl +++ b/src/host/abstractarray.jl @@ -142,12 +142,21 @@ Base.print_array(io::IO, @nospecialize(X::AnyGPUArray)) = Base.print_array(io, adapt(ToArray(), X)) # show -Base._show_nonempty(io::IO, @nospecialize(X::AnyGPUArray), prefix::String) = +function Base._show_nonempty(io::IO, @nospecialize(X::AnyGPUArray), prefix::String) + print(io, typeof(X).name.name, "(") Base._show_nonempty(io, adapt(ToArray(), X), prefix) -Base._show_empty(io::IO, @nospecialize(X::AnyGPUArray)) = + print(io, ")") +end +function Base._show_empty(io::IO, @nospecialize(X::AnyGPUArray)) + print(io, typeof(X).name.name, "(") Base._show_empty(io, adapt(ToArray(), X)) -Base.show_vector(io::IO, @nospecialize(v::AnyGPUArray), args...) = + print(io, ")") +end +function Base.show_vector(io::IO, @nospecialize(v::AnyGPUArray), args...) + print(io, typeof(v).name.name, "(") Base.show_vector(io, adapt(ToArray(), v), args...) + print(io, ")") +end ## collect to CPU (discarding wrapper type) diff --git a/test/testsuite/base.jl b/test/testsuite/base.jl index a4367ceb..daceffc9 100644 --- a/test/testsuite/base.jl +++ b/test/testsuite/base.jl @@ -367,13 +367,13 @@ end # due to different definition of `Int` type # print([1]) shows as [1] on 64bit but Int64[1] on 32bit msg = showstr(A) - @test msg == "[1]" || msg == "Int64[1]" + AT != Array && @test occursin("([1])", msg) || occursin("(Int64[1])", msg) msg = replstr(B) @test occursin(Regex("^2×2 $AT{Int64,\\s?2.*}:\n 1 2\n 3 4\$"), msg) msg = showstr(B) - @test msg == "[1 2; 3 4]" || msg == "Int64[1 2; 3 4]" + AT != Array && @test occursin("([1 2; 3 4])", msg) || occursin("(Int64[1 2; 3 4])", msg) # the printing of Adjoint depends on global state msg = replstr(A') @@ -406,7 +406,7 @@ end @testset "selectdim" begin @test compare(x -> selectdim(x, 3, 1), AT, rand(Float32, 2, 2, 2)) let x = AT(rand(Float32, 5, 4, 3)) - @test typeof(selectdim(x, 3, 1)) == typeof(view(x, :, :, 1)) + @test typeof(selectdim(x, 3, 1)) == typeof(view(x, :, :, 1)) @test typeof(selectdim(x, 2, 1)) == typeof(view(x, :, 1, :)) end end