Compare commits
2 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9f71594f47 | ||
|
|
af706e5b46 |
11 changed files with 13 additions and 264 deletions
|
|
@ -36,7 +36,7 @@ detected and handled.
|
|||
## ndarray methods
|
||||
|
||||
`ulab` implements `numpy`'s `ndarray` with the `==`, `!=`, `<`, `<=`, `>`, `>=`, `+`, `-`, `/`, `*`, `**`,
|
||||
`%`, `+=`, `-=`, `*=`, `/=`, `**=`, `%=` binary operators, and the `len`, `~`, `-`, `+`, `abs` unary operators that
|
||||
`+=`, `-=`, `*=`, `/=`, `**=` binary operators, and the `len`, `~`, `-`, `+`, `abs` unary operators that
|
||||
operate element-wise. Type-aware `ndarray`s can be initialised from any `micropython` iterable, lists of
|
||||
iterables via the `array` constructor, or by means of the `arange`, `concatenate`, `diag`, `eye`,
|
||||
`frombuffer`, `full`, `linspace`, `logspace`, `ones`, or `zeros` functions.
|
||||
|
|
|
|||
|
|
@ -1648,12 +1648,6 @@ mp_obj_t ndarray_binary_op(mp_binary_op_t _op, mp_obj_t lobj, mp_obj_t robj) {
|
|||
return ndarray_inplace_ams(lhs, rhs, rstrides, op);
|
||||
break;
|
||||
#endif
|
||||
#if NDARRAY_HAS_INPLACE_MODULO
|
||||
case MP_BINARY_OP_INPLACE_MODULO:
|
||||
COMPLEX_DTYPE_NOT_IMPLEMENTED(lhs->dtype);
|
||||
return ndarray_inplace_modulo(lhs, rhs, rstrides);
|
||||
break;
|
||||
#endif
|
||||
#if NDARRAY_HAS_INPLACE_MULTIPLY
|
||||
case MP_BINARY_OP_INPLACE_MULTIPLY:
|
||||
COMPLEX_DTYPE_NOT_IMPLEMENTED(lhs->dtype);
|
||||
|
|
|
|||
|
|
@ -1173,29 +1173,6 @@ mp_obj_t ndarray_inplace_ams(ndarray_obj_t *lhs, ndarray_obj_t *rhs, int32_t *rs
|
|||
}
|
||||
#endif /* NDARRAY_HAS_INPLACE_ADD || NDARRAY_HAS_INPLACE_MULTIPLY || NDARRAY_HAS_INPLACE_SUBTRACT */
|
||||
|
||||
|
||||
#if NDARRAY_HAS_INPLACE_MODULO
|
||||
mp_obj_t ndarray_inplace_modulo(ndarray_obj_t *lhs, ndarray_obj_t *rhs, int32_t *rstrides) {
|
||||
if((lhs->dtype != NDARRAY_FLOAT) && (rhs->dtype == NDARRAY_FLOAT)) {
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("results cannot be cast to specified type"));
|
||||
}
|
||||
if(lhs->dtype == NDARRAY_FLOAT) {
|
||||
if(rhs->dtype == NDARRAY_UINT8) {
|
||||
INLINE_MODULO_FLOAT_LOOP(lhs, uint8_t, larray, rarray, rstrides);
|
||||
} else if(rhs->dtype == NDARRAY_UINT8) {
|
||||
INLINE_MODULO_FLOAT_LOOP(lhs, int8_t, larray, rarray, rstrides);
|
||||
} else if(rhs->dtype == NDARRAY_UINT16) {
|
||||
INLINE_MODULO_FLOAT_LOOP(lhs, uint16_t, larray, rarray, rstrides);
|
||||
} else if(rhs->dtype == NDARRAY_INT16) {
|
||||
INLINE_MODULO_FLOAT_LOOP(lhs, int16_t, larray, rarray, rstrides);
|
||||
} else {
|
||||
INLINE_MODULO_FLOAT_LOOP(lhs, mp_float_t, larray, rarray, rstrides);
|
||||
}
|
||||
}
|
||||
return MP_OBJ_FROM_PTR(lhs);
|
||||
}
|
||||
#endif /* NDARRAY_HAS_INPLACE_MODULO */
|
||||
|
||||
#if NDARRAY_HAS_INPLACE_TRUE_DIVIDE
|
||||
mp_obj_t ndarray_inplace_divide(ndarray_obj_t *lhs, ndarray_obj_t *rhs, int32_t *rstrides) {
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ mp_obj_t ndarray_binary_logical(ndarray_obj_t *, ndarray_obj_t *, uint8_t , size
|
|||
mp_obj_t ndarray_binary_floor_divide(ndarray_obj_t *, ndarray_obj_t *, uint8_t , size_t *, int32_t *, int32_t *);
|
||||
|
||||
mp_obj_t ndarray_inplace_ams(ndarray_obj_t *, ndarray_obj_t *, int32_t *, uint8_t );
|
||||
mp_obj_t ndarray_inplace_modulo(ndarray_obj_t *, ndarray_obj_t *, int32_t *);
|
||||
mp_obj_t ndarray_inplace_power(ndarray_obj_t *, ndarray_obj_t *, int32_t *);
|
||||
mp_obj_t ndarray_inplace_divide(ndarray_obj_t *, ndarray_obj_t *, int32_t *);
|
||||
|
||||
|
|
@ -625,90 +624,4 @@ mp_obj_t ndarray_inplace_divide(ndarray_obj_t *, ndarray_obj_t *, int32_t *);
|
|||
j++;\
|
||||
} while(j < (results)->shape[ULAB_MAX_DIMS - 4]);\
|
||||
} while(0)
|
||||
#endif /* ULAB_MAX_DIMS == 4 */
|
||||
|
||||
|
||||
#define INPLACE_MODULO_FLOAT1(results, type_right, larray, rarray, rstrides)\
|
||||
({\
|
||||
size_t l = 0;\
|
||||
do {\
|
||||
*((mp_float_t *)larray) = MICROPY_FLOAT_C_FUN(fmod)(*((mp_float_t *)(larray)), *((type_right *)(rarray)));\
|
||||
(larray) += (results)->strides[ULAB_MAX_DIMS - 1];\
|
||||
(rarray) += (rstrides)[ULAB_MAX_DIMS - 1];\
|
||||
l++;\
|
||||
} while(l < (results)->shape[ULAB_MAX_DIMS - 1]);\
|
||||
})
|
||||
|
||||
|
||||
#if ULAB_MAX_DIMS == 1
|
||||
#define INPLACE_MODULO_FLOAT_LOOP(results, type_right, larray, rarray, rstrides) do {\
|
||||
INPLACE_MODULO_FLOAT1((results), type_right, (larray), (rarray), (rstrides));\
|
||||
} while(0)
|
||||
#endif /* ULAB_MAX_DIMS == 1 */
|
||||
|
||||
|
||||
#if ULAB_MAX_DIMS == 2
|
||||
#define INLINE_MODULO_FLOAT_LOOP(results, type_right, larray, rarray, rstrides) do {\
|
||||
size_t l = 0;\
|
||||
do {\
|
||||
INPLACE_MODULO_FLOAT1((results), type_right, (larray), (rarray), (rstrides));\
|
||||
(larray) -= (results)->strides[ULAB_MAX_DIMS - 1] * (results)->shape[ULAB_MAX_DIMS - 1];\
|
||||
(larray) += (results)->strides[ULAB_MAX_DIMS - 2];\
|
||||
(rarray) -= (rstrides)[ULAB_MAX_DIMS - 1] * (results)->shape[ULAB_MAX_DIMS - 1];\
|
||||
(rarray) += (rstrides)[ULAB_MAX_DIMS - 2];\
|
||||
l++;\
|
||||
} while(l < (results)->shape[ULAB_MAX_DIMS - 2]);\
|
||||
} while(0)
|
||||
#endif /* ULAB_MAX_DIMS == 2 */
|
||||
|
||||
#if ULAB_MAX_DIMS == 3
|
||||
#define INLINE_MODULO_FLOAT_LOOP(results, type_right, larray, rarray, rstrides) do {\
|
||||
size_t k = 0;\
|
||||
do {\
|
||||
size_t l = 0;\
|
||||
do {\
|
||||
INPLACE_MODULO_FLOAT1((results), type_right, (larray), (rarray), (rstrides));\
|
||||
(larray) -= (results)->strides[ULAB_MAX_DIMS - 1] * (results)->shape[ULAB_MAX_DIMS - 1];\
|
||||
(larray) += (results)->strides[ULAB_MAX_DIMS - 2];\
|
||||
(rarray) -= (rstrides)[ULAB_MAX_DIMS - 1] * (results)->shape[ULAB_MAX_DIMS - 1];\
|
||||
(rarray) += (rstrides)[ULAB_MAX_DIMS - 2];\
|
||||
l++;\
|
||||
} while(l < (results)->shape[ULAB_MAX_DIMS - 2]);\
|
||||
(larray) -= (results)->strides[ULAB_MAX_DIMS - 2] * (results)->shape[ULAB_MAX_DIMS - 2];\
|
||||
(larray) += (results)->strides[ULAB_MAX_DIMS - 3];\
|
||||
(rarray) -= (rstrides)[ULAB_MAX_DIMS - 2] * (results)->shape[ULAB_MAX_DIMS - 2];\
|
||||
(rarray) += (rstrides)[ULAB_MAX_DIMS - 3];\
|
||||
k++;\
|
||||
} while(k < (results)->shape[ULAB_MAX_DIMS - 3]);\
|
||||
} while(0)
|
||||
#endif /* ULAB_MAX_DIMS == 3 */
|
||||
|
||||
#if ULAB_MAX_DIMS == 4
|
||||
#define INLINE_MODULO_FLOAT_LOOP(results, type_right, larray, rarray, rstrides) do {\
|
||||
size_t j = 0;\
|
||||
do {\
|
||||
size_t k = 0;\
|
||||
do {\
|
||||
size_t l = 0;\
|
||||
do {\
|
||||
INPLACE_MODULO_FLOAT1((results), type_right, (larray), (rarray), (rstrides));\
|
||||
(larray) -= (results)->strides[ULAB_MAX_DIMS - 1] * (results)->shape[ULAB_MAX_DIMS - 1];\
|
||||
(larray) += (results)->strides[ULAB_MAX_DIMS - 2];\
|
||||
(rarray) -= (rstrides)[ULAB_MAX_DIMS - 1] * (results)->shape[ULAB_MAX_DIMS - 1];\
|
||||
(rarray) += (rstrides)[ULAB_MAX_DIMS - 2];\
|
||||
l++;\
|
||||
} while(l < (results)->shape[ULAB_MAX_DIMS - 2]);\
|
||||
(larray) -= (results)->strides[ULAB_MAX_DIMS - 2] * (results)->shape[ULAB_MAX_DIMS - 2];\
|
||||
(larray) += (results)->strides[ULAB_MAX_DIMS - 3];\
|
||||
(rarray) -= (rstrides)[ULAB_MAX_DIMS - 2] * (results)->shape[ULAB_MAX_DIMS - 2];\
|
||||
(rarray) += (rstrides)[ULAB_MAX_DIMS - 3];\
|
||||
k++;\
|
||||
} while(k < (results)->shape[ULAB_MAX_DIMS - 3]);\
|
||||
(larray) -= (results)->strides[ULAB_MAX_DIMS - 3] * (results)->shape[ULAB_MAX_DIMS - 3];\
|
||||
(larray) += (results)->strides[ULAB_MAX_DIMS - 4];\
|
||||
(rarray) -= (rstrides)[ULAB_MAX_DIMS - 3] * (results)->shape[ULAB_MAX_DIMS - 3];\
|
||||
(rarray) += (rstrides)[ULAB_MAX_DIMS - 4];\
|
||||
j++;\
|
||||
} while(j < (results)->shape[ULAB_MAX_DIMS - 4]);\
|
||||
} while(0)
|
||||
#endif /* ULAB_MAX_DIMS == 4 */
|
||||
|
|
@ -165,10 +165,6 @@
|
|||
#define NDARRAY_HAS_INPLACE_ADD (1)
|
||||
#endif
|
||||
|
||||
#ifndef NDARRAY_HAS_INPLACE_MODULO
|
||||
#define NDARRAY_HAS_INPLACE_MODU (1)
|
||||
#endif
|
||||
|
||||
#ifndef NDARRAY_HAS_INPLACE_MULTIPLY
|
||||
#define NDARRAY_HAS_INPLACE_MULTIPLY (1)
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ copyright = '2019-2025, Zoltán Vörös and contributors'
|
|||
author = 'Zoltán Vörös'
|
||||
|
||||
# The full version, including alpha/beta/rc tags
|
||||
release = '6.9.0'
|
||||
release = '6.7.3'
|
||||
|
||||
|
||||
# -- General configuration ---------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -1814,12 +1814,12 @@ array.
|
|||
Binary operators
|
||||
================
|
||||
|
||||
``ulab`` implements the ``+``, ``-``, ``*``, ``/``, ``**``, ``%``,
|
||||
``<``, ``>``, ``<=``, ``>=``, ``==``, ``!=``, ``+=``, ``-=``, ``*=``,
|
||||
``/=``, ``**=``, ``%=`` binary operators, as well as the ``AND``,
|
||||
``OR``, ``XOR`` bit-wise operators that work element-wise. Note that the
|
||||
bit-wise operators will raise an exception, if either of the operands is
|
||||
of ``float`` or ``complex`` type.
|
||||
``ulab`` implements the ``+``, ``-``, ``*``, ``/``, ``**``, ``<``,
|
||||
``>``, ``<=``, ``>=``, ``==``, ``!=``, ``+=``, ``-=``, ``*=``, ``/=``,
|
||||
``**=`` binary operators, as well as the ``AND``, ``OR``, ``XOR``
|
||||
bit-wise operators that work element-wise. Note that the bit-wise
|
||||
operators will raise an exception, if either of the operands is of
|
||||
``float`` or ``complex`` type.
|
||||
|
||||
Broadcasting is available, meaning that the two operands do not even
|
||||
have to have the same shape. If the lengths along the respective axes
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"execution_count": 1,
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2022-02-09T06:27:15.118699Z",
|
||||
|
|
@ -61,7 +61,7 @@
|
|||
"author = 'Zoltán Vörös'\n",
|
||||
"\n",
|
||||
"# The full version, including alpha/beta/rc tags\n",
|
||||
"release = '6.9.0'\n",
|
||||
"release = '6.7.3'\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# -- General configuration ---------------------------------------------------\n",
|
||||
|
|
@ -217,7 +217,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"execution_count": 2,
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2022-02-09T06:27:21.647179Z",
|
||||
|
|
@ -258,7 +258,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"execution_count": 3,
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2022-02-09T06:27:42.024028Z",
|
||||
|
|
|
|||
|
|
@ -2599,7 +2599,7 @@
|
|||
"source": [
|
||||
"# Binary operators\n",
|
||||
"\n",
|
||||
"`ulab` implements the `+`, `-`, `*`, `/`, `**`, `%`, `<`, `>`, `<=`, `>=`, `==`, `!=`, `+=`, `-=`, `*=`, `/=`, `**=`, `%=` binary operators, as well as the `AND`, `OR`, `XOR` bit-wise operators that work element-wise. Note that the bit-wise operators will raise an exception, if either of the operands is of `float` or `complex` type.\n",
|
||||
"`ulab` implements the `+`, `-`, `*`, `/`, `**`, `%`, `<`, `>`, `<=`, `>=`, `==`, `!=`, `+=`, `-=`, `*=`, `/=`, `**=` binary operators, as well as the `AND`, `OR`, `XOR` bit-wise operators that work element-wise. Note that the bit-wise operators will raise an exception, if either of the operands is of `float` or `complex` type.\n",
|
||||
"\n",
|
||||
"Broadcasting is available, meaning that the two operands do not even have to have the same shape. If the lengths along the respective axes are equal, or one of them is 1, or the axis is missing, the element-wise operation can still be carried out. \n",
|
||||
"A thorough explanation of broadcasting can be found under https://numpy.org/doc/stable/user/basics.broadcasting.html. \n",
|
||||
|
|
|
|||
|
|
@ -1,26 +0,0 @@
|
|||
try:
|
||||
from ulab import numpy as np
|
||||
except:
|
||||
import numpy as np
|
||||
|
||||
|
||||
dtypes = (np.uint8, np.int8, np.uint16, np.int16, np.float)
|
||||
|
||||
for dtype1 in dtypes:
|
||||
x1 = np.array(range(6), dtype=dtype1).reshape((2, 3))
|
||||
for dtype2 in dtypes:
|
||||
x2 = np.array(range(1, 4), dtype=dtype2)
|
||||
print(x1 % x2)
|
||||
|
||||
print()
|
||||
print('=' * 30)
|
||||
print('inplace modulo')
|
||||
print('=' * 30)
|
||||
print()
|
||||
|
||||
for dtype1 in dtypes:
|
||||
x1 = np.array(range(6), dtype=dtype1).reshape((2, 3))
|
||||
for dtype2 in dtypes:
|
||||
x2 = np.array(range(1, 4), dtype=dtype2)
|
||||
x1 %= x2
|
||||
print(x1)
|
||||
|
|
@ -1,105 +0,0 @@
|
|||
array([[0, 1, 2],
|
||||
[0, 0, 2]], dtype=uint8)
|
||||
array([[0, 1, 2],
|
||||
[0, 0, 2]], dtype=int16)
|
||||
array([[0, 1, 2],
|
||||
[0, 0, 2]], dtype=uint16)
|
||||
array([[0, 1, 2],
|
||||
[0, 0, 2]], dtype=int16)
|
||||
array([[0.0, 1.0, 2.0],
|
||||
[0.0, 0.0, 2.0]], dtype=float64)
|
||||
array([[0, 1, 2],
|
||||
[0, 0, 2]], dtype=int16)
|
||||
array([[0, 1, 2],
|
||||
[0, 0, 2]], dtype=int8)
|
||||
array([[0, 1, 2],
|
||||
[0, 0, 2]], dtype=int16)
|
||||
array([[0, 1, 2],
|
||||
[0, 0, 2]], dtype=int16)
|
||||
array([[0.0, 1.0, 2.0],
|
||||
[0.0, 0.0, 2.0]], dtype=float64)
|
||||
array([[0, 0, 1],
|
||||
[0, 2, 0]], dtype=uint8)
|
||||
array([[0.0, 1.0, 2.0],
|
||||
[0.0, 0.0, 2.0]], dtype=float64)
|
||||
array([[0, 1, 2],
|
||||
[0, 0, 2]], dtype=uint16)
|
||||
array([[0.0, 1.0, 2.0],
|
||||
[0.0, 0.0, 2.0]], dtype=float64)
|
||||
array([[0.0, 1.0, 2.0],
|
||||
[0.0, 0.0, 2.0]], dtype=float64)
|
||||
array([[0, 1, 2],
|
||||
[0, 0, 2]], dtype=int16)
|
||||
array([[0, 1, 2],
|
||||
[0, 0, 2]], dtype=int16)
|
||||
array([[0.0, 1.0, 2.0],
|
||||
[0.0, 0.0, 2.0]], dtype=float64)
|
||||
array([[0, 1, 2],
|
||||
[0, 0, 2]], dtype=int16)
|
||||
array([[0.0, 1.0, 2.0],
|
||||
[0.0, 0.0, 2.0]], dtype=float64)
|
||||
array([[0.0, 1.0, 2.0],
|
||||
[0.0, 0.0, 2.0]], dtype=float64)
|
||||
array([[0.0, 1.0, 2.0],
|
||||
[0.0, 0.0, 2.0]], dtype=float64)
|
||||
array([[0.0, 1.0, 2.0],
|
||||
[0.0, 0.0, 2.0]], dtype=float64)
|
||||
array([[0.0, 1.0, 2.0],
|
||||
[0.0, 0.0, 2.0]], dtype=float64)
|
||||
array([[0.0, 1.0, 2.0],
|
||||
[0.0, 0.0, 2.0]], dtype=float64)
|
||||
|
||||
==============================
|
||||
inplace modulo
|
||||
==============================
|
||||
|
||||
array([[0, 1, 2],
|
||||
[0, 0, 2]], dtype=uint8)
|
||||
array([[0, 1, 2],
|
||||
[0, 0, 2]], dtype=int16)
|
||||
array([[0.0, 1.0, 2.0],
|
||||
[0.0, 0.0, 2.0]], dtype=float64)
|
||||
array([[0.0, 1.0, 2.0],
|
||||
[0.0, 0.0, 2.0]], dtype=float64)
|
||||
array([[0.0, 1.0, 2.0],
|
||||
[0.0, 0.0, 2.0]], dtype=float64)
|
||||
array([[0, 1, 2],
|
||||
[0, 0, 2]], dtype=int16)
|
||||
array([[0, 1, 2],
|
||||
[0, 0, 2]], dtype=int16)
|
||||
array([[0.0, 1.0, 2.0],
|
||||
[0.0, 0.0, 2.0]], dtype=float64)
|
||||
array([[0.0, 1.0, 2.0],
|
||||
[0.0, 0.0, 2.0]], dtype=float64)
|
||||
array([[0.0, 1.0, 2.0],
|
||||
[0.0, 0.0, 2.0]], dtype=float64)
|
||||
array([[0, 0, 1],
|
||||
[0, 2, 0]], dtype=uint8)
|
||||
array([[0, 0, 1],
|
||||
[0, 0, 0]], dtype=int16)
|
||||
array([[0.0, 0.0, 1.0],
|
||||
[0.0, 0.0, 0.0]], dtype=float64)
|
||||
array([[0.0, 0.0, 1.0],
|
||||
[0.0, 0.0, 0.0]], dtype=float64)
|
||||
array([[0.0, 0.0, 1.0],
|
||||
[0.0, 0.0, 0.0]], dtype=float64)
|
||||
array([[0, 1, 2],
|
||||
[0, 0, 2]], dtype=int16)
|
||||
array([[0, 1, 2],
|
||||
[0, 0, 2]], dtype=int16)
|
||||
array([[0.0, 1.0, 2.0],
|
||||
[0.0, 0.0, 2.0]], dtype=float64)
|
||||
array([[0.0, 1.0, 2.0],
|
||||
[0.0, 0.0, 2.0]], dtype=float64)
|
||||
array([[0.0, 1.0, 2.0],
|
||||
[0.0, 0.0, 2.0]], dtype=float64)
|
||||
array([[0.0, 1.0, 2.0],
|
||||
[0.0, 0.0, 2.0]], dtype=float64)
|
||||
array([[0.0, 1.0, 2.0],
|
||||
[0.0, 0.0, 2.0]], dtype=float64)
|
||||
array([[0.0, 1.0, 2.0],
|
||||
[0.0, 0.0, 2.0]], dtype=float64)
|
||||
array([[0.0, 1.0, 2.0],
|
||||
[0.0, 0.0, 2.0]], dtype=float64)
|
||||
array([[0.0, 1.0, 2.0],
|
||||
[0.0, 0.0, 2.0]], dtype=float64)
|
||||
Loading…
Reference in a new issue