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

Fix (u)int8 upcasting as per docs and numpy #650

Merged
merged 3 commits into from
Dec 11, 2023

Conversation

s-ol
Copy link
Contributor

@s-ol s-ol commented Dec 8, 2023

Close #649.

For testing with CircuitPython, see the branch https://github.com/s-ol/micropython-ulab/tree/fix-int8-upcasting.

Apologies if this breaks any tests that should have been updated, I couldn't get the test build to work on my system.

@s-ol s-ol changed the title Fix (u) int8 upcasting as per docs and numpy Fix (u)int8 upcasting as per docs and numpy Dec 8, 2023
@v923z
Copy link
Owner

v923z commented Dec 8, 2023

The upcasting rules are given here:

uint8 + int8 => int16
, and here https://github.com/v923z/micropython-ulab/blob/master/docs/manual/source/ulab-ndarray.rst#upcasting

code/ndarray_operators.c Outdated Show resolved Hide resolved
} else if(rhs->dtype == NDARRAY_INT8) {
results = ndarray_new_dense_ndarray(ndim, shape, NDARRAY_INT16);
BINARY_LOOP(results, int16_t, uint8_t, int8_t, larray, lstrides, rarray, rstrides, *);
results = ndarray_new_dense_ndarray(ndim, shape, NDARRAY_INT8);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

code/ndarray_operators.c Outdated Show resolved Hide resolved
code/ndarray_operators.c Outdated Show resolved Hide resolved
@v923z
Copy link
Owner

v923z commented Dec 10, 2023

I think this is OK now, thanks! Could you, please, increment the sub-minor version here

#define ULAB_VERSION 6.4.1
, and add an entry here https://github.com/v923z/micropython-ulab/blob/master/docs/ulab-change-log.md? You'll also have to fix the test https://github.com/v923z/micropython-ulab/actions/runs/7153101407/job/19492990488?pr=650, but I think that's just a single line in https://github.com/v923z/micropython-ulab/blob/master/tests/2d/numpy/operators.py.exp, here
array([5, 7, 9], dtype=uint16)
.

@v923z
Copy link
Owner

v923z commented Dec 11, 2023

OK, thanks!

@v923z v923z merged commit e329206 into v923z:master Dec 11, 2023
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Operations on uint8 don't respect upcasting rules
2 participants