code: def test_create_csr():
      def check_create_csr_from_nd(shape, density, dtype):
          matrix = rand_ndarray(shape, "csr", density)
          # create data array with provided dtype and ctx
          data = mx.nd.array(matrix.data.asnumpy(), dtype=dtype)
          indptr = matrix.indptr
          indices = matrix.indices
          csr_created = mx.nd.sparse.csr_matrix(
              (data, indices, indptr), shape=shape
          )
          assert csr_created.stype == "csr"
          assert same(csr_created.data.asnumpy(), data.asnumpy())
          assert same(csr_created.indptr.asnumpy(), indptr.asnumpy())
          assert same(csr_created.indices.asnumpy(), indices.asnumpy())
          # verify csr matrix dtype and ctx is consistent from the ones provided
          assert csr_created.dtype == dtype, (csr_created, dtype)
          assert csr_created.data.dtype == dtype, (
              csr_created.data.dtype,
              dtype,
          )
          assert csr_created.context == mx.context.current_context(), (
              csr_created.context,
              mx.context.current_context(),
          )
          csr_copy = mx.nd.array(csr_created)
          assert same(csr_copy.asnumpy(), csr_created.asnumpy())
  
      def check_create_csr_from_coo(shape, density, dtype):
          matrix = rand_ndarray(shape, "csr", density)
          sp_csr = matrix.asscipy()
          sp_coo = sp_csr.tocoo()
          csr_created = mx.nd.sparse.csr_matrix(
              (sp_coo.data, (sp_coo.row, sp_coo.col)),
              shape=shape,
              dtype=dtype,
          )
          assert csr_created.stype == "csr"
          assert same(csr_created.data.asnumpy(), sp_csr.data)
          assert same(csr_created.indptr.asnumpy(), sp_csr.indptr)
          assert same(csr_created.indices.asnumpy(), sp_csr.indices)
          csr_copy = mx.nd.array(csr_created)
          assert same(csr_copy.asnumpy(), csr_created.asnumpy())
          # verify csr matrix dtype and ctx is consistent
          assert csr_created.dtype == dtype, (csr_created.dtype, dtype)
          assert csr_created.data.dtype == dtype, (
              csr_created.data.dtype,
              dtype,
          )
          assert csr_created.context == mx.context.current_context(), (
              csr_created.context,
              mx.context.current_context(),
          )
  
      def check_create_csr_from_scipy(shape, density, f):
          def assert_csr_almost_equal(nd, sp):
              assert_almost_equal(nd.data.asnumpy(), sp.data)
              assert_almost_equal(nd.indptr.asnumpy(), sp.indptr)
              assert_almost_equal(nd.indices.asnumpy(), sp.indices)
              sp_csr = nd.asscipy()
              assert_almost_equal(sp_csr.data, sp.data)
              assert_almost_equal(sp_csr.indptr, sp.indptr)
              assert_almost_equal(sp_csr.indices, sp.indices)
              assert sp.dtype == sp_csr.dtype, (sp.dtype, sp_csr.dtype)
  
          # random canonical csr
          csr_sp = spsp.rand(shape[0], shape[1], density, format="csr")
          csr_nd = f(csr_sp)
          assert_csr_almost_equal(csr_nd, csr_sp)
          # non-canonical csr which contains duplicates and unsorted indices
          indptr = np.array([0, 2, 3, 7])
          indices = np.array([0, 2, 2, 0, 1, 2, 1])
          data = np.array([1, 2, 3, 4, 5, 6, 1])
          non_canonical_csr = spsp.csr_matrix(
              (data, indices, indptr), shape=(3, 3), dtype=csr_nd.dtype
          )
          canonical_csr_nd = f(non_canonical_csr, dtype=csr_nd.dtype)
          canonical_csr_sp = non_canonical_csr.copy()
          canonical_csr_sp.sum_duplicates()
          canonical_csr_sp.sort_indices()
          assert_csr_almost_equal(canonical_csr_nd, canonical_csr_sp)
  
      dim0 = 20
      dim1 = 20
      densities = [0, 0.5]
      dtype = np.float64
      for density in densities:
          shape = rand_shape_2d(dim0, dim1)
          check_create_csr_from_nd(shape, density, dtype)
          check_create_csr_from_coo(shape, density, dtype)
          check_create_csr_from_scipy(
              shape, density, mx.nd.sparse.array
          )
          check_create_csr_from_scipy(shape, density, mx.nd.array)
  
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 28 for calling a global function with example usage: test_create_csr() without return types