def _cov(
        observations: torch.Tensor,
        rowvar: bool = False,
        bias: bool = False,
        ddof: int | None = None,
        aweights: torch.Tensor | None = None,
    ) -> torch.Tensor:
        """Estimate covariance matrix similar to numpy.cov.

        Args:
            observations: A 1-D or 2-D tensor containing multiple variables and
                observations. Each row represents a variable, and each column a
                single observation of all variables if ``rowvar=True``. The
                relationship is transposed if ``rowvar=False``.
            rowvar: If ``True``, each row represents a variable. If ``False``,
                each column represents a variable. Defaults to ``False``.
            bias: If ``False`` (default), normalize by ``(N-1)`` for unbiased
                estimate. If ``True``, normalize by ``N``. Can be overridden by
                ``ddof``.
            ddof: Delta degrees of freedom. If not ``None``, overrides ``bias``.
                ``ddof=1`` gives unbiased estimate, ``ddof=0`` gives simple
                average.
            aweights: Optional 1-D tensor of observation weights. Larger weights
                indicate more "important" observations. If ``ddof=0``, weights
                are treated as observation probabilities.

        Returns:
            Covariance matrix of the variables.
        """
        # ensure at least 2D
        if observations.dim() == 1:
            observations = observations.view(-1, 1)

        # treat each column as a data point, each row as a variable
        if rowvar and observations.shape[0] != 1:
            observations = observations.t()

        if ddof is None:
            ddof = 1 if bias == 0 else 0

        weights = aweights
        weights_sum: Any

        if weights is not None:
            if not torch.is_tensor(weights):
                weights = torch.tensor(weights, dtype=torch.float)
            weights_sum = torch.sum(weights)
            avg = torch.sum(observations * (weights / weights_sum)[:, None], 0)
        else:
            avg = torch.mean(observations, 0)

        # Determine the normalization
        if weights is None:
            fact = observations.shape[0] - ddof
        elif ddof == 0:
            fact = weights_sum
        elif aweights is None:
            fact = weights_sum - ddof
        else:
            fact = weights_sum - ddof * torch.sum(weights * weights) / weights_sum

        observations_m = observations.sub(avg.expand_as(observations))

        x_transposed = observations_m.t() if weights is None else torch.mm(torch.diag(weights), observations_m).t()

        covariance = torch.mm(x_transposed, observations_m)
        covariance = covariance / fact

        return covariance.squeeze()
Estimate covariance matrix similar to numpy.cov.

        Args:
            observations: A 1-D or 2-D tensor containing multiple variables and
                observations. Each row represents a variable, and each column a
                single observation of all variables if ``rowvar=True``. The
                relationship is transposed if ``rowvar=False``.
            rowvar: If ``True``, each row represents a variable. If ``False``,
                each column represents a variable. Defaults to ``False``.
            bias: If ``False`` (default), normalize by ``(N-1)`` for unbiased
                estimate. If ``True``, normalize by ``N``. Can be overridden by
                ``ddof``.
            ddof: Delta degrees of freedom. If not ``None``, overrides ``bias``.
                ``ddof=1`` gives unbiased estimate, ``ddof=0`` gives simple
                average.
            aweights: Optional 1-D tensor of observation weights. Larger weights
                indicate more "important" observations. If ``ddof=0``, weights
                are treated as observation probabilities.

        Returns:
            Covariance matrix of the variables.
        
src/anomalib/models/components/stats/multi_variate_gaussian.py