qr_multiply#
- rlinalg.qr_multiply(a: numpy.typing.ArrayLike, c: numpy.typing.ArrayLike, mode: Literal['left', 'right'] = 'right', tol=1e-07, check_finite=True, overwrite_a=False, overwrite_c=False) QRMultiplyResult#
Calculate the QR decomposition and multiply Q with a matrix.
Calculate the decomposition
A[:, P] = Q Rwhere Q is unitary/orthogonal and R upper triangular. Multiply Q with a vector or a matrix c.- Parameters:
a ((M, N), array_like) – Input array
c (array_like) – Input array to be multiplied by
Q.mode ({'left', 'right'}, optional) –
Q @ cis returned if mode is ‘left’,c @ Qis returned if mode is ‘right’. The shape of c must be appropriate for the matrix multiplications, if mode is ‘left’,min(a.shape) == c.shape[0], if mode is ‘right’,a.shape[0] == c.shape[1].overwrite_a (bool, optional) – Whether data in a is overwritten (may improve performance)
check_finite (bool, optional) – Whether to check that the input matrix contains only finite numbers. Disabling may give a performance gain, but may result in problems (crashes, non-termination) if the inputs do contain infinities or NaNs.
tol (float) – The absolute tolerance to which each column norm is required. An column is considered negligible when its norm falls under this value.
- Returns:
CQ (ndarray) – The product of
Qandc.R ((K, N), ndarray) – R array of the resulting QR factorization where
K = min(M, N).P ((N,) ndarray) – Integer pivot array.
rank (int) – The rank of the matrix.
- Raises:
ValueError – When parameters are not compatible.
Notes
This is an interface to the R-modified LINPACK routine
dqrdc2anddqrsl.See also
NoneThe SciPy implementation based on LAPACK.
Examples
>>> import numpy as np >>> from rlinalg import qr, qr_multiply >>> A = np.array([[1, 3, 3], [2, 3, 2], [2, 3, 3], [1, 3, 2]]) >>> qc, r1, piv1, rank = qr_multiply(A, 2*np.eye(4)) >>> qc array([[-0.63245553, 1.26491106, -1. ], [-1.26491106, -0.63245553, 1. ], [-1.26491106, -0.63245553, -1. ], [-0.63245553, 1.26491106, 1. ]]) >>> r1 array([[-3.16227766, -5.69209979, -4.74341649], [ 0. , 1.8973666 , 1.58113883], [ 0. , 0. , -1. ]]) >>> piv1 array([0, 1, 2], dtype=int32) >>> q2, r2, piv2, rank = qr(A, mode='economic') >>> np.allclose(2*q2 - qc, np.zeros((4, 3))) True