Created by: portnov
For the following nodes:
- Curve Formula
- Surface Formula
- Scalar Field Formula
- Vector Field Formula
allow to perform vectorized computations via numpy. Without vectorization, the formulas are evaluated for each input value separately. With vectorization, when the subsequent node calls something like surface.evaluate_array()
to calculate values at a series of points, the formula is evaluated one time for the whole array. Calls to usual math
module functions are automatically replaced with corresponding numpy
calls.
In my experiments, I have speedups from 2x to 100x. As usual with vectorization, the more values you compute at the time, the bigger speedup you will have. So, the biggest speedup there will be for use, for example, of "scalar field formula" + "Marching Cubes" with high samples, or "Surface Formula" + "Evaluate Surface" with a lot of samples.
I suspect there might be either bugs or precision-related troubles when math
functions are replaced with their numpy
counterparts, though I've not experienced such. So I made this vectorization mode optional, but enabled by default. It may be disabled in the node's N panel.
Preflight checklist
Put an x letter in each brackets when you're done this item:
-
Code changes complete. -
Code documentation complete. -
Documentation for users complete (or not required, if user never sees these changes). -
Manual testing done. -
Unit-tests implemented. -
Ready for merge.