211211
212212squeeze (A:: AbstractArray , dim:: Integer ) = squeeze (A, (Int (dim),))
213213
214+ # # from general iterable to any array
215+
214216function copy! (dest:: AbstractArray , src)
215217 i = 1
216218 for x in src
@@ -220,7 +222,6 @@ function copy!(dest::AbstractArray, src)
220222 return dest
221223end
222224
223- # copy with minimal requirements on src
224225# if src is not an AbstractArray, moving to the offset might be O(n)
225226function copy! (dest:: AbstractArray , doffs:: Integer , src)
226227 doffs < 1 && throw (BoundsError ())
@@ -247,7 +248,7 @@ function copy!(dest::AbstractArray, doffs::Integer, src, soffs::Integer)
247248 dn = done (src, st)
248249 dn && throw (BoundsError ())
249250 i, dmax = doffs, length (dest)
250- @inbounds while ! dn
251+ @inbounds while ! dn
251252 i > dmax && throw (BoundsError ())
252253 val, st = next (src, st)
253254 dest[i] = val
@@ -280,7 +281,20 @@ function copy!(dest::AbstractArray, doffs::Integer, src, soffs::Integer, n::Inte
280281 return dest
281282end
282283
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+
284298function copy! (dest:: AbstractArray , doffs:: Integer , src:: AbstractArray )
285299 copy! (dest, doffs, src, 1 , length (src))
286300end
0 commit comments