Tips for writing fast MARPLE code¶
Use scalar functions directly¶
Scalar functions (arithmetic, comparison, boolean) use the NumPy backend automatically. They are much faster than applying the same operation via rank:
Prefer reduce over explicit recursion¶
Built-in reduce (+/V) uses NumPy's ufunc.reduce for commutative operations (add, multiply, maximum, minimum):
Writing the same reduction as a recursive dfn would be orders of magnitude slower.
Minimise per-cell dfn calls¶
The rank operator calls your dfn once per cell. For large arrays with many cells, this can be slow. When possible, express your computation using built-in primitives and operators that map to vectorised NumPy operations.
Operations with NumPy acceleration¶
These operations use NumPy when available:
- Arithmetic:
+,-,*,÷,*(power) - Comparison:
<,≤,=,≥,>,≠ - Boolean:
∧,∨,~ - Structural:
⍴(reshape) - Operators:
+/,*/,⌈/,⌊/(commutative reduce) - Inner product:
+.×usesnumpy.dot
See also: NumPy backend, Performance issues