def _solve(self, b, tol):
    A = self._A
    M = self._M
    tol *= dasum(b)
    x = zeros(b.shape)
    r = b.copy()
    z = M(r)
    rz = ddot(r, z)
    p = z.copy()
    while True:
        Ap = A(p)
        alpha = (rz / ddot(p, Ap))
        x = daxpy(p, x, a=alpha)
        r = daxpy(Ap, r, a=(- alpha))
        if (dasum(r) < tol):
            return x
        z = M(r)
        beta = ddot(r, z)
        (beta, rz) = ((beta / rz), beta)
        p = daxpy(p, z, a=beta)
def _solve(self, b, tol):
    A = self._A
    M = self._M
    tol *= dasum(b)
    x = zeros(b.shape)
    r = b.copy()
    z = M(r)
    rz = ddot(r, z)
    p = z.copy()
    while True:
        Ap = A(p)
        alpha = (rz / ddot(p, Ap))
        x = daxpy(p, x, a=alpha)
        r = daxpy(Ap, r, a=(- alpha))
        if (dasum(r) < tol):
            return x
        z = M(r)
        beta = ddot(r, z)
        (beta, rz) = ((beta / rz), beta)
        p = daxpy(p, z, a=beta)