コード例 #1
0
ファイル: test.c プロジェクト: lemahdi/mglib
test_eigen_gen_workspace *
test_eigen_gen_alloc(const size_t n)
{
  test_eigen_gen_workspace *w;

  w = (test_eigen_gen_workspace *) calloc(1, sizeof(test_eigen_gen_workspace));

  w->A = gsl_matrix_alloc(n, n);
  w->B = gsl_matrix_alloc(n, n);
  w->alpha = gsl_vector_complex_alloc(n);
  w->beta = gsl_vector_alloc(n);
  w->alphav = gsl_vector_complex_alloc(n);
  w->betav = gsl_vector_alloc(n);
  w->eval = gsl_vector_complex_alloc(n);
  w->evalv = gsl_vector_complex_alloc(n);
  w->x = gsl_vector_alloc(n);
  w->y = gsl_vector_alloc(n);
  w->Q = gsl_matrix_alloc(n, n);
  w->Z = gsl_matrix_alloc(n, n);
  w->evec = gsl_matrix_complex_alloc(n, n);
  w->gen_p = gsl_eigen_gen_alloc(n);
  w->genv_p = gsl_eigen_genv_alloc(n);

  return (w);
} /* test_eigen_gen_alloc() */
コード例 #2
0
ファイル: fbfoptics.c プロジェクト: jonbramble/FBF-Optics
void expm(gsl_matrix_complex * L, gsl_complex t, gsl_matrix * m)
     {
    int i,j,s;
	gsl_vector_complex *eval = gsl_vector_complex_alloc(4);
	gsl_matrix_complex *evec = gsl_matrix_complex_alloc(4, 4);
	gsl_eigen_nonsymmv_workspace * w = gsl_eigen_nonsymmv_alloc(4);
	gsl_matrix_complex *evalmat = gsl_matrix_complex_alloc(4, 4);
	gsl_matrix_complex *vd = gsl_matrix_complex_alloc(4, 4);
	gsl_complex one = gsl_complex_rect(1, 0);
	gsl_complex zero = gsl_complex_rect(0, 0);

	gsl_matrix_complex *K = gsl_matrix_complex_alloc(4, 4);
	gsl_permutation *p = gsl_permutation_alloc(4);
	gsl_vector_complex *x = gsl_vector_complex_alloc(4);

	gsl_vector_complex_view bp;
	gsl_complex z;

	gsl_eigen_nonsymmv(m, eval, evec, w);
	gsl_eigen_nonsymmv_sort(eval, evec, GSL_EIGEN_SORT_ABS_DESC);

	gsl_eigen_nonsymmv_free(w); // clear workspace

	for (i = 0; i < 4; i++)
	{
		gsl_complex eval_i = gsl_vector_complex_get(eval, i);
		gsl_complex expeval = gsl_complex_mul(eval_i,t);
		expeval = gsl_complex_exp(expeval);
		gsl_matrix_complex_set(evalmat, i, i, expeval);
	}

	gsl_vector_complex_free(eval); // clear vector for eigenvalues

	// v'L'=De'v'
	gsl_blas_zgemm(CblasTrans, CblasTrans, one, evalmat, evec, zero, vd);
	gsl_matrix_complex_transpose(evec);//transpose v

	gsl_matrix_complex_memcpy(K,evec);

	for (i = 0; i < 4; i++)
	{
		bp = gsl_matrix_complex_column(vd, i);
		gsl_linalg_complex_LU_decomp(evec, p, &s);
		gsl_linalg_complex_LU_solve(evec, p, &bp.vector, x);
			for (j = 0; j < 4; j++)
			{
				z = gsl_vector_complex_get(x, j);
				gsl_matrix_complex_set(L,i,j,z); //'through the looking glass' transpose
			}
		gsl_matrix_complex_memcpy(evec,K);
	}


	gsl_permutation_free(p);
	gsl_vector_complex_free(x);
	gsl_matrix_complex_free(vd);
	gsl_matrix_complex_free(evec);
	gsl_matrix_complex_free(evalmat);
	gsl_matrix_complex_free(K);
}
コード例 #3
0
ファイル: qmatrix.c プロジェクト: usqcd-software/qlua
static int
mc_qr(lua_State *L)                                            /* (-1,+2,e) */
{
    mMatComplex *m = qlua_checkMatComplex(L, 1);
    mMatComplex *qr = qlua_newMatComplex(L, m->l_size, m->r_size);
    mMatComplex *q = qlua_newMatComplex(L, m->l_size, m->l_size);
    mMatComplex *r = qlua_newMatComplex(L, m->l_size, m->r_size);
    int nm = m->l_size < m->r_size? m->l_size: m->r_size;
    gsl_vector_complex *tau;

    gsl_matrix_complex_memcpy(qr->m, m->m);
    tau = gsl_vector_complex_alloc(nm);
    if (tau == 0) {
        lua_gc(L, LUA_GCCOLLECT, 0);
        tau = gsl_vector_complex_alloc(nm);
        if (tau == 0)
            luaL_error(L, "not enough memory");
    }
    if (gsl_linalg_complex_QR_decomp(qr->m, tau))
        luaL_error(L, "matrix:qr() failed");
    
    if (gsl_linalg_complex_QR_unpack(qr->m, tau, q->m, r->m))
        luaL_error(L, "matrix:qr() failed");
    gsl_vector_complex_free(tau);
    
    return 2;
}
コード例 #4
0
ファイル: testgen2.c プロジェクト: BrianGladman/gsl
gen_workspace *
gen_alloc(size_t n, int compute_schur)
{
  gen_workspace *w;

  w = (gen_workspace *) calloc(1, sizeof(gen_workspace));

  w->gen_p = gsl_eigen_gen_alloc(n);

  w->A = gsl_matrix_alloc(n, n);
  w->B = gsl_matrix_alloc(n, n);
  w->alpha = gsl_vector_complex_alloc(n);
  w->beta = gsl_vector_alloc(n);
  w->evals = gsl_vector_complex_alloc(n);
  w->compute_schur = compute_schur;

  if (compute_schur)
    {
      w->Q = gsl_matrix_alloc(n, n);
      w->Z = gsl_matrix_alloc(n, n);
      gsl_eigen_gen_params(1, 1, 0, w->gen_p);
    }

  return (w);
} /* gen_alloc() */
コード例 #5
0
ファイル: lls_complex.c プロジェクト: pa345/lib
lls_complex_workspace *
lls_complex_alloc(const size_t max_block, const size_t p)
{
  const gsl_multifit_robust_type *robust_t = gsl_multifit_robust_huber;
  const size_t nblock = GSL_MAX(max_block, p);
  lls_complex_workspace *w;

  w = calloc(1, sizeof(lls_complex_workspace));
  if (!w)
    return 0;

  w->AHA = gsl_matrix_complex_alloc(p, p);
  w->work_A = gsl_matrix_complex_alloc(p, p);
  if (!w->AHA || !w->work_A)
    {
      lls_complex_free(w);
      return 0;
    }

  w->AHb = gsl_vector_complex_alloc(p);
  w->work_b = gsl_vector_complex_alloc(p);
  w->AF = gsl_matrix_complex_alloc(p, p);
  w->S = gsl_vector_alloc(p);
  if (!w->AHb || !w->work_b)
    {
      lls_complex_free(w);
      return 0;
    }

  w->r_complex = gsl_vector_complex_alloc(nblock);
  w->c = gsl_vector_complex_alloc(p);
  w->r = gsl_vector_alloc(nblock);
  w->w_robust = gsl_vector_alloc(nblock);
  w->robust_workspace_p = gsl_multifit_robust_alloc(robust_t, nblock, p);
  if (!w->r_complex || !w->w_robust || !w->c)
    {
      lls_complex_free(w);
      return 0;
    }

  w->eigen_p = gsl_eigen_herm_alloc(p);
  w->eval = gsl_vector_alloc(p);

  w->p = p;
  w->max_block = nblock;

  w->residual = 0.0;
  w->chisq = 0.0;
  w->cond = -1.0;
  w->niter = 0;
  w->bHb = 0.0;

  /* initialize matrices/vectors to 0 */
  lls_complex_reset(w);

  return w;
} /* lls_complex_alloc() */
コード例 #6
0
ファイル: testgen2.c プロジェクト: BrianGladman/gsl
lapack_workspace *
lapack_alloc(const size_t n)
{
  lapack_workspace *w;
  double work[1];

  w = (lapack_workspace *) calloc(1, sizeof(lapack_workspace));

  w->A = gsl_matrix_alloc(n, n);
  w->B = gsl_matrix_alloc(n, n);
  w->Q = gsl_matrix_alloc(n, n);
  w->Z = gsl_matrix_alloc(n, n);
  w->alphar = malloc(n * sizeof(double));
  w->alphai = malloc(n * sizeof(double));
  w->beta = gsl_vector_alloc(n);
  w->alpha = gsl_vector_complex_alloc(n);
  w->evals = gsl_vector_complex_alloc(n);

  w->N = (int) n;
  w->n_evals = 0;

  w->jobvsl = 'N';
  w->jobvsr = 'N';
  w->sort = 'N';
  w->info = 0;

  w->lwork = -1;
  dgges_(&w->jobvsl,
         &w->jobvsr,
         &w->sort,
         (int *) 0,
         &w->N,
         w->A->data,
         (int *) &w->A->tda,
         w->B->data,
         (int *) &w->B->tda,
         &w->sdim,
         w->alphar,
         w->alphai,
         w->beta->data,
         w->Q->data,
         (int *) &w->Q->tda,
         w->Z->data,
         (int *) &w->Z->tda,
         work,
         &w->lwork,
         (int *) 0,
         &w->info);

  w->lwork = (int) work[0];
  w->work = malloc(w->lwork * sizeof(double));

  return (w);
} /* lapack_alloc() */
コード例 #7
0
ファイル: test.c プロジェクト: lemahdi/mglib
void
test_eigen_genherm_results (const gsl_matrix_complex * A, 
                            const gsl_matrix_complex * B,
                            const gsl_vector * eval, 
                            const gsl_matrix_complex * evec, 
                            size_t count,
                            const char * desc,
                            const char * desc2)
{
  const size_t N = A->size1;
  size_t i, j;

  gsl_vector_complex * x = gsl_vector_complex_alloc(N);
  gsl_vector_complex * y = gsl_vector_complex_alloc(N);

  /* check A v = lambda B v */
  for (i = 0; i < N; i++)
    {
      double ei = gsl_vector_get (eval, i);
      gsl_vector_complex_const_view vi =
        gsl_matrix_complex_const_column(evec, i);
      double norm = gsl_blas_dznrm2(&vi.vector);

      /* check that eigenvector is normalized */
      gsl_test_rel(norm, 1.0, N * GSL_DBL_EPSILON,
                   "genherm(N=%u,cnt=%u), %s, normalized(%d), %s", N, count,
                   desc, i, desc2);

      /* compute y = A z */
      gsl_blas_zgemv (CblasNoTrans, GSL_COMPLEX_ONE, A, &vi.vector, GSL_COMPLEX_ZERO, y);

      /* compute x = B z */
      gsl_blas_zgemv (CblasNoTrans, GSL_COMPLEX_ONE, B, &vi.vector, GSL_COMPLEX_ZERO, x);

      /* compute x = lambda B z */
      gsl_blas_zdscal(ei, x);

      /* now test if y = x */
      for (j = 0; j < N; j++)
        {
          gsl_complex xj = gsl_vector_complex_get (x, j);
          gsl_complex yj = gsl_vector_complex_get (y, j);

          gsl_test_rel(GSL_REAL(yj), GSL_REAL(xj), 1e9 * GSL_DBL_EPSILON, 
                       "genherm(N=%u,cnt=%u), %s, eigenvalue(%d,%d), real, %s", N, count, desc, i, j, desc2);
          gsl_test_abs(GSL_IMAG(yj), GSL_IMAG(xj), 1e9 * GSL_DBL_EPSILON, 
                       "genherm(N=%u,cnt=%u), %s, eigenvalue(%d,%d), imag, %s", N, count, desc, i, j, desc2);
        }
    }

  gsl_vector_complex_free(x);
  gsl_vector_complex_free(y);
}
コード例 #8
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);
}
コード例 #9
0
ファイル: math.c プロジェクト: blackwinter/rb-gsl
VALUE rb_gsl_math_complex_eval(gsl_complex (*func)(gsl_complex), VALUE obj)
{
  gsl_complex *z, *znew;
  gsl_vector_complex *v, *vnew;
  gsl_matrix_complex *m, *mnew;
  size_t i, j;
  if (COMPLEX_P(obj)) {
    Data_Get_Struct(obj, gsl_complex, z);
    znew = xmalloc(sizeof(gsl_complex));
    *znew = (*func)(*z);
    return Data_Wrap_Struct(cgsl_complex, 0, free, znew);
  } else if (VECTOR_COMPLEX_P(obj)) {
    Data_Get_Struct(obj, gsl_vector_complex, v);
    vnew = gsl_vector_complex_alloc(v->size);
    for (i = 0; i < v->size; i++) {
      z = GSL_COMPLEX_AT(v, i);
      gsl_vector_complex_set(vnew, i, (*func)(*z));
    }
    return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, vnew);
  } else if (MATRIX_COMPLEX_P(obj)) {
    Data_Get_Struct(obj, gsl_matrix_complex, m);
    mnew = gsl_matrix_complex_alloc(m->size1, m->size2);
    for (i = 0; i < m->size1; i++) {
      for (j = 0; j < m->size2; j++) {
        gsl_matrix_complex_set(mnew, i, j, (*func)(gsl_matrix_complex_get(m, i, j)));
      }
    }
    return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, mnew);
  } else {
    rb_raise(rb_eTypeError,
             "wrong argument type %s "
             " (GSL::Complex or GSL::Vector::Complex expected)",
             rb_class2name(CLASS_OF(obj)));
  }
}
コード例 #10
0
ファイル: Vector_complex.c プロジェクト: codahale/ruby-gsl
static VALUE Vector_complex_new(VALUE klass, VALUE arg) {
  gsl_vector_complex * v = NULL;
  size_t i, n, dim;
  switch (TYPE(arg)) {
    case T_FIXNUM:
    case T_BIGNUM:
      dim = NUM2INT(arg);
      v = gsl_vector_complex_calloc(dim);
      break;
    case T_ARRAY:
      n = RARRAY(arg)->len;
      dim = n/2;
      v = gsl_vector_complex_alloc(dim);
      for (i = 0; i < dim; i++){
        double d0, d1;
        gsl_complex z;
        d0 = NUM2DBL(rb_ary_entry(arg, 2*i));
        d1 = NUM2DBL(rb_ary_entry(arg, 2*i+1));
        GSL_SET_COMPLEX(&z, d0, d1);
        gsl_vector_complex_set(v, i, z);
      }
      break;
    default:
      rb_raise(rb_eArgError, "Illegal argument for constructor");
  }

  return Data_Wrap_Struct(klass, 0, gsl_vector_complex_free, v);
}
コード例 #11
0
void eigen_setIM(double partial[EdgeN],struct RootSet RS[SampleN][MultiRootN],double point,long unsigned int sam,long unsigned int samwork,int rn, int realInterval, int imageInterval){

	double kappa;
	double data[EdgeN];
	int i;

	kappa = EIGENVALUESCAN_MINKAPPA * pow(EIGENVALUESCAN_MAXKAPPA/EIGENVALUESCAN_MINKAPPA, point);
	for (i=0;i<EdgeN;i++){
		data[i]=partial[i];
		if( (int)i/NodeN == i%NodeN ) data[i]-=kappa*Sample[sam].D[(int)i/NodeN];
	}

	gsl_matrix_view m;
	gsl_vector_complex * eval;
	gsl_eigen_nonsymm_workspace * w;

	m = gsl_matrix_view_array (data, NodeN, NodeN);
    eval = gsl_vector_complex_alloc (NodeN);
    w = gsl_eigen_nonsymm_alloc (NodeN);
   	gsl_eigen_nonsymm (&m.matrix, eval, w);

	for ( i = 0; i < NodeN; i ++ )
	{
		RS[samwork][rn].RE[realInterval].IM[imageInterval].eigenIM[i][0]=GSL_REAL( gsl_vector_complex_get( eval, i ));
		RS[samwork][rn].RE[realInterval].IM[imageInterval].eigenIM[i][1]=GSL_IMAG( gsl_vector_complex_get( eval, i ));
	}
	gsl_vector_complex_free(eval);
	gsl_eigen_nonsymm_free (w);

}
コード例 #12
0
ファイル: fft.c プロジェクト: james-barnard/gsl
static VALUE rb_fft_complex_trans(int argc, VALUE *argv, VALUE obj,
				  int (*transform)(gsl_complex_packed_array, 
						   size_t, size_t, 
						   const gsl_fft_complex_wavetable *,
						   gsl_fft_complex_workspace *),
				  int sss)
{
  int flag = 0;
  // local variable "status" was defined and set, but never used
  //int status;
  size_t stride, n;
  gsl_complex_packed_array data;
  gsl_vector_complex *vin, *vout;
  gsl_fft_complex_wavetable *table = NULL;
  gsl_fft_complex_workspace *space = NULL;
  flag = gsl_fft_get_argv_complex(argc, argv, obj, &vin, &data, &stride, &n, &table, &space);
  if (sss == RB_GSL_FFT_COPY) {
    vout = gsl_vector_complex_alloc(n);
    gsl_vector_complex_memcpy(vout, vin);
    /*status =*/ (*transform)(vout->data, vout->stride /*1*/, vout->size /*n*/, table, space);
    gsl_fft_free(flag, (GSL_FFT_Wavetable *) table, (GSL_FFT_Workspace *) space);
    return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, vout);
  } else {    /* in-place */
    /*status =*/ (*transform)(data, stride, n, table, space);
    gsl_fft_free(flag, (GSL_FFT_Wavetable *) table, (GSL_FFT_Workspace *) space);
    return obj;
  }
}
コード例 #13
0
ファイル: class_spinor.cpp プロジェクト: gintrona/SpinorClass
//CONSTRUCTORS
//by default
complex_spinor::complex_spinor(){

	this->_numSites = 1;
	this->dimension = 2;
	this->priv_pVector = gsl_vector_complex_alloc(dimension);

}
コード例 #14
0
ファイル: linal.c プロジェクト: kcoltin/blackjack
//-----------------------------------------------------------------------------
// Returns the eigendecomposition A = X*D*X^-1. 
// d is the diagonal entries of D. 
// X and d must be preallocated: X should be n x n and d should be length n. 
//-----------------------------------------------------------------------------
void eigendecomp (double **A, double complex **X, double complex *d, int n)
{
	double *a; 
	double complex **Xtmp; 
	double complex *dtmp; 
	gsl_matrix_view m; 
	gsl_vector_complex *eval; 
	gsl_matrix_complex *evec; 
	gsl_eigen_nonsymmv_workspace *w; 

	// Use GSL routine to compute eigenvalues and eigenvectors 
	a = matrixToVector (A, n, n); 
	m = gsl_matrix_view_array (a, n, n); 
	eval = gsl_vector_complex_alloc (n); 
	evec = gsl_matrix_complex_alloc (n, n); 
	w = gsl_eigen_nonsymmv_alloc (n); 

	gsl_eigen_nonsymmv (&m.matrix, eval, evec, w); 
	gsl_eigen_nonsymmv_free (w); 

	// Convert from GSL to intrinsic types 
	Xtmp = gslmToCx (evec, n, n); 
	dtmp = gslvToCx (eval, n); 

	copycm_inplace (X, Xtmp, n, n); 
	copycv_inplace (d, dtmp, n); 

	freecmatrix(Xtmp, n); 
	free(a);
	free(dtmp); 
	gsl_vector_complex_free(eval); 
	gsl_matrix_complex_free(evec); 
}
コード例 #15
0
ファイル: class_spinor.cpp プロジェクト: gintrona/SpinorClass
//with number of sites
complex_spinor::complex_spinor(const int & numSites){

	this->priv_pVector = gsl_vector_complex_alloc(2*numSites);
	this->_numSites = numSites;
	this->dimension = 2*numSites;

}		
コード例 #16
0
static VALUE rb_gsl_blas_zscal2(int argc, VALUE *argv, VALUE obj)
{
  gsl_complex *a = NULL;
  gsl_vector_complex *x = NULL, *xnew = NULL;
  CHECK_COMPLEX(argv[0]);
  switch (TYPE(obj)) {
  case T_MODULE:
  case T_CLASS:
  case T_OBJECT:
    if (argc != 2) rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
			    argc);
    CHECK_VECTOR_COMPLEX(argv[1]);
    Data_Get_Struct(argv[0], gsl_complex, a);
    Data_Get_Struct(argv[1], gsl_vector_complex, x);
    break;
  default:
    if (argc != 1) rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)",
			    argc);
    Data_Get_Struct(obj, gsl_vector_complex, x);
    Data_Get_Struct(argv[0], gsl_complex, a);
    break;
  }
  xnew = gsl_vector_complex_alloc(x->size);
  gsl_vector_complex_memcpy(xnew, x);
  gsl_blas_zscal(*a, xnew);
  return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, xnew);
}
コード例 #17
0
ファイル: linalg_complex.c プロジェクト: jakobjanot/rb-gsl
static VALUE rb_gsl_linalg_complex_LU_refine(VALUE obj, VALUE vm,
					     VALUE lu, VALUE pp, VALUE bb,
					     VALUE xx)
{
  gsl_matrix_complex *m = NULL, *mlu = NULL;
  gsl_permutation *p = NULL;
  gsl_vector_complex *b = NULL, *x = NULL, *r = NULL;
  int flagb = 0;
  VALUE vr;

  if (CLASS_OF(obj) != cgsl_matrix_complex_LU)
    rb_raise(rb_eRuntimeError, "Decompose first!");
  CHECK_MATRIX_COMPLEX(vm);
  CHECK_MATRIX_COMPLEX(lu);
  CHECK_PERMUTATION(pp);
  CHECK_VECTOR_COMPLEX(xx);
  Data_Get_Struct(vm, gsl_matrix_complex, m);
  Data_Get_Struct(lu, gsl_matrix_complex, mlu);
  Data_Get_Struct(pp, gsl_permutation, p);
  CHECK_VECTOR_COMPLEX(bb);
  Data_Get_Struct(bb, gsl_vector_complex, b);
  Data_Get_Struct(xx, gsl_vector_complex, x);
  r = gsl_vector_complex_alloc(m->size1);
  gsl_linalg_complex_LU_refine(m, mlu, p, b, x, r);
  vr = Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, r);
  if (flagb == 1) gsl_vector_complex_free(b);
  return rb_ary_new3(2, xx, vr);
}
コード例 #18
0
 vector<complex>::vector(const vector<double>& v)
 {
     size_t i, n;
     n = v.size();
     _vector = gsl_vector_complex_alloc(n);
     for (i = 0; i < n; i++)
         gsl_vector_complex_set(_vector, i, v(i) + 0. * complex::i());
 }
コード例 #19
0
ファイル: class_spinor.cpp プロジェクト: gintrona/SpinorClass
// a simple spinor with two components
complex_spinor::complex_spinor(const gsl_complex & component_UP, const gsl_complex & component_DOWN){

	this->priv_pVector = gsl_vector_complex_alloc(2);
	this->dimension = 2;
	this->_numSites = 1;
	this->complex_spinor_set(UP, component_UP );
	this->complex_spinor_set(DOWN, component_DOWN );
}
コード例 #20
0
ファイル: class_spinor.cpp プロジェクト: gintrona/SpinorClass
//copy
complex_spinor::complex_spinor(const complex_spinor & another){
	
	this->_numSites = another._numSites;
	this->dimension = another.dimension;
	this->priv_pVector = gsl_vector_complex_alloc(this->dimension);
	gsl_vector_complex_memcpy(this->priv_pVector, another.priv_pVector);

}
コード例 #21
0
ファイル: Vector_complex.c プロジェクト: codahale/ruby-gsl
static VALUE Vector_complex_set_basis2(VALUE obj, VALUE ii) {
  gsl_vector_complex * v, * w;

  Data_Get_Struct(obj, gsl_vector_complex, v);
  w = gsl_vector_complex_alloc(v->size);

  gsl_vector_complex_set_basis(w, NUM2INT(ii));

  return Data_Wrap_Struct(rbgsl_cVector_complex, 0, gsl_vector_complex_free, w);
}
コード例 #22
0
ファイル: vectorc.cpp プロジェクト: jon2718/LinAO
vectorc::vectorc(const double values[], const int size) : size_m(size), v_m(gsl_vector_complex_alloc(size))

