* add bitwise operators

* add build to requirements

* [EDIT] - Tweaked test data and saved test results.

* Tweaked test values for and / or

* [EDIT] - Setting print options to be verbose for test comparisons.

* [EDIT] - Removed call to set_printoptions and added output from ulab instead of numpy. Of note - there seems to be a discrepancy between the numpy and ulab output for one of the left_shift cases.

* [EDIT] - Added newline at end of file for diffing purposes.

* [EDIT] - Added print options back in as output seemed truncated.

---------

Co-authored-by: Zoltán Vörös <zvoros@gmail.com>
Co-authored-by: JamieDouugh <jamie.davies@douugh.com>
This commit is contained in:
Derfies 2023-06-21 21:46:30 +10:00 committed by GitHub
parent ef248b684d
commit 2cde1280a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 168 additions and 80 deletions

View file

@ -16,6 +16,12 @@ version 6.1.0
add sinc function
Fri, 12 May 2023
version 6.0.13
add bitwise operators
Sun, 7 May 2023
version 6.0.12

View file

@ -5,10 +5,12 @@ except:
dtypes = (np.uint8, np.int8, np.uint16, np.int16)
test_values1 = (0, 1, 0, 1, 2, 5)
test_values2 = (0, 1, 1, 0, 2, 7)
for dtype1 in dtypes:
x1 = np.array(range(5), dtype=dtype1)
x1 = np.array(test_values1, dtype=dtype1)
for dtype2 in dtypes:
x2 = np.array(range(5, 0, -1), dtype=dtype2)
x2 = np.array(test_values2, dtype=dtype2)
print(np.bitwise_and(x1, x2))

View file

@ -1,16 +1,16 @@
array([0, 0, 2, 2, 0], dtype=uint8)
array([0, 0, 2, 2, 0], dtype=int16)
array([0, 0, 2, 2, 0], dtype=uint16)
array([0, 0, 2, 2, 0], dtype=int16)
array([0, 0, 2, 2, 0], dtype=int16)
array([0, 0, 2, 2, 0], dtype=int8)
array([0, 0, 2, 2, 0], dtype=uint16)
array([0, 0, 2, 2, 0], dtype=int16)
array([0, 0, 2, 2, 0], dtype=uint16)
array([0, 0, 2, 2, 0], dtype=uint16)
array([0, 0, 2, 2, 0], dtype=uint16)
array([0, 0, 2, 2, 0], dtype=int16)
array([0, 0, 2, 2, 0], dtype=int16)
array([0, 0, 2, 2, 0], dtype=int16)
array([0, 0, 2, 2, 0], dtype=int16)
array([0, 0, 2, 2, 0], dtype=int16)
array([0, 1, 0, 0, 2, 5], dtype=uint8)
array([0, 1, 0, 0, 2, 5], dtype=int16)
array([0, 1, 0, 0, 2, 5], dtype=uint16)
array([0, 1, 0, 0, 2, 5], dtype=int16)
array([0, 1, 0, 0, 2, 5], dtype=int16)
array([0, 1, 0, 0, 2, 5], dtype=int8)
array([0, 1, 0, 0, 2, 5], dtype=uint16)
array([0, 1, 0, 0, 2, 5], dtype=int16)
array([0, 1, 0, 0, 2, 5], dtype=uint16)
array([0, 1, 0, 0, 2, 5], dtype=uint16)
array([0, 1, 0, 0, 2, 5], dtype=uint16)
array([0, 1, 0, 0, 2, 5], dtype=int16)
array([0, 1, 0, 0, 2, 5], dtype=int16)
array([0, 1, 0, 0, 2, 5], dtype=int16)
array([0, 1, 0, 0, 2, 5], dtype=int16)
array([0, 1, 0, 0, 2, 5], dtype=int16)

View file

@ -5,10 +5,12 @@ except:
dtypes = (np.uint8, np.int8, np.uint16, np.int16)
test_values1 = (0, 1, 0, 1, 2, 5)
test_values2 = (0, 1, 1, 0, 2, 7)
for dtype1 in dtypes:
x1 = np.array(range(5), dtype=dtype1)
x1 = np.array(test_values1, dtype=dtype1)
for dtype2 in dtypes:
x2 = np.array(range(5, 0, -1), dtype=dtype2)
x2 = np.array(test_values2, dtype=dtype2)
print(np.bitwise_or(x1, x2))

