gslpp::vector< complex > Class Template Reference

A class for constructing and defining operations on complex vectors. More...

#include <gslpp_vector_complex.h>

Detailed Description

template<>
class gslpp::vector< complex >

A class for constructing and defining operations on complex vectors.

Author
HEPfit Collaboration

This class defines some common operations on complex vectors using the GSL.

Definition at line 33 of file gslpp_vector_complex.h.

Public Member Functions

gsl_vector_complex & as_gsl_type ()
 
const gsl_vector_complex & as_gsl_type () const
 
gsl_vector_complex * as_gsl_type_ptr () const
 
void assign (const size_t &i, const complex &z)
 
void assign (const size_t &i, const double &a)
 
vector< complexconjugate () const
 
vector< double > imag () const
 
double mod () const
 
const complex operator() (const size_t &i) const
 
complex operator* (const vector< complex > &v)
 
vector< complexoperator* (const complex &z)
 
vector< complexoperator* (const double &a)
 
vector< complex > & operator*= (const complex &z)
 
vector< complex > & operator*= (const double &a)
 
vector< complexoperator+ (const vector< complex > &v)
 
vector< complexoperator+ (const complex &z)
 
vector< complexoperator+ (const double &a)
 
vector< complex > & operator+= (const vector< complex > &v)
 
vector< complex > & operator+= (const complex &z)
 
vector< complex > & operator+= (const double &a)
 
vector< complexoperator- () const
 
vector< complexoperator- (const vector< complex > &v)
 
vector< complexoperator- (const complex &z)
 
vector< complexoperator- (const double &a)
 
vector< complex > & operator-= (const vector< complex > &v)
 
vector< complex > & operator-= (const complex &z)
 
vector< complex > & operator-= (const double &a)
 
vector< complexoperator/ (const complex &z)
 
vector< complexoperator/ (const double &a)
 
vector< complex > & operator/= (const complex &z)
 
vector< complex > & operator/= (const double &a)
 
vector< complex > & operator= (const vector< complex > &v)
 
vector< complex > & operator= (double a)
 
vector< double > real () const
 
size_t size () const
 
 vector (const size_t &size, const complex &z)
 
 vector (const size_t &size, const double &a)
 
 vector (const vector< complex > &v)
 
 vector (const vector< double > &v)
 
 vector (const gsl_vector_complex &v)
 
 vector (const gsl_vector_complex *v)
 
 ~vector ()
 

Private Attributes

gsl_vector_complex * _vector
 

Friends

std::ostream & operator<< (std::ostream &output, const vector< complex > &v)
 
Operations on vector<complex>
vector< complexoperator+ (const complex &z, vector< complex > v)
 
vector< complexoperator- (const complex &z, vector< complex > v)
 
vector< complexoperator* (const complex &z, vector< complex > v)
 
vector< complexoperator+ (const double &a, vector< complex > v)
 
vector< complexoperator- (const double &a, vector< complex > v)
 
vector< complexoperator* (const double &a, vector< complex > v)
 

Constructor & Destructor Documentation

gslpp::vector< complex >::vector ( const size_t &  size,
const complex z 
)

Constructor

Definition at line 23 of file gslpp_vector_complex.cpp.

24  {
25  _vector = gsl_vector_complex_alloc(size);
26  gsl_vector_complex_set_all(_vector, z.as_gsl_type());
27  }
gsl_vector_complex * _vector
gslpp::vector< complex >::vector ( const size_t &  size,
const double &  a 
)

Definition at line 29 of file gslpp_vector_complex.cpp.

30  {
31  complex z(a);
32  _vector = gsl_vector_complex_alloc(size);
33  gsl_vector_complex_set_all(_vector, z.as_gsl_type());
34  }
gsl_vector_complex * _vector
gslpp::vector< complex >::vector ( const vector< complex > &  v)

Copy constructor

Definition at line 37 of file gslpp_vector_complex.cpp.

38  {
39  _vector = gsl_vector_complex_alloc(v.size());
40  gsl_vector_complex_memcpy(_vector, v.as_gsl_type_ptr());
41  }
gsl_vector_complex * _vector
gslpp::vector< complex >::vector ( const vector< double > &  v)

