implement AND, OR, XOR binary operators (#639)
* implement AND, OR, XOR binary operators * fix unterminated if * add missing linebreak * add more linebreaks * remove leading linebreak
This commit is contained in:
parent
84f99f17fc
commit
5279de73ab
12 changed files with 337 additions and 1 deletions
|
|
@ -1949,6 +1949,12 @@ mp_obj_t ndarray_binary_op(mp_binary_op_t _op, mp_obj_t lobj, mp_obj_t robj) {
|
|||
return ndarray_binary_power(lhs, rhs, ndim, shape, lstrides, rstrides);
|
||||
break;
|
||||
#endif
|
||||
#if NDARRAY_HAS_BINARY_OP_OR | NDARRAY_HAS_BINARY_OP_XOR | NDARRAY_HAS_BINARY_OP_AND
|
||||
case MP_BINARY_OP_OR:
|
||||
case MP_BINARY_OP_XOR:
|
||||
case MP_BINARY_OP_AND:
|
||||
return ndarray_binary_logical(lhs, rhs, ndim, shape, lstrides, rstrides, op);
|
||||
#endif
|
||||
#if NDARRAY_HAS_BINARY_OP_FLOOR_DIVIDE
|
||||
case MP_BINARY_OP_FLOOR_DIVIDE:
|
||||
COMPLEX_DTYPE_NOT_IMPLEMENTED(lhs->dtype);
|
||||
|
|
|
|||
|
|
@ -857,6 +857,194 @@ mp_obj_t ndarray_binary_power(ndarray_obj_t *lhs, ndarray_obj_t *rhs,
|
|||
}
|
||||
#endif /* NDARRAY_HAS_BINARY_OP_POWER */
|
||||
|
||||
#if NDARRAY_HAS_BINARY_OP_OR | NDARRAY_HAS_BINARY_OP_XOR | NDARRAY_HAS_BINARY_OP_AND
|
||||
mp_obj_t ndarray_binary_logical(ndarray_obj_t *lhs, ndarray_obj_t *rhs,
|
||||
uint8_t ndim, size_t *shape, int32_t *lstrides, int32_t *rstrides, mp_binary_op_t op) {
|
||||
|
||||
#if ULAB_SUPPORTS_COMPLEX
|
||||
if((lhs->dtype == NDARRAY_COMPLEX) || (rhs->dtype == NDARRAY_COMPLEX) || (lhs->dtype == NDARRAY_FLOAT) || (rhs->dtype == NDARRAY_FLOAT)) {
|
||||
mp_raise_TypeError(translate("operation not supported for the input types"));
|
||||
}
|
||||
#else
|
||||
if((lhs->dtype == NDARRAY_FLOAT) || (rhs->dtype == NDARRAY_FLOAT)) {
|
||||
mp_raise_TypeError(translate("operation not supported for the input types"));
|
||||
}
|
||||
#endif
|
||||
|
||||
// bail out, if both inputs are of 16-bit types, but differ in sign;
|
||||
// numpy promotes the result to int32
|
||||
if(((lhs->dtype == NDARRAY_INT16) && (rhs->dtype == NDARRAY_UINT16)) ||
|
||||
((lhs->dtype == NDARRAY_UINT16) && (rhs->dtype == NDARRAY_INT16))) {
|
||||
mp_raise_TypeError(translate("dtype of int32 is not supported"));
|
||||
}
|
||||
|
||||
ndarray_obj_t *results = NULL;
|
||||
uint8_t *larray = (uint8_t *)lhs->array;
|
||||
uint8_t *rarray = (uint8_t *)rhs->array;
|
||||
|
||||
|
||||
switch(op) {
|
||||
case MP_BINARY_OP_XOR:
|
||||
if(lhs->dtype == NDARRAY_UINT8) {
|
||||
if(rhs->dtype == NDARRAY_UINT8) {
|
||||
results = ndarray_new_dense_ndarray(ndim, shape, NDARRAY_UINT8);
|
||||
if(lhs->boolean & rhs->boolean) {
|
||||
results->boolean = 1;
|
||||
}
|
||||
BINARY_LOOP(results, uint8_t, uint8_t, uint8_t, larray, lstrides, rarray, rstrides, ^);
|
||||
} else if(rhs->dtype == NDARRAY_INT8) {
|
||||
results = ndarray_new_dense_ndarray(ndim, shape, NDARRAY_INT16);
|
||||
BINARY_LOOP(results, int16_t, uint8_t, int8_t, larray, lstrides, rarray, rstrides, ^);
|
||||
} else if(rhs->dtype == NDARRAY_UINT16) {
|
||||
results = ndarray_new_dense_ndarray(ndim, shape, NDARRAY_UINT16);
|
||||
BINARY_LOOP(results, uint16_t, uint8_t, uint16_t, larray, lstrides, rarray, rstrides, ^);
|
||||
} else if(rhs->dtype == NDARRAY_INT16) {
|
||||
results = ndarray_new_dense_ndarray(ndim, shape, NDARRAY_INT16);
|
||||
BINARY_LOOP(results, int16_t, uint8_t, int16_t, larray, lstrides, rarray, rstrides, ^);
|
||||
}
|
||||
} else if(lhs->dtype == NDARRAY_INT8) {
|
||||
if(rhs->dtype == NDARRAY_INT8) {
|
||||
results = ndarray_new_dense_ndarray(ndim, shape, NDARRAY_INT8);
|
||||
BINARY_LOOP(results, int8_t, int8_t, int8_t, larray, lstrides, rarray, rstrides, ^);
|
||||
} else if(rhs->dtype == NDARRAY_UINT16) {
|
||||
results = ndarray_new_dense_ndarray(ndim, shape, NDARRAY_INT16);
|
||||
BINARY_LOOP(results, int16_t, int8_t, uint16_t, larray, lstrides, rarray, rstrides, ^);
|
||||
} else if(rhs->dtype == NDARRAY_INT16) {
|
||||
results = ndarray_new_dense_ndarray(ndim, shape, NDARRAY_INT16);
|
||||
BINARY_LOOP(results, int16_t, int8_t, int16_t, larray, lstrides, rarray, rstrides, ^);
|
||||
} else {
|
||||
return ndarray_binary_op(MP_BINARY_OP_XOR, MP_OBJ_FROM_PTR(rhs), MP_OBJ_FROM_PTR(lhs));
|
||||
}
|
||||
} else if(lhs->dtype == NDARRAY_UINT16) {
|
||||
if(rhs->dtype == NDARRAY_UINT16) {
|
||||
results = ndarray_new_dense_ndarray(ndim, shape, NDARRAY_UINT16);
|
||||
BINARY_LOOP(results, uint16_t, uint16_t, uint16_t, larray, lstrides, rarray, rstrides, ^);
|
||||
} else if(rhs->dtype == NDARRAY_INT16) {
|
||||
results = ndarray_new_dense_ndarray(ndim, shape, NDARRAY_FLOAT);
|
||||
BINARY_LOOP(results, mp_float_t, uint16_t, int16_t, larray, lstrides, rarray, rstrides, ^);
|
||||
} else {
|
||||
return ndarray_binary_op(MP_BINARY_OP_XOR, MP_OBJ_FROM_PTR(rhs), MP_OBJ_FROM_PTR(lhs));
|
||||
}
|
||||
} else if(lhs->dtype == NDARRAY_INT16) {
|
||||
if(rhs->dtype == NDARRAY_INT16) {
|
||||
results = ndarray_new_dense_ndarray(ndim, shape, NDARRAY_INT16);
|
||||
BINARY_LOOP(results, int16_t, int16_t, int16_t, larray, lstrides, rarray, rstrides, ^);
|
||||
} else {
|
||||
return ndarray_binary_op(MP_BINARY_OP_XOR, MP_OBJ_FROM_PTR(rhs), MP_OBJ_FROM_PTR(lhs));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case MP_BINARY_OP_OR:
|
||||
if(lhs->dtype == NDARRAY_UINT8) {
|
||||
if(rhs->dtype == NDARRAY_UINT8) {
|
||||
results = ndarray_new_dense_ndarray(ndim, shape, NDARRAY_UINT8);
|
||||
if(lhs->boolean & rhs->boolean) {
|
||||
results->boolean = 1;
|
||||
}
|
||||
BINARY_LOOP(results, uint8_t, uint8_t, uint8_t, larray, lstrides, rarray, rstrides, |);
|
||||
} else if(rhs->dtype == NDARRAY_INT8) {
|
||||
results = ndarray_new_dense_ndarray(ndim, shape, NDARRAY_INT16);
|
||||
BINARY_LOOP(results, int16_t, uint8_t, int8_t, larray, lstrides, rarray, rstrides, |);
|
||||
} else if(rhs->dtype == NDARRAY_UINT16) {
|
||||
results = ndarray_new_dense_ndarray(ndim, shape, NDARRAY_UINT16);
|
||||
BINARY_LOOP(results, uint16_t, uint8_t, uint16_t, larray, lstrides, rarray, rstrides, |);
|
||||
} else if(rhs->dtype == NDARRAY_INT16) {
|
||||
results = ndarray_new_dense_ndarray(ndim, shape, NDARRAY_INT16);
|
||||
BINARY_LOOP(results, int16_t, uint8_t, int16_t, larray, lstrides, rarray, rstrides, |);
|
||||
}
|
||||
} else if(lhs->dtype == NDARRAY_INT8) {
|
||||
if(rhs->dtype == NDARRAY_INT8) {
|
||||
results = ndarray_new_dense_ndarray(ndim, shape, NDARRAY_INT8);
|
||||
BINARY_LOOP(results, int8_t, int8_t, int8_t, larray, lstrides, rarray, rstrides, |);
|
||||
} else if(rhs->dtype == NDARRAY_UINT16) {
|
||||
results = ndarray_new_dense_ndarray(ndim, shape, NDARRAY_INT16);
|
||||
BINARY_LOOP(results, int16_t, int8_t, uint16_t, larray, lstrides, rarray, rstrides, |);
|
||||
} else if(rhs->dtype == NDARRAY_INT16) {
|
||||
results = ndarray_new_dense_ndarray(ndim, shape, NDARRAY_INT16);
|
||||
BINARY_LOOP(results, int16_t, int8_t, int16_t, larray, lstrides, rarray, rstrides, |);
|
||||
} else {
|
||||
return ndarray_binary_op(MP_BINARY_OP_OR, MP_OBJ_FROM_PTR(rhs), MP_OBJ_FROM_PTR(lhs));
|
||||
}
|
||||
} else if(lhs->dtype == NDARRAY_UINT16) {
|
||||
if(rhs->dtype == NDARRAY_UINT16) {
|
||||
results = ndarray_new_dense_ndarray(ndim, shape, NDARRAY_UINT16);
|
||||
BINARY_LOOP(results, uint16_t, uint16_t, uint16_t, larray, lstrides, rarray, rstrides, |);
|
||||
} else if(rhs->dtype == NDARRAY_INT16) {
|
||||
results = ndarray_new_dense_ndarray(ndim, shape, NDARRAY_FLOAT);
|
||||
BINARY_LOOP(results, mp_float_t, uint16_t, int16_t, larray, lstrides, rarray, rstrides, |);
|
||||
} else {
|
||||
return ndarray_binary_op(MP_BINARY_OP_OR, MP_OBJ_FROM_PTR(rhs), MP_OBJ_FROM_PTR(lhs));
|
||||
}
|
||||
} else if(lhs->dtype == NDARRAY_INT16) {
|
||||
if(rhs->dtype == NDARRAY_INT16) {
|
||||
results = ndarray_new_dense_ndarray(ndim, shape, NDARRAY_INT16);
|
||||
BINARY_LOOP(results, int16_t, int16_t, int16_t, larray, lstrides, rarray, rstrides, |);
|
||||
} else {
|
||||
return ndarray_binary_op(MP_BINARY_OP_OR, MP_OBJ_FROM_PTR(rhs), MP_OBJ_FROM_PTR(lhs));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case MP_BINARY_OP_AND:
|
||||
if(lhs->dtype == NDARRAY_UINT8) {
|
||||
if(rhs->dtype == NDARRAY_UINT8) {
|
||||
results = ndarray_new_dense_ndarray(ndim, shape, NDARRAY_UINT8);
|
||||
if(lhs->boolean & rhs->boolean) {
|
||||
results->boolean = 1;
|
||||
}
|
||||
BINARY_LOOP(results, uint8_t, uint8_t, uint8_t, larray, lstrides, rarray, rstrides, &);
|
||||
} else if(rhs->dtype == NDARRAY_INT8) {
|
||||
results = ndarray_new_dense_ndarray(ndim, shape, NDARRAY_INT16);
|
||||
BINARY_LOOP(results, int16_t, uint8_t, int8_t, larray, lstrides, rarray, rstrides, &);
|
||||
} else if(rhs->dtype == NDARRAY_UINT16) {
|
||||
results = ndarray_new_dense_ndarray(ndim, shape, NDARRAY_UINT16);
|
||||
BINARY_LOOP(results, uint16_t, uint8_t, uint16_t, larray, lstrides, rarray, rstrides, &);
|
||||
} else if(rhs->dtype == NDARRAY_INT16) {
|
||||
results = ndarray_new_dense_ndarray(ndim, shape, NDARRAY_INT16);
|
||||
BINARY_LOOP(results, int16_t, uint8_t, int16_t, larray, lstrides, rarray, rstrides, &);
|
||||
}
|
||||
} else if(lhs->dtype == NDARRAY_INT8) {
|
||||
if(rhs->dtype == NDARRAY_INT8) {
|
||||
results = ndarray_new_dense_ndarray(ndim, shape, NDARRAY_INT8);
|
||||
BINARY_LOOP(results, int8_t, int8_t, int8_t, larray, lstrides, rarray, rstrides, &);
|
||||
} else if(rhs->dtype == NDARRAY_UINT16) {
|
||||
results = ndarray_new_dense_ndarray(ndim, shape, NDARRAY_INT16);
|
||||
BINARY_LOOP(results, int16_t, int8_t, uint16_t, larray, lstrides, rarray, rstrides, &);
|
||||
} else if(rhs->dtype == NDARRAY_INT16) {
|
||||
results = ndarray_new_dense_ndarray(ndim, shape, NDARRAY_INT16);
|
||||
BINARY_LOOP(results, int16_t, int8_t, int16_t, larray, lstrides, rarray, rstrides, &);
|
||||
} else {
|
||||
return ndarray_binary_op(MP_BINARY_OP_AND, MP_OBJ_FROM_PTR(rhs), MP_OBJ_FROM_PTR(lhs));
|
||||
}
|
||||
} else if(lhs->dtype == NDARRAY_UINT16) {
|
||||
if(rhs->dtype == NDARRAY_UINT16) {
|
||||
results = ndarray_new_dense_ndarray(ndim, shape, NDARRAY_UINT16);
|
||||
BINARY_LOOP(results, uint16_t, uint16_t, uint16_t, larray, lstrides, rarray, rstrides, &);
|
||||
} else if(rhs->dtype == NDARRAY_INT16) {
|
||||
results = ndarray_new_dense_ndarray(ndim, shape, NDARRAY_FLOAT);
|
||||
BINARY_LOOP(results, mp_float_t, uint16_t, int16_t, larray, lstrides, rarray, rstrides, &);
|
||||
} else {
|
||||
return ndarray_binary_op(MP_BINARY_OP_AND, MP_OBJ_FROM_PTR(rhs), MP_OBJ_FROM_PTR(lhs));
|
||||
}
|
||||
} else if(lhs->dtype == NDARRAY_INT16) {
|
||||
if(rhs->dtype == NDARRAY_INT16) {
|
||||
results = ndarray_new_dense_ndarray(ndim, shape, NDARRAY_INT16);
|
||||
BINARY_LOOP(results, int16_t, int16_t, int16_t, larray, lstrides, rarray, rstrides, &);
|
||||
} else {
|
||||
return ndarray_binary_op(MP_BINARY_OP_AND, MP_OBJ_FROM_PTR(rhs), MP_OBJ_FROM_PTR(lhs));
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return MP_OBJ_NULL; // op not supported
|
||||
break;
|
||||
}
|
||||
return MP_OBJ_FROM_PTR(results);
|
||||
}
|
||||
|
||||
#endif /* NDARRAY_HAS_BINARY_OP_OR | NDARRAY_HAS_BINARY_OP_XOR | NDARRAY_HAS_BINARY_OP_AND */
|
||||
|
||||
#if NDARRAY_HAS_INPLACE_ADD || NDARRAY_HAS_INPLACE_MULTIPLY || NDARRAY_HAS_INPLACE_SUBTRACT
|
||||
mp_obj_t ndarray_inplace_ams(ndarray_obj_t *lhs, ndarray_obj_t *rhs, int32_t *rstrides, uint8_t optype) {
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ mp_obj_t ndarray_binary_more(ndarray_obj_t *, ndarray_obj_t *, uint8_t , size_t
|
|||
mp_obj_t ndarray_binary_power(ndarray_obj_t *, ndarray_obj_t *, uint8_t , size_t *, int32_t *, int32_t *);
|
||||
mp_obj_t ndarray_binary_subtract(ndarray_obj_t *, ndarray_obj_t *, uint8_t , size_t *, int32_t *, int32_t *);
|
||||
mp_obj_t ndarray_binary_true_divide(ndarray_obj_t *, ndarray_obj_t *, uint8_t , size_t *, int32_t *, int32_t *);
|
||||
mp_obj_t ndarray_binary_logical(ndarray_obj_t *, ndarray_obj_t *, uint8_t , size_t *, int32_t *, int32_t *, mp_binary_op_t );
|
||||
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 );
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
#include "user/user.h"
|
||||
#include "utils/utils.h"
|
||||
|
||||
#define ULAB_VERSION 6.3.5
|
||||
#define ULAB_VERSION 6.4.0
|
||||
#define xstr(s) str(s)
|
||||
#define str(s) #s
|
||||
|
||||
|
|
|
|||
12
code/ulab.h
12
code/ulab.h
|
|
@ -97,6 +97,10 @@
|
|||
#define NDARRAY_HAS_BINARY_OP_ADD (1)
|
||||
#endif
|
||||
|
||||
#ifndef NDARRAY_HAS_BINARY_OP_AND
|
||||
#define NDARRAY_HAS_BINARY_OP_AND (1)
|
||||
#endif
|
||||
|
||||
#ifndef NDARRAY_HAS_BINARY_OP_EQUAL
|
||||
#define NDARRAY_HAS_BINARY_OP_EQUAL (1)
|
||||
#endif
|
||||
|
|
@ -129,6 +133,10 @@
|
|||
#define NDARRAY_HAS_BINARY_OP_NOT_EQUAL (1)
|
||||
#endif
|
||||
|
||||
#ifndef NDARRAY_HAS_BINARY_OP_OR
|
||||
#define NDARRAY_HAS_BINARY_OP_OR (1)
|
||||
#endif
|
||||
|
||||
#ifndef NDARRAY_HAS_BINARY_OP_POWER
|
||||
#define NDARRAY_HAS_BINARY_OP_POWER (1)
|
||||
#endif
|
||||
|
|
@ -141,6 +149,10 @@
|
|||
#define NDARRAY_HAS_BINARY_OP_TRUE_DIVIDE (1)
|
||||
#endif
|
||||
|
||||
#ifndef NDARRAY_HAS_BINARY_OP_XOR
|
||||
#define NDARRAY_HAS_BINARY_OP_XOR (1)
|
||||
#endif
|
||||
|
||||
#ifndef NDARRAY_HAS_INPLACE_OPS
|
||||
#define NDARRAY_HAS_INPLACE_OPS (1)
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,3 +1,9 @@
|
|||
Thu, 20 Jul 2023
|
||||
|
||||
version 6.4.0
|
||||
|
||||
implement AND, OR, and XOR binary operators
|
||||
|
||||
Sat, 1 Jul 2023
|
||||
|
||||
version 6.3.5
|
||||
|
|
|
|||
21
tests/2d/numpy/and.py
Normal file
21
tests/2d/numpy/and.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
try:
|
||||
from ulab import numpy as np
|
||||
except ImportError:
|
||||
import numpy as np
|
||||
|
||||
dtypes = (np.uint8, np.int8, np.uint16, np.int16)
|
||||
|
||||
for dtype_a in dtypes:
|
||||
a = np.array(range(5), dtype=dtype_a)
|
||||
for dtype_b in dtypes:
|
||||
b = np.array(range(250, 255), dtype=dtype_b)
|
||||
try:
|
||||
print('a & b: ', a & b)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
b = np.array([False, True, False, True, False], dtype=np.bool)
|
||||
try:
|
||||
print('a & b (bool): ', a & b)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
20
tests/2d/numpy/and.py.exp
Normal file
20
tests/2d/numpy/and.py.exp
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
a & b: array([0, 1, 0, 1, 4], dtype=uint8)
|
||||
a & b: array([0, 1, 0, 1, 4], dtype=int16)
|
||||
a & b: array([0, 1, 0, 1, 4], dtype=uint16)
|
||||
a & b: array([0, 1, 0, 1, 4], dtype=int16)
|
||||
a & b (bool): array([0, 1, 0, 1, 0], dtype=uint8)
|
||||
a & b: array([0, 1, 0, 1, 4], dtype=int16)
|
||||
a & b: array([0, 1, 0, 1, 4], dtype=int8)
|
||||
a & b: array([0, 1, 0, 1, 4], dtype=int16)
|
||||
a & b: array([0, 1, 0, 1, 4], dtype=int16)
|
||||
a & b (bool): array([0, 1, 0, 1, 0], dtype=int16)
|
||||
a & b: array([0, 1, 0, 1, 4], dtype=uint16)
|
||||
a & b: array([0, 1, 0, 1, 4], dtype=int16)
|
||||
a & b: array([0, 1, 0, 1, 4], dtype=uint16)
|
||||
dtype of int32 is not supported
|
||||
a & b (bool): array([0, 1, 0, 1, 0], dtype=uint16)
|
||||
a & b: array([0, 1, 0, 1, 4], dtype=int16)
|
||||
a & b: array([0, 1, 0, 1, 4], dtype=int16)
|
||||
dtype of int32 is not supported
|
||||
a & b: array([0, 1, 0, 1, 4], dtype=int16)
|
||||
a & b (bool): array([0, 1, 0, 1, 0], dtype=int16)
|
||||
21
tests/2d/numpy/or.py
Normal file
21
tests/2d/numpy/or.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
try:
|
||||
from ulab import numpy as np
|
||||
except ImportError:
|
||||
import numpy as np
|
||||
|
||||
dtypes = (np.uint8, np.int8, np.uint16, np.int16)
|
||||
|
||||
for dtype_a in dtypes:
|
||||
a = np.array(range(5), dtype=dtype_a)
|
||||
for dtype_b in dtypes:
|
||||
b = np.array(range(250, 255), dtype=dtype_b)
|
||||
try:
|
||||
print('a | b: ', a | b)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
b = np.array([False, True, False, True, False], dtype=np.bool)
|
||||
try:
|
||||
print('a | b (bool): ', a | b)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
20
tests/2d/numpy/or.py.exp
Normal file
20
tests/2d/numpy/or.py.exp
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
a | b: array([250, 251, 254, 255, 254], dtype=uint8)
|
||||
a | b: array([-6, -5, -2, -1, -2], dtype=int16)
|
||||
a | b: array([250, 251, 254, 255, 254], dtype=uint16)
|
||||
a | b: array([250, 251, 254, 255, 254], dtype=int16)
|
||||
a | b (bool): array([0, 1, 2, 3, 4], dtype=uint8)
|
||||
a | b: array([250, 251, 254, 255, 254], dtype=int16)
|
||||
a | b: array([-6, -5, -2, -1, -2], dtype=int8)
|
||||
a | b: array([250, 251, 254, 255, 254], dtype=int16)
|
||||
a | b: array([250, 251, 254, 255, 254], dtype=int16)
|
||||
a | b (bool): array([0, 1, 2, 3, 4], dtype=int16)
|
||||
a | b: array([250, 251, 254, 255, 254], dtype=uint16)
|
||||
a | b: array([-6, -5, -2, -1, -2], dtype=int16)
|
||||
a | b: array([250, 251, 254, 255, 254], dtype=uint16)
|
||||
dtype of int32 is not supported
|
||||
a | b (bool): array([0, 1, 2, 3, 4], dtype=uint16)
|
||||
a | b: array([250, 251, 254, 255, 254], dtype=int16)
|
||||
a | b: array([-6, -5, -2, -1, -2], dtype=int16)
|
||||
dtype of int32 is not supported
|
||||
a | b: array([250, 251, 254, 255, 254], dtype=int16)
|
||||
a | b (bool): array([0, 1, 2, 3, 4], dtype=int16)
|
||||
21
tests/2d/numpy/xor.py
Normal file
21
tests/2d/numpy/xor.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
try:
|
||||
from ulab import numpy as np
|
||||
except ImportError:
|
||||
import numpy as np
|
||||
|
||||
dtypes = (np.uint8, np.int8, np.uint16, np.int16)
|
||||
|
||||
for dtype_a in dtypes:
|
||||
a = np.array(range(5), dtype=dtype_a)
|
||||
for dtype_b in dtypes:
|
||||
b = np.array(range(250, 255), dtype=dtype_b)
|
||||
try:
|
||||
print('a ^ b: ', a ^ b)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
b = np.array([False, True, False, True, False], dtype=np.bool)
|
||||
try:
|
||||
print('a ^ b (bool): ', a ^ b)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
20
tests/2d/numpy/xor.py.exp
Normal file
20
tests/2d/numpy/xor.py.exp
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
a ^ b: array([250, 250, 254, 254, 250], dtype=uint8)
|
||||
a ^ b: array([-6, -6, -2, -2, -6], dtype=int16)
|
||||
a ^ b: array([250, 250, 254, 254, 250], dtype=uint16)
|
||||
a ^ b: array([250, 250, 254, 254, 250], dtype=int16)
|
||||
a ^ b (bool): array([0, 0, 2, 2, 4], dtype=uint8)
|
||||
a ^ b: array([250, 250, 254, 254, 250], dtype=int16)
|
||||
a ^ b: array([-6, -6, -2, -2, -6], dtype=int8)
|
||||
a ^ b: array([250, 250, 254, 254, 250], dtype=int16)
|
||||
a ^ b: array([250, 250, 254, 254, 250], dtype=int16)
|
||||
a ^ b (bool): array([0, 0, 2, 2, 4], dtype=int16)
|
||||
a ^ b: array([250, 250, 254, 254, 250], dtype=uint16)
|
||||
a ^ b: array([-6, -6, -2, -2, -6], dtype=int16)
|
||||
a ^ b: array([250, 250, 254, 254, 250], dtype=uint16)
|
||||
dtype of int32 is not supported
|
||||
a ^ b (bool): array([0, 0, 2, 2, 4], dtype=uint16)
|
||||
a ^ b: array([250, 250, 254, 254, 250], dtype=int16)
|
||||
a ^ b: array([-6, -6, -2, -2, -6], dtype=int16)
|
||||
dtype of int32 is not supported
|
||||
a ^ b: array([250, 250, 254, 254, 250], dtype=int16)
|
||||
a ^ b (bool): array([0, 0, 2, 2, 4], dtype=int16)
|
||||
Loading…
Reference in a new issue