MATLAB: How to adapt arrayfun() to operate on vectors rather than scalars

gpu arrayfun parallelism

I have a 45-variable function for which I'm trying to speed up computation of the finite-differencing based gradient, as function evaluation is expensive. I'm currently doing this with parfor on my 4-core CPU, but I'd still like things to be faster by using arrayfun() on my GPU (1050 Ti).
So I was thinking of creating a 45×45 matrix P where the ith column has the ith variable incremented by a small step size for finite differencing, and then calling
z = arrayfun(@objectiveFunction, P), and having arrayfun apply objectiveFunction to each column of P at a time.
However, arrayfun doesn't seem configured to do this, and I couldn't find another answer on the forums addressing whether its possible to reconfigure somehow.
Any thoughts?
Thanks.

Best Answer

Look at pagefun for mixing in calls to vector operations with your ordinary element-wise functions. Usually with the functions supported by pagefun, standard MATLAB functions on gpuArray data, and arrayfun, you can get the result you're after.
Related Question