Given the following function definition

function foo{T<:FloatingPoint}(A::Array{T})
    B = copy(A)
    #do some work on B
end

is there any (easy) way I can replace the call to copy() with a call that 
allocates an array that is 2 elements longer in every dimension, and copies 
A into the middle? A few examples might clarify what I mean:

A = [1 2]    =>   B = [0 1 2 0]
A = [1 2; 3 4]     =>    B = [0 0 0 0; 0 1 2 0; 0 3 4 0; 0 0 0 0]

In two dimensions I could do the following

B = similar(A, eltype(A), ([size(A)...].+2)...);
B[2:end-1,2:end-1] = copy(A);

but on the second line I'm making assumptions about the number of 
dimensions. Is it possible to accomplish this without making that 
assumption?

// Tomas

Reply via email to