v923z / micropython-ulab

a numpy-like fast vector module for micropython, circuitpython, and their derivatives
https://micropython-ulab.readthedocs.io/en/latest
MIT License
430 stars 117 forks source link

[FEATURE REQUEST] add out keyword argument to math functions #620

Closed v923z closed 1 year ago

v923z commented 1 year ago

Describe the solution you'd like Going off-tangent with the feature request in https://github.com/adafruit/circuitpython/issues/7995, add the out keyword argument to all math functions implemented in the vector module.

Additional context Allowing to pass a pre-allocated array into functions would save on RAM, and execution time, while the implementation itself is trivial, and could be done with minimal flash space penalty, given that this could be done in

https://github.com/v923z/micropython-ulab/blob/3e996d9bd93005edbbb9763c4a0a525fe52dec3d/code/numpy/vector.c#L35-L46

where the output array is created.

An example can be found in https://numpy.org/doc/stable/reference/generated/numpy.fabs.html

v923z commented 1 year ago

Implemented in https://github.com/v923z/micropython-ulab/pull/621, closing now.