class_docstr: Sparse Random Projection using PyTorch operations.
  
  Args:
      eps (float, optional): Minimum distortion rate parameter for calculating
          Johnson-Lindenstrauss minimum dimensions. Defaults to 0.1.
      random_state (int | None, optional): Uses the seed to set the random
          state for sample_without_replacement function. Defaults to None.
docstr: Generates sparse matrix from the embedding tensor.
  
  Args:
      embedding (Tensor): embedding tensor for generating embedding
  
  Returns:
      (SparseRandomProjection): Return self to be used as
      >>> generator = SparseRandomProjection()
      >>> generator = generator.fit()
docstr_tok: ["Generates","sparse","matrix","from","the","embedding","tensor",".","Args",":","embedding","(","Tensor",")",":","embedding","tensor","for","generating","embedding","Returns",":","(","SparseRandomProjection",")",":","Return","self","to","be","used","as",">",">",">","generator","=","SparseRandomProjection","(",")",">",">",">","generator","=","generator.fit","(",")"]
code: def fit(self, embedding: Tensor) -> SparseRandomProjection:
      """Generates sparse matrix from the embedding tensor.
  
      Args:
          embedding (Tensor): embedding tensor for generating embedding
  
      Returns:
          (SparseRandomProjection): Return self to be used as
          >>> generator = SparseRandomProjection()
          >>> generator = generator.fit()
      """
      n_samples, n_features = embedding.shape
      device = embedding.device
  
      self.n_components = self.johnson_lindenstrauss_min_dim(
          n_samples=n_samples, eps=self.eps
      )
  
      # Generate projection matrix
      # torch can't multiply directly on sparse matrix and moving sparse matrix to cuda throws error
      # (Could not run 'aten::empty_strided' with arguments from the 'SparseCsrCUDA' backend)
      # hence sparse matrix is stored as a dense matrix on the device
      self.sparse_random_matrix = self._sparse_random_matrix(
          n_features=n_features
      ).to(device)
  
      return self
  
file_path: anomalib/src/anomalib/models/components/dimensionality_reduction/random_projection.py
imports: from __future__ import annotations
  import numpy
  import torch
  from sklearn.utils.random import sample_without_replacement
  from torch import Tensor
label_desc: Use image node_id 4 for calling the SparseRandomProjection obj's underlying member method code with example usage: obj.fit(embedding) and returns: self