gslpp::vector< double > Class Template Reference

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

#include <gslpp_vector_double.h>

Detailed Description

template<>
class gslpp::vector< double >

A class for constructing and defining operations on real vectors.

Author
HEPfit Collaboration

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

Definition at line 33 of file gslpp_vector_double.h.

Public Member Functions

gsl_vector & as_gsl_type ()
 
const gsl_vector & as_gsl_type () const
 
gsl_vector * as_gsl_type_ptr () const
 
double max () const
 
double min () const
 
double mod () const
 
const double & operator() (const size_t &i) const
 
double & operator() (const size_t &i)
 
double operator* (const vector< double > &v)
 
vector< double > operator* (const double &a)
 
vector< complexoperator* (const complex &z)
 
vector< double > & operator*= (const double &a)
 
vector< double > operator+ (const vector< double > &v)
 
vector< double > operator+ (const double &a)
 
vector< complexoperator+ (const complex &z)
 
vector< double > & operator+= (const vector< double > &v)
 
vector< double > & operator+= (const double &a)
 
vector< double > operator- () const
 
vector< double > operator- (const vector< double > &v)
 
vector< double > operator- (const double &a)
 
vector< complexoperator- (const complex &z)
 
vector< double > & operator-= (const vector< double > &v)
 
vector< double > & operator-= (const double &a)
 
vector< double > operator/ (const double &a)
 
vector< complexoperator/ (const complex &z)
 
vector< double > & operator/= (const double &a)
 
vector< double > & operator= (const vector< double > &v)
 
size_t size () const
 
 vector (const size_t &size)
 
 vector (const size_t &size, const double &a)
 
 vector (const vector< double > &v)
 
 vector (const gsl_vector &v)
 
 vector (const gsl_vector *v)
 
 ~vector ()
 

Private Attributes

gsl_vector * _vector
 

Friends

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

Constructor & Destructor Documentation

gslpp::vector< double >::vector ( const size_t &  size)

Constructor

Definition at line 29 of file gslpp_vector_double.cpp.

30  {
31  _vector = gsl_vector_alloc(size);
32  gsl_vector_set_all(_vector, 0.);
33  }
gslpp::vector< double >::vector ( const size_t &  size,
const double &  a 
)

Constructor

Definition at line 23 of file gslpp_vector_double.cpp.

24  {
25  _vector = gsl_vector_alloc(size);
26  gsl_vector_set_all(_vector, a);
27  }
gslpp::vector< double >::vector ( const vector< double > &  v)

Copy constructor

Definition at line 36 of file gslpp_vector_double.cpp.

37  {
38  _vector = gsl_vector_alloc(v.size());
39  gsl_vector_memcpy(_vector, v.as_gsl_type_ptr());
40  }
gslpp::vector< double >::vector ( const gsl_vector< double > &  v)

Definition at line 42 of file gslpp_vector_double.cpp.

43  {
44  _vector = gsl_vector_alloc(v.size);
45  gsl_vector_memcpy(_vector, &v);
46  }
gslpp::vector< double >::vector ( const gsl_vector< double > *  v)

Definition at line 48 of file gslpp_vector_double.cpp.

49  {
50  _vector = gsl_vector_alloc(v->size);
51  gsl_vector_memcpy(_vector, v);
52  }
gslpp::vector< double >::~vector ( )

Destructor

Definition at line 55 of file gslpp_vector_double.cpp.

56  {
57  gsl_vector_free(_vector);
58  }

Member Function Documentation

gsl_vector & gslpp::vector< double >::as_gsl_type ( )

Definition at line 111 of file gslpp_vector_double.cpp.

112  {
113  return const_cast<gsl_vector&>(*_vector);
114  }
const gsl_vector & gslpp::vector< double >::as_gsl_type ( ) const

Definition at line 116 of file gslpp_vector_double.cpp.

117  {
118  return const_cast<gsl_vector&>(*_vector);
119  }
gsl_vector * gslpp::vector< double >::as_gsl_type_ptr ( ) const

Conversion

Definition at line 106 of file gslpp_vector_double.cpp.

107  {
108  return _vector;
109  }
double gslpp::vector< double >::max ( ) const

Get max element

Definition at line 94 of file gslpp_vector_double.cpp.

95  {
96  return gsl_vector_max(_vector);
97  }
double gslpp::vector< double >::min ( ) const

Get min element

Definition at line 100 of file gslpp_vector_double.cpp.

101  {
102  return gsl_vector_min(_vector);
103  }
double gslpp::vector< double >::mod ( ) const

Get Euclidean norm

Definition at line 88 of file gslpp_vector_double.cpp.

