library
stringclasses
1 value
test_file
stringclasses
785 values
test_function
stringlengths
1
295
before
stringlengths
0
448k
after
stringlengths
0
487k
context_before
stringclasses
947 values
context_after
stringlengths
0
16.3k
commit_before
stringclasses
1 value
commit_after
stringclasses
1 value
change_type
stringclasses
3 values
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_specific_axes
def test_specific_axes(self): # Testing that gradient can work on a given axis only v = [[1, 1], [3, 4]] x = np.array(v) dx = [np.array([[2.0, 3.0], [2.0, 3.0]]), np.array([[0.0, 0.0], [1.0, 1.0]])] assert_array_equal(gradient(x, axis=0), dx[0]) assert_array_equal(gradient(x, axis=1), dx[1]) assert_array_equal(gradient(x, axis=-1), dx[1]) assert_array_equal(gradient(x, axis=(1, 0)), [dx[1], dx[0]]) # test axis=None which means all axes assert_almost_equal(gradient(x, axis=None), [dx[0], dx[1]]) # and is the same as no axis keyword given assert_almost_equal(gradient(x, axis=None), gradient(x)) # test vararg order assert_array_equal(gradient(x, 2, 3, axis=(1, 0)), [dx[1] / 2.0, dx[0] / 3.0]) # test maximal number of varargs assert_raises(TypeError, gradient, x, 1, 2, axis=1) assert_raises(np.AxisError, gradient, x, axis=3) assert_raises(np.AxisError, gradient, x, axis=-3) # assert_raises(TypeError, gradient, x, axis=[1,])
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) @instantiate_parametrized_tests class TestGradient(TestCase): import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_inexact_dtypes
def test_inexact_dtypes(self): for dt in [np.float16, np.float32, np.float64]: # dtypes should not be promoted in a different way to what diff does x = np.array([1, 2, 3], dtype=dt) assert_equal(gradient(x).dtype, np.diff(x).dtype)
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) @instantiate_parametrized_tests class TestGradient(TestCase): import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_x_signed_int_big_jump
def test_x_signed_int_big_jump(self, x_dtype): minint = np.iinfo(x_dtype).min maxint = np.iinfo(x_dtype).max x = np.array([-1, maxint], dtype=x_dtype) f = np.array([minint // 2, 0]) dfdx = gradient(f, x) assert_array_equal(dfdx, [0.5, 0.5])
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) @instantiate_parametrized_tests class TestGradient(TestCase): import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_basic
def test_basic(self): assert_raises(ValueError, np.rot90, np.ones(4)) assert_raises( (ValueError, RuntimeError), np.rot90, np.ones((2, 2, 2)), axes=(0, 1, 2) ) assert_raises(ValueError, np.rot90, np.ones((2, 2)), axes=(0, 2)) assert_raises(ValueError, np.rot90, np.ones((2, 2)), axes=(1, 1)) assert_raises(ValueError, np.rot90, np.ones((2, 2, 2)), axes=(-2, 1)) a = [[0, 1, 2], [3, 4, 5]] b1 = [[2, 5], [1, 4], [0, 3]] b2 = [[5, 4, 3], [2, 1, 0]] b3 = [[3, 0], [4, 1], [5, 2]] b4 = [[0, 1, 2], [3, 4, 5]] for k in range(-3, 13, 4): assert_equal(np.rot90(a, k=k), b1) for k in range(-2, 13, 4): assert_equal(np.rot90(a, k=k), b2) for k in range(-1, 13, 4): assert_equal(np.rot90(a, k=k), b3) for k in range(0, 13, 4): assert_equal(np.rot90(a, k=k), b4) assert_equal(np.rot90(np.rot90(a, axes=(0, 1)), axes=(1, 0)), a) assert_equal(np.rot90(a, k=1, axes=(1, 0)), np.rot90(a, k=-1, axes=(0, 1)))
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) class TestRot90(TestCase): import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
f
def f(**kw): res = 1.0 for _k in kw: res *= kw[_k] return res assert_array_equal(f(a=[1, 2], b=[3, 4]), [3, 8])
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_otypes
def test_otypes(self): f = np.vectorize(lambda x: x) f.otypes = "i" x = np.arange(5) assert_array_equal(f(x), x)
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) @skip # (reason="vectorize not implemented") class TestVectorize(TestCase): import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
mean
def mean(a): return a.mean() f = vectorize(mean, signature="(n)->()") r = f([[1, 3], [2, 4]]) assert_array_equal(r, [2, 3])
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
center
def center(a): return a - a.mean() f = vectorize(center, signature="(n)->(n)") r = f([[1, 3], [2, 4]]) assert_array_equal(r, [[-1, 1], [-1, 1]])
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_signature_two_outputs
def test_signature_two_outputs(self): f = vectorize(lambda x: (x, x), signature="()->(),()") r = f([1, 2, 3]) assert_(isinstance(r, tuple) and len(r) == 2) assert_array_equal(r[0], [1, 2, 3]) assert_array_equal(r[1], [1, 2, 3])
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) @skip # (reason="vectorize not implemented") class TestVectorize(TestCase): import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_signature_outer
def test_signature_outer(self): f = vectorize(np.outer, signature="(a),(b)->(a,b)") r = f([1, 2], [1, 2, 3]) assert_array_equal(r, [[1, 2, 3], [2, 4, 6]]) r = f([[[1, 2]]], [1, 2, 3]) assert_array_equal(r, [[[[1, 2, 3], [2, 4, 6]]]]) r = f([[1, 0], [2, 0]], [1, 2, 3]) assert_array_equal(r, [[[1, 2, 3], [0, 0, 0]], [[2, 4, 6], [0, 0, 0]]]) r = f([1, 2], [[1, 2, 3], [0, 0, 0]]) assert_array_equal(r, [[[1, 2, 3], [2, 4, 6]], [[0, 0, 0], [0, 0, 0]]])
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) @skip # (reason="vectorize not implemented") class TestVectorize(TestCase): import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_signature_computed_size
def test_signature_computed_size(self): f = vectorize(lambda x: x[:-1], signature="(n)->(m)") r = f([1, 2, 3]) assert_array_equal(r, [1, 2]) r = f([[1, 2, 3], [2, 3, 4]]) assert_array_equal(r, [[1, 2], [2, 3]])
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) @skip # (reason="vectorize not implemented") class TestVectorize(TestCase): import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
foo
def foo(a, b=1): return a + b f = vectorize(foo) args = np.array([1, 2, 3]) r1 = f(args) r2 = np.array([2, 3, 4]) assert_array_equal(r1, r2) r1 = f(args, 2) r2 = np.array([3, 4, 5]) assert_array_equal(r1, r2)
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_signature_otypes
def test_signature_otypes(self): f = vectorize(lambda x: x, signature="(n)->(n)", otypes=["float64"]) r = f([1, 2, 3]) assert_equal(r.dtype, np.dtype("float64")) assert_array_equal(r, [1, 2, 3])
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) @skip # (reason="vectorize not implemented") class TestVectorize(TestCase): import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_signature_invalid_inputs
def test_signature_invalid_inputs(self): f = vectorize(operator.add, signature="(n),(n)->(n)") with assert_raises_regex(TypeError, "wrong number of positional"): f([1, 2]) with assert_raises_regex(ValueError, "does not have enough dimensions"): f(1, 2) with assert_raises_regex(ValueError, "inconsistent size for core dimension"): f([1, 2], [1, 2, 3]) f = vectorize(operator.add, signature="()->()") with assert_raises_regex(TypeError, "wrong number of positional"): f(1, 2)
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) @skip # (reason="vectorize not implemented") class TestVectorize(TestCase): import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
f
def f(**kw): res = 1.0 for _k in kw: res *= kw[_k] return res assert_array_equal(f(a=[1, 2], b=[3, 4]), [3, 8])
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_keywords5_ticket_2100
def test_keywords5_ticket_2100(self): # Test vectorizing function with no kwargs args. @vectorize def f(*v): return np.prod(v) assert_array_equal(f([1, 2], [3, 4]), [3, 8])
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) @skip # (reason="vectorize not implemented") class TestVectorize(TestCase): import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
f
def f(**kw): res = 1.0 for _k in kw: res *= kw[_k] return res assert_array_equal(f(a=[1, 2], b=[3, 4]), [3, 8])
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
foo
def foo(a, b=1): return a + b f = vectorize(foo) args = np.array([1, 2, 3]) r1 = f(args) r2 = np.array([2, 3, 4]) assert_array_equal(r1, r2) r1 = f(args, 2) r2 = np.array([3, 4, 5]) assert_array_equal(r1, r2)
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
foo
def foo(a, b=1): return a + b f = vectorize(foo) args = np.array([1, 2, 3]) r1 = f(args) r2 = np.array([2, 3, 4]) assert_array_equal(r1, r2) r1 = f(args, 2) r2 = np.array([3, 4, 5]) assert_array_equal(r1, r2)
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_UnboundMethod_ticket_1156
def test_UnboundMethod_ticket_1156(self): # Regression test for issue 1156 class Foo: b = 2 def bar(self, a): return a**self.b assert_array_equal(vectorize(Foo().bar)(np.arange(9)), np.arange(9) ** 2) assert_array_equal(vectorize(Foo.bar)(Foo(), np.arange(9)), np.arange(9) ** 2)
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) @skip # (reason="vectorize not implemented") class TestVectorize(TestCase): import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
bar
def bar(self, a): return a**self.b
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random class Foo:
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_execution_order_ticket_1487
def test_execution_order_ticket_1487(self): # Regression test for dependence on execution order: issue 1487 f1 = vectorize(lambda x: x) res1a = f1(np.arange(3)) res1b = f1(np.arange(0.1, 3)) f2 = vectorize(lambda x: x) res2b = f2(np.arange(0.1, 3)) res2a = f2(np.arange(3)) assert_equal(res1a, res2a) assert_equal(res1b, res2b)
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) @skip # (reason="vectorize not implemented") class TestVectorize(TestCase): import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_string_ticket_1892
def test_string_ticket_1892(self): # Test vectorization over strings: issue 1892. f = np.vectorize(lambda x: x) s = "0123456789" * 10 assert_equal(s, f(s))
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) @skip # (reason="vectorize not implemented") class TestVectorize(TestCase): import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_cache
def test_cache(self): # Ensure that vectorized func called exactly once per argument. _calls = [0] @vectorize def f(x): _calls[0] += 1 return x**2 f.cache = True x = np.arange(5) assert_array_equal(f(x), x * x) assert_equal(_calls[0], len(x))
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) @skip # (reason="vectorize not implemented") class TestVectorize(TestCase): import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_casting_error
def test_casting_error(self): x = [1, 2, 3 + 1.0j] bins = [1, 2, 3] assert_raises(TypeError, digitize, x, bins) x, bins = bins, x assert_raises(TypeError, digitize, x, bins)
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @xpassIfTorchDynamo # (reason="TODO: implement") class TestDigitize(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_large_integers_decreasing
def test_large_integers_decreasing(self): # gh-11022 x = 2**54 # loses precision in a float assert_equal(np.digitize(x, [x + 1, x - 1]), 1)
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @xpassIfTorchDynamo # (reason="TODO: implement") class TestDigitize(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_simple
def test_simple(self): def addsubtract(a, b): if a > b: return a - b else: return a + b f = vectorize(addsubtract) r = f([0, 3, 6, 9], [1, 3, 5, 7]) assert_array_equal(r, [1, 6, 1, 2])
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) @skip # (reason="vectorize not implemented") class TestVectorize(TestCase): import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_period
def test_period(self): # check that unwrap removes jumps greater that 255 assert_array_equal(unwrap([1, 1 + 256], period=255), [1, 2]) # check that unwrap maintains continuity assert_(np.all(diff(unwrap(rand(10) * 1000, period=255)) < 255)) # check simple case simple_seq = np.array([0, 75, 150, 225, 300]) wrap_seq = np.mod(simple_seq, 255) assert_array_equal(unwrap(wrap_seq, period=255), simple_seq) # check custom discont value uneven_seq = np.array([0, 75, 150, 225, 300, 430]) wrap_uneven = np.mod(uneven_seq, 250) no_discont = unwrap(wrap_uneven, period=250) assert_array_equal(no_discont, [0, 75, 150, 225, 300, 180]) sm_discont = unwrap(wrap_uneven, period=250, discont=140) assert_array_equal(sm_discont, [0, 75, 150, 225, 300, 430]) assert sm_discont.dtype == wrap_uneven.dtype
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @skip # (reason="TODO: implement; here unwrap if from numpy") class TestUnwrap(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_simple
def test_simple(self): def addsubtract(a, b): if a > b: return a - b else: return a + b f = vectorize(addsubtract) r = f([0, 3, 6, 9], [1, 3, 5, 7]) assert_array_equal(r, [1, 6, 1, 2])
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) @skip # (reason="vectorize not implemented") class TestVectorize(TestCase): import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_ndim
def test_ndim(self): x = np.linspace(0, 1, 3) y = np.linspace(0, 2, 8) z = np.linspace(0, 3, 13) wx = np.ones_like(x) * (x[1] - x[0]) wx[0] /= 2 wx[-1] /= 2 wy = np.ones_like(y) * (y[1] - y[0]) wy[0] /= 2 wy[-1] /= 2 wz = np.ones_like(z) * (z[1] - z[0]) wz[0] /= 2 wz[-1] /= 2 q = x[:, None, None] + y[None, :, None] + z[None, None, :] qx = (q * wx[:, None, None]).sum(axis=0) qy = (q * wy[None, :, None]).sum(axis=1) qz = (q * wz[None, None, :]).sum(axis=2) # n-d `x` r = trapz(q, x=x[:, None, None], axis=0) assert_almost_equal(r, qx) r = trapz(q, x=y[None, :, None], axis=1) assert_almost_equal(r, qy) r = trapz(q, x=z[None, None, :], axis=2) assert_almost_equal(r, qz) # 1-d `x` r = trapz(q, x=x, axis=0) assert_almost_equal(r, qx) r = trapz(q, x=y, axis=1) assert_almost_equal(r, qy) r = trapz(q, x=z, axis=2) assert_almost_equal(r, qz)
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @xpassIfTorchDynamo # (reason="TODO: implement") class TestTrapz(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_simple
def test_simple(self): def addsubtract(a, b): if a > b: return a - b else: return a + b f = vectorize(addsubtract) r = f([0, 3, 6, 9], [1, 3, 5, 7]) assert_array_equal(r, [1, 6, 1, 2])
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) @skip # (reason="vectorize not implemented") class TestVectorize(TestCase): import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_array_like
def test_array_like(self): x = [0, 0.5] y1 = sinc(np.array(x)) y2 = sinc(list(x)) y3 = sinc(tuple(x)) assert_array_equal(y1, y2) assert_array_equal(y1, y3)
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random class TestSinc(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_simple
def test_simple(self): def addsubtract(a, b): if a > b: return a - b else: return a + b f = vectorize(addsubtract) r = f([0, 3, 6, 9], [1, 3, 5, 7]) assert_array_equal(r, [1, 6, 1, 2])
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) @skip # (reason="vectorize not implemented") class TestVectorize(TestCase): import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_corrcoef_dtype
def test_corrcoef_dtype(self, test_type): cast_A = self.A.astype(test_type) res = corrcoef(cast_A, dtype=test_type) assert test_type == res.dtype
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @instantiate_parametrized_tests class TestCorrCoef(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_basic
def test_basic(self): assert_raises(ValueError, np.rot90, np.ones(4)) assert_raises( (ValueError, RuntimeError), np.rot90, np.ones((2, 2, 2)), axes=(0, 1, 2) ) assert_raises(ValueError, np.rot90, np.ones((2, 2)), axes=(0, 2)) assert_raises(ValueError, np.rot90, np.ones((2, 2)), axes=(1, 1)) assert_raises(ValueError, np.rot90, np.ones((2, 2, 2)), axes=(-2, 1)) a = [[0, 1, 2], [3, 4, 5]] b1 = [[2, 5], [1, 4], [0, 3]] b2 = [[5, 4, 3], [2, 1, 0]] b3 = [[3, 0], [4, 1], [5, 2]] b4 = [[0, 1, 2], [3, 4, 5]] for k in range(-3, 13, 4): assert_equal(np.rot90(a, k=k), b1) for k in range(-2, 13, 4): assert_equal(np.rot90(a, k=k), b2) for k in range(-1, 13, 4): assert_equal(np.rot90(a, k=k), b3) for k in range(0, 13, 4): assert_equal(np.rot90(a, k=k), b4) assert_equal(np.rot90(np.rot90(a, axes=(0, 1)), axes=(1, 0)), a) assert_equal(np.rot90(a, k=1, axes=(1, 0)), np.rot90(a, k=-1, axes=(0, 1)))
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) class TestRot90(TestCase): import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_complex
def test_complex(self): x = np.array([[1, 2, 3], [1j, 2j, 3j]]) res = corrcoef(x) tgt = np.array([[1.0, -1.0j], [1.0j, 1.0]]) assert_allclose(res, tgt) assert_(np.all(np.abs(res) <= 1.0))
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @instantiate_parametrized_tests class TestCorrCoef(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_xy
def test_xy(self): x = np.array([[1, 2, 3]]) y = np.array([[1j, 2j, 3j]]) assert_allclose(np.corrcoef(x, y), np.array([[1.0, -1.0j], [1.0j, 1.0]]))
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @instantiate_parametrized_tests class TestCorrCoef(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_empty
def test_empty(self): with warnings.catch_warnings(record=True): warnings.simplefilter("always", RuntimeWarning) assert_array_equal(corrcoef(np.array([])), np.nan) assert_array_equal( corrcoef(np.array([]).reshape(0, 2)), np.array([]).reshape(0, 0) ) assert_array_equal( corrcoef(np.array([]).reshape(2, 0)), np.array([[np.nan, np.nan], [np.nan, np.nan]]), )
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @instantiate_parametrized_tests class TestCorrCoef(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_wrong_ddof
def test_wrong_ddof(self): with warnings.catch_warnings(record=True): warnings.simplefilter("always", RuntimeWarning) assert_array_equal( cov(self.x1, ddof=5), np.array([[np.inf, -np.inf], [-np.inf, np.inf]]) )
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @instantiate_parametrized_tests class TestCov(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_1D_rowvar
def test_1D_rowvar(self): assert_allclose(cov(self.x3), cov(self.x3, rowvar=False)) y = np.array([0.0780, 0.3107, 0.2111, 0.0334, 0.8501]) assert_allclose(cov(self.x3, y), cov(self.x3, y, rowvar=False))
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @instantiate_parametrized_tests class TestCov(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_1D_variance
def test_1D_variance(self): assert_allclose(cov(self.x3, ddof=1), np.var(self.x3, ddof=1))
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @instantiate_parametrized_tests class TestCov(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_fweights
def test_fweights(self): assert_allclose(cov(self.x2, fweights=self.frequencies), cov(self.x2_repeats)) assert_allclose(cov(self.x1, fweights=self.frequencies), self.res2) assert_allclose(cov(self.x1, fweights=self.unit_frequencies), self.res1) nonint = self.frequencies + 0.5 assert_raises((TypeError, RuntimeError), cov, self.x1, fweights=nonint) f = np.ones((2, 3), dtype=np.int_) assert_raises(RuntimeError, cov, self.x1, fweights=f) f = np.ones(2, dtype=np.int_) assert_raises(RuntimeError, cov, self.x1, fweights=f) f = -1 * np.ones(3, dtype=np.int_) assert_raises((ValueError, RuntimeError), cov, self.x1, fweights=f)
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @instantiate_parametrized_tests class TestCov(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_simple_complex
def test_simple_complex(self): x = np.array([5 + 6j, 1 + 1j, 1 + 10j, 10, 5 + 6j]) assert_(np.all(unique(x) == [1 + 1j, 1 + 10j, 5 + 6j, 10]))
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random class TestUnique(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_simple
def test_simple(self): def addsubtract(a, b): if a > b: return a - b else: return a + b f = vectorize(addsubtract) r = f([0, 3, 6, 9], [1, 3, 5, 7]) assert_array_equal(r, [1, 6, 1, 2])
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) @skip # (reason="vectorize not implemented") class TestVectorize(TestCase): import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_dtype_order
def test_dtype_order(self): # Regression test for missing dtype and order arguments a = [1, 2, 3] a = np.lib.asarray_chkfinite(a, order="F", dtype=np.float64) assert_(a.dtype == np.float64)
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @xpassIfTorchDynamo # (reason="TODO: implement") class TestCheckFinite(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_non_array
def test_non_array(self): assert_almost_equal( np.corrcoef([0, 1, 0], [1, 0, 1]), [[1.0, -1.0], [-1.0, 1.0]] )
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @instantiate_parametrized_tests class TestCorrCoef(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_simple
def test_simple(self): def addsubtract(a, b): if a > b: return a - b else: return a + b f = vectorize(addsubtract) r = f([0, 3, 6, 9], [1, 3, 5, 7]) assert_array_equal(r, [1, 6, 1, 2])
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) @skip # (reason="vectorize not implemented") class TestVectorize(TestCase): import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_bias
def test_bias(self): # bias raises DeprecationWarning with suppress_warnings() as sup: warnings.simplefilter("always") assert_warns(DeprecationWarning, corrcoef, self.A, self.B, 1, 0) assert_warns(DeprecationWarning, corrcoef, self.A, bias=0) sup.filter(DeprecationWarning) # bias has no or negligible effect on the function assert_almost_equal(corrcoef(self.A, bias=1), self.res1)
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @instantiate_parametrized_tests class TestCorrCoef(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_complex
def test_complex(self): x = np.array([[1, 2, 3], [1j, 2j, 3j]]) res = corrcoef(x) tgt = np.array([[1.0, -1.0j], [1.0j, 1.0]]) assert_allclose(res, tgt) assert_(np.all(np.abs(res) <= 1.0))
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @instantiate_parametrized_tests class TestCorrCoef(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_xy
def test_xy(self): x = np.array([[1, 2, 3]]) y = np.array([[1j, 2j, 3j]]) assert_allclose(np.corrcoef(x, y), np.array([[1.0, -1.0j], [1.0j, 1.0]]))
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @instantiate_parametrized_tests class TestCorrCoef(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_empty
def test_empty(self): with warnings.catch_warnings(record=True): warnings.simplefilter("always", RuntimeWarning) assert_array_equal(corrcoef(np.array([])), np.nan) assert_array_equal( corrcoef(np.array([]).reshape(0, 2)), np.array([]).reshape(0, 0) ) assert_array_equal( corrcoef(np.array([]).reshape(2, 0)), np.array([[np.nan, np.nan], [np.nan, np.nan]]), )
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @instantiate_parametrized_tests class TestCorrCoef(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_signature_invalid_outputs
def test_signature_invalid_outputs(self): f = vectorize(lambda x: x[:-1], signature="(n)->(n)") with assert_raises_regex(ValueError, "inconsistent size for core dimension"): f([1, 2, 3]) f = vectorize(lambda x: x, signature="()->(),()") with assert_raises_regex(ValueError, "wrong number of outputs"): f(1) f = vectorize(lambda x: (x, x), signature="()->()") with assert_raises_regex(ValueError, "wrong number of outputs"): f([1, 2])
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) @skip # (reason="vectorize not implemented") class TestVectorize(TestCase): import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_size_zero_output
def test_size_zero_output(self): # see issue 5868 f = np.vectorize(lambda x: x) x = np.zeros([0, 5], dtype=int) with assert_raises_regex(ValueError, "otypes"): f(x) f.otypes = "i" assert_array_equal(f(x), x) f = np.vectorize(lambda x: x, signature="()->()") with assert_raises_regex(ValueError, "otypes"): f(x) f = np.vectorize(lambda x: x, signature="()->()", otypes="i") assert_array_equal(f(x), x) f = np.vectorize(lambda x: x, signature="(n)->(n)", otypes="i") assert_array_equal(f(x), x) f = np.vectorize(lambda x: x, signature="(n)->(n)") assert_array_equal(f(x.T), x.T) f = np.vectorize(lambda x: [x], signature="()->(n)", otypes="i") with assert_raises_regex(ValueError, "new output dimensions"): f(x)
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) @skip # (reason="vectorize not implemented") class TestVectorize(TestCase): import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_forward
def test_forward(self): x = np.arange(-6, 5) bins = np.arange(-5, 5) assert_array_equal(digitize(x, bins), np.arange(11))
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @xpassIfTorchDynamo # (reason="TODO: implement") class TestDigitize(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_reverse
def test_reverse(self): x = np.arange(5, -6, -1) bins = np.arange(5, -5, -1) assert_array_equal(digitize(x, bins), np.arange(11))
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @xpassIfTorchDynamo # (reason="TODO: implement") class TestDigitize(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_random
def test_random(self): x = rand(10) bin = np.linspace(x.min(), x.max(), 10) assert_(np.all(digitize(x, bin) != 0))
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @xpassIfTorchDynamo # (reason="TODO: implement") class TestDigitize(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_right_basic
def test_right_basic(self): x = [1, 5, 4, 10, 8, 11, 0] bins = [1, 5, 10] default_answer = [1, 2, 1, 3, 2, 3, 0] assert_array_equal(digitize(x, bins), default_answer) right_answer = [0, 1, 1, 2, 2, 3, 0] assert_array_equal(digitize(x, bins, True), right_answer)
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @xpassIfTorchDynamo # (reason="TODO: implement") class TestDigitize(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_right_open
def test_right_open(self): x = np.arange(-6, 5) bins = np.arange(-6, 4) assert_array_equal(digitize(x, bins, True), np.arange(11))
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @xpassIfTorchDynamo # (reason="TODO: implement") class TestDigitize(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_right_open_reverse
def test_right_open_reverse(self): x = np.arange(5, -6, -1) bins = np.arange(4, -6, -1) assert_array_equal(digitize(x, bins, True), np.arange(11))
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @xpassIfTorchDynamo # (reason="TODO: implement") class TestDigitize(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_right_open_random
def test_right_open_random(self): x = rand(10) bins = np.linspace(x.min(), x.max(), 10) assert_(np.all(digitize(x, bins, True) != 10))
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @xpassIfTorchDynamo # (reason="TODO: implement") class TestDigitize(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_monotonic
def test_monotonic(self): x = [-1, 0, 1, 2] bins = [0, 0, 1] assert_array_equal(digitize(x, bins, False), [0, 2, 3, 3]) assert_array_equal(digitize(x, bins, True), [0, 0, 2, 3]) bins = [1, 1, 0] assert_array_equal(digitize(x, bins, False), [3, 2, 0, 0]) assert_array_equal(digitize(x, bins, True), [3, 3, 2, 0]) bins = [1, 1, 1, 1] assert_array_equal(digitize(x, bins, False), [0, 0, 4, 4]) assert_array_equal(digitize(x, bins, True), [0, 0, 0, 4]) bins = [0, 0, 1, 0] assert_raises(ValueError, digitize, x, bins) bins = [1, 1, 0, 1] assert_raises(ValueError, digitize, x, bins)
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @xpassIfTorchDynamo # (reason="TODO: implement") class TestDigitize(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_aweights
def test_aweights(self): assert_allclose(cov(self.x1, aweights=self.weights), self.res3) assert_allclose( cov(self.x1, aweights=3.0 * self.weights), cov(self.x1, aweights=self.weights), ) assert_allclose(cov(self.x1, aweights=self.unit_weights), self.res1) w = np.ones((2, 3)) assert_raises(RuntimeError, cov, self.x1, aweights=w) w = np.ones(2) assert_raises(RuntimeError, cov, self.x1, aweights=w) w = -1.0 * np.ones(3) assert_raises((ValueError, RuntimeError), cov, self.x1, aweights=w)
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @instantiate_parametrized_tests class TestCov(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_cov_dtype
def test_cov_dtype(self, test_type): cast_x1 = self.x1.astype(test_type) res = cov(cast_x1, dtype=test_type) assert test_type == res.dtype
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @instantiate_parametrized_tests class TestCov(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_simple
def test_simple(self): def addsubtract(a, b): if a > b: return a - b else: return a + b f = vectorize(addsubtract) r = f([0, 3, 6, 9], [1, 3, 5, 7]) assert_array_equal(r, [1, 6, 1, 2])
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) @skip # (reason="vectorize not implemented") class TestVectorize(TestCase): import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_complex
def test_complex(self): x = np.array([[1, 2, 3], [1j, 2j, 3j]]) res = corrcoef(x) tgt = np.array([[1.0, -1.0j], [1.0j, 1.0]]) assert_allclose(res, tgt) assert_(np.all(np.abs(res) <= 1.0))
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @instantiate_parametrized_tests class TestCorrCoef(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_simple
def test_simple(self): def addsubtract(a, b): if a > b: return a - b else: return a + b f = vectorize(addsubtract) r = f([0, 3, 6, 9], [1, 3, 5, 7]) assert_array_equal(r, [1, 6, 1, 2])
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) @skip # (reason="vectorize not implemented") class TestVectorize(TestCase): import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_int_beta
def test_int_beta(self): kaiser(3, 4)
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random class TestKaiser(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_simple
def test_simple(self): def addsubtract(a, b): if a > b: return a - b else: return a + b f = vectorize(addsubtract) r = f([0, 3, 6, 9], [1, 3, 5, 7]) assert_array_equal(r, [1, 6, 1, 2])
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) @skip # (reason="vectorize not implemented") class TestVectorize(TestCase): import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_simple
def test_simple(self): def addsubtract(a, b): if a > b: return a - b else: return a + b f = vectorize(addsubtract) r = f([0, 3, 6, 9], [1, 3, 5, 7]) assert_array_equal(r, [1, 6, 1, 2])
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) @skip # (reason="vectorize not implemented") class TestVectorize(TestCase): import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_single_input
def test_single_input(self): [X] = meshgrid([1, 2, 3, 4]) assert_array_equal(X, np.array([1, 2, 3, 4]))
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random class TestMeshgrid(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_no_input
def test_no_input(self): args = [] assert_array_equal([], meshgrid(*args)) assert_array_equal([], meshgrid(*args, copy=False))
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random class TestMeshgrid(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_indexing
def test_indexing(self): x = [1, 2, 3] y = [4, 5, 6, 7] [X, Y] = meshgrid(x, y, indexing="ij") assert_array_equal(X, np.array([[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]])) assert_array_equal(Y, np.array([[4, 5, 6, 7], [4, 5, 6, 7], [4, 5, 6, 7]])) # Test expected shapes: z = [8, 9] assert_(meshgrid(x, y)[0].shape == (4, 3)) assert_(meshgrid(x, y, indexing="ij")[0].shape == (3, 4)) assert_(meshgrid(x, y, z)[0].shape == (4, 3, 2)) assert_(meshgrid(x, y, z, indexing="ij")[0].shape == (3, 4, 2)) assert_raises(ValueError, meshgrid, x, y, indexing="notvalid")
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random class TestMeshgrid(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_sparse
def test_sparse(self): [X, Y] = meshgrid([1, 2, 3], [4, 5, 6, 7], sparse=True) assert_array_equal(X, np.array([[1, 2, 3]])) assert_array_equal(Y, np.array([[4], [5], [6], [7]]))
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random class TestMeshgrid(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_invalid_arguments
def test_invalid_arguments(self): # Test that meshgrid complains about invalid arguments # Regression test for issue #4755: # https://github.com/numpy/numpy/issues/4755 assert_raises(TypeError, meshgrid, [1, 2, 3], [4, 5, 6, 7], indices="ij")
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random class TestMeshgrid(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_return_type
def test_return_type(self): # Test for appropriate dtype in returned arrays. # Regression test for issue #5297 # https://github.com/numpy/numpy/issues/5297 x = np.arange(0, 10, dtype=np.float32) y = np.arange(10, 20, dtype=np.float64) X, Y = np.meshgrid(x, y) assert_(X.dtype == x.dtype) assert_(Y.dtype == y.dtype) # copy X, Y = np.meshgrid(x, y, copy=True) assert_(X.dtype == x.dtype) assert_(Y.dtype == y.dtype) # sparse X, Y = np.meshgrid(x, y, sparse=True) assert_(X.dtype == x.dtype) assert_(Y.dtype == y.dtype)
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random class TestMeshgrid(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_writeback
def test_writeback(self): # Issue 8561 X = np.array([1.1, 2.2]) Y = np.array([3.3, 4.4]) x, y = np.meshgrid(X, Y, sparse=False, copy=True) x[0, :] = 0 assert_equal(x[0, :], 0) assert_equal(x[1, :], X)
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random class TestMeshgrid(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_nd_shape
def test_nd_shape(self): a, b, c, d, e = np.meshgrid(*([0] * i for i in range(1, 6))) expected_shape = (2, 1, 3, 4, 5) assert_equal(a.shape, expected_shape) assert_equal(b.shape, expected_shape) assert_equal(c.shape, expected_shape) assert_equal(d.shape, expected_shape) assert_equal(e.shape, expected_shape)
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random class TestMeshgrid(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_nd_values
def test_nd_values(self): a, b, c = np.meshgrid([0], [1, 2], [3, 4, 5]) assert_equal(a, [[[0, 0, 0]], [[0, 0, 0]]]) assert_equal(b, [[[1, 1, 1]], [[2, 2, 2]]]) assert_equal(c, [[[3, 4, 5]], [[3, 4, 5]]])
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random class TestMeshgrid(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_nd_indexing
def test_nd_indexing(self): a, b, c = np.meshgrid([0], [1, 2], [3, 4, 5], indexing="ij") assert_equal(a, [[[0, 0, 0], [0, 0, 0]]]) assert_equal(b, [[[1, 1, 1], [2, 2, 2]]]) assert_equal(c, [[[3, 4, 5], [3, 4, 5]]])
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random class TestMeshgrid(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_simple
def test_simple(self): def addsubtract(a, b): if a > b: return a - b else: return a + b f = vectorize(addsubtract) r = f([0, 3, 6, 9], [1, 3, 5, 7]) assert_array_equal(r, [1, 6, 1, 2])
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) @skip # (reason="vectorize not implemented") class TestVectorize(TestCase): import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_two_conditions
def test_two_conditions(self): x = piecewise([1, 2], [[True, False], [False, True]], [3, 4]) assert_array_equal(x, [3, 4])
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @xfail # (reason="TODO: implement") class TestPiecewise(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_scalar_domains_three_conditions
def test_scalar_domains_three_conditions(self): x = piecewise(3, [True, False, False], [4, 2, 0]) assert_equal(x, 4)
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @xfail # (reason="TODO: implement") class TestPiecewise(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_default
def test_default(self): # No value specified for x[1], should be 0 x = piecewise([1, 2], [True, False], [2]) assert_array_equal(x, [2, 0]) # Should set x[1] to 3 x = piecewise([1, 2], [True, False], [2, 3]) assert_array_equal(x, [2, 3])
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @xfail # (reason="TODO: implement") class TestPiecewise(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_0d
def test_0d(self): a = np.array(1) with pytest.raises(np.AxisError): insert(a, [], 2, axis=0) with pytest.raises(TypeError): insert(a, [], 2, axis="nonsense")
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) @xpassIfTorchDynamo # (reason="TODO: implement") @instantiate_parametrized_tests class TestInsert(TestCase): import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_0d_comparison
def test_0d_comparison(self): x = 3 y = piecewise(x, [x <= 3, x > 3], [4, 0]) # Should succeed. assert_equal(y, 4) # With 3 ranges (It was failing, before) x = 4 y = piecewise(x, [x <= 3, (x > 3) * (x <= 5), x > 5], [1, 2, 3]) assert_array_equal(y, 2) assert_raises_regex( ValueError, "2 or 3 functions are expected", piecewise, x, [x <= 3, x > 3], [1], ) assert_raises_regex( ValueError, "2 or 3 functions are expected", piecewise, x, [x <= 3, x > 3], [1, 1, 1, 1], )
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @xfail # (reason="TODO: implement") class TestPiecewise(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_0d_0d_condition
def test_0d_0d_condition(self): x = np.array(3) c = np.array(x > 3) y = piecewise(x, [c], [1, 2]) assert_equal(y, 2)
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @xfail # (reason="TODO: implement") class TestPiecewise(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_multidimensional_extrafunc
def test_multidimensional_extrafunc(self): x = np.array([[-2.5, -1.5, -0.5], [0.5, 1.5, 2.5]]) y = piecewise(x, [x < 0, x >= 2], [-1, 1, 3]) assert_array_equal(y, np.array([[-1.0, -1.0, -1.0], [3.0, 3.0, 1.0]]))
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @xfail # (reason="TODO: implement") class TestPiecewise(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_simple
def test_simple(self): def addsubtract(a, b): if a > b: return a - b else: return a + b f = vectorize(addsubtract) r = f([0, 3, 6, 9], [1, 3, 5, 7]) assert_array_equal(r, [1, 6, 1, 2])
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) @skip # (reason="vectorize not implemented") class TestVectorize(TestCase): import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_simple2
def test_simple2(self): y = np.bincount(np.array([1, 5, 2, 4, 1])) assert_array_equal(y, np.array([0, 2, 1, 0, 1, 1]))
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @instantiate_parametrized_tests class TestBincount(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_simple_weight
def test_simple_weight(self): x = np.arange(4) w = np.array([0.2, 0.3, 0.5, 0.1]) y = np.bincount(x, w) assert_array_equal(y, w)
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @instantiate_parametrized_tests class TestBincount(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_basic
def test_basic(self): assert_raises(ValueError, np.rot90, np.ones(4)) assert_raises( (ValueError, RuntimeError), np.rot90, np.ones((2, 2, 2)), axes=(0, 1, 2) ) assert_raises(ValueError, np.rot90, np.ones((2, 2)), axes=(0, 2)) assert_raises(ValueError, np.rot90, np.ones((2, 2)), axes=(1, 1)) assert_raises(ValueError, np.rot90, np.ones((2, 2, 2)), axes=(-2, 1)) a = [[0, 1, 2], [3, 4, 5]] b1 = [[2, 5], [1, 4], [0, 3]] b2 = [[5, 4, 3], [2, 1, 0]] b3 = [[3, 0], [4, 1], [5, 2]] b4 = [[0, 1, 2], [3, 4, 5]] for k in range(-3, 13, 4): assert_equal(np.rot90(a, k=k), b1) for k in range(-2, 13, 4): assert_equal(np.rot90(a, k=k), b2) for k in range(-1, 13, 4): assert_equal(np.rot90(a, k=k), b3) for k in range(0, 13, 4): assert_equal(np.rot90(a, k=k), b4) assert_equal(np.rot90(np.rot90(a, axes=(0, 1)), axes=(1, 0)), a) assert_equal(np.rot90(a, k=1, axes=(1, 0)), np.rot90(a, k=-1, axes=(0, 1)))
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) class TestRot90(TestCase): import random
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_right_left_behavior
def test_right_left_behavior(self): # Needs range of sizes to test different code paths. # size ==1 is special cased, 1 < size < 5 is linear search, and # size >= 5 goes through local search and possibly binary search. for size in range(1, 10): xp = np.arange(size, dtype=np.double) yp = np.ones(size, dtype=np.double) incpts = np.array([-1, 0, size - 1, size], dtype=np.double) decpts = incpts[::-1] incres = interp(incpts, xp, yp) decres = interp(decpts, xp, yp) inctgt = np.array([1, 1, 1, 1], dtype=float) dectgt = inctgt[::-1] assert_equal(incres, inctgt) assert_equal(decres, dectgt) incres = interp(incpts, xp, yp, left=0) decres = interp(decpts, xp, yp, left=0) inctgt = np.array([0, 1, 1, 1], dtype=float) dectgt = inctgt[::-1] assert_equal(incres, inctgt) assert_equal(decres, dectgt) incres = interp(incpts, xp, yp, right=2) decres = interp(decpts, xp, yp, right=2) inctgt = np.array([1, 1, 1, 2], dtype=float) dectgt = inctgt[::-1] assert_equal(incres, inctgt) assert_equal(decres, dectgt) incres = interp(incpts, xp, yp, left=0, right=2) decres = interp(decpts, xp, yp, left=0, right=2) inctgt = np.array([0, 1, 1, 2], dtype=float) dectgt = inctgt[::-1] assert_equal(incres, inctgt) assert_equal(decres, dectgt)
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random parametrize_interp_sc = parametrize( "sc", [ subtest(lambda x: np.float64(x), name="real"), subtest(lambda x: _make_complex(x, 0), name="complex-real"), subtest(lambda x: _make_complex(0, x), name="complex-imag"), subtest(lambda x: _make_complex(x, np.multiply(x, -2)), name="complex-both"), ], ) @xpassIfTorchDynamo # (reason="TODO: implement") @instantiate_parametrized_tests class TestInterp(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_scalar_interpolation_point
def test_scalar_interpolation_point(self): x = np.linspace(0, 1, 5) y = np.linspace(0, 1, 5) x0 = 0 assert_almost_equal(np.interp(x0, x, y), x0) x0 = 0.3 assert_almost_equal(np.interp(x0, x, y), x0) x0 = np.float32(0.3) assert_almost_equal(np.interp(x0, x, y), x0) x0 = np.float64(0.3) assert_almost_equal(np.interp(x0, x, y), x0) x0 = np.nan assert_almost_equal(np.interp(x0, x, y), x0)
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random parametrize_interp_sc = parametrize( "sc", [ subtest(lambda x: np.float64(x), name="real"), subtest(lambda x: _make_complex(x, 0), name="complex-real"), subtest(lambda x: _make_complex(0, x), name="complex-imag"), subtest(lambda x: _make_complex(x, np.multiply(x, -2)), name="complex-both"), ], ) @xpassIfTorchDynamo # (reason="TODO: implement") @instantiate_parametrized_tests class TestInterp(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_non_finite_half_inf_f
def test_non_finite_half_inf_f(self, sc): """Test interp where the f axis has a bound at inf""" assert_equal(np.interp(0.5, [0, 1], sc([0, -np.inf])), sc(-np.inf)) assert_equal(np.interp(0.5, [0, 1], sc([0, +np.inf])), sc(+np.inf)) assert_equal(np.interp(0.5, [0, 1], sc([-np.inf, 10])), sc(-np.inf)) assert_equal(np.interp(0.5, [0, 1], sc([+np.inf, 10])), sc(+np.inf)) assert_equal(np.interp(0.5, [0, 1], sc([-np.inf, -np.inf])), sc(-np.inf)) assert_equal(np.interp(0.5, [0, 1], sc([+np.inf, +np.inf])), sc(+np.inf))
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random parametrize_interp_sc = parametrize( "sc", [ subtest(lambda x: np.float64(x), name="real"), subtest(lambda x: _make_complex(x, 0), name="complex-real"), subtest(lambda x: _make_complex(0, x), name="complex-imag"), subtest(lambda x: _make_complex(x, np.multiply(x, -2)), name="complex-both"), ], ) @xpassIfTorchDynamo # (reason="TODO: implement") @instantiate_parametrized_tests class TestInterp(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_complex_interp
def test_complex_interp(self): # test complex interpolation x = np.linspace(0, 1, 5) y = np.linspace(0, 1, 5) + (1 + np.linspace(0, 1, 5)) * 1.0j x0 = 0.3 y0 = x0 + (1 + x0) * 1.0j assert_almost_equal(np.interp(x0, x, y), y0) # test complex left and right x0 = -1 left = 2 + 3.0j assert_almost_equal(np.interp(x0, x, y, left=left), left) x0 = 2.0 right = 2 + 3.0j assert_almost_equal(np.interp(x0, x, y, right=right), right) # test complex non finite x = [1, 2, 2.5, 3, 4] xp = [1, 2, 3, 4] fp = [1, 2 + 1j, np.inf, 4] y = [1, 2 + 1j, np.inf + 0.5j, np.inf, 4] assert_almost_equal(np.interp(x, xp, fp), y) # test complex periodic x = [-180, -170, -185, 185, -10, -5, 0, 365] xp = [190, -190, 350, -350] fp = [5 + 1.0j, 10 + 2j, 3 + 3j, 4 + 4j] y = [ 7.5 + 1.5j, 5.0 + 1.0j, 8.75 + 1.75j, 6.25 + 1.25j, 3.0 + 3j, 3.25 + 3.25j, 3.5 + 3.5j, 3.75 + 3.75j, ] assert_almost_equal(np.interp(x, xp, fp, period=360), y)
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random parametrize_interp_sc = parametrize( "sc", [ subtest(lambda x: np.float64(x), name="real"), subtest(lambda x: _make_complex(x, 0), name="complex-real"), subtest(lambda x: _make_complex(0, x), name="complex-imag"), subtest(lambda x: _make_complex(x, np.multiply(x, -2)), name="complex-both"), ], ) @xpassIfTorchDynamo # (reason="TODO: implement") @instantiate_parametrized_tests class TestInterp(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_simple_weight2
def test_simple_weight2(self): x = np.array([1, 2, 4, 5, 2]) w = np.array([0.2, 0.3, 0.5, 0.1, 0.2]) y = np.bincount(x, w) assert_array_equal(y, np.array([0, 0.2, 0.5, 0, 0.5, 0.1]))
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @instantiate_parametrized_tests class TestBincount(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_with_minlength
def test_with_minlength(self): x = np.array([0, 1, 0, 1, 1]) y = np.bincount(x, minlength=3) assert_array_equal(y, np.array([2, 3, 0])) x = [] y = np.bincount(x, minlength=0) assert_array_equal(y, np.array([]))
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @instantiate_parametrized_tests class TestBincount(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_with_minlength_smaller_than_maxvalue
def test_with_minlength_smaller_than_maxvalue(self): x = np.array([0, 1, 1, 2, 2, 3, 3]) y = np.bincount(x, minlength=2) assert_array_equal(y, np.array([1, 2, 2, 2])) y = np.bincount(x, minlength=0) assert_array_equal(y, np.array([1, 2, 2, 2]))
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @instantiate_parametrized_tests class TestBincount(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_with_minlength_and_weights
def test_with_minlength_and_weights(self): x = np.array([1, 2, 4, 5, 2]) w = np.array([0.2, 0.3, 0.5, 0.1, 0.2]) y = np.bincount(x, w, 8) assert_array_equal(y, np.array([0, 0.2, 0.5, 0, 0.5, 0.1, 0, 0]))
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @instantiate_parametrized_tests class TestBincount(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added
torch
test/torch_np/numpy_tests/lib/test_function_base.py
test_empty
def test_empty(self): with warnings.catch_warnings(record=True): warnings.simplefilter("always", RuntimeWarning) assert_array_equal(corrcoef(np.array([])), np.nan) assert_array_equal( corrcoef(np.array([]).reshape(0, 2)), np.array([]).reshape(0, 0) ) assert_array_equal( corrcoef(np.array([]).reshape(2, 0)), np.array([[np.nan, np.nan], [np.nan, np.nan]]), )
import functools import math import operator import sys import warnings from fractions import Fraction from unittest import expectedFailure as xfail, skipIf as skipif import hypothesis import hypothesis.strategies as st import numpy import pytest from hypothesis.extra.numpy import arrays from pytest import raises as assert_raises from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo, ) skip = functools.partial(skipif, True) HAS_REFCOUNT = True IS_WASM = False IS_PYPY = False from numpy.lib import delete, extract, insert, msort, place, setxor1d, unwrap, vectorize import numpy as np from numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, digitize, flipud, gradient, hamming, hanning, i0, interp, kaiser, meshgrid, sinc, trapz, trim_zeros, unique, ) from numpy.core.numeric import normalize_axis_tuple from numpy.random import rand from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import torch._numpy as np from torch._numpy import ( angle, bartlett, blackman, corrcoef, cov, diff, flipud, gradient, hamming, hanning, i0, kaiser, meshgrid, sinc, unique, ) from torch._numpy._util import normalize_axis_tuple from torch._numpy.random import rand from torch._numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises_regex, assert_warns, suppress_warnings, ) import random @instantiate_parametrized_tests class TestCorrCoef(TestCase):
c263bd43e8e8502d4726643bc6fd046f0130ac0e
32f585d9346e316e554c8d9bf7548af9f62141fc
added