@@ -609,6 +609,53 @@ 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
+ inds = indices (src)
638
+ indices (dest) == inds || throw (ArgumentError (" indices of src and dest must match (got $inds and $(indices (dest)) )" ))
639
+ _circshift! (dest, (), src, (), inds, fill_to_length (shiftamt, 0 , Val{N}))
640
+ end
641
+ circshift! (dest:: AbstractArray , src, shiftamt) = circshift! (dest, src, (shiftamt... ,))
642
+
643
+ @inline function _circshift! (dest, rdest, src, rsrc,
644
+ inds:: Tuple{AbstractUnitRange,Vararg{Any}} ,
645
+ shiftamt:: Tuple{Integer,Vararg{Any}} )
646
+ ind1, d = inds[1 ], shiftamt[1 ]
647
+ s = mod (d, length (ind1))
648
+ sf, sl = first (ind1)+ s, last (ind1)- s
649
+ r1, r2 = first (ind1): sf- 1 , sf: last (ind1)
650
+ r3, r4 = first (ind1): sl, sl+ 1 : last (ind1)
651
+ tinds, tshiftamt = tail (inds), tail (shiftamt)
652
+ _circshift! (dest, (rdest... , r1), src, (rsrc... , r4), tinds, tshiftamt)
653
+ _circshift! (dest, (rdest... , r2), src, (rsrc... , r3), tinds, tshiftamt)
654
+ end
655
+ # At least one of inds, shiftamt is empty
656
+ function _circshift! (dest, rdest, src, rsrc, inds, shiftamt)
657
+ copy! (dest, CartesianRange (rdest), src, CartesianRange (rsrc))
658
+ end
612
659
613
660
# ## BitArrays
614
661
0 commit comments