Пример #1
0
static VALUE rb_gsl_blas_zaxpy2(int argc, VALUE *argv, VALUE obj)
{
  gsl_complex *a = NULL;
  gsl_vector_complex *x = NULL, *y = NULL, *y2 = NULL;
  switch (TYPE(obj)) {
  case T_MODULE:
  case T_CLASS:
  case T_OBJECT:
    get_vector_complex2(argc-1, argv+1, obj, &x, &y);
    CHECK_COMPLEX(argv[0]);
    Data_Get_Struct(argv[0], gsl_complex, a);
    break;
  default:
    Data_Get_Struct(obj, gsl_vector_complex, x);
    if (argc != 2) rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
			    argc);
    CHECK_COMPLEX(argv[0]);
    CHECK_VECTOR_COMPLEX(argv[1]);
    Data_Get_Struct(argv[0], gsl_complex, a);
    Data_Get_Struct(argv[1], gsl_vector_complex, y);
    break;
  }
  y2 = gsl_vector_complex_alloc(y->size);
  gsl_vector_complex_memcpy(y2, y);
  gsl_blas_zaxpy(*a, x, y2);
  return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, y2);
}
Пример #2
0
int
gsl_linalg_complex_LU_refine (const gsl_matrix_complex * A, const gsl_matrix_complex * LU, const gsl_permutation * p, const gsl_vector_complex * b, gsl_vector_complex * x, gsl_vector_complex * residual)
{
  if (A->size1 != A->size2)
    {
      GSL_ERROR ("matrix a must be square", GSL_ENOTSQR);
    }
  if (LU->size1 != LU->size2)
    {
      GSL_ERROR ("LU matrix must be square", GSL_ENOTSQR);
    }
  else if (A->size1 != LU->size2)
    {
      GSL_ERROR ("LU matrix must be decomposition of a", GSL_ENOTSQR);
    }
  else if (LU->size1 != p->size)
    {
      GSL_ERROR ("permutation length must match matrix size", GSL_EBADLEN);
    }
  else if (LU->size1 != b->size)
    {
      GSL_ERROR ("matrix size must match b size", GSL_EBADLEN);
    }
  else if (LU->size1 != x->size)
    {
      GSL_ERROR ("matrix size must match solution size", GSL_EBADLEN);
    }
  else if (singular (LU)) 
    {
      GSL_ERROR ("matrix is singular", GSL_EDOM);
    }
  else
    {
      int status;

      /* Compute residual, residual = (A * x  - b) */

      gsl_vector_complex_memcpy (residual, b);

      {
        gsl_complex one = GSL_COMPLEX_ONE;
        gsl_complex negone = GSL_COMPLEX_NEGONE;
        gsl_blas_zgemv (CblasNoTrans, one, A, x, negone, residual);
      }

      /* Find correction, delta = - (A^-1) * residual, and apply it */

      status = gsl_linalg_complex_LU_svx (LU, p, residual);

      {
        gsl_complex negone= GSL_COMPLEX_NEGONE;
        gsl_blas_zaxpy (negone, residual, x);
      }

      return status;
    }
}
Пример #3
0
 /** Subtraction operator (vector) */
 vector<complex> vector<complex>::operator-(const vector<complex>& v) const
 {
     vector<complex> v1(_vector);
     gsl_complex z1;
     GSL_SET_COMPLEX(&z1, -1., 0.);
     if (gsl_blas_zaxpy(z1, v.as_gsl_type_ptr(), v1.as_gsl_type_ptr())) {
         std::cout << "\n Error in vector<complex> -" << std::endl;
         exit(EXIT_FAILURE);
     }
     return v1;
 }
Пример #4
0
 /** Subtraction assignment (complex) */
 vector<complex> vector<complex>::operator-(const complex& z)
 {
     vector<complex> v1(_vector);
     gsl_complex z1;
     gsl_vector_complex *v2;
     GSL_SET_COMPLEX(&z1, -1., 0.);
     v2 = gsl_vector_complex_alloc(v1.size());
     gsl_vector_complex_set_all(v2, z1);
     if (gsl_blas_zaxpy(z, v2, v1.as_gsl_type_ptr())) {
         std::cout << "\n Error in vector<complex> - (double)" << std::endl;
         exit(EXIT_FAILURE);
     }
     gsl_vector_complex_free(v2);
     return v1;
 }
Пример #5
0
 /**
  * C++ version of gsl_blas_zaxpy().
  * @param alpha A constant
  * @param X A vector
  * @param Y A vector
  * @return Error code on failure
  */
 int zaxpy( complex const& alpha, vector_complex const& X, vector_complex& Y ){
   return gsl_blas_zaxpy( alpha.get(), X.get(), Y.get() ); }
Пример #6
0
int 
gsl_linalg_hermtd_decomp (gsl_matrix_complex * A, gsl_vector_complex * tau)  
{
  if (A->size1 != A->size2)
    {
      GSL_ERROR ("hermitian tridiagonal decomposition requires square matrix",
                 GSL_ENOTSQR);
    }
  else if (tau->size + 1 != A->size1)
    {
      GSL_ERROR ("size of tau must be (matrix size - 1)", GSL_EBADLEN);
    }
  else
    {
      const size_t N = A->size1;
      size_t i;
  
      const gsl_complex zero = gsl_complex_rect (0.0, 0.0);
      const gsl_complex one = gsl_complex_rect (1.0, 0.0);
      const gsl_complex neg_one = gsl_complex_rect (-1.0, 0.0);

      for (i = 0 ; i < N - 1; i++)
        {
          gsl_vector_complex_view c = gsl_matrix_complex_column (A, i);
          gsl_vector_complex_view v = gsl_vector_complex_subvector (&c.vector, i + 1, N - (i + 1));
          gsl_complex tau_i = gsl_linalg_complex_householder_transform (&v.vector);
          
          /* Apply the transformation H^T A H to the remaining columns */

          if ((i + 1) < (N - 1) 
              && !(GSL_REAL(tau_i) == 0.0 && GSL_IMAG(tau_i) == 0.0)) 
            {
              gsl_matrix_complex_view m = 
                gsl_matrix_complex_submatrix (A, i + 1, i + 1, 
                                              N - (i+1), N - (i+1));
              gsl_complex ei = gsl_vector_complex_get(&v.vector, 0);
              gsl_vector_complex_view x = gsl_vector_complex_subvector (tau, i, N-(i+1));
              gsl_vector_complex_set (&v.vector, 0, one);
              
              /* x = tau * A * v */
              gsl_blas_zhemv (CblasLower, tau_i, &m.matrix, &v.vector, zero, &x.vector);

              /* w = x - (1/2) tau * (x' * v) * v  */
              {
                gsl_complex xv, txv, alpha;
                gsl_blas_zdotc(&x.vector, &v.vector, &xv);
                txv = gsl_complex_mul(tau_i, xv);
                alpha = gsl_complex_mul_real(txv, -0.5);
                gsl_blas_zaxpy(alpha, &v.vector, &x.vector);
              }
              
              /* apply the transformation A = A - v w' - w v' */
              gsl_blas_zher2(CblasLower, neg_one, &v.vector, &x.vector, &m.matrix);

              gsl_vector_complex_set (&v.vector, 0, ei);
            }
          
          gsl_vector_complex_set (tau, i, tau_i);
        }
      
      return GSL_SUCCESS;
    }
}