Skip to content

qttools.kernels.linalg#

source package qttools.kernels.linalg

Functions

  • eig Computes the eigenvalues and eigenvectors of matrices on a given location.

  • inv Computes the (batched) inverse of a matrix.

  • svd Computes the singular value decomposition of a matrix on a given location.

  • eigvalsh Compute eigenvalues of a hermitain generalized eigenvalue problem.

  • qr Computes the QR decomposition of a batch of matrices.

source eig(A: NDArray | list[NDArray], compute_module: str = 'numpy', output_module: str | None = None, use_pinned_memory: bool = True)tuple[NDArray, NDArray] | tuple[list[NDArray], list[NDArray]]

Computes the eigenvalues and eigenvectors of matrices on a given location.

To compute the eigenvalues and eigenvectors on the device with cupy is only possible if the cupy.linalg.eig function is available.

A list of matrices is beneficial if not all the matrices have the same shape. Then the host numba implementation will still parallelize, but not the cupy implementation. Only over the list will be parallelized, further extra dimensions are not allowed.

Assumes that all the input matrices are at the same location.

Parameters

  • A : NDArray | list[NDArray] The matrices.

  • compute_module : str, optional The location where to compute the eigenvalues and eigenvectors. Can be either "numpy" or "cupy".

  • output_module : str, optional The location where to store the eigenvalues and eigenvectors. Can be either "numpy" or "cupy". If None, the output location is the same as the input location

  • use_pinned_memory : bool, optional Whether to use pinnend memory if cupy is used. Default is True.

Returns

  • NDArray | list[NDArray] The eigenvalues.

  • NDArray | list[NDArray] The eigenvectors.

Raises

  • ValueError

source inv(a: NDArray)NDArray

Computes the (batched) inverse of a matrix.

Parameters

  • a : NDArray The (batched) matrix.

Returns

  • NDArray The inverse (batched) of the matrix.

source svd(A: NDArray, full_matrices: bool = True, compute_module: str = 'numpy', output_module: str | None = None, use_pinned_memory: bool = True)tuple[NDArray, NDArray, NDArray]

Computes the singular value decomposition of a matrix on a given location.

The kwargs compute_uv and hermitian are not supported. They are implicitly set to True and False, respectively.

Parameters

  • A : NDArray The matrix.

  • full_matrices : bool, optional Whether to compute the full matrices u and vh (see numpy.linalg.svd).

  • compute_module : str, optional The location where to compute the singular value decomposition. Can be either "numpy" or "cupy".

  • output_module : str, optional The location where to store the singular value decomposition. Can be either "numpy" or "cupy". If None, the output location is the same as the input location

  • use_pinned_memory : bool, optional Whether to use pinnend memory if cupy is used. Default is True.

Returns

  • NDArray : NDArray The left singular vectors.

  • NDArray : NDArray The singular values.

  • NDArray : NDArray The right singular vectors.

Raises

  • ValueError

source eigvalsh(A: NDArray, B: NDArray | None = None, compute_module: str = 'cupy', output_module: str | None = None, use_pinned_memory: bool = True)NDArray

Compute eigenvalues of a hermitain generalized eigenvalue problem.

TODO: only type 1 generalized problems are supported, Only a subset of keywords of scipy.linalg.eigvalsh are supported.

Parameters

  • A : NDArray A complex or real symmetric or hermitian matrix.

  • B : NDArray, optional A complex or real symmetric or hermitian positive definite matrix. If omitted, identity matrix is assumed.

  • compute_module : str, optional The location where to compute the eigenvalues.

  • output_module : str, optional The location where to store the resulting eigenvalues.

  • use_pinned_memory : bool, optional Whether to use pinnend memory if cupy is used. Default is True.

Returns

  • NDArray The eigenvalues of the generalized eigenvalue problem.

Raises

  • ValueError

source qr(A: NDArray, compute_module: str = 'numpy', output_module: str | None = None, use_pinned_memory: bool = True)tuple[NDArray, NDArray]

Computes the QR decomposition of a batch of matrices.

If compute_module is "numpy", the computation is done with numpy and parallelized with numba. Only mode 'reduced' is supported due to numba limitations.

Parameters

  • A : NDArray The matrices.

  • compute_module : str, optional The location where to compute the QR decomposition. Can be either "numpy" or "cupy".

  • output_module : str, optional The location where to store the QR decomposition. Can be either "numpy" or "cupy". If None, the output location is the same as the input location

  • use_pinned_memory : bool, optional Whether to use pinnend memory if cupy is used. Default is True.

Returns

  • NDArray : NDArray Unitary matrix Q in the QR decomposition.

  • NDArray : NDArray Upper triangular matrix R in the QR decomposition.

Raises

  • ValueError