code: def test_tensor():
      def check_ndarray_zeros():
          a = nd.zeros(shape=LARGE_X)
          assert a[-1] == 0
          assert a.shape == (LARGE_X,)
          assert a.size == LARGE_X
  
      def check_ndarray_ones():
          a = nd.ones(shape=LARGE_X)
          assert a[-1] == 1
          assert nd.sum(a) == LARGE_X
  
      def check_ndarray_empty():
          a = nd.empty(LARGE_X)
          assert a.shape == (LARGE_X,)
  
      @with_seed()
      def check_ndarray_random_uniform():
          a = nd.random.uniform(shape=LARGE_X)
          assert a[-1] != 0
  
      @pytest.mark.skip(
          reason="Randint flaky, tracked at https://github.com/apache/mxnet/issues/16172"
      )
      @with_seed()
      def check_ndarray_random_randint():
          # check if randint can generate value greater than 2**32 (large)
          low = 2**32
          high = 2**34
          a = nd.random.randint(
              low, high, dtype=np.int64, shape=LARGE_X
          ).asnumpy()
          assert a.shape == (LARGE_X,)
          assert (a >= low).all() and (a < high).all()
  
      @with_seed()
      def check_ndarray_random_exponential():
          a = nd.random.exponential(shape=LARGE_X)
          assert a[-1] >= 0.0
          assert a.shape[0] == LARGE_X
  
      @with_seed()
      def check_ndarray_random_gamma():
          a = nd.random.gamma(shape=LARGE_X)
          assert a[-1] >= 0.0
          assert a.shape[0] == LARGE_X
  
      @with_seed()
      def check_ndarray_random_generalized_negative_binomial():
          a = nd.random.generalized_negative_binomial(shape=LARGE_X)
          assert a[-1] >= 0.0
          assert a.shape[0] == LARGE_X
  
      @with_seed()
      def check_ndarray_random_multinomial():
          a = nd.random.multinomial(nd.random.uniform(shape=LARGE_X))
          assert a[-1] >= 0.0
          assert a.shape[0] == 1
  
      @with_seed()
      def check_ndarray_random_negative_binomial():
          a = nd.random.negative_binomial(shape=LARGE_X)
          assert a[-1] >= 0.0
          assert a.shape[0] == LARGE_X
  
      @with_seed()
      def check_ndarray_random_normal():
          a = nd.random.normal(shape=LARGE_X)
          assert a.shape[0] == LARGE_X
  
      @with_seed()
      def check_ndarray_random_poisson():
          a = nd.random.poisson(shape=LARGE_X)
          assert a[-1] >= 0.0
          assert a.shape[0] == LARGE_X
  
      @with_seed()
      def check_ndarray_random_randn():
          a = nd.random.randn(LARGE_X)
          assert a.shape[0] == LARGE_X
  
      @with_seed()
      def check_ndarray_random_shuffle():
          a = nd.ones(shape=LARGE_X)
          a[-1] = 3
          a = nd.random.shuffle(a)
          unique_a = np.unique(a.asnumpy())
          assert len(unique_a) == 2  # only 2 unique values
          assert unique_a[0] == 1  # first unique value is 1
          assert unique_a[1] == 3  # second unique value is 3
          assert a.shape[0] == LARGE_X
  
      def check_full():
          a = nd.full(LARGE_X, 3)
          assert a.shape[0] == LARGE_X
          assert a[LARGE_X // 2] == 3
          assert a[-1] == 3
  
      def check_repeat():
          x = create_vector(size=LARGE_X // 2)
          y = nd.repeat(x, repeats=2, axis=0)
          assert y.shape[0] == LARGE_X
          assert y[1] == 0
          assert y[LARGE_X - 1] == LARGE_X // 2 - 1
  
      def check_clip():
          a = create_vector(LARGE_X)
          res = nd.clip(a, a_min=100, a_max=1000)
          assert res[-1] == 1000
  
      def check_slice():
          a = nd.ones(LARGE_X)
          res = nd.slice(a, begin=(LARGE_X - MEDIUM_X), end=LARGE_X)
          assert res.shape[0] == MEDIUM_X
          assert res[0] == 1
  
      def check_slice_assign():
          a = nd.ones(shape=LARGE_X)
          a[LARGE_X - 1 : LARGE_X] = 1000
          assert np.sum(a[-1].asnumpy() == 1000) == 1
  
      def check_take():
          a = nd.ones(shape=LARGE_X)
          idx = nd.arange(LARGE_X - 1000, LARGE_X)
          res = nd.take(a, idx)
          assert np.sum(res.asnumpy() == 1) == res.shape[0]
  
      def check_expand_dims():
          a = nd.ones(shape=LARGE_X)
          res = nd.expand_dims(a, axis=0)
          assert res[0][0] == 1
          assert res.shape == (1, a.shape[0])
  
      def check_squeeze():
          a = nd.ones(shape=LARGE_X)
          data = nd.expand_dims(a, axis=0)
          res = nd.squeeze(data)
          assert a[0] == res[0]
          assert res.shape == a.shape
  
      def check_broadcast_div():
          a = nd.ones(shape=LARGE_X)
          b = nd.ones(shape=LARGE_X) * 2
          res = a / b
          assert np.sum(res.asnumpy() == 0.5) == a.shape[0]
  
      def check_size():
          b = create_vector(size=LARGE_X)
          # explicit wait_to_read()
          assert b[0] == 0
          assert b.size == LARGE_X
  
      def check_copy():
          a = nd.ones(LARGE_X)
          b = a.copy()
          assert a[0] == b[0]
          assert b.shape == a.shape
          assert b.size == LARGE_X
  
      def check_copy_to():
          a = create_vector(size=LARGE_X)
          # keeping dtype same as input uses parallel copy which is much faster
          b = nd.zeros(LARGE_X, dtype=np.int64)
          c = a.copyto(b)
          assert c is b
          assert b[-1] == LARGE_X - 1
          assert b[0] == 0
  
      def check_zeros_like():
          a = nd.ones(LARGE_X)
          b = nd.zeros_like(a)
          assert b[-1] == 0
          assert b.shape == a.shape
  
      def check_ones_like():
          a = nd.zeros(LARGE_X)
          b = nd.ones_like(a)
          assert b[-1] == 1
          assert b.shape == a.shape
  
      def check_shape():
          b = create_vector(size=LARGE_X)
          # explicit wait_to_read()
          assert b[0] == 0
          assert b.shape[0] == LARGE_X
  
      def check_concat():
          a = nd.ones(LARGE_X)
          b = nd.zeros(LARGE_X)
          c = nd.concat(a, b, dim=0)
          assert c[0] == 1
          assert c[-1] == 0
          assert c.shape[0] == (2 * LARGE_X)
  
      def check_slice_like():
          a = create_vector(size=LARGE_X)
          b = nd.ones(LARGE_X // 2)
          c = nd.slice_like(a, b)
          assert c.shape == b.shape
          assert c[0] == 0
          assert c[-1] == (LARGE_X // 2 - 1)
  
      def check_slice_axis():
          a = create_vector(size=LARGE_X)
          med = LARGE_X // 2
          c = nd.slice_axis(a, axis=0, begin=0, end=med)
          assert c.shape[0] == a.shape[0] // 2
          assert c[-1][0] == (med - 1)
  
      def check_gather():
          arr = mx.nd.ones(LARGE_X)
          # Passing dtype=np.int64 since randomly generated indices are
          # very large that exceeds int32 limits.
          idx = mx.nd.random.randint(0, LARGE_X, 10, dtype=np.int64)
          # Calls gather_nd internally
          tmp = arr[idx]
          assert np.sum(tmp.asnumpy() == 1) == 10
          # Calls gather_nd internally
          arr[idx] += 1
          assert np.sum(arr[idx].asnumpy() == 2) == 10
  
      def check_infer_shape():
          data_1 = mx.symbol.Variable("data_1")
          data_2 = mx.symbol.Variable("data_2")
          add = data_1 + data_2
          # > add.infer_shape(data_1=(LARGE_X,), data_2=(LARGE_X,))
          # OUTPUT - arg_shapes, out_shapes, aux_shapes
          _, out_shapes, _ = add.infer_shape(
              data_1=(LARGE_X,), data_2=(LARGE_X,)
          )
          assert out_shapes == [(LARGE_X,)]
  
      def check_astype():
          x = create_vector(size=LARGE_X // 4)
          x = nd.tile(x, 4)
          y = x.astype("int32")
          assert y.dtype == np.int32
          assert y[-1] == LARGE_X // 4 - 1
  
      def check_cast():
          x = create_vector(size=LARGE_X // 4)
          x = nd.tile(x, 4)
          y = nd.cast(x, np.int32)
          assert y.dtype == np.int32
          assert y[-1] == LARGE_X // 4 - 1
  
      def check_load_save():
          x = create_vector(size=LARGE_X)
          with TemporaryDirectory() as tmp:
              tmpfile = os.path.join(tmp, "large_vector")
              nd.save(tmpfile, [x])
              y = nd.load(tmpfile)
              y = y[0]
              assert x[0] == y[0]
              assert x[-1] == y[-1]
  
      def check_binary_broadcast():
          def check_correctness(mxnet_op, numpy_op, atol=1e-3):
              a = mx.nd.ones(LARGE_X).as_np_ndarray()
              b = 2 * mx.nd.ones(LARGE_X).as_np_ndarray()
              res = mxnet_op(a, b)
              np_res = numpy_op(1, 2)
              assert np.abs(res[-1] - np_res) < atol
  
          check_correctness(mx.np.arctan2, np.arctan2)
          check_correctness(mx.np.hypot, np.hypot)
  
      check_ndarray_zeros()
      check_ndarray_ones()
      check_ndarray_empty()
      check_ndarray_random_uniform()
      check_ndarray_random_randint()
      check_ndarray_random_exponential()
      check_ndarray_random_gamma()
      check_ndarray_random_generalized_negative_binomial()
      check_ndarray_random_multinomial()
      check_ndarray_random_negative_binomial()
      check_ndarray_random_normal()
      check_ndarray_random_poisson()
      check_ndarray_random_randn()
      check_ndarray_random_shuffle()
      check_full()
      check_repeat()
      check_clip()
      check_slice()
      check_slice_assign()
      check_take()
      check_expand_dims()
      check_squeeze()
      check_broadcast_div()
      check_size()
      check_copy()
      check_copy_to()
      check_zeros_like()
      check_ones_like()
      check_shape()
      check_concat()
      check_slice_like()
      check_slice_axis()
      check_gather()
      check_infer_shape()
      check_astype()
      check_cast()
      check_load_save()
      check_binary_broadcast()
  
file_path: mxnet/tests/nightly/test_large_vector.py
imports: import os
  import sys
  import math
  import numpy
  import mxnet
  from mxnet.test_utils import rand_ndarray, assert_almost_equal, rand_coord_2d, create_vector
  from mxnet.util import TemporaryDirectory
  from mxnet import gluon, nd
  from common import with_seed
  import pytest
label_desc: Use image node_id 2 for calling a global function with example usage: test_tensor() without return types