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

[BUG] Weird behavior with invalid dtype= #585

Open
jepler opened this issue Jan 24, 2023 · 1 comment
Open

[BUG] Weird behavior with invalid dtype= #585

jepler opened this issue Jan 24, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@jepler
Copy link
Collaborator

jepler commented Jan 24, 2023

Describe the bug
A clear and concise description of what the bug is. Give the ulab version

MicroPython v1.19.1-837-g67fac4ebc on 2023-01-24; linux [GCC 4.2.1] version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> import ulab
>>> ulab.__version__
'6.0.5-2D-c'
>>> ulab.numpy.array([range(2000)], dtype=1)
array([[0, 1, 2, ..., 205, 206, 207]], dtype=float64)

Expected behavior
Probably an exception as the dtype= argument is not valid (numpy says TypeError: Cannot interpret '1' as a data type)

Additional context
discovered during fuzzing, but was not a crash

@jepler jepler added the bug Something isn't working label Jan 24, 2023
@v923z
Copy link
Owner

v923z commented Jan 25, 2023

This is indeed an ugly bug, and it's got to be fixed. What makes a problem a bit difficult is the fact that dtypes are stored as uint8s internally. So,

np.array([1, 2, 3], dtype=np.float)
np.array([1, 2, 3], dtype=100)

both work, while you want the second one to fail. The easiest solution is to simply set the ULAB_HAS_DTYPE_OBJECT constant

#ifndef ULAB_HAS_DTYPE_OBJECT
#define ULAB_HAS_DTYPE_OBJECT (0)
#endif
, but that adds some kB to the code. That's why I opted for the cheap solution, but I see that that causes issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants