11"""
22```julia
3- recursivecopy(b:: AbstractArray{T, N}, a::AbstractArray {T, N })
3+ recursivecopy(a::Union{ AbstractArray{T, N}, AbstractVectorOfArray {T,N} })
44```
55
66A recursive `copy` function. Acts like a `deepcopy` on arrays of arrays, but
@@ -26,6 +26,12 @@ function recursivecopy(a::AbstractArray{T, N}) where {T <: AbstractArray, N}
2626 end
2727end
2828
29+ function recursivecopy (a:: AbstractVectorOfArray )
30+ b = copy (a)
31+ b. u = recursivecopy .(a. u)
32+ return b
33+ end
34+
2935"""
3036```julia
3137recursivecopy!(b::AbstractArray{T, N}, a::AbstractArray{T, N})
@@ -36,37 +42,39 @@ like `copy!` on arrays of scalars.
3642"""
3743function recursivecopy! end
3844
39- function recursivecopy! (b:: AbstractArray{T, N} ,
40- a:: AbstractArray{T2, N} ) where {T <: StaticArraysCore.StaticArray ,
41- T2 <: StaticArraysCore.StaticArray ,
42- N}
43- @inbounds for i in eachindex (a)
44- # TODO : Check for `setindex!`` and use `copy!(b[i],a[i])` or `b[i] = a[i]`, see #19
45- b[i] = copy (a[i])
45+ for type in [AbstractArray, AbstractVectorOfArray]
46+ @eval function recursivecopy! (b:: $type{T, N} ,
47+ a:: $type{T2, N} ) where {T <: StaticArraysCore.StaticArray ,
48+ T2 <: StaticArraysCore.StaticArray ,
49+ N}
50+ @inbounds for i in eachindex (a)
51+ # TODO : Check for `setindex!`` and use `copy!(b[i],a[i])` or `b[i] = a[i]`, see #19
52+ b[i] = copy (a[i])
53+ end
4654 end
47- end
4855
49- function recursivecopy! (b:: AbstractArray {T, N} ,
50- a:: AbstractArray {T2, N} ) where {T <: Enum , T2 <: Enum , N}
51- copyto! (b, a)
52- end
56+ @eval function recursivecopy! (b:: $type {T, N} ,
57+ a:: $type {T2, N} ) where {T <: Enum , T2 <: Enum , N}
58+ copyto! (b, a)
59+ end
5360
54- function recursivecopy! (b:: AbstractArray {T, N} ,
55- a:: AbstractArray {T2, N} ) where {T <: Number , T2 <: Number , N}
56- copyto! (b, a)
57- end
61+ @eval function recursivecopy! (b:: $type {T, N} ,
62+ a:: $type {T2, N} ) where {T <: Number , T2 <: Number , N}
63+ copyto! (b, a)
64+ end
5865
59- function recursivecopy! (b:: AbstractArray{T, N} ,
60- a:: AbstractArray{T2, N} ) where {T <: AbstractArray ,
61- T2 <: AbstractArray , N}
62- if ArrayInterface. ismutable (T)
63- @inbounds for i in eachindex (b, a)
64- recursivecopy! (b[i], a[i])
66+ @eval function recursivecopy! (b:: $type{T, N} ,
67+ a:: $type{T2, N} ) where {T <: Union{AbstractArray, AbstractVectorOfArray} ,
68+ T2 <: Union{AbstractArray, AbstractVectorOfArray} , N}
69+ if ArrayInterface. ismutable (T)
70+ @inbounds for i in eachindex (b, a)
71+ recursivecopy! (b[i], a[i])
72+ end
73+ else
74+ copyto! (b, a)
6575 end
66- else
67- copyto! (b, a)
76+ return b
6877 end
69- return b
7078end
7179
7280"""
@@ -110,32 +118,36 @@ function recursivefill!(bs::AbstractVectorOfArray{T, N},
110118 end
111119end
112120
113- function recursivefill! (b:: AbstractArray{T, N} , a:: T2 ) where {T <: Enum , T2 <: Enum , N}
114- fill! (b, a)
115- end
121+ for type in [AbstractArray, AbstractVectorOfArray]
122+ @eval function recursivefill! (b:: $type{T, N} , a:: T2 ) where {T <: Enum , T2 <: Enum , N}
123+ fill! (b, a)
124+ end
116125
117- function recursivefill! (b:: AbstractArray {T, N} ,
118- a:: T2 ) where {T <: Union{Number, Bool} , T2 <: Union{Number, Bool} , N
119- }
120- fill! (b, a)
121- end
126+ @eval function recursivefill! (b:: $type {T, N} ,
127+ a:: T2 ) where {T <: Union{Number, Bool} , T2 <: Union{Number, Bool} , N
128+ }
129+ fill! (b, a)
130+ end
122131
123- function recursivefill! (b:: AbstractArray{T, N} , a) where {T <: StaticArraysCore.MArray , N}
124- @inbounds for i in eachindex (b)
125- if isassigned (b, i)
126- recursivefill! (b[i], a)
127- else
128- b[i] = zero (eltype (b))
129- recursivefill! (b[i], a)
132+ for type2 in [Any, StaticArraysCore. StaticArray]
133+ @eval function recursivefill! (b:: $type{T, N} , a:: $type2 ) where {T <: StaticArraysCore.MArray , N}
134+ @inbounds for i in eachindex (b)
135+ if isassigned (b, i)
136+ recursivefill! (b[i], a)
137+ else
138+ b[i] = zero (eltype (b))
139+ recursivefill! (b[i], a)
140+ end
141+ end
130142 end
131143 end
132- end
133-
134- function recursivefill! (b:: AbstractArray{T, N} , a) where {T <: AbstractArray , N}
135- @inbounds for i in eachindex (b)
136- recursivefill! (b[i], a)
144+
145+ @eval function recursivefill! (b:: $type{T, N} , a) where {T <: AbstractArray , N}
146+ @inbounds for i in eachindex (b)
147+ recursivefill! (b[i], a)
148+ end
149+ return b
137150 end
138- return b
139151end
140152
141153# Deprecated
0 commit comments