@@ -609,6 +609,54 @@ function copy!{T,N}(dest::AbstractArray{T,N}, src::AbstractArray{T,N})
609
609
dest
610
610
end
611
611
612
+ function copy! (dest:: AbstractArray , Rdest:: CartesianRange , src:: AbstractArray , Rsrc:: CartesianRange )
613
+ isempty (Rdest) && return dest
614
+ size (Rdest) == size (Rsrc) || throw (ArgumentError (" source and destination must have same size (got $(size (Rsrc)) and $(size (Rdest)) )" ))
615
+ @boundscheck checkbounds (dest, Rdest. start)
616
+ @boundscheck checkbounds (dest, Rdest. stop)
617
+ @boundscheck checkbounds (src, Rsrc. start)
618
+ @boundscheck checkbounds (src, Rsrc. stop)
619
+ deltaI = Rdest. start - Rsrc. start
620
+ for I in Rsrc
621
+ @inbounds dest[I+ deltaI] = src[I]
622
+ end
623
+ dest
624
+ end
625
+
626
+ # circshift!
627
+ circshift! (dest:: AbstractArray , src, :: Tuple{} ) = copy! (dest, src)
628
+ """
629
+ circshift!(dest, src, shifts)
630
+
631
+ Circularly shift the data in `src`, storing the result in
632
+ `dest`. `shifts` specifies the amount to shift in each dimension.
633
+
634
+ See also `circshift`.
635
+ """
636
+ @noinline function circshift! {T,N} (dest:: AbstractArray{T,N} , src, shiftamt:: DimsInteger )
637
+ dest === src && throw (ArgumentError (" dest and src must be separate arrays" ))
638
+ inds = indices (src)
639
+ indices (dest) == inds || throw (ArgumentError (" indices of src and dest must match (got $inds and $(indices (dest)) )" ))
640
+ _circshift! (dest, (), src, (), inds, fill_to_length (shiftamt, 0 , Val{N}))
641
+ end
642
+ circshift! (dest:: AbstractArray , src, shiftamt) = circshift! (dest, src, (shiftamt... ,))
643
+
644
+ @inline function _circshift! (dest, rdest, src, rsrc,
645
+ inds:: Tuple{AbstractUnitRange,Vararg{Any}} ,
646
+ shiftamt:: Tuple{Integer,Vararg{Any}} )
647
+ ind1, d = inds[1 ], shiftamt[1 ]
648
+ s = mod (d, length (ind1))
649
+ sf, sl = first (ind1)+ s, last (ind1)- s
650
+ r1, r2 = first (ind1): sf- 1 , sf: last (ind1)
651
+ r3, r4 = first (ind1): sl, sl+ 1 : last (ind1)
652
+ tinds, tshiftamt = tail (inds), tail (shiftamt)
653
+ _circshift! (dest, (rdest... , r1), src, (rsrc... , r4), tinds, tshiftamt)
654
+ _circshift! (dest, (rdest... , r2), src, (rsrc... , r3), tinds, tshiftamt)
655
+ end
656
+ # At least one of inds, shiftamt is empty
657
+ function _circshift! (dest, rdest, src, rsrc, inds, shiftamt)
658
+ copy! (dest, CartesianRange (rdest), src, CartesianRange (rsrc))
659
+ end
612
660
613
661
# ## BitArrays
614
662
0 commit comments