Class: Numo::GSL::SpLinalg::IterSolve

Inherits:
Object
  • Object
show all
Defined in:
ext/numo/gsl/spmatrix/gsl_spmatrix.c

Direct Known Subclasses

Gmres

Defined Under Namespace

Classes: Gmres

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.iterate(a, b, tol, x) ⇒ Integer

This function performs one iteration of the iterative method for the sparse linear system specfied by the matrix A, right hand side vector b and solution vector x. On input, x must be set to an initial guess for the solution. On output, x is updated to give the current solution estimate. The parameter tol specifies the relative tolerance between the residual norm and norm of b in order to check for convergence. When the following condition is satisfied: || A x - b || <= tol * || b || the method has converged, the function returns GSL_SUCCESS and the final solution is provided in x. Otherwise, the function returns GSL_CONTINUE to signal that more iterations are required. Here, || \cdot || represents the Euclidean norm. The input matrix A may be in triplet or compressed column format.

Parameters:

  • a (Numo::GSL::SpMatrix)

    (input sparse matrix)

  • b (Numo::DFloat)

    (input vector)

  • tol (Float)
  • x (Numo::DFloat)
    (input output vector)

Returns:

  • (Integer)

    returns GSL::CONTINUE=-2 to signal that more iterations are required.



804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
# File 'ext/numo/gsl/spmatrix/gsl_spmatrix.c', line 804

static VALUE
splinalg_itersolve_s_iterate(VALUE self, VALUE vA, VALUE vb, VALUE vtol, VALUE vx)
{
    gsl_spmatrix *A;
    gsl_vector *b, *x;
    double tol;
    gsl_splinalg_itersolve *w;
    narray_t *na;
    int status;

    TypedData_Get_Struct(self, gsl_splinalg_itersolve, &splinalg_itersolve_data_type, w);

    TypedData_Get_Struct(vA, gsl_spmatrix, &spmatrix_data_type, A);

    vb = cast_1d_contiguous(vb, cDF);
    ALLOCA_GSL_VECTOR_FROM_NARRAY_R(vb, b);
    tol = NUM2DBL(vtol);

    if (CLASS_OF(vx) != cDF) {
        rb_raise(rb_eTypeError, "x should be Numo::DFloat");
    }
    GetNArray(vx,na);
    if (NA_NDIM(na) != 1) {
        rb_raise(nary_eShapeError, "x should be 1-dimensional array");
    }
    if (!RTEST(na_check_contiguous(vx))) {
        rb_raise(nary_eOperationError, "x should be contiguous array");
    }
    ALLOCA_GSL_VECTOR_FROM_NARRAY_RW(vx, x);

    status = gsl_splinalg_itersolve_iterate(A, b, tol, x, w);
    RB_GC_GUARD(vb);
    return INT2FIX(status);
}

Instance Method Details

#nameString

This function returns a string pointer to the name of the solver.

Returns:

  • (String)


767
768
769
770
771
772
773
774
775
# File 'ext/numo/gsl/spmatrix/gsl_spmatrix.c', line 767

static VALUE
splinalg_itersolve_name(VALUE self)
{
    gsl_splinalg_itersolve *w;

    TypedData_Get_Struct(self, gsl_splinalg_itersolve, &splinalg_itersolve_data_type, w);

    return rb_str_new_cstr(gsl_splinalg_itersolve_name(w));
}

#normrFloat

This function returns the current residual norm ||r|| = ||A x - b||, which is updated after each call to gsl_splinalg_itersolve_iterate.

Returns:

  • (Float)


849
850
851
852
853
854
855
856
857
# File 'ext/numo/gsl/spmatrix/gsl_spmatrix.c', line 849

static VALUE
splinalg_itersolve_normr(VALUE self)
{
    gsl_splinalg_itersolve *w;

    TypedData_Get_Struct(self, gsl_splinalg_itersolve, &splinalg_itersolve_data_type, w);

    return DBL2NUM(gsl_splinalg_itersolve_normr(w));
}