{
	gsl_complex z;
	for (int i=0; i<size_m; i++)
	{
		GSL_SET_COMPLEX(&z, values[2*i], values[2*i+1]);
		gsl_vector_complex_set(v_m, i, z);
	}	
}
コード例 #23
0
ファイル: sort.c プロジェクト: rbalint/rb-gsl
static VALUE rb_gsl_heapsort_vector_complex2(VALUE obj)
{
  gsl_vector_complex *v = NULL, *vnew = NULL;
  if (!rb_block_given_p()) rb_raise(rb_eRuntimeError, "Proc is not given");
  Data_Get_Struct(obj, gsl_vector_complex, v);
  vnew = gsl_vector_complex_alloc(v->size);
  gsl_vector_complex_memcpy(vnew, v);
  gsl_heapsort(vnew->data, vnew->size, sizeof(gsl_complex), rb_gsl_comparison_complex);
  return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, vnew);
}
コード例 #24
0
ファイル: vectorc.cpp プロジェクト: jon2718/LinAO
vectorc vectorc::operator=(const vectorc& vec)
{
	if (this==&vec)
		return *this;
	gsl_vector_complex_free (v_m);
	size_m=vec.size_m;
	v_m=gsl_vector_complex_alloc(size_m);
	for (int i=0; i<size_m; i++)
		gsl_vector_complex_set(v_m, i, gsl_vector_complex_get(vec.v_m, i));
	return *this;
}
コード例 #25
0
ファイル: ComplexVector.cpp プロジェクト: DanNixon/mantid
/// Resize the vector
/// @param n :: The new length
void ComplexVector::resize(const size_t n) {
  auto oldVector = m_vector;
  m_vector = gsl_vector_complex_alloc(n);
  size_t m = oldVector->size < n ? oldVector->size : n;
  for (size_t i = 0; i < m; ++i) {
    gsl_vector_complex_set(m_vector, i, gsl_vector_complex_get(oldVector, i));
  }
  for (size_t i = m; i < n; ++i) {
    gsl_vector_complex_set(m_vector, i, gsl_complex{{0, 0}});
  }
  gsl_vector_complex_free(oldVector);
}
コード例 #26
0
ファイル: gsl_nmatrix.c プロジェクト: Zenexer/rb-gsl
gsl_vector_complex* nv_to_gv_complex(VALUE nm) {
  DENSE_STORAGE* s = NM_DENSE_STORAGE(nm);
  gsl_vector_complex* v = gsl_vector_complex_alloc( s->count );

  if (s->dtype != NM_COMPLEX128) {
    rb_raise(nm_eDataTypeError, "requires dtype of :complex128 to convert to a GSL complex vector");
  }

  memcpy(v->data, s->elements, v->size*sizeof(double)*2);

  return v;
}
コード例 #27
0
ファイル: fft.c プロジェクト: james-barnard/gsl
static VALUE rb_gsl_fft_complex_radix2_dif_transform(VALUE obj, VALUE val_sign)
{
  size_t stride, n;
  gsl_complex_packed_array data;
  gsl_vector_complex *vin, *vout;
  gsl_fft_direction sign;
  sign = NUM2INT(val_sign);
  get_complex_stride_n(obj, &vin, &data, &stride, &n);
  vout = gsl_vector_complex_alloc(n);
  gsl_vector_complex_memcpy(vout, vin); 
  gsl_fft_complex_radix2_dif_transform(vout->data, vout->stride /*1*/, vout->size /*n*/, sign);
  return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, vout);
}
コード例 #28
0
ファイル: Vector_complex.c プロジェクト: codahale/ruby-gsl
/* Given a variable-length argument list consisting of 1 or more
 * complex numbers, create a vector with size = argc
 */