Definition at line 43 of file gslpp_vector_complex.cpp.

44  {
45  size_t i, n;
46  n = v.size();
47  _vector = gsl_vector_complex_alloc(n);
48  for (i = 0; i < n; i++)
49  gsl_vector_complex_set(_vector, i, v(i) + 0. * complex::i());
50  }
gsl_vector_complex * _vector
static const complex & i()
gslpp::vector< complex >::vector ( const gsl_vector_complex &  v)

Definition at line 52 of file gslpp_vector_complex.cpp.

53  {
54  _vector = gsl_vector_complex_alloc(v.size);
55  gsl_vector_complex_memcpy(_vector, &v);
56  }
gsl_vector_complex * _vector
gslpp::vector< complex >::vector ( const gsl_vector_complex *  v)

Definition at line 58 of file gslpp_vector_complex.cpp.

59  {
60  _vector = gsl_vector_complex_alloc(v->size);
61  gsl_vector_complex_memcpy(_vector, v);
62  }
gsl_vector_complex * _vector

Destructor

Definition at line 65 of file gslpp_vector_complex.cpp.

66  {
67  gsl_vector_complex_free(_vector);
68  }
gsl_vector_complex * _vector

Member Function Documentation

gsl_vector_complex & gslpp::vector< complex >::as_gsl_type ( )

Definition at line 155 of file gslpp_vector_complex.cpp.

156  {
157  return const_cast<gsl_vector_complex&> (*_vector);
158  }
const gsl_vector_complex & gslpp::vector< complex >::as_gsl_type ( ) const

Definition at line 160 of file gslpp_vector_complex.cpp.

161  {
162  return const_cast<gsl_vector_complex&> (*_vector);
163  }
gsl_vector_complex * gslpp::vector< complex >::as_gsl_type_ptr ( ) const

Conversion

Definition at line 150 of file gslpp_vector_complex.cpp.

151  {
152  return _vector;
153  }
gsl_vector_complex * _vector
void gslpp::vector< complex >::assign ( const size_t &  i,
const complex z 
)

Assign element

Definition at line 99 of file gslpp_vector_complex.cpp.

100  {
101  gsl_complex *x = gsl_vector_complex_ptr(_vector, i);
102  *x = z.as_gsl_type();
103  }
gsl_vector_complex * _vector
void gslpp::vector< complex >::assign ( const size_t &  i,
const double &  a 
)

Definition at line 105 of file gslpp_vector_complex.cpp.

106  {
107  gsl_complex *x = gsl_vector_complex_ptr(_vector, i);
108  *x = complex(a).as_gsl_type();
109  }
gsl_vector_complex * _vector
vector< complex > gslpp::vector< complex >::conjugate ( ) const

Get complex conjugate vector

Get conjugate vector

Definition at line 124 of file gslpp_vector_complex.cpp.

125  {
126  vector<complex> v1(*this);
127  for (unsigned int i = 0; i < v1.size(); i++)
128  v1.assign(i, v1(i).conjugate());
129 
130  return v1;
131  }
vector< complex > conjugate() const
vector< double > gslpp::vector< complex >::imag ( ) const

Get vector of imaginary parts

Definition at line 142 of file gslpp_vector_complex.cpp.

143  {
144  gsl_vector_view r = gsl_vector_complex_imag(_vector);
145  vector<double> re((&r.vector));
146  return re;
147  }
gsl_vector_complex * _vector
double gslpp::vector< complex >::mod ( ) const

Get Euclidean norm

Definition at line 118 of file gslpp_vector_complex.cpp.

119  {
120  return gsl_blas_dznrm2(_vector);
121  }
gsl_vector_complex * _vector
const complex gslpp::vector< complex >::operator() ( const size_t &  i) const

Get i-th element

Definition at line 71 of file gslpp_vector_complex.cpp.

72  {
73  const gsl_complex *x = gsl_vector_complex_const_ptr(_vector, i);
74  return complex(x);
75  }
gsl_vector_complex * _vector
complex gslpp::vector< complex >::operator* ( const vector< complex > &  v)