View file

@ -1,16 +1,16 @@
array([5, 5, 3, 3, 5], dtype=uint8)
array([5, 5, 3, 3, 5], dtype=int16)
array([5, 5, 3, 3, 5], dtype=uint16)
array([5, 5, 3, 3, 5], dtype=int16)
array([5, 5, 3, 3, 5], dtype=int16)
array([5, 5, 3, 3, 5], dtype=int8)
array([5, 5, 3, 3, 5], dtype=uint16)
array([5, 5, 3, 3, 5], dtype=int16)
array([5, 5, 3, 3, 5], dtype=uint16)
array([5, 5, 3, 3, 5], dtype=uint16)
array([5, 5, 3, 3, 5], dtype=uint16)
array([5, 5, 3, 3, 5], dtype=int16)
array([5, 5, 3, 3, 5], dtype=int16)
array([5, 5, 3, 3, 5], dtype=int16)
array([5, 5, 3, 3, 5], dtype=int16)
array([5, 5, 3, 3, 5], dtype=int16)
array([0, 1, 1, 1, 2, 7], dtype=uint8)
array([0, 1, 1, 1, 2, 7], dtype=int16)
array([0, 1, 1, 1, 2, 7], dtype=uint16)
array([0, 1, 1, 1, 2, 7], dtype=int16)
array([0, 1, 1, 1, 2, 7], dtype=int16)
array([0, 1, 1, 1, 2, 7], dtype=int8)
array([0, 1, 1, 1, 2, 7], dtype=uint16)
array([0, 1, 1, 1, 2, 7], dtype=int16)
array([0, 1, 1, 1, 2, 7], dtype=uint16)
array([0, 1, 1, 1, 2, 7], dtype=uint16)
array([0, 1, 1, 1, 2, 7], dtype=uint16)
array([0, 1, 1, 1, 2, 7], dtype=int16)
array([0, 1, 1, 1, 2, 7], dtype=int16)
array([0, 1, 1, 1, 2, 7], dtype=int16)
array([0, 1, 1, 1, 2, 7], dtype=int16)
array([0, 1, 1, 1, 2, 7], dtype=int16)

View file

@ -2,13 +2,20 @@ try:
from ulab import numpy as np
except:
import numpy as np
np.set_printoptions(threshold=100)
shift_values = (
(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2),
)
dtypes = (np.uint8, np.int8, np.uint16, np.int16)
for dtype1 in dtypes:
x1 = np.array(range(5), dtype=dtype1)
for dtype2 in dtypes:
x2 = np.array(range(5, 0, -1), dtype=dtype2)
print(np.left_shift(x1, x2))
for shift_value in shift_values:
for dtype1 in dtypes:
x1 = np.array([0, 1, 2, 4, 8, 16, 32, 3, 5, 7, 11, 13], dtype=dtype1)
for dtype2 in dtypes:
x2 = np.array(shift_value, dtype=dtype2)
print(np.left_shift(x1, x2))

View file

