@@ -50,23 +50,36 @@ function to_cartesian(A, indices::Tuple)
50
50
CartesianIndices (start, stop)
51
51
end
52
52
53
- # # showing
53
+ # # convert to CPU (keeping wrapper type)
54
54
55
55
Adapt. adapt_storage (:: Type{<:Array} , xs:: AbstractArray ) = convert (Array, xs)
56
- cpu (xs) = adapt (Array, xs)
56
+ convert_to_cpu (xs) = adapt (Array, xs)
57
+
58
+ # # showing
57
59
58
60
for (W, ctor) in (:AT => (A,mut)-> mut (A), Adapt. wrappers... )
59
61
@eval begin
60
62
# display
61
- Base. print_array (io:: IO , X:: $W where {AT <: GPUArray }) = Base. print_array (io, $ ctor (X, cpu))
63
+ Base. print_array (io:: IO , X:: $W where {AT <: GPUArray }) =
64
+ Base. print_array (io, $ ctor (X, convert_to_cpu))
62
65
63
66
# show
64
67
Base. _show_nonempty (io:: IO , X:: $W where {AT <: GPUArray }, prefix:: String ) =
65
- Base. _show_nonempty (io, $ ctor (X, cpu ), prefix)
68
+ Base. _show_nonempty (io, $ ctor (X, convert_to_cpu ), prefix)
66
69
Base. _show_empty (io:: IO , X:: $W where {AT <: GPUArray }) =
67
- Base. _show_empty (io, $ ctor (X, cpu ))
70
+ Base. _show_empty (io, $ ctor (X, convert_to_cpu ))
68
71
Base. show_vector (io:: IO , v:: $W where {AT <: GPUArray }, args... ) =
69
- Base. show_vector (io, $ ctor (v, cpu), args... )
72
+ Base. show_vector (io, $ ctor (v, convert_to_cpu), args... )
73
+ end
74
+ end
75
+
76
+ # # collect to CPU (discarding wrapper type)
77
+
78
+ collect_to_cpu (xs:: AbstractArray ) = collect (convert_to_cpu (xs))
79
+
80
+ for (W, ctor) in (:AT => (A,mut)-> mut (A), Adapt. wrappers... )
81
+ @eval begin
82
+ Base. collect (X:: $W where {AT <: GPUArray }) = collect_to_cpu (X)
70
83
end
71
84
end
72
85
0 commit comments