def regularized_lsq_with_qr(m, n, R, QTb, perm, diag, copy_R=True):
 if copy_R:
  R = R.copy()
 v = QTb.copy()
 givens_elimination(R, v, diag[perm])
 abs_diag_R = np.abs(np.diag(R))
 threshold = ((EPS * max(m, n)) * np.max(abs_diag_R))
 (nns,) = np.nonzero((abs_diag_R > threshold))
 R = R[np.ix_(nns, nns)]
 v = v[nns]
 x = np.zeros(n)
 x[perm[nns]] = solve_triangular(R, v)
 return x

def regularized_lsq_with_qr ( m , n , R , QTb , perm , diag , copy_R = True ) : if copy_R : R = R . copy ( ) v = QTb . copy ( ) givens_elimination ( R , v , diag [ perm ] ) abs_diag_R = np . abs ( np . diag ( R ) ) threshold = ( ( EPS * max ( m , n ) ) * np . max ( abs_diag_R ) ) ( nns , ) = np . nonzero ( ( abs_diag_R > threshold ) ) R = R [ np . ix_ ( nns , nns ) ] v = v [ nns ] x = np . zeros ( n ) x [ perm [ nns ] ] = solve_triangular ( R , v ) return x
solve regularized least squares using information from qr-decomposition .