Skip to main content

cgs_impl

Function cgs_impl 

Source
pub fn cgs_impl<R, C>(
    client: &C,
    a: &CsrData<R>,
    b: &Tensor<R>,
    x0: Option<&Tensor<R>>,
    options: CgsOptions,
) -> Result<CgsResult<R>>
where R: Runtime<DType = DType>, R::Client: SparseOps<R>, C: SparseLinAlgAlgorithms<R> + SparseOps<R> + BinaryOps<R> + UnaryOps<R> + ReduceOps<R> + ScalarOps<R>,
Expand description

Generic preconditioned CGS implementation

Algorithm (Sonneveld):

x = x0, r = b - A*x, r_hat = r
rho = <r_hat, r>, u = r, p = r

for iter = 1, 2, ...:
    p_hat = M^-1 * p
    v = A * p_hat
    sigma = <r_hat, v>
    alpha = rho / sigma

    q = u - alpha * v
    u_plus_q = u + q
    uq_hat = M^-1 * u_plus_q
    x = x + alpha * uq_hat
    r = r - alpha * A * uq_hat

    if ||r|| < tol: return

    rho_new = <r_hat, r>
    beta = rho_new / rho
    u = r + beta * q
    p = u + beta * (q + beta * p)
    rho = rho_new