89  {
90  return gsl_blas_dnrm2(_vector);
91  }
const double & gslpp::vector< double >::operator() ( const size_t &  i) const

Get i-th element

Definition at line 61 of file gslpp_vector_double.cpp.

62  {
63  const double *x = gsl_vector_const_ptr(_vector, i);
64  return *x;
65  }
double & gslpp::vector< double >::operator() ( const size_t &  i)

Set i-th element

Definition at line 68 of file gslpp_vector_double.cpp.

69  {
70  double *x = gsl_vector_ptr(_vector, i);
71  return *x;
72  }
double gslpp::vector< double >::operator* ( const vector< double > &  v)

Scalar product operator (vector)

Definition at line 156 of file gslpp_vector_double.cpp.

157  {
158  double a=0.;
159  vector<double> v1(_vector);
160  if(gsl_blas_ddot(v1.as_gsl_type_ptr(), v.as_gsl_type_ptr(), &a))
161  {
162  std::cout << "\n Error in vector<double> *" << std::endl;
163  exit(EXIT_FAILURE);
164  }
165  return a;
166  }
vector< double > gslpp::vector< double >::operator* ( const double &  a)

Multiplication operator (double)

Definition at line 210 of file gslpp_vector_double.cpp.

211  {
212  vector<double> v1(_vector);
213  if (gsl_vector_scale(v1.as_gsl_type_ptr(), a))
214  {
215  std::cout << "\n Error in vector<double> * (double)" << std::endl;
216  exit(EXIT_FAILURE);
217  }
218  return v1;
219  }
vector< complex > gslpp::vector< double >::operator* ( const complex z)

Multiplication operator (complex)

Definition at line 268 of file gslpp_vector_double.cpp.

269  {
270  vector<complex> v1(*this);
271  return v1*z;
272  }
vector< double > & gslpp::vector< double >::operator*= ( const double &  a)

Multiplication assignment (double)

Definition at line 244 of file gslpp_vector_double.cpp.

245  {
246  *this = *this * a;
247  return *this;
248  }
vector< double > gslpp::vector< double >::operator+ ( const vector< double > &  v)

Addition operator (vector)

Definition at line 134 of file gslpp_vector_double.cpp.

135  {
136  vector<double> v1(_vector);
137  if (gsl_vector_add(v1.as_gsl_type_ptr(), v.as_gsl_type_ptr()))
138  {
139  std::cout << "\n Error in vector<double> +" << std::endl;
140  exit(EXIT_FAILURE);
141  }
142  return v1;
143  }
vector< double > gslpp::vector< double >::operator+ ( const double &  a)

Addition operator (double)

Definition at line 188 of file gslpp_vector_double.cpp.

189  {
190  vector<double> v1(_vector);
191  if (gsl_vector_add_constant(v1.as_gsl_type_ptr(), a))
192  {
193  std::cout << "\n Error in vector<double> + (double)" << std::endl;
194  exit(EXIT_FAILURE);
195  }
196  return v1;
197  }
vector< complex > gslpp::vector< double >::operator+ ( const complex z)

Addition operator (complex)

Definition at line 256 of file gslpp_vector_double.cpp.

257  {
258  vector<complex> v1(*this);
259  return v1+z;
260  }
vector< double > & gslpp::vector< double >::operator+= ( const vector< double > &  v)

Vector product operator Addition assignment (vector)

Vector product operator (vector) Addition assignment (vector)

Definition at line 175 of file gslpp_vector_double.cpp.

176  {
177  *this = *this + v;
178  return *this;
179  }
vector< double > & gslpp::vector< double >::operator+= ( const double &  a)

Addition assignment (double)

Definition at line 232 of file gslpp_vector_double.cpp.

233  {
234  *this = *this + a;
235  return *this;
236  }
vector< double > gslpp::vector< double >::operator- ( ) const

Unary minus (vector)

Unary minus

Definition at line 122 of file gslpp_vector_double.cpp.

123  {
124  vector<double> v1(_vector);
125  if (gsl_vector_scale(v1.as_gsl_type_ptr(), -1.))
126  {
127  std::cout << "\n Error in vector<double> unary -" << std::endl;
128  exit(EXIT_FAILURE);
129  }
130  return v1;
131  }
vector< double > gslpp::vector< double >::operator- ( const vector< double > &  v)

Subtraction operator (vector)

Definition at line 145 of file gslpp_vector_double.cpp.

146  {
147  vector<double> v1(_vector);
148  if (gsl_vector_sub(v1.as_gsl_type_ptr(), v.as_gsl_type_ptr()))
149  {
150  std::cout << "\n Error in vector<double> -" << std::endl;
151  exit(EXIT_FAILURE);
152  }
153  return v1;
154  }
vector< double > gslpp::vector< double >::operator- ( const double &  a)

