spyrit.core.torch.Cov2Var

spyrit.core.torch.Cov2Var(Cov: tensor, out_shape=None)[source]

Extracts Variance Matrix from Covariance Matrix.

The Variance matrix is extracted from the diagonal of the Covariance matrix.

Args:

Cov (torch.tensor): Covariance matrix of shape \((N_x, N_x)\).

out_shape (tuple, optional): Shape of the output variance matrix. If None, \(N_x\) must be a perfect square and the output is a square matrix whose shape is \((\sqrt{N_x}, \sqrt{N_x})\). Default is None.

Raises:

ValueError: If the input matrix is not square.

ValueError: If the output shape is not valid.

Returns:

torch.tensor: Variance matrix of shape \((\sqrt{N_x}, \sqrt{N_x})\) or \(out_shape\) if provided.