code: def test_sparse_nd_broadcast():
      sample_num = 1000
  
      # TODO(haibin) test with more than 2 dimensions
      def test_broadcast_to(stype):
          for _ in range(sample_num):
              ndim = 2
              target_shape = np.random.randint(1, 11, size=ndim)
              shape = target_shape.copy()
              axis_flags = np.random.randint(0, 2, size=ndim)
              for axis, flag in enumerate(axis_flags):
                  if flag:
                      shape[axis] = 1
              dat = np.random.rand(*shape) - 0.5
              numpy_ret = dat
              ndarray = mx.nd.array(dat).tostype(stype)
              ndarray_ret = ndarray.broadcast_to(shape=target_shape)
              if type(ndarray_ret) is mx.ndarray.NDArray:
                  ndarray_ret = ndarray_ret.asnumpy()
              assert (ndarray_ret.shape == target_shape).all()
              err = np.square(ndarray_ret - numpy_ret).mean()
              assert err < 1e-8
  
      def test_broadcast_like(stype):
          for _ in range(sample_num):
              ndim = 2
              target_shape = np.random.randint(1, 11, size=ndim)
              target = mx.nd.ones(shape=tuple(target_shape))
              shape = target_shape.copy()
              axis_flags = np.random.randint(0, 2, size=ndim)
              for axis, flag in enumerate(axis_flags):
                  if flag:
                      shape[axis] = 1
              dat = np.random.rand(*shape) - 0.5
              numpy_ret = dat
              ndarray = mx.nd.array(dat).tostype(stype)
              ndarray_ret = ndarray.broadcast_like(target)
              if type(ndarray_ret) is mx.ndarray.NDArray:
                  ndarray_ret = ndarray_ret.asnumpy()
              assert (ndarray_ret.shape == target_shape).all()
              err = np.square(ndarray_ret - numpy_ret).mean()
              assert err < 1e-8
  
      stypes = ["csr", "row_sparse"]
      for stype in stypes:
          test_broadcast_to(stype)
          test_broadcast_like(stype)
  
imports: import pickle
  from mxnet.ndarray import NDArray
  import mxnet
  from mxnet.test_utils import *
  from common import random_seed
  from mxnet.base import mx_real_t
  from numpy.testing import assert_allclose
  import numpy.random
  import numpy
  import scipy.sparse
  from common import assertRaises, xfail_when_nonstandard_decimal_separator
  from mxnet.ndarray.sparse import RowSparseNDArray, CSRNDArray
  import pytest
label_desc: Use image node_id 18 for calling a global function with example usage: test_sparse_nd_broadcast() without return types