Compare commits

...

2 commits

Author SHA1 Message Date
Zoltán Vörös
c758859640
Merge branch 'master' into sort_complex-fix 2023-01-23 21:53:12 +01:00
Zoltán Vörös
cf38fcd424 fix sorting of empty arrays in sort_complex 2023-01-22 19:20:06 +01:00
5 changed files with 21 additions and 3 deletions

View file

@ -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); ndarray_obj_t *ndarray = ndarray_copy_view_convert_type(source, NDARRAY_COMPLEX);
if(ndarray->len != 0) {
mp_float_t *array = (mp_float_t *)ndarray->array; mp_float_t *array = (mp_float_t *)ndarray->array;
carray_sort_complex_(array, ndarray->len); carray_sort_complex_(array, ndarray->len);
}
return MP_OBJ_FROM_PTR(ndarray); return MP_OBJ_FROM_PTR(ndarray);
} }

View file

@ -33,7 +33,7 @@
#include "user/user.h" #include "user/user.h"
#include "utils/utils.h" #include "utils/utils.h"
#define ULAB_VERSION 6.0.6 #define ULAB_VERSION 6.0.7
#define xstr(s) str(s) #define xstr(s) str(s)
#define str(s) #s #define str(s) #s

View file

@ -6,6 +6,12 @@ version 6.0.6
Sun, 21 Jan 2023 Sun, 21 Jan 2023
version 6.0.7
treat empty arrays in sort_complex correctly
Sun, 21 Jan 2023
version 6.0.5 version 6.0.5
fix ones()/zeros() method when the amount of memory to allocate overflows fix ones()/zeros() method when the amount of memory to allocate overflows

View file

@ -7,6 +7,8 @@ dtypes = (np.uint8, np.int8, np.uint16, np.int16, np.float, np.complex)
for dtype in dtypes: for dtype in dtypes:
print(np.sort_complex(np.array(range(5, 0, -1), dtype=dtype))) 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() print()
n = 6 n = 6

View file

@ -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([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([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([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([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([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([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+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) 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)