Subtraction assignment (double)

Subtraction operator (double)

Definition at line 199 of file gslpp_vector_double.cpp.

200  {
201  vector<double> v1(_vector);
202  if (gsl_vector_add_constant(v1.as_gsl_type_ptr(), -a))
203  {
204  std::cout << "\n Error in vector<double> - (double)" << std::endl;
205  exit(EXIT_FAILURE);
206  }
207  return v1;
208  }
vector< complex > gslpp::vector< double >::operator- ( const complex z)

Subtraction assignment (complex)

Subtraction operator (complex)

Definition at line 262 of file gslpp_vector_double.cpp.

263  {
264  vector<complex> v1(*this);
265  return v1-z;
266  }
vector< double > & gslpp::vector< double >::operator-= ( const vector< double > &  v)

Subtraction assignment (vector)

Definition at line 181 of file gslpp_vector_double.cpp.

182  {
183  *this = *this - v;
184  return *this;
185  }
vector< double > & gslpp::vector< double >::operator-= ( const double &  a)

Subtraction assignment (double)

Definition at line 238 of file gslpp_vector_double.cpp.

239  {
240  *this = *this - a;
241  return *this;
242  }
vector< double > gslpp::vector< double >::operator/ ( const double &  a)

Division operator (double)

Definition at line 221 of file gslpp_vector_double.cpp.

222  {
223  vector<double> v1(_vector);
224  if (gsl_vector_scale(v1.as_gsl_type_ptr(), 1./a))
225  {
226  std::cout << "\n Error in vector<double> / (double)" << std::endl;
227  exit(EXIT_FAILURE);
228  }
229  return v1;
230  }
vector< complex > gslpp::vector< double >::operator/ ( const complex z)

Division operator (complex)

Definition at line 274 of file gslpp_vector_double.cpp.

275  {
276  vector<complex> v1(*this);
277  return v1/z;
278  }
vector< double > & gslpp::vector< double >::operator/= ( const double &  a)

Division assignment (double)

Definition at line 250 of file gslpp_vector_double.cpp.

251  {
252  *this = *this / a;
253  return *this;
254  }
vector< double > & gslpp::vector< double >::operator= ( const vector< double > &  v)

Assign

Definition at line 75 of file gslpp_vector_double.cpp.

76  {
77  gsl_vector_memcpy(_vector, v.as_gsl_type_ptr());
78  return *this;
79  }
size_t gslpp::vector< double >::size ( ) const

Get vector size

Definition at line 82 of file gslpp_vector_double.cpp.

83  {
84  return _vector->size;
85  }

Friends And Related Function Documentation

vector<double> operator* ( const double &  a,
vector< double >  v 
)
friend

Multiply a real number by real vector

Parameters
aReal number
vReal vector
Returns
\( a*v \)

Definition at line 300 of file gslpp_vector_double.cpp.

301  {
302  return v*a;
303  }
vector<complex> operator* ( const complex z,
vector< double >  v 
)
friend

Multiply a complex number by a real vector

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

Definition at line 315 of file gslpp_vector_double.cpp.

316  {
317  return v*z;
318  }
vector<double> operator+ ( const double &  a,
vector< double >  v 
)
friend

Add a real number to a real vector

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

Definition at line 290 of file gslpp_vector_double.cpp.

291  {
292  return v+a;
293  }
vector<complex> operator+ ( const complex z,
vector< double >  v 
)
friend

Add a complex number to a real vector

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

Definition at line 305 of file gslpp_vector_double.cpp.

306  {
307  return v+z;
308  }
vector<double> operator- ( const double &  a,
vector< double >  v 
)
friend

Subtract a real number from a real vector

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

Definition at line 295 of file gslpp_vector_double.cpp.

296  {
297  return -v+a;
298  }
vector<complex> operator- ( const complex z,
vector< double >  v 
)
friend

Subtract a complex number from a real vector

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

Definition at line 310 of file gslpp_vector_double.cpp.

311  {
312  return -v+z;
313  }
std::ostream& operator<< ( std::ostream &  output,
const vector< double > &  v 
)
friend

friend functions

Definition at line 280 of file gslpp_vector_double.cpp.

281  {
282  size_t i;
283  output << "(";
284  for (i=0; i<v.size()-1; i++)
285  output << v(i) << ",";
286  output << v(i) << ")";
287  return output;
288  }

Member Data Documentation

gsl_vector* gslpp::vector< double >::_vector
private

Definition at line 35 of file gslpp_vector_double.h.


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