Skip to content

Commit f2dd223

Browse files
authored
fix sorting of empty arrays in sort_complex (#583)
1 parent 578ca66 commit f2dd223

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed

code/numpy/carray/carray.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,12 @@ mp_obj_t carray_sort_complex(mp_obj_t _source) {
191191
}
192192

193193
ndarray_obj_t *ndarray = ndarray_copy_view_convert_type(source, NDARRAY_COMPLEX);
194-
mp_float_t *array = (mp_float_t *)ndarray->array;
195-
carray_sort_complex_(array, ndarray->len);
194+
195+
if(ndarray->len != 0) {
196+
mp_float_t *array = (mp_float_t *)ndarray->array;
197+
carray_sort_complex_(array, ndarray->len);
198+
}
199+
196200
return MP_OBJ_FROM_PTR(ndarray);
197201
}
198202

code/ulab.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include "user/user.h"
3434
#include "utils/utils.h"
3535

36-
#define ULAB_VERSION 6.0.6
36+
#define ULAB_VERSION 6.0.7
3737
#define xstr(s) str(s)
3838
#define str(s) #s
3939

docs/ulab-change-log.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ version 6.0.6
66

77
Sun, 21 Jan 2023
88

9+
version 6.0.7
10+
11+
treat empty arrays in sort_complex correctly
12+
13+
Sun, 21 Jan 2023
14+
915
version 6.0.5
1016

1117
fix ones()/zeros() method when the amount of memory to allocate overflows

tests/2d/complex/sort_complex.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

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

1113
print()
1214
n = 6

tests/2d/complex/sort_complex.py.exp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
array([1.0+0.0j, 2.0+0.0j, 3.0+0.0j, 4.0+0.0j, 5.0+0.0j], dtype=complex)
2+
array([], dtype=complex)
23
array([1.0+0.0j, 2.0+0.0j, 3.0+0.0j, 4.0+0.0j, 5.0+0.0j], dtype=complex)
4+
array([], dtype=complex)
35
array([1.0+0.0j, 2.0+0.0j, 3.0+0.0j, 4.0+0.0j, 5.0+0.0j], dtype=complex)
6+
array([], dtype=complex)
47
array([1.0+0.0j, 2.0+0.0j, 3.0+0.0j, 4.0+0.0j, 5.0+0.0j], dtype=complex)
8+
array([], dtype=complex)
59
array([1.0+0.0j, 2.0+0.0j, 3.0+0.0j, 4.0+0.0j, 5.0+0.0j], dtype=complex)
10+
array([], dtype=complex)
611
array([1.0+0.0j, 2.0+0.0j, 3.0+0.0j, 4.0+0.0j, 5.0+0.0j], dtype=complex)
12+
array([], dtype=complex)
713

814
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)
915
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)

0 commit comments

Comments
 (0)