Skip to content

Commit 0d1588a

Browse files
committed
Specialize deepcopy for ArrayOfSimilarArrays
1 parent 09757f8 commit 0d1588a

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/array_of_similar_arrays.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ function Base.similar(A::ArrayOfSimilarArrays{T,M,N}, ::Type{<:AbstractArray{U}}
166166
end
167167

168168

169+
function Base.deepcopy(A::ArrayOfSimilarArrays{T,M,N}) where {T,M,N}
170+
ArrayOfSimilarArrays{T,M,N}(deepcopy(A.data))
171+
end
172+
173+
169174
function Base.copyto!(dest::ArrayOfSimilarArrays{T,M,N}, src::ArrayOfSimilarArrays{U,M,N}) where {T,M,N,U}
170175
copyto!(dest.data, src.data)
171176
dest

test/array_of_similar_arrays.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ using UnsafeArrays
121121
end
122122

123123

124+
@testset "deepcopy" begin
125+
A = ArrayOfSimilarArrays{Float64,1}(rand_flat_array(Val(1)))
126+
@test (@inferred deepcopy(A)) == A
127+
@test typeof(deepcopy(A)) == typeof(A)
128+
end
129+
130+
124131
@testset "flatview" begin
125132
A = rand_nested_similar_arrays(Val(3), Val(2))
126133
B = ArrayOfSimilarArrays(A)

0 commit comments

Comments
 (0)