code: def test_sparse_matrix_indexes(rng):
      ratings = ml_test.ratings
      uidx = pd.Index(rng.permutation(ratings["user"].unique()))
      iidx = pd.Index(rng.permutation(ratings["item"].unique()))
  
      mat, _uidx, _iidx = sparse_ratings(
          ratings, users=uidx, items=iidx
      )
  
      assert _uidx is uidx
      assert _iidx is iidx
      assert len(_uidx) == ratings.user.nunique()
      assert len(_iidx) == ratings.item.nunique()
  
      # verify rating values
      ratings = ratings.set_index(["user", "item"])
      for u in rng.choice(_uidx, size=50):
          ui = _uidx.get_loc(u)
          vs = mat.row_vs(ui)
          vs = pd.Series(vs, _iidx[mat.row_cs(ui)])
          rates = ratings.loc[u]["rating"]
          vs, rates = vs.align(rates)
          assert not any(vs.isna())
          assert not any(rates.isna())
          assert all(vs == rates)
  
file_path: lkpy/tests/test_matrix.py
imports: import scipy.sparse
  import pandas
  from lenskit.data import sparse_ratings
  from lenskit.util.test import ml_test
  from pytest import mark
label_desc: Use image node_id 5 for calling a global function with example usage: test_sparse_matrix_indexes(rng) without return types