Fastest way to apply function to rows without slices


I have a function which takes two 2-element Array{Float64,1} as input. An example (mine is much more complicated, but can’t be shared sadly). It can look something like this.

function Example(x,y)
    return norm(x.-y)

Imagine now that I have two Nx2-element Array{Float64,2} xv and yv, where N is a large number. Of course, with a for loop and slices, we can apply Èxample to each row, by

for i in N

I want to do this fast and I want to avoid slices since I want to use ForwardDiff later on. I have tried pmap and mapslices with no luck. Any tips?

It may help to provide an example of what you need to differentiate. Instead of elementwise operations on N x 2 arrays, you may want to consider reshaping into a 2 X N array to take advantage of Julia’s column-major memory layout, or better yet, a vector of StaticVectors. Your original example can be written as

map(Example, eachrow(xv), eachrow(yv))