Skip to content

Commit 4e02346

Browse files
committed
Simplify adapt calls when showing arrays.
1 parent 7f8410a commit 4e02346

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

src/host/abstractarray.jl

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,30 +39,26 @@ function Serialization.deserialize(s::AbstractSerializer, ::Type{T}) where T <:
3939
T(A)
4040
end
4141

42-
## convert to CPU (keeping wrapper type)
42+
## showing
4343

4444
struct ToArray end
45-
46-
Adapt.adapt_storage(::ToArray, xs::AbstractArray) = convert(Array, xs)
47-
convert_to_cpu(xs) = adapt(ToArray(), xs)
48-
49-
## showing
45+
Adapt.adapt_storage(::ToArray, xs::AbstractGPUArray) = convert(Array, xs)
5046

5147
# display
5248
Base.print_array(io::IO, X::AnyGPUArray) =
53-
Base.print_array(io, convert_to_cpu(X))
49+
Base.print_array(io, adapt(ToArray(), X))
5450

5551
# show
5652
Base._show_nonempty(io::IO, X::AnyGPUArray, prefix::String) =
57-
Base._show_nonempty(io, convert_to_cpu(X), prefix)
53+
Base._show_nonempty(io, adapt(ToArray(), X), prefix)
5854
Base._show_empty(io::IO, X::AnyGPUArray) =
59-
Base._show_empty(io, convert_to_cpu(X))
55+
Base._show_empty(io, adapt(ToArray(), X))
6056
Base.show_vector(io::IO, v::AnyGPUArray, args...) =
61-
Base.show_vector(io, convert_to_cpu(v), args...)
57+
Base.show_vector(io, adapt(ToArray(), v), args...)
6258

6359
## collect to CPU (discarding wrapper type)
6460

65-
collect_to_cpu(xs::AbstractArray) = collect(convert_to_cpu(xs))
61+
collect_to_cpu(xs::AbstractArray) = collect(adapt(ToArray(), xs))
6662
Base.collect(X::AnyGPUArray) = collect_to_cpu(X)
6763

6864

0 commit comments

Comments
 (0)