Skip to content

Commit

Permalink
fix sorting of empty arrays in sort_complex (#583)
Browse files Browse the repository at this point in the history
  • Loading branch information
v923z authored Jan 23, 2023
1 parent 578ca66 commit f2dd223
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
8 changes: 6 additions & 2 deletions code/numpy/carray/carray.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,12 @@ mp_obj_t carray_sort_complex(mp_obj_t _source) {
}

ndarray_obj_t *ndarray = ndarray_copy_view_convert_type(source, NDARRAY_COMPLEX);
mp_float_t *array = (mp_float_t *)ndarray->array;
carray_sort_complex_(array, ndarray->len);

if(ndarray->len != 0) {
mp_float_t *array = (mp_float_t *)ndarray->array;
carray_sort_complex_(array, ndarray->len);
}

return MP_OBJ_FROM_PTR(ndarray);
}

Expand Down
2 changes: 1 addition & 1 deletion code/ulab.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include "user/user.h"
#include "utils/utils.h"

#define ULAB_VERSION 6.0.6
#define ULAB_VERSION 6.0.7
#define xstr(s) str(s)
#define str(s) #s

Expand Down
6 changes: 6 additions & 0 deletions docs/ulab-change-log.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ version 6.0.6

Sun, 21 Jan 2023

version 6.0.7

treat empty arrays in sort_complex correctly

Sun, 21 Jan 2023

version 6.0.5

fix ones()/zeros() method when the amount of memory to allocate overflows
Expand Down
2 changes: 2 additions & 0 deletions tests/2d/complex/sort_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

for dtype in dtypes:
print(np.sort_complex(np.array(range(5, 0, -1), dtype=dtype)))
# these should all return an empty complex array
print(np.sort_complex(np.array(range(5, 0, 1), dtype=dtype)))

print()
n = 6
Expand Down
6 changes: 6 additions & 0 deletions tests/2d/complex/sort_complex.py.exp
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
array([1.0+0.0j, 2.0+0.0j, 3.0+0.0j, 4.0+0.0j, 5.0+0.0j], dtype=complex)
array([], dtype=complex)
array([1.0+0.0j, 2.0+0.0j, 3.0+0.0j, 4.0+0.0j, 5.0+0.0j], dtype=complex)
array([], dtype=complex)
array([1.0+0.0j, 2.0+0.0j, 3.0+0.0j, 4.0+0.0j, 5.0+0.0j], dtype=complex)
array([], dtype=complex)
array([1.0+0.0j, 2.0+0.0j, 3.0+0.0j, 4.0+0.0j, 5.0+0.0j], dtype=complex)
array([], dtype=complex)
array([1.0+0.0j, 2.0+0.0j, 3.0+0.0j, 4.0+0.0j, 5.0+0.0j], dtype=complex)
array([], dtype=complex)
array([1.0+0.0j, 2.0+0.0j, 3.0+0.0j, 4.0+0.0j, 5.0+0.0j], dtype=complex)
array([], dtype=complex)

array([1.0+1.0j, 1.0+2.0j, 1.0+3.0j, 1.0+4.0j, 1.0+5.0j, 1.0+6.0j], dtype=complex)
array([1.0+0.0j, 1.0+1.0j, 1.0+2.0j, 1.0+3.0j, 1.0+4.0j, 1.0+5.0j], dtype=complex)
Expand Down

0 comments on commit f2dd223

Please sign in to comment.