Skip to content

Commit

Permalink
Fix sort when dtype is uint16 (#563)
Browse files Browse the repository at this point in the history
Prior to this fix the code was using the mp_float_t data type for uint16
and producing incorrect sort results.

Signed-off-by: Damien George <damien@micropython.org>

Signed-off-by: Damien George <damien@micropython.org>
  • Loading branch information
dpgeorge committed Nov 29, 2022
1 parent 25a825e commit 1a440d7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion code/numpy/numerical.c
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ static mp_obj_t numerical_sort_helper(mp_obj_t oin, mp_obj_t axis, uint8_t inpla
if(ndarray->shape[ax]) {
if((ndarray->dtype == NDARRAY_UINT8) || (ndarray->dtype == NDARRAY_INT8)) {
HEAPSORT(ndarray, uint8_t, array, shape, strides, ax, increment, ndarray->shape[ax]);
} else if((ndarray->dtype == NDARRAY_INT16) || (ndarray->dtype == NDARRAY_INT16)) {
} else if((ndarray->dtype == NDARRAY_UINT16) || (ndarray->dtype == NDARRAY_INT16)) {
HEAPSORT(ndarray, uint16_t, array, shape, strides, ax, increment, ndarray->shape[ax]);
} else {
HEAPSORT(ndarray, mp_float_t, array, shape, strides, ax, increment, ndarray->shape[ax]);
Expand Down
2 changes: 1 addition & 1 deletion tests/2d/numpy/sort.py.exp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ array([1, 2, 3, 4], dtype=int8)

array([], dtype=uint16)
[]
array([0, 0, 0, 0], dtype=uint16)
array([1, 2, 3, 4], dtype=uint16)
[1, 3, 2, 0]

array([], dtype=int16)
Expand Down

0 comments on commit 1a440d7

Please sign in to comment.