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