Scalar product operator

Scalar product operator (vector)

Definition at line 200 of file gslpp_vector_complex.cpp.

201  {
202  complex z1(0., 0., false);
203  vector<complex> v1(_vector);
204  if (gsl_blas_zdotu(v1.as_gsl_type_ptr(), v.as_gsl_type_ptr(), z1.as_gsl_type_ptr())) {
205  std::cout << "\n Error in vector<complex> *" << std::endl;
206  exit(EXIT_FAILURE);
207  }
208  return z1;
209  }
gsl_vector_complex * _vector
vector< complex > gslpp::vector< complex >::operator* ( const complex z)

Multiplication operator

Multiplication operator (complex)

Definition at line 274 of file gslpp_vector_complex.cpp.

275  {
276  vector<complex> v1(_vector);
277  gsl_blas_zscal(z.as_gsl_type(), v1.as_gsl_type_ptr());
278  return v1;
279  }
gsl_vector_complex * _vector
vector< complex > gslpp::vector< complex >::operator* ( const double &  a)

Multiplication operator

Multiplication operator (double)

Definition at line 332 of file gslpp_vector_complex.cpp.

333  {
334  complex z(a);
335  return *this * z;
336  }
vector< complex > & gslpp::vector< complex >::operator*= ( const complex z)

Multiplication assignment

Multiplication assignment (complex)

Definition at line 304 of file gslpp_vector_complex.cpp.

305  {
306  *this = *this * z;
307  return *this;
308  }
vector< complex > & gslpp::vector< complex >::operator*= ( const double &  a)

Multiplication assignment

Multiplication assignment (double)

Definition at line 360 of file gslpp_vector_complex.cpp.

361  {
362  *this = *this * a;
363  return *this;
364  }
vector< complex > gslpp::vector< complex >::operator+ ( const vector< complex > &  v)

Addition operator

Addition operator (vector)

Definition at line 174 of file gslpp_vector_complex.cpp.

175  {
176  vector<complex> v1(_vector);
177  gsl_complex z1;
178  GSL_SET_COMPLEX(&z1, 1., 0.);
179  if (gsl_blas_zaxpy(z1, v.as_gsl_type_ptr(), v1.as_gsl_type_ptr())) {
180  std::cout << "\n Error in vector<complex> +" << std::endl;
181  exit(EXIT_FAILURE);
182  }
183  return v1;
184  }
gsl_vector_complex * _vector
vector< complex > gslpp::vector< complex >::operator+ ( const complex z)

Addition operator

Addition operator (complex)

Definition at line 240 of file gslpp_vector_complex.cpp.

241  {
242  vector<complex> v1(_vector);
243  gsl_complex z1;
244  gsl_vector_complex *v2;
245  GSL_SET_COMPLEX(&z1, 1., 0.);
246  v2 = gsl_vector_complex_alloc(v1.size());
247  gsl_vector_complex_set_all(v2, z1);
248  if (gsl_blas_zaxpy(z, v2, v1.as_gsl_type_ptr())) {
249  std::cout << "\n Error in vector<complex> + (double)" << std::endl;
250  exit(EXIT_FAILURE);
251  }
252  gsl_vector_complex_free(v2);
253  return v1;
254  }
gsl_vector_complex * _vector
vector< complex > gslpp::vector< complex >::operator+ ( const double &  a)

Addition operator

Addition operator (double)

Definition at line 318 of file gslpp_vector_complex.cpp.

319  {
320  complex z(a);
321  return *this +z;
322  }
vector< complex > & gslpp::vector< complex >::operator+= ( const vector< complex > &  v)

Vector product operator Addition assignment

Vector product operator (vector) Addition assignment (vector)

Definition at line 218 of file gslpp_vector_complex.cpp.

219  {
220  /* gsl_complex z1;
221  GSL_SET_COMPLEX(&z1,1.,0.);
222  if (gsl_blas_zaxpy(z1, v.as_gsl_type_ptr(), _vector))
223  {
224  std::cout << "\n Error in vector<complex> +=" << std::endl;
225  exit(EXIT_FAILURE);
226  }
227  return *this;*/
228  *this = *this +v;
229  return *this;
230  }
vector< complex > & gslpp::vector< complex >::operator+= ( const complex z)

