提交 869c923c authored 作者: Brandon T. Willard's avatar Brandon T. Willard

Move theano.tensor.inplace tests from tests.tensor.test_basic into tests.tensor.test_inplace

上级 c9f8a753
...@@ -70,8 +70,8 @@ jobs: ...@@ -70,8 +70,8 @@ jobs:
float32: [0] float32: [0]
part: part:
- "tests --ignore=tests/tensor --ignore=tests/sparse --ignore=tests/tensor/nnet" - "tests --ignore=tests/tensor --ignore=tests/sparse --ignore=tests/tensor/nnet"
- "tests/tensor tests/sparse --ignore=tests/tensor/test_basic.py --ignore=tests/tensor/test_basic_scipy.py --ignore=tests/tensor/test_elemwise.py --ignore=tests/tensor/test_opt.py --ignore=tests/tensor/nnet" - "tests/tensor tests/sparse --ignore=tests/tensor/test_basic.py --ignore=tests/tensor/test_basic_scipy.py --ignore=tests/tensor/test_inplace.py --ignore=tests/tensor/test_elemwise.py --ignore=tests/tensor/test_opt.py --ignore=tests/tensor/nnet"
- "tests/tensor/test_basic.py tests/tensor/test_basic_scipy.py" - "tests/tensor/test_basic.py tests/tensor/test_basic_scipy.py tests/tensor/test_inplace.py"
- "tests/tensor/test_elemwise.py tests/tensor/test_opt.py" - "tests/tensor/test_elemwise.py tests/tensor/test_opt.py"
- "tests/tensor/nnet --ignore-glob='*/test_abstract_conv.py'" - "tests/tensor/nnet --ignore-glob='*/test_abstract_conv.py'"
- "tests/tensor/nnet/test_abstract_conv.py" - "tests/tensor/nnet/test_abstract_conv.py"
......
...@@ -17,19 +17,41 @@ from tests.tensor.utils import ( ...@@ -17,19 +17,41 @@ from tests.tensor.utils import (
ALL_DTYPES, ALL_DTYPES,
COMPLEX_DTYPES, COMPLEX_DTYPES,
REAL_DTYPES, REAL_DTYPES,
_bad_build_broadcast_binary_normal,
_bad_runtime_broadcast_binary_normal,
_bad_runtime_inv,
_eps, _eps,
_good_broadcast_binary_arctan2,
_good_broadcast_binary_normal,
_good_broadcast_div_mod_normal_float,
_good_broadcast_div_mod_normal_float_no_complex,
_good_broadcast_pow_normal_float,
_good_broadcast_unary_arccosh,
_good_broadcast_unary_arcsin,
_good_broadcast_unary_arctanh,
_good_broadcast_unary_normal, _good_broadcast_unary_normal,
_good_broadcast_unary_normal_float,
_good_broadcast_unary_normal_float_no_complex, _good_broadcast_unary_normal_float_no_complex,
_good_broadcast_unary_normal_float_no_empty_no_complex,
_good_broadcast_unary_normal_no_complex, _good_broadcast_unary_normal_no_complex,
_good_broadcast_unary_positive,
_good_broadcast_unary_tan,
_good_broadcast_unary_wide,
_good_inv,
_grad_broadcast_binary_normal,
_grad_broadcast_pow_normal,
_grad_broadcast_unary_normal, _grad_broadcast_unary_normal,
_grad_broadcast_unary_normal_no_complex,
_grad_broadcast_unary_normal_no_complex_no_corner_case,
_grad_broadcast_unary_normal_noint,
_grad_inv,
_numpy_true_div, _numpy_true_div,
angle_eps,
check_floatX, check_floatX,
copymod, copymod,
corner_case_grad,
div_grad_rtol, div_grad_rtol,
eval_outputs, eval_outputs,
get_numeric_types, get_numeric_types,
ignore_isfinite_mode,
inplace_func, inplace_func,
makeBroadcastTester, makeBroadcastTester,
makeTester, makeTester,
...@@ -39,13 +61,9 @@ from tests.tensor.utils import ( ...@@ -39,13 +61,9 @@ from tests.tensor.utils import (
rand_nonzero, rand_nonzero,
rand_of_dtype, rand_of_dtype,
rand_ranged, rand_ranged,
randc128_ranged,
randcomplex, randcomplex,
randcomplex_nonzero,
randint, randint,
randint_nonzero,
randint_ranged, randint_ranged,
randuint16,
randuint32, randuint32,
upcast_float16_ufunc, upcast_float16_ufunc,
upcast_int8_nfunc, upcast_int8_nfunc,
...@@ -122,7 +140,6 @@ from theano.tensor import ( ...@@ -122,7 +140,6 @@ from theano.tensor import (
hessian, hessian,
horizontal_stack, horizontal_stack,
imatrix, imatrix,
inplace,
inverse_permutation, inverse_permutation,
iscalar, iscalar,
iscalars, iscalars,
...@@ -191,46 +208,6 @@ if config.mode == "FAST_COMPILE": ...@@ -191,46 +208,6 @@ if config.mode == "FAST_COMPILE":
else: else:
mode_opt = get_default_mode() mode_opt = get_default_mode()
_good_broadcast_binary_normal = dict(
same_shapes=(rand(2, 3), rand(2, 3)),
not_same_dimensions=(rand(2, 2), rand(2)),
scalar=(rand(2, 3), rand(1, 1)),
row=(rand(2, 3), rand(1, 3)),
column=(rand(2, 3), rand(2, 1)),
integers=(randint(2, 3), randint(2, 3)),
uint32=(randuint32(2, 3), randuint32(2, 3)),
uint16=(randuint16(2, 3), randuint16(2, 3)),
dtype_mixup_1=(rand(2, 3), randint(2, 3)),
dtype_mixup_2=(randint(2, 3), rand(2, 3)),
complex1=(randcomplex(2, 3), randcomplex(2, 3)),
complex2=(randcomplex(2, 3), rand(2, 3)),
# Disabled as we test the case where we reuse the same output as the
# first inputs.
# complex3=(rand(2,3),randcomplex(2,3)),
empty=(np.asarray([], dtype=config.floatX), np.asarray([1], dtype=config.floatX)),
)
_bad_build_broadcast_binary_normal = dict()
_bad_runtime_broadcast_binary_normal = dict(
bad_shapes=(rand(2, 3), rand(3, 2)), bad_row=(rand(2, 3), rand(1, 2))
)
_grad_broadcast_binary_normal = dict(
same_shapes=(rand(2, 3), rand(2, 3)),
scalar=(rand(2, 3), rand(1, 1)),
row=(rand(2, 3), rand(1, 3)),
column=(rand(2, 3), rand(2, 1)),
# This don't work as verify grad don't support that
# empty=(np.asarray([]), np.asarray([1]))
# complex1=(randcomplex(2,3),randcomplex(2,3)),
# complex2=(randcomplex(2,3),rand(2,3)),
# Disabled as we test the case where we reuse the same output as the
# first inputs.
# complex3=(rand(2,3),randcomplex(2,3)),
)
TestAddBroadcast = makeBroadcastTester( TestAddBroadcast = makeBroadcastTester(
op=add, op=add,
expected=lambda *inputs: check_floatX(inputs, reduce(lambda x, y: x + y, inputs)), expected=lambda *inputs: check_floatX(inputs, reduce(lambda x, y: x + y, inputs)),
...@@ -249,15 +226,6 @@ TestAddBroadcast = makeBroadcastTester( ...@@ -249,15 +226,6 @@ TestAddBroadcast = makeBroadcastTester(
) )
TestAddInplaceBroadcast = makeBroadcastTester(
op=inplace.add_inplace,
expected=lambda x, y: x + y,
good=_good_broadcast_binary_normal,
bad_build=_bad_build_broadcast_binary_normal,
bad_runtime=_bad_runtime_broadcast_binary_normal,
inplace=True,
)
TestSubBroadcast = makeBroadcastTester( TestSubBroadcast = makeBroadcastTester(
op=sub, op=sub,
expected=lambda x, y: check_floatX((x, y), x - y), expected=lambda x, y: check_floatX((x, y), x - y),
...@@ -267,15 +235,6 @@ TestSubBroadcast = makeBroadcastTester( ...@@ -267,15 +235,6 @@ TestSubBroadcast = makeBroadcastTester(
grad=_grad_broadcast_binary_normal, grad=_grad_broadcast_binary_normal,
) )
TestSubInplaceBroadcast = makeBroadcastTester(
op=inplace.sub_inplace,
expected=lambda x, y: x - y,
good=_good_broadcast_binary_normal,
bad_build=_bad_build_broadcast_binary_normal,
bad_runtime=_bad_runtime_broadcast_binary_normal,
inplace=True,
)
TestSwitchBroadcast = makeBroadcastTester( TestSwitchBroadcast = makeBroadcastTester(
op=switch, op=switch,
expected=np.where, expected=np.where,
...@@ -310,15 +269,6 @@ TestMaximumBroadcast = makeBroadcastTester( ...@@ -310,15 +269,6 @@ TestMaximumBroadcast = makeBroadcastTester(
grad=_grad_broadcast_binary_normal, grad=_grad_broadcast_binary_normal,
) )
TestMaximumInplaceBroadcast = makeBroadcastTester(
op=inplace.maximum_inplace,
expected=np.maximum,
good=_good_broadcast_binary_normal,
bad_build=_bad_build_broadcast_binary_normal,
bad_runtime=_bad_runtime_broadcast_binary_normal,
inplace=True,
)
def test_maximum_minimum_grad(): def test_maximum_minimum_grad():
# Test the discontinuity point. # Test the discontinuity point.
...@@ -341,15 +291,6 @@ TestMinimumBroadcast = makeBroadcastTester( ...@@ -341,15 +291,6 @@ TestMinimumBroadcast = makeBroadcastTester(
grad=_grad_broadcast_binary_normal, grad=_grad_broadcast_binary_normal,
) )
TestMinimumInplaceBroadcast = makeBroadcastTester(
op=inplace.minimum_inplace,
expected=np.minimum,
good=_good_broadcast_binary_normal,
bad_build=_bad_build_broadcast_binary_normal,
bad_runtime=_bad_runtime_broadcast_binary_normal,
inplace=True,
)
TestMulBroadcast = makeBroadcastTester( TestMulBroadcast = makeBroadcastTester(
op=mul, op=mul,
expected=lambda *inputs: check_floatX(inputs, reduce(lambda x, y: x * y, inputs)), expected=lambda *inputs: check_floatX(inputs, reduce(lambda x, y: x * y, inputs)),
...@@ -367,48 +308,6 @@ TestMulBroadcast = makeBroadcastTester( ...@@ -367,48 +308,6 @@ TestMulBroadcast = makeBroadcastTester(
), ),
) )
TestMulInplaceBroadcast = makeBroadcastTester(
op=inplace.mul_inplace,
expected=lambda x, y: x * y,
good=_good_broadcast_binary_normal,
bad_build=_bad_build_broadcast_binary_normal,
bad_runtime=_bad_runtime_broadcast_binary_normal,
inplace=True,
)
_good_broadcast_div_mod_normal_float_no_complex = dict(
same_shapes=(rand(2, 3), rand_nonzero((2, 3))),
scalar=(rand(2, 3), rand_nonzero((1, 1))),
row=(rand(2, 3), rand_nonzero((1, 3))),
column=(rand(2, 3), rand_nonzero((2, 1))),
dtype_mixup_1=(rand(2, 3), randint_nonzero(2, 3)),
dtype_mixup_2=(randint_nonzero(2, 3), rand_nonzero((2, 3))),
integer=(randint(2, 3), randint_nonzero(2, 3)),
uint8=(randint(2, 3).astype("uint8"), randint_nonzero(2, 3).astype("uint8")),
uint16=(randint(2, 3).astype("uint16"), randint_nonzero(2, 3).astype("uint16")),
int8=[
np.tile(np.arange(-127, 128, dtype="int8"), [254, 1]).T,
np.tile(
np.array(list(range(-127, 0)) + list(range(1, 128)), dtype="int8"), [255, 1]
),
],
# This empty2 doesn't work for some tests. I don't remember why
# empty2=(np.asarray([0]), np.asarray([])),
)
_good_broadcast_div_mod_normal_float_inplace = copymod(
_good_broadcast_div_mod_normal_float_no_complex,
empty1=(np.asarray([]), np.asarray([1])),
# No complex floor division in python 3.x
)
_good_broadcast_div_mod_normal_float = copymod(
_good_broadcast_div_mod_normal_float_inplace,
empty2=(np.asarray([0], dtype=config.floatX), np.asarray([], dtype=config.floatX)),
)
_grad_broadcast_div_mod_normal = dict( _grad_broadcast_div_mod_normal = dict(
same_shapes=(rand(2, 3), rand_nonzero((2, 3))), same_shapes=(rand(2, 3), rand_nonzero((2, 3))),
scalar=(rand(2, 3), rand_nonzero((1, 1))), scalar=(rand(2, 3), rand_nonzero((1, 1))),
...@@ -431,44 +330,6 @@ TestTrueDivBroadcast = makeBroadcastTester( ...@@ -431,44 +330,6 @@ TestTrueDivBroadcast = makeBroadcastTester(
grad_rtol=div_grad_rtol, grad_rtol=div_grad_rtol,
) )
TestTrueDivInplaceBroadcast = makeBroadcastTester(
op=inplace.true_div_inplace,
expected=_numpy_true_div,
good=copymod(
_good_broadcast_div_mod_normal_float_inplace,
# The output is now in float, we cannot work inplace on an int.
without=["integer", "uint8", "uint16", "int8"],
),
grad_rtol=div_grad_rtol,
inplace=True,
)
_good_inv = dict(
normal=[5 * rand_nonzero((2, 3))],
integers=[randint_nonzero(2, 3)],
int8=[np.array(list(range(-127, 0)) + list(range(1, 127)), dtype="int8")],
uint8=[np.array(list(range(0, 255)), dtype="uint8")],
uint16=[np.array(list(range(0, 65535)), dtype="uint16")],
complex=[randcomplex_nonzero((2, 3))],
empty=[np.asarray([], dtype=config.floatX)],
)
_good_inv_inplace = copymod(
_good_inv, without=["integers", "int8", "uint8", "uint16", "complex"]
)
_grad_inv = copymod(
_good_inv, without=["integers", "int8", "uint8", "uint16", "complex", "empty"]
)
_bad_runtime_inv = dict(
float=[np.zeros((2, 3))],
integers=[np.zeros((2, 3), dtype="int64")],
int8=[np.zeros((2, 3), dtype="int8")],
complex=[np.zeros((2, 3), dtype="complex128")],
)
TestInvBroadcast = makeBroadcastTester( TestInvBroadcast = makeBroadcastTester(
op=tt.inv, op=tt.inv,
expected=lambda x: upcast_int8_nfunc(np.true_divide)(np.int8(1), x), expected=lambda x: upcast_int8_nfunc(np.true_divide)(np.int8(1), x),
...@@ -478,16 +339,6 @@ TestInvBroadcast = makeBroadcastTester( ...@@ -478,16 +339,6 @@ TestInvBroadcast = makeBroadcastTester(
grad_rtol=div_grad_rtol, grad_rtol=div_grad_rtol,
) )
TestInvInplaceBroadcast = makeBroadcastTester(
op=inplace.inv_inplace,
expected=lambda x: _numpy_true_div(np.int8(1), x),
good=_good_inv_inplace,
bad_runtime=_bad_runtime_inv,
grad_rtol=div_grad_rtol,
inplace=True,
)
TestCeilIntDivBroadcast = makeBroadcastTester( TestCeilIntDivBroadcast = makeBroadcastTester(
op=tt.ceil_intdiv, op=tt.ceil_intdiv,
expected=lambda x, y: check_floatX((x, y), (x // y) + ((x % y) != 0)), expected=lambda x, y: check_floatX((x, y), (x // y) + ((x % y) != 0)),
...@@ -508,55 +359,7 @@ TestModBroadcast = makeBroadcastTester( ...@@ -508,55 +359,7 @@ TestModBroadcast = makeBroadcastTester(
grad_eps=1e-5, grad_eps=1e-5,
) )
TestModInplaceBroadcast = makeBroadcastTester(
op=inplace.mod_inplace,
expected=lambda x, y: np.asarray(
x % y, dtype=theano.scalar.basic.upcast(x.dtype, y.dtype)
),
good=copymod(
_good_broadcast_div_mod_normal_float_inplace, ["complex1", "complex2"]
),
grad_eps=1e-5,
inplace=True,
)
_good_broadcast_pow_normal_float = dict(
same_shapes=(rand_ranged(1, 5, (2, 3)), rand_ranged(-3, 3, (2, 3))),
scalar=(rand_ranged(1, 5, (2, 3)), rand_ranged(-3, 3, (1, 1))),
row=(rand_ranged(1, 5, (2, 3)), rand_ranged(-3, 3, (1, 3))),
column=(rand_ranged(1, 5, (2, 3)), rand_ranged(-3, 3, (2, 1))),
dtype_mixup=(rand_ranged(-3, 3, (2, 3)), randint_ranged(-3, 3, (2, 3))),
complex1=(randcomplex(2, 3), randcomplex(2, 3)),
complex2=(randcomplex(2, 3), rand(2, 3)),
# complex3 = (rand(2,3),randcomplex(2,3)), # Inplace on the first element.
empty1=(np.asarray([], dtype=config.floatX), np.asarray([1], dtype=config.floatX)),
empty2=(np.asarray([0], dtype=config.floatX), np.asarray([], dtype=config.floatX)),
empty3=(np.asarray([], dtype=config.floatX), np.asarray([], dtype=config.floatX)),
)
_grad_broadcast_pow_normal = dict(
same_shapes=(rand_ranged(1, 5, (2, 3)), rand_ranged(-3, 3, (2, 3))),
scalar=(rand_ranged(1, 5, (2, 3)), rand_ranged(-3, 3, (1, 1))),
row=(rand_ranged(1, 5, (2, 3)), rand_ranged(-3, 3, (1, 3))),
column=(rand_ranged(1, 5, (2, 3)), rand_ranged(-3, 3, (2, 1))),
# complex1 = (randcomplex(2,3),randcomplex(2,3)),
# complex2 = (randcomplex(2,3),rand(2,3)),
# complex3 = (rand(2,3),randcomplex(2,3)),
# empty1 = (np.asarray([]), np.asarray([1])),
# empty2 = (np.asarray([0]), np.asarray([])),
x_eq_zero=(
np.asarray([0.0], dtype=config.floatX),
np.asarray([2.0], dtype=config.floatX),
), # Test for issue 1780
)
# empty2 case is not supported by numpy.
_good_broadcast_pow_normal_float_pow = copy(_good_broadcast_pow_normal_float)
del _good_broadcast_pow_normal_float_pow["empty2"]
# Disable NAN checking for pow operator per issue #1780 # Disable NAN checking for pow operator per issue #1780
ignore_isfinite_mode = copy(theano.compile.get_default_mode())
ignore_isfinite_mode.check_isfinite = False
TestPowBroadcast = makeBroadcastTester( TestPowBroadcast = makeBroadcastTester(
op=pow, op=pow,
expected=lambda x, y: check_floatX((x, y), x ** y), expected=lambda x, y: check_floatX((x, y), x ** y),
...@@ -566,54 +369,12 @@ TestPowBroadcast = makeBroadcastTester( ...@@ -566,54 +369,12 @@ TestPowBroadcast = makeBroadcastTester(
mode=ignore_isfinite_mode, mode=ignore_isfinite_mode,
) )
TestPowInplaceBroadcast = makeBroadcastTester(
op=inplace.pow_inplace,
expected=lambda x, y: x ** y,
good=_good_broadcast_pow_normal_float_pow,
inplace=True,
mode=ignore_isfinite_mode,
)
_good_broadcast_unary_normal_float_no_empty = copymod(
_good_broadcast_unary_normal_float, without=["empty"]
)
_good_broadcast_unary_normal_float_no_empty_no_complex = copymod(
_good_broadcast_unary_normal_float_no_empty, without=["complex"]
)
_grad_broadcast_unary_normal_no_complex = dict(
normal=[np.asarray(rand_ranged(-5, 5, (2, 3)), dtype=config.floatX)],
corner_case=[corner_case_grad],
)
# Avoid epsilon around integer values
_grad_broadcast_unary_normal_noint = dict(
normal=[(rand_ranged(_eps, 1 - _eps, (2, 3)) + randint(2, 3)).astype(config.floatX)]
)
_grad_broadcast_unary_normal_no_complex_no_corner_case = copymod(
_grad_broadcast_unary_normal_no_complex, without=["corner_case"]
)
# inplace ops when the input is integer and the output is float*
# don't have a well defined behavior. We don't test that case.
TestAbsBroadcast = makeBroadcastTester( TestAbsBroadcast = makeBroadcastTester(
op=tt.abs_, op=tt.abs_,
expected=lambda x: abs(x), expected=lambda x: abs(x),
good=_good_broadcast_unary_normal, good=_good_broadcast_unary_normal,
grad=_grad_broadcast_unary_normal, grad=_grad_broadcast_unary_normal,
) )
_good_broadcast_unary_normal_abs = copy(_good_broadcast_unary_normal)
# Can't do inplace on Abs as the input/output are not of the same type!
del _good_broadcast_unary_normal_abs["complex"]
TestAbsInplaceBroadcast = makeBroadcastTester(
op=inplace.abs__inplace,
expected=lambda x: np.abs(x),
good=_good_broadcast_unary_normal_abs,
inplace=True,
)
TestNegBroadcast = makeBroadcastTester( TestNegBroadcast = makeBroadcastTester(
op=tt.neg, op=tt.neg,
...@@ -621,12 +382,6 @@ TestNegBroadcast = makeBroadcastTester( ...@@ -621,12 +382,6 @@ TestNegBroadcast = makeBroadcastTester(
good=_good_broadcast_unary_normal, good=_good_broadcast_unary_normal,
grad=_grad_broadcast_unary_normal, grad=_grad_broadcast_unary_normal,
) )
TestNegInplaceBroadcast = makeBroadcastTester(
op=inplace.neg_inplace,
expected=lambda x: -x,
good=_good_broadcast_unary_normal,
inplace=True,
)
TestSgnBroadcast = makeBroadcastTester( TestSgnBroadcast = makeBroadcastTester(
op=tt.sgn, op=tt.sgn,
...@@ -634,32 +389,6 @@ TestSgnBroadcast = makeBroadcastTester( ...@@ -634,32 +389,6 @@ TestSgnBroadcast = makeBroadcastTester(
good=_good_broadcast_unary_normal_no_complex, good=_good_broadcast_unary_normal_no_complex,
grad=_grad_broadcast_unary_normal, grad=_grad_broadcast_unary_normal,
) )
TestSgnInplaceBroadcast = makeBroadcastTester(
op=inplace.sgn_inplace,
expected=np.sign,
good=_good_broadcast_unary_normal_no_complex,
inplace=True,
)
TestIntDivBroadcast = makeBroadcastTester(
op=tt.int_div,
expected=lambda x, y: check_floatX((x, y), x // y),
good=_good_broadcast_div_mod_normal_float,
# I don't test the grad as the output is always an integer
# (this is not a continuous output).
# grad=_grad_broadcast_div_mod_normal,
)
TestIntDivInplaceBroadcast = makeBroadcastTester(
op=inplace.int_div_inplace,
expected=lambda x, y: check_floatX((x, y), x // y),
good=_good_broadcast_div_mod_normal_float_inplace,
# I don't test the grad as the output is always an integer
# (this is not a continuous output).
# grad=_grad_broadcast_div_mod_normal,
inplace=True,
)
TestCeilBroadcast = makeBroadcastTester( TestCeilBroadcast = makeBroadcastTester(
op=tt.ceil, op=tt.ceil,
...@@ -671,18 +400,6 @@ TestCeilBroadcast = makeBroadcastTester( ...@@ -671,18 +400,6 @@ TestCeilBroadcast = makeBroadcastTester(
), ),
) )
TestCeilInplaceBroadcast = makeBroadcastTester(
op=inplace.ceil_inplace,
expected=upcast_float16_ufunc(np.ceil),
good=copymod(
_good_broadcast_unary_normal_no_complex,
without=["integers", "int8", "uint8", "uint16"],
),
# corner cases includes a lot of integers: points where Ceil is not
# continuous (not differentiable)
inplace=True,
)
TestFloorBroadcast = makeBroadcastTester( TestFloorBroadcast = makeBroadcastTester(
op=tt.floor, op=tt.floor,
expected=upcast_float16_ufunc(np.floor), expected=upcast_float16_ufunc(np.floor),
...@@ -690,23 +407,6 @@ TestFloorBroadcast = makeBroadcastTester( ...@@ -690,23 +407,6 @@ TestFloorBroadcast = makeBroadcastTester(
grad=_grad_broadcast_unary_normal_noint, grad=_grad_broadcast_unary_normal_noint,
) )
TestFloorInplaceBroadcast = makeBroadcastTester(
op=inplace.floor_inplace,
expected=upcast_float16_ufunc(np.floor),
good=copymod(
_good_broadcast_unary_normal_no_complex,
without=["integers", "int8", "uint8", "uint16"],
),
inplace=True,
)
TestTruncInplaceBroadcast = makeBroadcastTester(
op=inplace.trunc_inplace,
expected=upcast_float16_ufunc(np.trunc),
good=_good_broadcast_unary_normal_no_complex,
inplace=True,
)
TestTruncBroadcast = makeBroadcastTester( TestTruncBroadcast = makeBroadcastTester(
op=tt.trunc, op=tt.trunc,
expected=upcast_float16_ufunc(np.trunc), expected=upcast_float16_ufunc(np.trunc),
...@@ -720,13 +420,6 @@ TestRoundHalfToEvenBroadcast = makeBroadcastTester( ...@@ -720,13 +420,6 @@ TestRoundHalfToEvenBroadcast = makeBroadcastTester(
grad=_grad_broadcast_unary_normal_no_complex_no_corner_case, grad=_grad_broadcast_unary_normal_no_complex_no_corner_case,
) )
TestRoundHalfToEvenInplaceBroadcast = makeBroadcastTester(
op=inplace.round_half_to_even_inplace,
expected=np.round,
good=_good_broadcast_unary_normal_float_no_complex,
inplace=True,
)
# np.vectorize don't handle correctly empty ndarray. # np.vectorize don't handle correctly empty ndarray.
# see in their file numpy/lib/function_base.py in class vectorize.__call__ # see in their file numpy/lib/function_base.py in class vectorize.__call__
# This happen in float32 mode. # This happen in float32 mode.
...@@ -737,13 +430,6 @@ TestRoundHalfAwayFromZeroBroadcast = makeBroadcastTester( ...@@ -737,13 +430,6 @@ TestRoundHalfAwayFromZeroBroadcast = makeBroadcastTester(
grad=_grad_broadcast_unary_normal_no_complex_no_corner_case, grad=_grad_broadcast_unary_normal_no_complex_no_corner_case,
) )
TestRoundHalfAwayFromZeroInplaceBroadcast = makeBroadcastTester(
op=inplace.round_half_away_from_zero_inplace,
expected=lambda a: theano.scalar.basic.round_half_away_from_zero_vec(a),
good=_good_broadcast_unary_normal_float_no_empty_no_complex,
inplace=True,
)
TestSqrBroadcast = makeBroadcastTester( TestSqrBroadcast = makeBroadcastTester(
op=tt.sqr, op=tt.sqr,
expected=np.square, expected=np.square,
...@@ -751,13 +437,6 @@ TestSqrBroadcast = makeBroadcastTester( ...@@ -751,13 +437,6 @@ TestSqrBroadcast = makeBroadcastTester(
grad=_grad_broadcast_unary_normal, grad=_grad_broadcast_unary_normal,
) )
TestSqrInplaceBroadcast = makeBroadcastTester(
op=inplace.sqr_inplace,
expected=np.square,
good=_good_broadcast_unary_normal,
inplace=True,
)
TestExpBroadcast = makeBroadcastTester( TestExpBroadcast = makeBroadcastTester(
op=tt.exp, op=tt.exp,
expected=upcast_float16_ufunc(np.exp), expected=upcast_float16_ufunc(np.exp),
...@@ -769,12 +448,6 @@ TestExpBroadcast = makeBroadcastTester( ...@@ -769,12 +448,6 @@ TestExpBroadcast = makeBroadcastTester(
), ),
grad=_grad_broadcast_unary_normal, grad=_grad_broadcast_unary_normal,
) )
TestExpInplaceBroadcast = makeBroadcastTester(
op=inplace.exp_inplace,
expected=np.exp,
good=_good_broadcast_unary_normal_float,
inplace=True,
)
TestExp2Broadcast = makeBroadcastTester( TestExp2Broadcast = makeBroadcastTester(
op=tt.exp2, op=tt.exp2,
...@@ -782,13 +455,6 @@ TestExp2Broadcast = makeBroadcastTester( ...@@ -782,13 +455,6 @@ TestExp2Broadcast = makeBroadcastTester(
good=_good_broadcast_unary_normal, good=_good_broadcast_unary_normal,
grad=_grad_broadcast_unary_normal, grad=_grad_broadcast_unary_normal,
) )
TestExp2InplaceBroadcast = makeBroadcastTester(
op=inplace.exp2_inplace,
expected=np.exp2,
good=_good_broadcast_unary_normal_float,
inplace=True,
)
TestExpm1Broadcast = makeBroadcastTester( TestExpm1Broadcast = makeBroadcastTester(
op=tt.expm1, op=tt.expm1,
...@@ -801,25 +467,7 @@ TestExpm1Broadcast = makeBroadcastTester( ...@@ -801,25 +467,7 @@ TestExpm1Broadcast = makeBroadcastTester(
), ),
grad=_grad_broadcast_unary_normal, grad=_grad_broadcast_unary_normal,
) )
TestExpm1InplaceBroadcast = makeBroadcastTester(
op=inplace.expm1_inplace,
expected=np.expm1,
good=_good_broadcast_unary_normal_float,
inplace=True,
)
_good_broadcast_unary_positive = dict(
normal=(rand_ranged(0.001, 5, (2, 3)),),
integers=(randint_ranged(1, 5, (2, 3)),),
uint8=[np.arange(1, 256, dtype="uint8")],
complex=(randc128_ranged(1, 5, (2, 3)),),
empty=(np.asarray([], dtype=config.floatX),),
)
_good_broadcast_unary_positive_float = copymod(
_good_broadcast_unary_positive, without=["integers", "uint8"]
)
_grad_broadcast_unary_positive = dict( _grad_broadcast_unary_positive = dict(
normal=(rand_ranged(_eps, 5, (2, 3)),), normal=(rand_ranged(_eps, 5, (2, 3)),),
...@@ -831,12 +479,6 @@ TestLogBroadcast = makeBroadcastTester( ...@@ -831,12 +479,6 @@ TestLogBroadcast = makeBroadcastTester(
good=_good_broadcast_unary_positive, good=_good_broadcast_unary_positive,
grad=_grad_broadcast_unary_positive, grad=_grad_broadcast_unary_positive,
) )
TestLogInplaceBroadcast = makeBroadcastTester(
op=inplace.log_inplace,
expected=np.log,
good=_good_broadcast_unary_positive_float,
inplace=True,
)
TestLog2Broadcast = makeBroadcastTester( TestLog2Broadcast = makeBroadcastTester(
op=tt.log2, op=tt.log2,
...@@ -844,12 +486,6 @@ TestLog2Broadcast = makeBroadcastTester( ...@@ -844,12 +486,6 @@ TestLog2Broadcast = makeBroadcastTester(
good=_good_broadcast_unary_positive, good=_good_broadcast_unary_positive,
grad=_grad_broadcast_unary_positive, grad=_grad_broadcast_unary_positive,
) )
TestLog2InplaceBroadcast = makeBroadcastTester(
op=inplace.log2_inplace,
expected=np.log2,
good=_good_broadcast_unary_positive_float,
inplace=True,
)
TestLog10Broadcast = makeBroadcastTester( TestLog10Broadcast = makeBroadcastTester(
op=tt.log10, op=tt.log10,
...@@ -857,12 +493,6 @@ TestLog10Broadcast = makeBroadcastTester( ...@@ -857,12 +493,6 @@ TestLog10Broadcast = makeBroadcastTester(
good=_good_broadcast_unary_positive, good=_good_broadcast_unary_positive,
grad=_grad_broadcast_unary_positive, grad=_grad_broadcast_unary_positive,
) )
TestLog10InplaceBroadcast = makeBroadcastTester(
op=inplace.log10_inplace,
expected=np.log10,
good=_good_broadcast_unary_positive_float,
inplace=True,
)
TestLog1pBroadcast = makeBroadcastTester( TestLog1pBroadcast = makeBroadcastTester(
op=tt.log1p, op=tt.log1p,
...@@ -870,12 +500,6 @@ TestLog1pBroadcast = makeBroadcastTester( ...@@ -870,12 +500,6 @@ TestLog1pBroadcast = makeBroadcastTester(
good=_good_broadcast_unary_positive, good=_good_broadcast_unary_positive,
grad=_grad_broadcast_unary_positive, grad=_grad_broadcast_unary_positive,
) )
TestLog1pInplaceBroadcast = makeBroadcastTester(
op=inplace.log1p_inplace,
expected=np.log1p,
good=_good_broadcast_unary_positive_float,
inplace=True,
)
TestSqrtBroadcast = makeBroadcastTester( TestSqrtBroadcast = makeBroadcastTester(
op=tt.sqrt, op=tt.sqrt,
...@@ -883,34 +507,11 @@ TestSqrtBroadcast = makeBroadcastTester( ...@@ -883,34 +507,11 @@ TestSqrtBroadcast = makeBroadcastTester(
good=_good_broadcast_unary_positive, good=_good_broadcast_unary_positive,
grad=_grad_broadcast_unary_positive, grad=_grad_broadcast_unary_positive,
) )
TestSqrtInplaceBroadcast = makeBroadcastTester(
op=inplace.sqrt_inplace,
expected=np.sqrt,
good=_good_broadcast_unary_positive_float,
inplace=True,
)
_good_broadcast_unary_wide = dict(
normal=(rand_ranged(-1000, 1000, (2, 3)),),
integers=(randint_ranged(-1000, 1000, (2, 3)),),
int8=[np.arange(-127, 128, dtype="int8")],
uint8=[np.arange(0, 255, dtype="uint8")],
uint16=[np.arange(0, 65535, dtype="uint16")],
complex=(randc128_ranged(-1000, 1000, (2, 3)),),
empty=(np.asarray([], dtype=config.floatX),),
)
_good_broadcast_unary_wide_float = copymod(
_good_broadcast_unary_wide, without=["integers", "int8", "uint8", "uint16"]
)
_grad_broadcast_unary_wide = dict( _grad_broadcast_unary_wide = dict(
normal=(rand_ranged(-1000, 1000, (2, 3)),), normal=(rand_ranged(-1000, 1000, (2, 3)),),
) )
if theano.config.floatX == "float32":
angle_eps = 1e-4
else:
angle_eps = 1e-10
TestDeg2radBroadcast = makeBroadcastTester( TestDeg2radBroadcast = makeBroadcastTester(
op=tt.deg2rad, op=tt.deg2rad,
expected=upcast_float16_ufunc(np.deg2rad), expected=upcast_float16_ufunc(np.deg2rad),
...@@ -918,13 +519,6 @@ TestDeg2radBroadcast = makeBroadcastTester( ...@@ -918,13 +519,6 @@ TestDeg2radBroadcast = makeBroadcastTester(
grad=_grad_broadcast_unary_normal_no_complex, grad=_grad_broadcast_unary_normal_no_complex,
eps=angle_eps, eps=angle_eps,
) )
TestDeg2radInplaceBroadcast = makeBroadcastTester(
op=inplace.deg2rad_inplace,
expected=np.deg2rad,
good=_good_broadcast_unary_normal_float_no_complex,
inplace=True,
eps=angle_eps,
)
TestRad2degBroadcast = makeBroadcastTester( TestRad2degBroadcast = makeBroadcastTester(
op=tt.rad2deg, op=tt.rad2deg,
...@@ -933,13 +527,6 @@ TestRad2degBroadcast = makeBroadcastTester( ...@@ -933,13 +527,6 @@ TestRad2degBroadcast = makeBroadcastTester(
grad=_grad_broadcast_unary_normal_no_complex, grad=_grad_broadcast_unary_normal_no_complex,
eps=angle_eps, eps=angle_eps,
) )
TestRad2degInplaceBroadcast = makeBroadcastTester(
op=inplace.rad2deg_inplace,
expected=np.rad2deg,
good=_good_broadcast_unary_normal_float_no_complex,
inplace=True,
eps=angle_eps,
)
TestSinBroadcast = makeBroadcastTester( TestSinBroadcast = makeBroadcastTester(
op=tt.sin, op=tt.sin,
...@@ -947,26 +534,6 @@ TestSinBroadcast = makeBroadcastTester( ...@@ -947,26 +534,6 @@ TestSinBroadcast = makeBroadcastTester(
good=_good_broadcast_unary_wide, good=_good_broadcast_unary_wide,
grad=_grad_broadcast_unary_wide, grad=_grad_broadcast_unary_wide,
) )
TestSinInplaceBroadcast = makeBroadcastTester(
op=inplace.sin_inplace,
expected=np.sin,
good=_good_broadcast_unary_wide_float,
inplace=True,
)
_good_broadcast_unary_arcsin = dict(
normal=(rand_ranged(-1, 1, (2, 3)),),
integers=(randint_ranged(-1, 1, (2, 3)),),
int8=[np.arange(-1, 2, dtype="int8")],
uint8=[np.arange(0, 2, dtype="uint8")],
uint16=[np.arange(0, 2, dtype="uint16")],
complex=(randc128_ranged(-1, 1, (2, 3)),),
empty=(np.asarray([], dtype=config.floatX),),
)
_good_broadcast_unary_arcsin_float = copymod(
_good_broadcast_unary_arcsin, without=["integers", "int8", "uint8", "uint16"]
)
# The actual range is [-1, 1] but the numerical gradient is too # The actual range is [-1, 1] but the numerical gradient is too
# unstable near those values # unstable near those values
...@@ -980,12 +547,6 @@ TestArcsinBroadcast = makeBroadcastTester( ...@@ -980,12 +547,6 @@ TestArcsinBroadcast = makeBroadcastTester(
good=_good_broadcast_unary_arcsin, good=_good_broadcast_unary_arcsin,
grad=_grad_broadcast_unary_arcsin, grad=_grad_broadcast_unary_arcsin,
) )
TestArcsinInplaceBroadcast = makeBroadcastTester(
op=inplace.arcsin_inplace,
expected=np.arcsin,
good=_good_broadcast_unary_arcsin_float,
inplace=True,
)
TestCosBroadcast = makeBroadcastTester( TestCosBroadcast = makeBroadcastTester(
op=tt.cos, op=tt.cos,
...@@ -993,12 +554,6 @@ TestCosBroadcast = makeBroadcastTester( ...@@ -993,12 +554,6 @@ TestCosBroadcast = makeBroadcastTester(
good=_good_broadcast_unary_wide, good=_good_broadcast_unary_wide,
grad=_grad_broadcast_unary_wide, grad=_grad_broadcast_unary_wide,
) )
TestCosInplaceBroadcast = makeBroadcastTester(
op=inplace.cos_inplace,
expected=np.cos,
good=_good_broadcast_unary_wide_float,
inplace=True,
)
def test_py_c_match(): def test_py_c_match():
...@@ -1014,23 +569,7 @@ TestArccosBroadcast = makeBroadcastTester( ...@@ -1014,23 +569,7 @@ TestArccosBroadcast = makeBroadcastTester(
good=_good_broadcast_unary_arcsin, good=_good_broadcast_unary_arcsin,
grad=_grad_broadcast_unary_arcsin, grad=_grad_broadcast_unary_arcsin,
) )
TestArccosInplaceBroadcast = makeBroadcastTester(
op=inplace.arccos_inplace,
expected=np.arccos,
good=_good_broadcast_unary_arcsin_float,
inplace=True,
)
_good_broadcast_unary_tan = dict(
normal=(rand_ranged(-3.14, 3.14, (2, 3)),),
shifted=(rand_ranged(3.15, 6.28, (2, 3)),),
integers=(randint_ranged(-3, 3, (2, 3)),),
int8=[np.arange(-3, 4, dtype="int8")],
uint8=[np.arange(0, 4, dtype="uint8")],
uint16=[np.arange(0, 4, dtype="uint16")],
complex=(randc128_ranged(-3.14, 3.14, (2, 3)),),
empty=(np.asarray([], dtype=config.floatX),),
)
# We do not want to test around the discontinuity. # We do not want to test around the discontinuity.
_grad_broadcast_unary_tan = dict( _grad_broadcast_unary_tan = dict(
normal=(rand_ranged(-1.5, 1.5, (2, 3)),), shifted=(rand_ranged(1.6, 4.6, (2, 3)),) normal=(rand_ranged(-1.5, 1.5, (2, 3)),), shifted=(rand_ranged(1.6, 4.6, (2, 3)),)
...@@ -1043,51 +582,12 @@ TestTanBroadcast = makeBroadcastTester( ...@@ -1043,51 +582,12 @@ TestTanBroadcast = makeBroadcastTester(
grad=_grad_broadcast_unary_tan, grad=_grad_broadcast_unary_tan,
) )
TestTanInplaceBroadcast = makeBroadcastTester(
op=inplace.tan_inplace,
expected=np.tan,
good=copymod(
_good_broadcast_unary_tan, without=["integers", "int8", "uint8", "uint16"]
),
inplace=True,
)
TestArctanBroadcast = makeBroadcastTester( TestArctanBroadcast = makeBroadcastTester(
op=tt.arctan, op=tt.arctan,
expected=upcast_float16_ufunc(np.arctan), expected=upcast_float16_ufunc(np.arctan),
good=_good_broadcast_unary_wide, good=_good_broadcast_unary_wide,
grad=_grad_broadcast_unary_wide, grad=_grad_broadcast_unary_wide,
) )
TestArctanInplaceBroadcast = makeBroadcastTester(
op=inplace.arctan_inplace,
expected=np.arctan,
good=_good_broadcast_unary_wide_float,
inplace=True,
)
_good_broadcast_binary_arctan2 = dict(
same_shapes=(rand(2, 3), rand(2, 3)),
not_same_dimensions=(rand(2, 2), rand(2)),
scalar=(rand(2, 3), rand(1, 1)),
row=(rand(2, 3), rand(1, 3)),
column=(rand(2, 3), rand(2, 1)),
integers=(randint(2, 3), randint(2, 3)),
int8=[
np.arange(-127, 128, dtype="int8"),
np.arange(-127, 128, dtype="int8")[:, np.newaxis],
],
uint8=[
np.arange(0, 128, dtype="uint8"),
np.arange(0, 128, dtype="uint8")[:, np.newaxis],
],
uint16=[
np.arange(0, 128, dtype="uint16"),
np.arange(0, 128, dtype="uint16")[:, np.newaxis],
],
dtype_mixup_1=(rand(2, 3), randint(2, 3)),
dtype_mixup_2=(randint(2, 3), rand(2, 3)),
empty=(np.asarray([], dtype=config.floatX), np.asarray([1], dtype=config.floatX)),
)
_grad_broadcast_binary_arctan2 = dict( _grad_broadcast_binary_arctan2 = dict(
same_shapes=(rand(2, 3), rand(2, 3)), same_shapes=(rand(2, 3), rand(2, 3)),
...@@ -1103,16 +603,6 @@ TestArctan2Broadcast = makeBroadcastTester( ...@@ -1103,16 +603,6 @@ TestArctan2Broadcast = makeBroadcastTester(
grad=_grad_broadcast_binary_arctan2, grad=_grad_broadcast_binary_arctan2,
) )
TestArctan2InplaceBroadcast = makeBroadcastTester(
op=inplace.arctan2_inplace,
expected=np.arctan2,
good=copymod(
_good_broadcast_binary_arctan2,
without=["integers", "int8", "uint8", "uint16", "dtype_mixup_2"],
),
inplace=True,
)
TestCoshBroadcast = makeBroadcastTester( TestCoshBroadcast = makeBroadcastTester(
op=tt.cosh, op=tt.cosh,
expected=upcast_float16_ufunc(np.cosh), expected=upcast_float16_ufunc(np.cosh),
...@@ -1124,20 +614,7 @@ TestCoshBroadcast = makeBroadcastTester( ...@@ -1124,20 +614,7 @@ TestCoshBroadcast = makeBroadcastTester(
), ),
grad=_grad_broadcast_unary_normal, grad=_grad_broadcast_unary_normal,
) )
TestCoshInplaceBroadcast = makeBroadcastTester(
op=inplace.cosh_inplace,
expected=np.cosh,
good=_good_broadcast_unary_normal_float,
inplace=True,
)
_good_broadcast_unary_arccosh = dict(
normal=(rand_ranged(1, 1000, (2, 3)),),
integers=(randint_ranged(1, 1000, (2, 3)),),
uint8=[np.arange(1, 256, dtype="uint8")],
complex=(randc128_ranged(1, 1000, (2, 3)),),
empty=(np.asarray([], dtype=config.floatX),),
)
_grad_broadcast_unary_arccosh = dict( _grad_broadcast_unary_arccosh = dict(
normal=(rand_ranged(1 + _eps, 1000, (2, 3)),), normal=(rand_ranged(1 + _eps, 1000, (2, 3)),),
) )
...@@ -1148,12 +625,6 @@ TestArccoshBroadcast = makeBroadcastTester( ...@@ -1148,12 +625,6 @@ TestArccoshBroadcast = makeBroadcastTester(
good=_good_broadcast_unary_arccosh, good=_good_broadcast_unary_arccosh,
grad=_grad_broadcast_unary_arccosh, grad=_grad_broadcast_unary_arccosh,
) )
TestArccoshInplaceBroadcast = makeBroadcastTester(
op=inplace.arccosh_inplace,
expected=np.arccosh,
good=copymod(_good_broadcast_unary_arccosh, without=["integers", "uint8"]),
inplace=True,
)
TestSinhBroadcast = makeBroadcastTester( TestSinhBroadcast = makeBroadcastTester(
op=tt.sinh, op=tt.sinh,
...@@ -1166,12 +637,6 @@ TestSinhBroadcast = makeBroadcastTester( ...@@ -1166,12 +637,6 @@ TestSinhBroadcast = makeBroadcastTester(
), ),
grad=_grad_broadcast_unary_normal, grad=_grad_broadcast_unary_normal,
) )
TestSinhInplaceBroadcast = makeBroadcastTester(
op=inplace.sinh_inplace,
expected=np.sinh,
good=_good_broadcast_unary_normal_float,
inplace=True,
)
TestArcsinhBroadcast = makeBroadcastTester( TestArcsinhBroadcast = makeBroadcastTester(
op=tt.arcsinh, op=tt.arcsinh,
...@@ -1179,12 +644,6 @@ TestArcsinhBroadcast = makeBroadcastTester( ...@@ -1179,12 +644,6 @@ TestArcsinhBroadcast = makeBroadcastTester(
good=_good_broadcast_unary_normal, good=_good_broadcast_unary_normal,
grad=_grad_broadcast_unary_normal, grad=_grad_broadcast_unary_normal,
) )
TestArcsinhInplaceBroadcast = makeBroadcastTester(
op=inplace.arcsinh_inplace,
expected=np.arcsinh,
good=_good_broadcast_unary_normal_float,
inplace=True,
)
TestTanhBroadcast = makeBroadcastTester( TestTanhBroadcast = makeBroadcastTester(
op=tt.tanh, op=tt.tanh,
...@@ -1192,22 +651,7 @@ TestTanhBroadcast = makeBroadcastTester( ...@@ -1192,22 +651,7 @@ TestTanhBroadcast = makeBroadcastTester(
good=_good_broadcast_unary_normal, good=_good_broadcast_unary_normal,
grad=_grad_broadcast_unary_normal, grad=_grad_broadcast_unary_normal,
) )
TestTanhInplaceBroadcast = makeBroadcastTester(
op=inplace.tanh_inplace,
expected=np.tanh,
good=_good_broadcast_unary_normal_float,
inplace=True,
)
_good_broadcast_unary_arctanh = dict(
normal=(rand_ranged(-1 + _eps, 1 - _eps, (2, 3)),),
integers=(randint_ranged(-1 + _eps, 1 - _eps, (2, 3)),),
int8=[np.arange(0, 1, dtype="int8")],
uint8=[np.arange(0, 1, dtype="uint8")],
uint16=[np.arange(0, 1, dtype="uint16")],
complex=(randc128_ranged(-1 + _eps, 1 - _eps, (2, 3)),),
empty=(np.asarray([], dtype=config.floatX),),
)
_grad_broadcast_unary_arctanh = dict( _grad_broadcast_unary_arctanh = dict(
normal=(rand_ranged(-1 + _eps, 1 - _eps, (2, 3)),), normal=(rand_ranged(-1 + _eps, 1 - _eps, (2, 3)),),
) )
...@@ -1218,14 +662,6 @@ TestArctanhBroadcast = makeBroadcastTester( ...@@ -1218,14 +662,6 @@ TestArctanhBroadcast = makeBroadcastTester(
good=_good_broadcast_unary_arctanh, good=_good_broadcast_unary_arctanh,
grad=_grad_broadcast_unary_arctanh, grad=_grad_broadcast_unary_arctanh,
) )
TestArctanhInplaceBroadcast = makeBroadcastTester(
op=inplace.arctanh_inplace,
expected=np.arctanh,
good=copymod(
_good_broadcast_unary_arctanh, without=["integers", "int8", "uint8", "uint16"]
),
inplace=True,
)
TestZerosLikeBroadcast = makeBroadcastTester( TestZerosLikeBroadcast = makeBroadcastTester(
op=tt.zeros_like, op=tt.zeros_like,
...@@ -1269,12 +705,6 @@ TestComplexFromPolarBroadcast = makeBroadcastTester( ...@@ -1269,12 +705,6 @@ TestComplexFromPolarBroadcast = makeBroadcastTester(
TestConjBroadcast = makeBroadcastTester( TestConjBroadcast = makeBroadcastTester(
op=tt.conj, expected=np.conj, good=_good_broadcast_unary_normal op=tt.conj, expected=np.conj, good=_good_broadcast_unary_normal
) )
TestConjInplaceBroadcast = makeBroadcastTester(
op=inplace.conj_inplace,
expected=np.conj,
good=_good_broadcast_unary_normal,
inplace=True,
)
TestDot = makeTester( TestDot = makeTester(
...@@ -4005,20 +3435,14 @@ class TestBitwise: ...@@ -4005,20 +3435,14 @@ class TestBitwise:
v = fn(l, r) v = fn(l, r)
assert np.all(v == (operator.or_(l, r))), (l, r, v) assert np.all(v == (operator.or_(l, r))), (l, r, v)
def test_xor(self): def test_XOR(self):
for dtype in self.dtype: for dtype in self.dtype:
x, y = vector(dtype=dtype), vector(dtype=dtype) x, y = vector(dtype=dtype), vector(dtype=dtype)
fn = inplace_func([x, y], x ^ y) fn = inplace_func([x, y], x ^ y)
ix = x
ix = inplace.xor_inplace(ix, y)
gn = inplace_func([x, y], ix)
l = theano._asarray([0, 0, 1, 1], dtype=dtype) l = theano._asarray([0, 0, 1, 1], dtype=dtype)
r = theano._asarray([0, 1, 0, 1], dtype=dtype) r = theano._asarray([0, 1, 0, 1], dtype=dtype)
v = fn(l, r) v = fn(l, r)
assert np.all(v == (operator.xor(l, r))), (l, r, v) assert np.all(v == (operator.xor(l, r))), (l, r, v)
v = gn(l, r)
# test the in-place stuff
assert np.all(l == np.asarray([0, 1, 1, 0])), l
def test_and(self): def test_and(self):
for dtype in self.dtype: for dtype in self.dtype:
...@@ -4105,24 +3529,6 @@ class TestExp: ...@@ -4105,24 +3529,6 @@ class TestExp:
], ],
) )
fails = (
theano.config.cycle_detection == "fast" and theano.config.mode != "FAST_COMPILE"
)
@pytest.mark.xfail(fails, reason="cycle detection is fast and mode is FAST_COMPILE")
def test_grad_1(self):
utt.verify_grad(
inplace.exp_inplace,
[
np.asarray(
[
[1.5089518, 1.48439076, -4.7820262],
[2.04832468, 0.50791564, -1.58892269],
]
)
],
)
def test_int(self): def test_int(self):
x = ivector() x = ivector()
f = function([x], exp(x)) f = function([x], exp(x))
......
import numpy as np
import pytest
from tests import unittest_tools as utt
from tests.tensor.utils import (
_bad_build_broadcast_binary_normal,
_bad_runtime_broadcast_binary_normal,
_bad_runtime_inv,
_good_broadcast_binary_arctan2,
_good_broadcast_binary_normal,
_good_broadcast_div_mod_normal_float_inplace,
_good_broadcast_pow_normal_float_pow,
_good_broadcast_unary_arccosh,
_good_broadcast_unary_arcsin_float,
_good_broadcast_unary_arctanh,
_good_broadcast_unary_normal,
_good_broadcast_unary_normal_abs,
_good_broadcast_unary_normal_float,
_good_broadcast_unary_normal_float_no_complex,
_good_broadcast_unary_normal_float_no_empty_no_complex,
_good_broadcast_unary_normal_no_complex,
_good_broadcast_unary_positive_float,
_good_broadcast_unary_tan,
_good_broadcast_unary_wide_float,
_good_inv_inplace,
_numpy_true_div,
angle_eps,
check_floatX,
copymod,
div_grad_rtol,
ignore_isfinite_mode,
inplace_func,
makeBroadcastTester,
upcast_float16_ufunc,
)
from theano import _asarray, config
from theano.scalar.basic import round_half_away_from_zero_vec, upcast
from theano.tensor import vector
from theano.tensor.inplace import (
abs__inplace,
add_inplace,
arccos_inplace,
arccosh_inplace,
arcsin_inplace,
arcsinh_inplace,
arctan2_inplace,
arctan_inplace,
arctanh_inplace,
ceil_inplace,
conj_inplace,
cos_inplace,
cosh_inplace,
deg2rad_inplace,
exp2_inplace,
exp_inplace,
expm1_inplace,
floor_inplace,
int_div_inplace,
inv_inplace,
log1p_inplace,
log2_inplace,
log10_inplace,
log_inplace,
maximum_inplace,
minimum_inplace,
mod_inplace,
mul_inplace,
neg_inplace,
pow_inplace,
rad2deg_inplace,
round_half_away_from_zero_inplace,
round_half_to_even_inplace,
sgn_inplace,
sin_inplace,
sinh_inplace,
sqr_inplace,
sqrt_inplace,
sub_inplace,
tan_inplace,
tanh_inplace,
true_div_inplace,
trunc_inplace,
xor_inplace,
)
TestAddInplaceBroadcast = makeBroadcastTester(
op=add_inplace,
expected=lambda x, y: x + y,
good=_good_broadcast_binary_normal,
bad_build=_bad_build_broadcast_binary_normal,
bad_runtime=_bad_runtime_broadcast_binary_normal,
inplace=True,
)
TestSubInplaceBroadcast = makeBroadcastTester(
op=sub_inplace,
expected=lambda x, y: x - y,
good=_good_broadcast_binary_normal,
bad_build=_bad_build_broadcast_binary_normal,
bad_runtime=_bad_runtime_broadcast_binary_normal,
inplace=True,
)
TestMaximumInplaceBroadcast = makeBroadcastTester(
op=maximum_inplace,
expected=np.maximum,
good=_good_broadcast_binary_normal,
bad_build=_bad_build_broadcast_binary_normal,
bad_runtime=_bad_runtime_broadcast_binary_normal,
inplace=True,
)
TestMinimumInplaceBroadcast = makeBroadcastTester(
op=minimum_inplace,
expected=np.minimum,
good=_good_broadcast_binary_normal,
bad_build=_bad_build_broadcast_binary_normal,
bad_runtime=_bad_runtime_broadcast_binary_normal,
inplace=True,
)
TestMulInplaceBroadcast = makeBroadcastTester(
op=mul_inplace,
expected=lambda x, y: x * y,
good=_good_broadcast_binary_normal,
bad_build=_bad_build_broadcast_binary_normal,
bad_runtime=_bad_runtime_broadcast_binary_normal,
inplace=True,
)
TestTrueDivInplaceBroadcast = makeBroadcastTester(
op=true_div_inplace,
expected=_numpy_true_div,
good=copymod(
_good_broadcast_div_mod_normal_float_inplace,
# The output is now in float, we cannot work inplace on an int.
without=["integer", "uint8", "uint16", "int8"],
),
grad_rtol=div_grad_rtol,
inplace=True,
)
TestInvInplaceBroadcast = makeBroadcastTester(
op=inv_inplace,
expected=lambda x: _numpy_true_div(np.int8(1), x),
good=_good_inv_inplace,
bad_runtime=_bad_runtime_inv,
grad_rtol=div_grad_rtol,
inplace=True,
)
TestModInplaceBroadcast = makeBroadcastTester(
op=mod_inplace,
expected=lambda x, y: np.asarray(x % y, dtype=upcast(x.dtype, y.dtype)),
good=copymod(
_good_broadcast_div_mod_normal_float_inplace, ["complex1", "complex2"]
),
grad_eps=1e-5,
inplace=True,
)
TestPowInplaceBroadcast = makeBroadcastTester(
op=pow_inplace,
expected=lambda x, y: x ** y,
good=_good_broadcast_pow_normal_float_pow,
inplace=True,
mode=ignore_isfinite_mode,
)
TestNegInplaceBroadcast = makeBroadcastTester(
op=neg_inplace,
expected=lambda x: -x,
good=_good_broadcast_unary_normal,
inplace=True,
)
TestSgnInplaceBroadcast = makeBroadcastTester(
op=sgn_inplace,
expected=np.sign,
good=_good_broadcast_unary_normal_no_complex,
inplace=True,
)
TestAbsInplaceBroadcast = makeBroadcastTester(
op=abs__inplace,
expected=lambda x: np.abs(x),
good=_good_broadcast_unary_normal_abs,
inplace=True,
)
TestIntDivInplaceBroadcast = makeBroadcastTester(
op=int_div_inplace,
expected=lambda x, y: check_floatX((x, y), x // y),
good=_good_broadcast_div_mod_normal_float_inplace,
# I don't test the grad as the output is always an integer
# (this is not a continuous output).
# grad=_grad_broadcast_div_mod_normal,
inplace=True,
)
TestCeilInplaceBroadcast = makeBroadcastTester(
op=ceil_inplace,
expected=upcast_float16_ufunc(np.ceil),
good=copymod(
_good_broadcast_unary_normal_no_complex,
without=["integers", "int8", "uint8", "uint16"],
),
# corner cases includes a lot of integers: points where Ceil is not
# continuous (not differentiable)
inplace=True,
)
TestFloorInplaceBroadcast = makeBroadcastTester(
op=floor_inplace,
expected=upcast_float16_ufunc(np.floor),
good=copymod(
_good_broadcast_unary_normal_no_complex,
without=["integers", "int8", "uint8", "uint16"],
),
inplace=True,
)
TestTruncInplaceBroadcast = makeBroadcastTester(
op=trunc_inplace,
expected=upcast_float16_ufunc(np.trunc),
good=_good_broadcast_unary_normal_no_complex,
inplace=True,
)
TestRoundHalfToEvenInplaceBroadcast = makeBroadcastTester(
op=round_half_to_even_inplace,
expected=np.round,
good=_good_broadcast_unary_normal_float_no_complex,
inplace=True,
)
TestRoundHalfAwayFromZeroInplaceBroadcast = makeBroadcastTester(
op=round_half_away_from_zero_inplace,
expected=lambda a: round_half_away_from_zero_vec(a),
good=_good_broadcast_unary_normal_float_no_empty_no_complex,
inplace=True,
)
TestSqrInplaceBroadcast = makeBroadcastTester(
op=sqr_inplace,
expected=np.square,
good=_good_broadcast_unary_normal,
inplace=True,
)
TestExpInplaceBroadcast = makeBroadcastTester(
op=exp_inplace,
expected=np.exp,
good=_good_broadcast_unary_normal_float,
inplace=True,
)
TestExp2InplaceBroadcast = makeBroadcastTester(
op=exp2_inplace,
expected=np.exp2,
good=_good_broadcast_unary_normal_float,
inplace=True,
)
TestExpm1InplaceBroadcast = makeBroadcastTester(
op=expm1_inplace,
expected=np.expm1,
good=_good_broadcast_unary_normal_float,
inplace=True,
)
TestLogInplaceBroadcast = makeBroadcastTester(
op=log_inplace,
expected=np.log,
good=_good_broadcast_unary_positive_float,
inplace=True,
)
TestLog2InplaceBroadcast = makeBroadcastTester(
op=log2_inplace,
expected=np.log2,
good=_good_broadcast_unary_positive_float,
inplace=True,
)
TestLog10InplaceBroadcast = makeBroadcastTester(
op=log10_inplace,
expected=np.log10,
good=_good_broadcast_unary_positive_float,
inplace=True,
)
TestLog1pInplaceBroadcast = makeBroadcastTester(
op=log1p_inplace,
expected=np.log1p,
good=_good_broadcast_unary_positive_float,
inplace=True,
)
TestSqrtInplaceBroadcast = makeBroadcastTester(
op=sqrt_inplace,
expected=np.sqrt,
good=_good_broadcast_unary_positive_float,
inplace=True,
)
TestDeg2radInplaceBroadcast = makeBroadcastTester(
op=deg2rad_inplace,
expected=np.deg2rad,
good=_good_broadcast_unary_normal_float_no_complex,
inplace=True,
eps=angle_eps,
)
TestRad2degInplaceBroadcast = makeBroadcastTester(
op=rad2deg_inplace,
expected=np.rad2deg,
good=_good_broadcast_unary_normal_float_no_complex,
inplace=True,
eps=angle_eps,
)
TestSinInplaceBroadcast = makeBroadcastTester(
op=sin_inplace,
expected=np.sin,
good=_good_broadcast_unary_wide_float,
inplace=True,
)
TestArcsinInplaceBroadcast = makeBroadcastTester(
op=arcsin_inplace,
expected=np.arcsin,
good=_good_broadcast_unary_arcsin_float,
inplace=True,
)
TestCosInplaceBroadcast = makeBroadcastTester(
op=cos_inplace,
expected=np.cos,
good=_good_broadcast_unary_wide_float,
inplace=True,
)
TestArccosInplaceBroadcast = makeBroadcastTester(
op=arccos_inplace,
expected=np.arccos,
good=_good_broadcast_unary_arcsin_float,
inplace=True,
)
TestTanInplaceBroadcast = makeBroadcastTester(
op=tan_inplace,
expected=np.tan,
good=copymod(
_good_broadcast_unary_tan, without=["integers", "int8", "uint8", "uint16"]
),
inplace=True,
)
TestArctanInplaceBroadcast = makeBroadcastTester(
op=arctan_inplace,
expected=np.arctan,
good=_good_broadcast_unary_wide_float,
inplace=True,
)
TestArctan2InplaceBroadcast = makeBroadcastTester(
op=arctan2_inplace,
expected=np.arctan2,
good=copymod(
_good_broadcast_binary_arctan2,
without=["integers", "int8", "uint8", "uint16", "dtype_mixup_2"],
),
inplace=True,
)
TestCoshInplaceBroadcast = makeBroadcastTester(
op=cosh_inplace,
expected=np.cosh,
good=_good_broadcast_unary_normal_float,
inplace=True,
)
TestArccoshInplaceBroadcast = makeBroadcastTester(
op=arccosh_inplace,
expected=np.arccosh,
good=copymod(_good_broadcast_unary_arccosh, without=["integers", "uint8"]),
inplace=True,
)
TestSinhInplaceBroadcast = makeBroadcastTester(
op=sinh_inplace,
expected=np.sinh,
good=_good_broadcast_unary_normal_float,
inplace=True,
)
TestArcsinhInplaceBroadcast = makeBroadcastTester(
op=arcsinh_inplace,
expected=np.arcsinh,
good=_good_broadcast_unary_normal_float,
inplace=True,
)
TestTanhInplaceBroadcast = makeBroadcastTester(
op=tanh_inplace,
expected=np.tanh,
good=_good_broadcast_unary_normal_float,
inplace=True,
)
TestArctanhInplaceBroadcast = makeBroadcastTester(
op=arctanh_inplace,
expected=np.arctanh,
good=copymod(
_good_broadcast_unary_arctanh, without=["integers", "int8", "uint8", "uint16"]
),
inplace=True,
)
TestConjInplaceBroadcast = makeBroadcastTester(
op=conj_inplace,
expected=np.conj,
good=_good_broadcast_unary_normal,
inplace=True,
)
@pytest.mark.xfail(
config.cycle_detection == "fast" and config.mode != "FAST_COMPILE",
reason="Cycle detection is fast and mode is FAST_COMPILE",
)
def test_exp_inplace_grad_1():
utt.verify_grad(
exp_inplace,
[
np.asarray(
[
[1.5089518, 1.48439076, -4.7820262],
[2.04832468, 0.50791564, -1.58892269],
]
)
],
)
def test_XOR_inplace():
dtype = [
"int8",
"int16",
"int32",
"int64",
]
for dtype in dtype:
x, y = vector(dtype=dtype), vector(dtype=dtype)
l = _asarray([0, 0, 1, 1], dtype=dtype)
r = _asarray([0, 1, 0, 1], dtype=dtype)
ix = x
ix = xor_inplace(ix, y)
gn = inplace_func([x, y], ix)
_ = gn(l, r)
# test the in-place stuff
assert np.all(l == np.asarray([0, 1, 1, 0])), l
...@@ -16,6 +16,12 @@ from theano.tensor.type import TensorType ...@@ -16,6 +16,12 @@ from theano.tensor.type import TensorType
# Used to exclude random numbers too close to certain values # Used to exclude random numbers too close to certain values
_eps = 1e-2 _eps = 1e-2
if theano.config.floatX == "float32":
angle_eps = 1e-4
else:
angle_eps = 1e-10
div_grad_rtol = None div_grad_rtol = None
if config.floatX == "float32": if config.floatX == "float32":
# We raise the relative tolerance for the grad as there can be errors in # We raise the relative tolerance for the grad as there can be errors in
...@@ -48,6 +54,9 @@ ALL_DTYPES = ( ...@@ -48,6 +54,9 @@ ALL_DTYPES = (
REAL_DTYPES = ALL_DTYPES[:6] REAL_DTYPES = ALL_DTYPES[:6]
COMPLEX_DTYPES = ALL_DTYPES[-2:] COMPLEX_DTYPES = ALL_DTYPES[-2:]
ignore_isfinite_mode = copy(theano.compile.get_default_mode())
ignore_isfinite_mode.check_isfinite = False
def multi_dtype_checks(shape1, shape2, dtypes=ALL_DTYPES, nameprefix=""): def multi_dtype_checks(shape1, shape2, dtypes=ALL_DTYPES, nameprefix=""):
for dtype1, dtype2 in combinations(dtypes, 2): for dtype1, dtype2 in combinations(dtypes, 2):
...@@ -807,3 +816,250 @@ _good_broadcast_unary_normal_no_complex = dict( ...@@ -807,3 +816,250 @@ _good_broadcast_unary_normal_no_complex = dict(
empty=[np.asarray([], dtype=config.floatX)], empty=[np.asarray([], dtype=config.floatX)],
big_scalar=[np.arange(17.0, 29.0, 0.5, dtype=config.floatX)], big_scalar=[np.arange(17.0, 29.0, 0.5, dtype=config.floatX)],
) )
_bad_build_broadcast_binary_normal = dict()
_bad_runtime_broadcast_binary_normal = dict(
bad_shapes=(rand(2, 3), rand(3, 2)), bad_row=(rand(2, 3), rand(1, 2))
)
_grad_broadcast_binary_normal = dict(
same_shapes=(rand(2, 3), rand(2, 3)),
scalar=(rand(2, 3), rand(1, 1)),
row=(rand(2, 3), rand(1, 3)),
column=(rand(2, 3), rand(2, 1)),
# This don't work as verify grad don't support that
# empty=(np.asarray([]), np.asarray([1]))
# complex1=(randcomplex(2,3),randcomplex(2,3)),
# complex2=(randcomplex(2,3),rand(2,3)),
# Disabled as we test the case where we reuse the same output as the
# first inputs.
# complex3=(rand(2,3),randcomplex(2,3)),
)
_good_inv = dict(
normal=[5 * rand_nonzero((2, 3))],
integers=[randint_nonzero(2, 3)],
int8=[np.array(list(range(-127, 0)) + list(range(1, 127)), dtype="int8")],
uint8=[np.array(list(range(0, 255)), dtype="uint8")],
uint16=[np.array(list(range(0, 65535)), dtype="uint16")],
complex=[randcomplex_nonzero((2, 3))],
empty=[np.asarray([], dtype=config.floatX)],
)
_good_inv_inplace = copymod(
_good_inv, without=["integers", "int8", "uint8", "uint16", "complex"]
)
_grad_inv = copymod(
_good_inv, without=["integers", "int8", "uint8", "uint16", "complex", "empty"]
)
_bad_runtime_inv = dict(
float=[np.zeros((2, 3))],
integers=[np.zeros((2, 3), dtype="int64")],
int8=[np.zeros((2, 3), dtype="int8")],
complex=[np.zeros((2, 3), dtype="complex128")],
)
_good_broadcast_pow_normal_float = dict(
same_shapes=(rand_ranged(1, 5, (2, 3)), rand_ranged(-3, 3, (2, 3))),
scalar=(rand_ranged(1, 5, (2, 3)), rand_ranged(-3, 3, (1, 1))),
row=(rand_ranged(1, 5, (2, 3)), rand_ranged(-3, 3, (1, 3))),
column=(rand_ranged(1, 5, (2, 3)), rand_ranged(-3, 3, (2, 1))),
dtype_mixup=(rand_ranged(-3, 3, (2, 3)), randint_ranged(-3, 3, (2, 3))),
complex1=(randcomplex(2, 3), randcomplex(2, 3)),
complex2=(randcomplex(2, 3), rand(2, 3)),
# complex3 = (rand(2,3),randcomplex(2,3)), # Inplace on the first element.
empty1=(np.asarray([], dtype=config.floatX), np.asarray([1], dtype=config.floatX)),
empty2=(np.asarray([0], dtype=config.floatX), np.asarray([], dtype=config.floatX)),
empty3=(np.asarray([], dtype=config.floatX), np.asarray([], dtype=config.floatX)),
)
_grad_broadcast_pow_normal = dict(
same_shapes=(rand_ranged(1, 5, (2, 3)), rand_ranged(-3, 3, (2, 3))),
scalar=(rand_ranged(1, 5, (2, 3)), rand_ranged(-3, 3, (1, 1))),
row=(rand_ranged(1, 5, (2, 3)), rand_ranged(-3, 3, (1, 3))),
column=(rand_ranged(1, 5, (2, 3)), rand_ranged(-3, 3, (2, 1))),
# complex1 = (randcomplex(2,3),randcomplex(2,3)),
# complex2 = (randcomplex(2,3),rand(2,3)),
# complex3 = (rand(2,3),randcomplex(2,3)),
# empty1 = (np.asarray([]), np.asarray([1])),
# empty2 = (np.asarray([0]), np.asarray([])),
x_eq_zero=(
np.asarray([0.0], dtype=config.floatX),
np.asarray([2.0], dtype=config.floatX),
), # Test for issue 1780
)
# empty2 case is not supported by numpy.
_good_broadcast_pow_normal_float_pow = copy(_good_broadcast_pow_normal_float)
del _good_broadcast_pow_normal_float_pow["empty2"]
_good_broadcast_unary_normal_float_no_empty = copymod(
_good_broadcast_unary_normal_float, without=["empty"]
)
_good_broadcast_unary_normal_float_no_empty_no_complex = copymod(
_good_broadcast_unary_normal_float_no_empty, without=["complex"]
)
_grad_broadcast_unary_normal_no_complex = dict(
normal=[np.asarray(rand_ranged(-5, 5, (2, 3)), dtype=config.floatX)],
corner_case=[corner_case_grad],
)
# Avoid epsilon around integer values
_grad_broadcast_unary_normal_noint = dict(
normal=[(rand_ranged(_eps, 1 - _eps, (2, 3)) + randint(2, 3)).astype(config.floatX)]
)
_grad_broadcast_unary_normal_no_complex_no_corner_case = copymod(
_grad_broadcast_unary_normal_no_complex, without=["corner_case"]
)
_good_broadcast_binary_arctan2 = dict(
same_shapes=(rand(2, 3), rand(2, 3)),
not_same_dimensions=(rand(2, 2), rand(2)),
scalar=(rand(2, 3), rand(1, 1)),
row=(rand(2, 3), rand(1, 3)),
column=(rand(2, 3), rand(2, 1)),
integers=(randint(2, 3), randint(2, 3)),
int8=[
np.arange(-127, 128, dtype="int8"),
np.arange(-127, 128, dtype="int8")[:, np.newaxis],
],
uint8=[
np.arange(0, 128, dtype="uint8"),
np.arange(0, 128, dtype="uint8")[:, np.newaxis],
],
uint16=[
np.arange(0, 128, dtype="uint16"),
np.arange(0, 128, dtype="uint16")[:, np.newaxis],
],
dtype_mixup_1=(rand(2, 3), randint(2, 3)),
dtype_mixup_2=(randint(2, 3), rand(2, 3)),
empty=(np.asarray([], dtype=config.floatX), np.asarray([1], dtype=config.floatX)),
)
_good_broadcast_unary_arccosh = dict(
normal=(rand_ranged(1, 1000, (2, 3)),),
integers=(randint_ranged(1, 1000, (2, 3)),),
uint8=[np.arange(1, 256, dtype="uint8")],
complex=(randc128_ranged(1, 1000, (2, 3)),),
empty=(np.asarray([], dtype=config.floatX),),
)
_good_broadcast_unary_arctanh = dict(
normal=(rand_ranged(-1 + _eps, 1 - _eps, (2, 3)),),
integers=(randint_ranged(-1 + _eps, 1 - _eps, (2, 3)),),
int8=[np.arange(0, 1, dtype="int8")],
uint8=[np.arange(0, 1, dtype="uint8")],
uint16=[np.arange(0, 1, dtype="uint16")],
complex=(randc128_ranged(-1 + _eps, 1 - _eps, (2, 3)),),
empty=(np.asarray([], dtype=config.floatX),),
)
_good_broadcast_unary_normal_abs = copy(_good_broadcast_unary_normal)
# Can't do inplace on Abs as the input/output are not of the same type!
del _good_broadcast_unary_normal_abs["complex"]
_good_broadcast_unary_positive = dict(
normal=(rand_ranged(0.001, 5, (2, 3)),),
integers=(randint_ranged(1, 5, (2, 3)),),
uint8=[np.arange(1, 256, dtype="uint8")],
complex=(randc128_ranged(1, 5, (2, 3)),),
empty=(np.asarray([], dtype=config.floatX),),
)
_good_broadcast_unary_positive_float = copymod(
_good_broadcast_unary_positive, without=["integers", "uint8"]
)
_good_broadcast_unary_tan = dict(
normal=(rand_ranged(-3.14, 3.14, (2, 3)),),
shifted=(rand_ranged(3.15, 6.28, (2, 3)),),
integers=(randint_ranged(-3, 3, (2, 3)),),
int8=[np.arange(-3, 4, dtype="int8")],
uint8=[np.arange(0, 4, dtype="uint8")],
uint16=[np.arange(0, 4, dtype="uint16")],
complex=(randc128_ranged(-3.14, 3.14, (2, 3)),),
empty=(np.asarray([], dtype=config.floatX),),
)
_good_broadcast_unary_wide = dict(
normal=(rand_ranged(-1000, 1000, (2, 3)),),
integers=(randint_ranged(-1000, 1000, (2, 3)),),
int8=[np.arange(-127, 128, dtype="int8")],
uint8=[np.arange(0, 255, dtype="uint8")],
uint16=[np.arange(0, 65535, dtype="uint16")],
complex=(randc128_ranged(-1000, 1000, (2, 3)),),
empty=(np.asarray([], dtype=config.floatX),),
)
_good_broadcast_unary_wide_float = copymod(
_good_broadcast_unary_wide, without=["integers", "int8", "uint8", "uint16"]
)
_good_broadcast_binary_normal = dict(
same_shapes=(rand(2, 3), rand(2, 3)),
not_same_dimensions=(rand(2, 2), rand(2)),
scalar=(rand(2, 3), rand(1, 1)),
row=(rand(2, 3), rand(1, 3)),
column=(rand(2, 3), rand(2, 1)),
integers=(randint(2, 3), randint(2, 3)),
uint32=(randuint32(2, 3), randuint32(2, 3)),
uint16=(randuint16(2, 3), randuint16(2, 3)),
dtype_mixup_1=(rand(2, 3), randint(2, 3)),
dtype_mixup_2=(randint(2, 3), rand(2, 3)),
complex1=(randcomplex(2, 3), randcomplex(2, 3)),
complex2=(randcomplex(2, 3), rand(2, 3)),
# Disabled as we test the case where we reuse the same output as the
# first inputs.
# complex3=(rand(2,3),randcomplex(2,3)),
empty=(np.asarray([], dtype=config.floatX), np.asarray([1], dtype=config.floatX)),
)
_good_broadcast_div_mod_normal_float_no_complex = dict(
same_shapes=(rand(2, 3), rand_nonzero((2, 3))),
scalar=(rand(2, 3), rand_nonzero((1, 1))),
row=(rand(2, 3), rand_nonzero((1, 3))),
column=(rand(2, 3), rand_nonzero((2, 1))),
dtype_mixup_1=(rand(2, 3), randint_nonzero(2, 3)),
dtype_mixup_2=(randint_nonzero(2, 3), rand_nonzero((2, 3))),
integer=(randint(2, 3), randint_nonzero(2, 3)),
uint8=(randint(2, 3).astype("uint8"), randint_nonzero(2, 3).astype("uint8")),
uint16=(randint(2, 3).astype("uint16"), randint_nonzero(2, 3).astype("uint16")),
int8=[
np.tile(np.arange(-127, 128, dtype="int8"), [254, 1]).T,
np.tile(
np.array(list(range(-127, 0)) + list(range(1, 128)), dtype="int8"), [255, 1]
),
],
# This empty2 doesn't work for some tests. I don't remember why
# empty2=(np.asarray([0]), np.asarray([])),
)
_good_broadcast_div_mod_normal_float_inplace = copymod(
_good_broadcast_div_mod_normal_float_no_complex,
empty1=(np.asarray([]), np.asarray([1])),
# No complex floor division in python 3.x
)
_good_broadcast_div_mod_normal_float = copymod(
_good_broadcast_div_mod_normal_float_inplace,
empty2=(np.asarray([0], dtype=config.floatX), np.asarray([], dtype=config.floatX)),
)
_good_broadcast_unary_arcsin = dict(
normal=(rand_ranged(-1, 1, (2, 3)),),
integers=(randint_ranged(-1, 1, (2, 3)),),
int8=[np.arange(-1, 2, dtype="int8")],
uint8=[np.arange(0, 2, dtype="uint8")],
uint16=[np.arange(0, 2, dtype="uint16")],
complex=(randc128_ranged(-1, 1, (2, 3)),),
empty=(np.asarray([], dtype=config.floatX),),
)
_good_broadcast_unary_arcsin_float = copymod(
_good_broadcast_unary_arcsin, without=["integers", "int8", "uint8", "uint16"]
)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论