def forward(self, embedding: torch.Tensor) -> list[torch.Tensor]:
        """Calculate multivariate Gaussian distribution parameters.

        Computes the mean and inverse covariance matrix from input feature
        embeddings. A small regularization term (0.01) is added to the diagonal
        of the covariance matrix for numerical stability.

        Args:
            embedding: Input tensor of shape ``(B, C, H, W)`` containing CNN
                feature embeddings.

        Returns:
            List containing:
                - Mean tensor of shape ``(C, H*W)``
                - Inverse covariance tensor of shape ``(H*W, C, C)``
        """
        device = embedding.device

        batch, channel, height, width = embedding.size()
        embedding_vectors = embedding.view(batch, channel, height * width)
        self.mean = torch.mean(embedding_vectors, dim=0)
        covariance = torch.zeros(size=(channel, channel, height * width), device=device)
        identity = torch.eye(channel).to(device)
        for i in range(height * width):
            covariance[:, :, i] = self._cov(embedding_vectors[:, :, i], rowvar=False) + 0.01 * identity

        # Stabilize the covariance matrix by adding a small regularization term
        stabilized_covariance = covariance.permute(2, 0, 1) + 1e-5 * identity

        # Check if the device is MPS and fallback to CPU if necessary
        if device.type == "mps":
            # Move stabilized covariance to CPU for inversion
            self.inv_covariance = torch.linalg.inv(stabilized_covariance.cpu()).to(device)
        else:
            # Calculate inverse covariance as we need only the inverse
            self.inv_covariance = torch.linalg.inv(stabilized_covariance)

        return [self.mean, self.inv_covariance]
Calculate multivariate Gaussian distribution parameters.

        Computes the mean and inverse covariance matrix from input feature
        embeddings. A small regularization term (0.01) is added to the diagonal
        of the covariance matrix for numerical stability.

        Args:
            embedding: Input tensor of shape ``(B, C, H, W)`` containing CNN
                feature embeddings.

        Returns:
            List containing:
                - Mean tensor of shape ``(C, H*W)``
                - Inverse covariance tensor of shape ``(H*W, C, C)``
        
src/anomalib/models/components/stats/multi_variate_gaussian.py