By the way, you can do this more easily now, without macros, like this:

for IA in CartesianRange(size(A))
    for IB in CartesianRange(size(B))
        ret[IA+IB] = A[IA] * B[IB]
    end
end

--Tim

On Monday, April 13, 2015 08:05:15 AM Derek Thomas wrote:
> Hi all,
> 
> I'm trying to implement a multidimensional convolution defined like this in
> 2d:
> 
> "We initialize to zero a matrix c and add to it, starting at the (i,j)th
> position, submatrices b[i, j] * a[:, :] padded with zeros."
> 
> I have this function:
> stagedfunction convn{T,N}(A::Array{T,N}, B::Array{T,N})
>     quote
>         retsize = [size(A)...] + [size(B)...]
>         retsize = tuple(retsize...)
>         ret = zeros(T, retsize)
>         @nloops $N i A begin
>             @nloops $N j B begin
>                 (@nref $N ret k->(i_d + j_d)) = (@nref A i) * (@nref B j)
>             end
>         end
>         return ret
>     end
> end
> 
> but I'm getting a cryptic ERROR: wrong number of arguments message to this
> input
> 
> A = randn(5, 5)
> 
> convn(A, A)
> 
> Any help is appreciated.  Thanks,
> 
> Derek

Reply via email to