Modulo (#734)
* add modulo operator * fix module loops * add in-place modulo operator * update readme * add test files, update documentation
This commit is contained in:
parent
a0999aba79
commit
068da5fc96
5 changed files with 142 additions and 11 deletions
|
|
@ -27,7 +27,7 @@ copyright = '2019-2025, Zoltán Vörös and contributors'
|
||||||
author = 'Zoltán Vörös'
|
author = 'Zoltán Vörös'
|
||||||
|
|
||||||
# The full version, including alpha/beta/rc tags
|
# The full version, including alpha/beta/rc tags
|
||||||
release = '6.7.3'
|
release = '6.9.0'
|
||||||
|
|
||||||
|
|
||||||
# -- General configuration ---------------------------------------------------
|
# -- General configuration ---------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -1814,12 +1814,12 @@ array.
|
||||||
Binary operators
|
Binary operators
|
||||||
================
|
================
|
||||||
|
|
||||||
``ulab`` implements the ``+``, ``-``, ``*``, ``/``, ``**``, ``<``,
|
``ulab`` implements the ``+``, ``-``, ``*``, ``/``, ``**``, ``%``,
|
||||||
``>``, ``<=``, ``>=``, ``==``, ``!=``, ``+=``, ``-=``, ``*=``, ``/=``,
|
``<``, ``>``, ``<=``, ``>=``, ``==``, ``!=``, ``+=``, ``-=``, ``*=``,
|
||||||
``**=`` binary operators, as well as the ``AND``, ``OR``, ``XOR``
|
``/=``, ``**=``, ``%=`` binary operators, as well as the ``AND``,
|
||||||
bit-wise operators that work element-wise. Note that the bit-wise
|
``OR``, ``XOR`` bit-wise operators that work element-wise. Note that the
|
||||||
operators will raise an exception, if either of the operands is of
|
bit-wise operators will raise an exception, if either of the operands is
|
||||||
``float`` or ``complex`` type.
|
of ``float`` or ``complex`` type.
|
||||||
|
|
||||||
Broadcasting is available, meaning that the two operands do not even
|
Broadcasting is available, meaning that the two operands do not even
|
||||||
have to have the same shape. If the lengths along the respective axes
|
have to have the same shape. If the lengths along the respective axes
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 1,
|
"execution_count": 2,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"ExecuteTime": {
|
"ExecuteTime": {
|
||||||
"end_time": "2022-02-09T06:27:15.118699Z",
|
"end_time": "2022-02-09T06:27:15.118699Z",
|
||||||
|
|
@ -61,7 +61,7 @@
|
||||||
"author = 'Zoltán Vörös'\n",
|
"author = 'Zoltán Vörös'\n",
|
||||||
"\n",
|
"\n",
|
||||||
"# The full version, including alpha/beta/rc tags\n",
|
"# The full version, including alpha/beta/rc tags\n",
|
||||||
"release = '6.7.3'\n",
|
"release = '6.9.0'\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"# -- General configuration ---------------------------------------------------\n",
|
"# -- General configuration ---------------------------------------------------\n",
|
||||||
|
|
@ -217,7 +217,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 2,
|
"execution_count": 3,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"ExecuteTime": {
|
"ExecuteTime": {
|
||||||
"end_time": "2022-02-09T06:27:21.647179Z",
|
"end_time": "2022-02-09T06:27:21.647179Z",
|
||||||
|
|
@ -258,7 +258,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 3,
|
"execution_count": 4,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"ExecuteTime": {
|
"ExecuteTime": {
|
||||||
"end_time": "2022-02-09T06:27:42.024028Z",
|
"end_time": "2022-02-09T06:27:42.024028Z",
|
||||||
|
|
|
||||||
26
tests/2d/numpy/modulo.py
Normal file
26
tests/2d/numpy/modulo.py
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
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)
|
||||||
105
tests/2d/numpy/modulo.py.exp
Normal file
105
tests/2d/numpy/modulo.py.exp
Normal file
|
|
@ -0,0 +1,105 @@
|
||||||
|
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