Skip to content

Commit 068da5f

Browse files
authored
Modulo (#734)
* add modulo operator * fix module loops * add in-place modulo operator * update readme * add test files, update documentation
1 parent a0999ab commit 068da5f

File tree

5 files changed

+142
-11
lines changed

5 files changed

+142
-11
lines changed

docs/manual/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
author = 'Zoltán Vörös'
2828

2929
# The full version, including alpha/beta/rc tags
30-
release = '6.7.3'
30+
release = '6.9.0'
3131

3232

3333
# -- General configuration ---------------------------------------------------

docs/manual/source/ulab-ndarray.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,12 +1814,12 @@ array.
18141814
Binary operators
18151815
================
18161816

1817-
``ulab`` implements the ``+``, ``-``, ``*``, ``/``, ``**``, ``<``,
1818-
``>``, ``<=``, ``>=``, ``==``, ``!=``, ``+=``, ``-=``, ``*=``, ``/=``,
1819-
``**=`` binary operators, as well as the ``AND``, ``OR``, ``XOR``
1820-
bit-wise operators that work element-wise. Note that the bit-wise
1821-
operators will raise an exception, if either of the operands is of
1822-
``float`` or ``complex`` type.
1817+
``ulab`` implements the ``+``, ``-``, ``*``, ``/``, ``**``, ``%``,
1818+
``<``, ``>``, ``<=``, ``>=``, ``==``, ``!=``, ``+=``, ``-=``, ``*=``,
1819+
``/=``, ``**=``, ``%=`` binary operators, as well as the ``AND``,
1820+
``OR``, ``XOR`` bit-wise operators that work element-wise. Note that the
1821+
bit-wise operators will raise an exception, if either of the operands is
1822+
of ``float`` or ``complex`` type.
18231823

18241824
Broadcasting is available, meaning that the two operands do not even
18251825
have to have the same shape. If the lengths along the respective axes

docs/ulab-convert.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
},
1515
{
1616
"cell_type": "code",
17-
"execution_count": 1,
17+
"execution_count": 2,
1818
"metadata": {
1919
"ExecuteTime": {
2020
"end_time": "2022-02-09T06:27:15.118699Z",
@@ -61,7 +61,7 @@
6161
"author = 'Zoltán Vörös'\n",
6262
"\n",
6363
"# The full version, including alpha/beta/rc tags\n",
64-
"release = '6.7.3'\n",
64+
"release = '6.9.0'\n",
6565
"\n",
6666
"\n",
6767
"# -- General configuration ---------------------------------------------------\n",
@@ -217,7 +217,7 @@
217217
},
218218
{
219219
"cell_type": "code",
220-
"execution_count": 2,
220+
"execution_count": 3,
221221
"metadata": {
222222
"ExecuteTime": {
223223
"end_time": "2022-02-09T06:27:21.647179Z",
@@ -258,7 +258,7 @@
258258
},
259259
{
260260
"cell_type": "code",
261-
"execution_count": 3,
261+
"execution_count": 4,
262262
"metadata": {
263263
"ExecuteTime": {
264264
"end_time": "2022-02-09T06:27:42.024028Z",

tests/2d/numpy/modulo.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
try:
2+
from ulab import numpy as np
3+
except:
4+
import numpy as np
5+
6+
7+
dtypes = (np.uint8, np.int8, np.uint16, np.int16, np.float)
8+
9+
for dtype1 in dtypes:
10+
x1 = np.array(range(6), dtype=dtype1).reshape((2, 3))
11+
for dtype2 in dtypes:
12+
x2 = np.array(range(1, 4), dtype=dtype2)
13+
print(x1 % x2)
14+
15+
print()
16+
print('=' * 30)
17+
print('inplace modulo')
18+
print('=' * 30)
19+
print()
20+
21+
for dtype1 in dtypes:
22+
x1 = np.array(range(6), dtype=dtype1).reshape((2, 3))
23+
for dtype2 in dtypes:
24+
x2 = np.array(range(1, 4), dtype=dtype2)
25+
x1 %= x2
26+
print(x1)

tests/2d/numpy/modulo.py.exp

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
array([[0, 1, 2],
2+
[0, 0, 2]], dtype=uint8)
3+
array([[0, 1, 2],
4+
[0, 0, 2]], dtype=int16)
5+
array([[0, 1, 2],
6+
[0, 0, 2]], dtype=uint16)
7+
array([[0, 1, 2],
8+
[0, 0, 2]], dtype=int16)
9+
array([[0.0, 1.0, 2.0],
10+
[0.0, 0.0, 2.0]], dtype=float64)
11+
array([[0, 1, 2],
12+
[0, 0, 2]], dtype=int16)
13+
array([[0, 1, 2],
14+
[0, 0, 2]], dtype=int8)
15+
array([[0, 1, 2],
16+
[0, 0, 2]], dtype=int16)
17+
array([[0, 1, 2],
18+
[0, 0, 2]], dtype=int16)
19+
array([[0.0, 1.0, 2.0],
20+
[0.0, 0.0, 2.0]], dtype=float64)
21+
array([[0, 0, 1],
22+
[0, 2, 0]], dtype=uint8)
23+
array([[0.0, 1.0, 2.0],
24+
[0.0, 0.0, 2.0]], dtype=float64)
25+
array([[0, 1, 2],
26+
[0, 0, 2]], dtype=uint16)
27+
array([[0.0, 1.0, 2.0],
28+
[0.0, 0.0, 2.0]], dtype=float64)
29+
array([[0.0, 1.0, 2.0],
30+
[0.0, 0.0, 2.0]], dtype=float64)
31+
array([[0, 1, 2],
32+
[0, 0, 2]], dtype=int16)
33+
array([[0, 1, 2],
34+
[0, 0, 2]], dtype=int16)
35+
array([[0.0, 1.0, 2.0],
36+
[0.0, 0.0, 2.0]], dtype=float64)
37+
array([[0, 1, 2],
38+
[0, 0, 2]], dtype=int16)
39+
array([[0.0, 1.0, 2.0],
40+
[0.0, 0.0, 2.0]], dtype=float64)
41+
array([[0.0, 1.0, 2.0],
42+
[0.0, 0.0, 2.0]], dtype=float64)
43+
array([[0.0, 1.0, 2.0],
44+
[0.0, 0.0, 2.0]], dtype=float64)
45+
array([[0.0, 1.0, 2.0],
46+
[0.0, 0.0, 2.0]], dtype=float64)
47+
array([[0.0, 1.0, 2.0],
48+
[0.0, 0.0, 2.0]], dtype=float64)
49+
array([[0.0, 1.0, 2.0],
50+
[0.0, 0.0, 2.0]], dtype=float64)
51+
52+
==============================
53+
inplace modulo
54+
==============================
55+
56+
array([[0, 1, 2],
57+
[0, 0, 2]], dtype=uint8)
58+
array([[0, 1, 2],
59+
[0, 0, 2]], dtype=int16)
60+
array([[0.0, 1.0, 2.0],
61+
[0.0, 0.0, 2.0]], dtype=float64)
62+
array([[0.0, 1.0, 2.0],
63+
[0.0, 0.0, 2.0]], dtype=float64)
64+
array([[0.0, 1.0, 2.0],
65+
[0.0, 0.0, 2.0]], dtype=float64)
66+
array([[0, 1, 2],
67+
[0, 0, 2]], dtype=int16)
68+
array([[0, 1, 2],
69+
[0, 0, 2]], dtype=int16)
70+
array([[0.0, 1.0, 2.0],
71+
[0.0, 0.0, 2.0]], dtype=float64)
72+
array([[0.0, 1.0, 2.0],
73+
[0.0, 0.0, 2.0]], dtype=float64)
74+
array([[0.0, 1.0, 2.0],
75+
[0.0, 0.0, 2.0]], dtype=float64)
76+
array([[0, 0, 1],
77+
[0, 2, 0]], dtype=uint8)
78+
array([[0, 0, 1],
79+
[0, 0, 0]], dtype=int16)
80+
array([[0.0, 0.0, 1.0],
81+
[0.0, 0.0, 0.0]], dtype=float64)
82+
array([[0.0, 0.0, 1.0],
83+
[0.0, 0.0, 0.0]], dtype=float64)
84+
array([[0.0, 0.0, 1.0],
85+
[0.0, 0.0, 0.0]], dtype=float64)
86+
array([[0, 1, 2],
87+
[0, 0, 2]], dtype=int16)
88+
array([[0, 1, 2],
89+
[0, 0, 2]], dtype=int16)
90+
array([[0.0, 1.0, 2.0],
91+
[0.0, 0.0, 2.0]], dtype=float64)
92+
array([[0.0, 1.0, 2.0],
93+
[0.0, 0.0, 2.0]], dtype=float64)
94+
array([[0.0, 1.0, 2.0],
95+
[0.0, 0.0, 2.0]], dtype=float64)
96+
array([[0.0, 1.0, 2.0],
97+
[0.0, 0.0, 2.0]], dtype=float64)
98+
array([[0.0, 1.0, 2.0],
99+
[0.0, 0.0, 2.0]], dtype=float64)
100+
array([[0.0, 1.0, 2.0],
101+
[0.0, 0.0, 2.0]], dtype=float64)
102+
array([[0.0, 1.0, 2.0],
103+
[0.0, 0.0, 2.0]], dtype=float64)
104+
array([[0.0, 1.0, 2.0],
105+
[0.0, 0.0, 2.0]], dtype=float64)

0 commit comments

Comments
 (0)