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/core/test_shape_base.py
|
test_1D_array
|
def test_1D_array(self):
a = array([1, 2])
b = array([2, 3])
res = [atleast_1d(a), atleast_1d(b)]
desired = [array([1, 2]), array([2, 3])]
assert_array_equal(res, desired)
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
class TestAtleast1d(TestCase):
import operator
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_2D_array
|
def test_2D_array(self):
a = array([[1, 2], [1, 2]])
b = array([[2, 3], [2, 3]])
res = [atleast_1d(a), atleast_1d(b)]
desired = [a, b]
assert_array_equal(res, desired)
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
class TestAtleast1d(TestCase):
import operator
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_3D_array
|
def test_3D_array(self):
a = array([[1, 2], [1, 2]])
b = array([[2, 3], [2, 3]])
a = array([a, a])
b = array([b, b])
res = [atleast_1d(a), atleast_1d(b)]
desired = [a, b]
assert_array_equal(res, desired)
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
class TestAtleast1d(TestCase):
import operator
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_non_iterable
|
def test_non_iterable(self):
assert_raises(TypeError, hstack, 1)
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
class TestHstack(TestCase):
import operator
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_empty_input
|
def test_empty_input(self):
assert_raises(ValueError, hstack, ())
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
class TestHstack(TestCase):
import operator
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_0D_array
|
def test_0D_array(self):
a = array(1)
b = array(2)
res = [atleast_1d(a), atleast_1d(b)]
desired = [array([1]), array([2])]
assert_array_equal(res, desired)
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
class TestAtleast1d(TestCase):
import operator
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_1D_array
|
def test_1D_array(self):
a = array([1, 2])
b = array([2, 3])
res = [atleast_1d(a), atleast_1d(b)]
desired = [array([1, 2]), array([2, 3])]
assert_array_equal(res, desired)
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
class TestAtleast1d(TestCase):
import operator
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_2D_array
|
def test_2D_array(self):
a = array([[1, 2], [1, 2]])
b = array([[2, 3], [2, 3]])
res = [atleast_1d(a), atleast_1d(b)]
desired = [a, b]
assert_array_equal(res, desired)
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
class TestAtleast1d(TestCase):
import operator
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_casting_and_dtype
|
def test_casting_and_dtype(self):
a = np.array([1, 2, 3])
b = np.array([2.5, 3.5, 4.5])
res = np.hstack(np.append(a, b), casting="unsafe", dtype=np.int64)
expected_res = np.array([1, 2, 3, 2, 3, 4])
assert_array_equal(res, expected_res)
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
class TestHstack(TestCase):
import operator
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_casting_and_dtype_type_error
|
def test_casting_and_dtype_type_error(self):
a = np.array([1, 2, 3])
b = np.array([2.5, 3.5, 4.5])
with pytest.raises(TypeError):
hstack((a, b), casting="safe", dtype=np.int64)
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
class TestHstack(TestCase):
import operator
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_non_iterable
|
def test_non_iterable(self):
assert_raises(TypeError, hstack, 1)
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
class TestHstack(TestCase):
import operator
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_empty_input
|
def test_empty_input(self):
assert_raises(ValueError, hstack, ())
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
class TestHstack(TestCase):
import operator
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_0D_array
|
def test_0D_array(self):
a = array(1)
b = array(2)
res = [atleast_1d(a), atleast_1d(b)]
desired = [array([1]), array([2])]
assert_array_equal(res, desired)
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
class TestAtleast1d(TestCase):
import operator
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_1D_array
|
def test_1D_array(self):
a = array([1, 2])
b = array([2, 3])
res = [atleast_1d(a), atleast_1d(b)]
desired = [array([1, 2]), array([2, 3])]
assert_array_equal(res, desired)
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
class TestAtleast1d(TestCase):
import operator
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_2D_array
|
def test_2D_array(self):
a = array([[1, 2], [1, 2]])
b = array([[2, 3], [2, 3]])
res = [atleast_1d(a), atleast_1d(b)]
desired = [a, b]
assert_array_equal(res, desired)
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
class TestAtleast1d(TestCase):
import operator
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_casting_and_dtype
|
def test_casting_and_dtype(self):
a = np.array([1, 2, 3])
b = np.array([2.5, 3.5, 4.5])
res = np.hstack(np.append(a, b), casting="unsafe", dtype=np.int64)
expected_res = np.array([1, 2, 3, 2, 3, 4])
assert_array_equal(res, expected_res)
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
class TestHstack(TestCase):
import operator
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_casting_and_dtype_type_error
|
def test_casting_and_dtype_type_error(self):
a = np.array([1, 2, 3])
b = np.array([2.5, 3.5, 4.5])
with pytest.raises(TypeError):
hstack((a, b), casting="safe", dtype=np.int64)
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
class TestHstack(TestCase):
import operator
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_out_and_dtype_simple
|
def test_out_and_dtype_simple(self):
# numpy raises TypeError on both out=... and dtype=...
a, b, out = np.ones(3), np.ones(4), np.ones(3 + 4)
with pytest.raises(TypeError):
np.concatenate((a, b), out=out, dtype=float)
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
@instantiate_parametrized_tests
class TestConcatenate(TestCase):
import operator
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_returns_copy
|
def test_returns_copy(self):
a = np.eye(3)
b = np.concatenate([a])
b[0, 0] = 2
assert b[0, 0] != a[0, 0]
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
@instantiate_parametrized_tests
class TestConcatenate(TestCase):
import operator
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_exceptions
|
def test_exceptions(self):
# test axis must be in bounds
for ndim in [1, 2, 3]:
a = np.ones((1,) * ndim)
np.concatenate((a, a), axis=0) # OK
assert_raises((IndexError, np.AxisError), np.concatenate, (a, a), axis=ndim)
assert_raises(
(IndexError, np.AxisError), np.concatenate, (a, a), axis=-(ndim + 1)
)
# Scalars cannot be concatenated
assert_raises((RuntimeError, ValueError), concatenate, (0,))
assert_raises((RuntimeError, ValueError), concatenate, (np.array(0),))
# dimensionality must match
assert_raises(
(RuntimeError, ValueError),
# assert_raises_regex(
# ValueError,
# r"all the input arrays must have same number of dimensions, but "
# r"the array at index 0 has 1 dimension\(s\) and the array at "
# r"index 1 has 2 dimension\(s\)",
np.concatenate,
(np.zeros(1), np.zeros((1, 1))),
)
# test shapes must match except for concatenation axis
a = np.ones((1, 2, 3))
b = np.ones((2, 2, 3))
axis = list(range(3))
for i in range(3):
np.concatenate((a, b), axis=axis[0]) # OK
# assert_raises_regex(
assert_raises(
(RuntimeError, ValueError),
# "all the input array dimensions except for the concatenation axis "
# "must match exactly, but along dimension {}, the array at "
# "index 0 has size 1 and the array at index 1 has size 2"
# .format(i),
np.concatenate,
(a, b),
axis=axis[1],
)
assert_raises(
(RuntimeError, ValueError), np.concatenate, (a, b), axis=axis[2]
)
a = np.moveaxis(a, -1, 0)
b = np.moveaxis(b, -1, 0)
axis.append(axis.pop(0))
# No arrays to concatenate raises ValueError
assert_raises(ValueError, concatenate, ())
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
@instantiate_parametrized_tests
class TestConcatenate(TestCase):
import operator
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_large_concatenate_axis_None
|
def test_large_concatenate_axis_None(self):
# When no axis is given, concatenate uses flattened versions.
# This also had a bug with many arrays (see gh-5979).
x = np.arange(1, 100)
r = np.concatenate(x, None)
assert np.all(x == r)
# This should probably be deprecated:
r = np.concatenate(x, 100) # axis is >= MAXDIMS
assert_array_equal(x, r)
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
@instantiate_parametrized_tests
class TestConcatenate(TestCase):
import operator
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_operator_concat
|
def test_operator_concat(self):
import operator
a = array([1, 2])
b = array([3, 4])
n = [1, 2]
res = array([1, 2, 3, 4])
assert_raises(TypeError, operator.concat, a, b)
assert_raises(TypeError, operator.concat, a, n)
assert_raises(TypeError, operator.concat, n, a)
assert_raises(TypeError, operator.concat, a, 1)
assert_raises(TypeError, operator.concat, 1, a)
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
@instantiate_parametrized_tests
class TestConcatenate(TestCase):
import operator
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_out_and_dtype
|
def test_out_and_dtype(self, axis, out_dtype, casting):
# Compare usage of `out=out` with `dtype=out.dtype`
out = np.empty(4, dtype=out_dtype)
to_concat = (array([1.1, 2.2]), array([3.3, 4.4]))
if not np.can_cast(to_concat[0], out_dtype, casting=casting):
with assert_raises(TypeError):
concatenate(to_concat, out=out, axis=axis, casting=casting)
with assert_raises(TypeError):
concatenate(to_concat, dtype=out.dtype, axis=axis, casting=casting)
else:
res_out = concatenate(to_concat, out=out, axis=axis, casting=casting)
res_dtype = concatenate(
to_concat, dtype=out.dtype, axis=axis, casting=casting
)
assert res_out is out
assert_array_equal(out, res_dtype)
assert res_dtype.dtype == out_dtype
with assert_raises(TypeError):
concatenate(to_concat, out=out, dtype=out_dtype, axis=axis)
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
@instantiate_parametrized_tests
class TestConcatenate(TestCase):
import operator
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_stack_out_and_dtype
|
def test_stack_out_and_dtype(self, axis, out_dtype, casting):
to_concat = (array([1, 2]), array([3, 4]))
res = array([[1, 2], [3, 4]])
out = np.zeros_like(res)
if not np.can_cast(to_concat[0], out_dtype, casting=casting):
with assert_raises(TypeError):
stack(to_concat, dtype=out_dtype, axis=axis, casting=casting)
else:
res_out = stack(to_concat, out=out, axis=axis, casting=casting)
res_dtype = stack(to_concat, dtype=out_dtype, axis=axis, casting=casting)
assert res_out is out
assert_array_equal(out, res_dtype)
assert res_dtype.dtype == out_dtype
with assert_raises(TypeError):
stack(to_concat, out=out, dtype=out_dtype, axis=axis)
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
import operator
@instantiate_parametrized_tests
class TestStackMisc(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
block
|
def block(self, request):
# blocking small arrays and large arrays go through different paths.
# the algorithm is triggered depending on the number of element
# copies required.
# We define a test fixture that forces most tests to go through
# both code paths.
# Ultimately, this should be removed if a single algorithm is found
# to be faster for both small and large arrays.
def _block_force_concatenate(arrays):
arrays, list_ndim, result_ndim, _ = _block_setup(arrays)
return _block_concatenate(arrays, list_ndim, result_ndim)
def _block_force_slicing(arrays):
arrays, list_ndim, result_ndim, _ = _block_setup(arrays)
return _block_slicing(arrays, list_ndim, result_ndim)
if request.param == "force_concatenate":
return _block_force_concatenate
elif request.param == "force_slicing":
return _block_force_slicing
elif request.param == "block":
return block
else:
raise ValueError("Unknown blocking request. There is a typo in the tests.")
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
import operator
@xfail # (reason="TODO: implement block(...)")
@instantiate_parametrized_tests
class TestBlock(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
_block_force_concatenate
|
def _block_force_concatenate(arrays):
arrays, list_ndim, result_ndim, _ = _block_setup(arrays)
return _block_concatenate(arrays, list_ndim, result_ndim)
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
import operator
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
_block_force_slicing
|
def _block_force_slicing(arrays):
arrays, list_ndim, result_ndim, _ = _block_setup(arrays)
return _block_slicing(arrays, list_ndim, result_ndim)
if request.param == "force_concatenate":
return _block_force_concatenate
elif request.param == "force_slicing":
return _block_force_slicing
elif request.param == "block":
return block
else:
raise ValueError("Unknown blocking request. There is a typo in the tests.")
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
import operator
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/fft/test_pocketfft.py
|
test_fft_with_order
|
def test_fft_with_order(self, dtype, order, fft):
# Check that FFT/IFFT produces identical results for C, Fortran and
# non contiguous arrays
# rng = np.random.RandomState(42)
rng = np.random
X = rng.rand(8, 7, 13).astype(dtype) # , copy=False)
# See discussion in pull/14178
_tol = float(8.0 * np.sqrt(np.log2(X.size)) * np.finfo(X.dtype).eps)
if order == "F":
raise SkipTest("Fortran order arrays")
Y = np.asfortranarray(X)
else:
# Make a non contiguous array
Z = np.empty((16, 7, 13), dtype=X.dtype)
Z[::2] = X
Y = Z[::2]
X = Y.copy()
if fft.__name__.endswith("fft"):
for axis in range(3):
X_res = fft(X, axis=axis)
Y_res = fft(Y, axis=axis)
assert_allclose(X_res, Y_res, atol=_tol, rtol=_tol)
elif fft.__name__.endswith(("fft2", "fftn")):
axes = [(0, 1), (1, 2), (0, 2)]
if fft.__name__.endswith("fftn"):
axes.extend([(0,), (1,), (2,), None])
for ax in axes:
X_res = fft(X, axes=ax)
Y_res = fft(Y, axes=ax)
assert_allclose(X_res, Y_res, atol=_tol, rtol=_tol)
else:
raise ValueError
|
import functools
import queue
import threading
from unittest import skipIf as skipif, SkipTest
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
)
import numpy as np
from numpy.random import random
from numpy.testing import assert_allclose # , IS_WASM
import torch._numpy as np
from torch._numpy.random import random
from torch._numpy.testing import assert_allclose # , IS_WASM
skip = functools.partial(skipif, True)
IS_WASM = False
@instantiate_parametrized_tests
class TestFFT1D(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/fft/test_pocketfft.py
|
worker
|
def worker(args, q):
q.put(func(*args))
q = queue.Queue()
expected = func(*args)
# Spin off a bunch of threads to call the same function simultaneously
t = [
threading.Thread(target=worker, args=(args, q)) for i in range(self.threads)
]
[x.start() for x in t]
[x.join() for x in t]
# Make sure all threads returned the correct value
for i in range(self.threads):
# under torch.dynamo `assert_array_equal` fails with relative errors of
# about 1.5e-14. Hence replace it with `assert_allclose(..., rtol=2e-14)`
assert_allclose(
q.get(timeout=5),
expected,
atol=2e-14
# msg="Function returned wrong value in multithreaded context",
)
|
import functools
import queue
import threading
from unittest import skipIf as skipif, SkipTest
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
)
import numpy as np
from numpy.random import random
from numpy.testing import assert_allclose # , IS_WASM
import torch._numpy as np
from torch._numpy.random import random
from torch._numpy.testing import assert_allclose # , IS_WASM
skip = functools.partial(skipif, True)
IS_WASM = False
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/fft/test_pocketfft.py
|
test_ifft
|
def test_ifft(self, norm):
x = random(30) + 1j * random(30)
assert_allclose(x, np.fft.ifft(np.fft.fft(x, norm=norm), norm=norm), atol=1e-6)
# Ensure we get the correct error message
# NB: Exact wording differs slightly under Dynamo and in eager.
with pytest.raises((ValueError, RuntimeError), match="Invalid number of"):
np.fft.ifft([], norm=norm)
|
import functools
import queue
import threading
from unittest import skipIf as skipif, SkipTest
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
)
import numpy as np
from numpy.random import random
from numpy.testing import assert_allclose # , IS_WASM
import torch._numpy as np
from torch._numpy.random import random
from torch._numpy.testing import assert_allclose # , IS_WASM
skip = functools.partial(skipif, True)
IS_WASM = False
@instantiate_parametrized_tests
class TestFFT1D(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/fft/test_pocketfft.py
|
test_rfft
|
def test_rfft(self):
x = random(30)
for n in [x.size, 2 * x.size]:
for norm in [None, "backward", "ortho", "forward"]:
assert_allclose(
np.fft.fft(x, n=n, norm=norm)[: (n // 2 + 1)],
np.fft.rfft(x, n=n, norm=norm),
atol=1e-6,
)
assert_allclose(
np.fft.rfft(x, n=n), np.fft.rfft(x, n=n, norm="backward"), atol=1e-6
)
assert_allclose(
np.fft.rfft(x, n=n) / np.sqrt(n),
np.fft.rfft(x, n=n, norm="ortho"),
atol=1e-6,
)
assert_allclose(
np.fft.rfft(x, n=n) / n, np.fft.rfft(x, n=n, norm="forward"), atol=1e-6
)
|
import functools
import queue
import threading
from unittest import skipIf as skipif, SkipTest
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
)
import numpy as np
from numpy.random import random
from numpy.testing import assert_allclose # , IS_WASM
import torch._numpy as np
from torch._numpy.random import random
from torch._numpy.testing import assert_allclose # , IS_WASM
skip = functools.partial(skipif, True)
IS_WASM = False
@instantiate_parametrized_tests
class TestFFT1D(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/fft/test_pocketfft.py
|
test_irfft
|
def test_irfft(self):
x = random(30)
assert_allclose(x, np.fft.irfft(np.fft.rfft(x)), atol=1e-6)
assert_allclose(
x, np.fft.irfft(np.fft.rfft(x, norm="backward"), norm="backward"), atol=1e-6
)
assert_allclose(
x, np.fft.irfft(np.fft.rfft(x, norm="ortho"), norm="ortho"), atol=1e-6
)
assert_allclose(
x, np.fft.irfft(np.fft.rfft(x, norm="forward"), norm="forward"), atol=1e-6
)
|
import functools
import queue
import threading
from unittest import skipIf as skipif, SkipTest
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
)
import numpy as np
from numpy.random import random
from numpy.testing import assert_allclose # , IS_WASM
import torch._numpy as np
from torch._numpy.random import random
from torch._numpy.testing import assert_allclose # , IS_WASM
skip = functools.partial(skipif, True)
IS_WASM = False
@instantiate_parametrized_tests
class TestFFT1D(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/lib/test_arraypad.py
|
test_check_constant
|
def test_check_constant(self):
a = np.arange(100)
a = np.pad(a, (25, 20), "constant", constant_values=(10, 20))
b = np.array(
[
10,
10,
10,
10,
10,
10,
10,
10,
10,
10,
10,
10,
10,
10,
10,
10,
10,
10,
10,
10,
10,
10,
10,
10,
10,
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53,
54,
55,
56,
57,
58,
59,
60,
61,
62,
63,
64,
65,
66,
67,
68,
69,
70,
71,
72,
73,
74,
75,
76,
77,
78,
79,
80,
81,
82,
83,
84,
85,
86,
87,
88,
89,
90,
91,
92,
93,
94,
95,
96,
97,
98,
99,
20,
20,
20,
20,
20,
20,
20,
20,
20,
20,
20,
20,
20,
20,
20,
20,
20,
20,
20,
20,
]
)
assert_array_equal(a, b)
|
from unittest import skipIf as skipif
from torch.testing._internal.common_utils import (
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy.testing import assert_allclose, assert_array_equal
import torch._numpy as np
from torch._numpy.testing import assert_allclose, assert_array_equal
class TestConstant(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/lib/test_arraypad.py
|
test_check_constant_zeros
|
def test_check_constant_zeros(self):
a = np.arange(100)
a = np.pad(a, (25, 20), "constant")
b = np.array(
[
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53,
54,
55,
56,
57,
58,
59,
60,
61,
62,
63,
64,
65,
66,
67,
68,
69,
70,
71,
72,
73,
74,
75,
76,
77,
78,
79,
80,
81,
82,
83,
84,
85,
86,
87,
88,
89,
90,
91,
92,
93,
94,
95,
96,
97,
98,
99,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
]
)
assert_array_equal(a, b)
|
from unittest import skipIf as skipif
from torch.testing._internal.common_utils import (
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy.testing import assert_allclose, assert_array_equal
import torch._numpy as np
from torch._numpy.testing import assert_allclose, assert_array_equal
class TestConstant(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/lib/test_arraypad.py
|
test_check_constant_float
|
def test_check_constant_float(self):
# If input array is int, but constant_values are float, the dtype of
# the array to be padded is kept
arr = np.arange(30).reshape(5, 6)
test = np.pad(arr, (1, 2), mode="constant", constant_values=1.1)
expected = np.array(
[
[1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 0, 1, 2, 3, 4, 5, 1, 1],
[1, 6, 7, 8, 9, 10, 11, 1, 1],
[1, 12, 13, 14, 15, 16, 17, 1, 1],
[1, 18, 19, 20, 21, 22, 23, 1, 1],
[1, 24, 25, 26, 27, 28, 29, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1],
]
)
assert_allclose(test, expected)
|
from unittest import skipIf as skipif
from torch.testing._internal.common_utils import (
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy.testing import assert_allclose, assert_array_equal
import torch._numpy as np
from torch._numpy.testing import assert_allclose, assert_array_equal
class TestConstant(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/fft/test_pocketfft.py
|
test_irfft
|
def test_irfft(self):
x = random(30)
assert_allclose(x, np.fft.irfft(np.fft.rfft(x)), atol=1e-6)
assert_allclose(
x, np.fft.irfft(np.fft.rfft(x, norm="backward"), norm="backward"), atol=1e-6
)
assert_allclose(
x, np.fft.irfft(np.fft.rfft(x, norm="ortho"), norm="ortho"), atol=1e-6
)
assert_allclose(
x, np.fft.irfft(np.fft.rfft(x, norm="forward"), norm="forward"), atol=1e-6
)
|
import functools
import queue
import threading
from unittest import skipIf as skipif, SkipTest
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
)
import numpy as np
from numpy.random import random
from numpy.testing import assert_allclose # , IS_WASM
import torch._numpy as np
from torch._numpy.random import random
from torch._numpy.testing import assert_allclose # , IS_WASM
skip = functools.partial(skipif, True)
IS_WASM = False
@instantiate_parametrized_tests
class TestFFT1D(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/fft/test_pocketfft.py
|
test_rfft2
|
def test_rfft2(self):
x = random((30, 20))
assert_allclose(np.fft.fft2(x)[:, :11], np.fft.rfft2(x), atol=1e-6)
assert_allclose(np.fft.rfft2(x), np.fft.rfft2(x, norm="backward"), atol=1e-6)
assert_allclose(
np.fft.rfft2(x) / np.sqrt(30 * 20), np.fft.rfft2(x, norm="ortho"), atol=1e-6
)
assert_allclose(
np.fft.rfft2(x) / (30.0 * 20.0), np.fft.rfft2(x, norm="forward"), atol=1e-6
)
|
import functools
import queue
import threading
from unittest import skipIf as skipif, SkipTest
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
)
import numpy as np
from numpy.random import random
from numpy.testing import assert_allclose # , IS_WASM
import torch._numpy as np
from torch._numpy.random import random
from torch._numpy.testing import assert_allclose # , IS_WASM
skip = functools.partial(skipif, True)
IS_WASM = False
@instantiate_parametrized_tests
class TestFFT1D(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/fft/test_pocketfft.py
|
test_irfft2
|
def test_irfft2(self):
x = random((30, 20))
assert_allclose(x, np.fft.irfft2(np.fft.rfft2(x)), atol=1e-6)
assert_allclose(
x,
np.fft.irfft2(np.fft.rfft2(x, norm="backward"), norm="backward"),
atol=1e-6,
)
assert_allclose(
x, np.fft.irfft2(np.fft.rfft2(x, norm="ortho"), norm="ortho"), atol=1e-6
)
assert_allclose(
x, np.fft.irfft2(np.fft.rfft2(x, norm="forward"), norm="forward"), atol=1e-6
)
|
import functools
import queue
import threading
from unittest import skipIf as skipif, SkipTest
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
)
import numpy as np
from numpy.random import random
from numpy.testing import assert_allclose # , IS_WASM
import torch._numpy as np
from torch._numpy.random import random
from torch._numpy.testing import assert_allclose # , IS_WASM
skip = functools.partial(skipif, True)
IS_WASM = False
@instantiate_parametrized_tests
class TestFFT1D(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/fft/test_pocketfft.py
|
test_rfftn
|
def test_rfftn(self):
x = random((30, 20, 10))
assert_allclose(np.fft.fftn(x)[:, :, :6], np.fft.rfftn(x), atol=1e-6)
assert_allclose(np.fft.rfftn(x), np.fft.rfftn(x, norm="backward"), atol=1e-6)
assert_allclose(
np.fft.rfftn(x) / np.sqrt(30 * 20 * 10),
np.fft.rfftn(x, norm="ortho"),
atol=1e-6,
)
assert_allclose(
np.fft.rfftn(x) / (30.0 * 20.0 * 10.0),
np.fft.rfftn(x, norm="forward"),
atol=1e-6,
)
|
import functools
import queue
import threading
from unittest import skipIf as skipif, SkipTest
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
)
import numpy as np
from numpy.random import random
from numpy.testing import assert_allclose # , IS_WASM
import torch._numpy as np
from torch._numpy.random import random
from torch._numpy.testing import assert_allclose # , IS_WASM
skip = functools.partial(skipif, True)
IS_WASM = False
@instantiate_parametrized_tests
class TestFFT1D(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/fft/test_pocketfft.py
|
test_irfftn
|
def test_irfftn(self):
x = random((30, 20, 10))
assert_allclose(x, np.fft.irfftn(np.fft.rfftn(x)), atol=1e-6)
assert_allclose(
x,
np.fft.irfftn(np.fft.rfftn(x, norm="backward"), norm="backward"),
atol=1e-6,
)
assert_allclose(
x, np.fft.irfftn(np.fft.rfftn(x, norm="ortho"), norm="ortho"), atol=1e-6
)
assert_allclose(
x, np.fft.irfftn(np.fft.rfftn(x, norm="forward"), norm="forward"), atol=1e-6
)
|
import functools
import queue
import threading
from unittest import skipIf as skipif, SkipTest
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
)
import numpy as np
from numpy.random import random
from numpy.testing import assert_allclose # , IS_WASM
import torch._numpy as np
from torch._numpy.random import random
from torch._numpy.testing import assert_allclose # , IS_WASM
skip = functools.partial(skipif, True)
IS_WASM = False
@instantiate_parametrized_tests
class TestFFT1D(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/fft/test_pocketfft.py
|
test_hfft
|
def test_hfft(self):
x = random(14) + 1j * random(14)
x_herm = np.concatenate((random(1), x, random(1)))
x = np.concatenate((x_herm, np.flip(x).conj()))
assert_allclose(np.fft.fft(x), np.fft.hfft(x_herm), atol=1e-6)
assert_allclose(
np.fft.hfft(x_herm), np.fft.hfft(x_herm, norm="backward"), atol=1e-6
)
assert_allclose(
np.fft.hfft(x_herm) / np.sqrt(30),
np.fft.hfft(x_herm, norm="ortho"),
atol=1e-6,
)
assert_allclose(
np.fft.hfft(x_herm) / 30.0, np.fft.hfft(x_herm, norm="forward"), atol=1e-6
)
|
import functools
import queue
import threading
from unittest import skipIf as skipif, SkipTest
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
)
import numpy as np
from numpy.random import random
from numpy.testing import assert_allclose # , IS_WASM
import torch._numpy as np
from torch._numpy.random import random
from torch._numpy.testing import assert_allclose # , IS_WASM
skip = functools.partial(skipif, True)
IS_WASM = False
@instantiate_parametrized_tests
class TestFFT1D(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/fft/test_pocketfft.py
|
test_axes
|
def test_axes(self, op):
x = random((30, 20, 10))
axes = [(0, 1, 2), (0, 2, 1), (1, 0, 2), (1, 2, 0), (2, 0, 1), (2, 1, 0)]
for a in axes:
op_tr = op(np.transpose(x, a))
tr_op = np.transpose(op(x, axes=a), a)
assert_allclose(op_tr, tr_op, atol=1e-6)
|
import functools
import queue
import threading
from unittest import skipIf as skipif, SkipTest
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
)
import numpy as np
from numpy.random import random
from numpy.testing import assert_allclose # , IS_WASM
import torch._numpy as np
from torch._numpy.random import random
from torch._numpy.testing import assert_allclose # , IS_WASM
skip = functools.partial(skipif, True)
IS_WASM = False
@instantiate_parametrized_tests
class TestFFT1D(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_returns_copy
|
def test_returns_copy(self):
a = np.eye(3)
b = np.concatenate([a])
b[0, 0] = 2
assert b[0, 0] != a[0, 0]
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
@instantiate_parametrized_tests
class TestConcatenate(TestCase):
import operator
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_block_total_size_estimate
|
def test_block_total_size_estimate(self, block):
_, _, _, total_size = _block_setup([1])
assert total_size == 1
_, _, _, total_size = _block_setup([[1]])
assert total_size == 1
_, _, _, total_size = _block_setup([[1, 1]])
assert total_size == 2
_, _, _, total_size = _block_setup([[1], [1]])
assert total_size == 2
_, _, _, total_size = _block_setup([[1, 2], [3, 4]])
assert total_size == 4
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
import operator
@xfail # (reason="TODO: implement block(...)")
@instantiate_parametrized_tests
class TestBlock(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_block_simple_row_wise
|
def test_block_simple_row_wise(self, block):
a_2d = np.ones((2, 2))
b_2d = 2 * a_2d
desired = np.array([[1, 1, 2, 2], [1, 1, 2, 2]])
result = block([a_2d, b_2d])
assert_equal(desired, result)
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
import operator
@xfail # (reason="TODO: implement block(...)")
@instantiate_parametrized_tests
class TestBlock(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_block_simple_column_wise
|
def test_block_simple_column_wise(self, block):
a_2d = np.ones((2, 2))
b_2d = 2 * a_2d
expected = np.array([[1, 1], [1, 1], [2, 2], [2, 2]])
result = block([[a_2d], [b_2d]])
assert_equal(expected, result)
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
import operator
@xfail # (reason="TODO: implement block(...)")
@instantiate_parametrized_tests
class TestBlock(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_block_with_1d_arrays_row_wise
|
def test_block_with_1d_arrays_row_wise(self, block):
# # # 1-D vectors are treated as row arrays
a = np.array([1, 2, 3])
b = np.array([2, 3, 4])
expected = np.array([1, 2, 3, 2, 3, 4])
result = block([a, b])
assert_equal(expected, result)
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
import operator
@xfail # (reason="TODO: implement block(...)")
@instantiate_parametrized_tests
class TestBlock(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_block_with_1d_arrays_multiple_rows
|
def test_block_with_1d_arrays_multiple_rows(self, block):
a = np.array([1, 2, 3])
b = np.array([2, 3, 4])
expected = np.array([[1, 2, 3, 2, 3, 4], [1, 2, 3, 2, 3, 4]])
result = block([[a, b], [a, b]])
assert_equal(expected, result)
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
import operator
@xfail # (reason="TODO: implement block(...)")
@instantiate_parametrized_tests
class TestBlock(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_block_with_1d_arrays_column_wise
|
def test_block_with_1d_arrays_column_wise(self, block):
# # # 1-D vectors are treated as row arrays
a_1d = np.array([1, 2, 3])
b_1d = np.array([2, 3, 4])
expected = np.array([[1, 2, 3], [2, 3, 4]])
result = block([[a_1d], [b_1d]])
assert_equal(expected, result)
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
import operator
@xfail # (reason="TODO: implement block(...)")
@instantiate_parametrized_tests
class TestBlock(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_block_mixed_1d_and_2d
|
def test_block_mixed_1d_and_2d(self, block):
a_2d = np.ones((2, 2))
b_1d = np.array([2, 2])
result = block([[a_2d], [b_1d]])
expected = np.array([[1, 1], [1, 1], [2, 2]])
assert_equal(expected, result)
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
import operator
@xfail # (reason="TODO: implement block(...)")
@instantiate_parametrized_tests
class TestBlock(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_block_complicated
|
def test_block_complicated(self, block):
# a bit more complicated
one_2d = np.array([[1, 1, 1]])
two_2d = np.array([[2, 2, 2]])
three_2d = np.array([[3, 3, 3, 3, 3, 3]])
four_1d = np.array([4, 4, 4, 4, 4, 4])
five_0d = np.array(5)
six_1d = np.array([6, 6, 6, 6, 6])
zero_2d = np.zeros((2, 6))
expected = np.array(
[
[1, 1, 1, 2, 2, 2],
[3, 3, 3, 3, 3, 3],
[4, 4, 4, 4, 4, 4],
[5, 6, 6, 6, 6, 6],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
]
)
result = block(
[[one_2d, two_2d], [three_2d], [four_1d], [five_0d, six_1d], [zero_2d]]
)
assert_equal(result, expected)
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
import operator
@xfail # (reason="TODO: implement block(...)")
@instantiate_parametrized_tests
class TestBlock(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_nested
|
def test_nested(self, block):
one = np.array([1, 1, 1])
two = np.array([[2, 2, 2], [2, 2, 2], [2, 2, 2]])
three = np.array([3, 3, 3])
four = np.array([4, 4, 4])
five = np.array(5)
six = np.array([6, 6, 6, 6, 6])
zero = np.zeros((2, 6))
result = block([[block([[one], [three], [four]]), two], [five, six], [zero]])
expected = np.array(
[
[1, 1, 1, 2, 2, 2],
[3, 3, 3, 2, 2, 2],
[4, 4, 4, 2, 2, 2],
[5, 6, 6, 6, 6, 6],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
]
)
assert_equal(result, expected)
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
import operator
@xfail # (reason="TODO: implement block(...)")
@instantiate_parametrized_tests
class TestBlock(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_3d
|
def test_3d(self, block):
a000 = np.ones((2, 2, 2), int) * 1
a100 = np.ones((3, 2, 2), int) * 2
a010 = np.ones((2, 3, 2), int) * 3
a001 = np.ones((2, 2, 3), int) * 4
a011 = np.ones((2, 3, 3), int) * 5
a101 = np.ones((3, 2, 3), int) * 6
a110 = np.ones((3, 3, 2), int) * 7
a111 = np.ones((3, 3, 3), int) * 8
result = block(
[
[
[a000, a001],
[a010, a011],
],
[
[a100, a101],
[a110, a111],
],
]
)
expected = array(
[
[
[1, 1, 4, 4, 4],
[1, 1, 4, 4, 4],
[3, 3, 5, 5, 5],
[3, 3, 5, 5, 5],
[3, 3, 5, 5, 5],
],
[
[1, 1, 4, 4, 4],
[1, 1, 4, 4, 4],
[3, 3, 5, 5, 5],
[3, 3, 5, 5, 5],
[3, 3, 5, 5, 5],
],
[
[2, 2, 6, 6, 6],
[2, 2, 6, 6, 6],
[7, 7, 8, 8, 8],
[7, 7, 8, 8, 8],
[7, 7, 8, 8, 8],
],
[
[2, 2, 6, 6, 6],
[2, 2, 6, 6, 6],
[7, 7, 8, 8, 8],
[7, 7, 8, 8, 8],
[7, 7, 8, 8, 8],
],
[
[2, 2, 6, 6, 6],
[2, 2, 6, 6, 6],
[7, 7, 8, 8, 8],
[7, 7, 8, 8, 8],
[7, 7, 8, 8, 8],
],
]
)
assert_array_equal(result, expected)
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
import operator
@xfail # (reason="TODO: implement block(...)")
@instantiate_parametrized_tests
class TestBlock(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_block_with_mismatched_shape
|
def test_block_with_mismatched_shape(self, block):
a = np.array([0, 0])
b = np.eye(2)
assert_raises(ValueError, block, [a, b])
assert_raises(ValueError, block, [b, a])
to_block = [
[np.ones((2, 3)), np.ones((2, 2))],
[np.ones((2, 2)), np.ones((2, 2))],
]
assert_raises(ValueError, block, to_block)
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
import operator
@xfail # (reason="TODO: implement block(...)")
@instantiate_parametrized_tests
class TestBlock(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_no_lists
|
def test_no_lists(self, block):
assert_equal(block(1), np.array(1))
assert_equal(block(np.eye(3)), np.eye(3))
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
import operator
@xfail # (reason="TODO: implement block(...)")
@instantiate_parametrized_tests
class TestBlock(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_invalid_nesting
|
def test_invalid_nesting(self, block):
msg = "depths are mismatched"
assert_raises_regex(ValueError, msg, block, [1, [2]])
assert_raises_regex(ValueError, msg, block, [1, []])
assert_raises_regex(ValueError, msg, block, [[1], 2])
assert_raises_regex(ValueError, msg, block, [[], 2])
assert_raises_regex(
ValueError, msg, block, [[[1], [2]], [[3, 4]], [5]] # missing brackets
)
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
import operator
@xfail # (reason="TODO: implement block(...)")
@instantiate_parametrized_tests
class TestBlock(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_empty_lists
|
def test_empty_lists(self, block):
assert_raises_regex(ValueError, "empty", block, [])
assert_raises_regex(ValueError, "empty", block, [[]])
assert_raises_regex(ValueError, "empty", block, [[1], []])
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
import operator
@xfail # (reason="TODO: implement block(...)")
@instantiate_parametrized_tests
class TestBlock(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_tuple
|
def test_tuple(self, block):
assert_raises_regex(TypeError, "tuple", block, ([1, 2], [3, 4]))
assert_raises_regex(TypeError, "tuple", block, [(1, 2), (3, 4)])
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
import operator
@xfail # (reason="TODO: implement block(...)")
@instantiate_parametrized_tests
class TestBlock(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_different_ndims
|
def test_different_ndims(self, block):
a = 1.0
b = 2 * np.ones((1, 2))
c = 3 * np.ones((1, 1, 3))
result = block([a, b, c])
expected = np.array([[[1.0, 2.0, 2.0, 3.0, 3.0, 3.0]]])
assert_equal(result, expected)
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
import operator
@xfail # (reason="TODO: implement block(...)")
@instantiate_parametrized_tests
class TestBlock(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_different_ndims_depths
|
def test_different_ndims_depths(self, block):
a = 1.0
b = 2 * np.ones((1, 2))
c = 3 * np.ones((1, 2, 3))
result = block([[a, b], [c]])
expected = np.array([[[1.0, 2.0, 2.0], [3.0, 3.0, 3.0], [3.0, 3.0, 3.0]]])
assert_equal(result, expected)
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
import operator
@xfail # (reason="TODO: implement block(...)")
@instantiate_parametrized_tests
class TestBlock(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/core/test_shape_base.py
|
test_block_memory_order
|
def test_block_memory_order(self, block):
# 3D
arr_c = np.zeros((3,) * 3, order="C")
arr_f = np.zeros((3,) * 3, order="F")
b_c = [[[arr_c, arr_c], [arr_c, arr_c]], [[arr_c, arr_c], [arr_c, arr_c]]]
b_f = [[[arr_f, arr_f], [arr_f, arr_f]], [[arr_f, arr_f], [arr_f, arr_f]]]
assert block(b_c).flags["C_CONTIGUOUS"]
assert block(b_f).flags["F_CONTIGUOUS"]
arr_c = np.zeros((3, 3), order="C")
arr_f = np.zeros((3, 3), order="F")
# 2D
b_c = [[arr_c, arr_c], [arr_c, arr_c]]
b_f = [[arr_f, arr_f], [arr_f, arr_f]]
assert block(b_c).flags["C_CONTIGUOUS"]
assert block(b_f).flags["F_CONTIGUOUS"]
|
import functools
from unittest import expectedFailure as xfail, skipIf as skipif
import numpy
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from numpy.testing import assert_, assert_array_equal, assert_equal
import torch._numpy as np
from torch._numpy import (
array,
atleast_1d,
atleast_2d,
atleast_3d,
AxisError,
concatenate,
hstack,
newaxis,
stack,
vstack,
)
from torch._numpy.testing import assert_, assert_array_equal, assert_equal
skip = functools.partial(skipif, True)
IS_PYPY = False
import operator
@xfail # (reason="TODO: implement block(...)")
@instantiate_parametrized_tests
class TestBlock(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/fft/test_helper.py
|
test_definition
|
def test_definition(self):
x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
y = [-4, -3, -2, -1, 0, 1, 2, 3, 4]
assert_array_almost_equal(fft.fftshift(x), y)
assert_array_almost_equal(fft.ifftshift(y), x)
x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
y = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4]
assert_array_almost_equal(fft.fftshift(x), y)
assert_array_almost_equal(fft.ifftshift(y), x)
|
from torch.testing._internal.common_utils import (
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
)
import numpy as np
from numpy import fft, pi
from numpy.testing import assert_array_almost_equal
import torch._numpy as np
from torch._numpy import fft, pi
from torch._numpy.testing import assert_array_almost_equal
class TestFFTShift(TestCase):
from numpy import arange, asarray, concatenate, take
from torch._numpy import arange, asarray, concatenate, take
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/fft/test_helper.py
|
test_inverse
|
def test_inverse(self):
for n in [1, 4, 9, 100, 211]:
x = np.random.random((n,))
assert_array_almost_equal(fft.ifftshift(fft.fftshift(x)), x)
|
from torch.testing._internal.common_utils import (
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
)
import numpy as np
from numpy import fft, pi
from numpy.testing import assert_array_almost_equal
import torch._numpy as np
from torch._numpy import fft, pi
from torch._numpy.testing import assert_array_almost_equal
class TestFFTShift(TestCase):
from numpy import arange, asarray, concatenate, take
from torch._numpy import arange, asarray, concatenate, take
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/fft/test_helper.py
|
test_axes_keyword
|
def test_axes_keyword(self):
freqs = [[0, 1, 2], [3, 4, -4], [-3, -2, -1]]
shifted = [[-1, -3, -2], [2, 0, 1], [-4, 3, 4]]
assert_array_almost_equal(fft.fftshift(freqs, axes=(0, 1)), shifted)
assert_array_almost_equal(
fft.fftshift(freqs, axes=0), fft.fftshift(freqs, axes=(0,))
)
assert_array_almost_equal(fft.ifftshift(shifted, axes=(0, 1)), freqs)
assert_array_almost_equal(
fft.ifftshift(shifted, axes=0), fft.ifftshift(shifted, axes=(0,))
)
assert_array_almost_equal(fft.fftshift(freqs), shifted)
assert_array_almost_equal(fft.ifftshift(shifted), freqs)
|
from torch.testing._internal.common_utils import (
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
)
import numpy as np
from numpy import fft, pi
from numpy.testing import assert_array_almost_equal
import torch._numpy as np
from torch._numpy import fft, pi
from torch._numpy.testing import assert_array_almost_equal
class TestFFTShift(TestCase):
from numpy import arange, asarray, concatenate, take
from torch._numpy import arange, asarray, concatenate, take
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/fft/test_helper.py
|
test_uneven_dims
|
def test_uneven_dims(self):
"""Test 2D input, which has uneven dimension sizes"""
freqs = [[0, 1], [2, 3], [4, 5]]
# shift in dimension 0
shift_dim0 = [[4, 5], [0, 1], [2, 3]]
assert_array_almost_equal(fft.fftshift(freqs, axes=0), shift_dim0)
assert_array_almost_equal(fft.ifftshift(shift_dim0, axes=0), freqs)
assert_array_almost_equal(fft.fftshift(freqs, axes=(0,)), shift_dim0)
assert_array_almost_equal(fft.ifftshift(shift_dim0, axes=[0]), freqs)
# shift in dimension 1
shift_dim1 = [[1, 0], [3, 2], [5, 4]]
assert_array_almost_equal(fft.fftshift(freqs, axes=1), shift_dim1)
assert_array_almost_equal(fft.ifftshift(shift_dim1, axes=1), freqs)
# shift in both dimensions
shift_dim_both = [[5, 4], [1, 0], [3, 2]]
assert_array_almost_equal(fft.fftshift(freqs, axes=(0, 1)), shift_dim_both)
assert_array_almost_equal(fft.ifftshift(shift_dim_both, axes=(0, 1)), freqs)
assert_array_almost_equal(fft.fftshift(freqs, axes=[0, 1]), shift_dim_both)
assert_array_almost_equal(fft.ifftshift(shift_dim_both, axes=[0, 1]), freqs)
# axes=None (default) shift in all dimensions
assert_array_almost_equal(fft.fftshift(freqs, axes=None), shift_dim_both)
assert_array_almost_equal(fft.ifftshift(shift_dim_both, axes=None), freqs)
assert_array_almost_equal(fft.fftshift(freqs), shift_dim_both)
assert_array_almost_equal(fft.ifftshift(shift_dim_both), freqs)
|
from torch.testing._internal.common_utils import (
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
)
import numpy as np
from numpy import fft, pi
from numpy.testing import assert_array_almost_equal
import torch._numpy as np
from torch._numpy import fft, pi
from torch._numpy.testing import assert_array_almost_equal
class TestFFTShift(TestCase):
from numpy import arange, asarray, concatenate, take
from torch._numpy import arange, asarray, concatenate, take
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/fft/test_helper.py
|
test_equal_to_original
|
def test_equal_to_original(self):
"""Test that the new (>=v1.15) implementation (see #10073) is equal to the original (<=v1.14)"""
if TEST_WITH_TORCHDYNAMO:
from numpy import arange, asarray, concatenate, take
else:
from torch._numpy import arange, asarray, concatenate, take
def original_fftshift(x, axes=None):
"""How fftshift was implemented in v1.14"""
tmp = asarray(x)
ndim = tmp.ndim
if axes is None:
axes = list(range(ndim))
elif isinstance(axes, int):
axes = (axes,)
y = tmp
for k in axes:
n = tmp.shape[k]
p2 = (n + 1) // 2
mylist = concatenate((arange(p2, n), arange(p2)))
y = take(y, mylist, k)
return y
def original_ifftshift(x, axes=None):
"""How ifftshift was implemented in v1.14"""
tmp = asarray(x)
ndim = tmp.ndim
if axes is None:
axes = list(range(ndim))
elif isinstance(axes, int):
axes = (axes,)
y = tmp
for k in axes:
n = tmp.shape[k]
p2 = n - (n + 1) // 2
mylist = concatenate((arange(p2, n), arange(p2)))
y = take(y, mylist, k)
return y
# create possible 2d array combinations and try all possible keywords
# compare output to original functions
for i in range(16):
for j in range(16):
for axes_keyword in [0, 1, None, (0,), (0, 1)]:
inp = np.random.rand(i, j)
assert_array_almost_equal(
fft.fftshift(inp, axes_keyword),
original_fftshift(inp, axes_keyword),
)
assert_array_almost_equal(
fft.ifftshift(inp, axes_keyword),
original_ifftshift(inp, axes_keyword),
)
|
from torch.testing._internal.common_utils import (
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
)
import numpy as np
from numpy import fft, pi
from numpy.testing import assert_array_almost_equal
import torch._numpy as np
from torch._numpy import fft, pi
from torch._numpy.testing import assert_array_almost_equal
class TestFFTShift(TestCase):
from numpy import arange, asarray, concatenate, take
from torch._numpy import arange, asarray, concatenate, take
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/fft/test_helper.py
|
original_fftshift
|
def original_fftshift(x, axes=None):
"""How fftshift was implemented in v1.14"""
tmp = asarray(x)
ndim = tmp.ndim
if axes is None:
axes = list(range(ndim))
elif isinstance(axes, int):
axes = (axes,)
y = tmp
for k in axes:
n = tmp.shape[k]
p2 = (n + 1) // 2
mylist = concatenate((arange(p2, n), arange(p2)))
y = take(y, mylist, k)
return y
|
from torch.testing._internal.common_utils import (
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
)
import numpy as np
from numpy import fft, pi
from numpy.testing import assert_array_almost_equal
import torch._numpy as np
from torch._numpy import fft, pi
from torch._numpy.testing import assert_array_almost_equal
from numpy import arange, asarray, concatenate, take
from torch._numpy import arange, asarray, concatenate, take
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/fft/test_helper.py
|
original_ifftshift
|
def original_ifftshift(x, axes=None):
"""How ifftshift was implemented in v1.14"""
tmp = asarray(x)
ndim = tmp.ndim
if axes is None:
axes = list(range(ndim))
elif isinstance(axes, int):
axes = (axes,)
y = tmp
for k in axes:
n = tmp.shape[k]
p2 = n - (n + 1) // 2
mylist = concatenate((arange(p2, n), arange(p2)))
y = take(y, mylist, k)
return y
# create possible 2d array combinations and try all possible keywords
# compare output to original functions
for i in range(16):
for j in range(16):
for axes_keyword in [0, 1, None, (0,), (0, 1)]:
inp = np.random.rand(i, j)
assert_array_almost_equal(
fft.fftshift(inp, axes_keyword),
original_fftshift(inp, axes_keyword),
)
assert_array_almost_equal(
fft.ifftshift(inp, axes_keyword),
original_ifftshift(inp, axes_keyword),
)
|
from torch.testing._internal.common_utils import (
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
)
import numpy as np
from numpy import fft, pi
from numpy.testing import assert_array_almost_equal
import torch._numpy as np
from torch._numpy import fft, pi
from torch._numpy.testing import assert_array_almost_equal
from numpy import arange, asarray, concatenate, take
from torch._numpy import arange, asarray, concatenate, take
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/fft/test_helper.py
|
test_definition
|
def test_definition(self):
x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
y = [-4, -3, -2, -1, 0, 1, 2, 3, 4]
assert_array_almost_equal(fft.fftshift(x), y)
assert_array_almost_equal(fft.ifftshift(y), x)
x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
y = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4]
assert_array_almost_equal(fft.fftshift(x), y)
assert_array_almost_equal(fft.ifftshift(y), x)
|
from torch.testing._internal.common_utils import (
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
)
import numpy as np
from numpy import fft, pi
from numpy.testing import assert_array_almost_equal
import torch._numpy as np
from torch._numpy import fft, pi
from torch._numpy.testing import assert_array_almost_equal
class TestFFTShift(TestCase):
from numpy import arange, asarray, concatenate, take
from torch._numpy import arange, asarray, concatenate, take
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/fft/test_helper.py
|
test_definition
|
def test_definition(self):
x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
y = [-4, -3, -2, -1, 0, 1, 2, 3, 4]
assert_array_almost_equal(fft.fftshift(x), y)
assert_array_almost_equal(fft.ifftshift(y), x)
x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
y = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4]
assert_array_almost_equal(fft.fftshift(x), y)
assert_array_almost_equal(fft.ifftshift(y), x)
|
from torch.testing._internal.common_utils import (
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
)
import numpy as np
from numpy import fft, pi
from numpy.testing import assert_array_almost_equal
import torch._numpy as np
from torch._numpy import fft, pi
from torch._numpy.testing import assert_array_almost_equal
class TestFFTShift(TestCase):
from numpy import arange, asarray, concatenate, take
from torch._numpy import arange, asarray, concatenate, take
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/fft/test_helper.py
|
test_not_last_axis_success
|
def test_not_last_axis_success(self):
ar, ai = np.random.random((2, 16, 8, 32))
a = ar + 1j * ai
axes = (-2,)
# Should not raise error
fft.irfftn(a, axes=axes)
|
from torch.testing._internal.common_utils import (
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
)
import numpy as np
from numpy import fft, pi
from numpy.testing import assert_array_almost_equal
import torch._numpy as np
from torch._numpy import fft, pi
from torch._numpy.testing import assert_array_almost_equal
from numpy import arange, asarray, concatenate, take
from torch._numpy import arange, asarray, concatenate, take
class TestIRFFTN(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/fft/test_pocketfft.py
|
fft1
|
def fft1(x):
L = len(x)
phase = -2j * np.pi * (np.arange(L) / L)
phase = np.arange(L).reshape(-1, 1) * phase
return np.sum(x * np.exp(phase), axis=1)
class TestFFTShift(TestCase):
def test_fft_n(self):
assert_raises((ValueError, RuntimeError), np.fft.fft, [1, 2, 3], 0)
@instantiate_parametrized_tests
class TestFFT1D(TestCase):
def setUp(self):
super().setUp()
np.random.seed(123456)
def test_identity(self):
maxlen = 512
x = random(maxlen) + 1j * random(maxlen)
xr = random(maxlen)
for i in range(1, maxlen):
assert_allclose(np.fft.ifft(np.fft.fft(x[0:i])), x[0:i], atol=1e-12)
assert_allclose(np.fft.irfft(np.fft.rfft(xr[0:i]), i), xr[0:i], atol=1e-12)
def test_fft(self):
np.random.seed(1234)
x = random(30) + 1j * random(30)
assert_allclose(fft1(x), np.fft.fft(x), atol=3e-5)
assert_allclose(fft1(x), np.fft.fft(x, norm="backward"), atol=3e-5)
assert_allclose(fft1(x) / np.sqrt(30), np.fft.fft(x, norm="ortho"), atol=5e-6)
assert_allclose(fft1(x) / 30.0, np.fft.fft(x, norm="forward"), atol=5e-6)
@parametrize("norm", (None, "backward", "ortho", "forward"))
def test_ifft(self, norm):
x = random(30) + 1j * random(30)
assert_allclose(x, np.fft.ifft(np.fft.fft(x, norm=norm), norm=norm), atol=1e-6)
# Ensure we get the correct error message
# NB: Exact wording differs slightly under Dynamo and in eager.
with pytest.raises((ValueError, RuntimeError), match="Invalid number of"):
np.fft.ifft([], norm=norm)
def test_fft2(self):
x = random((30, 20)) + 1j * random((30, 20))
assert_allclose(
np.fft.fft(np.fft.fft(x, axis=1), axis=0), np.fft.fft2(x), atol=1e-6
)
assert_allclose(np.fft.fft2(x), np.fft.fft2(x, norm="backward"), atol=1e-6)
assert_allclose(
np.fft.fft2(x) / np.sqrt(30 * 20), np.fft.fft2(x, norm="ortho"), atol=1e-6
)
assert_allclose(
np.fft.fft2(x) / (30.0 * 20.0), np.fft.fft2(x, norm="forward"), atol=1e-6
)
def test_ifft2(self):
x = random((30, 20)) + 1j * random((30, 20))
assert_allclose(
np.fft.ifft(np.fft.ifft(x, axis=1), axis=0), np.fft.ifft2(x), atol=1e-6
)
assert_allclose(np.fft.ifft2(x), np.fft.ifft2(x, norm="backward"), atol=1e-6)
assert_allclose(
np.fft.ifft2(x) * np.sqrt(30 * 20), np.fft.ifft2(x, norm="ortho"), atol=1e-6
)
assert_allclose(
np.fft.ifft2(x) * (30.0 * 20.0), np.fft.ifft2(x, norm="forward"), atol=1e-6
)
def test_fftn(self):
x = random((30, 20, 10)) + 1j * random((30, 20, 10))
assert_allclose(
np.fft.fft(np.fft.fft(np.fft.fft(x, axis=2), axis=1), axis=0),
np.fft.fftn(x),
atol=1e-6,
)
assert_allclose(np.fft.fftn(x), np.fft.fftn(x, norm="backward"), atol=1e-6)
assert_allclose(
np.fft.fftn(x) / np.sqrt(30 * 20 * 10),
np.fft.fftn(x, norm="ortho"),
atol=1e-6,
)
assert_allclose(
np.fft.fftn(x) / (30.0 * 20.0 * 10.0),
np.fft.fftn(x, norm="forward"),
atol=1e-6,
)
def test_ifftn(self):
x = random((30, 20, 10)) + 1j * random((30, 20, 10))
assert_allclose(
np.fft.ifft(np.fft.ifft(np.fft.ifft(x, axis=2), axis=1), axis=0),
np.fft.ifftn(x),
atol=1e-6,
)
assert_allclose(np.fft.ifftn(x), np.fft.ifftn(x, norm="backward"), atol=1e-6)
assert_allclose(
np.fft.ifftn(x) * np.sqrt(30 * 20 * 10),
np.fft.ifftn(x, norm="ortho"),
atol=1e-6,
)
assert_allclose(
np.fft.ifftn(x) * (30.0 * 20.0 * 10.0),
np.fft.ifftn(x, norm="forward"),
atol=1e-6,
)
def test_rfft(self):
x = random(30)
for n in [x.size, 2 * x.size]:
for norm in [None, "backward", "ortho", "forward"]:
assert_allclose(
np.fft.fft(x, n=n, norm=norm)[: (n // 2 + 1)],
np.fft.rfft(x, n=n, norm=norm),
atol=1e-6,
)
assert_allclose(
np.fft.rfft(x, n=n), np.fft.rfft(x, n=n, norm="backward"), atol=1e-6
)
assert_allclose(
np.fft.rfft(x, n=n) / np.sqrt(n),
np.fft.rfft(x, n=n, norm="ortho"),
atol=1e-6,
)
assert_allclose(
np.fft.rfft(x, n=n) / n, np.fft.rfft(x, n=n, norm="forward"), atol=1e-6
)
def test_irfft(self):
x = random(30)
assert_allclose(x, np.fft.irfft(np.fft.rfft(x)), atol=1e-6)
assert_allclose(
x, np.fft.irfft(np.fft.rfft(x, norm="backward"), norm="backward"), atol=1e-6
)
assert_allclose(
x, np.fft.irfft(np.fft.rfft(x, norm="ortho"), norm="ortho"), atol=1e-6
)
assert_allclose(
x, np.fft.irfft(np.fft.rfft(x, norm="forward"), norm="forward"), atol=1e-6
)
def test_rfft2(self):
x = random((30, 20))
assert_allclose(np.fft.fft2(x)[:, :11], np.fft.rfft2(x), atol=1e-6)
assert_allclose(np.fft.rfft2(x), np.fft.rfft2(x, norm="backward"), atol=1e-6)
assert_allclose(
np.fft.rfft2(x) / np.sqrt(30 * 20), np.fft.rfft2(x, norm="ortho"), atol=1e-6
)
assert_allclose(
np.fft.rfft2(x) / (30.0 * 20.0), np.fft.rfft2(x, norm="forward"), atol=1e-6
)
def test_irfft2(self):
x = random((30, 20))
assert_allclose(x, np.fft.irfft2(np.fft.rfft2(x)), atol=1e-6)
assert_allclose(
x,
np.fft.irfft2(np.fft.rfft2(x, norm="backward"), norm="backward"),
atol=1e-6,
)
assert_allclose(
x, np.fft.irfft2(np.fft.rfft2(x, norm="ortho"), norm="ortho"), atol=1e-6
)
assert_allclose(
x, np.fft.irfft2(np.fft.rfft2(x, norm="forward"), norm="forward"), atol=1e-6
)
def test_rfftn(self):
x = random((30, 20, 10))
assert_allclose(np.fft.fftn(x)[:, :, :6], np.fft.rfftn(x), atol=1e-6)
assert_allclose(np.fft.rfftn(x), np.fft.rfftn(x, norm="backward"), atol=1e-6)
assert_allclose(
np.fft.rfftn(x) / np.sqrt(30 * 20 * 10),
np.fft.rfftn(x, norm="ortho"),
atol=1e-6,
)
assert_allclose(
np.fft.rfftn(x) / (30.0 * 20.0 * 10.0),
np.fft.rfftn(x, norm="forward"),
atol=1e-6,
)
def test_irfftn(self):
x = random((30, 20, 10))
assert_allclose(x, np.fft.irfftn(np.fft.rfftn(x)), atol=1e-6)
assert_allclose(
x,
np.fft.irfftn(np.fft.rfftn(x, norm="backward"), norm="backward"),
atol=1e-6,
)
assert_allclose(
x, np.fft.irfftn(np.fft.rfftn(x, norm="ortho"), norm="ortho"), atol=1e-6
)
assert_allclose(
x, np.fft.irfftn(np.fft.rfftn(x, norm="forward"), norm="forward"), atol=1e-6
)
def test_hfft(self):
x = random(14) + 1j * random(14)
x_herm = np.concatenate((random(1), x, random(1)))
x = np.concatenate((x_herm, np.flip(x).conj()))
assert_allclose(np.fft.fft(x), np.fft.hfft(x_herm), atol=1e-6)
assert_allclose(
np.fft.hfft(x_herm), np.fft.hfft(x_herm, norm="backward"), atol=1e-6
)
assert_allclose(
np.fft.hfft(x_herm) / np.sqrt(30),
np.fft.hfft(x_herm, norm="ortho"),
atol=1e-6,
)
assert_allclose(
np.fft.hfft(x_herm) / 30.0, np.fft.hfft(x_herm, norm="forward"), atol=1e-6
)
def test_ihfft(self):
x = random(14) + 1j * random(14)
x_herm = np.concatenate((random(1), x, random(1)))
x = np.concatenate((x_herm, np.flip(x).conj()))
assert_allclose(x_herm, np.fft.ihfft(np.fft.hfft(x_herm)), atol=1e-6)
assert_allclose(
x_herm,
np.fft.ihfft(np.fft.hfft(x_herm, norm="backward"), norm="backward"),
atol=1e-6,
)
assert_allclose(
x_herm,
np.fft.ihfft(np.fft.hfft(x_herm, norm="ortho"), norm="ortho"),
atol=1e-6,
)
assert_allclose(
x_herm,
np.fft.ihfft(np.fft.hfft(x_herm, norm="forward"), norm="forward"),
atol=1e-6,
)
@parametrize("op", [np.fft.fftn, np.fft.ifftn, np.fft.rfftn, np.fft.irfftn])
def test_axes(self, op):
x = random((30, 20, 10))
axes = [(0, 1, 2), (0, 2, 1), (1, 0, 2), (1, 2, 0), (2, 0, 1), (2, 1, 0)]
for a in axes:
op_tr = op(np.transpose(x, a))
tr_op = np.transpose(op(x, axes=a), a)
assert_allclose(op_tr, tr_op, atol=1e-6)
def test_all_1d_norm_preserving(self):
# verify that round-trip transforms are norm-preserving
x = random(30)
x_norm = np.linalg.norm(x)
n = x.size * 2
func_pairs = [
(np.fft.fft, np.fft.ifft),
(np.fft.rfft, np.fft.irfft),
# hfft: order so the first function takes x.size samples
# (necessary for comparison to x_norm above)
(np.fft.ihfft, np.fft.hfft),
]
for forw, back in func_pairs:
for n in [x.size, 2 * x.size]:
for norm in [None, "backward", "ortho", "forward"]:
tmp = forw(x, n=n, norm=norm)
tmp = back(tmp, n=n, norm=norm)
assert_allclose(x_norm, np.linalg.norm(tmp), atol=1e-6)
@parametrize("dtype", [np.half, np.single, np.double])
def test_dtypes(self, dtype):
# make sure that all input precisions are accepted and internally
# converted to 64bit
x = random(30).astype(dtype)
assert_allclose(np.fft.ifft(np.fft.fft(x)), x, atol=1e-6)
assert_allclose(np.fft.irfft(np.fft.rfft(x)), x, atol=1e-6)
@parametrize("dtype", [np.float32, np.float64, np.complex64, np.complex128])
@parametrize("order", ["F", "non-contiguous"])
@parametrize(
"fft",
[np.fft.fft, np.fft.fft2, np.fft.fftn, np.fft.ifft, np.fft.ifft2, np.fft.ifftn],
)
def test_fft_with_order(self, dtype, order, fft):
# Check that FFT/IFFT produces identical results for C, Fortran and
# non contiguous arrays
# rng = np.random.RandomState(42)
rng = np.random
X = rng.rand(8, 7, 13).astype(dtype) # , copy=False)
# See discussion in pull/14178
_tol = float(8.0 * np.sqrt(np.log2(X.size)) * np.finfo(X.dtype).eps)
if order == "F":
raise SkipTest("Fortran order arrays")
Y = np.asfortranarray(X)
else:
# Make a non contiguous array
Z = np.empty((16, 7, 13), dtype=X.dtype)
Z[::2] = X
Y = Z[::2]
X = Y.copy()
if fft.__name__.endswith("fft"):
for axis in range(3):
X_res = fft(X, axis=axis)
Y_res = fft(Y, axis=axis)
assert_allclose(X_res, Y_res, atol=_tol, rtol=_tol)
elif fft.__name__.endswith(("fft2", "fftn")):
axes = [(0, 1), (1, 2), (0, 2)]
if fft.__name__.endswith("fftn"):
axes.extend([(0,), (1,), (2,), None])
for ax in axes:
X_res = fft(X, axes=ax)
Y_res = fft(Y, axes=ax)
assert_allclose(X_res, Y_res, atol=_tol, rtol=_tol)
else:
raise ValueError
@skipif(IS_WASM, reason="Cannot start thread")
class TestFFTThreadSafe(TestCase):
threads = 16
input_shape = (800, 200)
def _test_mtsame(self, func, *args):
def worker(args, q):
q.put(func(*args))
q = queue.Queue()
expected = func(*args)
# Spin off a bunch of threads to call the same function simultaneously
t = [
threading.Thread(target=worker, args=(args, q)) for i in range(self.threads)
]
[x.start() for x in t]
[x.join() for x in t]
# Make sure all threads returned the correct value
for i in range(self.threads):
# under torch.dynamo `assert_array_equal` fails with relative errors of
# about 1.5e-14. Hence replace it with `assert_allclose(..., rtol=2e-14)`
assert_allclose(
q.get(timeout=5),
expected,
atol=2e-14
# msg="Function returned wrong value in multithreaded context",
)
def test_fft(self):
a = np.ones(self.input_shape) * 1 + 0j
self._test_mtsame(np.fft.fft, a)
def test_ifft(self):
a = np.ones(self.input_shape) * 1 + 0j
self._test_mtsame(np.fft.ifft, a)
def test_rfft(self):
a = np.ones(self.input_shape)
self._test_mtsame(np.fft.rfft, a)
def test_irfft(self):
a = np.ones(self.input_shape) * 1 + 0j
self._test_mtsame(np.fft.irfft, a)
if __name__ == "__main__":
run_tests()
|
import functools
import queue
import threading
from unittest import skipIf as skipif, SkipTest
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
)
import numpy as np
from numpy.random import random
from numpy.testing import assert_allclose # , IS_WASM
import torch._numpy as np
from torch._numpy.random import random
from torch._numpy.testing import assert_allclose # , IS_WASM
skip = functools.partial(skipif, True)
IS_WASM = False
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/fft/test_pocketfft.py
|
test_fft_n
|
def test_fft_n(self):
assert_raises((ValueError, RuntimeError), np.fft.fft, [1, 2, 3], 0)
|
import functools
import queue
import threading
from unittest import skipIf as skipif, SkipTest
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
)
import numpy as np
from numpy.random import random
from numpy.testing import assert_allclose # , IS_WASM
import torch._numpy as np
from torch._numpy.random import random
from torch._numpy.testing import assert_allclose # , IS_WASM
skip = functools.partial(skipif, True)
IS_WASM = False
class TestFFTShift(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/fft/test_pocketfft.py
|
setUp
|
def setUp(self):
super().setUp()
np.random.seed(123456)
|
import functools
import queue
import threading
from unittest import skipIf as skipif, SkipTest
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
)
import numpy as np
from numpy.random import random
from numpy.testing import assert_allclose # , IS_WASM
import torch._numpy as np
from torch._numpy.random import random
from torch._numpy.testing import assert_allclose # , IS_WASM
skip = functools.partial(skipif, True)
IS_WASM = False
@instantiate_parametrized_tests
class TestFFT1D(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/fft/test_pocketfft.py
|
test_identity
|
def test_identity(self):
maxlen = 512
x = random(maxlen) + 1j * random(maxlen)
xr = random(maxlen)
for i in range(1, maxlen):
assert_allclose(np.fft.ifft(np.fft.fft(x[0:i])), x[0:i], atol=1e-12)
assert_allclose(np.fft.irfft(np.fft.rfft(xr[0:i]), i), xr[0:i], atol=1e-12)
|
import functools
import queue
import threading
from unittest import skipIf as skipif, SkipTest
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
)
import numpy as np
from numpy.random import random
from numpy.testing import assert_allclose # , IS_WASM
import torch._numpy as np
from torch._numpy.random import random
from torch._numpy.testing import assert_allclose # , IS_WASM
skip = functools.partial(skipif, True)
IS_WASM = False
@instantiate_parametrized_tests
class TestFFT1D(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/fft/test_pocketfft.py
|
test_ifft
|
def test_ifft(self, norm):
x = random(30) + 1j * random(30)
assert_allclose(x, np.fft.ifft(np.fft.fft(x, norm=norm), norm=norm), atol=1e-6)
# Ensure we get the correct error message
# NB: Exact wording differs slightly under Dynamo and in eager.
with pytest.raises((ValueError, RuntimeError), match="Invalid number of"):
np.fft.ifft([], norm=norm)
|
import functools
import queue
import threading
from unittest import skipIf as skipif, SkipTest
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
)
import numpy as np
from numpy.random import random
from numpy.testing import assert_allclose # , IS_WASM
import torch._numpy as np
from torch._numpy.random import random
from torch._numpy.testing import assert_allclose # , IS_WASM
skip = functools.partial(skipif, True)
IS_WASM = False
@instantiate_parametrized_tests
class TestFFT1D(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/fft/test_pocketfft.py
|
test_fft2
|
def test_fft2(self):
x = random((30, 20)) + 1j * random((30, 20))
assert_allclose(
np.fft.fft(np.fft.fft(x, axis=1), axis=0), np.fft.fft2(x), atol=1e-6
)
assert_allclose(np.fft.fft2(x), np.fft.fft2(x, norm="backward"), atol=1e-6)
assert_allclose(
np.fft.fft2(x) / np.sqrt(30 * 20), np.fft.fft2(x, norm="ortho"), atol=1e-6
)
assert_allclose(
np.fft.fft2(x) / (30.0 * 20.0), np.fft.fft2(x, norm="forward"), atol=1e-6
)
|
import functools
import queue
import threading
from unittest import skipIf as skipif, SkipTest
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
)
import numpy as np
from numpy.random import random
from numpy.testing import assert_allclose # , IS_WASM
import torch._numpy as np
from torch._numpy.random import random
from torch._numpy.testing import assert_allclose # , IS_WASM
skip = functools.partial(skipif, True)
IS_WASM = False
@instantiate_parametrized_tests
class TestFFT1D(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/fft/test_pocketfft.py
|
test_ifft2
|
def test_ifft2(self):
x = random((30, 20)) + 1j * random((30, 20))
assert_allclose(
np.fft.ifft(np.fft.ifft(x, axis=1), axis=0), np.fft.ifft2(x), atol=1e-6
)
assert_allclose(np.fft.ifft2(x), np.fft.ifft2(x, norm="backward"), atol=1e-6)
assert_allclose(
np.fft.ifft2(x) * np.sqrt(30 * 20), np.fft.ifft2(x, norm="ortho"), atol=1e-6
)
assert_allclose(
np.fft.ifft2(x) * (30.0 * 20.0), np.fft.ifft2(x, norm="forward"), atol=1e-6
)
|
import functools
import queue
import threading
from unittest import skipIf as skipif, SkipTest
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
)
import numpy as np
from numpy.random import random
from numpy.testing import assert_allclose # , IS_WASM
import torch._numpy as np
from torch._numpy.random import random
from torch._numpy.testing import assert_allclose # , IS_WASM
skip = functools.partial(skipif, True)
IS_WASM = False
@instantiate_parametrized_tests
class TestFFT1D(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/fft/test_pocketfft.py
|
test_fftn
|
def test_fftn(self):
x = random((30, 20, 10)) + 1j * random((30, 20, 10))
assert_allclose(
np.fft.fft(np.fft.fft(np.fft.fft(x, axis=2), axis=1), axis=0),
np.fft.fftn(x),
atol=1e-6,
)
assert_allclose(np.fft.fftn(x), np.fft.fftn(x, norm="backward"), atol=1e-6)
assert_allclose(
np.fft.fftn(x) / np.sqrt(30 * 20 * 10),
np.fft.fftn(x, norm="ortho"),
atol=1e-6,
)
assert_allclose(
np.fft.fftn(x) / (30.0 * 20.0 * 10.0),
np.fft.fftn(x, norm="forward"),
atol=1e-6,
)
|
import functools
import queue
import threading
from unittest import skipIf as skipif, SkipTest
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
)
import numpy as np
from numpy.random import random
from numpy.testing import assert_allclose # , IS_WASM
import torch._numpy as np
from torch._numpy.random import random
from torch._numpy.testing import assert_allclose # , IS_WASM
skip = functools.partial(skipif, True)
IS_WASM = False
@instantiate_parametrized_tests
class TestFFT1D(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/fft/test_pocketfft.py
|
test_ifftn
|
def test_ifftn(self):
x = random((30, 20, 10)) + 1j * random((30, 20, 10))
assert_allclose(
np.fft.ifft(np.fft.ifft(np.fft.ifft(x, axis=2), axis=1), axis=0),
np.fft.ifftn(x),
atol=1e-6,
)
assert_allclose(np.fft.ifftn(x), np.fft.ifftn(x, norm="backward"), atol=1e-6)
assert_allclose(
np.fft.ifftn(x) * np.sqrt(30 * 20 * 10),
np.fft.ifftn(x, norm="ortho"),
atol=1e-6,
)
assert_allclose(
np.fft.ifftn(x) * (30.0 * 20.0 * 10.0),
np.fft.ifftn(x, norm="forward"),
atol=1e-6,
)
|
import functools
import queue
import threading
from unittest import skipIf as skipif, SkipTest
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
)
import numpy as np
from numpy.random import random
from numpy.testing import assert_allclose # , IS_WASM
import torch._numpy as np
from torch._numpy.random import random
from torch._numpy.testing import assert_allclose # , IS_WASM
skip = functools.partial(skipif, True)
IS_WASM = False
@instantiate_parametrized_tests
class TestFFT1D(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/fft/test_pocketfft.py
|
test_rfft
|
def test_rfft(self):
x = random(30)
for n in [x.size, 2 * x.size]:
for norm in [None, "backward", "ortho", "forward"]:
assert_allclose(
np.fft.fft(x, n=n, norm=norm)[: (n // 2 + 1)],
np.fft.rfft(x, n=n, norm=norm),
atol=1e-6,
)
assert_allclose(
np.fft.rfft(x, n=n), np.fft.rfft(x, n=n, norm="backward"), atol=1e-6
)
assert_allclose(
np.fft.rfft(x, n=n) / np.sqrt(n),
np.fft.rfft(x, n=n, norm="ortho"),
atol=1e-6,
)
assert_allclose(
np.fft.rfft(x, n=n) / n, np.fft.rfft(x, n=n, norm="forward"), atol=1e-6
)
|
import functools
import queue
import threading
from unittest import skipIf as skipif, SkipTest
import pytest
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
)
import numpy as np
from numpy.random import random
from numpy.testing import assert_allclose # , IS_WASM
import torch._numpy as np
from torch._numpy.random import random
from torch._numpy.testing import assert_allclose # , IS_WASM
skip = functools.partial(skipif, True)
IS_WASM = False
@instantiate_parametrized_tests
class TestFFT1D(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/lib/test_arraypad.py
|
test_check_constant_float3
|
def test_check_constant_float3(self):
a = np.arange(100, dtype=float)
a = np.pad(a, (25, 20), "constant", constant_values=(-1.1, -1.2))
b = np.array(
[
-1.1,
-1.1,
-1.1,
-1.1,
-1.1,
-1.1,
-1.1,
-1.1,
-1.1,
-1.1,
-1.1,
-1.1,
-1.1,
-1.1,
-1.1,
-1.1,
-1.1,
-1.1,
-1.1,
-1.1,
-1.1,
-1.1,
-1.1,
-1.1,
-1.1,
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53,
54,
55,
56,
57,
58,
59,
60,
61,
62,
63,
64,
65,
66,
67,
68,
69,
70,
71,
72,
73,
74,
75,
76,
77,
78,
79,
80,
81,
82,
83,
84,
85,
86,
87,
88,
89,
90,
91,
92,
93,
94,
95,
96,
97,
98,
99,
-1.2,
-1.2,
-1.2,
-1.2,
-1.2,
-1.2,
-1.2,
-1.2,
-1.2,
-1.2,
-1.2,
-1.2,
-1.2,
-1.2,
-1.2,
-1.2,
-1.2,
-1.2,
-1.2,
-1.2,
]
)
assert_allclose(a, b)
|
from unittest import skipIf as skipif
from torch.testing._internal.common_utils import (
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy.testing import assert_allclose, assert_array_equal
import torch._numpy as np
from torch._numpy.testing import assert_allclose, assert_array_equal
class TestConstant(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/lib/test_arraypad.py
|
test_check_large_integers
|
def test_check_large_integers(self):
int64_max = 2**63 - 1
arr = np.full(5, int64_max, dtype=np.int64)
test = np.pad(arr, 1, mode="constant", constant_values=arr.min())
expected = np.full(7, int64_max, dtype=np.int64)
assert_array_equal(test, expected)
|
from unittest import skipIf as skipif
from torch.testing._internal.common_utils import (
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy.testing import assert_allclose, assert_array_equal
import torch._numpy as np
from torch._numpy.testing import assert_allclose, assert_array_equal
class TestConstant(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/lib/test_arraypad.py
|
test_pad_empty_dimension
|
def test_pad_empty_dimension(self):
arr = np.zeros((3, 0, 2))
result = np.pad(arr, [(0,), (2,), (1,)], mode="constant")
assert result.shape == (3, 4, 4)
|
from unittest import skipIf as skipif
from torch.testing._internal.common_utils import (
run_tests,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy.testing import assert_allclose, assert_array_equal
import torch._numpy as np
from torch._numpy.testing import assert_allclose, assert_array_equal
class TestConstant(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/lib/test_arraysetops.py
|
test_intersect1d
|
def test_intersect1d(self):
# unique inputs
a = np.array([5, 7, 1, 2])
b = np.array([2, 4, 3, 1, 5])
ec = np.array([1, 2, 5])
c = intersect1d(a, b, assume_unique=True)
assert_array_equal(c, ec)
# non-unique inputs
a = np.array([5, 5, 7, 1, 2])
b = np.array([2, 1, 4, 3, 3, 1, 5])
ed = np.array([1, 2, 5])
c = intersect1d(a, b)
assert_array_equal(c, ed)
assert_array_equal([], intersect1d([], []))
|
from unittest import expectedFailure as xfail, skipIf
import numpy
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
subtest,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import ediff1d, in1d, intersect1d, setdiff1d, setxor1d, union1d, unique
from numpy.testing import assert_array_equal, assert_equal, assert_raises_regex
import torch._numpy as np
from torch._numpy import unique
from torch._numpy.testing import assert_array_equal, assert_equal
@skipIf(numpy.__version__ < "1.24", reason="NP_VER: fails on NumPy 1.23.x")
@skipIf(True, reason="TODO implement these ops")
@instantiate_parametrized_tests
class TestSetOps(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/lib/test_arraysetops.py
|
test_intersect1d_array_like
|
def test_intersect1d_array_like(self):
# See gh-11772
class Test:
def __array__(self):
return np.arange(3)
a = Test()
res = intersect1d(a, a)
assert_array_equal(res, a)
res = intersect1d([1, 2, 3], [1, 2, 3])
assert_array_equal(res, [1, 2, 3])
|
from unittest import expectedFailure as xfail, skipIf
import numpy
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
subtest,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import ediff1d, in1d, intersect1d, setdiff1d, setxor1d, union1d, unique
from numpy.testing import assert_array_equal, assert_equal, assert_raises_regex
import torch._numpy as np
from torch._numpy import unique
from torch._numpy.testing import assert_array_equal, assert_equal
@skipIf(numpy.__version__ < "1.24", reason="NP_VER: fails on NumPy 1.23.x")
@skipIf(True, reason="TODO implement these ops")
@instantiate_parametrized_tests
class TestSetOps(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/lib/test_arraysetops.py
|
__array__
|
def __array__(self):
return np.arange(3)
|
from unittest import expectedFailure as xfail, skipIf
import numpy
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
subtest,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import ediff1d, in1d, intersect1d, setdiff1d, setxor1d, union1d, unique
from numpy.testing import assert_array_equal, assert_equal, assert_raises_regex
import torch._numpy as np
from torch._numpy import unique
from torch._numpy.testing import assert_array_equal, assert_equal
class Test:
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/lib/test_arraysetops.py
|
test_intersect1d_indices
|
def test_intersect1d_indices(self):
# unique inputs
a = np.array([1, 2, 3, 4])
b = np.array([2, 1, 4, 6])
c, i1, i2 = intersect1d(a, b, assume_unique=True, return_indices=True)
ee = np.array([1, 2, 4])
assert_array_equal(c, ee)
assert_array_equal(a[i1], ee)
assert_array_equal(b[i2], ee)
# non-unique inputs
a = np.array([1, 2, 2, 3, 4, 3, 2])
b = np.array([1, 8, 4, 2, 2, 3, 2, 3])
c, i1, i2 = intersect1d(a, b, return_indices=True)
ef = np.array([1, 2, 3, 4])
assert_array_equal(c, ef)
assert_array_equal(a[i1], ef)
assert_array_equal(b[i2], ef)
# non1d, unique inputs
a = np.array([[2, 4, 5, 6], [7, 8, 1, 15]])
b = np.array([[3, 2, 7, 6], [10, 12, 8, 9]])
c, i1, i2 = intersect1d(a, b, assume_unique=True, return_indices=True)
ui1 = np.unravel_index(i1, a.shape)
ui2 = np.unravel_index(i2, b.shape)
ea = np.array([2, 6, 7, 8])
assert_array_equal(ea, a[ui1])
assert_array_equal(ea, b[ui2])
# non1d, not assumed to be uniqueinputs
a = np.array([[2, 4, 5, 6, 6], [4, 7, 8, 7, 2]])
b = np.array([[3, 2, 7, 7], [10, 12, 8, 7]])
c, i1, i2 = intersect1d(a, b, return_indices=True)
ui1 = np.unravel_index(i1, a.shape)
ui2 = np.unravel_index(i2, b.shape)
ea = np.array([2, 7, 8])
assert_array_equal(ea, a[ui1])
assert_array_equal(ea, b[ui2])
|
from unittest import expectedFailure as xfail, skipIf
import numpy
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
subtest,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import ediff1d, in1d, intersect1d, setdiff1d, setxor1d, union1d, unique
from numpy.testing import assert_array_equal, assert_equal, assert_raises_regex
import torch._numpy as np
from torch._numpy import unique
from torch._numpy.testing import assert_array_equal, assert_equal
@skipIf(numpy.__version__ < "1.24", reason="NP_VER: fails on NumPy 1.23.x")
@skipIf(True, reason="TODO implement these ops")
@instantiate_parametrized_tests
class TestSetOps(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/lib/test_arraysetops.py
|
test_setxor1d
|
def test_setxor1d(self):
a = np.array([5, 7, 1, 2])
b = np.array([2, 4, 3, 1, 5])
ec = np.array([3, 4, 7])
c = setxor1d(a, b)
assert_array_equal(c, ec)
a = np.array([1, 2, 3])
b = np.array([6, 5, 4])
ec = np.array([1, 2, 3, 4, 5, 6])
c = setxor1d(a, b)
assert_array_equal(c, ec)
a = np.array([1, 8, 2, 3])
b = np.array([6, 5, 4, 8])
ec = np.array([1, 2, 3, 4, 5, 6])
c = setxor1d(a, b)
assert_array_equal(c, ec)
assert_array_equal([], setxor1d([], []))
|
from unittest import expectedFailure as xfail, skipIf
import numpy
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
subtest,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import ediff1d, in1d, intersect1d, setdiff1d, setxor1d, union1d, unique
from numpy.testing import assert_array_equal, assert_equal, assert_raises_regex
import torch._numpy as np
from torch._numpy import unique
from torch._numpy.testing import assert_array_equal, assert_equal
@skipIf(numpy.__version__ < "1.24", reason="NP_VER: fails on NumPy 1.23.x")
@skipIf(True, reason="TODO implement these ops")
@instantiate_parametrized_tests
class TestSetOps(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/lib/test_arraysetops.py
|
test_in1d_with_arrays_containing_tuples
|
def test_in1d_with_arrays_containing_tuples(self):
ar1 = np.array([(1,), 2], dtype=object)
ar2 = np.array([(1,), 2], dtype=object)
expected = np.array([True, True])
result = np.in1d(ar1, ar2)
assert_array_equal(result, expected)
result = np.in1d(ar1, ar2, invert=True)
assert_array_equal(result, np.invert(expected))
# An integer is added at the end of the array to make sure
# that the array builder will create the array with tuples
# and after it's created the integer is removed.
# There's a bug in the array constructor that doesn't handle
# tuples properly and adding the integer fixes that.
ar1 = np.array([(1,), (2, 1), 1], dtype=object)
ar1 = ar1[:-1]
ar2 = np.array([(1,), (2, 1), 1], dtype=object)
ar2 = ar2[:-1]
expected = np.array([True, True])
result = np.in1d(ar1, ar2)
assert_array_equal(result, expected)
result = np.in1d(ar1, ar2, invert=True)
assert_array_equal(result, np.invert(expected))
ar1 = np.array([(1,), (2, 3), 1], dtype=object)
ar1 = ar1[:-1]
ar2 = np.array([(1,), 2], dtype=object)
expected = np.array([True, False])
result = np.in1d(ar1, ar2)
assert_array_equal(result, expected)
result = np.in1d(ar1, ar2, invert=True)
assert_array_equal(result, np.invert(expected))
|
from unittest import expectedFailure as xfail, skipIf
import numpy
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
subtest,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import ediff1d, in1d, intersect1d, setdiff1d, setxor1d, union1d, unique
from numpy.testing import assert_array_equal, assert_equal, assert_raises_regex
import torch._numpy as np
from torch._numpy import unique
from torch._numpy.testing import assert_array_equal, assert_equal
@skipIf(numpy.__version__ < "1.24", reason="NP_VER: fails on NumPy 1.23.x")
@skipIf(True, reason="TODO implement these ops")
@instantiate_parametrized_tests
class TestSetOps(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/lib/test_arraysetops.py
|
test_in1d_errors
|
def test_in1d_errors(self):
"""Test that in1d raises expected errors."""
# Error 1: `kind` is not one of 'sort' 'table' or None.
ar1 = np.array([1, 2, 3, 4, 5])
ar2 = np.array([2, 4, 6, 8, 10])
assert_raises(ValueError, in1d, ar1, ar2, kind="quicksort")
# Error 2: `kind="table"` does not work for non-integral arrays.
obj_ar1 = np.array([1, "a", 3, "b", 5], dtype=object)
obj_ar2 = np.array([1, "a", 3, "b", 5], dtype=object)
assert_raises(ValueError, in1d, obj_ar1, obj_ar2, kind="table")
for dtype in [np.int32, np.int64]:
ar1 = np.array([-1, 2, 3, 4, 5], dtype=dtype)
# The range of this array will overflow:
overflow_ar2 = np.array([-1, np.iinfo(dtype).max], dtype=dtype)
# Error 3: `kind="table"` will trigger a runtime error
# if there is an integer overflow expected when computing the
# range of ar2
assert_raises(RuntimeError, in1d, ar1, overflow_ar2, kind="table")
# Non-error: `kind=None` will *not* trigger a runtime error
# if there is an integer overflow, it will switch to
# the `sort` algorithm.
result = np.in1d(ar1, overflow_ar2, kind=None)
assert_array_equal(result, [True] + [False] * 4)
result = np.in1d(ar1, overflow_ar2, kind="sort")
assert_array_equal(result, [True] + [False] * 4)
|
from unittest import expectedFailure as xfail, skipIf
import numpy
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
subtest,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import ediff1d, in1d, intersect1d, setdiff1d, setxor1d, union1d, unique
from numpy.testing import assert_array_equal, assert_equal, assert_raises_regex
import torch._numpy as np
from torch._numpy import unique
from torch._numpy.testing import assert_array_equal, assert_equal
@skipIf(numpy.__version__ < "1.24", reason="NP_VER: fails on NumPy 1.23.x")
@skipIf(True, reason="TODO implement these ops")
@instantiate_parametrized_tests
class TestSetOps(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/lib/test_arraysetops.py
|
test_union1d
|
def test_union1d(self):
a = np.array([5, 4, 7, 1, 2])
b = np.array([2, 4, 3, 3, 2, 1, 5])
ec = np.array([1, 2, 3, 4, 5, 7])
c = union1d(a, b)
assert_array_equal(c, ec)
# Tests gh-10340, arguments to union1d should be
# flattened if they are not already 1D
x = np.array([[0, 1, 2], [3, 4, 5]])
y = np.array([0, 1, 2, 3, 4])
ez = np.array([0, 1, 2, 3, 4, 5])
z = union1d(x, y)
assert_array_equal(z, ez)
assert_array_equal([], union1d([], []))
|
from unittest import expectedFailure as xfail, skipIf
import numpy
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
subtest,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import ediff1d, in1d, intersect1d, setdiff1d, setxor1d, union1d, unique
from numpy.testing import assert_array_equal, assert_equal, assert_raises_regex
import torch._numpy as np
from torch._numpy import unique
from torch._numpy.testing import assert_array_equal, assert_equal
@skipIf(numpy.__version__ < "1.24", reason="NP_VER: fails on NumPy 1.23.x")
@skipIf(True, reason="TODO implement these ops")
@instantiate_parametrized_tests
class TestSetOps(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/lib/test_arraysetops.py
|
test_setdiff1d
|
def test_setdiff1d(self):
a = np.array([6, 5, 4, 7, 1, 2, 7, 4])
b = np.array([2, 4, 3, 3, 2, 1, 5])
ec = np.array([6, 7])
c = setdiff1d(a, b)
assert_array_equal(c, ec)
a = np.arange(21)
b = np.arange(19)
ec = np.array([19, 20])
c = setdiff1d(a, b)
assert_array_equal(c, ec)
assert_array_equal([], setdiff1d([], []))
a = np.array((), np.uint32)
assert_equal(setdiff1d(a, []).dtype, np.uint32)
|
from unittest import expectedFailure as xfail, skipIf
import numpy
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
subtest,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import ediff1d, in1d, intersect1d, setdiff1d, setxor1d, union1d, unique
from numpy.testing import assert_array_equal, assert_equal, assert_raises_regex
import torch._numpy as np
from torch._numpy import unique
from torch._numpy.testing import assert_array_equal, assert_equal
@skipIf(numpy.__version__ < "1.24", reason="NP_VER: fails on NumPy 1.23.x")
@skipIf(True, reason="TODO implement these ops")
@instantiate_parametrized_tests
class TestSetOps(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/lib/test_arraysetops.py
|
test_setdiff1d_unique
|
def test_setdiff1d_unique(self):
a = np.array([3, 2, 1])
b = np.array([7, 5, 2])
expected = np.array([3, 1])
actual = setdiff1d(a, b, assume_unique=True)
assert_equal(actual, expected)
|
from unittest import expectedFailure as xfail, skipIf
import numpy
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
subtest,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import ediff1d, in1d, intersect1d, setdiff1d, setxor1d, union1d, unique
from numpy.testing import assert_array_equal, assert_equal, assert_raises_regex
import torch._numpy as np
from torch._numpy import unique
from torch._numpy.testing import assert_array_equal, assert_equal
@skipIf(numpy.__version__ < "1.24", reason="NP_VER: fails on NumPy 1.23.x")
@skipIf(True, reason="TODO implement these ops")
@instantiate_parametrized_tests
class TestSetOps(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/lib/test_arraysetops.py
|
test_setdiff1d_char_array
|
def test_setdiff1d_char_array(self):
a = np.array(["a", "b", "c"])
b = np.array(["a", "b", "s"])
assert_array_equal(setdiff1d(a, b), np.array(["c"]))
|
from unittest import expectedFailure as xfail, skipIf
import numpy
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
subtest,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import ediff1d, in1d, intersect1d, setdiff1d, setxor1d, union1d, unique
from numpy.testing import assert_array_equal, assert_equal, assert_raises_regex
import torch._numpy as np
from torch._numpy import unique
from torch._numpy.testing import assert_array_equal, assert_equal
@skipIf(numpy.__version__ < "1.24", reason="NP_VER: fails on NumPy 1.23.x")
@skipIf(True, reason="TODO implement these ops")
@instantiate_parametrized_tests
class TestSetOps(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/lib/test_arraysetops.py
|
test_manyways
|
def test_manyways(self):
a = np.array([5, 7, 1, 2, 8])
b = np.array([9, 8, 2, 4, 3, 1, 5])
c1 = setxor1d(a, b)
aux1 = intersect1d(a, b)
aux2 = union1d(a, b)
c2 = setdiff1d(aux2, aux1)
assert_array_equal(c1, c2)
|
from unittest import expectedFailure as xfail, skipIf
import numpy
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
subtest,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import ediff1d, in1d, intersect1d, setdiff1d, setxor1d, union1d, unique
from numpy.testing import assert_array_equal, assert_equal, assert_raises_regex
import torch._numpy as np
from torch._numpy import unique
from torch._numpy.testing import assert_array_equal, assert_equal
@skipIf(numpy.__version__ < "1.24", reason="NP_VER: fails on NumPy 1.23.x")
@skipIf(True, reason="TODO implement these ops")
@instantiate_parametrized_tests
class TestSetOps(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/lib/test_arraysetops.py
|
test_unique_1d_2
|
def test_unique_1d_2(self):
# test for ticket 2111 - float
a = [2.0, np.nan, 1.0, np.nan]
ua = [1.0, 2.0, np.nan]
ua_idx = [2, 0, 1]
ua_inv = [1, 2, 0, 2]
ua_cnt = [1, 1, 2]
assert_equal(np.unique(a), ua)
assert_equal(np.unique(a, return_index=True), (ua, ua_idx))
assert_equal(np.unique(a, return_inverse=True), (ua, ua_inv))
assert_equal(np.unique(a, return_counts=True), (ua, ua_cnt))
# test for ticket 2111 - complex
a = [2.0 - 1j, np.nan, 1.0 + 1j, complex(0.0, np.nan), complex(1.0, np.nan)]
ua = [1.0 + 1j, 2.0 - 1j, complex(0.0, np.nan)]
ua_idx = [2, 0, 3]
ua_inv = [1, 2, 0, 2, 2]
ua_cnt = [1, 1, 3]
assert_equal(np.unique(a), ua)
assert_equal(np.unique(a, return_index=True), (ua, ua_idx))
assert_equal(np.unique(a, return_inverse=True), (ua, ua_inv))
assert_equal(np.unique(a, return_counts=True), (ua, ua_cnt))
# test for gh-19300
all_nans = [np.nan] * 4
ua = [np.nan]
ua_idx = [0]
ua_inv = [0, 0, 0, 0]
ua_cnt = [4]
assert_equal(np.unique(all_nans), ua)
assert_equal(np.unique(all_nans, return_index=True), (ua, ua_idx))
assert_equal(np.unique(all_nans, return_inverse=True), (ua, ua_inv))
assert_equal(np.unique(all_nans, return_counts=True), (ua, ua_cnt))
|
from unittest import expectedFailure as xfail, skipIf
import numpy
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
subtest,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import ediff1d, in1d, intersect1d, setdiff1d, setxor1d, union1d, unique
from numpy.testing import assert_array_equal, assert_equal, assert_raises_regex
import torch._numpy as np
from torch._numpy import unique
from torch._numpy.testing import assert_array_equal, assert_equal
@instantiate_parametrized_tests
class TestUnique(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/lib/test_arraysetops.py
|
test_unique_axis_errors
|
def test_unique_axis_errors(self):
assert_raises(np.AxisError, unique, np.arange(10), axis=2)
assert_raises(np.AxisError, unique, np.arange(10), axis=-2)
|
from unittest import expectedFailure as xfail, skipIf
import numpy
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
subtest,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import ediff1d, in1d, intersect1d, setdiff1d, setxor1d, union1d, unique
from numpy.testing import assert_array_equal, assert_equal, assert_raises_regex
import torch._numpy as np
from torch._numpy import unique
from torch._numpy.testing import assert_array_equal, assert_equal
@instantiate_parametrized_tests
class TestUnique(TestCase):
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/lib/test_arraysetops.py
|
_isin_slow
|
def _isin_slow(a, b):
b = np.asarray(b).flatten().tolist()
return a in b
isin_slow = np.vectorize(_isin_slow, otypes=[bool], excluded={1})
|
from unittest import expectedFailure as xfail, skipIf
import numpy
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
subtest,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import ediff1d, in1d, intersect1d, setdiff1d, setxor1d, union1d, unique
from numpy.testing import assert_array_equal, assert_equal, assert_raises_regex
import torch._numpy as np
from torch._numpy import unique
from torch._numpy.testing import assert_array_equal, assert_equal
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
||
torch
|
test/torch_np/numpy_tests/lib/test_arraysetops.py
|
assert_isin_equal
|
def assert_isin_equal(a, b):
x = np.isin(a, b, kind=kind)
y = isin_slow(a, b)
assert_array_equal(x, y)
# multidimensional arrays in both arguments
a = np.arange(24).reshape([2, 3, 4])
b = np.array([[10, 20, 30], [0, 1, 3], [11, 22, 33]])
assert_isin_equal(a, b)
# array-likes as both arguments
c = [(9, 8), (7, 6)]
d = (9, 7)
assert_isin_equal(c, d)
# zero-d array:
f = np.array(3)
assert_isin_equal(f, b)
assert_isin_equal(a, f)
assert_isin_equal(f, f)
# scalar:
assert_isin_equal(5, b)
assert_isin_equal(a, 6)
assert_isin_equal(5, 6)
# empty array-like:
if kind != "table":
# An empty list will become float64,
# which is invalid for kind="table"
x = []
assert_isin_equal(x, b)
assert_isin_equal(a, x)
assert_isin_equal(x, x)
# empty array with various types:
for dtype in [bool, np.int64, np.float64]:
if kind == "table" and dtype == np.float64:
continue
if dtype in {np.int64, np.float64}:
ar = np.array([10, 20, 30], dtype=dtype)
elif dtype in {bool}:
ar = np.array([True, False, False])
empty_array = np.array([], dtype=dtype)
assert_isin_equal(empty_array, ar)
assert_isin_equal(ar, empty_array)
assert_isin_equal(empty_array, empty_array)
|
from unittest import expectedFailure as xfail, skipIf
import numpy
from pytest import raises as assert_raises
from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
subtest,
TEST_WITH_TORCHDYNAMO,
TestCase,
xpassIfTorchDynamo,
)
import numpy as np
from numpy import ediff1d, in1d, intersect1d, setdiff1d, setxor1d, union1d, unique
from numpy.testing import assert_array_equal, assert_equal, assert_raises_regex
import torch._numpy as np
from torch._numpy import unique
from torch._numpy.testing import assert_array_equal, assert_equal
|
c263bd43e8e8502d4726643bc6fd046f0130ac0e
|
32f585d9346e316e554c8d9bf7548af9f62141fc
|
added
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.