Merge branch 'master' into complex-fix
This commit is contained in:
commit
fdf23c9956
12 changed files with 541 additions and 47 deletions
|
|
@ -152,6 +152,9 @@ static const mp_rom_map_elem_t ulab_numpy_globals_table[] = {
|
|||
#if ULAB_NUMPY_HAS_CONCATENATE
|
||||
{ MP_ROM_QSTR(MP_QSTR_concatenate), (mp_obj_t)&create_concatenate_obj },
|
||||
#endif
|
||||
#if ULAB_NUMPY_HAS_DELETE
|
||||
{ MP_ROM_QSTR(MP_QSTR_delete), (mp_obj_t)&transform_delete_obj },
|
||||
#endif
|
||||
#if ULAB_NUMPY_HAS_DIAG
|
||||
#if ULAB_MAX_DIMS > 1
|
||||
{ MP_ROM_QSTR(MP_QSTR_diag), (mp_obj_t)&create_diag_obj },
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
#include "../ulab.h"
|
||||
#include "../ulab_tools.h"
|
||||
#include "carray/carray_tools.h"
|
||||
#include "numerical.h"
|
||||
#include "transform.h"
|
||||
|
||||
#if ULAB_NUMPY_HAS_COMPRESS
|
||||
|
|
@ -33,8 +34,13 @@ static mp_obj_t transform_compress(size_t n_args, const mp_obj_t *pos_args, mp_m
|
|||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
mp_obj_t condition = args[0].u_obj;
|
||||
|
||||
if(!mp_obj_is_type(args[1].u_obj, &ulab_ndarray_type)) {
|
||||
mp_raise_TypeError(translate("wrong input type"));
|
||||
}
|
||||
ndarray_obj_t *ndarray = MP_OBJ_TO_PTR(args[1].u_obj);
|
||||
uint8_t *array = (uint8_t *)ndarray->array;
|
||||
|
||||
mp_obj_t axis = args[2].u_obj;
|
||||
|
||||
size_t len = MP_OBJ_SMALL_INT_VALUE(mp_obj_len_maybe(condition));
|
||||
|
|
@ -62,7 +68,6 @@ static mp_obj_t transform_compress(size_t n_args, const mp_obj_t *pos_args, mp_m
|
|||
iterable = mp_getiter(condition, &iter_buf);
|
||||
|
||||
ndarray_obj_t *result = NULL;
|
||||
uint8_t *rarray = NULL;
|
||||
|
||||
size_t *shape = m_new(size_t, ULAB_MAX_DIMS);
|
||||
memcpy(shape, ndarray->shape, ULAB_MAX_DIMS * sizeof(size_t));
|
||||
|
|
@ -77,7 +82,6 @@ static mp_obj_t transform_compress(size_t n_args, const mp_obj_t *pos_args, mp_m
|
|||
|
||||
if(axis == mp_const_none) {
|
||||
result = ndarray_new_linear_array(true_count, ndarray->dtype);
|
||||
rarray = (uint8_t *)result->array;
|
||||
memset(rstrides, 0, ndarray->ndim * sizeof(int32_t));
|
||||
rstrides[ULAB_MAX_DIMS - 1] = ndarray->itemsize;
|
||||
rshape[ULAB_MAX_DIMS - 1] = 0;
|
||||
|
|
@ -85,7 +89,6 @@ static mp_obj_t transform_compress(size_t n_args, const mp_obj_t *pos_args, mp_m
|
|||
rshape[shift_ax] = true_count;
|
||||
|
||||
result = ndarray_new_dense_ndarray(ndarray->ndim, rshape, ndarray->dtype);
|
||||
rarray = (uint8_t *)result->array;
|
||||
|
||||
SWAP(size_t, shape[shift_ax], shape[ULAB_MAX_DIMS - 1]);
|
||||
SWAP(size_t, rshape[shift_ax], rshape[ULAB_MAX_DIMS - 1]);
|
||||
|
|
@ -95,6 +98,8 @@ static mp_obj_t transform_compress(size_t n_args, const mp_obj_t *pos_args, mp_m
|
|||
SWAP(int32_t, rstrides[shift_ax], rstrides[ULAB_MAX_DIMS - 1]);
|
||||
}
|
||||
|
||||
uint8_t *rarray = (uint8_t *)result->array;
|
||||
|
||||
#if ULAB_MAX_DIMS > 3
|
||||
size_t i = 0;
|
||||
do {
|
||||
|
|
@ -151,6 +156,180 @@ static mp_obj_t transform_compress(size_t n_args, const mp_obj_t *pos_args, mp_m
|
|||
MP_DEFINE_CONST_FUN_OBJ_KW(transform_compress_obj, 2, transform_compress);
|
||||
#endif /* ULAB_NUMPY_HAS_COMPRESS */
|
||||
|
||||
#if ULAB_NUMPY_HAS_DELETE
|
||||
static mp_obj_t transform_delete(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_rom_obj = mp_const_none } },
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_rom_obj = mp_const_none } },
|
||||
{ MP_QSTR_axis, MP_ARG_KW_ONLY | MP_ARG_OBJ, { .u_rom_obj = mp_const_none } },
|
||||
};
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
if(!mp_obj_is_type(args[0].u_obj, &ulab_ndarray_type)) {
|
||||
mp_raise_TypeError(translate("first argument must be an ndarray"));
|
||||
}
|
||||
ndarray_obj_t *ndarray = MP_OBJ_TO_PTR(args[0].u_obj);
|
||||
uint8_t *array = (uint8_t *)ndarray->array;
|
||||
|
||||
mp_obj_t indices = args[1].u_obj;
|
||||
|
||||
mp_obj_t axis = args[2].u_obj;
|
||||
|
||||
int8_t shift_ax;
|
||||
|
||||
size_t axis_len;
|
||||
|
||||
if(axis != mp_const_none) {
|
||||
int8_t ax = tools_get_axis(axis, ndarray->ndim);
|
||||
shift_ax = ULAB_MAX_DIMS - ndarray->ndim + ax;
|
||||
axis_len = ndarray->shape[shift_ax];
|
||||
} else {
|
||||
axis_len = ndarray->len;
|
||||
}
|
||||
|
||||
size_t index_len;
|
||||
if(mp_obj_is_int(indices)) {
|
||||
index_len = 1;
|
||||
} else {
|
||||
if(mp_obj_len_maybe(indices) == MP_OBJ_NULL) {
|
||||
mp_raise_TypeError(translate("wrong index type"));
|
||||
}
|
||||
index_len = MP_OBJ_SMALL_INT_VALUE(mp_obj_len_maybe(indices));
|
||||
}
|
||||
|
||||
if(index_len > axis_len) {
|
||||
mp_raise_ValueError(translate("wrong length of index array"));
|
||||
}
|
||||
|
||||
size_t *index_array = m_new(size_t, index_len);
|
||||
|
||||
if(mp_obj_is_int(indices)) {
|
||||
ssize_t value = (ssize_t)mp_obj_get_int(indices);
|
||||
if(value < 0) {
|
||||
value += axis_len;
|
||||
}
|
||||
if((value < 0) || (value > (ssize_t)axis_len)) {
|
||||
mp_raise_ValueError(translate("index is out of bounds"));
|
||||
} else {
|
||||
*index_array++ = (size_t)value;
|
||||
}
|
||||
} else {
|
||||
mp_obj_iter_buf_t iter_buf;
|
||||
mp_obj_t item, iterable = mp_getiter(indices, &iter_buf);
|
||||
while((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) {
|
||||
ssize_t value = (ssize_t)mp_obj_get_int(item);
|
||||
if(value < 0) {
|
||||
value += axis_len;
|
||||
}
|
||||
if((value < 0) || (value > (ssize_t)axis_len)) {
|
||||
mp_raise_ValueError(translate("index is out of bounds"));
|
||||
} else {
|
||||
*index_array++ = (size_t)value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// sort the array, since it is not guaranteed that the input is sorted
|
||||
HEAPSORT1(size_t, index_array, 1, index_len);
|
||||
|
||||
size_t *shape = m_new(size_t, ULAB_MAX_DIMS);
|
||||
memcpy(shape, ndarray->shape, ULAB_MAX_DIMS * sizeof(size_t));
|
||||
|
||||
size_t *rshape = m_new(size_t, ULAB_MAX_DIMS);
|
||||
memcpy(rshape, ndarray->shape, ULAB_MAX_DIMS * sizeof(size_t));
|
||||
|
||||
int32_t *strides = m_new(int32_t, ULAB_MAX_DIMS);
|
||||
memcpy(strides, ndarray->strides, ULAB_MAX_DIMS * sizeof(int32_t));
|
||||
|
||||
int32_t *rstrides = m_new(int32_t, ULAB_MAX_DIMS);
|
||||
|
||||
ndarray_obj_t *result = NULL;
|
||||
|
||||
if(axis == mp_const_none) {
|
||||
result = ndarray_new_linear_array(ndarray->len - index_len, ndarray->dtype);
|
||||
memset(rstrides, 0, ndarray->ndim * sizeof(int32_t));
|
||||
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;
|
||||
|
||||
result = ndarray_new_dense_ndarray(ndarray->ndim, rshape, ndarray->dtype);
|
||||
|
||||
SWAP(size_t, shape[shift_ax], shape[ULAB_MAX_DIMS - 1]);
|
||||
SWAP(size_t, rshape[shift_ax], rshape[ULAB_MAX_DIMS - 1]);
|
||||
SWAP(int32_t, strides[shift_ax], strides[ULAB_MAX_DIMS - 1]);
|
||||
|
||||
memcpy(rstrides, result->strides, ULAB_MAX_DIMS * sizeof(int32_t));
|
||||
SWAP(int32_t, rstrides[shift_ax], rstrides[ULAB_MAX_DIMS - 1]);
|
||||
}
|
||||
|
||||
uint8_t *rarray = (uint8_t *)result->array;
|
||||
index_array -= index_len;
|
||||
size_t count = 0;
|
||||
|
||||
#if ULAB_MAX_DIMS > 3
|
||||
size_t i = 0;
|
||||
do {
|
||||
#endif
|
||||
#if ULAB_MAX_DIMS > 2
|
||||
size_t j = 0;
|
||||
do {
|
||||
#endif
|
||||
#if ULAB_MAX_DIMS > 1
|
||||
size_t k = 0;
|
||||
do {
|
||||
#endif
|
||||
size_t l = 0;
|
||||
do {
|
||||
if(count == *index_array) {
|
||||
index_array++;
|
||||
} else {
|
||||
memcpy(rarray, array, ndarray->itemsize);
|
||||
rarray += rstrides[ULAB_MAX_DIMS - 1];
|
||||
}
|
||||
array += strides[ULAB_MAX_DIMS - 1];
|
||||
l++;
|
||||
count++;
|
||||
} while(l < shape[ULAB_MAX_DIMS - 1]);
|
||||
if(axis != mp_const_none) {
|
||||
index_array -= index_len;
|
||||
count = 0;
|
||||
}
|
||||
#if ULAB_MAX_DIMS > 1
|
||||
array -= strides[ULAB_MAX_DIMS - 1] * shape[ULAB_MAX_DIMS - 1];
|
||||
array += strides[ULAB_MAX_DIMS - 2];
|
||||
rarray -= rstrides[ULAB_MAX_DIMS - 1] * rshape[ULAB_MAX_DIMS - 1];
|
||||
rarray += rstrides[ULAB_MAX_DIMS - 2];
|
||||
k++;
|
||||
} while(k < shape[ULAB_MAX_DIMS - 2]);
|
||||
#endif
|
||||
#if ULAB_MAX_DIMS > 2
|
||||
array -= strides[ULAB_MAX_DIMS - 2] * shape[ULAB_MAX_DIMS - 2];
|
||||
array += strides[ULAB_MAX_DIMS - 3];
|
||||
rarray -= rstrides[ULAB_MAX_DIMS - 2] * rshape[ULAB_MAX_DIMS - 2];
|
||||
rarray += rstrides[ULAB_MAX_DIMS - 3];
|
||||
j++;
|
||||
} while(j < shape[ULAB_MAX_DIMS - 3]);
|
||||
#endif
|
||||
#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];
|
||||
i++;
|
||||
} while(i < shape[ULAB_MAX_DIMS - 4]);
|
||||
#endif
|
||||
|
||||
return MP_OBJ_FROM_PTR(result);
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(transform_delete_obj, 2, transform_delete);
|
||||
#endif /* ULAB_NUMPY_HAS_DELETE */
|
||||
|
||||
|
||||
#if ULAB_MAX_DIMS > 1
|
||||
#if ULAB_NUMPY_HAS_DOT
|
||||
//| def dot(m1: ulab.numpy.ndarray, m2: ulab.numpy.ndarray) -> Union[ulab.numpy.ndarray, _float]:
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@
|
|||
|
||||
#include "../ulab.h"
|
||||
#include "../ulab_tools.h"
|
||||
#include "transform.h"
|
||||
|
||||
MP_DECLARE_CONST_FUN_OBJ_KW(transform_compress_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ_KW(transform_delete_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ_2(transform_dot_obj);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
#include "user/user.h"
|
||||
#include "utils/utils.h"
|
||||
|
||||
#define ULAB_VERSION 4.0.1
|
||||
#define ULAB_VERSION 4.1.1
|
||||
#define xstr(s) str(s)
|
||||
#define str(s) #s
|
||||
|
||||
|
|
|
|||
|
|
@ -438,6 +438,10 @@
|
|||
#define ULAB_NUMPY_HAS_CROSS (1)
|
||||
#endif
|
||||
|
||||
#ifndef ULAB_NUMPY_HAS_DELETE
|
||||
#define ULAB_NUMPY_HAS_DELETE (1)
|
||||
#endif
|
||||
|
||||
#ifndef ULAB_NUMPY_HAS_DIFF
|
||||
#define ULAB_NUMPY_HAS_DIFF (1)
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ copyright = '2019-2022, Zoltán Vörös and contributors'
|
|||
author = 'Zoltán Vörös'
|
||||
|
||||
# The full version, including alpha/beta/rc tags
|
||||
release = '4.0.0'
|
||||
release = '4.1.0'
|
||||
|
||||
|
||||
# -- General configuration ---------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -15,32 +15,33 @@ the firmware was compiled with complex support.
|
|||
7. `numpy.compress\* <#compress>`__
|
||||
8. `numpy.conjugate\* <#conjugate>`__
|
||||
9. `numpy.convolve\* <#convolve>`__
|
||||
10. `numpy.diff <#diff>`__
|
||||
11. `numpy.dot <#dot>`__
|
||||
12. `numpy.equal <#equal>`__
|
||||
13. `numpy.flip\* <#flip>`__
|
||||
14. `numpy.imag\* <#imag>`__
|
||||
15. `numpy.interp <#interp>`__
|
||||
16. `numpy.isfinite <#isfinite>`__
|
||||
17. `numpy.isinf <#isinf>`__
|
||||
18. `numpy.max <#max>`__
|
||||
19. `numpy.maximum <#maximum>`__
|
||||
20. `numpy.mean <#mean>`__
|
||||
21. `numpy.median <#median>`__
|
||||
22. `numpy.min <#min>`__
|
||||
23. `numpy.minimum <#minimum>`__
|
||||
24. `numpy.not_equal <#equal>`__
|
||||
25. `numpy.polyfit <#polyfit>`__
|
||||
26. `numpy.polyval <#polyval>`__
|
||||
27. `numpy.real\* <#real>`__
|
||||
28. `numpy.roll <#roll>`__
|
||||
29. `numpy.sort <#sort>`__
|
||||
30. `numpy.sort_complex\* <#sort_complex>`__
|
||||
31. `numpy.std <#std>`__
|
||||
32. `numpy.sum <#sum>`__
|
||||
33. `numpy.trace <#trace>`__
|
||||
34. `numpy.trapz <#trapz>`__
|
||||
35. `numpy.where <#where>`__
|
||||
10. `numpy.delete <#delete>`__
|
||||
11. `numpy.diff <#diff>`__
|
||||
12. `numpy.dot <#dot>`__
|
||||
13. `numpy.equal <#equal>`__
|
||||
14. `numpy.flip\* <#flip>`__
|
||||
15. `numpy.imag\* <#imag>`__
|
||||
16. `numpy.interp <#interp>`__
|
||||
17. `numpy.isfinite <#isfinite>`__
|
||||
18. `numpy.isinf <#isinf>`__
|
||||
19. `numpy.max <#max>`__
|
||||
20. `numpy.maximum <#maximum>`__
|
||||
21. `numpy.mean <#mean>`__
|
||||
22. `numpy.median <#median>`__
|
||||
23. `numpy.min <#min>`__
|
||||
24. `numpy.minimum <#minimum>`__
|
||||
25. `numpy.not_equal <#equal>`__
|
||||
26. `numpy.polyfit <#polyfit>`__
|
||||
27. `numpy.polyval <#polyval>`__
|
||||
28. `numpy.real\* <#real>`__
|
||||
29. `numpy.roll <#roll>`__
|
||||
30. `numpy.sort <#sort>`__
|
||||
31. `numpy.sort_complex\* <#sort_complex>`__
|
||||
32. `numpy.std <#std>`__
|
||||
33. `numpy.sum <#sum>`__
|
||||
34. `numpy.trace <#trace>`__
|
||||
35. `numpy.trapz <#trapz>`__
|
||||
36. `numpy.where <#where>`__
|
||||
|
||||
all
|
||||
---
|
||||
|
|
@ -412,6 +413,67 @@ accept complex arrays.
|
|||
|
||||
|
||||
|
||||
delete
|
||||
------
|
||||
|
||||
``numpy``:
|
||||
https://docs.scipy.org/doc/numpy/reference/generated/numpy.delete.html
|
||||
|
||||
The function returns a new array with sub-arrays along an axis deleted.
|
||||
It takes two positional arguments, the array, and the indices, which
|
||||
will be removed, as well as the ``axis`` keyword argument with a default
|
||||
value of ``None``. If the ``axis`` is ``None``, the will be flattened
|
||||
first.
|
||||
|
||||
The second positional argument can be a scalar, or any ``micropython``
|
||||
iterable. Since ``range`` can also be passed in place of the indices,
|
||||
slicing can be emulated. If the indices are negative, the elements are
|
||||
counted from the end of the axis.
|
||||
|
||||
Note that the function creates a copy of the indices first, because it
|
||||
is not guaranteed that the indices are ordered. Keep this in mind, when
|
||||
working with large arrays.
|
||||
|
||||
.. code::
|
||||
|
||||
# code to be run in micropython
|
||||
|
||||
from ulab import numpy as np
|
||||
|
||||
a = np.array(range(25), dtype=np.uint8).reshape((5,5))
|
||||
print('a:\n', a)
|
||||
print('\naxis = 0\n', np.delete(a, 2, axis=0))
|
||||
print('\naxis = 1\n', np.delete(a, -2, axis=1))
|
||||
print('\naxis = None\n', np.delete(a, [0, 1, 2, 22]))
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
a:
|
||||
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)
|
||||
|
||||
axis = 0
|
||||
array([[0, 1, 2, 3, 4],
|
||||
[5, 6, 7, 8, 9],
|
||||
[15, 16, 17, 18, 19],
|
||||
[20, 21, 22, 23, 24]], dtype=uint8)
|
||||
|
||||
axis = 1
|
||||
array([[0, 1, 2, 4],
|
||||
[5, 6, 7, 9],
|
||||
[10, 11, 12, 14],
|
||||
[15, 16, 17, 19],
|
||||
[20, 21, 22, 24]], dtype=uint8)
|
||||
|
||||
axis = None
|
||||
array([3, 4, 5, ..., 21, 23, 24], dtype=uint8)
|
||||
|
||||
|
||||
|
||||
|
||||
diff
|
||||
----
|
||||
|
||||
|
|
|
|||
|
|
@ -34,8 +34,8 @@
|
|||
"execution_count": 1,
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2022-01-07T19:45:28.079350Z",
|
||||
"start_time": "2022-01-07T19:45:28.073911Z"
|
||||
"end_time": "2022-01-12T16:41:02.299473Z",
|
||||
"start_time": "2022-01-12T16:41:02.282389Z"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
|
|
@ -52,8 +52,8 @@
|
|||
"execution_count": 2,
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2022-01-07T19:45:28.654136Z",
|
||||
"start_time": "2022-01-07T19:45:28.634610Z"
|
||||
"end_time": "2022-01-12T16:41:02.475299Z",
|
||||
"start_time": "2022-01-12T16:41:02.401569Z"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
|
|
@ -241,6 +241,7 @@
|
|||
"1. [numpy.compress*](#compress)\n",
|
||||
"1. [numpy.conjugate*](#conjugate)\n",
|
||||
"1. [numpy.convolve*](#convolve)\n",
|
||||
"1. [numpy.delete](#delete)\n",
|
||||
"1. [numpy.diff](#diff)\n",
|
||||
"1. [numpy.dot](#dot)\n",
|
||||
"1. [numpy.equal](#equal)\n",
|
||||
|
|
@ -738,6 +739,74 @@
|
|||
"print(np.convolve(x, y))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## delete\n",
|
||||
"\n",
|
||||
"`numpy`: https://docs.scipy.org/doc/numpy/reference/generated/numpy.delete.html\n",
|
||||
"\n",
|
||||
"The function returns a new array with sub-arrays along an axis deleted. It takes two positional arguments, the array, and the indices, which will be removed, as well as the `axis` keyword argument with a default value of `None`. If the `axis` is `None`, the will be flattened first. \n",
|
||||
"\n",
|
||||
"The second positional argument can be a scalar, or any `micropython` iterable. Since `range` can also be passed in place of the indices, slicing can be emulated. If the indices are negative, the elements are counted from the end of the axis.\n",
|
||||
"\n",
|
||||
"Note that the function creates a copy of the indices first, because it is not guaranteed that the indices are ordered. Keep this in mind, when working with large arrays."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2022-01-12T17:03:29.099233Z",
|
||||
"start_time": "2022-01-12T17:03:29.084117Z"
|
||||
}
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"a:\n",
|
||||
" array([[0, 1, 2, 3, 4],\n",
|
||||
" [5, 6, 7, 8, 9],\n",
|
||||
" [10, 11, 12, 13, 14],\n",
|
||||
" [15, 16, 17, 18, 19],\n",
|
||||
" [20, 21, 22, 23, 24]], dtype=uint8)\n",
|
||||
"\n",
|
||||
"axis = 0\n",
|
||||
" array([[0, 1, 2, 3, 4],\n",
|
||||
" [5, 6, 7, 8, 9],\n",
|
||||
" [15, 16, 17, 18, 19],\n",
|
||||
" [20, 21, 22, 23, 24]], dtype=uint8)\n",
|
||||
"\n",
|
||||
"axis = 1\n",
|
||||
" array([[0, 1, 2, 4],\n",
|
||||
" [5, 6, 7, 9],\n",
|
||||
" [10, 11, 12, 14],\n",
|
||||
" [15, 16, 17, 19],\n",
|
||||
" [20, 21, 22, 24]], dtype=uint8)\n",
|
||||
"\n",
|
||||
"axis = None\n",
|
||||
" array([3, 4, 5, ..., 21, 23, 24], dtype=uint8)\n",
|
||||
"\n",
|
||||
"\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"%%micropython -unix 1\n",
|
||||
"\n",
|
||||
"from ulab import numpy as np\n",
|
||||
"\n",
|
||||
"a = np.array(range(25), dtype=np.uint8).reshape((5,5))\n",
|
||||
"print('a:\\n', a)\n",
|
||||
"print('\\naxis = 0\\n', np.delete(a, 2, axis=0))\n",
|
||||
"print('\\naxis = 1\\n', np.delete(a, -2, axis=1))\n",
|
||||
"print('\\naxis = None\\n', np.delete(a, [0, 1, 2, 22]))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
|
|
|
|||
|
|
@ -1,9 +1,15 @@
|
|||
Mon, 10 Jan 2022
|
||||
Wed, 12 Jan 2022
|
||||
|
||||
version 4.0.1
|
||||
version 4.1.1
|
||||
|
||||
fix complex printout for long arrays
|
||||
|
||||
Wed, 12 Jan 2022
|
||||
|
||||
version 4.1.0
|
||||
|
||||
add numpy.delete
|
||||
|
||||
Sat, 8 Jan 2022
|
||||
|
||||
version 4.0.0
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@
|
|||
"execution_count": 1,
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2022-01-07T18:24:12.745063Z",
|
||||
"start_time": "2022-01-07T18:24:12.733067Z"
|
||||
"end_time": "2022-01-12T17:00:33.582729Z",
|
||||
"start_time": "2022-01-12T17:00:33.566591Z"
|
||||
}
|
||||
},
|
||||
"outputs": [
|
||||
|
|
@ -61,7 +61,7 @@
|
|||
"author = 'Zoltán Vörös'\n",
|
||||
"\n",
|
||||
"# The full version, including alpha/beta/rc tags\n",
|
||||
"release = '4.0.0'\n",
|
||||
"release = '4.1.0'\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# -- General configuration ---------------------------------------------------\n",
|
||||
|
|
@ -215,11 +215,11 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"execution_count": 1,
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2022-01-07T18:24:27.671415Z",
|
||||
"start_time": "2022-01-07T18:24:24.933205Z"
|
||||
"end_time": "2022-01-12T17:03:49.038101Z",
|
||||
"start_time": "2022-01-12T17:03:48.886617Z"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
|
|
@ -256,11 +256,11 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"execution_count": 2,
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2022-01-07T19:52:29.910335Z",
|
||||
"start_time": "2022-01-07T19:52:28.432391Z"
|
||||
"end_time": "2022-01-12T17:03:52.084601Z",
|
||||
"start_time": "2022-01-12T17:03:50.354118Z"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
|
|
|
|||
26
tests/2d/numpy/delete.py
Normal file
26
tests/2d/numpy/delete.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
try:
|
||||
from ulab import numpy as np
|
||||
except:
|
||||
import numpy as np
|
||||
|
||||
np.set_printoptions(threshold=200)
|
||||
|
||||
dtypes = (np.uint8, np.int8, np.uint16, np.int16, np.float)
|
||||
|
||||
for dtype in dtypes:
|
||||
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, [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))
|
||||
145
tests/2d/numpy/delete.py.exp
Normal file
145
tests/2d/numpy/delete.py.exp
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
array([[0, 1, 2, 3, 4],
|
||||
[15, 16, 17, 18, 19],
|
||||
[20, 21, 22, 23, 24]], dtype=uint8)
|
||||
array([[0, 3, 4],
|
||||
[5, 8, 9],
|
||||
[10, 13, 14],
|
||||
[15, 18, 19],
|
||||
[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],
|
||||
[15, 16, 17, 18, 19],
|
||||
[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],
|
||||
[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, 2, 3, 4],
|
||||
[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)
|
||||
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=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)
|
||||
array([[0, 1, 2, 3, 4],
|
||||
[5, 6, 7, 8, 9],
|
||||
[15, 16, 17, 18, 19],
|
||||
[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=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)
|
||||
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, 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],
|
||||
[5, 6, 7, 8, 9],
|
||||
[15, 16, 17, 18, 19],
|
||||
[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=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=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=int8)
|
||||
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, 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],
|
||||
[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=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],
|
||||
[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, 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, 23.0, 24.0], dtype=float64)
|
||||
Loading…
Reference in a new issue