@ -1,16 +1,48 @@
array([0, 16, 16, 12, 8], dtype=uint8)
array([0, 16, 16, 12, 8], dtype=int16)
array([0, 16, 16, 12, 8], dtype=uint16)
array([0, 16, 16, 12, 8], dtype=int16)
array([0, 16, 16, 12, 8], dtype=int16)
array([0, 16, 16, 12, 8], dtype=int8)
array([0, 16, 16, 12, 8], dtype=uint16)
array([0, 16, 16, 12, 8], dtype=int16)
array([0, 16, 16, 12, 8], dtype=uint16)
array([0, 16, 16, 12, 8], dtype=int8)
array([0, 16, 16, 12, 8], dtype=uint16)
array([0, 16, 16, 12, 8], dtype=int16)
array([0, 16, 16, 12, 8], dtype=int16)
array([0, 16, 16, 12, 8], dtype=int16)
array([0, 16, 16, 12, 8], dtype=int16)
array([0, 16, 16, 12, 8], dtype=int16)
array([0, 1, 2, 4, 8, 16, 32, 3, 5, 7, 11, 13], dtype=uint8)
array([0, 1, 2, 4, 8, 16, 32, 3, 5, 7, 11, 13], dtype=int16)
array([0, 1, 2, 4, 8, 16, 32, 3, 5, 7, 11, 13], dtype=uint16)
array([0, 1, 2, 4, 8, 16, 32, 3, 5, 7, 11, 13], dtype=int16)
array([0, 1, 2, 4, 8, 16, 32, 3, 5, 7, 11, 13], dtype=int16)
array([0, 1, 2, 4, 8, 16, 32, 3, 5, 7, 11, 13], dtype=int8)
array([0, 1, 2, 4, 8, 16, 32, 3, 5, 7, 11, 13], dtype=uint16)
array([0, 1, 2, 4, 8, 16, 32, 3, 5, 7, 11, 13], dtype=int16)
array([0, 1, 2, 4, 8, 16, 32, 3, 5, 7, 11, 13], dtype=uint16)
array([0, 1, 2, 4, 8, 16, 32, 3, 5, 7, 11, 13], dtype=int8)
array([0, 1, 2, 4, 8, 16, 32, 3, 5, 7, 11, 13], dtype=uint16)
array([0, 1, 2, 4, 8, 16, 32, 3, 5, 7, 11, 13], dtype=int16)
array([0, 1, 2, 4, 8, 16, 32, 3, 5, 7, 11, 13], dtype=int16)
array([0, 1, 2, 4, 8, 16, 32, 3, 5, 7, 11, 13], dtype=int16)
array([0, 1, 2, 4, 8, 16, 32, 3, 5, 7, 11, 13], dtype=int16)
array([0, 1, 2, 4, 8, 16, 32, 3, 5, 7, 11, 13], dtype=int16)
array([0, 2, 4, 8, 16, 32, 64, 6, 10, 14, 22, 26], dtype=uint8)
array([0, 2, 4, 8, 16, 32, 64, 6, 10, 14, 22, 26], dtype=int16)
array([0, 2, 4, 8, 16, 32, 64, 6, 10, 14, 22, 26], dtype=uint16)
array([0, 2, 4, 8, 16, 32, 64, 6, 10, 14, 22, 26], dtype=int16)
array([0, 2, 4, 8, 16, 32, 64, 6, 10, 14, 22, 26], dtype=int16)
array([0, 2, 4, 8, 16, 32, 64, 6, 10, 14, 22, 26], dtype=int8)
array([0, 2, 4, 8, 16, 32, 64, 6, 10, 14, 22, 26], dtype=uint16)
array([0, 2, 4, 8, 16, 32, 64, 6, 10, 14, 22, 26], dtype=int16)
array([0, 2, 4, 8, 16, 32, 64, 6, 10, 14, 22, 26], dtype=uint16)
array([0, 2, 4, 8, 16, 32, 64, 6, 10, 14, 22, 26], dtype=int8)
array([0, 2, 4, 8, 16, 32, 64, 6, 10, 14, 22, 26], dtype=uint16)
array([0, 2, 4, 8, 16, 32, 64, 6, 10, 14, 22, 26], dtype=int16)
array([0, 2, 4, 8, 16, 32, 64, 6, 10, 14, 22, 26], dtype=int16)
array([0, 2, 4, 8, 16, 32, 64, 6, 10, 14, 22, 26], dtype=int16)
array([0, 2, 4, 8, 16, 32, 64, 6, 10, 14, 22, 26], dtype=int16)
array([0, 2, 4, 8, 16, 32, 64, 6, 10, 14, 22, 26], dtype=int16)
array([0, 4, 8, 16, 32, 64, 128, 12, 20, 28, 44, 52], dtype=uint8)
array([0, 4, 8, 16, 32, 64, 128, 12, 20, 28, 44, 52], dtype=int16)
array([0, 4, 8, 16, 32, 64, 128, 12, 20, 28, 44, 52], dtype=uint16)
array([0, 4, 8, 16, 32, 64, 128, 12, 20, 28, 44, 52], dtype=int16)
array([0, 4, 8, 16, 32, 64, 128, 12, 20, 28, 44, 52], dtype=int16)
array([0, 4, 8, 16, 32, 64, -128, 12, 20, 28, 44, 52], dtype=int8)
array([0, 4, 8, 16, 32, 64, 128, 12, 20, 28, 44, 52], dtype=uint16)
array([0, 4, 8, 16, 32, 64, 128, 12, 20, 28, 44, 52], dtype=int16)
array([0, 4, 8, 16, 32, 64, 128, 12, 20, 28, 44, 52], dtype=uint16)
array([0, 4, 8, 16, 32, 64, -128, 12, 20, 28, 44, 52], dtype=int8)
array([0, 4, 8, 16, 32, 64, 128, 12, 20, 28, 44, 52], dtype=uint16)
array([0, 4, 8, 16, 32, 64, 128, 12, 20, 28, 44, 52], dtype=int16)
array([0, 4, 8, 16, 32, 64, 128, 12, 20, 28, 44, 52], dtype=int16)
array([0, 4, 8, 16, 32, 64, 128, 12, 20, 28, 44, 52], dtype=int16)
array([0, 4, 8, 16, 32, 64, 128, 12, 20, 28, 44, 52], dtype=int16)
array([0, 4, 8, 16, 32, 64, 128, 12, 20, 28, 44, 52], dtype=int16)

