v923z / micropython-ulab

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

[FEATURE REQUEST] Support for keepdims? #697

Open kwagyeman opened 3 days ago

kwagyeman commented 3 days ago

For processing things like yolo in ulab the vector size could be 1:N. In the case of 1 we need support for keepdims to prevent dimensionality reduction from happening: https://github.com/openmv/openmv/pull/2521/files

v923z commented 3 days ago

There are other instances, where keeping the dimension would be useful. It shouldn't be too hard, I simply didn't have time to implement it.

kwagyeman commented 3 days ago

Looks like you could just add it as an arg here and handle the return of a scalar from each case and turn that scalar back into an array: https://github.com/v923z/micropython-ulab/blob/master/code/numpy/numerical.c. Probably also need to do the same in a few other places.

v923z commented 3 days ago

That would cover the case, when the return value is a scalar, but you might also want to keep the dimension, when the tensor is contracted. So, it's a bit more involving. I'll take a stab at it over the weekend.

kwagyeman commented 3 days ago

Thank you! Yes, handling this otherwise gets quite ugly quickly.