def cov(tensor: torch.Tensor) -> torch.Tensor:
        """Calculate the unbiased covariance matrix.

        Args:
            tensor (torch.Tensor): Input tensor of shape ``(D, N)`` where ``D``
                is the dimension and ``N`` is the number of samples.

        Returns:
            torch.Tensor: Covariance matrix of shape ``(D, D)``.

        Example:
            >>> x = torch.randn(5, 100)  # 5 dimensions, 100 samples
            >>> cov_matrix = GaussianKDE.cov(x)
            >>> cov_matrix.shape
            torch.Size([5, 5])
        """
        mean = torch.mean(tensor, dim=1)
        tensor -= mean[:, None]
        return torch.matmul(tensor, tensor.T) / (tensor.size(1) - 1)
Calculate the unbiased covariance matrix.

        Args:
            tensor (torch.Tensor): Input tensor of shape ``(D, N)`` where ``D``
                is the dimension and ``N`` is the number of samples.

        Returns:
            torch.Tensor: Covariance matrix of shape ``(D, D)``.

        Example:
            >>> x = torch.randn(5, 100)  # 5 dimensions, 100 samples
            >>> cov_matrix = GaussianKDE.cov(x)
            >>> cov_matrix.shape
            torch.Size([5, 5])
        
src/anomalib/models/components/stats/kde.py