Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix delete error
  • Loading branch information
v923z committed Apr 22, 2022
commit a3dce3b6c2db6e610d8f5ed6135f02a185c99ddd
8 changes: 4 additions & 4 deletions code/numpy/transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ static mp_obj_t transform_delete(size_t n_args, const mp_obj_t *pos_args, mp_map
result = ndarray_new_linear_array(ndarray->len - index_len, ndarray->dtype);
rstrides[ULAB_MAX_DIMS - 1] = ndarray->itemsize;
memset(rshape, 0, sizeof(size_t) * ULAB_MAX_DIMS);
// rshape[ULAB_MAX_DIMS - 1] = 0;
} else {
rshape[shift_ax] = shape[shift_ax] - index_len;

Expand Down Expand Up @@ -323,13 +322,14 @@ static mp_obj_t transform_delete(size_t n_args, const mp_obj_t *pos_args, mp_map
#if ULAB_MAX_DIMS > 3
array -= strides[ULAB_MAX_DIMS - 3] * shape[ULAB_MAX_DIMS - 3];
array += strides[ULAB_MAX_DIMS - 4];
rarray -= rstrides[ULAB_MAX_DIMS - 2] * rshape[ULAB_MAX_DIMS - 2];
rarray += rstrides[ULAB_MAX_DIMS - 3];
rarray -= rstrides[ULAB_MAX_DIMS - 3] * rshape[ULAB_MAX_DIMS - 3];
rarray += rstrides[ULAB_MAX_DIMS - 4];
i++;
} while(i < shape[ULAB_MAX_DIMS - 4]);
#endif

m_del(size_t, shape, ULAB_MAX_DIMS);
// TODO: deleting shape generates a seg fault
// m_del(size_t, shape, ULAB_MAX_DIMS);
m_del(size_t, rshape, ULAB_MAX_DIMS);
m_del(int32_t, strides, ULAB_MAX_DIMS);
m_del(int32_t, rstrides, ULAB_MAX_DIMS);
Expand Down
4 changes: 4 additions & 0 deletions tests/2d/numpy/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
print(np.delete(a, [1, 2], axis=1))
print(np.delete(a, [1, 5, 10]))

for dtype in dtypes:
a = np.array(range(25), dtype=dtype).reshape((5,5))
print(np.delete(a, 2, axis=0))
print(np.delete(a, 2, axis=1))
print(np.delete(a, 2))

for dtype in dtypes:
a = np.array(range(25), dtype=dtype).reshape((5,5))
print(np.delete(a, -3, axis=0))
print(np.delete(a, -3, axis=1))
print(np.delete(a, -3))
128 changes: 64 additions & 64 deletions tests/2d/numpy/delete.py.exp
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,51 @@ array([[0, 3, 4],
[20, 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],
[15, 16, 17, 18, 19],
[20, 21, 22, 23, 24]], dtype=uint8)
array([[0, 1, 3, 4],
[5, 6, 8, 9],
[10, 11, 13, 14],
[15, 16, 18, 19],
[20, 21, 23, 24]], dtype=uint8)
array([0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24], dtype=uint8)
[20, 21, 22, 23, 24]], dtype=int8)
array([[0, 3, 4],
[5, 8, 9],
[10, 13, 14],
[15, 18, 19],
[20, 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],
[15, 16, 17, 18, 19],
[20, 21, 22, 23, 24]], dtype=uint8)
array([[0, 1, 3, 4],
[5, 6, 8, 9],
[10, 11, 13, 14],
[15, 16, 18, 19],
[20, 21, 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, 23, 24], dtype=uint8)
[20, 21, 22, 23, 24]], dtype=uint16)
array([[0, 3, 4],
[5, 8, 9],
[10, 13, 14],
[15, 18, 19],
[20, 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],
[15, 16, 17, 18, 19],
[20, 21, 22, 23, 24]], dtype=int8)
[20, 21, 22, 23, 24]], dtype=int16)
array([[0, 3, 4],
[5, 8, 9],
[10, 13, 14],
[15, 18, 19],
[20, 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)
[20, 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.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)
array([[0.0, 3.0, 4.0],
[5.0, 8.0, 9.0],
[10.0, 13.0, 14.0],
[15.0, 18.0, 19.0],
[20.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, 1, 2, 3, 4],
[5, 6, 7, 8, 9],
[15, 16, 17, 18, 19],
[20, 21, 22, 23, 24]], dtype=int8)
[20, 21, 22, 23, 24]], dtype=uint8)
array([[0, 1, 3, 4],
[5, 6, 8, 9],
[10, 11, 13, 14],
[15, 16, 18, 19],
[20, 21, 23, 24]], dtype=int8)
array([0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24], dtype=int8)
[20, 21, 23, 24]], dtype=uint8)
array([0, 1, 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],
[5, 6, 7, 8, 9],
[15, 16, 17, 18, 19],
Expand All @@ -55,16 +62,7 @@ array([[0, 1, 3, 4],
[10, 11, 13, 14],
[15, 16, 18, 19],
[20, 21, 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, 23, 24], dtype=int8)
array([[0, 1, 2, 3, 4],
[15, 16, 17, 18, 19],
[20, 21, 22, 23, 24]], dtype=uint16)
array([[0, 3, 4],
[5, 8, 9],
[10, 13, 14],
[15, 18, 19],
[20, 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, 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],
[5, 6, 7, 8, 9],
[15, 16, 17, 18, 19],
Expand All @@ -78,32 +76,53 @@ array([0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21
array([[0, 1, 2, 3, 4],
[5, 6, 7, 8, 9],
[15, 16, 17, 18, 19],
[20, 21, 22, 23, 24]], dtype=uint16)
[20, 21, 22, 23, 24]], dtype=int16)
array([[0, 1, 3, 4],
[5, 6, 8, 9],
[10, 11, 13, 14],
[15, 16, 18, 19],
[20, 21, 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, 23, 24], dtype=uint16)
[20, 21, 23, 24]], dtype=int16)
array([0, 1, 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],
[5.0, 6.0, 7.0, 8.0, 9.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, 3.0, 4.0],
[5.0, 6.0, 8.0, 9.0],
[10.0, 11.0, 13.0, 14.0],
[15.0, 16.0, 18.0, 19.0],
[20.0, 21.0, 23.0, 24.0]], dtype=float64)
array([0.0, 1.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],
[20, 21, 22, 23, 24]], dtype=int16)
array([[0, 3, 4],
[5, 8, 9],
[10, 13, 14],
[15, 18, 19],
[20, 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)
[20, 21, 22, 23, 24]], dtype=uint8)
array([[0, 1, 3, 4],
[5, 6, 8, 9],
[10, 11, 13, 14],
[15, 16, 18, 19],
[20, 21, 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, 23, 24], dtype=uint8)
array([[0, 1, 2, 3, 4],
[5, 6, 7, 8, 9],
[15, 16, 17, 18, 19],
[20, 21, 22, 23, 24]], dtype=int16)
[20, 21, 22, 23, 24]], dtype=int8)
array([[0, 1, 3, 4],
[5, 6, 8, 9],
[10, 11, 13, 14],
[15, 16, 18, 19],
[20, 21, 23, 24]], dtype=int16)
array([0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24], dtype=int16)
[20, 21, 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, 23, 24], dtype=int8)
array([[0, 1, 2, 3, 4],
[5, 6, 7, 8, 9],
[15, 16, 17, 18, 19],
[20, 21, 22, 23, 24]], dtype=uint16)
array([[0, 1, 3, 4],
[5, 6, 8, 9],
[10, 11, 13, 14],
[15, 16, 18, 19],
[20, 21, 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, 23, 24], dtype=uint16)
array([[0, 1, 2, 3, 4],
[5, 6, 7, 8, 9],
[15, 16, 17, 18, 19],
Expand All @@ -114,25 +133,6 @@ array([[0, 1, 3, 4],
[15, 16, 18, 19],
[20, 21, 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, 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)
array([[0.0, 3.0, 4.0],
[5.0, 8.0, 9.0],
[10.0, 13.0, 14.0],
[15.0, 18.0, 19.0],
[20.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],
[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, 3.0, 4.0],
[5.0, 6.0, 8.0, 9.0],
[10.0, 11.0, 13.0, 14.0],
[15.0, 16.0, 18.0, 19.0],
[20.0, 21.0, 23.0, 24.0]], dtype=float64)
array([0.0, 1.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, 1.0, 2.0, 3.0, 4.0],
[5.0, 6.0, 7.0, 8.0, 9.0],
[15.0, 16.0, 17.0, 18.0, 19.0],
Expand Down