def lu_factor(A, rho):
r"""
Compute LU factorisation of either :math:`A^T A + \rho I` or
:math:`A A^T + \rho I`, depending on which matrix is smaller.
Parameters
----------
A : array_like
Array :math:`A`
rho : float
Scalar :math:`\rho`
Returns
-------
lu : ndarray
Matrix containing U in its upper triangle, and L in its lower triangle,
as returned by :func:`scipy.linalg.lu_factor`
piv : ndarray
Pivot indices representing the permutation matrix P, as returned by
:func:`scipy.linalg.lu_factor`
"""
N, M = A.shape
# If N < M it is cheaper to factorise A*A^T + rho*I and then use the
# matrix inversion lemma to compute the inverse of A^T*A + rho*I
if N >= M:
lu, piv = linalg.lu_factor(A.T.dot(A) + rho*np.identity(M,
dtype=A.dtype))
else:
lu, piv = linalg.lu_factor(A.dot(A.T) + rho*np.identity(N,
dtype=A.dtype))
return lu, piv
评论列表
文章目录