Speed and Multiple Evaluations of UserFuncs¶
Some UserFuncs can decrease computation time by vectorization, or simultaneous multiple evaluations. For example, consider the function \(f(x,y) = x+y\), which we want to evaluate for several values of \((x,y)\), namely \((0,0)\), \((0,1)\), \((2,3)\), and \((-1,2)\). We can often get results faster by performing all 4 evaluations at once, essentially trading 4 calls to the plus function with scalar arguments for 1 call to a plus function with 4-vector arguments. Since the addition of two numbers can usually be done faster than a function call, this is often a good trade-off, even though there are extra computational costs to allowing multiple (or vector) evaluation.
Unfortunately, vectorization is not always possible, and is not always efficient even when it is possible.
UserFuncs of kind expression allow multiple evaluations, limited by the maxNumEvals attribute. Expressions are pretty efficient evaluated one at a time; however, performing 64 evaluations at once typically reduces the computation time (per evaluation) by 30%–50%. There seems to be little benefit to going beyond 128 simultaneous evaluations.
The userFuncUpdater can efficiently use the ability to perform multiple evaluations at once. However, other Vorpal objects that use user-given functions cannot.