code: def sparsify_rows(
      x: np.ndarray,
      *,
      quantile: float = 0.01,
      dtype: Optional[DTypeLike] = None,
  ) -> scipy.sparse.csr_matrix:
      """Return a row-sparse matrix approximating the input
  
      Parameters
      ----------
      x : np.ndarray [ndim <= 2]
          The input matrix to sparsify.
      quantile : float in [0, 1.0)
          Percentage of magnitude to discard in each row of ``x``
      dtype : np.dtype, optional
          The dtype of the output array.
          If not provided, then ``x.dtype`` will be used.
  
      Returns
      -------
      x_sparse : ``scipy.sparse.csr_matrix`` [shape=x.shape]
          Row-sparsified approximation of ``x``
  
          If ``x.ndim == 1``, then ``x`` is interpreted as a row vector,
          and ``x_sparse.shape == (1, len(x))``.
  
      Raises
      ------
      ParameterError
          If ``x.ndim > 2``
  
          If ``quantile`` lies outside ``[0, 1.0)``
  
      Notes
      -----
      This function caches at level 40.
  
      Examples
      --------
      >>> # Construct a Hann window to sparsify
      >>> x = scipy.signal.hann(32)
      >>> x
      array([ 0.   ,  0.01 ,  0.041,  0.09 ,  0.156,  0.236,  0.326,
              0.424,  0.525,  0.625,  0.72 ,  0.806,  0.879,  0.937,
              0.977,  0.997,  0.997,  0.977,  0.937,  0.879,  0.806,
              0.72 ,  0.625,  0.525,  0.424,  0.326,  0.236,  0.156,
              0.09 ,  0.041,  0.01 ,  0.   ])
      >>> # Discard the bottom percentile
      >>> x_sparse = librosa.util.sparsify_rows(x, quantile=0.01)
      >>> x_sparse
      <1x32 sparse matrix of type '<type 'numpy.float64'>'
          with 26 stored elements in Compressed Sparse Row format>
      >>> x_sparse.todense()
      matrix([[ 0.   ,  0.   ,  0.   ,  0.09 ,  0.156,  0.236,  0.326,
                0.424,  0.525,  0.625,  0.72 ,  0.806,  0.879,  0.937,
                0.977,  0.997,  0.997,  0.977,  0.937,  0.879,  0.806,
                0.72 ,  0.625,  0.525,  0.424,  0.326,  0.236,  0.156,
                0.09 ,  0.   ,  0.   ,  0.   ]])
      >>> # Discard up to the bottom 10th percentile
      >>> x_sparse = librosa.util.sparsify_rows(x, quantile=0.1)
      >>> x_sparse
      <1x32 sparse matrix of type '<type 'numpy.float64'>'
          with 20 stored elements in Compressed Sparse Row format>
      >>> x_sparse.todense()
      matrix([[ 0.   ,  0.   ,  0.   ,  0.   ,  0.   ,  0.   ,  0.326,
                0.424,  0.525,  0.625,  0.72 ,  0.806,  0.879,  0.937,
                0.977,  0.997,  0.997,  0.977,  0.937,  0.879,  0.806,
                0.72 ,  0.625,  0.525,  0.424,  0.326,  0.   ,  0.   ,
                0.   ,  0.   ,  0.   ,  0.   ]])
      """
      if x.ndim == 1:
          x = x.reshape((1, -1))
  
      elif x.ndim > 2:
          raise ParameterError(
              f"Input must have 2 or fewer dimensions. Provided x.shape={x.shape}."
          )
  
      if not 0.0 <= quantile < 1:
          raise ParameterError(f"Invalid quantile {quantile:.2f}")
  
      if dtype is None:
          dtype = x.dtype
  
      x_sparse = scipy.sparse.lil_matrix(x.shape, dtype=dtype)
  
      mags = np.abs(x)
      norms = np.sum(mags, axis=1, keepdims=True)
  
      mag_sort = np.sort(mags, axis=1)
      cumulative_mag = np.cumsum(mag_sort / norms, axis=1)
  
      threshold_idx = np.argmin(cumulative_mag < quantile, axis=1)
  
      for i, j in enumerate(threshold_idx):
          idx = np.where(mags[i] >= mag_sort[i, j])
          x_sparse[i, idx] = x[i, idx]
  
      return x_sparse.tocsr()
  
imports: from __future__ import annotations
  import scipy.ndimage
  import scipy.sparse
  import numpy
  import numba
  from numpy.lib.stride_tricks import as_strided
  from .._cache import cache
  from .exceptions import ParameterError
  from .deprecation import Deprecated
  from numpy.typing import ArrayLike, DTypeLike
  from typing import Any, Callable, Iterable, List, Dict, Optional, Sequence, Tuple, TypeVar, Union, overload
  from typing_extensions import Literal
  from .._typing import _SequenceLike, _FloatLike_co, _ComplexLike_co
label_desc: Use image node_id 21 for calling a global function with example usage: sparsify_rows(x) and returns: x_sparse