Addition assignment

Addition assignment (complex)

Definition at line 290 of file gslpp_vector_complex.cpp.

291  {
292  *this = *this +z;
293  return *this;
294  }
vector< complex > & gslpp::vector< complex >::operator+= ( const double &  a)

Addition assignment

Addition assignment (double)

Definition at line 346 of file gslpp_vector_complex.cpp.

347  {
348  *this = *this +a;
349  return *this;
350  }
vector< complex > gslpp::vector< complex >::operator- ( ) const

Unary minus

Definition at line 166 of file gslpp_vector_complex.cpp.

167  {
168  vector<complex> v1(_vector);
169  gsl_blas_zdscal(-1., v1.as_gsl_type_ptr());
170  return v1;
171  }
gsl_vector_complex * _vector
vector< complex > gslpp::vector< complex >::operator- ( const vector< complex > &  v)

Subtraction operator

Subtraction operator (vector)

Definition at line 187 of file gslpp_vector_complex.cpp.

188  {
189  vector<complex> v1(_vector);
190  gsl_complex z1;
191  GSL_SET_COMPLEX(&z1, -1., 0.);
192  if (gsl_blas_zaxpy(z1, v.as_gsl_type_ptr(), v1.as_gsl_type_ptr())) {
193  std::cout << "\n Error in vector<complex> -" << std::endl;
194  exit(EXIT_FAILURE);
195  }
196  return v1;
197  }
gsl_vector_complex * _vector
vector< complex > gslpp::vector< complex >::operator- ( const complex z)

Subtraction assignment

Subtraction assignment (complex)

Definition at line 257 of file gslpp_vector_complex.cpp.

258  {
259  vector<complex> v1(_vector);
260  gsl_complex z1;
261  gsl_vector_complex *v2;
262  GSL_SET_COMPLEX(&z1, -1., 0.);
263  v2 = gsl_vector_complex_alloc(v1.size());
264  gsl_vector_complex_set_all(v2, z1);
265  if (gsl_blas_zaxpy(z, v2, v1.as_gsl_type_ptr())) {
266  std::cout << "\n Error in vector<complex> - (double)" << std::endl;
267  exit(EXIT_FAILURE);
268  }
269  gsl_vector_complex_free(v2);
270  return v1;
271  }
gsl_vector_complex * _vector
vector< complex > gslpp::vector< complex >::operator- ( const double &  a)

Subtraction assignment

Subtraction assignment (double)

Definition at line 325 of file gslpp_vector_complex.cpp.

326  {
327  complex z(a);
328  return *this -z;
329  }
vector< complex > & gslpp::vector< complex >::operator-= ( const vector< complex > &  v)

Subtraction assignment

Subtraction assignment (vector)

Definition at line 233 of file gslpp_vector_complex.cpp.

234  {
235  *this = *this -v;
236  return *this;
237  }
vector< complex > & gslpp::vector< complex >::operator-= ( const complex z)

Subtraction assignment

Subtraction assignment (complex)

Definition at line 297 of file gslpp_vector_complex.cpp.

298  {
299  *this = *this -z;
300  return *this;
301  }
vector< complex > & gslpp::vector< complex >::operator-= ( const double &  a)

Subtraction assignment

Subtraction assignment (double)

Definition at line 353 of file gslpp_vector_complex.cpp.

354  {
355  *this = *this -a;
356  return *this;
357  }
vector< complex > gslpp::vector< complex >::operator/ ( const complex z)

Division operator

Division operator (complex)

Definition at line 282 of file gslpp_vector_complex.cpp.

283  {
284  vector<complex> v1(_vector);
285  gsl_blas_zscal(z.inverse().as_gsl_type(), v1.as_gsl_type_ptr());
286  return v1;
287  }
gsl_vector_complex * _vector
vector< complex > gslpp::vector< complex >::operator/ ( const double &  a)

Division operator

Division operator (double)

Definition at line 339 of file gslpp_vector_complex.cpp.

