-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Please add ulab.numpy.absolute function #7995
Comments
Heads up @v923z - the "ulab" label was applied to this issue. |
@jamesra The absolute value unary operator was one of the first operators implemented: https://github.com/v923z/micropython-ulab/blob/3e996d9bd93005edbbb9763c4a0a525fe52dec3d/code/ndarray.c#L1968-L2000 In any case, it's easier to track issues and requests, if you raise them directly in https://github.com/v923z/micropython-ulab/issues. |
I think the request is for >>> ulab.numpy.abs
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'abs' |
OK, but then is it worth the flash space? If there is a good reason, we can easily add the function. |
So, if this is the function in question https://numpy.org/doc/stable/reference/generated/numpy.fabs.html, then the difference to On the other hand, math functions always return a floatint point array, while the |
This may be a documentation issue instead. abs is only listed on the page for complex arrays. I tried np.abs and np.absolute, but I know I did not try calling it directly off my array. Edit: I didn't think to use the interactive console to run dir(myarray) to find available methods. np.abs is probably still worth having, but not necessary if it is exposed on the array object itself. (My apologies if abs is documented somewhere else and I just missed it.) |
OK, at the risk of sounding dumb, what is the syntax for the unary absolute value operator in numpy? (I am using 8.1.0-beta 2 to obtain analogbufio on the ESP32-S3) I launched an interactive Circuit Python session and there is no abs function on the array:
|
MicroPython 8.1.0-beta.2-43-g4901bdceb7-dirty on 2023-05-18; linux version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> import ulab.numpy as numpy
>>> abs(numpy.array([-1, 2, -3]))
array([1.0, 2.0, 3.0], dtype=float64) It corresponds to the abs built-in function. In another post v923z referred to it as a "unary operator", but that reflects some implementation detail of micropython, it's not actually a unary operator like |
Oh!!! I'm trying to decide how I feel about that. On one level it makes total sense to use the built-in language operator. On another level it is some lateral thinking to step outside of the numpy library to do one operation... My suggested fix would be documentation. Thank you for explaining the intended use. |
This has actually been documented, unless you have something else in mind: https://micropython-ulab.readthedocs.io/en/latest/ulab-ndarray.html#unary-operators |
Closing because I think this has been resolved. |
The abs function from numpy would be nice to add to ulab.numpy. There is a lot of numpy functionality missing for good reason but this function feels particularly fundamental and it would be convenient to have it built-in. Thanks.
The text was updated successfully, but these errors were encountered: