def regularized_lsq_operator(J, diag):
    J = aslinearoperator(J)
    m, n = J.shape

    def matvec(x):
        return np.hstack((J.matvec(x), diag * x))

    def rmatvec(x):
        x1 = x[:m]
        x2 = x[m:]
        return J.rmatvec(x1) + diag * x2

    return LinearOperator((m + n, n), matvec=matvec, rmatvec=rmatvec)
Return a matrix arising in regularized least squares as LinearOperator.
dataset/ETHPy150Open scipy/scipy/scipy/optimize/_lsq/common.py/regularized_lsq_operator