spd_learn.functional.vec_to_sym#
- spd_learn.functional.vec_to_sym(x_vec, preserve_norm=True, upper=True)[source]#
Reconstructs symmetric matrices from vectorization.
This function is the inverse of
sym_to_upper(). It reconstructs symmetric matrices from their vectorized triangular representation.When
preserve_norm=True, the inverse \(1/\sqrt{2}\) scaling is applied to off-diagonal elements to recover the original matrix values from a norm-preserving vectorization.When
preserve_norm=False, no scaling is applied (inverse of rawvech).- Parameters:
x_vec (torch.Tensor) – Vectorized triangular matrices with shape (…, n(n+1)/2).
preserve_norm (bool, default=True) – If True, applies inverse sqrt(2) scaling to off-diagonal elements. If False, uses raw values without scaling.
upper (bool, default=True) – If True, reconstructs from upper triangular representation. If False, reconstructs from lower triangular representation.
- Returns:
Symmetric matrices with shape (…, n, n).
- Return type:
See also
sym_to_upper()Forward operation, vectorizes symmetric matrices.
ExpEigMaps tangent vectors back to SPD manifold.
Examples
>>> import torch >>> from spd_learn.functional import sym_to_upper, vec_to_sym >>> X = torch.tensor([[1., 2.], [2., 3.]]) >>> v = sym_to_upper(X) >>> X_reconstructed = vec_to_sym(v) >>> torch.allclose(X, X_reconstructed) True