mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
1. Inherit from TestCase 2. Use pytorch parametrization 3. Use unittest.expectedFailure to mark xfails All this to make pytest-less invocation work: $ python test/torch_np/test_basic.py Furthermor, tests can now be run under dynamo, and we see first errors: ``` $ PYTORCH_TEST_WITH_DYNAMO=1 python test/torch_np/test_basic.py -k test_toscalar_list_func .E. ====================================================================== ERROR: test_toscalar_list_func_<function shape at 0x7f9b83a4fc10>_np_func_<function shape at 0x7f9a8dd38af0> (__main__.TestOneArrToScalar) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/ev-br/repos/pytorch/torch/testing/_internal/common_utils.py", line 356, in instantiated_test test(self, **param_kwargs) File "test/torch_np/test_basic.py", line 232, in test_toscalar_list @parametrize("func, np_func", one_arg_scalar_funcs) File "/home/ev-br/repos/pytorch/torch/nn/modules/module.py", line 1519, in _wrapped_call_impl return self._call_impl(*args, **kwargs) File "/home/ev-br/repos/pytorch/torch/nn/modules/module.py", line 1528, in _call_impl return forward_call(*args, **kwargs) File "/home/ev-br/repos/pytorch/torch/_dynamo/eval_frame.py", line 406, in _fn return fn(*args, **kwargs) File "/home/ev-br/repos/pytorch/torch/fx/graph_module.py", line 726, in call_wrapped return self._wrapped_call(self, *args, **kwargs) File "/home/ev-br/repos/pytorch/torch/fx/graph_module.py", line 305, in __call__ raise e File "/home/ev-br/repos/pytorch/torch/fx/graph_module.py", line 292, in __call__ return super(self.cls, obj).__call__(*args, **kwargs) # type: ignore[misc] File "/home/ev-br/repos/pytorch/torch/nn/modules/module.py", line 1519, in _wrapped_call_impl return self._call_impl(*args, **kwargs) File "/home/ev-br/repos/pytorch/torch/nn/modules/module.py", line 1528, in _call_impl return forward_call(*args, **kwargs) File "<eval_with_key>.2", line 5, in forward shape = torch._numpy._funcs_impl.shape([[1, 2, 3], [4, 5, 6]]) File "/home/ev-br/repos/pytorch/torch/_numpy/_funcs_impl.py", line 655, in shape return tuple(a.shape) AttributeError: 'list' object has no attribute 'shape' ---------------------------------------------------------------------- Ran 3 tests in 0.915s FAILED (errors=1) ``` Pull Request resolved: https://github.com/pytorch/pytorch/pull/109593 Approved by: https://github.com/lezcano
205 lines
5.8 KiB
Python
205 lines
5.8 KiB
Python
# Owner(s): ["module: dynamo"]
|
|
|
|
# this file is autogenerated via gen_ufuncs.py
|
|
# do not edit manually!
|
|
import numpy as np
|
|
|
|
from torch._numpy._ufuncs import * # noqa: F403
|
|
from torch._numpy.testing import assert_allclose
|
|
from torch.testing._internal.common_utils import run_tests, TestCase
|
|
|
|
|
|
class TestBinaryUfuncBasic(TestCase):
|
|
def test_add(self):
|
|
assert_allclose(np.add(0.5, 0.6), add(0.5, 0.6), atol=1e-7, check_dtype=False)
|
|
|
|
def test_arctan2(self):
|
|
assert_allclose(
|
|
np.arctan2(0.5, 0.6), arctan2(0.5, 0.6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
def test_bitwise_and(self):
|
|
assert_allclose(
|
|
np.bitwise_and(5, 6), bitwise_and(5, 6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
def test_bitwise_or(self):
|
|
assert_allclose(
|
|
np.bitwise_or(5, 6), bitwise_or(5, 6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
def test_bitwise_xor(self):
|
|
assert_allclose(
|
|
np.bitwise_xor(5, 6), bitwise_xor(5, 6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
def test_copysign(self):
|
|
assert_allclose(
|
|
np.copysign(0.5, 0.6), copysign(0.5, 0.6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
def test_divide(self):
|
|
assert_allclose(
|
|
np.divide(0.5, 0.6), divide(0.5, 0.6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
def test_equal(self):
|
|
assert_allclose(
|
|
np.equal(0.5, 0.6), equal(0.5, 0.6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
def test_float_power(self):
|
|
assert_allclose(
|
|
np.float_power(0.5, 0.6),
|
|
float_power(0.5, 0.6),
|
|
atol=1e-7,
|
|
check_dtype=False,
|
|
)
|
|
|
|
def test_floor_divide(self):
|
|
assert_allclose(
|
|
np.floor_divide(0.5, 0.6),
|
|
floor_divide(0.5, 0.6),
|
|
atol=1e-7,
|
|
check_dtype=False,
|
|
)
|
|
|
|
def test_fmax(self):
|
|
assert_allclose(np.fmax(0.5, 0.6), fmax(0.5, 0.6), atol=1e-7, check_dtype=False)
|
|
|
|
def test_fmin(self):
|
|
assert_allclose(np.fmin(0.5, 0.6), fmin(0.5, 0.6), atol=1e-7, check_dtype=False)
|
|
|
|
def test_fmod(self):
|
|
assert_allclose(np.fmod(0.5, 0.6), fmod(0.5, 0.6), atol=1e-7, check_dtype=False)
|
|
|
|
def test_gcd(self):
|
|
assert_allclose(np.gcd(5, 6), gcd(5, 6), atol=1e-7, check_dtype=False)
|
|
|
|
def test_greater(self):
|
|
assert_allclose(
|
|
np.greater(0.5, 0.6), greater(0.5, 0.6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
def test_greater_equal(self):
|
|
assert_allclose(
|
|
np.greater_equal(0.5, 0.6),
|
|
greater_equal(0.5, 0.6),
|
|
atol=1e-7,
|
|
check_dtype=False,
|
|
)
|
|
|
|
def test_heaviside(self):
|
|
assert_allclose(
|
|
np.heaviside(0.5, 0.6), heaviside(0.5, 0.6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
def test_hypot(self):
|
|
assert_allclose(
|
|
np.hypot(0.5, 0.6), hypot(0.5, 0.6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
def test_lcm(self):
|
|
assert_allclose(np.lcm(5, 6), lcm(5, 6), atol=1e-7, check_dtype=False)
|
|
|
|
def test_ldexp(self):
|
|
assert_allclose(np.ldexp(0.5, 6), ldexp(0.5, 6), atol=1e-7, check_dtype=False)
|
|
|
|
def test_left_shift(self):
|
|
assert_allclose(
|
|
np.left_shift(5, 6), left_shift(5, 6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
def test_less(self):
|
|
assert_allclose(np.less(0.5, 0.6), less(0.5, 0.6), atol=1e-7, check_dtype=False)
|
|
|
|
def test_less_equal(self):
|
|
assert_allclose(
|
|
np.less_equal(0.5, 0.6), less_equal(0.5, 0.6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
def test_logaddexp(self):
|
|
assert_allclose(
|
|
np.logaddexp(0.5, 0.6), logaddexp(0.5, 0.6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
def test_logaddexp2(self):
|
|
assert_allclose(
|
|
np.logaddexp2(0.5, 0.6), logaddexp2(0.5, 0.6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
def test_logical_and(self):
|
|
assert_allclose(
|
|
np.logical_and(0.5, 0.6),
|
|
logical_and(0.5, 0.6),
|
|
atol=1e-7,
|
|
check_dtype=False,
|
|
)
|
|
|
|
def test_logical_or(self):
|
|
assert_allclose(
|
|
np.logical_or(0.5, 0.6), logical_or(0.5, 0.6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
def test_logical_xor(self):
|
|
assert_allclose(
|
|
np.logical_xor(0.5, 0.6),
|
|
logical_xor(0.5, 0.6),
|
|
atol=1e-7,
|
|
check_dtype=False,
|
|
)
|
|
|
|
def test_matmul(self):
|
|
assert_allclose(
|
|
np.matmul([0.5], [0.6]), matmul([0.5], [0.6]), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
def test_maximum(self):
|
|
assert_allclose(
|
|
np.maximum(0.5, 0.6), maximum(0.5, 0.6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
def test_minimum(self):
|
|
assert_allclose(
|
|
np.minimum(0.5, 0.6), minimum(0.5, 0.6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
def test_remainder(self):
|
|
assert_allclose(
|
|
np.remainder(0.5, 0.6), remainder(0.5, 0.6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
def test_multiply(self):
|
|
assert_allclose(
|
|
np.multiply(0.5, 0.6), multiply(0.5, 0.6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
def test_nextafter(self):
|
|
assert_allclose(
|
|
np.nextafter(0.5, 0.6), nextafter(0.5, 0.6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
def test_not_equal(self):
|
|
assert_allclose(
|
|
np.not_equal(0.5, 0.6), not_equal(0.5, 0.6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
def test_power(self):
|
|
assert_allclose(
|
|
np.power(0.5, 0.6), power(0.5, 0.6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
def test_right_shift(self):
|
|
assert_allclose(
|
|
np.right_shift(5, 6), right_shift(5, 6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
def test_subtract(self):
|
|
assert_allclose(
|
|
np.subtract(0.5, 0.6), subtract(0.5, 0.6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
run_tests()
|