mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 12:21:27 +01:00
RFC: https://github.com/pytorch/rfcs/pull/54 First commit is the contents of https://github.com/Quansight-Labs/numpy_pytorch_interop/ We have already been using this in core for the last few months as a external dependency. This PR pulls all these into core. In the next commits, I do a number of things in this order - Fix a few small issues - Make the tests that this PR adds pass - Bend backwards until lintrunner passes - Remove the optional dependency on `torch_np` and simply rely on the upstreamed code - Fix a number dynamo tests that were passing before (they were not tasting anything I think) and are not passing now. Missing from this PR (but not blocking): - Have a flag that deactivates tracing NumPy functions and simply breaks. There used to be one but after the merge stopped working and I removed it. @lezcano to investigate. - https://github.com/pytorch/pytorch/pull/106431#issuecomment-1667079543. @voznesenskym to submit a fix after we merge. All the tests in `tests/torch_np` take about 75s to run. This was a work by @ev-br, @rgommers @honno and I. I did not create this PR via ghstack (which would have been convenient) as this is a collaboration, and ghstack doesn't allow for shared contributions. Pull Request resolved: https://github.com/pytorch/pytorch/pull/106211 Approved by: https://github.com/ezyang
212 lines
4.8 KiB
Python
212 lines
4.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
|
|
|
|
|
|
def test_add():
|
|
assert_allclose(np.add(0.5, 0.6), add(0.5, 0.6), atol=1e-7, check_dtype=False)
|
|
|
|
|
|
def test_arctan2():
|
|
assert_allclose(
|
|
np.arctan2(0.5, 0.6), arctan2(0.5, 0.6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
|
|
def test_bitwise_and():
|
|
assert_allclose(
|
|
np.bitwise_and(5, 6), bitwise_and(5, 6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
|
|
def test_bitwise_or():
|
|
assert_allclose(np.bitwise_or(5, 6), bitwise_or(5, 6), atol=1e-7, check_dtype=False)
|
|
|
|
|
|
def test_bitwise_xor():
|
|
assert_allclose(
|
|
np.bitwise_xor(5, 6), bitwise_xor(5, 6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
|
|
def test_copysign():
|
|
assert_allclose(
|
|
np.copysign(0.5, 0.6), copysign(0.5, 0.6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
|
|
def test_divide():
|
|
assert_allclose(np.divide(0.5, 0.6), divide(0.5, 0.6), atol=1e-7, check_dtype=False)
|
|
|
|
|
|
def test_equal():
|
|
assert_allclose(np.equal(0.5, 0.6), equal(0.5, 0.6), atol=1e-7, check_dtype=False)
|
|
|
|
|
|
def test_float_power():
|
|
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():
|
|
assert_allclose(
|
|
np.floor_divide(0.5, 0.6), floor_divide(0.5, 0.6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
|
|
def test_fmax():
|
|
assert_allclose(np.fmax(0.5, 0.6), fmax(0.5, 0.6), atol=1e-7, check_dtype=False)
|
|
|
|
|
|
def test_fmin():
|
|
assert_allclose(np.fmin(0.5, 0.6), fmin(0.5, 0.6), atol=1e-7, check_dtype=False)
|
|
|
|
|
|
def test_fmod():
|
|
assert_allclose(np.fmod(0.5, 0.6), fmod(0.5, 0.6), atol=1e-7, check_dtype=False)
|
|
|
|
|
|
def test_gcd():
|
|
assert_allclose(np.gcd(5, 6), gcd(5, 6), atol=1e-7, check_dtype=False)
|
|
|
|
|
|
def test_greater():
|
|
assert_allclose(
|
|
np.greater(0.5, 0.6), greater(0.5, 0.6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
|
|
def test_greater_equal():
|
|
assert_allclose(
|
|
np.greater_equal(0.5, 0.6),
|
|
greater_equal(0.5, 0.6),
|
|
atol=1e-7,
|
|
check_dtype=False,
|
|
)
|
|
|
|
|
|
def test_heaviside():
|
|
assert_allclose(
|
|
np.heaviside(0.5, 0.6), heaviside(0.5, 0.6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
|
|
def test_hypot():
|
|
assert_allclose(np.hypot(0.5, 0.6), hypot(0.5, 0.6), atol=1e-7, check_dtype=False)
|
|
|
|
|
|
def test_lcm():
|
|
assert_allclose(np.lcm(5, 6), lcm(5, 6), atol=1e-7, check_dtype=False)
|
|
|
|
|
|
def test_ldexp():
|
|
assert_allclose(np.ldexp(0.5, 6), ldexp(0.5, 6), atol=1e-7, check_dtype=False)
|
|
|
|
|
|
def test_left_shift():
|
|
assert_allclose(np.left_shift(5, 6), left_shift(5, 6), atol=1e-7, check_dtype=False)
|
|
|
|
|
|
def test_less():
|
|
assert_allclose(np.less(0.5, 0.6), less(0.5, 0.6), atol=1e-7, check_dtype=False)
|
|
|
|
|
|
def test_less_equal():
|
|
assert_allclose(
|
|
np.less_equal(0.5, 0.6), less_equal(0.5, 0.6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
|
|
def test_logaddexp():
|
|
assert_allclose(
|
|
np.logaddexp(0.5, 0.6), logaddexp(0.5, 0.6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
|
|
def test_logaddexp2():
|
|
assert_allclose(
|
|
np.logaddexp2(0.5, 0.6), logaddexp2(0.5, 0.6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
|
|
def test_logical_and():
|
|
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():
|
|
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():
|
|
assert_allclose(
|
|
np.logical_xor(0.5, 0.6), logical_xor(0.5, 0.6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
|
|
def test_matmul():
|
|
assert_allclose(
|
|
np.matmul([0.5], [0.6]), matmul([0.5], [0.6]), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
|
|
def test_maximum():
|
|
assert_allclose(
|
|
np.maximum(0.5, 0.6), maximum(0.5, 0.6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
|
|
def test_minimum():
|
|
assert_allclose(
|
|
np.minimum(0.5, 0.6), minimum(0.5, 0.6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
|
|
def test_remainder():
|
|
assert_allclose(
|
|
np.remainder(0.5, 0.6), remainder(0.5, 0.6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
|
|
def test_multiply():
|
|
assert_allclose(
|
|
np.multiply(0.5, 0.6), multiply(0.5, 0.6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
|
|
def test_nextafter():
|
|
assert_allclose(
|
|
np.nextafter(0.5, 0.6), nextafter(0.5, 0.6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
|
|
def test_not_equal():
|
|
assert_allclose(
|
|
np.not_equal(0.5, 0.6), not_equal(0.5, 0.6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
|
|
def test_power():
|
|
assert_allclose(np.power(0.5, 0.6), power(0.5, 0.6), atol=1e-7, check_dtype=False)
|
|
|
|
|
|
def test_right_shift():
|
|
assert_allclose(
|
|
np.right_shift(5, 6), right_shift(5, 6), atol=1e-7, check_dtype=False
|
|
)
|
|
|
|
|
|
def test_subtract():
|
|
assert_allclose(
|
|
np.subtract(0.5, 0.6), subtract(0.5, 0.6), atol=1e-7, check_dtype=False
|
|
)
|