diff --git a/code/numpy/transform.c b/code/numpy/transform.c index b6b1bebc..b77364ba 100644 --- a/code/numpy/transform.c +++ b/code/numpy/transform.c @@ -204,6 +204,11 @@ static mp_obj_t transform_delete(size_t n_args, const mp_obj_t *pos_args, mp_map mp_raise_TypeError(MP_ERROR_TEXT("wrong index type")); } index_len = MP_OBJ_SMALL_INT_VALUE(mp_obj_len_maybe(indices)); + if (index_len == 0){ + // if the second positional argument is empty + // return the original array + return MP_OBJ_FROM_PTR(ndarray); + } } if(index_len > axis_len) { diff --git a/code/ulab.c b/code/ulab.c index 5c5067bd..5ff4e502 100644 --- a/code/ulab.c +++ b/code/ulab.c @@ -33,7 +33,7 @@ #include "user/user.h" #include "utils/utils.h" -#define ULAB_VERSION 6.4.2 +#define ULAB_VERSION 6.4.3 #define xstr(s) str(s) #define str(s) #s diff --git a/docs/ulab-change-log.md b/docs/ulab-change-log.md index 4d389f9a..3650141f 100644 --- a/docs/ulab-change-log.md +++ b/docs/ulab-change-log.md @@ -1,3 +1,9 @@ +Mon, 25 Dec 2023 + +version 6.4.3 + + fix the 'np.delete' error that occurs when passing an empty iterable object as the second positional argument (#653) + Thu, 11 Dec 2023 version 6.4.2 diff --git a/tests/2d/numpy/delete.py b/tests/2d/numpy/delete.py index c7718ad5..fdb96a87 100644 --- a/tests/2d/numpy/delete.py +++ b/tests/2d/numpy/delete.py @@ -11,7 +11,9 @@ a = np.array(range(25), dtype=dtype).reshape((5,5)) print(np.delete(a, [1, 2], axis=0)) print(np.delete(a, [1, 2], axis=1)) + print(np.delete(a, [], axis=1)) print(np.delete(a, [1, 5, 10])) + print(np.delete(a, [])) for dtype in dtypes: a = np.array(range(25), dtype=dtype).reshape((5,5)) diff --git a/tests/2d/numpy/delete.py.exp b/tests/2d/numpy/delete.py.exp index 72a2a286..e678f8dc 100644 --- a/tests/2d/numpy/delete.py.exp +++ b/tests/2d/numpy/delete.py.exp @@ -6,7 +6,17 @@ array([[0, 3, 4], [10, 13, 14], [15, 18, 19], [20, 23, 24]], dtype=uint8) +array([[0, 1, 2, 3, 4], + [5, 6, 7, 8, 9], + [10, 11, 12, 13, 14], + [15, 16, 17, 18, 19], + [20, 21, 22, 23, 24]], dtype=uint8) array([0, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24], dtype=uint8) +array([[0, 1, 2, 3, 4], + [5, 6, 7, 8, 9], + [10, 11, 12, 13, 14], + [15, 16, 17, 18, 19], + [20, 21, 22, 23, 24]], dtype=uint8) array([[0, 1, 2, 3, 4], [15, 16, 17, 18, 19], [20, 21, 22, 23, 24]], dtype=int8) @@ -15,7 +25,17 @@ array([[0, 3, 4], [10, 13, 14], [15, 18, 19], [20, 23, 24]], dtype=int8) +array([[0, 1, 2, 3, 4], + [5, 6, 7, 8, 9], + [10, 11, 12, 13, 14], + [15, 16, 17, 18, 19], + [20, 21, 22, 23, 24]], dtype=int8) array([0, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24], dtype=int8) +array([[0, 1, 2, 3, 4], + [5, 6, 7, 8, 9], + [10, 11, 12, 13, 14], + [15, 16, 17, 18, 19], + [20, 21, 22, 23, 24]], dtype=int8) array([[0, 1, 2, 3, 4], [15, 16, 17, 18, 19], [20, 21, 22, 23, 24]], dtype=uint16) @@ -24,7 +44,17 @@ array([[0, 3, 4], [10, 13, 14], [15, 18, 19], [20, 23, 24]], dtype=uint16) +array([[0, 1, 2, 3, 4], + [5, 6, 7, 8, 9], + [10, 11, 12, 13, 14], + [15, 16, 17, 18, 19], + [20, 21, 22, 23, 24]], dtype=uint16) array([0, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24], dtype=uint16) +array([[0, 1, 2, 3, 4], + [5, 6, 7, 8, 9], + [10, 11, 12, 13, 14], + [15, 16, 17, 18, 19], + [20, 21, 22, 23, 24]], dtype=uint16) array([[0, 1, 2, 3, 4], [15, 16, 17, 18, 19], [20, 21, 22, 23, 24]], dtype=int16) @@ -33,7 +63,17 @@ array([[0, 3, 4], [10, 13, 14], [15, 18, 19], [20, 23, 24]], dtype=int16) +array([[0, 1, 2, 3, 4], + [5, 6, 7, 8, 9], + [10, 11, 12, 13, 14], + [15, 16, 17, 18, 19], + [20, 21, 22, 23, 24]], dtype=int16) array([0, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24], dtype=int16) +array([[0, 1, 2, 3, 4], + [5, 6, 7, 8, 9], + [10, 11, 12, 13, 14], + [15, 16, 17, 18, 19], + [20, 21, 22, 23, 24]], dtype=int16) array([[0.0, 1.0, 2.0, 3.0, 4.0], [15.0, 16.0, 17.0, 18.0, 19.0], [20.0, 21.0, 22.0, 23.0, 24.0]], dtype=float64) @@ -42,7 +82,17 @@ array([[0.0, 3.0, 4.0], [10.0, 13.0, 14.0], [15.0, 18.0, 19.0], [20.0, 23.0, 24.0]], dtype=float64) +array([[0.0, 1.0, 2.0, 3.0, 4.0], + [5.0, 6.0, 7.0, 8.0, 9.0], + [10.0, 11.0, 12.0, 13.0, 14.0], + [15.0, 16.0, 17.0, 18.0, 19.0], + [20.0, 21.0, 22.0, 23.0, 24.0]], dtype=float64) array([0.0, 2.0, 3.0, 4.0, 6.0, 7.0, 8.0, 9.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0], dtype=float64) +array([[0.0, 1.0, 2.0, 3.0, 4.0], + [5.0, 6.0, 7.0, 8.0, 9.0], + [10.0, 11.0, 12.0, 13.0, 14.0], + [15.0, 16.0, 17.0, 18.0, 19.0], + [20.0, 21.0, 22.0, 23.0, 24.0]], dtype=float64) array([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [15, 16, 17, 18, 19],