96
96
97
97
parent_type (:: Type{<:FixedSizeArray{T}} ) where {T} = Memory{T}
98
98
99
- memory_of (m:: Memory ) = m
100
- memory_of (f:: FixedSizeArray ) = f. mem
101
-
102
- first_linear_index (a) = first (eachindex (IndexLinear (), a))
99
+ underlying_storage (m) = m
100
+ underlying_storage (f:: FixedSizeArray ) = f. mem
103
101
104
102
axes_are_one_based (axes) = all (isone ∘ first, axes)
105
103
@@ -126,38 +124,30 @@ FixedSizeArray(a::AbstractArray{T,N}) where {T,N} = FixedSizeArray{T,N}
126
124
Base. convert (:: Type{T} , a:: T ) where {T<: FixedSizeArray } = a
127
125
Base. convert (:: Type{T} , a:: AbstractArray ) where {T<: FixedSizeArray } = T (a):: T
128
126
129
- # `copyto!` between `FixedSizeArray` and `Memory`
127
+ # `copyto!`
130
128
131
129
Base. @propagate_inbounds function copyto5! (dst, doff, src, soff, n)
132
- if ! iszero (n)
133
- if n < false
134
- throw (ArgumentError (" the number of elements to copy must be nonnegative" ))
135
- end
136
- @boundscheck checkbounds (dst, doff: doff+ n- 1 )
137
- @boundscheck checkbounds (src, soff: soff+ n- 1 )
138
- @inbounds let d, s
139
- d = GenericMemoryRef (memory_of (dst), doff)
140
- s = GenericMemoryRef (memory_of (src), soff)
141
- unsafe_copyto! (d, s, n)
142
- end
143
- end
130
+ copyto! (underlying_storage (dst), doff, underlying_storage (src), soff, n)
144
131
dst
145
132
end
146
133
147
- Base. @propagate_inbounds function copyto2! (dst:: T , src) where {T}
148
- fd = first_linear_index (dst)
149
- fs = first_linear_index (src)
150
- len = length (src)
151
- copyto5! (dst, fd, src, fs, len):: T
134
+ Base. @propagate_inbounds function copyto2! (dst, src)
135
+ copyto! (underlying_storage (dst), underlying_storage (src))
136
+ dst
152
137
end
153
138
154
139
Base. @propagate_inbounds Base. copyto! (dst:: FixedSizeArray , doff:: Integer , src:: FixedSizeArray , soff:: Integer , n:: Integer ) = copyto5! (dst, doff, src, soff, n)
155
- Base. @propagate_inbounds Base. copyto! (dst:: FixedSizeArray , doff:: Integer , src:: Memory , soff:: Integer , n:: Integer ) = copyto5! (dst, doff, src, soff, n)
156
- Base. @propagate_inbounds Base. copyto! (dst:: Memory , doff:: Integer , src:: FixedSizeArray , soff:: Integer , n:: Integer ) = copyto5! (dst, doff, src, soff, n)
157
-
158
140
Base. @propagate_inbounds Base. copyto! (dst:: FixedSizeArray , src:: FixedSizeArray ) = copyto2! (dst, src)
159
- Base. @propagate_inbounds Base. copyto! (dst:: FixedSizeArray , src:: Memory ) = copyto2! (dst, src)
160
- Base. @propagate_inbounds Base. copyto! (dst:: Memory , src:: FixedSizeArray ) = copyto2! (dst, src)
141
+
142
+ for A ∈ (Array, GenericMemory) # Add more? Too bad we have to hardcode to avoid ambiguity.
143
+ @eval begin
144
+ Base. @propagate_inbounds Base. copyto! (dst:: FixedSizeArray , doff:: Integer , src:: $A , soff:: Integer , n:: Integer ) = copyto5! (dst, doff, src, soff, n)
145
+ Base. @propagate_inbounds Base. copyto! (dst:: $A , doff:: Integer , src:: FixedSizeArray , soff:: Integer , n:: Integer ) = copyto5! (dst, doff, src, soff, n)
146
+
147
+ Base. @propagate_inbounds Base. copyto! (dst:: FixedSizeArray , src:: $A ) = copyto2! (dst, src)
148
+ Base. @propagate_inbounds Base. copyto! (dst:: $A , src:: FixedSizeArray ) = copyto2! (dst, src)
149
+ end
150
+ end
161
151
162
152
# unsafe: the native address of the array's storage
163
153
0 commit comments