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.
dataset/ETHPy150Open scipy/scipy/scipy/optimize/_lsq/trf_linear.py/regularized_lsq_with_qr