{ } Raw JSON

bundles / scipy 1.17.1 / scipy / linalg / _decomp_update / qr_update

function

scipy.linalg._decomp_update:qr_update

Signature

def   qr_update ( Q R u v overwrite_qruv = False check_finite = True )

Summary

Rank-k QR update

Extended Summary

If A = Q R is the QR factorization of A, return the QR factorization of A + u v**T for real A or A + u v**H for complex A.

The documentation is written assuming array arguments are of specified "core" shapes. However, array argument(s) of this function may have additional "batch" dimensions prepended to the core shape. In this case, the array is treated as a batch of lower-dimensional slices; see linalg_batch for details. Note that calls with zero-size batches are unsupported and will raise a ValueError.

Parameters

Q : (M, M) or (M, N) array_like

Unitary/orthogonal matrix from the qr decomposition of A.

R : (M, N) or (N, N) array_like

Upper triangular matrix from the qr decomposition of A.

u : (M,) or (M, k) array_like

Left update vector

v : (N,) or (N, k) array_like

Right update vector

overwrite_qruv : bool, optional

If True, consume Q, R, u, and v, if possible, while performing the update, otherwise make copies as necessary. Defaults to False.

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. Default is True.

Returns

Q1 : ndarray

Updated unitary/orthogonal factor

R1 : ndarray

Updated upper triangular factor

Notes

This routine does not guarantee that the diagonal entries of R1 are real or positive.

Examples

import numpy as np
from scipy import linalg
a = np.array([[  3.,  -2.,  -2.],
              [  6.,  -9.,  -3.],
              [ -3.,  10.,   1.],
              [  6.,  -7.,   4.],
              [  7.,   8.,  -6.]])
q, r = linalg.qr(a)
Given this q, r decomposition, perform a rank 1 update.
u = np.array([7., -2., 4., 3., 5.])
v = np.array([1., 3., -5.])
q_up, r_up = linalg.qr_update(q, r, u, v, False)
q_up
r_up
The update is equivalent, but faster than the following.
a_up = a + np.outer(u, v)
q_direct, r_direct = linalg.qr(a_up)
Check that we have equivalent results:
np.allclose(np.dot(q_up, r_up), a_up)
And the updated Q is still unitary:
np.allclose(np.dot(q_up.T, q_up), np.eye(5))
Updating economic (reduced, thin) decompositions is also possible:
qe, re = linalg.qr(a, mode='economic')
qe_up, re_up = linalg.qr_update(qe, re, u, v, False)
qe_up
re_up
np.allclose(np.dot(qe_up, re_up), a_up)
np.allclose(np.dot(qe_up.T, qe_up), np.eye(3))
Similarly to the above, perform a rank 2 update.
u2 = np.array([[ 7., -1,],
               [-2.,  4.],
               [ 4.,  2.],
               [ 3., -6.],
               [ 5.,  3.]])
v2 = np.array([[ 1., 2.],
               [ 3., 4.],
               [-5., 2]])
q_up2, r_up2 = linalg.qr_update(q, r, u2, v2, False)
q_up2
r_up2
This update is also a valid qr decomposition of ``A + U V**T``.
a_up2 = a + np.dot(u2, v2.T)
np.allclose(a_up2, np.dot(q_up2, r_up2))
np.allclose(np.dot(q_up2.T, q_up2), np.eye(5))

See also

qr
qr_delete
qr_insert
qr_multiply

Aliases

  • scipy.linalg.qr_update

Referenced by

This package