-
Notifications
You must be signed in to change notification settings - Fork 118
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
[BUG] indexing with Booleans leads to crash #672
Comments
Wouldn't it be better to use https://numpy.org/doc/stable/reference/generated/numpy.select.html for this? My reasoning is that first, that would lead to a cleaner implementation, second, it would be easier to customise the firmware. Excluding a function/method is more meaningful than excluding a sub-feature of a feature. |
Sounds fine. Just need a way to do it. |
Question, does where() work?
I could use it to accomplish my goal of being able to select indices. ChatGPT wrote the code above, though, and it might have made a mistake regarding how to select columns. |
Yes, |
Having issues with this stuff still:
Doesn't work. Not sure why. I get a And then this says:
It's not clear how to move forward without writing a for loop. Trying to stay vectorized. |
It's not trivial (and this is why I didn't implement it in the first place), but I'll try to find a way. |
@v923z - Any updates on this? Happy to pay for this to get done sooner. |
The last 2-3 months were a bit hectic for me, but I'll try to devote some time to it. Sorry for the delay! |
I'm wondering, whether we're trying to fix something that's already correct:
Here is my output: >>> import ulab
>>> ulab.__version__
'6.5.4-2D-c'
>>> a = np.arange(36).reshape((6,6))
>>> a
array([[0, 1, 2, 3, 4, 5],
[6, 7, 8, 9, 10, 11],
[12, 13, 14, 15, 16, 17],
[18, 19, 20, 21, 22, 23],
[24, 25, 26, 27, 28, 29],
[30, 31, 32, 33, 34, 35]], dtype=int16)
>>> a[:, 4]
array([4, 10, 16, 22, 28, 34], dtype=int16)
>>> a[:, 4] > 15
array([False, False, True, True, True, True], dtype=bool)
>>> np.where(a[:, 4] > 15, 1, 0)
array([0, 0, 1, 1, 1, 1], dtype=uint8) Is this not what you need? I've just looked at the implementation of In fact, that particular exception is raised at one location only, when you try to get a slice via a higher-dimensional tensor: micropython-ulab/code/ndarray.c Lines 1317 to 1319 in c0b3262
|
Looks like it's working now.
Doesn't work still. |
Looks like it fails on the
|
Oh, I see. The problem is actually with >>> i = np.nonzero(np.asarray(a[:, 4] > 15))
>>> i
(array([2, 3, 4, 5], dtype=uint16),) As a workaround, could you try with |
? Not sure what you mean, I'm trying to slice into the array |
Yes, I get that, but >>> i
(array([2, 3, 4, 5], dtype=uint16),) |
Yeah, this is the operation I'd like to have so that I can use lab to vectorize non-max-suppression code. Per the post above... |
I think there might be two issues here: one is with >>> np.asarray(a[:, 4] > 15)
array([False, False, True, True, True, True], dtype=bool) The problem occurs, when this is passed to Then the second issue is that you want to use 2D Booleans for indexing/slicing. |
As for >>> from numpy import *
>>> x = arange(5)
>>> x
array([0, 1, 2, 3, 4])
>>> nonzero(x)
(array([1, 2, 3, 4]),) |
It seems to me that >>> a = arange(36).reshape((6, 6))
>>> a
array([[ 0, 1, 2, 3, 4, 5],
[ 6, 7, 8, 9, 10, 11],
[12, 13, 14, 15, 16, 17],
[18, 19, 20, 21, 22, 23],
[24, 25, 26, 27, 28, 29],
[30, 31, 32, 33, 34, 35]])
>>> i = nonzero(asarray(a[:, 4] > 15))
>>> i
(array([2, 3, 4, 5]),)
>>> a[i]
array([[12, 13, 14, 15, 16, 17],
[18, 19, 20, 21, 22, 23],
[24, 25, 26, 27, 28, 29],
[30, 31, 32, 33, 34, 35]]) So, if we caught that here micropython-ulab/code/ndarray.c Lines 1317 to 1319 in c0b3262
|
Not sure if I'm following. The trace above is what I want to happen. However, EDIT: So, you are saying all you need to do is make |
In the interim, you could simply use |
Great! |
I'm trying to understand what exactly you need, and it seems to me that #661 could do, so I'm wondering, whether I should clean that one up, and then we would kill two birds with one stone. |
I just need to be able to do your Numpy example above. To select rows from a 2D array using a 1D array of row indices. |
Can you check out https://github.com/v923z/micropython-ulab/tree/take and see if it works for you? |
Yeah, that should work. I'll have a list of row indexes. You may also wish to implement take_along_axis since it's just a wrapper around take. |
|
Okay, take is sufficient. |
OK, thanks for the feedback! I'll write up the documentation and merge the code. |
Fixed through #688. |
As mentioned in #671, the following code leads to a crash:
@kwagyeman
The text was updated successfully, but these errors were encountered: