codon/test/numpy/test_fusion.codon

2065 lines
153 KiB
Python

import numpy as np
L: List[str] = []
@pure
def f(x, label):
L.append(label)
return x
def eq(got, exp, dtype: type):
if got.dtype is not dtype:
print('-> dtype mismatch: got', got.dtype.__name__, 'but expected', dtype.__name__)
return False
return np.allclose(got, np.asarray(exp, dtype), equal_nan=True, atol=1e-10)
@test
def test_basic():
# A few trivial cases
a = np.array([1, 2, 3, 4])
b = np.array([10, 11, 12, 13])
assert eq((1 + a)/2, [1., 1.5, 2., 2.5], float)
assert eq(a + b**2, [101, 123, 147, 173], int)
assert eq(np.multiply(a, b) + np.subtract(a, b) + np.square(a) + (b**2), [102, 138, 180, 228], int)
@test
def test_order():
# Make sure things are executed in the correct order after fusion
L.clear()
a = np.array([1, 2, 3, 4])
b = np.array([10, 11, 12, 13])
z = (f(1, '1') + f(a, 'a')) * (f(b, 'b') + f(2, '2'))
assert eq(z, [24, 39, 56, 75], int)
assert L == ['1', 'a', 'b', '2']
@test
def test_ops_int64():
a = np.array([1, 2, 3, 4])
assert eq(1 + (+a), [2, 3, 4, 5], int)
assert eq(1 + (-a), [0, -1, -2, -3], int)
assert eq(1 + (~a), [-1, -2, -3, -4], int)
assert eq(1 + np.abs(a), [2, 3, 4, 5], int)
assert eq(1 + abs(a), [2, 3, 4, 5], int)
assert eq(2 * (1 + a), [4, 6, 8, 10], int)
assert eq(2 * (a + 1), [4, 6, 8, 10], int)
assert eq(2 * (a - 1), [0, 2, 4, 6], int)
assert eq(2 * (1 - a), [0, -2, -4, -6], int)
assert eq(1 + (a * 2), [3, 5, 7, 9], int)
assert eq(1 + (2 * a), [3, 5, 7, 9], int)
assert eq(1 + (a.reshape(1, -1) @ a.reshape(-1, 1)), [[31]], int)
assert eq(1 + (a / 2), [1.5, 2., 2.5, 3.], float)
assert eq(1 + (2 / a), [3., 2., 1 + 2/3, 1.5], float)
assert eq(1 + (a // 2), [1, 2, 2, 3], int)
assert eq(1 + (10 // a), [11, 6, 4, 3], int)
assert eq(1 + (a % 3), [2, 3, 1, 2], int)
assert eq(1 + (10 % a), [1, 1, 2, 3], int)
assert eq(1 + np.fmod(a, 3), [2, 3, 1, 2], int)
assert eq(1 + np.fmod(10, a), [1, 1, 2, 3], int)
assert eq(1 + (a ** 3), [2, 9, 28, 65], int)
assert eq(1 + (3 ** a), [4, 10, 28, 82], int)
assert eq(1 + (a << 3), [9, 17, 25, 33], int)
assert eq(1 + (3 << a), [7, 13, 25, 49], int)
assert eq(1 + (a >> 1), [1, 2, 2, 3], int)
assert eq(1 + (1000 >> a), [501, 251, 126, 63], int)
assert eq(1 + (a & 2), [1, 3, 3, 1], int)
assert eq(1 + (2 & a), [1, 3, 3, 1], int)
assert eq(1 + (a | 2), [4, 3, 4, 7], int)
assert eq(1 + (2 | a), [4, 3, 4, 7], int)
assert eq(1 + (a ^ 2), [4, 1, 2, 7], int)
assert eq(1 + (2 ^ a), [4, 1, 2, 7], int)
assert eq(np.logical_and(a, a & 1), [True, False, True, False], bool)
assert eq(np.logical_or(a & 2, a & 1), [True, True, True, False], bool)
assert eq(np.logical_xor(a, a & 1), [False, True, False, True], bool)
assert eq((a + 1) == 2, [True, False, False, False], bool)
assert eq(2 == (a + 1), [True, False, False, False], bool)
assert eq((a + 1) != 2, [False, True, True, True], bool)
assert eq(2 != (a + 1), [False, True, True, True], bool)
assert eq((a + 1) < 3, [True, False, False, False], bool)
assert eq(3 < (a + 1), [False, False, True, True], bool)
assert eq((a + 1) > 3, [False, False, True, True], bool)
assert eq(3 > (a + 1), [True, False, False, False], bool)
assert eq((a + 1) <= 3, [True, True, False, False], bool)
assert eq(3 <= (a + 1), [False, True, True, True], bool)
assert eq((a + 1) >= 3, [False, True, True, True], bool)
assert eq(3 >= (a + 1), [True, True, False, False], bool)
assert eq(1 + np.minimum(a, 3), [2, 3, 4, 4], int)
assert eq(1 + np.minimum(3, a), [2, 3, 4, 4], int)
assert eq(1 + np.maximum(a, 3), [4, 4, 4, 5], int)
assert eq(1 + np.maximum(3, a), [4, 4, 4, 5], int)
assert eq(1 + np.fmin(a, 3), [2, 3, 4, 4], int)
assert eq(1 + np.fmin(3, a), [2, 3, 4, 4], int)
assert eq(1 + np.fmax(a, 3), [4, 4, 4, 5], int)
assert eq(1 + np.fmax(3, a), [4, 4, 4, 5], int)
assert eq(1 + np.sin(a), [1 + np.sin(1), 1 + np.sin(2), 1 + np.sin(3), 1 + np.sin(4)], float)
assert eq(1 + np.cos(a), [1 + np.cos(1), 1 + np.cos(2), 1 + np.cos(3), 1 + np.cos(4)], float)
assert eq(1 + np.tan(a), [1 + np.tan(1), 1 + np.tan(2), 1 + np.tan(3), 1 + np.tan(4)], float)
assert eq(1 + np.arcsin(a), [1 + np.arcsin(1), 1 + np.arcsin(2), 1 + np.arcsin(3), 1 + np.arcsin(4)], float)
assert eq(1 + np.arccos(a), [1 + np.arccos(1), 1 + np.arccos(2), 1 + np.arccos(3), 1 + np.arccos(4)], float)
assert eq(1 + np.arctan(a), [1 + np.arctan(1), 1 + np.arctan(2), 1 + np.arctan(3), 1 + np.arctan(4)], float)
assert eq(1 + np.arctan2(a, 3), [1 + np.arctan2(1, 3), 1 + np.arctan2(2, 3), 1 + np.arctan2(3, 3), 1 + np.arctan2(4, 3)], float)
assert eq(1 + np.arctan2(3, a), [1 + np.arctan2(3, 1), 1 + np.arctan2(3, 2), 1 + np.arctan2(3, 3), 1 + np.arctan2(3, 4)], float)
assert eq(1 + np.hypot(a, 3), [1 + np.hypot(1, 3), 1 + np.hypot(2, 3), 1 + np.hypot(3, 3), 1 + np.hypot(4, 3)], float)
assert eq(1 + np.hypot(3, a), [1 + np.hypot(3, 1), 1 + np.hypot(3, 2), 1 + np.hypot(3, 3), 1 + np.hypot(3, 4)], float)
assert eq(1 + np.sinh(a), [1 + np.sinh(1), 1 + np.sinh(2), 1 + np.sinh(3), 1 + np.sinh(4)], float)
assert eq(1 + np.cosh(a), [1 + np.cosh(1), 1 + np.cosh(2), 1 + np.cosh(3), 1 + np.cosh(4)], float)
assert eq(1 + np.tanh(a), [1 + np.tanh(1), 1 + np.tanh(2), 1 + np.tanh(3), 1 + np.tanh(4)], float)
assert eq(1 + np.arcsinh(a), [1 + np.arcsinh(1), 1 + np.arcsinh(2), 1 + np.arcsinh(3), 1 + np.arcsinh(4)], float)
assert eq(1 + np.arccosh(a), [1 + np.arccosh(1), 1 + np.arccosh(2), 1 + np.arccosh(3), 1 + np.arccosh(4)], float)
assert eq(1 + np.arctanh(a), [1 + np.arctanh(1), 1 + np.arctanh(2), 1 + np.arctanh(3), 1 + np.arctanh(4)], float)
assert eq(1 + np.conj(a), [1 + np.conj(1), 1 + np.conj(2), 1 + np.conj(3), 1 + np.conj(4)], int)
assert eq(1 + np.exp(a), [1 + np.exp(1), 1 + np.exp(2), 1 + np.exp(3), 1 + np.exp(4)], float)
assert eq(1 + np.exp2(a), [1 + np.exp2(1), 1 + np.exp2(2), 1 + np.exp2(3), 1 + np.exp2(4)], float)
assert eq(1 + np.log(a), [1 + np.log(1), 1 + np.log(2), 1 + np.log(3), 1 + np.log(4)], float)
assert eq(1 + np.log2(a), [1 + np.log2(1), 1 + np.log2(2), 1 + np.log2(3), 1 + np.log2(4)], float)
assert eq(1 + np.log10(a), [1 + np.log10(1), 1 + np.log10(2), 1 + np.log10(3), 1 + np.log10(4)], float)
assert eq(1 + np.expm1(a), [1 + np.expm1(1), 1 + np.expm1(2), 1 + np.expm1(3), 1 + np.expm1(4)], float)
assert eq(1 + np.log1p(a), [1 + np.log1p(1), 1 + np.log1p(2), 1 + np.log1p(3), 1 + np.log1p(4)], float)
assert eq(1 + np.sqrt(a), [1 + np.sqrt(1), 1 + np.sqrt(2), 1 + np.sqrt(3), 1 + np.sqrt(4)], float)
assert eq(1 + np.square(a), [1 + np.square(1), 1 + np.square(2), 1 + np.square(3), 1 + np.square(4)], int)
assert eq(1 + np.cbrt(a), [1 + np.cbrt(1), 1 + np.cbrt(2), 1 + np.cbrt(3), 1 + np.cbrt(4)], float)
assert eq(1 + np.logaddexp(a, 3), [1 + np.logaddexp(1, 3), 1 + np.logaddexp(2, 3), 1 + np.logaddexp(3, 3), 1 + np.logaddexp(4, 3)], float)
assert eq(1 + np.logaddexp(3, a), [1 + np.logaddexp(3, 1), 1 + np.logaddexp(3, 2), 1 + np.logaddexp(3, 3), 1 + np.logaddexp(3, 4)], float)
assert eq(1 + np.logaddexp2(a, 3), [1 + np.logaddexp2(1, 3), 1 + np.logaddexp2(2, 3), 1 + np.logaddexp2(3, 3), 1 + np.logaddexp2(4, 3)], float)
assert eq(1 + np.logaddexp2(3, a), [1 + np.logaddexp2(3, 1), 1 + np.logaddexp2(3, 2), 1 + np.logaddexp2(3, 3), 1 + np.logaddexp2(3, 4)], float)
assert eq(1 + np.reciprocal(a), [2, 1, 1, 1], int)
assert eq(1 + np.rint(a), [1 + np.rint(1), 1 + np.rint(2), 1 + np.rint(3), 1 + np.rint(4)], float)
assert eq(1 + np.floor(a), [1 + np.floor(1), 1 + np.floor(2), 1 + np.floor(3), 1 + np.floor(4)], float)
assert eq(1 + np.ceil(a), [1 + np.ceil(1), 1 + np.ceil(2), 1 + np.ceil(3), 1 + np.ceil(4)], float)
assert eq(1 + np.trunc(a), [1 + np.trunc(1), 1 + np.trunc(2), 1 + np.trunc(3), 1 + np.trunc(4)], float)
assert eq(1 + np.isnan(a), [1, 1, 1, 1], int)
assert eq(1 + np.isinf(a), [1, 1, 1, 1], int)
assert eq(1 + np.isfinite(a), [2, 2, 2, 2], int)
assert eq(1 + np.ldexp(a, 1), [1 + np.ldexp(1, 1), 1 + np.ldexp(2, 1), 1 + np.ldexp(3, 1), 1 + np.ldexp(4, 1)], float)
assert eq(1 + np.ldexp(1, a), [1 + np.ldexp(1, 1), 1 + np.ldexp(1, 2), 1 + np.ldexp(1, 3), 1 + np.ldexp(1, 4)], float)
assert eq(1 + np.sign(a), [2, 2, 2, 2], int)
assert eq(1 + np.signbit(a), [1, 1, 1, 1], int)
assert eq(1 + np.copysign(a, -1), [1 + np.copysign(1, -1), 1 + np.copysign(2, -1), 1 + np.copysign(3, -1), 1 + np.copysign(4, -1)], float)
assert eq(1 + np.copysign(-1, a), [1 + np.copysign(-1, 1), 1 + np.copysign(-1, 2), 1 + np.copysign(-1, 3), 1 + np.copysign(-1, 4)], float)
assert eq(1 + np.spacing(a), [1 + np.spacing(1), 1 + np.spacing(2), 1 + np.spacing(3), 1 + np.spacing(4)], float)
assert eq(1 + np.nextafter(a, 1), [1 + np.nextafter(1, 1), 1 + np.nextafter(2, 1), 1 + np.nextafter(3, 1), 1 + np.nextafter(4, 1)], float)
assert eq(1 + np.nextafter(1, a), [1 + np.nextafter(1, 1), 1 + np.nextafter(1, 2), 1 + np.nextafter(1, 3), 1 + np.nextafter(1, 4)], float)
assert eq(1 + np.deg2rad(a), [1 + np.deg2rad(1), 1 + np.deg2rad(2), 1 + np.deg2rad(3), 1 + np.deg2rad(4)], float)
assert eq(1 + np.rad2deg(a), [1 + np.rad2deg(1), 1 + np.rad2deg(2), 1 + np.rad2deg(3), 1 + np.rad2deg(4)], float)
assert eq(1 + np.heaviside(a, 1), [1 + np.heaviside(1, 1), 1 + np.heaviside(2, 1), 1 + np.heaviside(3, 1), 1 + np.heaviside(4, 1)], float)
assert eq(1 + np.heaviside(1, a), [1 + np.heaviside(1, 1), 1 + np.heaviside(1, 2), 1 + np.heaviside(1, 3), 1 + np.heaviside(1, 4)], float)
@test
def test_ops_int32():
a = np.array([1, 2, 3, 4], np.int32)
assert eq(1 + (+a), [2, 3, 4, 5], np.int32)
assert eq(1 + (-a), [0, -1, -2, -3], np.int32)
assert eq(1 + (~a), [-1, -2, -3, -4], np.int32)
assert eq(1 + np.abs(a), [2, 3, 4, 5], np.int32)
assert eq(1 + abs(a), [2, 3, 4, 5], np.int32)
assert eq(2 * (1 + a), [4, 6, 8, 10], np.int32)
assert eq(2 * (a + 1), [4, 6, 8, 10], np.int32)
assert eq(2 * (a - 1), [0, 2, 4, 6], np.int32)
assert eq(2 * (1 - a), [0, -2, -4, -6], np.int32)
assert eq(1 + (a * 2), [3, 5, 7, 9], np.int32)
assert eq(1 + (2 * a), [3, 5, 7, 9], np.int32)
assert eq(1 + (a.reshape(1, -1) @ a.reshape(-1, 1)), [[31]], np.int32)
assert eq(1 + (a / 2), [1.5, 2., 2.5, 3.], float)
assert eq(1 + (2 / a), [3., 2., 1 + 2/3, 1.5], float)
assert eq(1 + (a // 2), [1, 2, 2, 3], np.int32)
assert eq(1 + (10 // a), [11, 6, 4, 3], np.int32)
assert eq(1 + (a % 3), [2, 3, 1, 2], np.int32)
assert eq(1 + (10 % a), [1, 1, 2, 3], np.int32)
assert eq(1 + np.fmod(a, 3), [2, 3, 1, 2], np.int32)
assert eq(1 + np.fmod(10, a), [1, 1, 2, 3], np.int32)
assert eq(1 + (a ** 3), [2, 9, 28, 65], np.int32)
assert eq(1 + (3 ** a), [4, 10, 28, 82], np.int32)
assert eq(1 + (a << 3), [9, 17, 25, 33], np.int32)
assert eq(1 + (3 << a), [7, 13, 25, 49], np.int32)
assert eq(1 + (a >> 1), [1, 2, 2, 3], np.int32)
assert eq(1 + (1000 >> a), [501, 251, 126, 63], np.int32)
assert eq(1 + (a & 2), [1, 3, 3, 1], np.int32)
assert eq(1 + (2 & a), [1, 3, 3, 1], np.int32)
assert eq(1 + (a | 2), [4, 3, 4, 7], np.int32)
assert eq(1 + (2 | a), [4, 3, 4, 7], np.int32)
assert eq(1 + (a ^ 2), [4, 1, 2, 7], np.int32)
assert eq(1 + (2 ^ a), [4, 1, 2, 7], np.int32)
assert eq(np.logical_and(a, a & 1), [True, False, True, False], bool)
assert eq(np.logical_or(a & 2, a & 1), [True, True, True, False], bool)
assert eq(np.logical_xor(a, a & 1), [False, True, False, True], bool)
assert eq((a + 1) == 2, [True, False, False, False], bool)
assert eq(2 == (a + 1), [True, False, False, False], bool)
assert eq((a + 1) != 2, [False, True, True, True], bool)
assert eq(2 != (a + 1), [False, True, True, True], bool)
assert eq((a + 1) < 3, [True, False, False, False], bool)
assert eq(3 < (a + 1), [False, False, True, True], bool)
assert eq((a + 1) > 3, [False, False, True, True], bool)
assert eq(3 > (a + 1), [True, False, False, False], bool)
assert eq((a + 1) <= 3, [True, True, False, False], bool)
assert eq(3 <= (a + 1), [False, True, True, True], bool)
assert eq((a + 1) >= 3, [False, True, True, True], bool)
assert eq(3 >= (a + 1), [True, True, False, False], bool)
assert eq(1 + np.minimum(a, 3), [2, 3, 4, 4], np.int32)
assert eq(1 + np.minimum(3, a), [2, 3, 4, 4], np.int32)
assert eq(1 + np.maximum(a, 3), [4, 4, 4, 5], np.int32)
assert eq(1 + np.maximum(3, a), [4, 4, 4, 5], np.int32)
assert eq(1 + np.fmin(a, 3), [2, 3, 4, 4], np.int32)
assert eq(1 + np.fmin(3, a), [2, 3, 4, 4], np.int32)
assert eq(1 + np.fmax(a, 3), [4, 4, 4, 5], np.int32)
assert eq(1 + np.fmax(3, a), [4, 4, 4, 5], np.int32)
assert eq(1 + np.sin(a), [1 + np.sin(1), 1 + np.sin(2), 1 + np.sin(3), 1 + np.sin(4)], float)
assert eq(1 + np.cos(a), [1 + np.cos(1), 1 + np.cos(2), 1 + np.cos(3), 1 + np.cos(4)], float)
assert eq(1 + np.tan(a), [1 + np.tan(1), 1 + np.tan(2), 1 + np.tan(3), 1 + np.tan(4)], float)
assert eq(1 + np.arcsin(a), [1 + np.arcsin(1), 1 + np.arcsin(2), 1 + np.arcsin(3), 1 + np.arcsin(4)], float)
assert eq(1 + np.arccos(a), [1 + np.arccos(1), 1 + np.arccos(2), 1 + np.arccos(3), 1 + np.arccos(4)], float)
assert eq(1 + np.arctan(a), [1 + np.arctan(1), 1 + np.arctan(2), 1 + np.arctan(3), 1 + np.arctan(4)], float)
assert eq(1 + np.arctan2(a, 3), [1 + np.arctan2(1, 3), 1 + np.arctan2(2, 3), 1 + np.arctan2(3, 3), 1 + np.arctan2(4, 3)], float)
assert eq(1 + np.arctan2(3, a), [1 + np.arctan2(3, 1), 1 + np.arctan2(3, 2), 1 + np.arctan2(3, 3), 1 + np.arctan2(3, 4)], float)
assert eq(1 + np.hypot(a, 3), [1 + np.hypot(1, 3), 1 + np.hypot(2, 3), 1 + np.hypot(3, 3), 1 + np.hypot(4, 3)], float)
assert eq(1 + np.hypot(3, a), [1 + np.hypot(3, 1), 1 + np.hypot(3, 2), 1 + np.hypot(3, 3), 1 + np.hypot(3, 4)], float)
assert eq(1 + np.sinh(a), [1 + np.sinh(1), 1 + np.sinh(2), 1 + np.sinh(3), 1 + np.sinh(4)], float)
assert eq(1 + np.cosh(a), [1 + np.cosh(1), 1 + np.cosh(2), 1 + np.cosh(3), 1 + np.cosh(4)], float)
assert eq(1 + np.tanh(a), [1 + np.tanh(1), 1 + np.tanh(2), 1 + np.tanh(3), 1 + np.tanh(4)], float)
assert eq(1 + np.arcsinh(a), [1 + np.arcsinh(1), 1 + np.arcsinh(2), 1 + np.arcsinh(3), 1 + np.arcsinh(4)], float)
assert eq(1 + np.arccosh(a), [1 + np.arccosh(1), 1 + np.arccosh(2), 1 + np.arccosh(3), 1 + np.arccosh(4)], float)
assert eq(1 + np.arctanh(a), [1 + np.arctanh(1), 1 + np.arctanh(2), 1 + np.arctanh(3), 1 + np.arctanh(4)], float)
assert eq(1 + np.conj(a), [1 + np.conj(1), 1 + np.conj(2), 1 + np.conj(3), 1 + np.conj(4)], np.int32)
assert eq(1 + np.exp(a), [1 + np.exp(1), 1 + np.exp(2), 1 + np.exp(3), 1 + np.exp(4)], float)
assert eq(1 + np.exp2(a), [1 + np.exp2(1), 1 + np.exp2(2), 1 + np.exp2(3), 1 + np.exp2(4)], float)
assert eq(1 + np.log(a), [1 + np.log(1), 1 + np.log(2), 1 + np.log(3), 1 + np.log(4)], float)
assert eq(1 + np.log2(a), [1 + np.log2(1), 1 + np.log2(2), 1 + np.log2(3), 1 + np.log2(4)], float)
assert eq(1 + np.log10(a), [1 + np.log10(1), 1 + np.log10(2), 1 + np.log10(3), 1 + np.log10(4)], float)
assert eq(1 + np.expm1(a), [1 + np.expm1(1), 1 + np.expm1(2), 1 + np.expm1(3), 1 + np.expm1(4)], float)
assert eq(1 + np.log1p(a), [1 + np.log1p(1), 1 + np.log1p(2), 1 + np.log1p(3), 1 + np.log1p(4)], float)
assert eq(1 + np.sqrt(a), [1 + np.sqrt(1), 1 + np.sqrt(2), 1 + np.sqrt(3), 1 + np.sqrt(4)], float)
assert eq(1 + np.square(a), [1 + np.square(1), 1 + np.square(2), 1 + np.square(3), 1 + np.square(4)], np.int32)
assert eq(1 + np.cbrt(a), [1 + np.cbrt(1), 1 + np.cbrt(2), 1 + np.cbrt(3), 1 + np.cbrt(4)], float)
assert eq(1 + np.logaddexp(a, 3), [1 + np.logaddexp(1, 3), 1 + np.logaddexp(2, 3), 1 + np.logaddexp(3, 3), 1 + np.logaddexp(4, 3)], float)
assert eq(1 + np.logaddexp(3, a), [1 + np.logaddexp(3, 1), 1 + np.logaddexp(3, 2), 1 + np.logaddexp(3, 3), 1 + np.logaddexp(3, 4)], float)
assert eq(1 + np.logaddexp2(a, 3), [1 + np.logaddexp2(1, 3), 1 + np.logaddexp2(2, 3), 1 + np.logaddexp2(3, 3), 1 + np.logaddexp2(4, 3)], float)
assert eq(1 + np.logaddexp2(3, a), [1 + np.logaddexp2(3, 1), 1 + np.logaddexp2(3, 2), 1 + np.logaddexp2(3, 3), 1 + np.logaddexp2(3, 4)], float)
assert eq(1 + np.reciprocal(a), [2, 1, 1, 1], np.int32)
assert eq(1 + np.rint(a), [1 + np.rint(1), 1 + np.rint(2), 1 + np.rint(3), 1 + np.rint(4)], float)
assert eq(1 + np.floor(a), [1 + np.floor(1), 1 + np.floor(2), 1 + np.floor(3), 1 + np.floor(4)], float)
assert eq(1 + np.ceil(a), [1 + np.ceil(1), 1 + np.ceil(2), 1 + np.ceil(3), 1 + np.ceil(4)], float)
assert eq(1 + np.trunc(a), [1 + np.trunc(1), 1 + np.trunc(2), 1 + np.trunc(3), 1 + np.trunc(4)], float)
assert eq(1 + np.isnan(a), [1, 1, 1, 1], int)
assert eq(1 + np.isinf(a), [1, 1, 1, 1], int)
assert eq(1 + np.isfinite(a), [2, 2, 2, 2], int)
assert eq(1 + np.ldexp(a, 1), [1 + np.ldexp(1, 1), 1 + np.ldexp(2, 1), 1 + np.ldexp(3, 1), 1 + np.ldexp(4, 1)], float)
assert eq(1 + np.ldexp(1, a), [1 + np.ldexp(1, 1), 1 + np.ldexp(1, 2), 1 + np.ldexp(1, 3), 1 + np.ldexp(1, 4)], float)
assert eq(1 + np.sign(a), [2, 2, 2, 2], np.int32)
assert eq(1 + np.signbit(a), [1, 1, 1, 1], int)
assert eq(1 + np.copysign(a, -1), [1 + np.copysign(1, -1), 1 + np.copysign(2, -1), 1 + np.copysign(3, -1), 1 + np.copysign(4, -1)], float)
assert eq(1 + np.copysign(-1, a), [1 + np.copysign(-1, 1), 1 + np.copysign(-1, 2), 1 + np.copysign(-1, 3), 1 + np.copysign(-1, 4)], float)
assert eq(1 + np.spacing(a), [1 + np.spacing(1), 1 + np.spacing(2), 1 + np.spacing(3), 1 + np.spacing(4)], float)
assert eq(1 + np.nextafter(a, 1), [1 + np.nextafter(1, 1), 1 + np.nextafter(2, 1), 1 + np.nextafter(3, 1), 1 + np.nextafter(4, 1)], float)
assert eq(1 + np.nextafter(1, a), [1 + np.nextafter(1, 1), 1 + np.nextafter(1, 2), 1 + np.nextafter(1, 3), 1 + np.nextafter(1, 4)], float)
assert eq(1 + np.deg2rad(a), [1 + np.deg2rad(1), 1 + np.deg2rad(2), 1 + np.deg2rad(3), 1 + np.deg2rad(4)], float)
assert eq(1 + np.rad2deg(a), [1 + np.rad2deg(1), 1 + np.rad2deg(2), 1 + np.rad2deg(3), 1 + np.rad2deg(4)], float)
assert eq(1 + np.heaviside(a, 1), [1 + np.heaviside(1, 1), 1 + np.heaviside(2, 1), 1 + np.heaviside(3, 1), 1 + np.heaviside(4, 1)], float)
assert eq(1 + np.heaviside(1, a), [1 + np.heaviside(1, 1), 1 + np.heaviside(1, 2), 1 + np.heaviside(1, 3), 1 + np.heaviside(1, 4)], float)
@test
def test_ops_int16():
a = np.array([1, 2, 3, 4], np.int16)
assert eq(1 + (+a), [2, 3, 4, 5], np.int16)
assert eq(1 + (-a), [0, -1, -2, -3], np.int16)
assert eq(1 + (~a), [-1, -2, -3, -4], np.int16)
assert eq(1 + np.abs(a), [2, 3, 4, 5], np.int16)
assert eq(1 + abs(a), [2, 3, 4, 5], np.int16)
assert eq(2 * (1 + a), [4, 6, 8, 10], np.int16)
assert eq(2 * (a + 1), [4, 6, 8, 10], np.int16)
assert eq(2 * (a - 1), [0, 2, 4, 6], np.int16)
assert eq(2 * (1 - a), [0, -2, -4, -6], np.int16)
assert eq(1 + (a * 2), [3, 5, 7, 9], np.int16)
assert eq(1 + (2 * a), [3, 5, 7, 9], np.int16)
assert eq(1 + (a.reshape(1, -1) @ a.reshape(-1, 1)), [[31]], np.int16)
assert eq(1 + (a / 2), [1.5, 2., 2.5, 3.], float)
assert eq(1 + (2 / a), [3., 2., 1 + 2/3, 1.5], float)
assert eq(1 + (a // 2), [1, 2, 2, 3], np.int16)
assert eq(1 + (10 // a), [11, 6, 4, 3], np.int16)
assert eq(1 + (a % 3), [2, 3, 1, 2], np.int16)
assert eq(1 + (10 % a), [1, 1, 2, 3], np.int16)
assert eq(1 + np.fmod(a, 3), [2, 3, 1, 2], np.int16)
assert eq(1 + np.fmod(10, a), [1, 1, 2, 3], np.int16)
assert eq(1 + (a ** 3), [2, 9, 28, 65], np.int16)
assert eq(1 + (3 ** a), [4, 10, 28, 82], np.int16)
assert eq(1 + (a << 3), [9, 17, 25, 33], np.int16)
assert eq(1 + (3 << a), [7, 13, 25, 49], np.int16)
assert eq(1 + (a >> 1), [1, 2, 2, 3], np.int16)
assert eq(1 + (1000 >> a), [501, 251, 126, 63], np.int16)
assert eq(1 + (a & 2), [1, 3, 3, 1], np.int16)
assert eq(1 + (2 & a), [1, 3, 3, 1], np.int16)
assert eq(1 + (a | 2), [4, 3, 4, 7], np.int16)
assert eq(1 + (2 | a), [4, 3, 4, 7], np.int16)
assert eq(1 + (a ^ 2), [4, 1, 2, 7], np.int16)
assert eq(1 + (2 ^ a), [4, 1, 2, 7], np.int16)
assert eq(np.logical_and(a, a & 1), [True, False, True, False], bool)
assert eq(np.logical_or(a & 2, a & 1), [True, True, True, False], bool)
assert eq(np.logical_xor(a, a & 1), [False, True, False, True], bool)
assert eq((a + 1) == 2, [True, False, False, False], bool)
assert eq(2 == (a + 1), [True, False, False, False], bool)
assert eq((a + 1) != 2, [False, True, True, True], bool)
assert eq(2 != (a + 1), [False, True, True, True], bool)
assert eq((a + 1) < 3, [True, False, False, False], bool)
assert eq(3 < (a + 1), [False, False, True, True], bool)
assert eq((a + 1) > 3, [False, False, True, True], bool)
assert eq(3 > (a + 1), [True, False, False, False], bool)
assert eq((a + 1) <= 3, [True, True, False, False], bool)
assert eq(3 <= (a + 1), [False, True, True, True], bool)
assert eq((a + 1) >= 3, [False, True, True, True], bool)
assert eq(3 >= (a + 1), [True, True, False, False], bool)
assert eq(1 + np.minimum(a, 3), [2, 3, 4, 4], np.int16)
assert eq(1 + np.minimum(3, a), [2, 3, 4, 4], np.int16)
assert eq(1 + np.maximum(a, 3), [4, 4, 4, 5], np.int16)
assert eq(1 + np.maximum(3, a), [4, 4, 4, 5], np.int16)
assert eq(1 + np.fmin(a, 3), [2, 3, 4, 4], np.int16)
assert eq(1 + np.fmin(3, a), [2, 3, 4, 4], np.int16)
assert eq(1 + np.fmax(a, 3), [4, 4, 4, 5], np.int16)
assert eq(1 + np.fmax(3, a), [4, 4, 4, 5], np.int16)
assert eq(1 + np.sin(a), [1.f32 + np.sin(1.f32), 1.f32 + np.sin(2.f32), 1.f32 + np.sin(3.f32), 1.f32 + np.sin(4.f32)], np.float32)
assert eq(1 + np.cos(a), [1.f32 + np.cos(1.f32), 1.f32 + np.cos(2.f32), 1.f32 + np.cos(3.f32), 1.f32 + np.cos(4.f32)], np.float32)
assert eq(1 + np.tan(a), [1.f32 + np.tan(1.f32), 1.f32 + np.tan(2.f32), 1.f32 + np.tan(3.f32), 1.f32 + np.tan(4.f32)], np.float32)
assert eq(1 + np.arcsin(a), [1.f32 + np.arcsin(1.f32), 1.f32 + np.arcsin(2.f32), 1.f32 + np.arcsin(3.f32), 1.f32 + np.arcsin(4.f32)], np.float32)
assert eq(1 + np.arccos(a), [1.f32 + np.arccos(1.f32), 1.f32 + np.arccos(2.f32), 1.f32 + np.arccos(3.f32), 1.f32 + np.arccos(4.f32)], np.float32)
assert eq(1 + np.arctan(a), [1.f32 + np.arctan(1.f32), 1.f32 + np.arctan(2.f32), 1.f32 + np.arctan(3.f32), 1.f32 + np.arctan(4.f32)], np.float32)
assert eq(1 + np.arctan2(a, 3.f32), [1.f32 + np.arctan2(1.f32, 3.f32), 1.f32 + np.arctan2(2.f32, 3.f32), 1.f32 + np.arctan2(3.f32, 3.f32), 1.f32 + np.arctan2(4.f32, 3.f32)], np.float32)
assert eq(1 + np.arctan2(3.f32, a), [1.f32 + np.arctan2(3.f32, 1.f32), 1.f32 + np.arctan2(3.f32, 2.f32), 1.f32 + np.arctan2(3.f32, 3.f32), 1.f32 + np.arctan2(3.f32, 4.f32)], np.float32)
assert eq(1 + np.hypot(a, 3), [1.f32 + np.hypot(1.f32, 3.f32), 1.f32 + np.hypot(2.f32, 3.f32), 1.f32 + np.hypot(3.f32, 3.f32), 1.f32 + np.hypot(4.f32, 3.f32)], np.float32)
assert eq(1 + np.hypot(3, a), [1.f32 + np.hypot(3.f32, 1.f32), 1.f32 + np.hypot(3.f32, 2.f32), 1.f32 + np.hypot(3.f32, 3.f32), 1.f32 + np.hypot(3.f32, 4.f32)], np.float32)
assert eq(1 + np.sinh(a), [1.f32 + np.sinh(1.f32), 1.f32 + np.sinh(2.f32), 1.f32 + np.sinh(3.f32), 1.f32 + np.sinh(4.f32)], np.float32)
assert eq(1 + np.cosh(a), [1.f32 + np.cosh(1.f32), 1.f32 + np.cosh(2.f32), 1.f32 + np.cosh(3.f32), 1.f32 + np.cosh(4.f32)], np.float32)
assert eq(1 + np.tanh(a), [1.f32 + np.tanh(1.f32), 1.f32 + np.tanh(2.f32), 1.f32 + np.tanh(3.f32), 1.f32 + np.tanh(4.f32)], np.float32)
assert eq(1 + np.arcsinh(a), [1.f32 + np.arcsinh(1.f32), 1.f32 + np.arcsinh(2.f32), 1.f32 + np.arcsinh(3.f32), 1.f32 + np.arcsinh(4.f32)], np.float32)
assert eq(1 + np.arccosh(a), [1.f32 + np.arccosh(1.f32), 1.f32 + np.arccosh(2.f32), 1.f32 + np.arccosh(3.f32), 1.f32 + np.arccosh(4.f32)], np.float32)
assert eq(1 + np.arctanh(a), [1.f32 + np.arctanh(1.f32), 1.f32 + np.arctanh(2.f32), 1.f32 + np.arctanh(3.f32), 1.f32 + np.arctanh(4.f32)], np.float32)
assert eq(1 + np.conj(a), [1 + np.conj(1), 1 + np.conj(2), 1 + np.conj(3), 1 + np.conj(4)], np.int16)
assert eq(1 + np.exp(a), [1.f32 + np.exp(1.f32), 1.f32 + np.exp(2.f32), 1.f32 + np.exp(3.f32), 1.f32 + np.exp(4.f32)], np.float32)
assert eq(1 + np.exp2(a), [1.f32 + np.exp2(1.f32), 1.f32 + np.exp2(2.f32), 1.f32 + np.exp2(3.f32), 1.f32 + np.exp2(4.f32)], np.float32)
assert eq(1 + np.log(a), [1.f32 + np.log(1.f32), 1.f32 + np.log(2.f32), 1.f32 + np.log(3.f32), 1.f32 + np.log(4.f32)], np.float32)
assert eq(1 + np.log2(a), [1.f32 + np.log2(1.f32), 1.f32 + np.log2(2.f32), 1.f32 + np.log2(3.f32), 1.f32 + np.log2(4.f32)], np.float32)
assert eq(1 + np.log10(a), [1.f32 + np.log10(1.f32), 1.f32 + np.log10(2.f32), 1.f32 + np.log10(3.f32), 1.f32 + np.log10(4.f32)], np.float32)
assert eq(1 + np.expm1(a), [1.f32 + np.expm1(1.f32), 1.f32 + np.expm1(2.f32), 1.f32 + np.expm1(3.f32), 1.f32 + np.expm1(4.f32)], np.float32)
assert eq(1 + np.log1p(a), [1.f32 + np.log1p(1.f32), 1.f32 + np.log1p(2.f32), 1.f32 + np.log1p(3.f32), 1.f32 + np.log1p(4.f32)], np.float32)
assert eq(1 + np.sqrt(a), [1.f32 + np.sqrt(1.f32), 1.f32 + np.sqrt(2.f32), 1.f32 + np.sqrt(3.f32), 1.f32 + np.sqrt(4.f32)], np.float32)
assert eq(1 + np.square(a), [1 + np.square(1), 1 + np.square(2), 1 + np.square(3), 1 + np.square(4)], np.int16)
assert eq(1 + np.cbrt(a), [1.f32 + np.cbrt(1.f32), 1.f32 + np.cbrt(2.f32), 1.f32 + np.cbrt(3.f32), 1.f32 + np.cbrt(4.f32)], np.float32)
assert eq(1 + np.logaddexp(a, 3), [1.f32 + np.logaddexp(1.f32, 3.f32), 1.f32 + np.logaddexp(2.f32, 3.f32), 1.f32 + np.logaddexp(3.f32, 3.f32), 1.f32 + np.logaddexp(4.f32, 3.f32)], np.float32)
assert eq(1 + np.logaddexp(3, a), [1.f32 + np.logaddexp(3.f32, 1.f32), 1.f32 + np.logaddexp(3.f32, 2.f32), 1.f32 + np.logaddexp(3.f32, 3.f32), 1.f32 + np.logaddexp(3.f32, 4.f32)], np.float32)
assert eq(1 + np.logaddexp2(a, 3), [1.f32 + np.logaddexp2(1.f32, 3.f32), 1.f32 + np.logaddexp2(2.f32, 3.f32), 1.f32 + np.logaddexp2(3.f32, 3.f32), 1.f32 + np.logaddexp2(4.f32, 3.f32)], np.float32)
assert eq(1 + np.logaddexp2(3, a), [1.f32 + np.logaddexp2(3.f32, 1.f32), 1.f32 + np.logaddexp2(3.f32, 2.f32), 1.f32 + np.logaddexp2(3.f32, 3.f32), 1.f32 + np.logaddexp2(3.f32, 4.f32)], np.float32)
assert eq(1 + np.reciprocal(a), [2, 1, 1, 1], np.int16)
assert eq(1 + np.rint(a), [1.f32 + np.rint(1.f32), 1.f32 + np.rint(2.f32), 1.f32 + np.rint(3.f32), 1.f32 + np.rint(4.f32)], np.float32)
assert eq(1 + np.floor(a), [1.f32 + np.floor(1.f32), 1.f32 + np.floor(2.f32), 1.f32 + np.floor(3.f32), 1.f32 + np.floor(4.f32)], np.float32)
assert eq(1 + np.ceil(a), [1.f32 + np.ceil(1.f32), 1.f32 + np.ceil(2.f32), 1.f32 + np.ceil(3.f32), 1.f32 + np.ceil(4.f32)], np.float32)
assert eq(1 + np.trunc(a), [1.f32 + np.trunc(1.f32), 1.f32 + np.trunc(2.f32), 1.f32 + np.trunc(3.f32), 1.f32 + np.trunc(4.f32)], np.float32)
assert eq(1 + np.isnan(a), [1, 1, 1, 1], int)
assert eq(1 + np.isinf(a), [1, 1, 1, 1], int)
assert eq(1 + np.isfinite(a), [2, 2, 2, 2], int)
assert eq(1 + np.ldexp(a, 1), [1.f32 + np.ldexp(1.f32, 1), 1.f32 + np.ldexp(2.f32, 1), 1.f32 + np.ldexp(3.f32, 1), 1.f32 + np.ldexp(4.f32, 1)], np.float32)
assert eq(1 + np.ldexp(1, a), [1.f32 + np.ldexp(1.f32, 1), 1.f32 + np.ldexp(1.f32, 2), 1.f32 + np.ldexp(1.f32, 3), 1.f32 + np.ldexp(1.f32, 4)], np.float32)
assert eq(1 + np.sign(a), [2, 2, 2, 2], np.int16)
assert eq(1 + np.signbit(a), [1, 1, 1, 1], int)
assert eq(1 + np.copysign(a, -1), [1.f32 + np.copysign(1.f32, -1.f32), 1.f32 + np.copysign(2.f32, -1.f32), 1.f32 + np.copysign(3.f32, -1.f32), 1.f32 + np.copysign(4.f32, -1.f32)], np.float32)
assert eq(1 + np.copysign(-1, a), [1.f32 + np.copysign(-1.f32, 1.f32), 1.f32 + np.copysign(-1.f32, 2.f32), 1.f32 + np.copysign(-1.f32, 3.f32), 1.f32 + np.copysign(-1.f32, 4.f32)], np.float32)
assert eq(1 + np.spacing(a), [1.f32 + np.spacing(1.f32), 1.f32 + np.spacing(2.f32), 1.f32 + np.spacing(3.f32), 1.f32 + np.spacing(4.f32)], np.float32)
assert eq(1 + np.nextafter(a, 1), [1.f32 + np.nextafter(1.f32, 1.f32), 1.f32 + np.nextafter(2.f32, 1.f32), 1.f32 + np.nextafter(3.f32, 1.f32), 1.f32 + np.nextafter(4.f32, 1.f32)], np.float32)
assert eq(1 + np.nextafter(1, a), [1.f32 + np.nextafter(1.f32, 1.f32), 1.f32 + np.nextafter(1.f32, 2.f32), 1.f32 + np.nextafter(1.f32, 3.f32), 1.f32 + np.nextafter(1.f32, 4.f32)], np.float32)
assert eq(1 + np.deg2rad(a), [1.f32 + np.deg2rad(1.f32), 1.f32 + np.deg2rad(2.f32), 1.f32 + np.deg2rad(3.f32), 1.f32 + np.deg2rad(4.f32)], np.float32)
assert eq(1 + np.rad2deg(a), [1.f32 + np.rad2deg(1.f32), 1.f32 + np.rad2deg(2.f32), 1.f32 + np.rad2deg(3.f32), 1.f32 + np.rad2deg(4.f32)], np.float32)
assert eq(1 + np.heaviside(a, 1), [1.f32 + np.heaviside(1.f32, 1.f32), 1.f32 + np.heaviside(2.f32, 1.f32), 1.f32 + np.heaviside(3.f32, 1.f32), 1.f32 + np.heaviside(4.f32, 1.f32)], np.float32)
assert eq(1 + np.heaviside(1, a), [1.f32 + np.heaviside(1.f32, 1.f32), 1.f32 + np.heaviside(1.f32, 2.f32), 1.f32 + np.heaviside(1.f32, 3.f32), 1.f32 + np.heaviside(1.f32, 4.f32)], np.float32)
@test
def test_ops_int8():
a = np.array([1, 2, 3, 4], np.int8)
assert eq(1 + (+a), [2, 3, 4, 5], np.int8)
assert eq(1 + (-a), [0, -1, -2, -3], np.int8)
assert eq(1 + (~a), [-1, -2, -3, -4], np.int8)
assert eq(1 + np.abs(a), [2, 3, 4, 5], np.int8)
assert eq(1 + abs(a), [2, 3, 4, 5], np.int8)
assert eq(2 * (1 + a), [4, 6, 8, 10], np.int8)
assert eq(2 * (a + 1), [4, 6, 8, 10], np.int8)
assert eq(2 * (a - 1), [0, 2, 4, 6], np.int8)
assert eq(2 * (1 - a), [0, -2, -4, -6], np.int8)
assert eq(1 + (a * 2), [3, 5, 7, 9], np.int8)
assert eq(1 + (2 * a), [3, 5, 7, 9], np.int8)
assert eq(1 + (a.reshape(1, -1) @ a.reshape(-1, 1)), [[31]], np.int8)
assert eq(1 + (a / 2), [1.5, 2., 2.5, 3.], float)
assert eq(1 + (2 / a), [3., 2., 1 + 2/3, 1.5], float)
assert eq(1 + (a // 2), [1, 2, 2, 3], np.int8)
assert eq(1 + (10 // a), [11, 6, 4, 3], np.int8)
assert eq(1 + (a % 3), [2, 3, 1, 2], np.int8)
assert eq(1 + (10 % a), [1, 1, 2, 3], np.int8)
assert eq(1 + np.fmod(a, 3), [2, 3, 1, 2], np.int8)
assert eq(1 + np.fmod(10, a), [1, 1, 2, 3], np.int8)
assert eq(1 + (a ** 3), [2, 9, 28, 65], np.int8)
assert eq(1 + (3 ** a), [4, 10, 28, 82], np.int8)
assert eq(1 + (a << 3), [9, 17, 25, 33], np.int8)
assert eq(1 + (3 << a), [7, 13, 25, 49], np.int8)
assert eq(1 + (a >> 1), [1, 2, 2, 3], np.int8)
assert eq(1 + (100 >> a), [51, 26, 13, 7], np.int8)
assert eq(1 + (a & 2), [1, 3, 3, 1], np.int8)
assert eq(1 + (2 & a), [1, 3, 3, 1], np.int8)
assert eq(1 + (a | 2), [4, 3, 4, 7], np.int8)
assert eq(1 + (2 | a), [4, 3, 4, 7], np.int8)
assert eq(1 + (a ^ 2), [4, 1, 2, 7], np.int8)
assert eq(1 + (2 ^ a), [4, 1, 2, 7], np.int8)
assert eq(np.logical_and(a, a & 1), [True, False, True, False], bool)
assert eq(np.logical_or(a & 2, a & 1), [True, True, True, False], bool)
assert eq(np.logical_xor(a, a & 1), [False, True, False, True], bool)
assert eq((a + 1) == 2, [True, False, False, False], bool)
assert eq(2 == (a + 1), [True, False, False, False], bool)
assert eq((a + 1) != 2, [False, True, True, True], bool)
assert eq(2 != (a + 1), [False, True, True, True], bool)
assert eq((a + 1) < 3, [True, False, False, False], bool)
assert eq(3 < (a + 1), [False, False, True, True], bool)
assert eq((a + 1) > 3, [False, False, True, True], bool)
assert eq(3 > (a + 1), [True, False, False, False], bool)
assert eq((a + 1) <= 3, [True, True, False, False], bool)
assert eq(3 <= (a + 1), [False, True, True, True], bool)
assert eq((a + 1) >= 3, [False, True, True, True], bool)
assert eq(3 >= (a + 1), [True, True, False, False], bool)
assert eq(1 + np.minimum(a, 3), [2, 3, 4, 4], np.int8)
assert eq(1 + np.minimum(3, a), [2, 3, 4, 4], np.int8)
assert eq(1 + np.maximum(a, 3), [4, 4, 4, 5], np.int8)
assert eq(1 + np.maximum(3, a), [4, 4, 4, 5], np.int8)
assert eq(1 + np.fmin(a, 3), [2, 3, 4, 4], np.int8)
assert eq(1 + np.fmin(3, a), [2, 3, 4, 4], np.int8)
assert eq(1 + np.fmax(a, 3), [4, 4, 4, 5], np.int8)
assert eq(1 + np.fmax(3, a), [4, 4, 4, 5], np.int8)
assert eq(1 + np.sin(a), [1.f16 + np.sin(1.f16), 1.f16 + np.sin(2.f16), 1.f16 + np.sin(3.f16), 1.f16 + np.sin(4.f16)], np.float16)
assert eq(1 + np.cos(a), [1.f16 + np.cos(1.f16), 1.f16 + np.cos(2.f16), 1.f16 + np.cos(3.f16), 1.f16 + np.cos(4.f16)], np.float16)
assert eq(1 + np.tan(a), [1.f16 + np.tan(1.f16), 1.f16 + np.tan(2.f16), 1.f16 + np.tan(3.f16), 1.f16 + np.tan(4.f16)], np.float16)
assert eq(1 + np.arcsin(a), [1.f16 + np.arcsin(1.f16), 1.f16 + np.arcsin(2.f16), 1.f16 + np.arcsin(3.f16), 1.f16 + np.arcsin(4.f16)], np.float16)
assert eq(1 + np.arccos(a), [1.f16 + np.arccos(1.f16), 1.f16 + np.arccos(2.f16), 1.f16 + np.arccos(3.f16), 1.f16 + np.arccos(4.f16)], np.float16)
assert eq(1 + np.arctan(a), [1.f16 + np.arctan(1.f16), 1.f16 + np.arctan(2.f16), 1.f16 + np.arctan(3.f16), 1.f16 + np.arctan(4.f16)], np.float16)
assert eq(1 + np.arctan2(a, 3.f16), [1.f16 + np.arctan2(1.f16, 3.f16), 1.f16 + np.arctan2(2.f16, 3.f16), 1.f16 + np.arctan2(3.f16, 3.f16), 1.f16 + np.arctan2(4.f16, 3.f16)], np.float16)
assert eq(1 + np.arctan2(3.f16, a), [1.f16 + np.arctan2(3.f16, 1.f16), 1.f16 + np.arctan2(3.f16, 2.f16), 1.f16 + np.arctan2(3.f16, 3.f16), 1.f16 + np.arctan2(3.f16, 4.f16)], np.float16)
assert eq(1 + np.hypot(a, 3), [1.f16 + np.hypot(1.f16, 3.f16), 1.f16 + np.hypot(2.f16, 3.f16), 1.f16 + np.hypot(3.f16, 3.f16), 1.f16 + np.hypot(4.f16, 3.f16)], np.float16)
assert eq(1 + np.hypot(3, a), [1.f16 + np.hypot(3.f16, 1.f16), 1.f16 + np.hypot(3.f16, 2.f16), 1.f16 + np.hypot(3.f16, 3.f16), 1.f16 + np.hypot(3.f16, 4.f16)], np.float16)
assert eq(1 + np.sinh(a), [1.f16 + np.sinh(1.f16), 1.f16 + np.sinh(2.f16), 1.f16 + np.sinh(3.f16), 1.f16 + np.sinh(4.f16)], np.float16)
assert eq(1 + np.cosh(a), [1.f16 + np.cosh(1.f16), 1.f16 + np.cosh(2.f16), 1.f16 + np.cosh(3.f16), 1.f16 + np.cosh(4.f16)], np.float16)
assert eq(1 + np.tanh(a), [1.f16 + np.tanh(1.f16), 1.f16 + np.tanh(2.f16), 1.f16 + np.tanh(3.f16), 1.f16 + np.tanh(4.f16)], np.float16)
assert eq(1 + np.arcsinh(a), [1.f16 + np.arcsinh(1.f16), 1.f16 + np.arcsinh(2.f16), 1.f16 + np.arcsinh(3.f16), 1.f16 + np.arcsinh(4.f16)], np.float16)
assert eq(1 + np.arccosh(a), [1.f16 + np.arccosh(1.f16), 1.f16 + np.arccosh(2.f16), 1.f16 + np.arccosh(3.f16), 1.f16 + np.arccosh(4.f16)], np.float16)
assert eq(1 + np.arctanh(a), [1.f16 + np.arctanh(1.f16), 1.f16 + np.arctanh(2.f16), 1.f16 + np.arctanh(3.f16), 1.f16 + np.arctanh(4.f16)], np.float16)
assert eq(1 + np.conj(a), [1 + np.conj(1), 1 + np.conj(2), 1 + np.conj(3), 1 + np.conj(4)], np.int8)
assert eq(1 + np.exp(a), [1.f16 + np.exp(1.f16), 1.f16 + np.exp(2.f16), 1.f16 + np.exp(3.f16), 1.f16 + np.exp(4.f16)], np.float16)
assert eq(1 + np.exp2(a), [1.f16 + np.exp2(1.f16), 1.f16 + np.exp2(2.f16), 1.f16 + np.exp2(3.f16), 1.f16 + np.exp2(4.f16)], np.float16)
assert eq(1 + np.log(a), [1.f16 + np.log(1.f16), 1.f16 + np.log(2.f16), 1.f16 + np.log(3.f16), 1.f16 + np.log(4.f16)], np.float16)
assert eq(1 + np.log2(a), [1.f16 + np.log2(1.f16), 1.f16 + np.log2(2.f16), 1.f16 + np.log2(3.f16), 1.f16 + np.log2(4.f16)], np.float16)
assert eq(1 + np.log10(a), [1.f16 + np.log10(1.f16), 1.f16 + np.log10(2.f16), 1.f16 + np.log10(3.f16), 1.f16 + np.log10(4.f16)], np.float16)
assert eq(1 + np.expm1(a), [1.f16 + np.expm1(1.f16), 1.f16 + np.expm1(2.f16), 1.f16 + np.expm1(3.f16), 1.f16 + np.expm1(4.f16)], np.float16)
assert eq(1 + np.log1p(a), [1.f16 + np.log1p(1.f16), 1.f16 + np.log1p(2.f16), 1.f16 + np.log1p(3.f16), 1.f16 + np.log1p(4.f16)], np.float16)
assert eq(1 + np.sqrt(a), [1.f16 + np.sqrt(1.f16), 1.f16 + np.sqrt(2.f16), 1.f16 + np.sqrt(3.f16), 1.f16 + np.sqrt(4.f16)], np.float16)
assert eq(1 + np.square(a), [1 + np.square(1), 1 + np.square(2), 1 + np.square(3), 1 + np.square(4)], np.int8)
assert eq(1 + np.cbrt(a), [1.f16 + np.cbrt(1.f16), 1.f16 + np.cbrt(2.f16), 1.f16 + np.cbrt(3.f16), 1.f16 + np.cbrt(4.f16)], np.float16)
assert eq(1 + np.logaddexp(a, 3), [1.f16 + np.logaddexp(1.f16, 3.f16), 1.f16 + np.logaddexp(2.f16, 3.f16), 1.f16 + np.logaddexp(3.f16, 3.f16), 1.f16 + np.logaddexp(4.f16, 3.f16)], np.float16)
assert eq(1 + np.logaddexp(3, a), [1.f16 + np.logaddexp(3.f16, 1.f16), 1.f16 + np.logaddexp(3.f16, 2.f16), 1.f16 + np.logaddexp(3.f16, 3.f16), 1.f16 + np.logaddexp(3.f16, 4.f16)], np.float16)
assert eq(1 + np.logaddexp2(a, 3), [1.f16 + np.logaddexp2(1.f16, 3.f16), 1.f16 + np.logaddexp2(2.f16, 3.f16), 1.f16 + np.logaddexp2(3.f16, 3.f16), 1.f16 + np.logaddexp2(4.f16, 3.f16)], np.float16)
assert eq(1 + np.logaddexp2(3, a), [1.f16 + np.logaddexp2(3.f16, 1.f16), 1.f16 + np.logaddexp2(3.f16, 2.f16), 1.f16 + np.logaddexp2(3.f16, 3.f16), 1.f16 + np.logaddexp2(3.f16, 4.f16)], np.float16)
assert eq(1 + np.reciprocal(a), [2, 1, 1, 1], np.int8)
assert eq(1 + np.rint(a), [1.f16 + np.rint(1.f16), 1.f16 + np.rint(2.f16), 1.f16 + np.rint(3.f16), 1.f16 + np.rint(4.f16)], np.float16)
assert eq(1 + np.floor(a), [1.f16 + np.floor(1.f16), 1.f16 + np.floor(2.f16), 1.f16 + np.floor(3.f16), 1.f16 + np.floor(4.f16)], np.float16)
assert eq(1 + np.ceil(a), [1.f16 + np.ceil(1.f16), 1.f16 + np.ceil(2.f16), 1.f16 + np.ceil(3.f16), 1.f16 + np.ceil(4.f16)], np.float16)
assert eq(1 + np.trunc(a), [1.f16 + np.trunc(1.f16), 1.f16 + np.trunc(2.f16), 1.f16 + np.trunc(3.f16), 1.f16 + np.trunc(4.f16)], np.float16)
assert eq(1 + np.isnan(a), [1, 1, 1, 1], int)
assert eq(1 + np.isinf(a), [1, 1, 1, 1], int)
assert eq(1 + np.isfinite(a), [2, 2, 2, 2], int)
assert eq(1 + np.ldexp(a, 1), [1.f16 + np.ldexp(1.f16, 1), 1.f16 + np.ldexp(2.f16, 1), 1.f16 + np.ldexp(3.f16, 1), 1.f16 + np.ldexp(4.f16, 1)], np.float16)
assert eq(1 + np.ldexp(1, a), [1.f16 + np.ldexp(1.f16, 1), 1.f16 + np.ldexp(1.f16, 2), 1.f16 + np.ldexp(1.f16, 3), 1.f16 + np.ldexp(1.f16, 4)], np.float16)
assert eq(1 + np.sign(a), [2, 2, 2, 2], np.int8)
assert eq(1 + np.signbit(a), [1, 1, 1, 1], int)
assert eq(1 + np.copysign(a, -1), [1.f16 + np.copysign(1.f16, -1.f16), 1.f16 + np.copysign(2.f16, -1.f16), 1.f16 + np.copysign(3.f16, -1.f16), 1.f16 + np.copysign(4.f16, -1.f16)], np.float16)
assert eq(1 + np.copysign(-1, a), [1.f16 + np.copysign(-1.f16, 1.f16), 1.f16 + np.copysign(-1.f16, 2.f16), 1.f16 + np.copysign(-1.f16, 3.f16), 1.f16 + np.copysign(-1.f16, 4.f16)], np.float16)
assert eq(1 + np.spacing(a), [1.f16 + np.spacing(1.f16), 1.f16 + np.spacing(2.f16), 1.f16 + np.spacing(3.f16), 1.f16 + np.spacing(4.f16)], np.float16)
assert eq(1 + np.nextafter(a, 1), [1.f16 + np.nextafter(1.f16, 1.f16), 1.f16 + np.nextafter(2.f16, 1.f16), 1.f16 + np.nextafter(3.f16, 1.f16), 1.f16 + np.nextafter(4.f16, 1.f16)], np.float16)
assert eq(1 + np.nextafter(1, a), [1.f16 + np.nextafter(1.f16, 1.f16), 1.f16 + np.nextafter(1.f16, 2.f16), 1.f16 + np.nextafter(1.f16, 3.f16), 1.f16 + np.nextafter(1.f16, 4.f16)], np.float16)
assert eq(1 + np.deg2rad(a), [1.f16 + np.deg2rad(1.f16), 1.f16 + np.deg2rad(2.f16), 1.f16 + np.deg2rad(3.f16), 1.f16 + np.deg2rad(4.f16)], np.float16)
assert eq(1 + np.rad2deg(a), [1.f16 + np.rad2deg(1.f16), 1.f16 + np.rad2deg(2.f16), 1.f16 + np.rad2deg(3.f16), 1.f16 + np.rad2deg(4.f16)], np.float16)
assert eq(1 + np.heaviside(a, 1), [1.f16 + np.heaviside(1.f16, 1.f16), 1.f16 + np.heaviside(2.f16, 1.f16), 1.f16 + np.heaviside(3.f16, 1.f16), 1.f16 + np.heaviside(4.f16, 1.f16)], np.float16)
assert eq(1 + np.heaviside(1, a), [1.f16 + np.heaviside(1.f16, 1.f16), 1.f16 + np.heaviside(1.f16, 2.f16), 1.f16 + np.heaviside(1.f16, 3.f16), 1.f16 + np.heaviside(1.f16, 4.f16)], np.float16)
@test
def test_ops_uint64():
a = np.array([1, 2, 3, 4], dtype=np.uint64)
assert eq(1 + (+a), [2, 3, 4, 5], np.uint64)
assert eq(1 + (-a), [0, -1, -2, -3], np.uint64)
assert eq(1 + (~a), [-1, -2, -3, -4], np.uint64)
assert eq(1 + np.abs(a), [2, 3, 4, 5], np.uint64)
assert eq(1 + abs(a), [2, 3, 4, 5], np.uint64)
assert eq(2 * (1 + a), [4, 6, 8, 10], np.uint64)
assert eq(2 * (a + 1), [4, 6, 8, 10], np.uint64)
assert eq(2 * (a - 1), [0, 2, 4, 6], np.uint64)
assert eq(2 * (1 - a), [0, -2, -4, -6], np.uint64)
assert eq(1 + (a * 2), [3, 5, 7, 9], np.uint64)
assert eq(1 + (2 * a), [3, 5, 7, 9], np.uint64)
assert eq(1 + (a.reshape(1, -1) @ a.reshape(-1, 1)), [[31]], np.uint64)
assert eq(1 + (a / 2), [1.5, 2., 2.5, 3.], float)
assert eq(1 + (2 / a), [3., 2., 1 + 2/3, 1.5], float)
assert eq(1 + (a // 2), [1, 2, 2, 3], np.uint64)
assert eq(1 + (10 // a), [11, 6, 4, 3], np.uint64)
assert eq(1 + (a % 3), [2, 3, 1, 2], np.uint64)
assert eq(1 + (10 % a), [1, 1, 2, 3], np.uint64)
assert eq(1 + np.fmod(a, 3), [2, 3, 1, 2], np.uint64)
assert eq(1 + np.fmod(10, a), [1, 1, 2, 3], np.uint64)
assert eq(1 + (a ** 3), [2, 9, 28, 65], np.uint64)
assert eq(1 + (3 ** a), [4, 10, 28, 82], np.uint64)
assert eq(1 + (a << 3), [9, 17, 25, 33], np.uint64)
assert eq(1 + (3 << a), [7, 13, 25, 49], np.uint64)
assert eq(1 + (a >> 1), [1, 2, 2, 3], np.uint64)
assert eq(1 + (1000 >> a), [501, 251, 126, 63], np.uint64)
assert eq(1 + (a & 2), [1, 3, 3, 1], np.uint64)
assert eq(1 + (2 & a), [1, 3, 3, 1], np.uint64)
assert eq(1 + (a | 2), [4, 3, 4, 7], np.uint64)
assert eq(1 + (2 | a), [4, 3, 4, 7], np.uint64)
assert eq(1 + (a ^ 2), [4, 1, 2, 7], np.uint64)
assert eq(1 + (2 ^ a), [4, 1, 2, 7], np.uint64)
assert eq(np.logical_and(a, a & 1), [True, False, True, False], bool)
assert eq(np.logical_or(a & 2, a & 1), [True, True, True, False], bool)
assert eq(np.logical_xor(a, a & 1), [False, True, False, True], bool)
assert eq((a + 1) == 2, [True, False, False, False], bool)
assert eq(2 == (a + 1), [True, False, False, False], bool)
assert eq((a + 1) != 2, [False, True, True, True], bool)
assert eq(2 != (a + 1), [False, True, True, True], bool)
assert eq((a + 1) < 3, [True, False, False, False], bool)
assert eq(3 < (a + 1), [False, False, True, True], bool)
assert eq((a + 1) > 3, [False, False, True, True], bool)
assert eq(3 > (a + 1), [True, False, False, False], bool)
assert eq((a + 1) <= 3, [True, True, False, False], bool)
assert eq(3 <= (a + 1), [False, True, True, True], bool)
assert eq((a + 1) >= 3, [False, True, True, True], bool)
assert eq(3 >= (a + 1), [True, True, False, False], bool)
assert eq(1 + np.minimum(a, 3), [2, 3, 4, 4], np.uint64)
assert eq(1 + np.minimum(3, a), [2, 3, 4, 4], np.uint64)
assert eq(1 + np.maximum(a, 3), [4, 4, 4, 5], np.uint64)
assert eq(1 + np.maximum(3, a), [4, 4, 4, 5], np.uint64)
assert eq(1 + np.fmin(a, 3), [2, 3, 4, 4], np.uint64)
assert eq(1 + np.fmin(3, a), [2, 3, 4, 4], np.uint64)
assert eq(1 + np.fmax(a, 3), [4, 4, 4, 5], np.uint64)
assert eq(1 + np.fmax(3, a), [4, 4, 4, 5], np.uint64)
assert eq(1 + np.sin(a), [1 + np.sin(1), 1 + np.sin(2), 1 + np.sin(3), 1 + np.sin(4)], float)
assert eq(1 + np.cos(a), [1 + np.cos(1), 1 + np.cos(2), 1 + np.cos(3), 1 + np.cos(4)], float)
assert eq(1 + np.tan(a), [1 + np.tan(1), 1 + np.tan(2), 1 + np.tan(3), 1 + np.tan(4)], float)
assert eq(1 + np.arcsin(a), [1 + np.arcsin(1), 1 + np.arcsin(2), 1 + np.arcsin(3), 1 + np.arcsin(4)], float)
assert eq(1 + np.arccos(a), [1 + np.arccos(1), 1 + np.arccos(2), 1 + np.arccos(3), 1 + np.arccos(4)], float)
assert eq(1 + np.arctan(a), [1 + np.arctan(1), 1 + np.arctan(2), 1 + np.arctan(3), 1 + np.arctan(4)], float)
assert eq(1 + np.arctan2(a, 3), [1 + np.arctan2(1, 3), 1 + np.arctan2(2, 3), 1 + np.arctan2(3, 3), 1 + np.arctan2(4, 3)], float)
assert eq(1 + np.arctan2(3, a), [1 + np.arctan2(3, 1), 1 + np.arctan2(3, 2), 1 + np.arctan2(3, 3), 1 + np.arctan2(3, 4)], float)
assert eq(1 + np.hypot(a, 3), [1 + np.hypot(1, 3), 1 + np.hypot(2, 3), 1 + np.hypot(3, 3), 1 + np.hypot(4, 3)], float)
assert eq(1 + np.hypot(3, a), [1 + np.hypot(3, 1), 1 + np.hypot(3, 2), 1 + np.hypot(3, 3), 1 + np.hypot(3, 4)], float)
assert eq(1 + np.sinh(a), [1 + np.sinh(1), 1 + np.sinh(2), 1 + np.sinh(3), 1 + np.sinh(4)], float)
assert eq(1 + np.cosh(a), [1 + np.cosh(1), 1 + np.cosh(2), 1 + np.cosh(3), 1 + np.cosh(4)], float)
assert eq(1 + np.tanh(a), [1 + np.tanh(1), 1 + np.tanh(2), 1 + np.tanh(3), 1 + np.tanh(4)], float)
assert eq(1 + np.arcsinh(a), [1 + np.arcsinh(1), 1 + np.arcsinh(2), 1 + np.arcsinh(3), 1 + np.arcsinh(4)], float)
assert eq(1 + np.arccosh(a), [1 + np.arccosh(1), 1 + np.arccosh(2), 1 + np.arccosh(3), 1 + np.arccosh(4)], float)
assert eq(1 + np.arctanh(a), [1 + np.arctanh(1), 1 + np.arctanh(2), 1 + np.arctanh(3), 1 + np.arctanh(4)], float)
assert eq(1 + np.conj(a), [1 + np.conj(1), 1 + np.conj(2), 1 + np.conj(3), 1 + np.conj(4)], np.uint64)
assert eq(1 + np.exp(a), [1 + np.exp(1), 1 + np.exp(2), 1 + np.exp(3), 1 + np.exp(4)], float)
assert eq(1 + np.exp2(a), [1 + np.exp2(1), 1 + np.exp2(2), 1 + np.exp2(3), 1 + np.exp2(4)], float)
assert eq(1 + np.log(a), [1 + np.log(1), 1 + np.log(2), 1 + np.log(3), 1 + np.log(4)], float)
assert eq(1 + np.log2(a), [1 + np.log2(1), 1 + np.log2(2), 1 + np.log2(3), 1 + np.log2(4)], float)
assert eq(1 + np.log10(a), [1 + np.log10(1), 1 + np.log10(2), 1 + np.log10(3), 1 + np.log10(4)], float)
assert eq(1 + np.expm1(a), [1 + np.expm1(1), 1 + np.expm1(2), 1 + np.expm1(3), 1 + np.expm1(4)], float)
assert eq(1 + np.log1p(a), [1 + np.log1p(1), 1 + np.log1p(2), 1 + np.log1p(3), 1 + np.log1p(4)], float)
assert eq(1 + np.sqrt(a), [1 + np.sqrt(1), 1 + np.sqrt(2), 1 + np.sqrt(3), 1 + np.sqrt(4)], float)
assert eq(1 + np.square(a), [1 + np.square(1), 1 + np.square(2), 1 + np.square(3), 1 + np.square(4)], np.uint64)
assert eq(1 + np.cbrt(a), [1 + np.cbrt(1), 1 + np.cbrt(2), 1 + np.cbrt(3), 1 + np.cbrt(4)], float)
assert eq(1 + np.logaddexp(a, 3), [1 + np.logaddexp(1, 3), 1 + np.logaddexp(2, 3), 1 + np.logaddexp(3, 3), 1 + np.logaddexp(4, 3)], float)
assert eq(1 + np.logaddexp(3, a), [1 + np.logaddexp(3, 1), 1 + np.logaddexp(3, 2), 1 + np.logaddexp(3, 3), 1 + np.logaddexp(3, 4)], float)
assert eq(1 + np.logaddexp2(a, 3), [1 + np.logaddexp2(1, 3), 1 + np.logaddexp2(2, 3), 1 + np.logaddexp2(3, 3), 1 + np.logaddexp2(4, 3)], float)
assert eq(1 + np.logaddexp2(3, a), [1 + np.logaddexp2(3, 1), 1 + np.logaddexp2(3, 2), 1 + np.logaddexp2(3, 3), 1 + np.logaddexp2(3, 4)], float)
assert eq(1 + np.reciprocal(a), [2, 1, 1, 1], np.uint64)
assert eq(1 + np.rint(a), [1 + np.rint(1), 1 + np.rint(2), 1 + np.rint(3), 1 + np.rint(4)], float)
assert eq(1 + np.floor(a), [1 + np.floor(1), 1 + np.floor(2), 1 + np.floor(3), 1 + np.floor(4)], float)
assert eq(1 + np.ceil(a), [1 + np.ceil(1), 1 + np.ceil(2), 1 + np.ceil(3), 1 + np.ceil(4)], float)
assert eq(1 + np.trunc(a), [1 + np.trunc(1), 1 + np.trunc(2), 1 + np.trunc(3), 1 + np.trunc(4)], float)
assert eq(1 + np.isnan(a), [1, 1, 1, 1], int)
assert eq(1 + np.isinf(a), [1, 1, 1, 1], int)
assert eq(1 + np.isfinite(a), [2, 2, 2, 2], int)
assert eq(1 + np.ldexp(a, 1), [1 + np.ldexp(1, 1), 1 + np.ldexp(2, 1), 1 + np.ldexp(3, 1), 1 + np.ldexp(4, 1)], float)
assert eq(1 + np.ldexp(1, a), [1 + np.ldexp(1, 1), 1 + np.ldexp(1, 2), 1 + np.ldexp(1, 3), 1 + np.ldexp(1, 4)], float)
assert eq(1 + np.sign(a), [2, 2, 2, 2], np.uint64)
assert eq(1 + np.signbit(a), [1, 1, 1, 1], int)
assert eq(1 + np.copysign(a, -1), [1 + np.copysign(1, -1), 1 + np.copysign(2, -1), 1 + np.copysign(3, -1), 1 + np.copysign(4, -1)], float)
assert eq(1 + np.copysign(-1, a), [1 + np.copysign(-1, 1), 1 + np.copysign(-1, 2), 1 + np.copysign(-1, 3), 1 + np.copysign(-1, 4)], float)
assert eq(1 + np.spacing(a), [1 + np.spacing(1), 1 + np.spacing(2), 1 + np.spacing(3), 1 + np.spacing(4)], float)
assert eq(1 + np.nextafter(a, 1), [1 + np.nextafter(1, 1), 1 + np.nextafter(2, 1), 1 + np.nextafter(3, 1), 1 + np.nextafter(4, 1)], float)
assert eq(1 + np.nextafter(1, a), [1 + np.nextafter(1, 1), 1 + np.nextafter(1, 2), 1 + np.nextafter(1, 3), 1 + np.nextafter(1, 4)], float)
assert eq(1 + np.deg2rad(a), [1 + np.deg2rad(1), 1 + np.deg2rad(2), 1 + np.deg2rad(3), 1 + np.deg2rad(4)], float)
assert eq(1 + np.rad2deg(a), [1 + np.rad2deg(1), 1 + np.rad2deg(2), 1 + np.rad2deg(3), 1 + np.rad2deg(4)], float)
assert eq(1 + np.heaviside(a, 1), [1 + np.heaviside(1, 1), 1 + np.heaviside(2, 1), 1 + np.heaviside(3, 1), 1 + np.heaviside(4, 1)], float)
assert eq(1 + np.heaviside(1, a), [1 + np.heaviside(1, 1), 1 + np.heaviside(1, 2), 1 + np.heaviside(1, 3), 1 + np.heaviside(1, 4)], float)
@test
def test_ops_uint32():
a = np.array([1, 2, 3, 4], np.uint32)
assert eq(1 + (+a), [2, 3, 4, 5], np.uint32)
assert eq(1 + (-a), [0, -1, -2, -3], np.uint32)
assert eq(1 + (~a), [-1, -2, -3, -4], np.uint32)
assert eq(1 + np.abs(a), [2, 3, 4, 5], np.uint32)
assert eq(1 + abs(a), [2, 3, 4, 5], np.uint32)
assert eq(2 * (1 + a), [4, 6, 8, 10], np.uint32)
assert eq(2 * (a + 1), [4, 6, 8, 10], np.uint32)
assert eq(2 * (a - 1), [0, 2, 4, 6], np.uint32)
assert eq(2 * (1 - a), [0, -2, -4, -6], np.uint32)
assert eq(1 + (a * 2), [3, 5, 7, 9], np.uint32)
assert eq(1 + (2 * a), [3, 5, 7, 9], np.uint32)
assert eq(1 + (a.reshape(1, -1) @ a.reshape(-1, 1)), [[31]], np.uint32)
assert eq(1 + (a / 2), [1.5, 2., 2.5, 3.], float)
assert eq(1 + (2 / a), [3., 2., 1 + 2/3, 1.5], float)
assert eq(1 + (a // 2), [1, 2, 2, 3], np.uint32)
assert eq(1 + (10 // a), [11, 6, 4, 3], np.uint32)
assert eq(1 + (a % 3), [2, 3, 1, 2], np.uint32)
assert eq(1 + (10 % a), [1, 1, 2, 3], np.uint32)
assert eq(1 + np.fmod(a, 3), [2, 3, 1, 2], np.uint32)
assert eq(1 + np.fmod(10, a), [1, 1, 2, 3], np.uint32)
assert eq(1 + (a ** 3), [2, 9, 28, 65], np.uint32)
assert eq(1 + (3 ** a), [4, 10, 28, 82], np.uint32)
assert eq(1 + (a << 3), [9, 17, 25, 33], np.uint32)
assert eq(1 + (3 << a), [7, 13, 25, 49], np.uint32)
assert eq(1 + (a >> 1), [1, 2, 2, 3], np.uint32)
assert eq(1 + (1000 >> a), [501, 251, 126, 63], np.uint32)
assert eq(1 + (a & 2), [1, 3, 3, 1], np.uint32)
assert eq(1 + (2 & a), [1, 3, 3, 1], np.uint32)
assert eq(1 + (a | 2), [4, 3, 4, 7], np.uint32)
assert eq(1 + (2 | a), [4, 3, 4, 7], np.uint32)
assert eq(1 + (a ^ 2), [4, 1, 2, 7], np.uint32)
assert eq(1 + (2 ^ a), [4, 1, 2, 7], np.uint32)
assert eq(np.logical_and(a, a & 1), [True, False, True, False], bool)
assert eq(np.logical_or(a & 2, a & 1), [True, True, True, False], bool)
assert eq(np.logical_xor(a, a & 1), [False, True, False, True], bool)
assert eq((a + 1) == 2, [True, False, False, False], bool)
assert eq(2 == (a + 1), [True, False, False, False], bool)
assert eq((a + 1) != 2, [False, True, True, True], bool)
assert eq(2 != (a + 1), [False, True, True, True], bool)
assert eq((a + 1) < 3, [True, False, False, False], bool)
assert eq(3 < (a + 1), [False, False, True, True], bool)
assert eq((a + 1) > 3, [False, False, True, True], bool)
assert eq(3 > (a + 1), [True, False, False, False], bool)
assert eq((a + 1) <= 3, [True, True, False, False], bool)
assert eq(3 <= (a + 1), [False, True, True, True], bool)
assert eq((a + 1) >= 3, [False, True, True, True], bool)
assert eq(3 >= (a + 1), [True, True, False, False], bool)
assert eq(1 + np.minimum(a, 3), [2, 3, 4, 4], np.uint32)
assert eq(1 + np.minimum(3, a), [2, 3, 4, 4], np.uint32)
assert eq(1 + np.maximum(a, 3), [4, 4, 4, 5], np.uint32)
assert eq(1 + np.maximum(3, a), [4, 4, 4, 5], np.uint32)
assert eq(1 + np.fmin(a, 3), [2, 3, 4, 4], np.uint32)
assert eq(1 + np.fmin(3, a), [2, 3, 4, 4], np.uint32)
assert eq(1 + np.fmax(a, 3), [4, 4, 4, 5], np.uint32)
assert eq(1 + np.fmax(3, a), [4, 4, 4, 5], np.uint32)
assert eq(1 + np.sin(a), [1 + np.sin(1), 1 + np.sin(2), 1 + np.sin(3), 1 + np.sin(4)], float)
assert eq(1 + np.cos(a), [1 + np.cos(1), 1 + np.cos(2), 1 + np.cos(3), 1 + np.cos(4)], float)
assert eq(1 + np.tan(a), [1 + np.tan(1), 1 + np.tan(2), 1 + np.tan(3), 1 + np.tan(4)], float)
assert eq(1 + np.arcsin(a), [1 + np.arcsin(1), 1 + np.arcsin(2), 1 + np.arcsin(3), 1 + np.arcsin(4)], float)
assert eq(1 + np.arccos(a), [1 + np.arccos(1), 1 + np.arccos(2), 1 + np.arccos(3), 1 + np.arccos(4)], float)
assert eq(1 + np.arctan(a), [1 + np.arctan(1), 1 + np.arctan(2), 1 + np.arctan(3), 1 + np.arctan(4)], float)
assert eq(1 + np.arctan2(a, 3), [1 + np.arctan2(1, 3), 1 + np.arctan2(2, 3), 1 + np.arctan2(3, 3), 1 + np.arctan2(4, 3)], float)
assert eq(1 + np.arctan2(3, a), [1 + np.arctan2(3, 1), 1 + np.arctan2(3, 2), 1 + np.arctan2(3, 3), 1 + np.arctan2(3, 4)], float)
assert eq(1 + np.hypot(a, 3), [1 + np.hypot(1, 3), 1 + np.hypot(2, 3), 1 + np.hypot(3, 3), 1 + np.hypot(4, 3)], float)
assert eq(1 + np.hypot(3, a), [1 + np.hypot(3, 1), 1 + np.hypot(3, 2), 1 + np.hypot(3, 3), 1 + np.hypot(3, 4)], float)
assert eq(1 + np.sinh(a), [1 + np.sinh(1), 1 + np.sinh(2), 1 + np.sinh(3), 1 + np.sinh(4)], float)
assert eq(1 + np.cosh(a), [1 + np.cosh(1), 1 + np.cosh(2), 1 + np.cosh(3), 1 + np.cosh(4)], float)
assert eq(1 + np.tanh(a), [1 + np.tanh(1), 1 + np.tanh(2), 1 + np.tanh(3), 1 + np.tanh(4)], float)
assert eq(1 + np.arcsinh(a), [1 + np.arcsinh(1), 1 + np.arcsinh(2), 1 + np.arcsinh(3), 1 + np.arcsinh(4)], float)
assert eq(1 + np.arccosh(a), [1 + np.arccosh(1), 1 + np.arccosh(2), 1 + np.arccosh(3), 1 + np.arccosh(4)], float)
assert eq(1 + np.arctanh(a), [1 + np.arctanh(1), 1 + np.arctanh(2), 1 + np.arctanh(3), 1 + np.arctanh(4)], float)
assert eq(1 + np.conj(a), [1 + np.conj(1), 1 + np.conj(2), 1 + np.conj(3), 1 + np.conj(4)], np.uint32)
assert eq(1 + np.exp(a), [1 + np.exp(1), 1 + np.exp(2), 1 + np.exp(3), 1 + np.exp(4)], float)
assert eq(1 + np.exp2(a), [1 + np.exp2(1), 1 + np.exp2(2), 1 + np.exp2(3), 1 + np.exp2(4)], float)
assert eq(1 + np.log(a), [1 + np.log(1), 1 + np.log(2), 1 + np.log(3), 1 + np.log(4)], float)
assert eq(1 + np.log2(a), [1 + np.log2(1), 1 + np.log2(2), 1 + np.log2(3), 1 + np.log2(4)], float)
assert eq(1 + np.log10(a), [1 + np.log10(1), 1 + np.log10(2), 1 + np.log10(3), 1 + np.log10(4)], float)
assert eq(1 + np.expm1(a), [1 + np.expm1(1), 1 + np.expm1(2), 1 + np.expm1(3), 1 + np.expm1(4)], float)
assert eq(1 + np.log1p(a), [1 + np.log1p(1), 1 + np.log1p(2), 1 + np.log1p(3), 1 + np.log1p(4)], float)
assert eq(1 + np.sqrt(a), [1 + np.sqrt(1), 1 + np.sqrt(2), 1 + np.sqrt(3), 1 + np.sqrt(4)], float)
assert eq(1 + np.square(a), [1 + np.square(1), 1 + np.square(2), 1 + np.square(3), 1 + np.square(4)], np.uint32)
assert eq(1 + np.cbrt(a), [1 + np.cbrt(1), 1 + np.cbrt(2), 1 + np.cbrt(3), 1 + np.cbrt(4)], float)
assert eq(1 + np.logaddexp(a, 3), [1 + np.logaddexp(1, 3), 1 + np.logaddexp(2, 3), 1 + np.logaddexp(3, 3), 1 + np.logaddexp(4, 3)], float)
assert eq(1 + np.logaddexp(3, a), [1 + np.logaddexp(3, 1), 1 + np.logaddexp(3, 2), 1 + np.logaddexp(3, 3), 1 + np.logaddexp(3, 4)], float)
assert eq(1 + np.logaddexp2(a, 3), [1 + np.logaddexp2(1, 3), 1 + np.logaddexp2(2, 3), 1 + np.logaddexp2(3, 3), 1 + np.logaddexp2(4, 3)], float)
assert eq(1 + np.logaddexp2(3, a), [1 + np.logaddexp2(3, 1), 1 + np.logaddexp2(3, 2), 1 + np.logaddexp2(3, 3), 1 + np.logaddexp2(3, 4)], float)
assert eq(1 + np.reciprocal(a), [2, 1, 1, 1], np.uint32)
assert eq(1 + np.rint(a), [1 + np.rint(1), 1 + np.rint(2), 1 + np.rint(3), 1 + np.rint(4)], float)
assert eq(1 + np.floor(a), [1 + np.floor(1), 1 + np.floor(2), 1 + np.floor(3), 1 + np.floor(4)], float)
assert eq(1 + np.ceil(a), [1 + np.ceil(1), 1 + np.ceil(2), 1 + np.ceil(3), 1 + np.ceil(4)], float)
assert eq(1 + np.trunc(a), [1 + np.trunc(1), 1 + np.trunc(2), 1 + np.trunc(3), 1 + np.trunc(4)], float)
assert eq(1 + np.isnan(a), [1, 1, 1, 1], int)
assert eq(1 + np.isinf(a), [1, 1, 1, 1], int)
assert eq(1 + np.isfinite(a), [2, 2, 2, 2], int)
assert eq(1 + np.ldexp(a, 1), [1 + np.ldexp(1, 1), 1 + np.ldexp(2, 1), 1 + np.ldexp(3, 1), 1 + np.ldexp(4, 1)], float)
assert eq(1 + np.ldexp(1, a), [1 + np.ldexp(1, 1), 1 + np.ldexp(1, 2), 1 + np.ldexp(1, 3), 1 + np.ldexp(1, 4)], float)
assert eq(1 + np.sign(a), [2, 2, 2, 2], np.uint32)
assert eq(1 + np.signbit(a), [1, 1, 1, 1], int)
assert eq(1 + np.copysign(a, -1), [1 + np.copysign(1, -1), 1 + np.copysign(2, -1), 1 + np.copysign(3, -1), 1 + np.copysign(4, -1)], float)
assert eq(1 + np.copysign(-1, a), [1 + np.copysign(-1, 1), 1 + np.copysign(-1, 2), 1 + np.copysign(-1, 3), 1 + np.copysign(-1, 4)], float)
assert eq(1 + np.spacing(a), [1 + np.spacing(1), 1 + np.spacing(2), 1 + np.spacing(3), 1 + np.spacing(4)], float)
assert eq(1 + np.nextafter(a, 1), [1 + np.nextafter(1, 1), 1 + np.nextafter(2, 1), 1 + np.nextafter(3, 1), 1 + np.nextafter(4, 1)], float)
assert eq(1 + np.nextafter(1, a), [1 + np.nextafter(1, 1), 1 + np.nextafter(1, 2), 1 + np.nextafter(1, 3), 1 + np.nextafter(1, 4)], float)
assert eq(1 + np.deg2rad(a), [1 + np.deg2rad(1), 1 + np.deg2rad(2), 1 + np.deg2rad(3), 1 + np.deg2rad(4)], float)
assert eq(1 + np.rad2deg(a), [1 + np.rad2deg(1), 1 + np.rad2deg(2), 1 + np.rad2deg(3), 1 + np.rad2deg(4)], float)
assert eq(1 + np.heaviside(a, 1), [1 + np.heaviside(1, 1), 1 + np.heaviside(2, 1), 1 + np.heaviside(3, 1), 1 + np.heaviside(4, 1)], float)
assert eq(1 + np.heaviside(1, a), [1 + np.heaviside(1, 1), 1 + np.heaviside(1, 2), 1 + np.heaviside(1, 3), 1 + np.heaviside(1, 4)], float)
@test
def test_ops_uint16():
a = np.array([1, 2, 3, 4], np.uint16)
assert eq(1 + (+a), [2, 3, 4, 5], np.uint16)
assert eq(1 + (-a), [0, -1, -2, -3], np.uint16)
assert eq(1 + (~a), [-1, -2, -3, -4], np.uint16)
assert eq(1 + np.abs(a), [2, 3, 4, 5], np.uint16)
assert eq(1 + abs(a), [2, 3, 4, 5], np.uint16)
assert eq(2 * (1 + a), [4, 6, 8, 10], np.uint16)
assert eq(2 * (a + 1), [4, 6, 8, 10], np.uint16)
assert eq(2 * (a - 1), [0, 2, 4, 6], np.uint16)
assert eq(2 * (1 - a), [0, -2, -4, -6], np.uint16)
assert eq(1 + (a * 2), [3, 5, 7, 9], np.uint16)
assert eq(1 + (2 * a), [3, 5, 7, 9], np.uint16)
assert eq(1 + (a.reshape(1, -1) @ a.reshape(-1, 1)), [[31]], np.uint16)
assert eq(1 + (a / 2), [1.5, 2., 2.5, 3.], float)
assert eq(1 + (2 / a), [3., 2., 1 + 2/3, 1.5], float)
assert eq(1 + (a // 2), [1, 2, 2, 3], np.uint16)
assert eq(1 + (10 // a), [11, 6, 4, 3], np.uint16)
assert eq(1 + (a % 3), [2, 3, 1, 2], np.uint16)
assert eq(1 + (10 % a), [1, 1, 2, 3], np.uint16)
assert eq(1 + np.fmod(a, 3), [2, 3, 1, 2], np.uint16)
assert eq(1 + np.fmod(10, a), [1, 1, 2, 3], np.uint16)
assert eq(1 + (a ** 3), [2, 9, 28, 65], np.uint16)
assert eq(1 + (3 ** a), [4, 10, 28, 82], np.uint16)
assert eq(1 + (a << 3), [9, 17, 25, 33], np.uint16)
assert eq(1 + (3 << a), [7, 13, 25, 49], np.uint16)
assert eq(1 + (a >> 1), [1, 2, 2, 3], np.uint16)
assert eq(1 + (1000 >> a), [501, 251, 126, 63], np.uint16)
assert eq(1 + (a & 2), [1, 3, 3, 1], np.uint16)
assert eq(1 + (2 & a), [1, 3, 3, 1], np.uint16)
assert eq(1 + (a | 2), [4, 3, 4, 7], np.uint16)
assert eq(1 + (2 | a), [4, 3, 4, 7], np.uint16)
assert eq(1 + (a ^ 2), [4, 1, 2, 7], np.uint16)
assert eq(1 + (2 ^ a), [4, 1, 2, 7], np.uint16)
assert eq(np.logical_and(a, a & 1), [True, False, True, False], bool)
assert eq(np.logical_or(a & 2, a & 1), [True, True, True, False], bool)
assert eq(np.logical_xor(a, a & 1), [False, True, False, True], bool)
assert eq((a + 1) == 2, [True, False, False, False], bool)
assert eq(2 == (a + 1), [True, False, False, False], bool)
assert eq((a + 1) != 2, [False, True, True, True], bool)
assert eq(2 != (a + 1), [False, True, True, True], bool)
assert eq((a + 1) < 3, [True, False, False, False], bool)
assert eq(3 < (a + 1), [False, False, True, True], bool)
assert eq((a + 1) > 3, [False, False, True, True], bool)
assert eq(3 > (a + 1), [True, False, False, False], bool)
assert eq((a + 1) <= 3, [True, True, False, False], bool)
assert eq(3 <= (a + 1), [False, True, True, True], bool)
assert eq((a + 1) >= 3, [False, True, True, True], bool)
assert eq(3 >= (a + 1), [True, True, False, False], bool)
assert eq(1 + np.minimum(a, 3), [2, 3, 4, 4], np.uint16)
assert eq(1 + np.minimum(3, a), [2, 3, 4, 4], np.uint16)
assert eq(1 + np.maximum(a, 3), [4, 4, 4, 5], np.uint16)
assert eq(1 + np.maximum(3, a), [4, 4, 4, 5], np.uint16)
assert eq(1 + np.fmin(a, 3), [2, 3, 4, 4], np.uint16)
assert eq(1 + np.fmin(3, a), [2, 3, 4, 4], np.uint16)
assert eq(1 + np.fmax(a, 3), [4, 4, 4, 5], np.uint16)
assert eq(1 + np.fmax(3, a), [4, 4, 4, 5], np.uint16)
assert eq(1 + np.sin(a), [1.f32 + np.sin(1.f32), 1.f32 + np.sin(2.f32), 1.f32 + np.sin(3.f32), 1.f32 + np.sin(4.f32)], np.float32)
assert eq(1 + np.cos(a), [1.f32 + np.cos(1.f32), 1.f32 + np.cos(2.f32), 1.f32 + np.cos(3.f32), 1.f32 + np.cos(4.f32)], np.float32)
assert eq(1 + np.tan(a), [1.f32 + np.tan(1.f32), 1.f32 + np.tan(2.f32), 1.f32 + np.tan(3.f32), 1.f32 + np.tan(4.f32)], np.float32)
assert eq(1 + np.arcsin(a), [1.f32 + np.arcsin(1.f32), 1.f32 + np.arcsin(2.f32), 1.f32 + np.arcsin(3.f32), 1.f32 + np.arcsin(4.f32)], np.float32)
assert eq(1 + np.arccos(a), [1.f32 + np.arccos(1.f32), 1.f32 + np.arccos(2.f32), 1.f32 + np.arccos(3.f32), 1.f32 + np.arccos(4.f32)], np.float32)
assert eq(1 + np.arctan(a), [1.f32 + np.arctan(1.f32), 1.f32 + np.arctan(2.f32), 1.f32 + np.arctan(3.f32), 1.f32 + np.arctan(4.f32)], np.float32)
assert eq(1 + np.arctan2(a, 3.f32), [1.f32 + np.arctan2(1.f32, 3.f32), 1.f32 + np.arctan2(2.f32, 3.f32), 1.f32 + np.arctan2(3.f32, 3.f32), 1.f32 + np.arctan2(4.f32, 3.f32)], np.float32)
assert eq(1 + np.arctan2(3.f32, a), [1.f32 + np.arctan2(3.f32, 1.f32), 1.f32 + np.arctan2(3.f32, 2.f32), 1.f32 + np.arctan2(3.f32, 3.f32), 1.f32 + np.arctan2(3.f32, 4.f32)], np.float32)
assert eq(1 + np.hypot(a, 3), [1.f32 + np.hypot(1.f32, 3.f32), 1.f32 + np.hypot(2.f32, 3.f32), 1.f32 + np.hypot(3.f32, 3.f32), 1.f32 + np.hypot(4.f32, 3.f32)], np.float32)
assert eq(1 + np.hypot(3, a), [1.f32 + np.hypot(3.f32, 1.f32), 1.f32 + np.hypot(3.f32, 2.f32), 1.f32 + np.hypot(3.f32, 3.f32), 1.f32 + np.hypot(3.f32, 4.f32)], np.float32)
assert eq(1 + np.sinh(a), [1.f32 + np.sinh(1.f32), 1.f32 + np.sinh(2.f32), 1.f32 + np.sinh(3.f32), 1.f32 + np.sinh(4.f32)], np.float32)
assert eq(1 + np.cosh(a), [1.f32 + np.cosh(1.f32), 1.f32 + np.cosh(2.f32), 1.f32 + np.cosh(3.f32), 1.f32 + np.cosh(4.f32)], np.float32)
assert eq(1 + np.tanh(a), [1.f32 + np.tanh(1.f32), 1.f32 + np.tanh(2.f32), 1.f32 + np.tanh(3.f32), 1.f32 + np.tanh(4.f32)], np.float32)
assert eq(1 + np.arcsinh(a), [1.f32 + np.arcsinh(1.f32), 1.f32 + np.arcsinh(2.f32), 1.f32 + np.arcsinh(3.f32), 1.f32 + np.arcsinh(4.f32)], np.float32)
assert eq(1 + np.arccosh(a), [1.f32 + np.arccosh(1.f32), 1.f32 + np.arccosh(2.f32), 1.f32 + np.arccosh(3.f32), 1.f32 + np.arccosh(4.f32)], np.float32)
assert eq(1 + np.arctanh(a), [1.f32 + np.arctanh(1.f32), 1.f32 + np.arctanh(2.f32), 1.f32 + np.arctanh(3.f32), 1.f32 + np.arctanh(4.f32)], np.float32)
assert eq(1 + np.conj(a), [1 + np.conj(1), 1 + np.conj(2), 1 + np.conj(3), 1 + np.conj(4)], np.uint16)
assert eq(1 + np.exp(a), [1.f32 + np.exp(1.f32), 1.f32 + np.exp(2.f32), 1.f32 + np.exp(3.f32), 1.f32 + np.exp(4.f32)], np.float32)
assert eq(1 + np.exp2(a), [1.f32 + np.exp2(1.f32), 1.f32 + np.exp2(2.f32), 1.f32 + np.exp2(3.f32), 1.f32 + np.exp2(4.f32)], np.float32)
assert eq(1 + np.log(a), [1.f32 + np.log(1.f32), 1.f32 + np.log(2.f32), 1.f32 + np.log(3.f32), 1.f32 + np.log(4.f32)], np.float32)
assert eq(1 + np.log2(a), [1.f32 + np.log2(1.f32), 1.f32 + np.log2(2.f32), 1.f32 + np.log2(3.f32), 1.f32 + np.log2(4.f32)], np.float32)
assert eq(1 + np.log10(a), [1.f32 + np.log10(1.f32), 1.f32 + np.log10(2.f32), 1.f32 + np.log10(3.f32), 1.f32 + np.log10(4.f32)], np.float32)
assert eq(1 + np.expm1(a), [1.f32 + np.expm1(1.f32), 1.f32 + np.expm1(2.f32), 1.f32 + np.expm1(3.f32), 1.f32 + np.expm1(4.f32)], np.float32)
assert eq(1 + np.log1p(a), [1.f32 + np.log1p(1.f32), 1.f32 + np.log1p(2.f32), 1.f32 + np.log1p(3.f32), 1.f32 + np.log1p(4.f32)], np.float32)
assert eq(1 + np.sqrt(a), [1.f32 + np.sqrt(1.f32), 1.f32 + np.sqrt(2.f32), 1.f32 + np.sqrt(3.f32), 1.f32 + np.sqrt(4.f32)], np.float32)
assert eq(1 + np.square(a), [1 + np.square(1), 1 + np.square(2), 1 + np.square(3), 1 + np.square(4)], np.uint16)
assert eq(1 + np.cbrt(a), [1.f32 + np.cbrt(1.f32), 1.f32 + np.cbrt(2.f32), 1.f32 + np.cbrt(3.f32), 1.f32 + np.cbrt(4.f32)], np.float32)
assert eq(1 + np.logaddexp(a, 3), [1.f32 + np.logaddexp(1.f32, 3.f32), 1.f32 + np.logaddexp(2.f32, 3.f32), 1.f32 + np.logaddexp(3.f32, 3.f32), 1.f32 + np.logaddexp(4.f32, 3.f32)], np.float32)
assert eq(1 + np.logaddexp(3, a), [1.f32 + np.logaddexp(3.f32, 1.f32), 1.f32 + np.logaddexp(3.f32, 2.f32), 1.f32 + np.logaddexp(3.f32, 3.f32), 1.f32 + np.logaddexp(3.f32, 4.f32)], np.float32)
assert eq(1 + np.logaddexp2(a, 3), [1.f32 + np.logaddexp2(1.f32, 3.f32), 1.f32 + np.logaddexp2(2.f32, 3.f32), 1.f32 + np.logaddexp2(3.f32, 3.f32), 1.f32 + np.logaddexp2(4.f32, 3.f32)], np.float32)
assert eq(1 + np.logaddexp2(3, a), [1.f32 + np.logaddexp2(3.f32, 1.f32), 1.f32 + np.logaddexp2(3.f32, 2.f32), 1.f32 + np.logaddexp2(3.f32, 3.f32), 1.f32 + np.logaddexp2(3.f32, 4.f32)], np.float32)
assert eq(1 + np.reciprocal(a), [2, 1, 1, 1], np.uint16)
assert eq(1 + np.rint(a), [1.f32 + np.rint(1.f32), 1.f32 + np.rint(2.f32), 1.f32 + np.rint(3.f32), 1.f32 + np.rint(4.f32)], np.float32)
assert eq(1 + np.floor(a), [1.f32 + np.floor(1.f32), 1.f32 + np.floor(2.f32), 1.f32 + np.floor(3.f32), 1.f32 + np.floor(4.f32)], np.float32)
assert eq(1 + np.ceil(a), [1.f32 + np.ceil(1.f32), 1.f32 + np.ceil(2.f32), 1.f32 + np.ceil(3.f32), 1.f32 + np.ceil(4.f32)], np.float32)
assert eq(1 + np.trunc(a), [1.f32 + np.trunc(1.f32), 1.f32 + np.trunc(2.f32), 1.f32 + np.trunc(3.f32), 1.f32 + np.trunc(4.f32)], np.float32)
assert eq(1 + np.isnan(a), [1, 1, 1, 1], int)
assert eq(1 + np.isinf(a), [1, 1, 1, 1], int)
assert eq(1 + np.isfinite(a), [2, 2, 2, 2], int)
assert eq(1 + np.ldexp(a, 1), [1.f32 + np.ldexp(1.f32, 1), 1.f32 + np.ldexp(2.f32, 1), 1.f32 + np.ldexp(3.f32, 1), 1.f32 + np.ldexp(4.f32, 1)], np.float32)
assert eq(1 + np.ldexp(1, a), [1.f32 + np.ldexp(1.f32, 1), 1.f32 + np.ldexp(1.f32, 2), 1.f32 + np.ldexp(1.f32, 3), 1.f32 + np.ldexp(1.f32, 4)], np.float32)
assert eq(1 + np.sign(a), [2, 2, 2, 2], np.uint16)
assert eq(1 + np.signbit(a), [1, 1, 1, 1], int)
assert eq(1 + np.copysign(a, -1), [1.f32 + np.copysign(1.f32, -1.f32), 1.f32 + np.copysign(2.f32, -1.f32), 1.f32 + np.copysign(3.f32, -1.f32), 1.f32 + np.copysign(4.f32, -1.f32)], np.float32)
assert eq(1 + np.copysign(-1, a), [1.f32 + np.copysign(-1.f32, 1.f32), 1.f32 + np.copysign(-1.f32, 2.f32), 1.f32 + np.copysign(-1.f32, 3.f32), 1.f32 + np.copysign(-1.f32, 4.f32)], np.float32)
assert eq(1 + np.spacing(a), [1.f32 + np.spacing(1.f32), 1.f32 + np.spacing(2.f32), 1.f32 + np.spacing(3.f32), 1.f32 + np.spacing(4.f32)], np.float32)
assert eq(1 + np.nextafter(a, 1), [1.f32 + np.nextafter(1.f32, 1.f32), 1.f32 + np.nextafter(2.f32, 1.f32), 1.f32 + np.nextafter(3.f32, 1.f32), 1.f32 + np.nextafter(4.f32, 1.f32)], np.float32)
assert eq(1 + np.nextafter(1, a), [1.f32 + np.nextafter(1.f32, 1.f32), 1.f32 + np.nextafter(1.f32, 2.f32), 1.f32 + np.nextafter(1.f32, 3.f32), 1.f32 + np.nextafter(1.f32, 4.f32)], np.float32)
assert eq(1 + np.deg2rad(a), [1.f32 + np.deg2rad(1.f32), 1.f32 + np.deg2rad(2.f32), 1.f32 + np.deg2rad(3.f32), 1.f32 + np.deg2rad(4.f32)], np.float32)
assert eq(1 + np.rad2deg(a), [1.f32 + np.rad2deg(1.f32), 1.f32 + np.rad2deg(2.f32), 1.f32 + np.rad2deg(3.f32), 1.f32 + np.rad2deg(4.f32)], np.float32)
assert eq(1 + np.heaviside(a, 1), [1.f32 + np.heaviside(1.f32, 1.f32), 1.f32 + np.heaviside(2.f32, 1.f32), 1.f32 + np.heaviside(3.f32, 1.f32), 1.f32 + np.heaviside(4.f32, 1.f32)], np.float32)
assert eq(1 + np.heaviside(1, a), [1.f32 + np.heaviside(1.f32, 1.f32), 1.f32 + np.heaviside(1.f32, 2.f32), 1.f32 + np.heaviside(1.f32, 3.f32), 1.f32 + np.heaviside(1.f32, 4.f32)], np.float32)
@test
def test_ops_uint8():
a = np.array([1, 2, 3, 4], np.uint8)
assert eq(1 + (+a), [2, 3, 4, 5], np.uint8)
assert eq(1 + (-a), [0, -1, -2, -3], np.uint8)
assert eq(1 + (~a), [-1, -2, -3, -4], np.uint8)
assert eq(1 + np.abs(a), [2, 3, 4, 5], np.uint8)
assert eq(1 + abs(a), [2, 3, 4, 5], np.uint8)
assert eq(2 * (1 + a), [4, 6, 8, 10], np.uint8)
assert eq(2 * (a + 1), [4, 6, 8, 10], np.uint8)
assert eq(2 * (a - 1), [0, 2, 4, 6], np.uint8)
assert eq(2 * (1 - a), [0, -2, -4, -6], np.uint8)
assert eq(1 + (a * 2), [3, 5, 7, 9], np.uint8)
assert eq(1 + (2 * a), [3, 5, 7, 9], np.uint8)
assert eq(1 + (a.reshape(1, -1) @ a.reshape(-1, 1)), [[31]], np.uint8)
assert eq(1 + (a / 2), [1.5, 2., 2.5, 3.], float)
assert eq(1 + (2 / a), [3., 2., 1 + 2/3, 1.5], float)
assert eq(1 + (a // 2), [1, 2, 2, 3], np.uint8)
assert eq(1 + (10 // a), [11, 6, 4, 3], np.uint8)
assert eq(1 + (a % 3), [2, 3, 1, 2], np.uint8)
assert eq(1 + (10 % a), [1, 1, 2, 3], np.uint8)
assert eq(1 + np.fmod(a, 3), [2, 3, 1, 2], np.uint8)
assert eq(1 + np.fmod(10, a), [1, 1, 2, 3], np.uint8)
assert eq(1 + (a ** 3), [2, 9, 28, 65], np.uint8)
assert eq(1 + (3 ** a), [4, 10, 28, 82], np.uint8)
assert eq(1 + (a << 3), [9, 17, 25, 33], np.uint8)
assert eq(1 + (3 << a), [7, 13, 25, 49], np.uint8)
assert eq(1 + (a >> 1), [1, 2, 2, 3], np.uint8)
assert eq(1 + (100 >> a), [51, 26, 13, 7], np.uint8)
assert eq(1 + (a & 2), [1, 3, 3, 1], np.uint8)
assert eq(1 + (2 & a), [1, 3, 3, 1], np.uint8)
assert eq(1 + (a | 2), [4, 3, 4, 7], np.uint8)
assert eq(1 + (2 | a), [4, 3, 4, 7], np.uint8)
assert eq(1 + (a ^ 2), [4, 1, 2, 7], np.uint8)
assert eq(1 + (2 ^ a), [4, 1, 2, 7], np.uint8)
assert eq(np.logical_and(a, a & 1), [True, False, True, False], bool)
assert eq(np.logical_or(a & 2, a & 1), [True, True, True, False], bool)
assert eq(np.logical_xor(a, a & 1), [False, True, False, True], bool)
assert eq((a + 1) == 2, [True, False, False, False], bool)
assert eq(2 == (a + 1), [True, False, False, False], bool)
assert eq((a + 1) != 2, [False, True, True, True], bool)
assert eq(2 != (a + 1), [False, True, True, True], bool)
assert eq((a + 1) < 3, [True, False, False, False], bool)
assert eq(3 < (a + 1), [False, False, True, True], bool)
assert eq((a + 1) > 3, [False, False, True, True], bool)
assert eq(3 > (a + 1), [True, False, False, False], bool)
assert eq((a + 1) <= 3, [True, True, False, False], bool)
assert eq(3 <= (a + 1), [False, True, True, True], bool)
assert eq((a + 1) >= 3, [False, True, True, True], bool)
assert eq(3 >= (a + 1), [True, True, False, False], bool)
assert eq(1 + np.minimum(a, 3), [2, 3, 4, 4], np.uint8)
assert eq(1 + np.minimum(3, a), [2, 3, 4, 4], np.uint8)
assert eq(1 + np.maximum(a, 3), [4, 4, 4, 5], np.uint8)
assert eq(1 + np.maximum(3, a), [4, 4, 4, 5], np.uint8)
assert eq(1 + np.fmin(a, 3), [2, 3, 4, 4], np.uint8)
assert eq(1 + np.fmin(3, a), [2, 3, 4, 4], np.uint8)
assert eq(1 + np.fmax(a, 3), [4, 4, 4, 5], np.uint8)
assert eq(1 + np.fmax(3, a), [4, 4, 4, 5], np.uint8)
assert eq(1 + np.sin(a), [1.f16 + np.sin(1.f16), 1.f16 + np.sin(2.f16), 1.f16 + np.sin(3.f16), 1.f16 + np.sin(4.f16)], np.float16)
assert eq(1 + np.cos(a), [1.f16 + np.cos(1.f16), 1.f16 + np.cos(2.f16), 1.f16 + np.cos(3.f16), 1.f16 + np.cos(4.f16)], np.float16)
assert eq(1 + np.tan(a), [1.f16 + np.tan(1.f16), 1.f16 + np.tan(2.f16), 1.f16 + np.tan(3.f16), 1.f16 + np.tan(4.f16)], np.float16)
assert eq(1 + np.arcsin(a), [1.f16 + np.arcsin(1.f16), 1.f16 + np.arcsin(2.f16), 1.f16 + np.arcsin(3.f16), 1.f16 + np.arcsin(4.f16)], np.float16)
assert eq(1 + np.arccos(a), [1.f16 + np.arccos(1.f16), 1.f16 + np.arccos(2.f16), 1.f16 + np.arccos(3.f16), 1.f16 + np.arccos(4.f16)], np.float16)
assert eq(1 + np.arctan(a), [1.f16 + np.arctan(1.f16), 1.f16 + np.arctan(2.f16), 1.f16 + np.arctan(3.f16), 1.f16 + np.arctan(4.f16)], np.float16)
assert eq(1 + np.arctan2(a, 3.f16), [1.f16 + np.arctan2(1.f16, 3.f16), 1.f16 + np.arctan2(2.f16, 3.f16), 1.f16 + np.arctan2(3.f16, 3.f16), 1.f16 + np.arctan2(4.f16, 3.f16)], np.float16)
assert eq(1 + np.arctan2(3.f16, a), [1.f16 + np.arctan2(3.f16, 1.f16), 1.f16 + np.arctan2(3.f16, 2.f16), 1.f16 + np.arctan2(3.f16, 3.f16), 1.f16 + np.arctan2(3.f16, 4.f16)], np.float16)
assert eq(1 + np.hypot(a, 3), [1.f16 + np.hypot(1.f16, 3.f16), 1.f16 + np.hypot(2.f16, 3.f16), 1.f16 + np.hypot(3.f16, 3.f16), 1.f16 + np.hypot(4.f16, 3.f16)], np.float16)
assert eq(1 + np.hypot(3, a), [1.f16 + np.hypot(3.f16, 1.f16), 1.f16 + np.hypot(3.f16, 2.f16), 1.f16 + np.hypot(3.f16, 3.f16), 1.f16 + np.hypot(3.f16, 4.f16)], np.float16)
assert eq(1 + np.sinh(a), [1.f16 + np.sinh(1.f16), 1.f16 + np.sinh(2.f16), 1.f16 + np.sinh(3.f16), 1.f16 + np.sinh(4.f16)], np.float16)
assert eq(1 + np.cosh(a), [1.f16 + np.cosh(1.f16), 1.f16 + np.cosh(2.f16), 1.f16 + np.cosh(3.f16), 1.f16 + np.cosh(4.f16)], np.float16)
assert eq(1 + np.tanh(a), [1.f16 + np.tanh(1.f16), 1.f16 + np.tanh(2.f16), 1.f16 + np.tanh(3.f16), 1.f16 + np.tanh(4.f16)], np.float16)
assert eq(1 + np.arcsinh(a), [1.f16 + np.arcsinh(1.f16), 1.f16 + np.arcsinh(2.f16), 1.f16 + np.arcsinh(3.f16), 1.f16 + np.arcsinh(4.f16)], np.float16)
assert eq(1 + np.arccosh(a), [1.f16 + np.arccosh(1.f16), 1.f16 + np.arccosh(2.f16), 1.f16 + np.arccosh(3.f16), 1.f16 + np.arccosh(4.f16)], np.float16)
assert eq(1 + np.arctanh(a), [1.f16 + np.arctanh(1.f16), 1.f16 + np.arctanh(2.f16), 1.f16 + np.arctanh(3.f16), 1.f16 + np.arctanh(4.f16)], np.float16)
assert eq(1 + np.conj(a), [1 + np.conj(1), 1 + np.conj(2), 1 + np.conj(3), 1 + np.conj(4)], np.uint8)
assert eq(1 + np.exp(a), [1.f16 + np.exp(1.f16), 1.f16 + np.exp(2.f16), 1.f16 + np.exp(3.f16), 1.f16 + np.exp(4.f16)], np.float16)
assert eq(1 + np.exp2(a), [1.f16 + np.exp2(1.f16), 1.f16 + np.exp2(2.f16), 1.f16 + np.exp2(3.f16), 1.f16 + np.exp2(4.f16)], np.float16)
assert eq(1 + np.log(a), [1.f16 + np.log(1.f16), 1.f16 + np.log(2.f16), 1.f16 + np.log(3.f16), 1.f16 + np.log(4.f16)], np.float16)
assert eq(1 + np.log2(a), [1.f16 + np.log2(1.f16), 1.f16 + np.log2(2.f16), 1.f16 + np.log2(3.f16), 1.f16 + np.log2(4.f16)], np.float16)
assert eq(1 + np.log10(a), [1.f16 + np.log10(1.f16), 1.f16 + np.log10(2.f16), 1.f16 + np.log10(3.f16), 1.f16 + np.log10(4.f16)], np.float16)
assert eq(1 + np.expm1(a), [1.f16 + np.expm1(1.f16), 1.f16 + np.expm1(2.f16), 1.f16 + np.expm1(3.f16), 1.f16 + np.expm1(4.f16)], np.float16)
assert eq(1 + np.log1p(a), [1.f16 + np.log1p(1.f16), 1.f16 + np.log1p(2.f16), 1.f16 + np.log1p(3.f16), 1.f16 + np.log1p(4.f16)], np.float16)
assert eq(1 + np.sqrt(a), [1.f16 + np.sqrt(1.f16), 1.f16 + np.sqrt(2.f16), 1.f16 + np.sqrt(3.f16), 1.f16 + np.sqrt(4.f16)], np.float16)
assert eq(1 + np.square(a), [1 + np.square(1), 1 + np.square(2), 1 + np.square(3), 1 + np.square(4)], np.uint8)
assert eq(1 + np.cbrt(a), [1.f16 + np.cbrt(1.f16), 1.f16 + np.cbrt(2.f16), 1.f16 + np.cbrt(3.f16), 1.f16 + np.cbrt(4.f16)], np.float16)
assert eq(1 + np.logaddexp(a, 3), [1.f16 + np.logaddexp(1.f16, 3.f16), 1.f16 + np.logaddexp(2.f16, 3.f16), 1.f16 + np.logaddexp(3.f16, 3.f16), 1.f16 + np.logaddexp(4.f16, 3.f16)], np.float16)
assert eq(1 + np.logaddexp(3, a), [1.f16 + np.logaddexp(3.f16, 1.f16), 1.f16 + np.logaddexp(3.f16, 2.f16), 1.f16 + np.logaddexp(3.f16, 3.f16), 1.f16 + np.logaddexp(3.f16, 4.f16)], np.float16)
assert eq(1 + np.logaddexp2(a, 3), [1.f16 + np.logaddexp2(1.f16, 3.f16), 1.f16 + np.logaddexp2(2.f16, 3.f16), 1.f16 + np.logaddexp2(3.f16, 3.f16), 1.f16 + np.logaddexp2(4.f16, 3.f16)], np.float16)
assert eq(1 + np.logaddexp2(3, a), [1.f16 + np.logaddexp2(3.f16, 1.f16), 1.f16 + np.logaddexp2(3.f16, 2.f16), 1.f16 + np.logaddexp2(3.f16, 3.f16), 1.f16 + np.logaddexp2(3.f16, 4.f16)], np.float16)
assert eq(1 + np.reciprocal(a), [2, 1, 1, 1], np.uint8)
assert eq(1 + np.rint(a), [1.f16 + np.rint(1.f16), 1.f16 + np.rint(2.f16), 1.f16 + np.rint(3.f16), 1.f16 + np.rint(4.f16)], np.float16)
assert eq(1 + np.floor(a), [1.f16 + np.floor(1.f16), 1.f16 + np.floor(2.f16), 1.f16 + np.floor(3.f16), 1.f16 + np.floor(4.f16)], np.float16)
assert eq(1 + np.ceil(a), [1.f16 + np.ceil(1.f16), 1.f16 + np.ceil(2.f16), 1.f16 + np.ceil(3.f16), 1.f16 + np.ceil(4.f16)], np.float16)
assert eq(1 + np.trunc(a), [1.f16 + np.trunc(1.f16), 1.f16 + np.trunc(2.f16), 1.f16 + np.trunc(3.f16), 1.f16 + np.trunc(4.f16)], np.float16)
assert eq(1 + np.isnan(a), [1, 1, 1, 1], int)
assert eq(1 + np.isinf(a), [1, 1, 1, 1], int)
assert eq(1 + np.isfinite(a), [2, 2, 2, 2], int)
assert eq(1 + np.ldexp(a, 1), [1.f16 + np.ldexp(1.f16, 1), 1.f16 + np.ldexp(2.f16, 1), 1.f16 + np.ldexp(3.f16, 1), 1.f16 + np.ldexp(4.f16, 1)], np.float16)
assert eq(1 + np.ldexp(1, a), [1.f16 + np.ldexp(1.f16, 1), 1.f16 + np.ldexp(1.f16, 2), 1.f16 + np.ldexp(1.f16, 3), 1.f16 + np.ldexp(1.f16, 4)], np.float16)
assert eq(1 + np.sign(a), [2, 2, 2, 2], np.uint8)
assert eq(1 + np.signbit(a), [1, 1, 1, 1], int)
assert eq(1 + np.copysign(a, -1), [1.f16 + np.copysign(1.f16, -1.f16), 1.f16 + np.copysign(2.f16, -1.f16), 1.f16 + np.copysign(3.f16, -1.f16), 1.f16 + np.copysign(4.f16, -1.f16)], np.float16)
assert eq(1 + np.copysign(-1, a), [1.f16 + np.copysign(-1.f16, 1.f16), 1.f16 + np.copysign(-1.f16, 2.f16), 1.f16 + np.copysign(-1.f16, 3.f16), 1.f16 + np.copysign(-1.f16, 4.f16)], np.float16)
assert eq(1 + np.spacing(a), [1.f16 + np.spacing(1.f16), 1.f16 + np.spacing(2.f16), 1.f16 + np.spacing(3.f16), 1.f16 + np.spacing(4.f16)], np.float16)
assert eq(1 + np.nextafter(a, 1), [1.f16 + np.nextafter(1.f16, 1.f16), 1.f16 + np.nextafter(2.f16, 1.f16), 1.f16 + np.nextafter(3.f16, 1.f16), 1.f16 + np.nextafter(4.f16, 1.f16)], np.float16)
assert eq(1 + np.nextafter(1, a), [1.f16 + np.nextafter(1.f16, 1.f16), 1.f16 + np.nextafter(1.f16, 2.f16), 1.f16 + np.nextafter(1.f16, 3.f16), 1.f16 + np.nextafter(1.f16, 4.f16)], np.float16)
assert eq(1 + np.deg2rad(a), [1.f16 + np.deg2rad(1.f16), 1.f16 + np.deg2rad(2.f16), 1.f16 + np.deg2rad(3.f16), 1.f16 + np.deg2rad(4.f16)], np.float16)
assert eq(1 + np.rad2deg(a), [1.f16 + np.rad2deg(1.f16), 1.f16 + np.rad2deg(2.f16), 1.f16 + np.rad2deg(3.f16), 1.f16 + np.rad2deg(4.f16)], np.float16)
assert eq(1 + np.heaviside(a, 1), [1.f16 + np.heaviside(1.f16, 1.f16), 1.f16 + np.heaviside(2.f16, 1.f16), 1.f16 + np.heaviside(3.f16, 1.f16), 1.f16 + np.heaviside(4.f16, 1.f16)], np.float16)
assert eq(1 + np.heaviside(1, a), [1.f16 + np.heaviside(1.f16, 1.f16), 1.f16 + np.heaviside(1.f16, 2.f16), 1.f16 + np.heaviside(1.f16, 3.f16), 1.f16 + np.heaviside(1.f16, 4.f16)], np.float16)
@test
def test_ops_float64():
a = np.array([1., 2., 3., 4.])
assert eq(1 + (+a), [2, 3, 4, 5], float)
assert eq(1 + (-a), [0, -1, -2, -3], float)
assert eq(1 + np.abs(a), [2, 3, 4, 5], float)
assert eq(1 + abs(a), [2, 3, 4, 5], float)
assert eq(2 * (1 + a), [4, 6, 8, 10], float)
assert eq(2 * (a + 1), [4, 6, 8, 10], float)
assert eq(2 * (a - 1), [0, 2, 4, 6], float)
assert eq(2 * (1 - a), [0, -2, -4, -6], float)
assert eq(1 + (a * 2), [3, 5, 7, 9], float)
assert eq(1 + (2 * a), [3, 5, 7, 9], float)
assert eq(1 + (a.reshape(1, -1) @ a.reshape(-1, 1)), [[31]], float)
assert eq(1 + (a / 2), [1.5, 2., 2.5, 3.], float)
assert eq(1 + (2 / a), [3., 2., 1 + 2/3, 1.5], float)
assert eq(1 + (a // 2), [1, 2, 2, 3], float)
assert eq(1 + (10 // a), [11, 6, 4, 3], float)
assert eq(1 + (a % 3), [2, 3, 1, 2], float)
assert eq(1 + (10 % a), [1, 1, 2, 3], float)
assert eq(1 + np.fmod(a, 3), [2, 3, 1, 2], float)
assert eq(1 + np.fmod(10, a), [1, 1, 2, 3], float)
assert eq(1 + (a ** 3), [2, 9, 28, 65], float)
assert eq(1 + (3 ** a), [4, 10, 28, 82], float)
assert eq(np.logical_and(a, a - 1), [False, True, True, True], bool)
assert eq(np.logical_or(a, a - 1), [True, True, True, True], bool)
assert eq(np.logical_xor(a, a % 2), [False, True, False, True], bool)
assert eq((a + 1) == 2, [True, False, False, False], bool)
assert eq(2 == (a + 1), [True, False, False, False], bool)
assert eq((a + 1) != 2, [False, True, True, True], bool)
assert eq(2 != (a + 1), [False, True, True, True], bool)
assert eq((a + 1) < 3, [True, False, False, False], bool)
assert eq(3 < (a + 1), [False, False, True, True], bool)
assert eq((a + 1) > 3, [False, False, True, True], bool)
assert eq(3 > (a + 1), [True, False, False, False], bool)
assert eq((a + 1) <= 3, [True, True, False, False], bool)
assert eq(3 <= (a + 1), [False, True, True, True], bool)
assert eq((a + 1) >= 3, [False, True, True, True], bool)
assert eq(3 >= (a + 1), [True, True, False, False], bool)
assert eq(1 + np.minimum(a, 3), [2, 3, 4, 4], float)
assert eq(1 + np.minimum(3, a), [2, 3, 4, 4], float)
assert eq(1 + np.maximum(a, 3), [4, 4, 4, 5], float)
assert eq(1 + np.maximum(3, a), [4, 4, 4, 5], float)
assert eq(1 + np.fmin(a, 3), [2, 3, 4, 4], float)
assert eq(1 + np.fmin(3, a), [2, 3, 4, 4], float)
assert eq(1 + np.fmax(a, 3), [4, 4, 4, 5], float)
assert eq(1 + np.fmax(3, a), [4, 4, 4, 5], float)
assert eq(1 + np.minimum(a, np.nan), [np.nan, np.nan, np.nan, np.nan], float)
assert eq(1 + np.minimum(np.nan, a), [np.nan, np.nan, np.nan, np.nan], float)
assert eq(1 + np.maximum(a, np.nan), [np.nan, np.nan, np.nan, np.nan], float)
assert eq(1 + np.maximum(np.nan, a), [np.nan, np.nan, np.nan, np.nan], float)
assert eq(1 + np.fmin(a, np.nan), [2, 3, 4, 5], float)
assert eq(1 + np.fmin(np.nan, a), [2, 3, 4, 5], float)
assert eq(1 + np.fmax(a, np.nan), [2, 3, 4, 5], float)
assert eq(1 + np.fmax(np.nan, a), [2, 3, 4, 5], float)
assert eq(1 + np.sin(a), [1 + np.sin(1), 1 + np.sin(2), 1 + np.sin(3), 1 + np.sin(4)], float)
assert eq(1 + np.cos(a), [1 + np.cos(1), 1 + np.cos(2), 1 + np.cos(3), 1 + np.cos(4)], float)
assert eq(1 + np.tan(a), [1 + np.tan(1), 1 + np.tan(2), 1 + np.tan(3), 1 + np.tan(4)], float)
assert eq(1 + np.arcsin(a), [1 + np.arcsin(1), 1 + np.arcsin(2), 1 + np.arcsin(3), 1 + np.arcsin(4)], float)
assert eq(1 + np.arccos(a), [1 + np.arccos(1), 1 + np.arccos(2), 1 + np.arccos(3), 1 + np.arccos(4)], float)
assert eq(1 + np.arctan(a), [1 + np.arctan(1), 1 + np.arctan(2), 1 + np.arctan(3), 1 + np.arctan(4)], float)
assert eq(1 + np.arctan2(a, 3), [1 + np.arctan2(1, 3), 1 + np.arctan2(2, 3), 1 + np.arctan2(3, 3), 1 + np.arctan2(4, 3)], float)
assert eq(1 + np.arctan2(3, a), [1 + np.arctan2(3, 1), 1 + np.arctan2(3, 2), 1 + np.arctan2(3, 3), 1 + np.arctan2(3, 4)], float)
assert eq(1 + np.hypot(a, 3), [1 + np.hypot(1, 3), 1 + np.hypot(2, 3), 1 + np.hypot(3, 3), 1 + np.hypot(4, 3)], float)
assert eq(1 + np.hypot(3, a), [1 + np.hypot(3, 1), 1 + np.hypot(3, 2), 1 + np.hypot(3, 3), 1 + np.hypot(3, 4)], float)
assert eq(1 + np.sinh(a), [1 + np.sinh(1), 1 + np.sinh(2), 1 + np.sinh(3), 1 + np.sinh(4)], float)
assert eq(1 + np.cosh(a), [1 + np.cosh(1), 1 + np.cosh(2), 1 + np.cosh(3), 1 + np.cosh(4)], float)
assert eq(1 + np.tanh(a), [1 + np.tanh(1), 1 + np.tanh(2), 1 + np.tanh(3), 1 + np.tanh(4)], float)
assert eq(1 + np.arcsinh(a), [1 + np.arcsinh(1), 1 + np.arcsinh(2), 1 + np.arcsinh(3), 1 + np.arcsinh(4)], float)
assert eq(1 + np.arccosh(a), [1 + np.arccosh(1), 1 + np.arccosh(2), 1 + np.arccosh(3), 1 + np.arccosh(4)], float)
assert eq(1 + np.arctanh(a), [1 + np.arctanh(1), 1 + np.arctanh(2), 1 + np.arctanh(3), 1 + np.arctanh(4)], float)
assert eq(1 + np.conj(a), [1 + np.conj(1), 1 + np.conj(2), 1 + np.conj(3), 1 + np.conj(4)], float)
assert eq(1 + np.exp(a), [1 + np.exp(1), 1 + np.exp(2), 1 + np.exp(3), 1 + np.exp(4)], float)
assert eq(1 + np.exp2(a), [1 + np.exp2(1), 1 + np.exp2(2), 1 + np.exp2(3), 1 + np.exp2(4)], float)
assert eq(1 + np.log(a), [1 + np.log(1), 1 + np.log(2), 1 + np.log(3), 1 + np.log(4)], float)
assert eq(1 + np.log2(a), [1 + np.log2(1), 1 + np.log2(2), 1 + np.log2(3), 1 + np.log2(4)], float)
assert eq(1 + np.log10(a), [1 + np.log10(1), 1 + np.log10(2), 1 + np.log10(3), 1 + np.log10(4)], float)
assert eq(1 + np.expm1(a), [1 + np.expm1(1), 1 + np.expm1(2), 1 + np.expm1(3), 1 + np.expm1(4)], float)
assert eq(1 + np.log1p(a), [1 + np.log1p(1), 1 + np.log1p(2), 1 + np.log1p(3), 1 + np.log1p(4)], float)
assert eq(1 + np.sqrt(a), [1 + np.sqrt(1), 1 + np.sqrt(2), 1 + np.sqrt(3), 1 + np.sqrt(4)], float)
assert eq(1 + np.square(a), [1 + np.square(1), 1 + np.square(2), 1 + np.square(3), 1 + np.square(4)], float)
assert eq(1 + np.cbrt(a), [1 + np.cbrt(1), 1 + np.cbrt(2), 1 + np.cbrt(3), 1 + np.cbrt(4)], float)
assert eq(1 + np.logaddexp(a, 3), [1 + np.logaddexp(1, 3), 1 + np.logaddexp(2, 3), 1 + np.logaddexp(3, 3), 1 + np.logaddexp(4, 3)], float)
assert eq(1 + np.logaddexp(3, a), [1 + np.logaddexp(3, 1), 1 + np.logaddexp(3, 2), 1 + np.logaddexp(3, 3), 1 + np.logaddexp(3, 4)], float)
assert eq(1 + np.logaddexp2(a, 3), [1 + np.logaddexp2(1, 3), 1 + np.logaddexp2(2, 3), 1 + np.logaddexp2(3, 3), 1 + np.logaddexp2(4, 3)], float)
assert eq(1 + np.logaddexp2(3, a), [1 + np.logaddexp2(3, 1), 1 + np.logaddexp2(3, 2), 1 + np.logaddexp2(3, 3), 1 + np.logaddexp2(3, 4)], float)
assert eq(1 + np.reciprocal(a), [2., 1.5, 1 + 1/3, 1.25], float)
assert eq(1 + np.rint(a + .1), [1 + np.rint(1.1), 1 + np.rint(2.1), 1 + np.rint(3.1), 1 + np.rint(4.1)], float)
assert eq(1 + np.floor(a + .1), [1 + np.floor(1.1), 1 + np.floor(2.1), 1 + np.floor(3.1), 1 + np.floor(4.1)], float)
assert eq(1 + np.ceil(a + .1), [1 + np.ceil(1.1), 1 + np.ceil(2.1), 1 + np.ceil(3.1), 1 + np.ceil(4.1)], float)
assert eq(1 + np.trunc(a + .1), [1 + np.trunc(1.1), 1 + np.trunc(2.1), 1 + np.trunc(3.1), 1 + np.trunc(4.1)], float)
assert eq(1 + np.isnan(a), [1, 1, 1, 1], int)
assert eq(1 + np.isinf(a), [1, 1, 1, 1], int)
assert eq(1 + np.isfinite(a), [2, 2, 2, 2], int)
assert eq(1 + np.ldexp(a, 1), [1 + np.ldexp(1, 1), 1 + np.ldexp(2, 1), 1 + np.ldexp(3, 1), 1 + np.ldexp(4, 1)], float)
assert eq(1 + np.sign(a), [2, 2, 2, 2], float)
assert eq(1 + np.signbit(a), [1, 1, 1, 1], int)
assert eq(1 + np.copysign(a, -1), [1 + np.copysign(1, -1), 1 + np.copysign(2, -1), 1 + np.copysign(3, -1), 1 + np.copysign(4, -1)], float)
assert eq(1 + np.copysign(-1, a), [1 + np.copysign(-1, 1), 1 + np.copysign(-1, 2), 1 + np.copysign(-1, 3), 1 + np.copysign(-1, 4)], float)
assert eq(1 + np.spacing(a), [1 + np.spacing(1), 1 + np.spacing(2), 1 + np.spacing(3), 1 + np.spacing(4)], float)
assert eq(1 + np.nextafter(a, 1), [1 + np.nextafter(1, 1), 1 + np.nextafter(2, 1), 1 + np.nextafter(3, 1), 1 + np.nextafter(4, 1)], float)
assert eq(1 + np.nextafter(1, a), [1 + np.nextafter(1, 1), 1 + np.nextafter(1, 2), 1 + np.nextafter(1, 3), 1 + np.nextafter(1, 4)], float)
assert eq(1 + np.deg2rad(a), [1 + np.deg2rad(1), 1 + np.deg2rad(2), 1 + np.deg2rad(3), 1 + np.deg2rad(4)], float)
assert eq(1 + np.rad2deg(a), [1 + np.rad2deg(1), 1 + np.rad2deg(2), 1 + np.rad2deg(3), 1 + np.rad2deg(4)], float)
assert eq(1 + np.heaviside(a, 1), [1 + np.heaviside(1, 1), 1 + np.heaviside(2, 1), 1 + np.heaviside(3, 1), 1 + np.heaviside(4, 1)], float)
assert eq(1 + np.heaviside(1, a), [1 + np.heaviside(1, 1), 1 + np.heaviside(1, 2), 1 + np.heaviside(1, 3), 1 + np.heaviside(1, 4)], float)
@test
def test_ops_float32():
a = np.array([1., 2., 3., 4.], np.float32)
assert eq(1 + (+a), [2, 3, 4, 5], np.float32)
assert eq(1 + (-a), [0, -1, -2, -3], np.float32)
assert eq(1 + np.abs(a), [2, 3, 4, 5], np.float32)
assert eq(1 + abs(a), [2, 3, 4, 5], np.float32)
assert eq(2 * (1 + a), [4, 6, 8, 10], np.float32)
assert eq(2 * (a + 1), [4, 6, 8, 10], np.float32)
assert eq(2 * (a - 1), [0, 2, 4, 6], np.float32)
assert eq(2 * (1 - a), [0, -2, -4, -6], np.float32)
assert eq(1 + (a * 2), [3, 5, 7, 9], np.float32)
assert eq(1 + (2 * a), [3, 5, 7, 9], np.float32)
assert eq(1 + (a.reshape(1, -1) @ a.reshape(-1, 1)), [[31]], np.float32)
assert eq(1 + (a / 2), [1.5, 2., 2.5, 3.], np.float32)
assert eq(1 + (2 / a), [3., 2., 1 + 2/3, 1.5], np.float32)
assert eq(1 + (a // 2), [1, 2, 2, 3], np.float32)
assert eq(1 + (10 // a), [11, 6, 4, 3], np.float32)
assert eq(1 + (a % 3), [2, 3, 1, 2], np.float32)
assert eq(1 + (10 % a), [1, 1, 2, 3], np.float32)
assert eq(1 + np.fmod(a, 3), [2, 3, 1, 2], np.float32)
assert eq(1 + np.fmod(10, a), [1, 1, 2, 3], np.float32)
assert eq(1 + (a ** 3), [2, 9, 28, 65], np.float32)
assert eq(1 + (3 ** a), [4, 10, 28, 82], np.float32)
assert eq(np.logical_and(a, a - 1), [False, True, True, True], bool)
assert eq(np.logical_or(a, a - 1), [True, True, True, True], bool)
assert eq(np.logical_xor(a, a % 2), [False, True, False, True], bool)
assert eq((a + 1) == 2, [True, False, False, False], bool)
assert eq(2 == (a + 1), [True, False, False, False], bool)
assert eq((a + 1) != 2, [False, True, True, True], bool)
assert eq(2 != (a + 1), [False, True, True, True], bool)
assert eq((a + 1) < 3, [True, False, False, False], bool)
assert eq(3 < (a + 1), [False, False, True, True], bool)
assert eq((a + 1) > 3, [False, False, True, True], bool)
assert eq(3 > (a + 1), [True, False, False, False], bool)
assert eq((a + 1) <= 3, [True, True, False, False], bool)
assert eq(3 <= (a + 1), [False, True, True, True], bool)
assert eq((a + 1) >= 3, [False, True, True, True], bool)
assert eq(3 >= (a + 1), [True, True, False, False], bool)
assert eq(1 + np.minimum(a, 3), [2, 3, 4, 4], np.float32)
assert eq(1 + np.minimum(3, a), [2, 3, 4, 4], np.float32)
assert eq(1 + np.maximum(a, 3), [4, 4, 4, 5], np.float32)
assert eq(1 + np.maximum(3, a), [4, 4, 4, 5], np.float32)
assert eq(1 + np.fmin(a, 3), [2, 3, 4, 4], np.float32)
assert eq(1 + np.fmin(3, a), [2, 3, 4, 4], np.float32)
assert eq(1 + np.fmax(a, 3), [4, 4, 4, 5], np.float32)
assert eq(1 + np.fmax(3, a), [4, 4, 4, 5], np.float32)
assert eq(1 + np.minimum(a, np.nan), [np.nan, np.nan, np.nan, np.nan], np.float32)
assert eq(1 + np.minimum(np.nan, a), [np.nan, np.nan, np.nan, np.nan], np.float32)
assert eq(1 + np.maximum(a, np.nan), [np.nan, np.nan, np.nan, np.nan], np.float32)
assert eq(1 + np.maximum(np.nan, a), [np.nan, np.nan, np.nan, np.nan], np.float32)
assert eq(1 + np.fmin(a, np.nan), [2, 3, 4, 5], np.float32)
assert eq(1 + np.fmin(np.nan, a), [2, 3, 4, 5], np.float32)
assert eq(1 + np.fmax(a, np.nan), [2, 3, 4, 5], np.float32)
assert eq(1 + np.fmax(np.nan, a), [2, 3, 4, 5], np.float32)
assert eq(1 + np.sin(a), [1.f32 + np.sin(1.f32), 1.f32 + np.sin(2.f32), 1.f32 + np.sin(3.f32), 1.f32 + np.sin(4.f32)], np.float32)
assert eq(1 + np.cos(a), [1.f32 + np.cos(1.f32), 1.f32 + np.cos(2.f32), 1.f32 + np.cos(3.f32), 1.f32 + np.cos(4.f32)], np.float32)
assert eq(1 + np.tan(a), [1.f32 + np.tan(1.f32), 1.f32 + np.tan(2.f32), 1.f32 + np.tan(3.f32), 1.f32 + np.tan(4.f32)], np.float32)
assert eq(1 + np.arcsin(a), [1.f32 + np.arcsin(1.f32), 1.f32 + np.arcsin(2.f32), 1.f32 + np.arcsin(3.f32), 1.f32 + np.arcsin(4.f32)], np.float32)
assert eq(1 + np.arccos(a), [1.f32 + np.arccos(1.f32), 1.f32 + np.arccos(2.f32), 1.f32 + np.arccos(3.f32), 1.f32 + np.arccos(4.f32)], np.float32)
assert eq(1 + np.arctan(a), [1.f32 + np.arctan(1.f32), 1.f32 + np.arctan(2.f32), 1.f32 + np.arctan(3.f32), 1.f32 + np.arctan(4.f32)], np.float32)
assert eq(1 + np.arctan2(a, 3.f32), [1.f32 + np.arctan2(1.f32, 3.f32), 1.f32 + np.arctan2(2.f32, 3.f32), 1.f32 + np.arctan2(3.f32, 3.f32), 1.f32 + np.arctan2(4.f32, 3.f32)], np.float32)
assert eq(1 + np.arctan2(3.f32, a), [1.f32 + np.arctan2(3.f32, 1.f32), 1.f32 + np.arctan2(3.f32, 2.f32), 1.f32 + np.arctan2(3.f32, 3.f32), 1.f32 + np.arctan2(3.f32, 4.f32)], np.float32)
assert eq(1 + np.hypot(a, 3), [1.f32 + np.hypot(1.f32, 3.f32), 1.f32 + np.hypot(2.f32, 3.f32), 1.f32 + np.hypot(3.f32, 3.f32), 1.f32 + np.hypot(4.f32, 3.f32)], np.float32)
assert eq(1 + np.hypot(3, a), [1.f32 + np.hypot(3.f32, 1.f32), 1.f32 + np.hypot(3.f32, 2.f32), 1.f32 + np.hypot(3.f32, 3.f32), 1.f32 + np.hypot(3.f32, 4.f32)], np.float32)
assert eq(1 + np.sinh(a), [1.f32 + np.sinh(1.f32), 1.f32 + np.sinh(2.f32), 1.f32 + np.sinh(3.f32), 1.f32 + np.sinh(4.f32)], np.float32)
assert eq(1 + np.cosh(a), [1.f32 + np.cosh(1.f32), 1.f32 + np.cosh(2.f32), 1.f32 + np.cosh(3.f32), 1.f32 + np.cosh(4.f32)], np.float32)
assert eq(1 + np.tanh(a), [1.f32 + np.tanh(1.f32), 1.f32 + np.tanh(2.f32), 1.f32 + np.tanh(3.f32), 1.f32 + np.tanh(4.f32)], np.float32)
assert eq(1 + np.arcsinh(a), [1.f32 + np.arcsinh(1.f32), 1.f32 + np.arcsinh(2.f32), 1.f32 + np.arcsinh(3.f32), 1.f32 + np.arcsinh(4.f32)], np.float32)
assert eq(1 + np.arccosh(a), [1.f32 + np.arccosh(1.f32), 1.f32 + np.arccosh(2.f32), 1.f32 + np.arccosh(3.f32), 1.f32 + np.arccosh(4.f32)], np.float32)
assert eq(1 + np.arctanh(a), [1.f32 + np.arctanh(1.f32), 1.f32 + np.arctanh(2.f32), 1.f32 + np.arctanh(3.f32), 1.f32 + np.arctanh(4.f32)], np.float32)
assert eq(1 + np.conj(a), [1 + np.conj(1), 1 + np.conj(2), 1 + np.conj(3), 1 + np.conj(4)], np.float32)
assert eq(1 + np.exp(a), [1.f32 + np.exp(1.f32), 1.f32 + np.exp(2.f32), 1.f32 + np.exp(3.f32), 1.f32 + np.exp(4.f32)], np.float32)
assert eq(1 + np.exp2(a), [1.f32 + np.exp2(1.f32), 1.f32 + np.exp2(2.f32), 1.f32 + np.exp2(3.f32), 1.f32 + np.exp2(4.f32)], np.float32)
assert eq(1 + np.log(a), [1.f32 + np.log(1.f32), 1.f32 + np.log(2.f32), 1.f32 + np.log(3.f32), 1.f32 + np.log(4.f32)], np.float32)
assert eq(1 + np.log2(a), [1.f32 + np.log2(1.f32), 1.f32 + np.log2(2.f32), 1.f32 + np.log2(3.f32), 1.f32 + np.log2(4.f32)], np.float32)
assert eq(1 + np.log10(a), [1.f32 + np.log10(1.f32), 1.f32 + np.log10(2.f32), 1.f32 + np.log10(3.f32), 1.f32 + np.log10(4.f32)], np.float32)
assert eq(1 + np.expm1(a), [1.f32 + np.expm1(1.f32), 1.f32 + np.expm1(2.f32), 1.f32 + np.expm1(3.f32), 1.f32 + np.expm1(4.f32)], np.float32)
assert eq(1 + np.log1p(a), [1.f32 + np.log1p(1.f32), 1.f32 + np.log1p(2.f32), 1.f32 + np.log1p(3.f32), 1.f32 + np.log1p(4.f32)], np.float32)
assert eq(1 + np.sqrt(a), [1.f32 + np.sqrt(1.f32), 1.f32 + np.sqrt(2.f32), 1.f32 + np.sqrt(3.f32), 1.f32 + np.sqrt(4.f32)], np.float32)
assert eq(1 + np.square(a), [1 + np.square(1), 1 + np.square(2), 1 + np.square(3), 1 + np.square(4)], np.float32)
assert eq(1 + np.cbrt(a), [1.f32 + np.cbrt(1.f32), 1.f32 + np.cbrt(2.f32), 1.f32 + np.cbrt(3.f32), 1.f32 + np.cbrt(4.f32)], np.float32)
assert eq(1 + np.logaddexp(a, 3), [1.f32 + np.logaddexp(1.f32, 3.f32), 1.f32 + np.logaddexp(2.f32, 3.f32), 1.f32 + np.logaddexp(3.f32, 3.f32), 1.f32 + np.logaddexp(4.f32, 3.f32)], np.float32)
assert eq(1 + np.logaddexp(3, a), [1.f32 + np.logaddexp(3.f32, 1.f32), 1.f32 + np.logaddexp(3.f32, 2.f32), 1.f32 + np.logaddexp(3.f32, 3.f32), 1.f32 + np.logaddexp(3.f32, 4.f32)], np.float32)
assert eq(1 + np.logaddexp2(a, 3), [1.f32 + np.logaddexp2(1.f32, 3.f32), 1.f32 + np.logaddexp2(2.f32, 3.f32), 1.f32 + np.logaddexp2(3.f32, 3.f32), 1.f32 + np.logaddexp2(4.f32, 3.f32)], np.float32)
assert eq(1 + np.logaddexp2(3, a), [1.f32 + np.logaddexp2(3.f32, 1.f32), 1.f32 + np.logaddexp2(3.f32, 2.f32), 1.f32 + np.logaddexp2(3.f32, 3.f32), 1.f32 + np.logaddexp2(3.f32, 4.f32)], np.float32)
assert eq(1 + np.reciprocal(a), [2., 1.5, 1 + 1/3, 1.25], np.float32)
assert eq(1 + np.rint(a), [1.f32 + np.rint(1.f32), 1.f32 + np.rint(2.f32), 1.f32 + np.rint(3.f32), 1.f32 + np.rint(4.f32)], np.float32)
assert eq(1 + np.floor(a), [1.f32 + np.floor(1.f32), 1.f32 + np.floor(2.f32), 1.f32 + np.floor(3.f32), 1.f32 + np.floor(4.f32)], np.float32)
assert eq(1 + np.ceil(a), [1.f32 + np.ceil(1.f32), 1.f32 + np.ceil(2.f32), 1.f32 + np.ceil(3.f32), 1.f32 + np.ceil(4.f32)], np.float32)
assert eq(1 + np.trunc(a), [1.f32 + np.trunc(1.f32), 1.f32 + np.trunc(2.f32), 1.f32 + np.trunc(3.f32), 1.f32 + np.trunc(4.f32)], np.float32)
assert eq(1 + np.isnan(a), [1, 1, 1, 1], int)
assert eq(1 + np.isinf(a), [1, 1, 1, 1], int)
assert eq(1 + np.isfinite(a), [2, 2, 2, 2], int)
assert eq(1 + np.ldexp(a, 1), [1.f32 + np.ldexp(1.f32, 1), 1.f32 + np.ldexp(2.f32, 1), 1.f32 + np.ldexp(3.f32, 1), 1.f32 + np.ldexp(4.f32, 1)], np.float32)
assert eq(1 + np.sign(a), [2, 2, 2, 2], np.float32)
assert eq(1 + np.signbit(a), [1, 1, 1, 1], int)
assert eq(1 + np.copysign(a, -1), [1.f32 + np.copysign(1.f32, -1.f32), 1.f32 + np.copysign(2.f32, -1.f32), 1.f32 + np.copysign(3.f32, -1.f32), 1.f32 + np.copysign(4.f32, -1.f32)], np.float32)
assert eq(1 + np.copysign(-1, a), [1.f32 + np.copysign(-1.f32, 1.f32), 1.f32 + np.copysign(-1.f32, 2.f32), 1.f32 + np.copysign(-1.f32, 3.f32), 1.f32 + np.copysign(-1.f32, 4.f32)], np.float32)
assert eq(1 + np.spacing(a), [1.f32 + np.spacing(1.f32), 1.f32 + np.spacing(2.f32), 1.f32 + np.spacing(3.f32), 1.f32 + np.spacing(4.f32)], np.float32)
assert eq(1 + np.nextafter(a, 1), [1.f32 + np.nextafter(1.f32, 1.f32), 1.f32 + np.nextafter(2.f32, 1.f32), 1.f32 + np.nextafter(3.f32, 1.f32), 1.f32 + np.nextafter(4.f32, 1.f32)], np.float32)
assert eq(1 + np.nextafter(1, a), [1.f32 + np.nextafter(1.f32, 1.f32), 1.f32 + np.nextafter(1.f32, 2.f32), 1.f32 + np.nextafter(1.f32, 3.f32), 1.f32 + np.nextafter(1.f32, 4.f32)], np.float32)
assert eq(1 + np.deg2rad(a), [1.f32 + np.deg2rad(1.f32), 1.f32 + np.deg2rad(2.f32), 1.f32 + np.deg2rad(3.f32), 1.f32 + np.deg2rad(4.f32)], np.float32)
assert eq(1 + np.rad2deg(a), [1.f32 + np.rad2deg(1.f32), 1.f32 + np.rad2deg(2.f32), 1.f32 + np.rad2deg(3.f32), 1.f32 + np.rad2deg(4.f32)], np.float32)
assert eq(1 + np.heaviside(a, 1), [1.f32 + np.heaviside(1.f32, 1.f32), 1.f32 + np.heaviside(2.f32, 1.f32), 1.f32 + np.heaviside(3.f32, 1.f32), 1.f32 + np.heaviside(4.f32, 1.f32)], np.float32)
assert eq(1 + np.heaviside(1, a), [1.f32 + np.heaviside(1.f32, 1.f32), 1.f32 + np.heaviside(1.f32, 2.f32), 1.f32 + np.heaviside(1.f32, 3.f32), 1.f32 + np.heaviside(1.f32, 4.f32)], np.float32)
@test
def test_ops_float16():
a = np.array([1., 2., 3., 4.], np.float16)
assert eq(1 + (+a), [2, 3, 4, 5], np.float16)
assert eq(1 + (-a), [0, -1, -2, -3], np.float16)
assert eq(1 + np.abs(a), [2, 3, 4, 5], np.float16)
assert eq(1 + abs(a), [2, 3, 4, 5], np.float16)
assert eq(2 * (1 + a), [4, 6, 8, 10], np.float16)
assert eq(2 * (a + 1), [4, 6, 8, 10], np.float16)
assert eq(2 * (a - 1), [0, 2, 4, 6], np.float16)
assert eq(2 * (1 - a), [0, -2, -4, -6], np.float16)
assert eq(1 + (a * 2), [3, 5, 7, 9], np.float16)
assert eq(1 + (2 * a), [3, 5, 7, 9], np.float16)
assert eq(1 + (a.reshape(1, -1) @ a.reshape(-1, 1)), [[31]], np.float16)
assert eq(1 + (a / 2), [1.5, 2., 2.5, 3.], np.float16)
assert eq(1 + (2 / a), [3.f16, 2.f16, 1.f16 + 2.f16/3.f16, 1.5f16], np.float16)
assert eq(1 + (a // 2), [1, 2, 2, 3], np.float16)
assert eq(1 + (10 // a), [11, 6, 4, 3], np.float16)
assert eq(1 + (a % 3), [2, 3, 1, 2], np.float16)
assert eq(1 + (10 % a), [1, 1, 2, 3], np.float16)
assert eq(1 + np.fmod(a, 3), [2, 3, 1, 2], np.float16)
assert eq(1 + np.fmod(10, a), [1, 1, 2, 3], np.float16)
assert eq(1 + (a ** 3), [2, 9, 28, 65], np.float16)
assert eq(1 + (3 ** a), [4, 10, 28, 82], np.float16)
assert eq(np.logical_and(a, a - 1), [False, True, True, True], bool)
assert eq(np.logical_or(a, a - 1), [True, True, True, True], bool)
assert eq(np.logical_xor(a, a % 2), [False, True, False, True], bool)
assert eq((a + 1) == 2, [True, False, False, False], bool)
assert eq(2 == (a + 1), [True, False, False, False], bool)
assert eq((a + 1) != 2, [False, True, True, True], bool)
assert eq(2 != (a + 1), [False, True, True, True], bool)
assert eq((a + 1) < 3, [True, False, False, False], bool)
assert eq(3 < (a + 1), [False, False, True, True], bool)
assert eq((a + 1) > 3, [False, False, True, True], bool)
assert eq(3 > (a + 1), [True, False, False, False], bool)
assert eq((a + 1) <= 3, [True, True, False, False], bool)
assert eq(3 <= (a + 1), [False, True, True, True], bool)
assert eq((a + 1) >= 3, [False, True, True, True], bool)
assert eq(3 >= (a + 1), [True, True, False, False], bool)
assert eq(1 + np.minimum(a, 3), [2, 3, 4, 4], np.float16)
assert eq(1 + np.minimum(3, a), [2, 3, 4, 4], np.float16)
assert eq(1 + np.maximum(a, 3), [4, 4, 4, 5], np.float16)
assert eq(1 + np.maximum(3, a), [4, 4, 4, 5], np.float16)
assert eq(1 + np.fmin(a, 3), [2, 3, 4, 4], np.float16)
assert eq(1 + np.fmin(3, a), [2, 3, 4, 4], np.float16)
assert eq(1 + np.fmax(a, 3), [4, 4, 4, 5], np.float16)
assert eq(1 + np.fmax(3, a), [4, 4, 4, 5], np.float16)
assert eq(1 + np.minimum(a, np.nan), [np.nan, np.nan, np.nan, np.nan], np.float16)
assert eq(1 + np.minimum(np.nan, a), [np.nan, np.nan, np.nan, np.nan], np.float16)
assert eq(1 + np.maximum(a, np.nan), [np.nan, np.nan, np.nan, np.nan], np.float16)
assert eq(1 + np.maximum(np.nan, a), [np.nan, np.nan, np.nan, np.nan], np.float16)
assert eq(1 + np.fmin(a, np.nan), [2, 3, 4, 5], np.float16)
assert eq(1 + np.fmin(np.nan, a), [2, 3, 4, 5], np.float16)
assert eq(1 + np.fmax(a, np.nan), [2, 3, 4, 5], np.float16)
assert eq(1 + np.fmax(np.nan, a), [2, 3, 4, 5], np.float16)
assert eq(1 + np.sin(a), [1.f16 + np.sin(1.f16), 1.f16 + np.sin(2.f16), 1.f16 + np.sin(3.f16), 1.f16 + np.sin(4.f16)], np.float16)
assert eq(1 + np.cos(a), [1.f16 + np.cos(1.f16), 1.f16 + np.cos(2.f16), 1.f16 + np.cos(3.f16), 1.f16 + np.cos(4.f16)], np.float16)
assert eq(1 + np.tan(a), [1.f16 + np.tan(1.f16), 1.f16 + np.tan(2.f16), 1.f16 + np.tan(3.f16), 1.f16 + np.tan(4.f16)], np.float16)
assert eq(1 + np.arcsin(a), [1.f16 + np.arcsin(1.f16), 1.f16 + np.arcsin(2.f16), 1.f16 + np.arcsin(3.f16), 1.f16 + np.arcsin(4.f16)], np.float16)
assert eq(1 + np.arccos(a), [1.f16 + np.arccos(1.f16), 1.f16 + np.arccos(2.f16), 1.f16 + np.arccos(3.f16), 1.f16 + np.arccos(4.f16)], np.float16)
assert eq(1 + np.arctan(a), [1.f16 + np.arctan(1.f16), 1.f16 + np.arctan(2.f16), 1.f16 + np.arctan(3.f16), 1.f16 + np.arctan(4.f16)], np.float16)
assert eq(1 + np.arctan2(a, 3.f16), [1.f16 + np.arctan2(1.f16, 3.f16), 1.f16 + np.arctan2(2.f16, 3.f16), 1.f16 + np.arctan2(3.f16, 3.f16), 1.f16 + np.arctan2(4.f16, 3.f16)], np.float16)
assert eq(1 + np.arctan2(3.f16, a), [1.f16 + np.arctan2(3.f16, 1.f16), 1.f16 + np.arctan2(3.f16, 2.f16), 1.f16 + np.arctan2(3.f16, 3.f16), 1.f16 + np.arctan2(3.f16, 4.f16)], np.float16)
assert eq(1 + np.hypot(a, 3), [1.f16 + np.hypot(1.f16, 3.f16), 1.f16 + np.hypot(2.f16, 3.f16), 1.f16 + np.hypot(3.f16, 3.f16), 1.f16 + np.hypot(4.f16, 3.f16)], np.float16)
assert eq(1 + np.hypot(3, a), [1.f16 + np.hypot(3.f16, 1.f16), 1.f16 + np.hypot(3.f16, 2.f16), 1.f16 + np.hypot(3.f16, 3.f16), 1.f16 + np.hypot(3.f16, 4.f16)], np.float16)
assert eq(1 + np.sinh(a), [1.f16 + np.sinh(1.f16), 1.f16 + np.sinh(2.f16), 1.f16 + np.sinh(3.f16), 1.f16 + np.sinh(4.f16)], np.float16)
assert eq(1 + np.cosh(a), [1.f16 + np.cosh(1.f16), 1.f16 + np.cosh(2.f16), 1.f16 + np.cosh(3.f16), 1.f16 + np.cosh(4.f16)], np.float16)
assert eq(1 + np.tanh(a), [1.f16 + np.tanh(1.f16), 1.f16 + np.tanh(2.f16), 1.f16 + np.tanh(3.f16), 1.f16 + np.tanh(4.f16)], np.float16)
assert eq(1 + np.arcsinh(a), [1.f16 + np.arcsinh(1.f16), 1.f16 + np.arcsinh(2.f16), 1.f16 + np.arcsinh(3.f16), 1.f16 + np.arcsinh(4.f16)], np.float16)
assert eq(1 + np.arccosh(a), [1.f16 + np.arccosh(1.f16), 1.f16 + np.arccosh(2.f16), 1.f16 + np.arccosh(3.f16), 1.f16 + np.arccosh(4.f16)], np.float16)
assert eq(1 + np.arctanh(a), [1.f16 + np.arctanh(1.f16), 1.f16 + np.arctanh(2.f16), 1.f16 + np.arctanh(3.f16), 1.f16 + np.arctanh(4.f16)], np.float16)
assert eq(1 + np.conj(a), [1 + np.conj(1), 1 + np.conj(2), 1 + np.conj(3), 1 + np.conj(4)], np.float16)
assert eq(1 + np.exp(a), [1.f16 + np.exp(1.f16), 1.f16 + np.exp(2.f16), 1.f16 + np.exp(3.f16), 1.f16 + np.exp(4.f16)], np.float16)
assert eq(1 + np.exp2(a), [1.f16 + np.exp2(1.f16), 1.f16 + np.exp2(2.f16), 1.f16 + np.exp2(3.f16), 1.f16 + np.exp2(4.f16)], np.float16)
assert eq(1 + np.log(a), [1.f16 + np.log(1.f16), 1.f16 + np.log(2.f16), 1.f16 + np.log(3.f16), 1.f16 + np.log(4.f16)], np.float16)
assert eq(1 + np.log2(a), [1.f16 + np.log2(1.f16), 1.f16 + np.log2(2.f16), 1.f16 + np.log2(3.f16), 1.f16 + np.log2(4.f16)], np.float16)
assert eq(1 + np.log10(a), [1.f16 + np.log10(1.f16), 1.f16 + np.log10(2.f16), 1.f16 + np.log10(3.f16), 1.f16 + np.log10(4.f16)], np.float16)
assert eq(1 + np.expm1(a), [1.f16 + np.expm1(1.f16), 1.f16 + np.expm1(2.f16), 1.f16 + np.expm1(3.f16), 1.f16 + np.expm1(4.f16)], np.float16)
assert eq(1 + np.log1p(a), [1.f16 + np.log1p(1.f16), 1.f16 + np.log1p(2.f16), 1.f16 + np.log1p(3.f16), 1.f16 + np.log1p(4.f16)], np.float16)
assert eq(1 + np.sqrt(a), [1.f16 + np.sqrt(1.f16), 1.f16 + np.sqrt(2.f16), 1.f16 + np.sqrt(3.f16), 1.f16 + np.sqrt(4.f16)], np.float16)
assert eq(1 + np.square(a), [1 + np.square(1), 1 + np.square(2), 1 + np.square(3), 1 + np.square(4)], np.float16)
assert eq(1 + np.cbrt(a), [1.f16 + np.cbrt(1.f16), 1.f16 + np.cbrt(2.f16), 1.f16 + np.cbrt(3.f16), 1.f16 + np.cbrt(4.f16)], np.float16)
assert eq(1 + np.logaddexp(a, 3), [1.f16 + np.logaddexp(1.f16, 3.f16), 1.f16 + np.logaddexp(2.f16, 3.f16), 1.f16 + np.logaddexp(3.f16, 3.f16), 1.f16 + np.logaddexp(4.f16, 3.f16)], np.float16)
assert eq(1 + np.logaddexp(3, a), [1.f16 + np.logaddexp(3.f16, 1.f16), 1.f16 + np.logaddexp(3.f16, 2.f16), 1.f16 + np.logaddexp(3.f16, 3.f16), 1.f16 + np.logaddexp(3.f16, 4.f16)], np.float16)
assert eq(1 + np.logaddexp2(a, 3), [1.f16 + np.logaddexp2(1.f16, 3.f16), 1.f16 + np.logaddexp2(2.f16, 3.f16), 1.f16 + np.logaddexp2(3.f16, 3.f16), 1.f16 + np.logaddexp2(4.f16, 3.f16)], np.float16)
assert eq(1 + np.logaddexp2(3, a), [1.f16 + np.logaddexp2(3.f16, 1.f16), 1.f16 + np.logaddexp2(3.f16, 2.f16), 1.f16 + np.logaddexp2(3.f16, 3.f16), 1.f16 + np.logaddexp2(3.f16, 4.f16)], np.float16)
assert eq(1 + np.reciprocal(a), [2., 1.5, 1 + 1/3, 1.25], np.float16)
assert eq(1 + np.rint(a), [1.f16 + np.rint(1.f16), 1.f16 + np.rint(2.f16), 1.f16 + np.rint(3.f16), 1.f16 + np.rint(4.f16)], np.float16)
assert eq(1 + np.floor(a), [1.f16 + np.floor(1.f16), 1.f16 + np.floor(2.f16), 1.f16 + np.floor(3.f16), 1.f16 + np.floor(4.f16)], np.float16)
assert eq(1 + np.ceil(a), [1.f16 + np.ceil(1.f16), 1.f16 + np.ceil(2.f16), 1.f16 + np.ceil(3.f16), 1.f16 + np.ceil(4.f16)], np.float16)
assert eq(1 + np.trunc(a), [1.f16 + np.trunc(1.f16), 1.f16 + np.trunc(2.f16), 1.f16 + np.trunc(3.f16), 1.f16 + np.trunc(4.f16)], np.float16)
assert eq(1 + np.isnan(a), [1, 1, 1, 1], int)
assert eq(1 + np.isinf(a), [1, 1, 1, 1], int)
assert eq(1 + np.isfinite(a), [2, 2, 2, 2], int)
assert eq(1 + np.ldexp(a, 1), [1.f16 + np.ldexp(1.f16, 1), 1.f16 + np.ldexp(2.f16, 1), 1.f16 + np.ldexp(3.f16, 1), 1.f16 + np.ldexp(4.f16, 1)], np.float16)
assert eq(1 + np.sign(a), [2, 2, 2, 2], np.float16)
assert eq(1 + np.signbit(a), [1, 1, 1, 1], int)
assert eq(1 + np.copysign(a, -1), [1.f16 + np.copysign(1.f16, -1.f16), 1.f16 + np.copysign(2.f16, -1.f16), 1.f16 + np.copysign(3.f16, -1.f16), 1.f16 + np.copysign(4.f16, -1.f16)], np.float16)
assert eq(1 + np.copysign(-1, a), [1.f16 + np.copysign(-1.f16, 1.f16), 1.f16 + np.copysign(-1.f16, 2.f16), 1.f16 + np.copysign(-1.f16, 3.f16), 1.f16 + np.copysign(-1.f16, 4.f16)], np.float16)
assert eq(1 + np.spacing(a), [1.f16 + np.spacing(1.f16), 1.f16 + np.spacing(2.f16), 1.f16 + np.spacing(3.f16), 1.f16 + np.spacing(4.f16)], np.float16)
assert eq(1 + np.nextafter(a, 1), [1.f16 + np.nextafter(1.f16, 1.f16), 1.f16 + np.nextafter(2.f16, 1.f16), 1.f16 + np.nextafter(3.f16, 1.f16), 1.f16 + np.nextafter(4.f16, 1.f16)], np.float16)
assert eq(1 + np.nextafter(1, a), [1.f16 + np.nextafter(1.f16, 1.f16), 1.f16 + np.nextafter(1.f16, 2.f16), 1.f16 + np.nextafter(1.f16, 3.f16), 1.f16 + np.nextafter(1.f16, 4.f16)], np.float16)
assert eq(1 + np.deg2rad(a), [1.f16 + np.deg2rad(1.f16), 1.f16 + np.deg2rad(2.f16), 1.f16 + np.deg2rad(3.f16), 1.f16 + np.deg2rad(4.f16)], np.float16)
assert eq(1 + np.rad2deg(a), [1.f16 + np.rad2deg(1.f16), 1.f16 + np.rad2deg(2.f16), 1.f16 + np.rad2deg(3.f16), 1.f16 + np.rad2deg(4.f16)], np.float16)
assert eq(1 + np.heaviside(a, 1), [1.f16 + np.heaviside(1.f16, 1.f16), 1.f16 + np.heaviside(2.f16, 1.f16), 1.f16 + np.heaviside(3.f16, 1.f16), 1.f16 + np.heaviside(4.f16, 1.f16)], np.float16)
assert eq(1 + np.heaviside(1, a), [1.f16 + np.heaviside(1.f16, 1.f16), 1.f16 + np.heaviside(1.f16, 2.f16), 1.f16 + np.heaviside(1.f16, 3.f16), 1.f16 + np.heaviside(1.f16, 4.f16)], np.float16)
@test
def test_ops_complex128():
a = np.array([1., 2., 3., 4.], complex)
assert eq(1 + (+a), [2, 3, 4, 5], complex)
assert eq(1 + (-a), [0, -1, -2, -3], complex)
assert eq(1 + np.abs(a), [2, 3, 4, 5], float)
assert eq(1 + abs(a), [2, 3, 4, 5], float)
assert eq(2 * (1 + a), [4, 6, 8, 10], complex)
assert eq(2 * (a + 1), [4, 6, 8, 10], complex)
assert eq(2 * (a - 1), [0, 2, 4, 6], complex)
assert eq(2 * (1 - a), [0, -2, -4, -6], complex)
assert eq(1 + (a * 2), [3, 5, 7, 9], complex)
assert eq(1 + (2 * a), [3, 5, 7, 9], complex)
assert eq(1 + (a.reshape(1, -1) @ a.reshape(-1, 1)), [[31]], complex)
assert eq(1 + (a / 2), [1.5, 2., 2.5, 3.], complex)
assert eq(1 + (2 / a), [3., 2., 1 + 2/3, 1.5], complex)
assert eq(1 + (a ** 3), [2, 9, 28, 65], complex)
assert eq(1 + (3 ** a), [4, 10, 28, 82], complex)
assert eq(np.logical_and(a, a - 1), [False, True, True, True], bool)
assert eq(np.logical_or(a, a - 1), [True, True, True, True], bool)
assert eq(np.logical_xor(a, a - 1), [True, False, False, False], bool)
assert eq((a + 1) == 2, [True, False, False, False], bool)
assert eq(2 == (a + 1), [True, False, False, False], bool)
assert eq((a + 1) != 2, [False, True, True, True], bool)
assert eq(2 != (a + 1), [False, True, True, True], bool)
assert eq((a + 1) < 3, [True, False, False, False], bool)
assert eq(3 < (a + 1), [False, False, True, True], bool)
assert eq((a + 1) > 3, [False, False, True, True], bool)
assert eq(3 > (a + 1), [True, False, False, False], bool)
assert eq((a + 1) <= 3, [True, True, False, False], bool)
assert eq(3 <= (a + 1), [False, True, True, True], bool)
assert eq((a + 1) >= 3, [False, True, True, True], bool)
assert eq(3 >= (a + 1), [True, True, False, False], bool)
assert eq(1 + np.minimum(a, 3), [2, 3, 4, 4], complex)
assert eq(1 + np.minimum(3, a), [2, 3, 4, 4], complex)
assert eq(1 + np.maximum(a, 3), [4, 4, 4, 5], complex)
assert eq(1 + np.maximum(3, a), [4, 4, 4, 5], complex)
assert eq(1 + np.fmin(a, 3), [2, 3, 4, 4], complex)
assert eq(1 + np.fmin(3, a), [2, 3, 4, 4], complex)
assert eq(1 + np.fmax(a, 3), [4, 4, 4, 5], complex)
assert eq(1 + np.fmax(3, a), [4, 4, 4, 5], complex)
assert eq(1 + np.minimum(a, np.nan), [np.nan, np.nan, np.nan, np.nan], complex)
assert eq(1 + np.minimum(np.nan, a), [np.nan, np.nan, np.nan, np.nan], complex)
assert eq(1 + np.maximum(a, np.nan), [np.nan, np.nan, np.nan, np.nan], complex)
assert eq(1 + np.maximum(np.nan, a), [np.nan, np.nan, np.nan, np.nan], complex)
assert eq(1 + np.fmin(a, np.nan), [2, 3, 4, 5], complex)
assert eq(1 + np.fmin(np.nan, a), [2, 3, 4, 5], complex)
assert eq(1 + np.fmax(a, np.nan), [2, 3, 4, 5], complex)
assert eq(1 + np.fmax(np.nan, a), [2, 3, 4, 5], complex)
assert eq(1 + np.sin(a), [1 + np.sin(1+0j), 1 + np.sin(2+0j), 1 + np.sin(3+0j), 1 + np.sin(4+0j)], complex)
assert eq(1 + np.cos(a), [1 + np.cos(1+0j), 1 + np.cos(2+0j), 1 + np.cos(3+0j), 1 + np.cos(4+0j)], complex)
assert eq(1 + np.tan(a), [1 + np.tan(1+0j), 1 + np.tan(2+0j), 1 + np.tan(3+0j), 1 + np.tan(4+0j)], complex)
assert eq(1 + np.arcsin(a), [1 + np.arcsin(1+0j), 1 + np.arcsin(2+0j), 1 + np.arcsin(3+0j), 1 + np.arcsin(4+0j)], complex)
assert eq(1 + np.arccos(a), [1 + np.arccos(1+0j), 1 + np.arccos(2+0j), 1 + np.arccos(3+0j), 1 + np.arccos(4+0j)], complex)
assert eq(1 + np.arctan(a), [1 + np.arctan(1+0j), 1 + np.arctan(2+0j), 1 + np.arctan(3+0j), 1 + np.arctan(4+0j)], complex)
assert eq(1 + np.sinh(a), [1 + np.sinh(1+0j), 1 + np.sinh(2+0j), 1 + np.sinh(3+0j), 1 + np.sinh(4+0j)], complex)
assert eq(1 + np.cosh(a), [1 + np.cosh(1+0j), 1 + np.cosh(2+0j), 1 + np.cosh(3+0j), 1 + np.cosh(4+0j)], complex)
assert eq(1 + np.tanh(a), [1 + np.tanh(1+0j), 1 + np.tanh(2+0j), 1 + np.tanh(3+0j), 1 + np.tanh(4+0j)], complex)
assert eq(1 + np.arcsinh(a), [1 + np.arcsinh(1+0j), 1 + np.arcsinh(2+0j), 1 + np.arcsinh(3+0j), 1 + np.arcsinh(4+0j)], complex)
assert eq(1 + np.arccosh(a), [1 + np.arccosh(1+0j), 1 + np.arccosh(2+0j), 1 + np.arccosh(3+0j), 1 + np.arccosh(4+0j)], complex)
assert eq(1 + np.arctanh(a), [1 + np.arctanh(1+0j), 1 + np.arctanh(2+0j), 1 + np.arctanh(3+0j), 1 + np.arctanh(4+0j)], complex)
assert eq(1 + np.conj(a), [1 + np.conj(1), 1 + np.conj(2), 1 + np.conj(3), 1 + np.conj(4)], complex)
assert eq(1 + np.exp(a), [1 + np.exp(1), 1 + np.exp(2), 1 + np.exp(3), 1 + np.exp(4)], complex)
assert eq(1 + np.exp2(a), [1 + np.exp2(1), 1 + np.exp2(2), 1 + np.exp2(3), 1 + np.exp2(4)], complex)
assert eq(1 + np.log(a), [1 + np.log(1), 1 + np.log(2), 1 + np.log(3), 1 + np.log(4)], complex)
assert eq(1 + np.log2(a), [1 + np.log2(1), 1 + np.log2(2), 1 + np.log2(3), 1 + np.log2(4)], complex)
assert eq(1 + np.log10(a), [1 + np.log10(1), 1 + np.log10(2), 1 + np.log10(3), 1 + np.log10(4)], complex)
assert eq(1 + np.expm1(a), [1 + np.expm1(1), 1 + np.expm1(2), 1 + np.expm1(3), 1 + np.expm1(4)], complex)
assert eq(1 + np.log1p(a), [1 + np.log1p(1), 1 + np.log1p(2), 1 + np.log1p(3), 1 + np.log1p(4)], complex)
assert eq(1 + np.sqrt(a), [1 + np.sqrt(1), 1 + np.sqrt(2), 1 + np.sqrt(3), 1 + np.sqrt(4)], complex)
assert eq(1 + np.square(a), [1 + np.square(1), 1 + np.square(2), 1 + np.square(3), 1 + np.square(4)], complex)
assert eq(1 + np.reciprocal(a), [2., 1.5, 1 + 1/3, 1.25], complex)
assert eq(1 + np.isnan(a), [1, 1, 1, 1], int)
assert eq(1 + np.isinf(a), [1, 1, 1, 1], int)
assert eq(1 + np.isfinite(a), [2, 2, 2, 2], int)
assert eq(1 + np.sign(a), [2, 2, 2, 2], complex)
@test
def test_ops_complex64():
a = np.array([1., 2., 3., 4.], np.complex64)
assert eq(1 + (+a), [2, 3, 4, 5], np.complex64)
assert eq(1 + (-a), [0, -1, -2, -3], np.complex64)
assert eq(1 + np.abs(a), [2, 3, 4, 5], np.float32)
assert eq(1 + abs(a), [2, 3, 4, 5], np.float32)
assert eq(2 * (1 + a), [4, 6, 8, 10], np.complex64)
assert eq(2 * (a + 1), [4, 6, 8, 10], np.complex64)
assert eq(2 * (a - 1), [0, 2, 4, 6], np.complex64)
assert eq(2 * (1 - a), [0, -2, -4, -6], np.complex64)
assert eq(1 + (a * 2), [3, 5, 7, 9], np.complex64)
assert eq(1 + (2 * a), [3, 5, 7, 9], np.complex64)
assert eq(1 + (a.reshape(1, -1) @ a.reshape(-1, 1)), [[31]], np.complex64)
assert eq(1 + (a / 2), [1.5, 2., 2.5, 3.], np.complex64)
assert eq(1 + (2 / a), [3., 2., 1 + 2/3, 1.5], np.complex64)
assert eq(1 + (a ** 3), [2, 9, 28, 65], np.complex64)
assert eq(1 + (3 ** a), [4, 10, 28, 82], np.complex64)
assert eq(np.logical_and(a, a - 1), [False, True, True, True], bool)
assert eq(np.logical_or(a, a - 1), [True, True, True, True], bool)
assert eq(np.logical_xor(a, a - 1), [True, False, False, False], bool)
assert eq((a + 1) == 2, [True, False, False, False], bool)
assert eq(2 == (a + 1), [True, False, False, False], bool)
assert eq((a + 1) != 2, [False, True, True, True], bool)
assert eq(2 != (a + 1), [False, True, True, True], bool)
assert eq((a + 1) < 3, [True, False, False, False], bool)
assert eq(3 < (a + 1), [False, False, True, True], bool)
assert eq((a + 1) > 3, [False, False, True, True], bool)
assert eq(3 > (a + 1), [True, False, False, False], bool)
assert eq((a + 1) <= 3, [True, True, False, False], bool)
assert eq(3 <= (a + 1), [False, True, True, True], bool)
assert eq((a + 1) >= 3, [False, True, True, True], bool)
assert eq(3 >= (a + 1), [True, True, False, False], bool)
assert eq(1 + np.minimum(a, 3), [2, 3, 4, 4], np.complex64)
assert eq(1 + np.minimum(3, a), [2, 3, 4, 4], np.complex64)
assert eq(1 + np.maximum(a, 3), [4, 4, 4, 5], np.complex64)
assert eq(1 + np.maximum(3, a), [4, 4, 4, 5], np.complex64)
assert eq(1 + np.fmin(a, 3), [2, 3, 4, 4], np.complex64)
assert eq(1 + np.fmin(3, a), [2, 3, 4, 4], np.complex64)
assert eq(1 + np.fmax(a, 3), [4, 4, 4, 5], np.complex64)
assert eq(1 + np.fmax(3, a), [4, 4, 4, 5], np.complex64)
assert eq(1 + np.minimum(a, np.nan), [np.nan, np.nan, np.nan, np.nan], np.complex64)
assert eq(1 + np.minimum(np.nan, a), [np.nan, np.nan, np.nan, np.nan], np.complex64)
assert eq(1 + np.maximum(a, np.nan), [np.nan, np.nan, np.nan, np.nan], np.complex64)
assert eq(1 + np.maximum(np.nan, a), [np.nan, np.nan, np.nan, np.nan], np.complex64)
assert eq(1 + np.fmin(a, np.nan), [2, 3, 4, 5], np.complex64)
assert eq(1 + np.fmin(np.nan, a), [2, 3, 4, 5], np.complex64)
assert eq(1 + np.fmax(a, np.nan), [2, 3, 4, 5], np.complex64)
assert eq(1 + np.fmax(np.nan, a), [2, 3, 4, 5], np.complex64)
assert eq(1 + np.sin(a), [1 + np.sin(1+0j), 1 + np.sin(2+0j), 1 + np.sin(3+0j), 1 + np.sin(4+0j)], np.complex64)
assert eq(1 + np.cos(a), [1 + np.cos(1+0j), 1 + np.cos(2+0j), 1 + np.cos(3+0j), 1 + np.cos(4+0j)], np.complex64)
assert eq(1 + np.tan(a), [1 + np.tan(1+0j), 1 + np.tan(2+0j), 1 + np.tan(3+0j), 1 + np.tan(4+0j)], np.complex64)
assert eq(1 + np.arcsin(a), [1 + np.arcsin(1+0j), 1 + np.arcsin(2+0j), 1 + np.arcsin(3+0j), 1 + np.arcsin(4+0j)], np.complex64)
assert eq(1 + np.arccos(a), [1 + np.arccos(1+0j), 1 + np.arccos(2+0j), 1 + np.arccos(3+0j), 1 + np.arccos(4+0j)], np.complex64)
assert eq(1 + np.arctan(a), [1 + np.arctan(1+0j), 1 + np.arctan(2+0j), 1 + np.arctan(3+0j), 1 + np.arctan(4+0j)], np.complex64)
assert eq(1 + np.sinh(a), [1 + np.sinh(1+0j), 1 + np.sinh(2+0j), 1 + np.sinh(3+0j), 1 + np.sinh(4+0j)], np.complex64)
assert eq(1 + np.cosh(a), [1 + np.cosh(1+0j), 1 + np.cosh(2+0j), 1 + np.cosh(3+0j), 1 + np.cosh(4+0j)], np.complex64)
assert eq(1 + np.tanh(a), [1 + np.tanh(1+0j), 1 + np.tanh(2+0j), 1 + np.tanh(3+0j), 1 + np.tanh(4+0j)], np.complex64)
assert eq(1 + np.arcsinh(a), [1 + np.arcsinh(1+0j), 1 + np.arcsinh(2+0j), 1 + np.arcsinh(3+0j), 1 + np.arcsinh(4+0j)], np.complex64)
assert eq(1 + np.arccosh(a), [1 + np.arccosh(1+0j), 1 + np.arccosh(2+0j), 1 + np.arccosh(3+0j), 1 + np.arccosh(4+0j)], np.complex64)
# Note: it seems im(arctanh(complex64(1, 0))) == 0 on macOS
# assert eq(1 + np.arctanh(a), [1 + np.arctanh(1+0j), 1 + np.arctanh(2+0j), 1 + np.arctanh(3+0j), 1 + np.arctanh(4+0j)], np.complex64)
assert eq(1 + np.conj(a), [1 + np.conj(1), 1 + np.conj(2), 1 + np.conj(3), 1 + np.conj(4)], np.complex64)
assert eq(1 + np.exp(a), [1 + np.exp(1), 1 + np.exp(2), 1 + np.exp(3), 1 + np.exp(4)], np.complex64)
assert eq(1 + np.exp2(a), [1 + np.exp2(1), 1 + np.exp2(2), 1 + np.exp2(3), 1 + np.exp2(4)], np.complex64)
assert eq(1 + np.log(a), [1 + np.log(1), 1 + np.log(2), 1 + np.log(3), 1 + np.log(4)], np.complex64)
assert eq(1 + np.log2(a), [1 + np.log2(1), 1 + np.log2(2), 1 + np.log2(3), 1 + np.log2(4)], np.complex64)
assert eq(1 + np.log10(a), [1 + np.log10(1), 1 + np.log10(2), 1 + np.log10(3), 1 + np.log10(4)], np.complex64)
assert eq(1 + np.expm1(a), [1 + np.expm1(1), 1 + np.expm1(2), 1 + np.expm1(3), 1 + np.expm1(4)], np.complex64)
assert eq(1 + np.log1p(a), [1 + np.log1p(1), 1 + np.log1p(2), 1 + np.log1p(3), 1 + np.log1p(4)], np.complex64)
assert eq(1 + np.sqrt(a), [1 + np.sqrt(1), 1 + np.sqrt(2), 1 + np.sqrt(3), 1 + np.sqrt(4)], np.complex64)
assert eq(1 + np.square(a), [1 + np.square(1), 1 + np.square(2), 1 + np.square(3), 1 + np.square(4)], np.complex64)
assert eq(1 + np.reciprocal(a), [2., 1.5, 1 + 1/3, 1.25], np.complex64)
assert eq(1 + np.isnan(a), [1, 1, 1, 1], int)
assert eq(1 + np.isinf(a), [1, 1, 1, 1], int)
assert eq(1 + np.isfinite(a), [2, 2, 2, 2], int)
assert eq(1 + np.sign(a), [2, 2, 2, 2], np.complex64)
@test
def test_mixed_types():
i8 = np.array([1, 2, 3, 4], np.int8)
i16 = np.array([1, 2, 3, 4], np.int16)
i32 = np.array([1, 2, 3, 4], np.int32)
i64 = np.array([1, 2, 3, 4], np.int64)
u8 = np.array([1, 2, 3, 4], np.uint8)
u16 = np.array([1, 2, 3, 4], np.uint16)
u32 = np.array([1, 2, 3, 4], np.uint32)
u64 = np.array([1, 2, 3, 4], np.uint64)
f16 = np.array([1., 2., 3., 4.], np.float16)
f32 = np.array([1., 2., 3., 4.], np.float32)
f64 = np.array([1., 2., 3., 4.], np.float64)
c64 = np.array([1., 2., 3., 4.], np.complex64)
c128 = np.array([1., 2., 3., 4.], np.complex128)
assert eq(i8 + i16 + i32, [3, 6, 9, 12], np.int32)
assert eq(i16 + i32 + i64, [3, 6, 9, 12], np.int64)
assert eq(u8 + u16 + u32, [3, 6, 9, 12], np.uint32)
assert eq(i8 + u16 + i32, [3, 6, 9, 12], np.int32)
assert eq(i16 + u32 + i64, [3, 6, 9, 12], np.int64)
assert eq(u8 + i32 + u64, [3, 6, 9, 12], np.float64)
assert eq(i8 + u16 + u64, [3, 6, 9, 12], np.float64)
assert eq(i16 + i64 + u64, [3, 6, 9, 12], np.float64)
assert eq(i32 + u32 + i64, [3, 6, 9, 12], np.int64)
assert eq(u16 + i64 + u32, [3, 6, 9, 12], np.int64)
assert eq(f16 + f32 + f64, [3., 6., 9., 12.], np.float64)
assert eq(f16 + f32 + f16, [3., 6., 9., 12.], np.float32)
assert eq(f32 + f64 + f32, [3., 6., 9., 12.], np.float64)
assert eq(f64 + f16 + f32, [3., 6., 9., 12.], np.float64)
assert eq(f16 + f16 + f64, [3., 6., 9., 12.], np.float64)
assert eq(f32 + f32 + f16, [3., 6., 9., 12.], np.float32)
assert eq(f64 + f64 + f32, [3., 6., 9., 12.], np.float64)
assert eq(f16 + f64 + f64, [3., 6., 9., 12.], np.float64)
assert eq(f32 + f16 + f32, [3., 6., 9., 12.], np.float32)
assert eq(f64 + f32 + f64, [3., 6., 9., 12.], np.float64)
assert eq(i8 + i16 + f32, [3., 6., 9., 12.], np.float32)
assert eq(i32 + f32 + c64, [3.+0.j, 6.+0.j, 9.+0.j, 12.+0.j], np.complex128)
assert eq(f16 + u8 + u16, [3., 6., 9., 12.], np.float32)
assert eq(i64 + f64 + c128, [3.+0.j, 6.+0.j, 9+0.j, 12.+0.j], np.complex128)
assert eq(u16 + c64 + f32, [3.+0.j, 6.+0.j, 9.+0.j, 12.+0.j], np.complex64)
assert eq(f32 + c128 + i32, [3.+0.j, 6.+0.j, 9.+0.j, 12.+0.j], np.complex128)
assert eq(u32 + i16 + f64, [3., 6., 9., 12.], np.float64)
assert eq(i8 + u64 + f64, [3., 6., 9., 12.], np.float64)
assert eq(f64 + c64 + u16, [3.+0.j, 6.+0.j, 9.+0.j, 12.+0.j], np.complex128)
assert eq(c128 + i32 + u32, [3.+0.j, 6.+0.j, 9.+0.j, 12.+0.j], np.complex128)
assert eq(i8 + f16 + c64, [3.+0.j, 6.+0.j, 9.+0.j, 12.+0.j], np.complex64)
assert eq(u8 + i64 + c128, [3.+0.j, 6.+0.j, 9.+0.j, 12.+0.j], np.complex128)
assert eq(i16 + f32 + c64, [3.+0.j, 6.+0.j, 9.+0.j, 12.+0.j], np.complex64)
assert eq((i8 == i16) + c64, [2.+0j, 3.+0j, 4.+0j, 5.+0j], np.complex64)
assert eq(c64 + (i8 == i16), [2.+0j, 3.+0j, 4.+0j, 5.+0j], np.complex64)
assert eq((i8 + u8) + (i16 + u16) + (u32 + u32) + (i64 + u64) + f16 + f32 + f64 + c64 + c128,
[13.+0.j, 26.+0.j, 39.+0.j, 52.+0.j], np.complex128)
# Mixing scalars and arrays
assert eq((i8 + 100) << 1, [-54, -52, -50, -48], np.int8)
assert eq((i8 + np.array(100)) << 1, [202, 204, 206, 208], np.int64)
assert eq((100 + i8) << 1, [-54, -52, -50, -48], np.int8)
assert eq((np.array(100) + i8) << 1, [202, 204, 206, 208], np.int64)
assert eq((i32 + 1.5) * 2, [5., 7., 9., 11.], np.float64)
assert eq((i32 + np.array(1.5)) * 2, [5., 7., 9., 11.], np.float64)
assert eq((1.5 + i32) * 2, [5., 7., 9., 11.], np.float64)
assert eq((np.array(1.5) + i32) * 2, [5., 7., 9., 11.], np.float64)
assert eq((i32 + (1.5 + 0j)) * 2, [5., 7., 9., 11.], np.complex128)
assert eq((i32 + np.array(1.5 + 0j)) * 2, [5., 7., 9., 11.], np.complex128)
assert eq(((1.5 + 0j) + i32) * 2, [5., 7., 9., 11.], np.complex128)
assert eq((np.array(1.5 + 0j) + i32) * 2, [5., 7., 9., 11.], np.complex128)
# Complex -> Float conversions
z = np.array([1+1j, 2+2j, 3+3j])
assert eq(1 + abs(z), [2.41421356, 3.82842712, 5.24264069], np.float64)
assert eq(1 + np.abs(z), [2.41421356, 3.82842712, 5.24264069], np.float64)
z = np.array([1+1j, 2+2j, 3+3j], np.complex64)
assert eq(1 + abs(z), [2.41421356, 3.82842712, 5.24264069], np.float32)
assert eq(1 + np.abs(z), [2.41421356, 3.82842712, 5.24264069], np.float32)
@test
def test_div_mod():
xf64 = np.array([-4., -3., -2., -1., 0., 1., 2., 3., 4.], np.float64)
xf32 = np.array([-4., -3., -2., -1., 0., 1., 2., 3., 4.], np.float32)
xf16 = np.array([-4., -3., -2., -1., 0., 1., 2., 3., 4.], np.float16)
xi64 = np.array([-4, -3, -2, -1, 0, 1, 2, 3, 4], np.int64)
xi32 = np.array([-4, -3, -2, -1, 0, 1, 2, 3, 4], np.int32)
xi16 = np.array([-4, -3, -2, -1, 0, 1, 2, 3, 4], np.int16)
xi8 = np.array([-4, -3, -2, -1, 0, 1, 2, 3, 4], np.int8)
xu64 = np.array([0, 1, 2, 3, 4], np.uint64)
xu32 = np.array([0, 1, 2, 3, 4], np.uint32)
xu16 = np.array([0, 1, 2, 3, 4], np.uint16)
xu8 = np.array([0, 1, 2, 3, 4], np.uint8)
assert eq(xf64 % 1, [0., 0., 0., 0., 0., 0., 0., 0., 0.], np.float64)
assert eq(np.fmod(xf64, 1), [-0., -0., -0., -0., 0., 0., 0., 0., 0.],
np.float64)
assert eq(np.remainder(xf64, 1), [0., 0., 0., 0., 0., 0., 0., 0., 0.],
np.float64)
assert eq(xf64 % -1, [-0., -0., -0., -0., -0., -0., -0., -0., -0.], np.float64)
assert eq(np.fmod(xf64, -1), [-0., -0., -0., -0., 0., 0., 0., 0., 0.],
np.float64)
assert eq(np.remainder(xf64, -1),
[-0., -0., -0., -0., -0., -0., -0., -0., -0.], np.float64)
assert eq(xf64 % 2, [0., 1., 0., 1., 0., 1., 0., 1., 0.], np.float64)
assert eq(np.fmod(xf64, 2), [-0., -1., -0., -1., 0., 1., 0., 1., 0.],
np.float64)
assert eq(np.remainder(xf64, 2), [0., 1., 0., 1., 0., 1., 0., 1., 0.],
np.float64)
assert eq(xf64 % -2, [-0., -1., -0., -1., -0., -1., -0., -1., -0.], np.float64)
assert eq(np.fmod(xf64, -2), [-0., -1., -0., -1., 0., 1., 0., 1., 0.],
np.float64)
assert eq(np.remainder(xf64, -2),
[-0., -1., -0., -1., -0., -1., -0., -1., -0.], np.float64)
assert eq(xf64 % 3, [2., 0., 1., 2., 0., 1., 2., 0., 1.], np.float64)
assert eq(np.fmod(xf64, 3), [-1., -0., -2., -1., 0., 1., 2., 0., 1.],
np.float64)
assert eq(np.remainder(xf64, 3), [2., 0., 1., 2., 0., 1., 2., 0., 1.],
np.float64)
assert eq(xf64 % -3, [-1., -0., -2., -1., -0., -2., -1., -0., -2.], np.float64)
assert eq(np.fmod(xf64, -3), [-1., -0., -2., -1., 0., 1., 2., 0., 1.],
np.float64)
assert eq(np.remainder(xf64, -3),
[-1., -0., -2., -1., -0., -2., -1., -0., -2.], np.float64)
assert eq(xf32 % 1, [0., 0., 0., 0., 0., 0., 0., 0., 0.], np.float32)
assert eq(np.fmod(xf32, 1), [-0., -0., -0., -0., 0., 0., 0., 0., 0.],
np.float32)
assert eq(np.remainder(xf32, 1), [0., 0., 0., 0., 0., 0., 0., 0., 0.],
np.float32)
assert eq(xf32 % -1, [-0., -0., -0., -0., -0., -0., -0., -0., -0.], np.float32)
assert eq(np.fmod(xf32, -1), [-0., -0., -0., -0., 0., 0., 0., 0., 0.],
np.float32)
assert eq(np.remainder(xf32, -1),
[-0., -0., -0., -0., -0., -0., -0., -0., -0.], np.float32)
assert eq(xf32 % 2, [0., 1., 0., 1., 0., 1., 0., 1., 0.], np.float32)
assert eq(np.fmod(xf32, 2), [-0., -1., -0., -1., 0., 1., 0., 1., 0.],
np.float32)
assert eq(np.remainder(xf32, 2), [0., 1., 0., 1., 0., 1., 0., 1., 0.],
np.float32)
assert eq(xf32 % -2, [-0., -1., -0., -1., -0., -1., -0., -1., -0.], np.float32)
assert eq(np.fmod(xf32, -2), [-0., -1., -0., -1., 0., 1., 0., 1., 0.],
np.float32)
assert eq(np.remainder(xf32, -2),
[-0., -1., -0., -1., -0., -1., -0., -1., -0.], np.float32)
assert eq(xf32 % 3, [2., 0., 1., 2., 0., 1., 2., 0., 1.], np.float32)
assert eq(np.fmod(xf32, 3), [-1., -0., -2., -1., 0., 1., 2., 0., 1.],
np.float32)
assert eq(np.remainder(xf32, 3), [2., 0., 1., 2., 0., 1., 2., 0., 1.],
np.float32)
assert eq(xf32 % -3, [-1., -0., -2., -1., -0., -2., -1., -0., -2.], np.float32)
assert eq(np.fmod(xf32, -3), [-1., -0., -2., -1., 0., 1., 2., 0., 1.],
np.float32)
assert eq(np.remainder(xf32, -3),
[-1., -0., -2., -1., -0., -2., -1., -0., -2.], np.float32)
assert eq(xf16 % 1, [0., 0., 0., 0., 0., 0., 0., 0., 0.], np.float16)
assert eq(np.fmod(xf16, 1), [-0., -0., -0., -0., 0., 0., 0., 0., 0.],
np.float16)
assert eq(np.remainder(xf16, 1), [0., 0., 0., 0., 0., 0., 0., 0., 0.],
np.float16)
assert eq(xf16 % -1, [-0., -0., -0., -0., -0., -0., -0., -0., -0.], np.float16)
assert eq(np.fmod(xf16, -1), [-0., -0., -0., -0., 0., 0., 0., 0., 0.],
np.float16)
assert eq(np.remainder(xf16, -1),
[-0., -0., -0., -0., -0., -0., -0., -0., -0.], np.float16)
assert eq(xf16 % 2, [0., 1., 0., 1., 0., 1., 0., 1., 0.], np.float16)
assert eq(np.fmod(xf16, 2), [-0., -1., -0., -1., 0., 1., 0., 1., 0.],
np.float16)
assert eq(np.remainder(xf16, 2), [0., 1., 0., 1., 0., 1., 0., 1., 0.],
np.float16)
assert eq(xf16 % -2, [-0., -1., -0., -1., -0., -1., -0., -1., -0.], np.float16)
assert eq(np.fmod(xf16, -2), [-0., -1., -0., -1., 0., 1., 0., 1., 0.],
np.float16)
assert eq(np.remainder(xf16, -2),
[-0., -1., -0., -1., -0., -1., -0., -1., -0.], np.float16)
assert eq(xf16 % 3, [2., 0., 1., 2., 0., 1., 2., 0., 1.], np.float16)
assert eq(np.fmod(xf16, 3), [-1., -0., -2., -1., 0., 1., 2., 0., 1.],
np.float16)
assert eq(np.remainder(xf16, 3), [2., 0., 1., 2., 0., 1., 2., 0., 1.],
np.float16)
assert eq(xf16 % -3, [-1., -0., -2., -1., -0., -2., -1., -0., -2.], np.float16)
assert eq(np.fmod(xf16, -3), [-1., -0., -2., -1., 0., 1., 2., 0., 1.],
np.float16)
assert eq(np.remainder(xf16, -3),
[-1., -0., -2., -1., -0., -2., -1., -0., -2.], np.float16)
assert eq(xi64 % 1, [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int64)
assert eq(np.fmod(xi64, 1), [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int64)
assert eq(np.remainder(xi64, 1), [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int64)
assert eq(xi64 % -1, [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int64)
assert eq(np.fmod(xi64, -1), [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int64)
assert eq(np.remainder(xi64, -1), [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int64)
assert eq(xi64 % 2, [0, 1, 0, 1, 0, 1, 0, 1, 0], np.int64)
assert eq(np.fmod(xi64, 2), [0, -1, 0, -1, 0, 1, 0, 1, 0], np.int64)
assert eq(np.remainder(xi64, 2), [0, 1, 0, 1, 0, 1, 0, 1, 0], np.int64)
assert eq(xi64 % -2, [0, -1, 0, -1, 0, -1, 0, -1, 0], np.int64)
assert eq(np.fmod(xi64, -2), [0, -1, 0, -1, 0, 1, 0, 1, 0], np.int64)
assert eq(np.remainder(xi64, -2), [0, -1, 0, -1, 0, -1, 0, -1, 0], np.int64)
assert eq(xi64 % 3, [2, 0, 1, 2, 0, 1, 2, 0, 1], np.int64)
assert eq(np.fmod(xi64, 3), [-1, 0, -2, -1, 0, 1, 2, 0, 1], np.int64)
assert eq(np.remainder(xi64, 3), [2, 0, 1, 2, 0, 1, 2, 0, 1], np.int64)
assert eq(xi64 % -3, [-1, 0, -2, -1, 0, -2, -1, 0, -2], np.int64)
assert eq(np.fmod(xi64, -3), [-1, 0, -2, -1, 0, 1, 2, 0, 1], np.int64)
assert eq(np.remainder(xi64, -3), [-1, 0, -2, -1, 0, -2, -1, 0, -2], np.int64)
assert eq(xi32 % 1, [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int32)
assert eq(np.fmod(xi32, 1), [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int32)
assert eq(np.remainder(xi32, 1), [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int32)
assert eq(xi32 % -1, [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int32)
assert eq(np.fmod(xi32, -1), [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int32)
assert eq(np.remainder(xi32, -1), [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int32)
assert eq(xi32 % 2, [0, 1, 0, 1, 0, 1, 0, 1, 0], np.int32)
assert eq(np.fmod(xi32, 2), [0, -1, 0, -1, 0, 1, 0, 1, 0], np.int32)
assert eq(np.remainder(xi32, 2), [0, 1, 0, 1, 0, 1, 0, 1, 0], np.int32)
assert eq(xi32 % -2, [0, -1, 0, -1, 0, -1, 0, -1, 0], np.int32)
assert eq(np.fmod(xi32, -2), [0, -1, 0, -1, 0, 1, 0, 1, 0], np.int32)
assert eq(np.remainder(xi32, -2), [0, -1, 0, -1, 0, -1, 0, -1, 0], np.int32)
assert eq(xi32 % 3, [2, 0, 1, 2, 0, 1, 2, 0, 1], np.int32)
assert eq(np.fmod(xi32, 3), [-1, 0, -2, -1, 0, 1, 2, 0, 1], np.int32)
assert eq(np.remainder(xi32, 3), [2, 0, 1, 2, 0, 1, 2, 0, 1], np.int32)
assert eq(xi32 % -3, [-1, 0, -2, -1, 0, -2, -1, 0, -2], np.int32)
assert eq(np.fmod(xi32, -3), [-1, 0, -2, -1, 0, 1, 2, 0, 1], np.int32)
assert eq(np.remainder(xi32, -3), [-1, 0, -2, -1, 0, -2, -1, 0, -2], np.int32)
assert eq(xi16 % 1, [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int16)
assert eq(np.fmod(xi16, 1), [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int16)
assert eq(np.remainder(xi16, 1), [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int16)
assert eq(xi16 % -1, [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int16)
assert eq(np.fmod(xi16, -1), [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int16)
assert eq(np.remainder(xi16, -1), [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int16)
assert eq(xi16 % 2, [0, 1, 0, 1, 0, 1, 0, 1, 0], np.int16)
assert eq(np.fmod(xi16, 2), [0, -1, 0, -1, 0, 1, 0, 1, 0], np.int16)
assert eq(np.remainder(xi16, 2), [0, 1, 0, 1, 0, 1, 0, 1, 0], np.int16)
assert eq(xi16 % -2, [0, -1, 0, -1, 0, -1, 0, -1, 0], np.int16)
assert eq(np.fmod(xi16, -2), [0, -1, 0, -1, 0, 1, 0, 1, 0], np.int16)
assert eq(np.remainder(xi16, -2), [0, -1, 0, -1, 0, -1, 0, -1, 0], np.int16)
assert eq(xi16 % 3, [2, 0, 1, 2, 0, 1, 2, 0, 1], np.int16)
assert eq(np.fmod(xi16, 3), [-1, 0, -2, -1, 0, 1, 2, 0, 1], np.int16)
assert eq(np.remainder(xi16, 3), [2, 0, 1, 2, 0, 1, 2, 0, 1], np.int16)
assert eq(xi16 % -3, [-1, 0, -2, -1, 0, -2, -1, 0, -2], np.int16)
assert eq(np.fmod(xi16, -3), [-1, 0, -2, -1, 0, 1, 2, 0, 1], np.int16)
assert eq(np.remainder(xi16, -3), [-1, 0, -2, -1, 0, -2, -1, 0, -2], np.int16)
assert eq(xi8 % 1, [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int8)
assert eq(np.fmod(xi8, 1), [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int8)
assert eq(np.remainder(xi8, 1), [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int8)
assert eq(xi8 % -1, [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int8)
assert eq(np.fmod(xi8, -1), [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int8)
assert eq(np.remainder(xi8, -1), [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int8)
assert eq(xi8 % 2, [0, 1, 0, 1, 0, 1, 0, 1, 0], np.int8)
assert eq(np.fmod(xi8, 2), [0, -1, 0, -1, 0, 1, 0, 1, 0], np.int8)
assert eq(np.remainder(xi8, 2), [0, 1, 0, 1, 0, 1, 0, 1, 0], np.int8)
assert eq(xi8 % -2, [0, -1, 0, -1, 0, -1, 0, -1, 0], np.int8)
assert eq(np.fmod(xi8, -2), [0, -1, 0, -1, 0, 1, 0, 1, 0], np.int8)
assert eq(np.remainder(xi8, -2), [0, -1, 0, -1, 0, -1, 0, -1, 0], np.int8)
assert eq(xi8 % 3, [2, 0, 1, 2, 0, 1, 2, 0, 1], np.int8)
assert eq(np.fmod(xi8, 3), [-1, 0, -2, -1, 0, 1, 2, 0, 1], np.int8)
assert eq(np.remainder(xi8, 3), [2, 0, 1, 2, 0, 1, 2, 0, 1], np.int8)
assert eq(xi8 % -3, [-1, 0, -2, -1, 0, -2, -1, 0, -2], np.int8)
assert eq(np.fmod(xi8, -3), [-1, 0, -2, -1, 0, 1, 2, 0, 1], np.int8)
assert eq(np.remainder(xi8, -3), [-1, 0, -2, -1, 0, -2, -1, 0, -2], np.int8)
assert eq(xu64 % 1, [0, 0, 0, 0, 0], np.uint64)
assert eq(np.fmod(xu64, 1), [0, 0, 0, 0, 0], np.uint64)
assert eq(np.remainder(xu64, 1), [0, 0, 0, 0, 0], np.uint64)
assert eq(xu64 % 2, [0, 1, 0, 1, 0], np.uint64)
assert eq(np.fmod(xu64, 2), [0, 1, 0, 1, 0], np.uint64)
assert eq(np.remainder(xu64, 2), [0, 1, 0, 1, 0], np.uint64)
assert eq(xu64 % 3, [0, 1, 2, 0, 1], np.uint64)
assert eq(np.fmod(xu64, 3), [0, 1, 2, 0, 1], np.uint64)
assert eq(np.remainder(xu64, 3), [0, 1, 2, 0, 1], np.uint64)
assert eq(xu32 % 1, [0, 0, 0, 0, 0], np.uint32)
assert eq(np.fmod(xu32, 1), [0, 0, 0, 0, 0], np.uint32)
assert eq(np.remainder(xu32, 1), [0, 0, 0, 0, 0], np.uint32)
assert eq(xu32 % 2, [0, 1, 0, 1, 0], np.uint32)
assert eq(np.fmod(xu32, 2), [0, 1, 0, 1, 0], np.uint32)
assert eq(np.remainder(xu32, 2), [0, 1, 0, 1, 0], np.uint32)
assert eq(xu32 % 3, [0, 1, 2, 0, 1], np.uint32)
assert eq(np.fmod(xu32, 3), [0, 1, 2, 0, 1], np.uint32)
assert eq(np.remainder(xu32, 3), [0, 1, 2, 0, 1], np.uint32)
assert eq(xu16 % 1, [0, 0, 0, 0, 0], np.uint16)
assert eq(np.fmod(xu16, 1), [0, 0, 0, 0, 0], np.uint16)
assert eq(np.remainder(xu16, 1), [0, 0, 0, 0, 0], np.uint16)
assert eq(xu16 % 2, [0, 1, 0, 1, 0], np.uint16)
assert eq(np.fmod(xu16, 2), [0, 1, 0, 1, 0], np.uint16)
assert eq(np.remainder(xu16, 2), [0, 1, 0, 1, 0], np.uint16)
assert eq(xu16 % 3, [0, 1, 2, 0, 1], np.uint16)
assert eq(np.fmod(xu16, 3), [0, 1, 2, 0, 1], np.uint16)
assert eq(np.remainder(xu16, 3), [0, 1, 2, 0, 1], np.uint16)
assert eq(xu8 % 1, [0, 0, 0, 0, 0], np.uint8)
assert eq(np.fmod(xu8, 1), [0, 0, 0, 0, 0], np.uint8)
assert eq(np.remainder(xu8, 1), [0, 0, 0, 0, 0], np.uint8)
assert eq(xu8 % 2, [0, 1, 0, 1, 0], np.uint8)
assert eq(np.fmod(xu8, 2), [0, 1, 0, 1, 0], np.uint8)
assert eq(np.remainder(xu8, 2), [0, 1, 0, 1, 0], np.uint8)
assert eq(xu8 % 3, [0, 1, 2, 0, 1], np.uint8)
assert eq(np.fmod(xu8, 3), [0, 1, 2, 0, 1], np.uint8)
assert eq(np.remainder(xu8, 3), [0, 1, 2, 0, 1], np.uint8)
def eq1(got, exp, dtype: type):
return eq(got, np.asarray(exp, dtype) + 1, dtype)
assert eq1(1 + xf64 % 1, [0., 0., 0., 0., 0., 0., 0., 0., 0.], np.float64)
assert eq1(1 + np.fmod(xf64, 1), [-0., -0., -0., -0., 0., 0., 0., 0., 0.],
np.float64)
assert eq1(1 + np.remainder(xf64, 1), [0., 0., 0., 0., 0., 0., 0., 0., 0.],
np.float64)
assert eq1(1 + xf64 % -1, [-0., -0., -0., -0., -0., -0., -0., -0., -0.], np.float64)
assert eq1(1 + np.fmod(xf64, -1), [-0., -0., -0., -0., 0., 0., 0., 0., 0.],
np.float64)
assert eq1(1 + np.remainder(xf64, -1),
[-0., -0., -0., -0., -0., -0., -0., -0., -0.], np.float64)
assert eq1(1 + xf64 % 2, [0., 1., 0., 1., 0., 1., 0., 1., 0.], np.float64)
assert eq1(1 + np.fmod(xf64, 2), [-0., -1., -0., -1., 0., 1., 0., 1., 0.],
np.float64)
assert eq1(1 + np.remainder(xf64, 2), [0., 1., 0., 1., 0., 1., 0., 1., 0.],
np.float64)
assert eq1(1 + xf64 % -2, [-0., -1., -0., -1., -0., -1., -0., -1., -0.], np.float64)
assert eq1(1 + np.fmod(xf64, -2), [-0., -1., -0., -1., 0., 1., 0., 1., 0.],
np.float64)
assert eq1(1 + np.remainder(xf64, -2),
[-0., -1., -0., -1., -0., -1., -0., -1., -0.], np.float64)
assert eq1(1 + xf64 % 3, [2., 0., 1., 2., 0., 1., 2., 0., 1.], np.float64)
assert eq1(1 + np.fmod(xf64, 3), [-1., -0., -2., -1., 0., 1., 2., 0., 1.],
np.float64)
assert eq1(1 + np.remainder(xf64, 3), [2., 0., 1., 2., 0., 1., 2., 0., 1.],
np.float64)
assert eq1(1 + xf64 % -3, [-1., -0., -2., -1., -0., -2., -1., -0., -2.], np.float64)
assert eq1(1 + np.fmod(xf64, -3), [-1., -0., -2., -1., 0., 1., 2., 0., 1.],
np.float64)
assert eq1(1 + np.remainder(xf64, -3),
[-1., -0., -2., -1., -0., -2., -1., -0., -2.], np.float64)
assert eq1(1 + xf32 % 1, [0., 0., 0., 0., 0., 0., 0., 0., 0.], np.float32)
assert eq1(1 + np.fmod(xf32, 1), [-0., -0., -0., -0., 0., 0., 0., 0., 0.],
np.float32)
assert eq1(1 + np.remainder(xf32, 1), [0., 0., 0., 0., 0., 0., 0., 0., 0.],
np.float32)
assert eq1(1 + xf32 % -1, [-0., -0., -0., -0., -0., -0., -0., -0., -0.], np.float32)
assert eq1(1 + np.fmod(xf32, -1), [-0., -0., -0., -0., 0., 0., 0., 0., 0.],
np.float32)
assert eq1(1 + np.remainder(xf32, -1),
[-0., -0., -0., -0., -0., -0., -0., -0., -0.], np.float32)
assert eq1(1 + xf32 % 2, [0., 1., 0., 1., 0., 1., 0., 1., 0.], np.float32)
assert eq1(1 + np.fmod(xf32, 2), [-0., -1., -0., -1., 0., 1., 0., 1., 0.],
np.float32)
assert eq1(1 + np.remainder(xf32, 2), [0., 1., 0., 1., 0., 1., 0., 1., 0.],
np.float32)
assert eq1(1 + xf32 % -2, [-0., -1., -0., -1., -0., -1., -0., -1., -0.], np.float32)
assert eq1(1 + np.fmod(xf32, -2), [-0., -1., -0., -1., 0., 1., 0., 1., 0.],
np.float32)
assert eq1(1 + np.remainder(xf32, -2),
[-0., -1., -0., -1., -0., -1., -0., -1., -0.], np.float32)
assert eq1(1 + xf32 % 3, [2., 0., 1., 2., 0., 1., 2., 0., 1.], np.float32)
assert eq1(1 + np.fmod(xf32, 3), [-1., -0., -2., -1., 0., 1., 2., 0., 1.],
np.float32)
assert eq1(1 + np.remainder(xf32, 3), [2., 0., 1., 2., 0., 1., 2., 0., 1.],
np.float32)
assert eq1(1 + xf32 % -3, [-1., -0., -2., -1., -0., -2., -1., -0., -2.], np.float32)
assert eq1(1 + np.fmod(xf32, -3), [-1., -0., -2., -1., 0., 1., 2., 0., 1.],
np.float32)
assert eq1(1 + np.remainder(xf32, -3),
[-1., -0., -2., -1., -0., -2., -1., -0., -2.], np.float32)
assert eq1(1 + xf16 % 1, [0., 0., 0., 0., 0., 0., 0., 0., 0.], np.float16)
assert eq1(1 + np.fmod(xf16, 1), [-0., -0., -0., -0., 0., 0., 0., 0., 0.],
np.float16)
assert eq1(1 + np.remainder(xf16, 1), [0., 0., 0., 0., 0., 0., 0., 0., 0.],
np.float16)
assert eq1(1 + xf16 % -1, [-0., -0., -0., -0., -0., -0., -0., -0., -0.], np.float16)
assert eq1(1 + np.fmod(xf16, -1), [-0., -0., -0., -0., 0., 0., 0., 0., 0.],
np.float16)
assert eq1(1 + np.remainder(xf16, -1),
[-0., -0., -0., -0., -0., -0., -0., -0., -0.], np.float16)
assert eq1(1 + xf16 % 2, [0., 1., 0., 1., 0., 1., 0., 1., 0.], np.float16)
assert eq1(1 + np.fmod(xf16, 2), [-0., -1., -0., -1., 0., 1., 0., 1., 0.],
np.float16)
assert eq1(1 + np.remainder(xf16, 2), [0., 1., 0., 1., 0., 1., 0., 1., 0.],
np.float16)
assert eq1(1 + xf16 % -2, [-0., -1., -0., -1., -0., -1., -0., -1., -0.], np.float16)
assert eq1(1 + np.fmod(xf16, -2), [-0., -1., -0., -1., 0., 1., 0., 1., 0.],
np.float16)
assert eq1(1 + np.remainder(xf16, -2),
[-0., -1., -0., -1., -0., -1., -0., -1., -0.], np.float16)
assert eq1(1 + xf16 % 3, [2., 0., 1., 2., 0., 1., 2., 0., 1.], np.float16)
assert eq1(1 + np.fmod(xf16, 3), [-1., -0., -2., -1., 0., 1., 2., 0., 1.],
np.float16)
assert eq1(1 + np.remainder(xf16, 3), [2., 0., 1., 2., 0., 1., 2., 0., 1.],
np.float16)
assert eq1(1 + xf16 % -3, [-1., -0., -2., -1., -0., -2., -1., -0., -2.], np.float16)
assert eq1(1 + np.fmod(xf16, -3), [-1., -0., -2., -1., 0., 1., 2., 0., 1.],
np.float16)
assert eq1(1 + np.remainder(xf16, -3),
[-1., -0., -2., -1., -0., -2., -1., -0., -2.], np.float16)
assert eq1(1 + xi64 % 1, [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int64)
assert eq1(1 + np.fmod(xi64, 1), [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int64)
assert eq1(1 + np.remainder(xi64, 1), [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int64)
assert eq1(1 + xi64 % -1, [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int64)
assert eq1(1 + np.fmod(xi64, -1), [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int64)
assert eq1(1 + np.remainder(xi64, -1), [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int64)
assert eq1(1 + xi64 % 2, [0, 1, 0, 1, 0, 1, 0, 1, 0], np.int64)
assert eq1(1 + np.fmod(xi64, 2), [0, -1, 0, -1, 0, 1, 0, 1, 0], np.int64)
assert eq1(1 + np.remainder(xi64, 2), [0, 1, 0, 1, 0, 1, 0, 1, 0], np.int64)
assert eq1(1 + xi64 % -2, [0, -1, 0, -1, 0, -1, 0, -1, 0], np.int64)
assert eq1(1 + np.fmod(xi64, -2), [0, -1, 0, -1, 0, 1, 0, 1, 0], np.int64)
assert eq1(1 + np.remainder(xi64, -2), [0, -1, 0, -1, 0, -1, 0, -1, 0], np.int64)
assert eq1(1 + xi64 % 3, [2, 0, 1, 2, 0, 1, 2, 0, 1], np.int64)
assert eq1(1 + np.fmod(xi64, 3), [-1, 0, -2, -1, 0, 1, 2, 0, 1], np.int64)
assert eq1(1 + np.remainder(xi64, 3), [2, 0, 1, 2, 0, 1, 2, 0, 1], np.int64)
assert eq1(1 + xi64 % -3, [-1, 0, -2, -1, 0, -2, -1, 0, -2], np.int64)
assert eq1(1 + np.fmod(xi64, -3), [-1, 0, -2, -1, 0, 1, 2, 0, 1], np.int64)
assert eq1(1 + np.remainder(xi64, -3), [-1, 0, -2, -1, 0, -2, -1, 0, -2], np.int64)
assert eq1(1 + xi32 % 1, [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int32)
assert eq1(1 + np.fmod(xi32, 1), [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int32)
assert eq1(1 + np.remainder(xi32, 1), [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int32)
assert eq1(1 + xi32 % -1, [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int32)
assert eq1(1 + np.fmod(xi32, -1), [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int32)
assert eq1(1 + np.remainder(xi32, -1), [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int32)
assert eq1(1 + xi32 % 2, [0, 1, 0, 1, 0, 1, 0, 1, 0], np.int32)
assert eq1(1 + np.fmod(xi32, 2), [0, -1, 0, -1, 0, 1, 0, 1, 0], np.int32)
assert eq1(1 + np.remainder(xi32, 2), [0, 1, 0, 1, 0, 1, 0, 1, 0], np.int32)
assert eq1(1 + xi32 % -2, [0, -1, 0, -1, 0, -1, 0, -1, 0], np.int32)
assert eq1(1 + np.fmod(xi32, -2), [0, -1, 0, -1, 0, 1, 0, 1, 0], np.int32)
assert eq1(1 + np.remainder(xi32, -2), [0, -1, 0, -1, 0, -1, 0, -1, 0], np.int32)
assert eq1(1 + xi32 % 3, [2, 0, 1, 2, 0, 1, 2, 0, 1], np.int32)
assert eq1(1 + np.fmod(xi32, 3), [-1, 0, -2, -1, 0, 1, 2, 0, 1], np.int32)
assert eq1(1 + np.remainder(xi32, 3), [2, 0, 1, 2, 0, 1, 2, 0, 1], np.int32)
assert eq1(1 + xi32 % -3, [-1, 0, -2, -1, 0, -2, -1, 0, -2], np.int32)
assert eq1(1 + np.fmod(xi32, -3), [-1, 0, -2, -1, 0, 1, 2, 0, 1], np.int32)
assert eq1(1 + np.remainder(xi32, -3), [-1, 0, -2, -1, 0, -2, -1, 0, -2], np.int32)
assert eq1(1 + xi16 % 1, [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int16)
assert eq1(1 + np.fmod(xi16, 1), [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int16)
assert eq1(1 + np.remainder(xi16, 1), [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int16)
assert eq1(1 + xi16 % -1, [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int16)
assert eq1(1 + np.fmod(xi16, -1), [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int16)
assert eq1(1 + np.remainder(xi16, -1), [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int16)
assert eq1(1 + xi16 % 2, [0, 1, 0, 1, 0, 1, 0, 1, 0], np.int16)
assert eq1(1 + np.fmod(xi16, 2), [0, -1, 0, -1, 0, 1, 0, 1, 0], np.int16)
assert eq1(1 + np.remainder(xi16, 2), [0, 1, 0, 1, 0, 1, 0, 1, 0], np.int16)
assert eq1(1 + xi16 % -2, [0, -1, 0, -1, 0, -1, 0, -1, 0], np.int16)
assert eq1(1 + np.fmod(xi16, -2), [0, -1, 0, -1, 0, 1, 0, 1, 0], np.int16)
assert eq1(1 + np.remainder(xi16, -2), [0, -1, 0, -1, 0, -1, 0, -1, 0], np.int16)
assert eq1(1 + xi16 % 3, [2, 0, 1, 2, 0, 1, 2, 0, 1], np.int16)
assert eq1(1 + np.fmod(xi16, 3), [-1, 0, -2, -1, 0, 1, 2, 0, 1], np.int16)
assert eq1(1 + np.remainder(xi16, 3), [2, 0, 1, 2, 0, 1, 2, 0, 1], np.int16)
assert eq1(1 + xi16 % -3, [-1, 0, -2, -1, 0, -2, -1, 0, -2], np.int16)
assert eq1(1 + np.fmod(xi16, -3), [-1, 0, -2, -1, 0, 1, 2, 0, 1], np.int16)
assert eq1(1 + np.remainder(xi16, -3), [-1, 0, -2, -1, 0, -2, -1, 0, -2], np.int16)
assert eq1(1 + xi8 % 1, [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int8)
assert eq1(1 + np.fmod(xi8, 1), [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int8)
assert eq1(1 + np.remainder(xi8, 1), [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int8)
assert eq1(1 + xi8 % -1, [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int8)
assert eq1(1 + np.fmod(xi8, -1), [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int8)
assert eq1(1 + np.remainder(xi8, -1), [0, 0, 0, 0, 0, 0, 0, 0, 0], np.int8)
assert eq1(1 + xi8 % 2, [0, 1, 0, 1, 0, 1, 0, 1, 0], np.int8)
assert eq1(1 + np.fmod(xi8, 2), [0, -1, 0, -1, 0, 1, 0, 1, 0], np.int8)
assert eq1(1 + np.remainder(xi8, 2), [0, 1, 0, 1, 0, 1, 0, 1, 0], np.int8)
assert eq1(1 + xi8 % -2, [0, -1, 0, -1, 0, -1, 0, -1, 0], np.int8)
assert eq1(1 + np.fmod(xi8, -2), [0, -1, 0, -1, 0, 1, 0, 1, 0], np.int8)
assert eq1(1 + np.remainder(xi8, -2), [0, -1, 0, -1, 0, -1, 0, -1, 0], np.int8)
assert eq1(1 + xi8 % 3, [2, 0, 1, 2, 0, 1, 2, 0, 1], np.int8)
assert eq1(1 + np.fmod(xi8, 3), [-1, 0, -2, -1, 0, 1, 2, 0, 1], np.int8)
assert eq1(1 + np.remainder(xi8, 3), [2, 0, 1, 2, 0, 1, 2, 0, 1], np.int8)
assert eq1(1 + xi8 % -3, [-1, 0, -2, -1, 0, -2, -1, 0, -2], np.int8)
assert eq1(1 + np.fmod(xi8, -3), [-1, 0, -2, -1, 0, 1, 2, 0, 1], np.int8)
assert eq1(1 + np.remainder(xi8, -3), [-1, 0, -2, -1, 0, -2, -1, 0, -2], np.int8)
assert eq1(1 + xu64 % 1, [0, 0, 0, 0, 0], np.uint64)
assert eq1(1 + np.fmod(xu64, 1), [0, 0, 0, 0, 0], np.uint64)
assert eq1(1 + np.remainder(xu64, 1), [0, 0, 0, 0, 0], np.uint64)
assert eq1(1 + xu64 % 2, [0, 1, 0, 1, 0], np.uint64)
assert eq1(1 + np.fmod(xu64, 2), [0, 1, 0, 1, 0], np.uint64)
assert eq1(1 + np.remainder(xu64, 2), [0, 1, 0, 1, 0], np.uint64)
assert eq1(1 + xu64 % 3, [0, 1, 2, 0, 1], np.uint64)
assert eq1(1 + np.fmod(xu64, 3), [0, 1, 2, 0, 1], np.uint64)
assert eq1(1 + np.remainder(xu64, 3), [0, 1, 2, 0, 1], np.uint64)
assert eq1(1 + xu32 % 1, [0, 0, 0, 0, 0], np.uint32)
assert eq1(1 + np.fmod(xu32, 1), [0, 0, 0, 0, 0], np.uint32)
assert eq1(1 + np.remainder(xu32, 1), [0, 0, 0, 0, 0], np.uint32)
assert eq1(1 + xu32 % 2, [0, 1, 0, 1, 0], np.uint32)
assert eq1(1 + np.fmod(xu32, 2), [0, 1, 0, 1, 0], np.uint32)
assert eq1(1 + np.remainder(xu32, 2), [0, 1, 0, 1, 0], np.uint32)
assert eq1(1 + xu32 % 3, [0, 1, 2, 0, 1], np.uint32)
assert eq1(1 + np.fmod(xu32, 3), [0, 1, 2, 0, 1], np.uint32)
assert eq1(1 + np.remainder(xu32, 3), [0, 1, 2, 0, 1], np.uint32)
assert eq1(1 + xu16 % 1, [0, 0, 0, 0, 0], np.uint16)
assert eq1(1 + np.fmod(xu16, 1), [0, 0, 0, 0, 0], np.uint16)
assert eq1(1 + np.remainder(xu16, 1), [0, 0, 0, 0, 0], np.uint16)
assert eq1(1 + xu16 % 2, [0, 1, 0, 1, 0], np.uint16)
assert eq1(1 + np.fmod(xu16, 2), [0, 1, 0, 1, 0], np.uint16)
assert eq1(1 + np.remainder(xu16, 2), [0, 1, 0, 1, 0], np.uint16)
assert eq1(1 + xu16 % 3, [0, 1, 2, 0, 1], np.uint16)
assert eq1(1 + np.fmod(xu16, 3), [0, 1, 2, 0, 1], np.uint16)
assert eq1(1 + np.remainder(xu16, 3), [0, 1, 2, 0, 1], np.uint16)
assert eq1(1 + xu8 % 1, [0, 0, 0, 0, 0], np.uint8)
assert eq1(1 + np.fmod(xu8, 1), [0, 0, 0, 0, 0], np.uint8)
assert eq1(1 + np.remainder(xu8, 1), [0, 0, 0, 0, 0], np.uint8)
assert eq1(1 + xu8 % 2, [0, 1, 0, 1, 0], np.uint8)
assert eq1(1 + np.fmod(xu8, 2), [0, 1, 0, 1, 0], np.uint8)
assert eq1(1 + np.remainder(xu8, 2), [0, 1, 0, 1, 0], np.uint8)
assert eq1(1 + xu8 % 3, [0, 1, 2, 0, 1], np.uint8)
assert eq1(1 + np.fmod(xu8, 3), [0, 1, 2, 0, 1], np.uint8)
assert eq1(1 + np.remainder(xu8, 3), [0, 1, 2, 0, 1], np.uint8)
@test
def test_broadcasting():
a = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
b = np.array([10, 20, 30])
c = b.reshape((1, -1))
d = c.T
e = a.T
f = np.array(100)
assert eq(a * a + b * b, [[101, 404, 909], [116, 425, 936], [149, 464, 981]], int)
assert eq(b / a + 1, [[11., 11., 11.], [3.5, 5., 6.], [2.42857143, 3.5, 4.3333333333]], float)
assert eq((a + b) - (b**2 + b + 1) - (b**3 + b + 1), [[ -1111, -8420, -27929],
[ -1108, -8417, -27926],
[ -1105, -8414, -27923]], int)
assert eq(a * a + c * c, [[101, 404, 909], [116, 425, 936], [149, 464, 981]], int)
assert eq(c / a + 1, [[11., 11., 11.], [3.5, 5., 6.], [2.42857143, 3.5, 4.3333333333]], float)
assert eq((a + c) - (c**2 + c + 1) - (b**3 + b + 1), [[ -1111, -8420, -27929],
[ -1108, -8417, -27926],
[ -1105, -8414, -27923]], int)
assert eq((c + d) ^ (e - a), [[ 20, 28, 44], [-32, 40, 48], [-44, -52, 60]], int)
assert eq(f + c + d + a, [[121, 132, 143], [134, 145, 156], [147, 158, 169]], int)
@test
def test_forwarding():
a = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
# Basic
L.clear()
expr1 = (f(a, 'a1') + 1) * (f(a, 'a2') + 2)
expr2 = (f(1, '1') + expr1) ** 2
assert eq(expr2, [[ 49, 169, 441],
[ 961, 1849, 3249],
[ 5329, 8281, 12321]], int)
# If expr1 was forwarded into expr2, then the '1' should come first
assert L == ['1', 'a1', 'a2']
# Multiple
L.clear()
expr1 = (f(a, 'a1') + 1) * (f(a, 'a2') + 2)
expr2 = (f(a, 'a3') + 3) * (f(a, 'a4') + 4)
expr3 = (expr2 * f(2, '1') + expr1) ** 2
assert eq(expr3, [[ 2116, 5184, 10816],
[ 20164, 34596, 55696],
[ 85264, 125316, 178084]], int)
# '1' comes first because forwarded leaves are appended to original leaves
assert L == ['1', 'a3', 'a4', 'a1', 'a2']
# Chain
L.clear()
expr1 = (f(a, 'a1') + 1) * (f(a, 'a2') + 2)
expr2 = (expr1 + 3) * (f(a, 'a4') + 4)
expr3 = (expr2 * f(2, '1')) ** 2
assert eq(expr3, [[ 8100, 32400, 103684],
[ 278784, 656100, 1392400],
[2722500, 4981824, 8631844]], int)
# Similar comment to above
assert L == ['1', 'a4', 'a1', 'a2']
# Double Chain
L.clear()
expr1 = (f(a, 'a1') + 1) ^ (f(a, 'a2') + 2)
expr2 = (expr1 + 3) ^ (f(a, 'a3') + 4)
expr3 = (f(a, 'a4') + 3) ^ (f(a, 'a5') + 4)
expr4 = (expr3 + 5) ^ (f(a, 'a6') + 6)
expr5 = (expr2 * f(2, '1') + expr4) ** 2
assert eq(expr5, [[ 9, 576, 441],
[3364, 1521, 2704],
[1681, 484, 729]], int)
assert L == ['1', 'a3', 'a1', 'a2', 'a6', 'a4', 'a5']
# No forwarding
L.clear()
expr1 = (f(a, 'a1') + 1) * (f(a, 'a2') + 2)
L.append('break')
expr2 = (f(1, '1') + expr1) ** 2
assert eq(expr2, [[ 49, 169, 441],
[ 961, 1849, 3249],
[ 5329, 8281, 12321]], int)
# expr1 is not forwarded, so order is as you'd expect
assert L == ['a1', 'a2', 'break', '1']
test_basic()
test_order()
test_ops_int64()
test_ops_int32()
test_ops_int16()
test_ops_int8()
test_ops_uint64()
test_ops_uint32()
test_ops_uint16()
test_ops_uint8()
test_ops_float64()
test_ops_float32()
test_ops_float16()
test_ops_complex128()
test_ops_complex64()
test_mixed_types()
test_div_mod()
test_broadcasting()
test_forwarding()