static gsl_vector_complex * alloc_vector_from_complex(int argc, VALUE * argv)
{
  gsl_vector_complex * v = NULL;
  gsl_complex * pz;
  int n, i;
  n = argc;
  v = gsl_vector_complex_alloc(n);
  for (i = 0; i < n; i++) {
    Data_Get_Struct(argv[i], gsl_complex, pz);
    gsl_vector_complex_set(v, i, *pz);
  }
  return v;
}
コード例 #29
0
Calculator::Calculator(double lambda)
{
	double c = GSL_CONST_MKSA_SPEED_OF_LIGHT;
	double h = GSL_CONST_MKSA_PLANCKS_CONSTANT_H;
	double eV = GSL_CONST_MKSA_ELECTRON_VOLT;
	double A = GSL_CONST_MKSA_ANGSTROM;

	F 		= gsl_vector_complex_alloc(2);
	Fconj 	= gsl_vector_complex_alloc(2);
	W 		= gsl_vector_complex_alloc(2);

	tmp_vec = gsl_vector_complex_alloc(2);

	m_P		= gsl_matrix_complex_alloc(2, 2);
	T 		= gsl_matrix_complex_alloc(2, 2);
	m_Ps		= gsl_matrix_complex_alloc(2, 2);
	m_Exp		= gsl_matrix_complex_alloc(2, 2);

	tmp_mat = gsl_matrix_complex_alloc(2, 2);

	perm = gsl_permutation_alloc(2);

	m_L1 = 0.0;
	m_L2 = 0.0;
	m_L = 0.0;
	m_N = 0.0;

	m_lambda = lambda;
	/*calculate photon's energy*/
	m_energy = (h * c) / (eV * A) * 1.0 /lambda;

	m_sf1 = NULL;
	m_sf2 = NULL;

	m_I0 = 1.0;
	m_Ibg = 0.0;
	m_Q0 = 0.0;
}
コード例 #30
0
int
main (void)
{
  double data[] = { -1.0, 1.0, -1.0, 1.0,
                    -8.0, 4.0, -2.0, 1.0,
                    27.0, 9.0, 3.0, 1.0,
                    64.0, 16.0, 4.0, 1.0 };

  gsl_matrix_view m 
    = gsl_matrix_view_array (data, 4, 4);

  gsl_vector_complex *eval = gsl_vector_complex_alloc (4);
  gsl_matrix_complex *evec = gsl_matrix_complex_alloc (4, 4);

  gsl_eigen_nonsymmv_workspace * w = 
    gsl_eigen_nonsymmv_alloc (4);
  
  gsl_eigen_nonsymmv (&m.matrix, eval, evec, w);

  gsl_eigen_nonsymmv_free (w);

  gsl_eigen_nonsymmv_sort (eval, evec, 
                           GSL_EIGEN_SORT_ABS_DESC);
  
  {
    int i, j;

    for (i = 0; i < 4; i++)
      {
        gsl_complex eval_i 
           = gsl_vector_complex_get (eval, i);
        gsl_vector_complex_view evec_i 
           = gsl_matrix_complex_column (evec, i);

        printf ("eigenvalue = %g + %gi\n",
                GSL_REAL(eval_i), GSL_IMAG(eval_i));
        printf ("eigenvector = \n");
        for (j = 0; j < 4; ++j)
          {
            gsl_complex z = gsl_vector_complex_get(&evec_i.vector, j);
            printf("%g + %gi\n", GSL_REAL(z), GSL_IMAG(z));
          }
      }
  }

  gsl_vector_complex_free(eval);
  gsl_matrix_complex_free(evec);

  return 0;
}