View file

@ -2,13 +2,20 @@ try:
from ulab import numpy as np
except:
import numpy as np
np.set_printoptions(threshold=100)
shift_values = (
(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2),
)
dtypes = (np.uint8, np.int8, np.uint16, np.int16)
for dtype1 in dtypes:
x1 = np.array(range(5), dtype=dtype1)
for dtype2 in dtypes:
x2 = np.array(range(5, 0, -1), dtype=dtype2)
print(np.right_shift(x1, x2))
for shift_value in shift_values:
for dtype1 in dtypes:
x1 = np.array([0, 1, 2, 4, 8, 16, 32, 3, 5, 7, 11, 13], dtype=dtype1)
for dtype2 in dtypes:
x2 = np.array(shift_value, dtype=dtype2)
print(np.right_shift(x1, x2))

View file

@ -1,16 +1,48 @@
array([0, 0, 0, 0, 2], dtype=uint8)
array([0, 0, 0, 0, 2], dtype=int16)
array([0, 0, 0, 0, 2], dtype=uint16)
array([0, 0, 0, 0, 2], dtype=int16)
array([0, 0, 0, 0, 2], dtype=int16)
array([0, 0, 0, 0, 2], dtype=int8)
array([0, 0, 0, 0, 2], dtype=uint16)
array([0, 0, 0, 0, 2], dtype=int16)
array([0, 0, 0, 0, 2], dtype=uint16)
array([0, 0, 0, 0, 2], dtype=int8)
array([0, 0, 0, 0, 2], dtype=uint16)
array([0, 0, 0, 0, 2], dtype=int16)
array([0, 0, 0, 0, 2], dtype=int16)
array([0, 0, 0, 0, 2], dtype=int16)
array([0, 0, 0, 0, 2], dtype=int16)
array([0, 0, 0, 0, 2], dtype=int16)
array([0, 1, 2, 4, 8, 16, 32, 3, 5, 7, 11, 13], dtype=uint8)
array([0, 1, 2, 4, 8, 16, 32, 3, 5, 7, 11, 13], dtype=int16)
array([0, 1, 2, 4, 8, 16, 32, 3, 5, 7, 11, 13], dtype=uint16)
array([0, 1, 2, 4, 8, 16, 32, 3, 5, 7, 11, 13], dtype=int16)
array([0, 1, 2, 4, 8, 16, 32, 3, 5, 7, 11, 13], dtype=int16)
array([0, 1, 2, 4, 8, 16, 32, 3, 5, 7, 11, 13], dtype=int8)
array([0, 1, 2, 4, 8, 16, 32, 3, 5, 7, 11, 13], dtype=uint16)
array([0, 1, 2, 4, 8, 16, 32, 3, 5, 7, 11, 13], dtype=int16)
array([0, 1, 2, 4, 8, 16, 32, 3, 5, 7, 11, 13], dtype=uint16)
array([0, 1, 2, 4, 8, 16, 32, 3, 5, 7, 11, 13], dtype=int8)
array([0, 1, 2, 4, 8, 16, 32, 3, 5, 7, 11, 13], dtype=uint16)
array([0, 1, 2, 4, 8, 16, 32, 3, 5, 7, 11, 13], dtype=int16)
array([0, 1, 2, 4, 8, 16, 32, 3, 5, 7, 11, 13], dtype=int16)
array([0, 1, 2, 4, 8, 16, 32, 3, 5, 7, 11, 13], dtype=int16)
array([0, 1, 2, 4, 8, 16, 32, 3, 5, 7, 11, 13], dtype=int16)
array([0, 1, 2, 4, 8, 16, 32, 3, 5, 7, 11, 13], dtype=int16)
array([0, 0, 1, 2, 4, 8, 16, 1, 2, 3, 5, 6], dtype=uint8)
array([0, 0, 1, 2, 4, 8, 16, 1, 2, 3, 5, 6], dtype=int16)
array([0, 0, 1, 2, 4, 8, 16, 1, 2, 3, 5, 6], dtype=uint16)
array([0, 0, 1, 2, 4, 8, 16, 1, 2, 3, 5, 6], dtype=int16)
array([0, 0, 1, 2, 4, 8, 16, 1, 2, 3, 5, 6], dtype=int16)
array([0, 0, 1, 2, 4, 8, 16, 1, 2, 3, 5, 6], dtype=int8)
array([0, 0, 1, 2, 4, 8, 16, 1, 2, 3, 5, 6], dtype=uint16)
array([0, 0, 1, 2, 4, 8, 16, 1, 2, 3, 5, 6], dtype=int16)
array([0, 0, 1, 2, 4, 8, 16, 1, 2, 3, 5, 6], dtype=uint16)
array([0, 0, 1, 2, 4, 8, 16, 1, 2, 3, 5, 6], dtype=int8)
array([0, 0, 1, 2, 4, 8, 16, 1, 2, 3, 5, 6], dtype=uint16)
array([0, 0, 1, 2, 4, 8, 16, 1, 2, 3, 5, 6], dtype=int16)
array([0, 0, 1, 2, 4, 8, 16, 1, 2, 3, 5, 6], dtype=int16)
array([0, 0, 1, 2, 4, 8, 16, 1, 2, 3, 5, 6], dtype=int16)
array([0, 0, 1, 2, 4, 8, 16, 1, 2, 3, 5, 6], dtype=int16)
array([0, 0, 1, 2, 4, 8, 16, 1, 2, 3, 5, 6], dtype=int16)
array([0, 0, 0, 1, 2, 4, 8, 0, 1, 1, 2, 3], dtype=uint8)
array([0, 0, 0, 1, 2, 4, 8, 0, 1, 1, 2, 3], dtype=int16)
array([0, 0, 0, 1, 2, 4, 8, 0, 1, 1, 2, 3], dtype=uint16)
array([0, 0, 0, 1, 2, 4, 8, 0, 1, 1, 2, 3], dtype=int16)
array([0, 0, 0, 1, 2, 4, 8, 0, 1, 1, 2, 3], dtype=int16)
array([0, 0, 0, 1, 2, 4, 8, 0, 1, 1, 2, 3], dtype=int8)
array([0, 0, 0, 1, 2, 4, 8, 0, 1, 1, 2, 3], dtype=uint16)
array([0, 0, 0, 1, 2, 4, 8, 0, 1, 1, 2, 3], dtype=int16)
array([0, 0, 0, 1, 2, 4, 8, 0, 1, 1, 2, 3], dtype=uint16)
array([0, 0, 0, 1, 2, 4, 8, 0, 1, 1, 2, 3], dtype=int8)
array([0, 0, 0, 1, 2, 4, 8, 0, 1, 1, 2, 3], dtype=uint16)
array([0, 0, 0, 1, 2, 4, 8, 0, 1, 1, 2, 3], dtype=int16)
array([0, 0, 0, 1, 2, 4, 8, 0, 1, 1, 2, 3], dtype=int16)
array([0, 0, 0, 1, 2, 4, 8, 0, 1, 1, 2, 3], dtype=int16)
array([0, 0, 0, 1, 2, 4, 8, 0, 1, 1, 2, 3], dtype=int16)
array([0, 0, 0, 1, 2, 4, 8, 0, 1, 1, 2, 3], dtype=int16)