code: def test_to_csr(self, n_samples, n_features, sparsity) -> None:
      if n_samples == 0 or n_features == 0 or sparsity == 1.0:
          csr = scipy.sparse.csr_matrix(np.empty((0, 0)))
      else:
          csr = tm.make_sparse_regression(
              n_samples, n_features, sparsity, False
          )[0].astype(np.float32)
      m = xgb.DMatrix(data=csr)
      ret = m.get_data()
      np.testing.assert_equal(csr.indptr, ret.indptr)
      np.testing.assert_equal(csr.data, ret.data)
      np.testing.assert_equal(csr.indices, ret.indices)
  
imports: import csv
  import os
  import tempfile
  import warnings
  import numpy
  import pytest
  import scipy.sparse
  from hypothesis import given, settings, strategies
  from scipy.sparse import csr_matrix, rand
  import xgboost
  from xgboost import testing
  from xgboost.core import DataSplitMode
  from xgboost.testing.data import np_dtypes, run_base_margin_info
label_desc: Use image node_id 18 for calling the TestDMatrix obj's underlying member method code with example usage: obj.test_to_csr(n_samples, n_features, sparsity) without return types