Ejemplo n.º 1
0
static VALUE rb_gsl_linalg_cholesky_solve(int argc, VALUE *argv, VALUE obj)
{
  gsl_matrix_complex *A = NULL, *Atmp = NULL;
  gsl_vector_complex *b = NULL, *x = NULL;
  int flagb = 0, flaga = 0;
  VALUE vA, vb;
  switch(TYPE(obj)) {
  case T_MODULE:  case T_CLASS:  case T_OBJECT:
    if (argc != 2) rb_raise(rb_eArgError, "wrong number of argument (%d for 2)",
			    argc);
    vA = argv[0];
    vb = argv[1];
    break;
  default:
    if (argc != 1) rb_raise(rb_eArgError, "wrong number of argument (%d for 1)",
			    argc);
    vA = obj;
    vb = argv[0];
    break;
  }
  CHECK_MATRIX_COMPLEX(vA);
  Data_Get_Struct(vA, gsl_matrix_complex, Atmp);
  CHECK_VECTOR_COMPLEX(vb);
  Data_Get_Struct(vb, gsl_vector_complex, b);

  if (CLASS_OF(vA) == cgsl_matrix_complex_C) {
    A = Atmp;
  } else {
    A = make_matrix_complex_clone(Atmp);
    flaga = 1;
    gsl_linalg_complex_cholesky_decomp(A);
  }
  x = gsl_vector_complex_alloc(b->size);
  gsl_linalg_complex_cholesky_solve(A, b, x);
  if (flaga == 1) gsl_matrix_complex_free(A);
  if (flagb == 1) gsl_vector_complex_free(b);
  return Data_Wrap_Struct(cgsl_vector_complex_col, 0, gsl_vector_complex_free, x);
}
Ejemplo n.º 2
0
    /**
     * C++ version of gsl_linalg_complex_cholesky_solve().
     * @param cholesky A Cholesky decomposition matrix
     * @param b A vector
     * @param x A vector
     * @return Error code on failure
     */
    inline int complex_cholesky_solve( matrix_complex const& cholesky, vector_complex const& b,
				       vector_complex& x ){
      return gsl_linalg_complex_cholesky_solve( cholesky.get(), b.get(), x.get() ); }