forte2.helpers.matrix_functions#

Module Contents#

forte2.helpers.matrix_functions.MACHEPS = 1e-14#
forte2.helpers.matrix_functions.invsqrt_matrix(M, tol=1e-07)#

Compute the inverse square root of a symmetric (Hermitian) matrix A. Small eigenvalues below ‘tol’ are treated as zero (pseudo-inverse style).

Parameters:
MNDArray

A symmetric matrix (must be positive semi-definite).

tolfloat, optional, default=1e-7

Eigenvalue threshold below which values are treated as zero.

Returns:
invsqrt_MNDArray

The inverse square root of A.

Raises:
ValueError

If the matrix M is not positive semi-definite.

forte2.helpers.matrix_functions.canonical_orth(S, tol=1e-07)#

Compute the canonical orthogonalization given the metric matrix S.

Parameters:
SNDArray

Metric matrix (must be positive semi-definite).

tolfloat, optional, default=1e-7

Eigenvalue threshold below which values are treated as zero.

Returns:
XNDArray

The (possibly rectangular) canonical orthogonalization matrix X, such that X.T @ S @ X = I.

Raises:
ValueError

If the matrix S is not positive semi-definite.

forte2.helpers.matrix_functions.eigh_gen(A, B=None, remove_lindep=True, orth_tol=1e-07, orth_method='canonical')#

Solve the generalized eigenvalue problem A @ x = lambda * B @ x.

Parameters:
ANDArray

The matrix A.

BNDArray

The matrix B. If None, the identity matrix is used.

remove_lindepbool, optional, default=True

If True, perform orthogonalization to remove linear dependencies, else use sp.linalg.eigh.

orth_tolfloat, optional, default=1e-7

Eigenvalue threshold below which values are treated as zero.

orth_methodstr, optional, default=”canonical”

Orthogonalization method. Options are “canonical” or “symmetric”. “canonical” should be used when there are linear dependencies in the basis functions.

Returns:
tuple(NDArray, NDArray)

A tuple containing the eigenvalues and eigenvectors.

forte2.helpers.matrix_functions.givens_rotation(A, c, s, i, j, column=True)#

Apply a Givens rotation to the matrix A.

Parameters:
ANDArray

The matrix to apply the rotation to.

cfloat

The cosine of the rotation angle.

sfloat

The sine of the rotation angle.

iint

The index of the first row/column to rotate.

jint

The index of the second row/column to rotate.

columnbool, optional, default=True

If True, apply the rotation to columns; if False, to rows.

Returns:
NDArray

The rotated matrix.

forte2.helpers.matrix_functions.cholesky_wrapper(M, tol)#

Perform a Cholesky decomposition with complete pivoting, works with any symmetric positive semi-definite matrix.

Parameters:
MNDArray

The matrix to decompose.

tolfloat

The tolerance for the decomposition.

Returns:
BNDArray

The Cholesky factor such that B.T @ B = M.

forte2.helpers.matrix_functions.block_diag_2x2(M, complex=True)#

Return a block-diagonal matrix with two copies of M on the diagonal. Note this is not a function to block-diagonalize a matrix.

Parameters:
MNDArray

The matrix to convert, shape (n, n).

complexbool, optional, default=True

If True, the output will be explicitly converted to complex type.

Returns:
NDArray

The block-diagonal matrix, shape (2n, 2n).