def fit(self, embedding: Tensor) -> "BaseRandomProjection":
        """Generates projection matrix from the embedding tensor.

        Args:
            embedding (Tensor): embedding tensor for generating embedding

        Returns:
            (RandomProjection): Return self to be used as
            > generator = RandomProjection()
            > generator = generator.fit()
        """
        n_samples, n_features = embedding.shape
        # device = embedding.device
        # ported from sklearn
        if self.n_components == "auto":
            self.n_components_ = johnson_lindenstrauss_min_dim(
                n_samples=n_samples, eps=self.eps)

            if self.n_components_ <= 0:
                raise ValueError(
                    "eps=%f and n_samples=%d lead to a target dimension of "
                    "%d which is invalid" %
                    (self.eps, n_samples, self.n_components_))

            elif self.n_components_ > n_features:
                raise ValueError(
                    "eps=%f and n_samples=%d lead to a target dimension of "
                    "%d which is larger than the original space with "
                    "n_features=%d" %
                    (self.eps, n_samples, self.n_components_, n_features))
        else:
            if self.n_components <= 0:
                raise ValueError("n_components must be greater than 0, got %s" %
                                 self.n_components)

            elif self.n_components > n_features:
                warnings.warn(
                    "The number of components is higher than the number of"
                    " features: n_features < n_components (%s < %s)."
                    "The dimensionality of the problem will not be reduced." %
                    (n_features, self.n_components))

            self.n_components_ = self.n_components

        # Generate projection matrix
        self.random_matrix = self._make_random_matrix(
            self.n_components_, n_features=n_features)  # .to(device)

        return self
Generates projection matrix from the embedding tensor.

        Args:
            embedding (Tensor): embedding tensor for generating embedding

        Returns:
            (RandomProjection): Return self to be used as
            > generator = RandomProjection()
            > generator = generator.fit()
        
contrib/QualityInspector/qinspector/uad/utils/random_projection.py