1
1
"""
2
2
```julia
3
- recursivecopy(b:: AbstractArray{T, N}, a::AbstractArray {T, N })
3
+ recursivecopy(a::Union{ AbstractArray{T, N}, AbstractVectorOfArray {T,N} })
4
4
```
5
5
6
6
A 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}
26
26
end
27
27
end
28
28
29
+ function recursivecopy (a:: AbstractVectorOfArray )
30
+ b = copy (a)
31
+ b. u = recursivecopy .(a. u)
32
+ return b
33
+ end
34
+
29
35
"""
30
36
```julia
31
37
recursivecopy!(b::AbstractArray{T, N}, a::AbstractArray{T, N})
@@ -36,37 +42,39 @@ like `copy!` on arrays of scalars.
36
42
"""
37
43
function recursivecopy! end
38
44
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
46
54
end
47
- end
48
55
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
53
60
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
58
65
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)
65
75
end
66
- else
67
- copyto! (b, a)
76
+ return b
68
77
end
69
- return b
70
78
end
71
79
72
80
"""
@@ -110,32 +118,36 @@ function recursivefill!(bs::AbstractVectorOfArray{T, N},
110
118
end
111
119
end
112
120
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
116
125
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
122
131
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
130
142
end
131
143
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
137
150
end
138
- return b
139
151
end
140
152
141
153
# Deprecated
0 commit comments