340  {
341  complex z(a);
342  return *this / z;
343  }
vector< complex > & gslpp::vector< complex >::operator/= ( const complex z)

Division assignment

Division assignment (complex)

Definition at line 311 of file gslpp_vector_complex.cpp.

312  {
313  *this = *this / z;
314  return *this;
315  }
vector< complex > & gslpp::vector< complex >::operator/= ( const double &  a)

Division assignment

Division assignment (double)

Definition at line 367 of file gslpp_vector_complex.cpp.

368  {
369  *this = *this / a;
370  return *this;
371  }
vector< complex > & gslpp::vector< complex >::operator= ( const vector< complex > &  v)

Set i-th element Assign

Definition at line 85 of file gslpp_vector_complex.cpp.

86  {
87  gsl_vector_complex_memcpy(_vector, v.as_gsl_type_ptr());
88  return *this;
89  }
gsl_vector_complex * _vector
vector< complex > & gslpp::vector< complex >::operator= ( double  a)

Definition at line 91 of file gslpp_vector_complex.cpp.

92  {
93  complex z(a);
94  gsl_vector_complex_set_all(_vector, z.as_gsl_type());
95  return *this;
96  }
gsl_vector_complex * _vector
vector< double > gslpp::vector< complex >::real ( ) const

Get vector of real parts

Definition at line 134 of file gslpp_vector_complex.cpp.

135  {
136  gsl_vector_view r = gsl_vector_complex_real(_vector);
137  vector<double> re((&r.vector));
138  return re;
139  }
gsl_vector_complex * _vector
size_t gslpp::vector< complex >::size ( ) const

Get vector size

Definition at line 112 of file gslpp_vector_complex.cpp.

113  {
114  return _vector->size;
115  }
gsl_vector_complex * _vector

Friends And Related Function Documentation

vector<complex> operator* ( const complex z,
vector< complex v 
)
friend

Multiply a complex number by complex vector

Parameters
zComplex number
vComplex vector
Returns
\( z*v \)

Definition at line 394 of file gslpp_vector_complex.cpp.

395  {
396  return v*z;
397  }
vector<complex> operator* ( const double &  a,
vector< complex v 
)
friend

Multiply a real number by a complex vector

Parameters
aReal number
vComplex vector
Returns
\( z*v \)

Definition at line 409 of file gslpp_vector_complex.cpp.

410  {
411  return v*a;
412  }
vector<complex> operator+ ( const complex z,
vector< complex v 
)
friend

Add a complex number to a complex vector

Parameters
zComplex number
vComplex vector
Returns
\( z + v \)

Definition at line 384 of file gslpp_vector_complex.cpp.

385  {
386  return v + z;
387  }
vector<complex> operator+ ( const double &  a,
vector< complex v 
)
friend

Add a real number to a complex vector

Parameters
aReal number
vComplex vector
Returns
\( a + v \)

Definition at line 399 of file gslpp_vector_complex.cpp.

400  {
401  return v + a;
402  }
vector<complex> operator- ( const complex z,
vector< complex v 
)
friend

Subtract a complex number from a complex vector

Parameters
zComplex number
vComplex vector
Returns
\( z - v \)

Definition at line 389 of file gslpp_vector_complex.cpp.

390  {
391  return -v + z;
392  }
vector<complex> operator- ( const double &  a,
vector< complex v 
)
friend

Subtract a complex vector from a real number

Parameters
aReal number
vComplex vector
Returns
\( a - v \)

Definition at line 404 of file gslpp_vector_complex.cpp.

405  {
406  return -v + a;
407  }
std::ostream& operator<< ( std::ostream &  output,
const vector< complex > &  v 
)
friend

friend functions

Definition at line 374 of file gslpp_vector_complex.cpp.

375  {
376  size_t i;
377  output << "(";
378  for (i = 0; i < v.size() - 1; i++)
379  output << v(i) << ",";
380  output << v(i) << ")";
381  return output;
382  }

Member Data Documentation

gsl_vector_complex* gslpp::vector< complex >::_vector
private

Definition at line 35 of file gslpp_vector_complex.h.


The documentation for this class was generated from the following files: