@@ -563,16 +563,26 @@ Generate an index-vector to be used for padding. `inds` specifies the image axes
563
563
"""
564
564
function padindex (border:: Pad , lo:: Int , inds:: UnitRange{Int} , hi:: Int )
565
565
if border. style == :replicate
566
- indsnew = Int[fill (first (inds), lo); inds; fill (last (inds), hi)]
567
- OffsetArray (indsnew, first (inds)- lo: last (inds)+ hi)
566
+ indsnew = OffsetArray {Int} (undef, first (inds)- lo: last (inds)+ hi)
567
+ offview = OffsetArrays. no_offset_view (indsnew)
568
+ offview[1 : lo] .= first (inds)
569
+ offview[lo .+ eachindex (inds)] .= inds
570
+ offview[lo + length (inds) + 1 : end ] .= last (inds)
571
+ return indsnew
568
572
elseif border. style == :circular
569
573
return modrange (extend (lo, inds, hi), inds)
570
574
elseif border. style == :symmetric
571
- I = OffsetArray (Int[inds; reverse (inds)], (0 : 2 * length (inds)- 1 ) .+ first (inds))
575
+ I = OffsetArray {Int} (undef, (0 : 2 * length (inds)- 1 ) .+ first (inds))
576
+ offview = OffsetArrays. no_offset_view (I)
577
+ offview[eachindex (inds)] .= inds
578
+ offview[end : - 1 : length (inds) + 1 ] .= inds
572
579
r = modrange (extend (lo, inds, hi), axes (I, 1 ))
573
580
return I[r]
574
581
elseif border. style == :reflect
575
- I = OffsetArray (Int[inds; last (inds)- 1 : - 1 : first (inds)+ 1 ], (0 : 2 * length (inds)- 3 ) .+ first (inds))
582
+ I = OffsetArray {Int} (undef, (0 : 2 * length (inds)- 3 ) .+ first (inds))
583
+ offview = OffsetArrays. no_offset_view (I)
584
+ offview[eachindex (inds)] .= inds
585
+ offview[length (inds) + 1 : end ] .= last (inds)- 1 : - 1 : first (inds)+ 1
576
586
return I[modrange (extend (lo, inds, hi), axes (I, 1 ))]
577
587
else
578
588
error (" border style $(border. style) unrecognized" )
0 commit comments