@@ -563,16 +563,26 @@ Generate an index-vector to be used for padding. `inds` specifies the image axes
563563"""
564564function padindex (border:: Pad , lo:: Int , inds:: UnitRange{Int} , hi:: Int )
565565 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
568572 elseif border. style == :circular
569573 return modrange (extend (lo, inds, hi), inds)
570574 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
572579 r = modrange (extend (lo, inds, hi), axes (I, 1 ))
573580 return I[r]
574581 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
576586 return I[modrange (extend (lo, inds, hi), axes (I, 1 ))]
577587 else
578588 error (" border style $(border. style) unrecognized" )
0 commit comments