Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
v923z opened this issue May 19, 2023 · 1 comment
Closed

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

v923z opened this issue May 19, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@v923z
Copy link
Owner

v923z commented May 19, 2023

Describe the solution you'd like
Going off-tangent with the feature request in adafruit/circuitpython#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

static mp_obj_t vector_generic_vector(mp_obj_t o_in, mp_float_t (*f)(mp_float_t)) {
// Return a single value, if o_in is not iterable
if(mp_obj_is_float(o_in) || mp_obj_is_int(o_in)) {
return mp_obj_new_float(f(mp_obj_get_float(o_in)));
}
ndarray_obj_t *ndarray = NULL;
if(mp_obj_is_type(o_in, &ulab_ndarray_type)) {
ndarray_obj_t *source = MP_OBJ_TO_PTR(o_in);
COMPLEX_DTYPE_NOT_IMPLEMENTED(source->dtype)
uint8_t *sarray = (uint8_t *)source->array;
ndarray = ndarray_new_dense_ndarray(source->ndim, source->shape, NDARRAY_FLOAT);
mp_float_t *array = (mp_float_t *)ndarray->array;

where the output array is created.

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

@v923z v923z added the enhancement New feature or request label May 19, 2023
@v923z
Copy link
Owner Author

v923z commented Jun 21, 2023

Implemented in #621, closing now.

@v923z v923z closed this as completed Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant