Skip to content

Commit 910b5e1

Browse files
authored
Follow Array's behavior when initializing (#1800)
Initializing an `Array` with an `Array` creates a copy of the array. This change implements the same behavior for `CuArray`.
1 parent 940d23d commit 910b5e1

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/array.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,9 @@ CuArray{T}(xs::AbstractArray{S,N}) where {T,N,S} = CuArray{T,N}(xs)
355355
(::Type{CuArray{T,N} where T})(x::AbstractArray{S,N}) where {S,N} = CuArray{S,N}(x)
356356
CuArray(A::AbstractArray{T,N}) where {T,N} = CuArray{T,N}(A)
357357

358-
# idempotency
359-
CuArray{T,N,B}(xs::CuArray{T,N,B}) where {T,N,B} = xs
360-
CuArray{T,N}(xs::CuArray{T,N,B}) where {T,N,B} = xs
358+
# copy xs to match Array behavior
359+
CuArray{T,N,B}(xs::CuArray{T,N,B}) where {T,N,B} = copy(xs)
360+
CuArray{T,N}(xs::CuArray{T,N,B}) where {T,N,B} = copy(xs)
361361

362362

363363
## conversions

test/array.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Adapt
1111
@test testf(vec, rand(5,3))
1212
@test cu(1:3) === 1:3
1313
@test Base.elsize(xs) == sizeof(Int)
14-
@test CuArray{Int, 2}(xs) === xs
14+
@test pointer(CuArray{Int, 2}(xs)) != pointer(xs)
1515

1616
# test aggressive conversion to Float32, but only for floats, and only with `cu`
1717
@test cu([1]) isa CuArray{Int}

0 commit comments

Comments
 (0)