code: def sparse_encode(
      X,
      dictionary,
      *,
      gram=None,
      cov=None,
      algorithm="lasso_lars",
      n_nonzero_coefs=None,
      alpha=None,
      copy_cov=True,
      init=None,
      max_iter=1000,
      n_jobs=None,
      check_input=True,
      verbose=0,
      positive=False,
  ):
      """Sparse coding.
  
      Each row of the result is the solution to a sparse coding problem.
      The goal is to find a sparse array `code` such that::
  
          X ~= code * dictionary
  
      Read more in the :ref:`User Guide <SparseCoder>`.
  
      Parameters
      ----------
      X : array-like of shape (n_samples, n_features)
          Data matrix.
  
      dictionary : array-like of shape (n_components, n_features)
          The dictionary matrix against which to solve the sparse coding of
          the data. Some of the algorithms assume normalized rows for meaningful
          output.
  
      gram : array-like of shape (n_components, n_components), default=None
          Precomputed Gram matrix, `dictionary * dictionary'`.
  
      cov : array-like of shape (n_components, n_samples), default=None
          Precomputed covariance, `dictionary' * X`.
  
      algorithm : {'lasso_lars', 'lasso_cd', 'lars', 'omp', 'threshold'}, \
              default='lasso_lars'
          The algorithm used:
  
          * `'lars'`: uses the least angle regression method
            (`linear_model.lars_path`);
          * `'lasso_lars'`: uses Lars to compute the Lasso solution;
          * `'lasso_cd'`: uses the coordinate descent method to compute the
            Lasso solution (`linear_model.Lasso`). lasso_lars will be faster if
            the estimated components are sparse;
          * `'omp'`: uses orthogonal matching pursuit to estimate the sparse
            solution;
          * `'threshold'`: squashes to zero all coefficients less than
            regularization from the projection `dictionary * data'`.
  
      n_nonzero_coefs : int, default=None
          Number of nonzero coefficients to target in each column of the
          solution. This is only used by `algorithm='lars'` and `algorithm='omp'`
          and is overridden by `alpha` in the `omp` case. If `None`, then
          `n_nonzero_coefs=int(n_features / 10)`.
  
      alpha : float, default=None
          If `algorithm='lasso_lars'` or `algorithm='lasso_cd'`, `alpha` is the
          penalty applied to the L1 norm.
          If `algorithm='threshold'`, `alpha` is the absolute value of the
          threshold below which coefficients will be squashed to zero.
          If `algorithm='omp'`, `alpha` is the tolerance parameter: the value of
          the reconstruction error targeted. In this case, it overrides
          `n_nonzero_coefs`.
          If `None`, default to 1.
  
      copy_cov : bool, default=True
          Whether to copy the precomputed covariance matrix; if `False`, it may
          be overwritten.
  
      init : ndarray of shape (n_samples, n_components), default=None
          Initialization value of the sparse codes. Only used if
          `algorithm='lasso_cd'`.
  
      max_iter : int, default=1000
          Maximum number of iterations to perform if `algorithm='lasso_cd'` or
          `'lasso_lars'`.
  
      n_jobs : int, default=None
          Number of parallel jobs to run.
          ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.
          ``-1`` means using all processors. See :term:`Glossary <n_jobs>`
          for more details.
  
      check_input : bool, default=True
          If `False`, the input arrays X and dictionary will not be checked.
  
      verbose : int, default=0
          Controls the verbosity; the higher, the more messages.
  
      positive : bool, default=False
          Whether to enforce positivity when finding the encoding.
  
          .. versionadded:: 0.20
  
      Returns
      -------
      code : ndarray of shape (n_samples, n_components)
          The sparse codes.
  
      See Also
      --------
      sklearn.linear_model.lars_path : Compute Least Angle Regression or Lasso
          path using LARS algorithm.
      sklearn.linear_model.orthogonal_mp : Solves Orthogonal Matching Pursuit problems.
      sklearn.linear_model.Lasso : Train Linear Model with L1 prior as regularizer.
      SparseCoder : Find a sparse representation of data from a fixed precomputed
          dictionary.
      """
      if check_input:
          if algorithm == "lasso_cd":
              dictionary = check_array(
                  dictionary, order="C", dtype=[np.float64, np.float32]
              )
              X = check_array(
                  X, order="C", dtype=[np.float64, np.float32]
              )
          else:
              dictionary = check_array(dictionary)
              X = check_array(X)
  
      if dictionary.shape[1] != X.shape[1]:
          raise ValueError(
              "Dictionary and X have different numbers of features:"
              "dictionary.shape: {} X.shape{}".format(
                  dictionary.shape, X.shape
              )
          )
  
      _check_positive_coding(algorithm, positive)
  
      return _sparse_encode(
          X,
          dictionary,
          gram=gram,
          cov=cov,
          algorithm=algorithm,
          n_nonzero_coefs=n_nonzero_coefs,
          alpha=alpha,
          copy_cov=copy_cov,
          init=init,
          max_iter=max_iter,
          n_jobs=n_jobs,
          verbose=verbose,
          positive=positive,
      )
  
imports: import itertools
  import sys
  import time
  import warnings
  from math import ceil
  from numbers import Integral, Real
  import numpy
  from joblib import effective_n_jobs
  from scipy import linalg
  from ..base import BaseEstimator, ClassNamePrefixFeaturesOutMixin, TransformerMixin, _fit_context
  from ..linear_model import Lars, Lasso, LassoLars, orthogonal_mp_gram
  from ..utils import check_array, check_random_state, gen_batches, gen_even_slices
  from ..utils._param_validation import Hidden, Interval, StrOptions, validate_params
  from ..utils.extmath import randomized_svd, row_norms, svd_flip
  from ..utils.parallel import Parallel, delayed
  from ..utils.validation import check_is_fitted
label_desc: Use image node_id 3 for calling a global function with example usage: sparse_encode(X, dictionary) and returns: _sparse_encode