v923z / micropython-ulab

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

[FEATURE REQUEST] append and vstack #671

Open kwagyeman opened 2 months ago

kwagyeman commented 2 months ago

Describe the solution you'd like I would like if append() and vstack() could be implemented.

Also if this limitation could be removed.

Indices can also be a list of Booleans. By using a Boolean list, we can select those elements of an array that satisfy a specific condition. At the moment, such indexing is defined for row vectors only; when the rank of the tensor is higher than 1, the function raises a NotImplementedError exception, though this will be rectified in a future version of ulab.

Additional context I was trying to implement non-max-suppression using Ulab and ran into the lack of these features complicating things for me.

Happy to finance this work.

v923z commented 2 months ago

append should be relatively straightforward, and others might also find it useful, so I would be happy to add it.

Reading the documentation of vstack, it seems to me that it's only a shortcut to what you can already do: concatenate has already been implemented. If that doesn't match your requirements, we could discuss the addition of vstack.

Also if this limitation could be removed.

Do you mean the fact that Boolean indices are supposed to be 1D arrays, or something else?

kwagyeman commented 2 months ago

Reading the documentation of vstack, it seems to me that it's only a shortcut to what you can already do: concatenate has already been implemented. If that doesn't match your requirements, we could discuss the addition of vstack.

It's more about making it easier to use desktop code directly without having to modify it too much. vstack would just be a wrapper around concatenate.

Do you mean the fact that Boolean indices are supposed to be 1D arrays, or something else?

If I try to use a 1D array of booleans to select rows from a 2D array you get a crash right now. Not a Not implemented error.

np_boxes is a 2D array of (x, y, w, h, score, class).

filtered_boxes = np_boxes[np_boxes[:, 4] > 0.0]

The above crashes.

v923z commented 2 months ago

If I try to use a 1D array of booleans to select rows from a 2D array you get a crash right now. Not a Not implemented error.

np_boxes is a 2D array of (x, y, w, h, score, class).

filtered_boxes = np_boxes[np_boxes[:, 4] > 0.0]

The above crashes.

OK, this is a different issue then, thanks for bringing it up! I opened a ticket here https://github.com/v923z/micropython-ulab/issues/672, so that it can be addressed.