code: def test_tensor():
      def check_ndarray_zeros():
          a = nd.zeros(shape=(LARGE_X, SMALL_Y))
          assert a[-1][0] == 0
          assert a.shape == (LARGE_X, SMALL_Y)
          assert a.size == LARGE_SIZE
  
      def check_ndarray_ones():
          a = nd.ones(shape=(LARGE_X, SMALL_Y))
          assert a[-1][0] == 1
          assert nd.sum(a).asnumpy() == LARGE_SIZE
  
      @with_seed()
      def check_ndarray_random_uniform():
          a = nd.random.uniform(shape=(LARGE_X, SMALL_Y))
          assert a[-1][0] != 0
  
      @pytest.mark.skip(
          reason="Randint flaky, tracked at "
          "https://github.com/apache/mxnet/issues/16172"
      )
      @with_seed()
      def check_ndarray_random_randint():
          a = nd.random.randint(100, 10000, shape=(LARGE_X, SMALL_Y))
          assert a.shape == (LARGE_X, SMALL_Y)
          # check if randint can generate value greater than 2**32 (large)
          low_large_value = 2**32
          high_large_value = 2**34
          a = nd.random.randint(
              low_large_value, high_large_value, dtype=np.int64
          )
          low = mx.nd.array([low_large_value], dtype="int64")
          high = mx.nd.array([high_large_value], dtype="int64")
          assert a >= low and a < high
          assert a[-1][0].dtype == np.int64
  
      @with_seed()
      def check_ndarray_random_exponential():
          scale_array = nd.random.uniform(shape=(MEDIUM_X, SMALL_X))
          a = nd.random.exponential(
              scale=scale_array, shape=(SMALL_X, SMALL_Y)
          )
          assert a[-1][0][0][0] >= 0
          assert a.shape == (MEDIUM_X, SMALL_X, SMALL_X, SMALL_Y)
  
      @with_seed()
      def check_ndarray_random_gamma():
          alpha_array = nd.random.uniform(shape=(MEDIUM_X, SMALL_X))
          beta_array = nd.random.uniform(shape=(MEDIUM_X, SMALL_X))
          a = nd.random.gamma(
              alpha=alpha_array,
              beta=beta_array,
              shape=(SMALL_X, SMALL_Y),
          )
          assert a[-1][0][0][0] >= 0
          assert a.shape == (MEDIUM_X, SMALL_X, SMALL_X, SMALL_Y)
  
      @with_seed()
      def check_ndarray_random_multinomial():
          # test 1 shape dimension
          probs = nd.random.uniform(shape=(LARGE_X, SMALL_Y))
          a = nd.random.multinomial(probs)
          assert a[-1] >= 0
          assert a.shape == (LARGE_X,)
          # test for NDArray multi-dimension shape
          a = nd.random.multinomial(probs, shape=(2, SMALL_Y))
          assert a[-1][0][0] >= 0
          assert a.shape == (LARGE_X, 2, SMALL_Y)
          # test log_likelihood output shape
          a = nd.random.multinomial(
              probs, shape=(2, SMALL_Y), get_prob=True
          )
          assert a[0][0][0][0] >= 0
          assert (
              a[0].shape == (LARGE_X, 2, SMALL_Y)
              and a[0].shape == a[1].shape
          )
  
      @with_seed()
      def check_ndarray_random_generalized_negative_binomial():
          alpha_array = nd.random.uniform(shape=(MEDIUM_X, SMALL_X))
          mu_array = nd.random.uniform(shape=(MEDIUM_X, SMALL_X))
          a = nd.random.generalized_negative_binomial(
              mu=mu_array, alpha=alpha_array, shape=(SMALL_X, SMALL_Y)
          )
          assert a[-1][0][0][0] >= 0
          assert a.shape == (MEDIUM_X, SMALL_X, SMALL_X, SMALL_Y)
  
      @with_seed()
      def check_ndarray_random_negative_binomial():
          k_array = nd.random.uniform(shape=(MEDIUM_X, SMALL_X))
          p_array = nd.random.uniform(shape=(MEDIUM_X, SMALL_X))
          a = nd.random.negative_binomial(
              k=k_array, p=p_array, shape=(SMALL_X, SMALL_Y)
          )
          assert a[-1][0][0][0] >= 0
          assert a.shape == (MEDIUM_X, SMALL_X, SMALL_X, SMALL_Y)
  
      @with_seed()
      def check_ndarray_random_normal():
          scale_array = nd.random.uniform(shape=(MEDIUM_X, SMALL_X))
          loc_array = nd.random.uniform(shape=(MEDIUM_X, SMALL_X))
          a = nd.random.normal(
              loc=loc_array, scale=scale_array, shape=(SMALL_X, SMALL_Y)
          )
          assert a.shape == (MEDIUM_X, SMALL_X, SMALL_X, SMALL_Y)
  
      @with_seed()
      def check_ndarray_random_poisson():
          lambda_array = nd.random.uniform(shape=(MEDIUM_X, SMALL_X))
          a = nd.random.poisson(
              lam=lambda_array, shape=(SMALL_X, SMALL_Y)
          )
          assert a[-1][0][0][0] >= 0
          assert a.shape == (MEDIUM_X, SMALL_X, SMALL_X, SMALL_Y)
  
      @with_seed()
      def check_ndarray_random_randn():
          a = nd.random.randn(LARGE_X, SMALL_Y)
          assert a.shape == (LARGE_X, SMALL_Y)
          # TODO: Once PR #15772 for randn ndarray dtype for loc,scale param merged
          # Add check for (x,y,m,n) where x,y shape of loc,scale and m,n input shape
  
      @with_seed()
      def check_ndarray_random_shuffle():
          a = nd.ones(shape=(LARGE_X, SMALL_Y))
          a[-1] = 3  # assign 3 to entire last row
          a = nd.random.shuffle(a)
          # slice first column from shuffled array
          # pass LARGE_X values to numpy instead of LARGE_X*SMALL_Y
          # could have assigned to last column (so as to pass SMALL_Y)
          # but shuffle operation is performed along first axis
          unique_a = np.unique(a[:, 0].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 == (LARGE_X, SMALL_Y)
  
      def check_ndarray_empty():
          a = nd.empty((LARGE_X, SMALL_Y))
          assert a.shape == (LARGE_X, SMALL_Y)
  
      def check_zeros_like():
          a = nd.array(np.ones((SMALL_Y, LARGE_X)))
          b = nd.zeros_like(a)
          assert b[-1][-1] == 0
          assert b.shape == a.shape
  
      def check_ones_like():
          a = nd.array(np.zeros((SMALL_Y, LARGE_X)))
          b = nd.ones_like(a)
          assert b[-1][-1] == 1
          assert b.shape == a.shape
  
      def check_broadcast():
          a = nd.ones(shape=(LARGE_X, SMALL_Y))
          b = nd.arange(0, LARGE_X).reshape(LARGE_X, 1)
          res = nd.broadcast_to(b, shape=(b.shape[0], SMALL_Y))
          assert np.sum(res[-1].asnumpy() == LARGE_X) == res.shape[1]
          res = mx.nd.broadcast_like(b, a)
          assert np.sum(res[-1].asnumpy() == LARGE_X) == a.shape[1]
  
      def check_clip():
          a = nd.arange(0, LARGE_X * SMALL_Y).reshape(LARGE_X, SMALL_Y)
          res = nd.clip(a, a_min=100, a_max=1000)
          assert np.sum(res[-1].asnumpy() == 1000) == a.shape[1]
  
      def check_split():
          a = nd.arange(0, LARGE_X * SMALL_Y).reshape(LARGE_X, SMALL_Y)
          outs = nd.split(a, num_outputs=SMALL_Y, axis=1)
          result = sum(
              1 for i, v in enumerate(outs) if i == v[0].asnumpy()
          )
          assert result == a.shape[1]
  
      def check_tile():
          a = nd.arange(0, LARGE_X).reshape(LARGE_X, 1)
          b = nd.tile(a, reps=(1, SMALL_Y))
          assert np.sum(b[-1].asnumpy() == LARGE_X) == b.shape[1]
  
      def check_take():
          a = nd.ones(shape=(LARGE_X, SMALL_Y))
          idx = nd.arange(LARGE_X - 1000, LARGE_X)
          res = nd.take(a, idx)
          assert np.sum(res[-1].asnumpy() == 1) == res.shape[1]
  
      def check_slice():
          a = nd.ones(shape=(LARGE_X, SMALL_Y))
          res = nd.slice(
              a, begin=(LARGE_X - 1000, 1), end=(LARGE_X, SMALL_Y)
          )
          assert np.sum(res[-1].asnumpy() == 1) == res.shape[1]
  
      def check_slice_assign():
          a = nd.ones(shape=(LARGE_X, SMALL_Y))
          a[LARGE_X - 1 : LARGE_X] = 1000
          assert np.sum(a[-1].asnumpy() == 1000) == a.shape[1]
  
      def check_slice_like():
          a = create_2d_tensor(rows=SMALL_Y, columns=LARGE_X)
          b = nd.array(np.ones((SMALL_Y // 2, LARGE_X // 2)))
          c = nd.slice_like(a, b)
          d = nd.slice_like(a, b, axes=(0))
          e = nd.slice_like(a, b, axes=(-1))
          assert c.shape == b.shape
          assert d.shape[0] == b.shape[0]
          assert e.shape[-1] == b.shape[-1]
          assert c[0][-1] == 0
          assert d[-1][0] == (SMALL_Y // 2 - 1)
          assert e[-1][-1] == (SMALL_Y - 1)
  
      def check_slice_axis():
          a = create_2d_tensor(rows=SMALL_Y, columns=LARGE_X)
          c = nd.slice_axis(a, axis=0, begin=0, end=SMALL_Y // 2)
          d = nd.slice_axis(a, axis=1, begin=0, end=LARGE_X // 2)
          assert c.shape[0] == a.shape[0] // 2
          assert d.shape[1] == a.shape[1] // 2
          assert c[-1][0] == (SMALL_Y // 2 - 1)
          assert d[-1][-1] == (SMALL_Y - 1)
  
      def check_expand_dims():
          a = nd.ones(shape=(LARGE_X, SMALL_Y))
          res = nd.expand_dims(a, axis=1)
          res.wait_to_read()
          assert a[0][0][0] == 1
          assert res.shape == (a.shape[0], 1, a.shape[1])
  
      def check_squeeze():
          a = nd.ones(shape=(LARGE_X, SMALL_Y))
          data = nd.expand_dims(a, axis=1)
          res = nd.squeeze(data)
          assert res.shape == a.shape
  
      def check_broadcast_div():
          a = nd.ones(shape=(LARGE_X, SMALL_Y))
          b = nd.ones(shape=(LARGE_X, 1)) * 2
          res = a / b
          assert np.sum(res[-1].asnumpy() == 0.5) == a.shape[1]
  
      def check_where():
          a = nd.ones(shape=(LARGE_X, SMALL_Y))
          b = nd.arange(0, LARGE_X * SMALL_Y).reshape(LARGE_X, SMALL_Y)
          res = nd.where(b > 100, a, b)
          assert np.sum(res[-1].asnumpy() == 1) == b.shape[1]
          csr_cond = nd.sparse.cast_storage(b < 10, "csr")
          res = nd.sparse.where(csr_cond, a, b)
          assert np.sum(res[0].asnumpy() == 1) == 10
  
      def check_pick():
          a = mx.nd.ones(shape=(256 * 35, 1024 * 1024))
          b = mx.nd.ones(shape=(256 * 35,))
          res = mx.nd.pick(a, b)
          assert res.shape == b.shape
  
      @pytest.mark.skip(
          reason="Memory doesn't free up after stacked execution with other ops, "
          "tracked at https://github.com/apache/mxnet/issues/17411"
      )
      def check_depthtospace():
          def numpy_depth_to_space(x, blocksize):
              b, c, h, w = (
                  x.shape[0],
                  x.shape[1],
                  x.shape[2],
                  x.shape[3],
              )
              tmp = np.reshape(
                  x,
                  [
                      b,
                      blocksize,
                      blocksize,
                      c // (blocksize**2),
                      h,
                      w,
                  ],
              )
              tmp = np.transpose(tmp, [0, 3, 4, 1, 5, 2])
              y = np.reshape(
                  tmp,
                  [
                      b,
                      c // (blocksize**2),
                      h * blocksize,
                      w * blocksize,
                  ],
              )
              return y
  
          shape_inp = (LARGE_X, 8, 4, 2)
          data = rand_ndarray(shape_inp, "default")
          data_np = data.asnumpy()
          expected = numpy_depth_to_space(data_np, 2)
          output = mx.nd.depth_to_space(data, 2)
          assert_almost_equal(
              output.asnumpy(), expected, atol=1e-3, rtol=1e-3
          )
  
      @pytest.mark.skip(
          reason="Memory doesn't free up after stacked execution with other ops, "
          "tracked at https://github.com/apache/mxnet/issues/17411"
      )
      def check_spacetodepth():
          def numpy_space_to_depth(x, blocksize):
              b, c, h, w = (
                  x.shape[0],
                  x.shape[1],
                  x.shape[2],
                  x.shape[3],
              )
              tmp = np.reshape(
                  x,
                  [
                      b,
                      c,
                      h // blocksize,
                      blocksize,
                      w // blocksize,
                      blocksize,
                  ],
              )
              tmp = np.transpose(tmp, [0, 3, 5, 1, 2, 4])
              y = np.reshape(
                  tmp,
                  [
                      b,
                      c * (blocksize**2),
                      h // blocksize,
                      w // blocksize,
                  ],
              )
              return y
  
          shape_inp = (LARGE_X, 2, 8, 4)
          data = rand_ndarray(shape_inp, "default")
          data_np = data.asnumpy()
          expected = numpy_space_to_depth(data_np, 2)
          output = mx.nd.space_to_depth(data, 2)
          assert_almost_equal(
              output.asnumpy(), expected, atol=1e-3, rtol=1e-3
          )
  
      @with_seed()
      def check_diag():
          a_np = np.random.random((LARGE_X, SMALL_Y)).astype(np.float32)
          a = mx.nd.array(a_np)
  
          # k == 0
          r = mx.nd.diag(a)
          assert_almost_equal(r.asnumpy(), np.diag(a_np))
  
          # k == 1
          k = 1
          r = mx.nd.diag(a, k=k)
          assert_almost_equal(r.asnumpy(), np.diag(a_np, k=k))
  
          # k == -1
          k = -1
          r = mx.nd.diag(a, k=k)
          assert_almost_equal(r.asnumpy(), np.diag(a_np, k=k))
  
          # random k
          k = np.random.randint(
              -min(LARGE_X, SMALL_Y) + 1, min(LARGE_X, SMALL_Y)
          )
          r = mx.nd.diag(a, k=k)
          assert_almost_equal(r.asnumpy(), np.diag(a_np, k=k))
  
      @with_seed()
      def check_ravel_multi_index():
          x1, y1 = rand_coord_2d((LARGE_X - 100), LARGE_X, 10, SMALL_Y)
          x2, y2 = rand_coord_2d((LARGE_X - 200), LARGE_X, 9, SMALL_Y)
          x3, y3 = rand_coord_2d((LARGE_X - 300), LARGE_X, 8, SMALL_Y)
          indices_2d = [[x1, x2, x3], [y1, y2, y3]]
          idx = mx.nd.ravel_multi_index(
              mx.nd.array(indices_2d, dtype=np.int64),
              shape=(LARGE_X, SMALL_Y),
          )
          idx_numpy = np.ravel_multi_index(
              indices_2d, (LARGE_X, SMALL_Y)
          )
          assert (
              np.sum(
                  1 for i in range(idx.size) if idx[i] == idx_numpy[i]
              )
              == 3
          )
  
      @with_seed()
      def check_unravel_index():
          x1, y1 = rand_coord_2d((LARGE_X - 100), LARGE_X, 10, SMALL_Y)
          x2, y2 = rand_coord_2d((LARGE_X - 200), LARGE_X, 9, SMALL_Y)
          x3, y3 = rand_coord_2d((LARGE_X - 300), LARGE_X, 8, SMALL_Y)
          original_2d_indices = [[x1, x2, x3], [y1, y2, y3]]
          idx_numpy = np.ravel_multi_index(
              original_2d_indices, (LARGE_X, SMALL_Y)
          )
          indices_2d = mx.nd.unravel_index(
              mx.nd.array(idx_numpy, dtype=np.int64),
              shape=(LARGE_X, SMALL_Y),
          )
          assert (
              indices_2d.asnumpy() == np.array(original_2d_indices)
          ).all()
  
      @pytest.mark.skip(
          reason="Memory doesn't free up after stacked execution with other ops, "
          + "tracked at https://github.com/apache/mxnet/issues/17411"
      )
      def check_transpose():
          check_dtypes = [np.float32, np.int64]
          for dtype in check_dtypes:
              b = create_2d_tensor(
                  rows=LARGE_X, columns=SMALL_Y, dtype=dtype
              )
              t = b.T
              assert t.shape == (SMALL_Y, LARGE_X)
              ref_out = np.transpose(b.asnumpy())
              assert_almost_equal(t.asnumpy(), ref_out, rtol=1e-10)
  
      @pytest.mark.skip(
          reason="Memory doesn't free up after stacked execution with other ops, "
          + "tracked at https://github.com/apache/mxnet/issues/17411"
      )
      def check_swapaxes():
          b = create_2d_tensor(rows=LARGE_X, columns=SMALL_Y)
          t = nd.swapaxes(b, dim1=0, dim2=1)
          assert (
              np.sum(t[:, -1].asnumpy() == (LARGE_X - 1)) == b.shape[1]
          )
          assert t.shape == (SMALL_Y, LARGE_X)
  
      @pytest.mark.skip(
          reason="Memory doesn't free up after stacked execution with other ops, "
          + "tracked at https://github.com/apache/mxnet/issues/17411"
      )
      def check_flip():
          b = create_2d_tensor(rows=LARGE_X, columns=SMALL_Y)
          t = nd.flip(b, axis=0)
          assert np.sum(t[-1, :].asnumpy() == 0) == b.shape[1]
          assert t.shape == (LARGE_X, SMALL_Y)
  
      def check_sequence_mask():
          # Sequence Mask input [max_sequence_length, batch_size, other_feature_dims]
          # test with input batch_size = 2
          a = nd.arange(0, LARGE_X * SMALL_Y * 2).reshape(
              LARGE_X, 2, SMALL_Y
          )
          # test as identity operator
          b = nd.SequenceMask(a)
          assert b[-1][0][1] == a[-1][0][1]
          assert b.shape == a.shape
          # test with default mask
          b = nd.SequenceMask(
              a,
              sequence_length=nd.array([1, 1]),
              use_sequence_length=True,
          )
          assert (
              b[0][1][-1] == a[0][1][-1]
          )  # first sequence of each batch kept
          assert b[-1][-1][-1] != a[-1][-1][-1]  # rest sequences masked
          assert b[-1][-1][-1] == 0
  
          # test with mask value
          b = nd.SequenceMask(
              a,
              sequence_length=nd.array([1, 1]),
              use_sequence_length=True,
              value=-1,
          )
          assert b[-1][-1][-1] == -1
  
      def check_sequence_reverse():
          a = nd.arange(0, LARGE_X * SMALL_Y * 2).reshape(
              LARGE_X, 2, SMALL_Y
          )
          # test as reverse operator
          b = nd.SequenceReverse(a)
          assert b[-1][0][0] == a[0][0][0]
          assert b.shape == a.shape
          # test with sequence length
          # 2 rows of batch 1 and 3 rows of batch 2 reversed
          b = nd.SequenceReverse(
              a,
              sequence_length=nd.array([2, 3]),
              use_sequence_length=True,
          )
          assert b[1][0][0] == a[0][0][0]  # check if reversed
          assert b[-1][0][0] == a[-1][0][0]  # check if intact
          assert b.shape == a.shape
  
      def check_sequence_last():
          a = nd.arange(0, LARGE_X * SMALL_Y * 2).reshape(
              LARGE_X, 2, SMALL_Y
          )
          # test if returns last sequence
          b = nd.SequenceLast(a)
          assert_almost_equal(
              b.asnumpy(), a[-1].asnumpy()
          )  # only checks for (2, SMALL_Y) tensor
          assert b.shape == (2, SMALL_Y)
          # test with sequence length
          # parameter sequence_length - NDArray with shape (batch_size)
          # (2,3) indicates 2nd sequence from batch 1 and 3rd sequence from batch 2
          b = nd.SequenceLast(
              a,
              sequence_length=mx.nd.array([2, 3]),
              use_sequence_length=True,
          )
          # check if it takes 2nd sequence from the first batch
          assert b[0][-1] == a[1][0][-1]
  
      def check_index_copy():
          x = mx.nd.zeros((LARGE_X, SMALL_Y))
          t = mx.nd.arange(1, SMALL_Y + 1).reshape((1, SMALL_Y))
          index = mx.nd.array([LARGE_X - 1], dtype="int64")
  
          x = mx.nd.contrib.index_copy(x, index, t)
          assert x[-1][-1] == t[0][-1]
  
      def check_one_hot():
          # default dtype of ndarray is float32 which cannot index elements over 2^32
          a = nd.array([1, (VLARGE_X - 1)], dtype=np.int64)
          b = nd.one_hot(a, VLARGE_X)
          b[0][1] == 1
          b[1][-1] == 1
  
      def check_full():
          a = nd.full((SMALL_Y, LARGE_X), 3)
          assert a.shape == (SMALL_Y, LARGE_X)
          assert a[SMALL_Y // 2][LARGE_X // 2] == 3
          assert a[-1][-1] == 3
  
      def check_shape():
          b = create_2d_tensor(rows=SMALL_Y, columns=LARGE_X)
          mx.nd.waitall()
          assert b.shape == (SMALL_Y, LARGE_X)
  
      def check_size():
          b = create_2d_tensor(rows=SMALL_Y, columns=LARGE_X)
          mx.nd.waitall()
          assert b.size == LARGE_SIZE
  
      def check_copy():
          a = nd.ones((SMALL_Y, LARGE_X))
          b = a.copy()
          nd.waitall()
          assert b.shape == a.shape
          assert b.size == LARGE_SIZE
  
      def check_copy_to():
          a = create_2d_tensor(rows=SMALL_Y, columns=LARGE_X)
          b = nd.array(np.zeros((SMALL_Y, LARGE_X)))
          c = a.copyto(b)
          assert c is b
          assert b[-1][-1] == SMALL_Y - 1
  
      def check_reshape_like():
          a = nd.array(np.zeros((SMALL_Y, LARGE_X)))
          b = nd.array(np.zeros((SMALL_Y // 2, LARGE_X * 2)))
          c = nd.reshape_like(a, b)
          assert c.shape == (SMALL_Y // 2, LARGE_X * 2)
  
      def check_flatten():
          check_dtypes = [np.float32, np.int64]
          for dtype in check_dtypes:
              a = create_2d_tensor(
                  rows=LARGE_X, columns=SMALL_Y, dtype=dtype
              ).reshape((LARGE_X // 2, 2, SMALL_Y))
              b = nd.flatten(a)
              # Here we removed the value asserts due to different precision of `int64` and `float32`.
              # For `float32`, it will lose some precision when `LARGE_X` is too large, that is `LARGE_X-1`
              # and `LARGE_X-2` can not represent the accurate value in the current situation.
              assert b.shape == (LARGE_X // 2, SMALL_Y * 2)
              assert_almost_equal(
                  b[-1, -1].asnumpy(),
                  a[-1, -1, -1].asnumpy(),
                  rtol=1e-8,
              )
  
      def check_concat():
          a = nd.array(np.ones((SMALL_Y, LARGE_X)))
          b = nd.array(np.zeros((SMALL_Y, LARGE_X)))
          for axis in [0, 1]:
              c = nd.concat(a, b, dim=axis)
              c.wait_to_read()
              assert c.shape[axis] == b.shape[axis] * 2
              assert c.shape[1 - axis] == b.shape[1 - axis]
  
      def check_stack():
          a = nd.array(np.ones((SMALL_Y, LARGE_X)))
          b = nd.array(np.zeros((SMALL_Y, LARGE_X)))
          c = nd.stack(a, b, axis=1)
          assert c.shape == (b.shape[0], 2, LARGE_X)
  
      def check_broadcast_axes():
          a = create_2d_tensor(rows=1, columns=LARGE_X)
          b = nd.broadcast_axis(a, axis=[0], size=2)
          assert b.shape == (a.shape[0] * 2, a.shape[1])
  
      def check_astype():
          x = create_2d_tensor(rows=SMALL_Y, columns=LARGE_X)
          y = x.astype("int32")
          assert y.dtype == np.int32
          assert y[-1][-1] == SMALL_Y - 1
  
      def check_cast():
          x = create_2d_tensor(rows=SMALL_Y, columns=LARGE_X)
          y = nd.cast(x, np.int32)
          assert y.dtype == np.int32
          assert y[-1][-1] == SMALL_Y - 1
  
      def check_repeat():
          x = create_2d_tensor(rows=SMALL_Y, columns=LARGE_X // 2)
          y = nd.repeat(x, repeats=2, axis=1)
          assert y.shape == (SMALL_Y, LARGE_X)
          assert y[0][1] == 0
          assert y[-1][-1] == SMALL_Y - 1
          x = create_2d_tensor(rows=SMALL_Y // 2, columns=LARGE_X)
          y = nd.repeat(x, repeats=2, axis=0)
          assert y.shape == (SMALL_Y, LARGE_X)
          assert y[0][1] == 0
          assert y[-1][0] == SMALL_Y // 2 - 1
  
      def check_ndarray_convert():
          a = nd.zeros(shape=(LARGE_X, SMALL_Y))
          b = a.astype(np.int32)
          assert b.dtype == np.int32
          b = a.tostype("row_sparse")
          assert isinstance(b, mx.nd.sparse.RowSparseNDArray)
  
      def check_load_save():
          x = create_2d_tensor(SMALL_Y, LARGE_X)
          with TemporaryDirectory() as tmp:
              tmpfile = os.path.join(tmp, "large_tensor")
              nd.save(tmpfile, [x])
              y = nd.load(tmpfile)
              y = y[0]
              assert x[0][0] == y[0][0]
              assert x[-1][-1] == y[-1][-1]
  
      def check_pad():
          x = create_2d_tensor(
              rows=SMALL_Y - 2,
              columns=LARGE_X // 2 - 2,
              dtype=np.float32,
          ).reshape(1, 1, SMALL_Y - 2, LARGE_X // 2 - 2)
          y = nd.pad(x, mode="edge", pad_width=(0, 0, 0, 0, 1, 1, 1, 1))
          assert y[0][0][1][0] == 0
          assert y[0][0][1][-1] == 0
          assert y[0][0][-1][0] == SMALL_Y - 3
          assert y[0][0][-1][-1] == SMALL_Y - 3
          assert y.shape == (1, 1, SMALL_Y, LARGE_X // 2)
  
      def check_gather():
          arr = mx.nd.ones((LARGE_X, SMALL_Y))
          idx = mx.nd.random.randint(0, LARGE_X, SMALL_X)
          # Calls gather_nd internally
          tmp = arr[idx]
          assert np.sum(tmp[0].asnumpy() == 1) == SMALL_Y
          # Calls gather_nd internally
          arr[idx] += 1
          assert np.sum(arr[idx[0]].asnumpy() == 2) == SMALL_Y
  
      def check_binary_broadcast():
          def check_correctness(mxnet_op, numpy_op, atol=1e-3):
              a = mx.nd.ones((LARGE_X, SMALL_Y)).as_np_ndarray()
              b = 2 * mx.nd.ones((LARGE_X, SMALL_Y)).as_np_ndarray()
              res = mxnet_op(a, b)
              np_res = numpy_op(1, 2)
              assert np.abs(res[-1][-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_random_uniform()
      check_ndarray_random_randint()
      check_ndarray_random_exponential()
      check_ndarray_random_gamma()
      check_ndarray_random_multinomial()
      check_ndarray_random_generalized_negative_binomial()
      check_ndarray_random_negative_binomial()
      check_ndarray_random_normal()
      check_ndarray_random_poisson()
      check_ndarray_random_randn()
      check_ndarray_random_shuffle()
      check_ndarray_empty()
      check_zeros_like()
      check_ones_like()
      check_broadcast()
      check_clip()
      check_split()
      check_tile()
      check_take()
      check_slice()
      check_slice_assign()
      check_slice_like()
      check_slice_axis()
      check_expand_dims()
      check_squeeze()
      check_broadcast_div()
      check_where()
      check_pick()
      check_depthtospace()
      check_spacetodepth()
      check_diag()
      check_ravel_multi_index()
      check_unravel_index()
      check_transpose()
      check_swapaxes()
      check_flip()
      check_sequence_mask()
      check_sequence_reverse()
      check_sequence_last()
      check_index_copy()
      check_one_hot()
      check_full()
      check_shape()
      check_size()
      check_copy()
      check_copy_to()
      check_reshape_like()
      check_flatten()
      check_concat()
      check_stack()
      check_broadcast_axes()
      check_astype()
      check_cast()
      check_repeat()
      check_ndarray_convert()
      check_load_save()
      check_pad()
      check_gather()
      check_binary_broadcast()
  
file_path: mxnet/tests/nightly/test_large_array.py
imports: import os
  import sys
  import tempfile
  import math
  import numpy
  import mxnet
  from mxnet.test_utils import rand_ndarray, assert_almost_equal, rand_coord_2d, default_device, check_symbolic_forward, create_2d_tensor
  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() and returns: y, y