def _make_random_matrix(self, n_components: int, n_features: int):
        """Random sparse matrix. Based on https://web.stanford.edu/~hastie/Papers/Ping/KDD06_rp.pdf.

        # paddle 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

        Args:
            n_components (int): Dimensionality of the target projection space.
            n_features (int): Dimentionality of the original source space.

        Returns:
            Tensor: Sparse matrix of shape (n_components, n_features).
                The generated Gaussian random matrix is in CSR (compressed sparse row)
                format.
        """

        # Density 'auto'. Factorize density
        density = 1 / np.sqrt(n_features)

        if density == 1:
            # skip index generation if totally dense
            binomial = paddle.distributions.Binomial(total_count=1, probs=0.5)
            components = binomial.sample((n_components, n_features)) * 2 - 1
            components = 1 / np.sqrt(n_components) * components

        else:
            # Sparse matrix is not being generated here as it is stored as dense anyways
            components = paddle.zeros(
                (n_components, n_features), dtype=paddle.float64)
            for i in range(n_components):
                # find the indices of the non-zero components for row i
                nnz_idx = np.random.binomial(n_features, density)
                # get nnz_idx column indices
                # pylint: disable=not-callable
                c_idx = paddle.to_tensor(
                    sample_without_replacement(
                        n_population=n_features,
                        n_samples=nnz_idx,
                        random_state=self.random_state),
                    dtype='int64', )
                data = paddle.to_tensor(
                    np.random.binomial(1, 0.5, c_idx.size)) * 2 - 1
                # assign data to only those columns
                components[i, c_idx] = data

            components *= np.sqrt(1 / density) / np.sqrt(n_components)

        return components.astype('float32')
Random sparse matrix. Based on https://web.stanford.edu/~hastie/Papers/Ping/KDD06_rp.pdf.

        # paddle 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

        Args:
            n_components (int): Dimensionality of the target projection space.
            n_features (int): Dimentionality of the original source space.

        Returns:
            Tensor: Sparse matrix of shape (n_components, n_features).
                The generated Gaussian random matrix is in CSR (compressed sparse row)
                format.
        
contrib/QualityInspector/qinspector/uad/utils/random_projection.py