• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Owner(s): ["module: dynamo"]
2
3
4import pytest
5
6from torch.testing._internal.common_utils import (
7    run_tests,
8    TEST_WITH_TORCHDYNAMO,
9    TestCase,
10)
11
12
13# If we are going to trace through these, we should use NumPy
14# If testing on eager mode, we use torch._numpy
15if TEST_WITH_TORCHDYNAMO:
16    import numpy as np
17    from numpy.testing import assert_equal
18else:
19    import torch._numpy as np
20    from torch._numpy.testing import assert_equal
21
22
23class TestAppend(TestCase):
24    # tests taken from np.append docstring
25    def test_basic(self):
26        result = np.append([1, 2, 3], [[4, 5, 6], [7, 8, 9]])
27        assert_equal(result, np.arange(1, 10, dtype=int))
28
29        # When `axis` is specified, `values` must have the correct shape.
30        result = np.append([[1, 2, 3], [4, 5, 6]], [[7, 8, 9]], axis=0)
31        assert_equal(result, np.arange(1, 10, dtype=int).reshape((3, 3)))
32
33        with pytest.raises((RuntimeError, ValueError)):
34            np.append([[1, 2, 3], [4, 5, 6]], [7, 8, 9], axis=0)
35
36
37if __name__ == "__main__":
38    run_tests()
39