211
211
212
212
squeeze (A:: AbstractArray , dim:: Integer ) = squeeze (A, (Int (dim),))
213
213
214
+ # # from general iterable to any array
215
+
214
216
function copy! (dest:: AbstractArray , src)
215
217
i = 1
216
218
for x in src
@@ -220,7 +222,6 @@ function copy!(dest::AbstractArray, src)
220
222
return dest
221
223
end
222
224
223
- # copy with minimal requirements on src
224
225
# if src is not an AbstractArray, moving to the offset might be O(n)
225
226
function copy! (dest:: AbstractArray , doffs:: Integer , src)
226
227
doffs < 1 && throw (BoundsError ())
@@ -247,7 +248,7 @@ function copy!(dest::AbstractArray, doffs::Integer, src, soffs::Integer)
247
248
dn = done (src, st)
248
249
dn && throw (BoundsError ())
249
250
i, dmax = doffs, length (dest)
250
- @inbounds while ! dn
251
+ @inbounds while ! dn
251
252
i > dmax && throw (BoundsError ())
252
253
val, st = next (src, st)
253
254
dest[i] = val
@@ -280,7 +281,20 @@ function copy!(dest::AbstractArray, doffs::Integer, src, soffs::Integer, n::Inte
280
281
return dest
281
282
end
282
283
283
- # if src is an AbstractArray and a source offset is passed, use indexing
284
+ # # copy between abstract arrays - generally more efficient
285
+ # # since a single index variable can be used.
286
+
287
+ function copy! (dest:: AbstractArray , src:: AbstractArray )
288
+ n = length (src)
289
+ if n > length (dest)
290
+ throw (BoundsError ())
291
+ end
292
+ @inbounds for i = 1 : n
293
+ dest[i] = src[i]
294
+ end
295
+ return dest
296
+ end
297
+
284
298
function copy! (dest:: AbstractArray , doffs:: Integer , src:: AbstractArray )
285
299
copy! (dest, doffs, src, 1 , length (src))
286
300
end
0 commit comments