I’ve been searching the documentations for some kind of julia alternative to the padarray function in matlab (Pad array - MATLAB padarray) but I did not find anything useful.
TL;DR: what i want to do is given an array u=[1 2; 3 4] pad it with the values on the border of my original array u (corresponding to the keywords 'replicate' and 'both' in the matlab couterpart)
Oh right, I missed that. The difference is that padarray(arr, Pad((1,1))) creates a new matrix with the padding, vs. BorderArray which is a view of the old one. One of these may be preferred depending on what you do next.
BTW both of them have unconventional indices, axes(A,1) == 0:3 in the above examples, rather than 1:4. Which means that the original pixels are at their original locations.
Just to build a bit on this, these are some quick test i made that may be useful depending on the situation on which one would want to use these functions
H = 1000
pad = 2
u = rand(H, H)
@btime padarray($u, Pad((pad, pad))) # 72.718 μs (21 allocations: 7.71 MiB)
@btime BorderArray($u, Pad((pad, pad))) # 193.989 ns (3 allocations: 112 bytes)
function test_access(u)
for i in eachindex(u)
u[i]
end
end
u_pad = padarray(u, Pad((pad, pad)))
u_border = BorderArray(u, Pad((pad, pad)))
@btime test_access($u_pad); # 288.715 μs (0 allocations: 0 bytes)
@btime test_access($u_border); # 3.544 ms (0 allocations: 0 bytes)