C++ main module for mmsd Package  1.0
LAP_DoubleVector.h
Go to the documentation of this file.
1 #ifndef LAP_DoubleVector_H
2 #define LAP_DoubleVector_H
3 
4 #include "LAP_Vector.h"
5 #include "CORE_ListPointers.h"
6 
7 #include "dvector_functions.h"
8 
10 
20 class LAP_DoubleVector: public LAP_Vector<lapack_real> {
21 
22  SP_OBJECT(LAP_DoubleVector);
23 
24 private:
25  // ATTRIBUTES
26 
27 
28  // ASSOCIATIONS
29 
30  // METHODS
31 
32 
33 public:
34  // CONSTRUCTORS
41 
42 
43  // DESTRUCTORS
46  virtual ~LAP_DoubleVector();
47 
48 public:
49 
50 
51  // -------------
52  // NEW METHODS
53  // -------------
54 public:
57  inline static SP::LAP_DoubleVector New() {
58  SP::LAP_DoubleVector p(new LAP_DoubleVector(),
60  p->setThis(p);
61  return p;
62  };
65  inline static SP::LAP_DoubleVector New(const tLVectorIndex& s) {
66  SP::LAP_DoubleVector p(new LAP_DoubleVector(s),
68  p->setThis(p);
69  return p;
70  };
71 
74  inline static SP::LAP_DoubleVector New(const LAP_DoubleVector& s) {
75  SP::LAP_DoubleVector p(new LAP_DoubleVector(s),
77  p->setThis(p);
78  return p;
79  };
82  inline static SP::LAP_DoubleVector New(SPC::LAP_DoubleVector s) {
83  if (s.get()!=null) {
84  SP::LAP_DoubleVector p(new LAP_DoubleVector(*s.get()),
86  p->setThis(p);
87  return p;
88  } else
89  return New();
90  };
91 
92 
95  inline static SP::LAP_DoubleVector New(const vector<lapack_real>& vs) {
96  SP::LAP_DoubleVector p=New();
97  p.get()->copy(vs);
98  return p;
99  };
100 
101 
102  //copy operators
103  // ============
107  init(s);
108  return (*this);
109  };
110 
113  inline LAP_DoubleVector& operator=(const vector<lapack_real>& s) {
115  return (*this);
116  };
117 
121  copy(s);
122  return (*this);
123  };
127  copy(s);
128  return (*this);
129  };
130 
131 
132  //accessor methods
133  //==================
136  virtual tLVectorIndex getNullValuesNumber(const tReal& eps) const {
137  tLVectorIndex n=0;
138  tLVectorIndex i,nvs=getCapacity();
139  const double *vs=&(*this)[0];
140  for (i=nvs-1;i>0;i--) n+=(fabs(vs[i])<eps);
141  if (nvs>0) n+=(fabs(vs[i])<eps);
142  return n;
143  }
144 
145  //computation operators
146  //=====================
149  inline LAP_DoubleVector& operator+=(const double& s) {
151  return(*this);
152  }
153 
156  inline LAP_DoubleVector& operator-=(const double& s) {
157  sub(s);
158  return (*this);
159  };
160 
163  inline LAP_DoubleVector& operator^=(const double& s) {
164  power(s);
165  return (*this);
166  };
170  divideBy(s);
171  return (*this);
172  };
176  multiplyBy(s);
177  return (*this);
178  };
179 
180 
181  //BLAS operators
182  //==============
183 
187  scale(s);
188  return (*this);
189  };
193  scale(1./s);
194  return (*this);
195  };
196 
201  add(1,s);
202  return (*this);
203  };
208  add(-1,s);
209  return (*this);
210  };
211 
212  // copy methods
213  // ============
214 
222  void copy(const LAP_Vector<lapack_real>& v) {
223  setSize(v.getSize());
224  DoubleVectorCopy(v.getSize(),v.getIncrement(),&v(0),getIncrement(),&(*this)(0));
225  }
226 
235  setSize(v.getSize());
236  DoubleVectorCopy(v.getSize(),v.getIncrement(),&v(0),getIncrement(),&(*this)(0));
237  }
238 
241  virtual void copy(const vector<lapack_real>& vs) {
243  }
244 
245 
246  // ----------------
247  // scalar product
248  // ----------------
249 
250 
254  inline double product(const LAP_DoubleVector& v) const {
255 
256  if (getSize() != v.getSize())
257  throw LAP_Exception("math/linalg/core","LAD_DoubleVector::product","incompatible dimension of vectors");
258 
259  //call lapack function
260  return DoubleVectorDot(v.getSize(),
261  v.getIncrement(),&v(0),
262  getIncrement(),&(*this)(0));
263  }
264 
265  inline static double product(const LAP_DoubleVector& v,
266  const LAP_DoubleVector& w) {
267  return v.product(w);
268  }
269 
270 
271  // --------------
272  // add operators
273  // ---------------
274 
279  inline void add(const lapack_real& alpha,
280  const LAP_Vector<lapack_real>& x) {
281 
282  if (getSize() != x.getSize())
283  throw LAP_Exception("math/linalg/core","LAP_DoubleVector::add","incompatible dimension of vector");
284 
286  x.getIncrement(),&x(0),
287  alpha,
288  getIncrement(),&(*this)(0));
289  }
290 
295  inline void add(const lapack_real& alpha,
296  const tLVectorIndex n,
297  const lapack_real* x) {
298 
299 
300  DoubleVectorAdd(n,1,x,
301  alpha,
302  getIncrement(),&(*this)(0));
303  }
304 
308  virtual void add(const tLVectorIndex& i,const lapack_real& v) {
310  }
311 
312  // ------------------
313  // multiply operators
314  // -------------------
315 
320  inline void scale(const lapack_real& alpha) {
321  DoubleVectorScale(getSize(),getIncrement(),&(*this)(0),alpha);
322  }
323 
324 
325 
326  // ---------------------
327  // geometric operators
328  // --------------------
329 
336  static void rotate(LAP_DoubleVector& dx,LAP_DoubleVector& dy,const lapack_real& c,const lapack_real& s);
341  static inline void buildRotation(lapack_real& dx,lapack_real& dy,lapack_real& c,lapack_real& s) {
342  DoubleVectorRotationPlane(dx,dy,c,s);
343  }
344 
345  // ----------------
346  // swap operators
347  // ----------------
348 
352  inline static void swap(LAP_DoubleVector& x,LAP_DoubleVector& y) {
353  lapack_int n=x.getSize();
354  ASSERT_IN((tLVectorIndex) n == y.getSize());
355  if ((tLVectorIndex) n != y.getSize()) throw LAP_Exception("math/linalg/core","LAP_DoubleVector::swap","incompatible size of vectors");
356 
357  lapack_int incx =x.getIncrement();
358  lapack_int incy =y.getIncrement();
359  DoubleVectorSwap(n,incx,&x(0),incy,&y(0));
360  }
361 
362 
363 
364  // -----------------
365  // scalar operators
366  // -----------------
370  inline tLVectorIndex indexMax() const {
371  return DoubleVectorIndexMax(getSize(),getIncrement(),&(*this)(0));
372  }
373 
374 
377  double maxValue(tLVectorIndex& i) const {
379  }
382  double minValue(tLVectorIndex& i) const {
384  }
385 
389  inline double norm1() const{
390  return DoubleVectorNorm1(getSize(),getIncrement(),&(*this)(0));
391  }
392 
396  inline double norm2() const{
397  return DoubleVectorNorm2(getSize(),getIncrement(),&(*this)(0));
398  };
399 
402  double sum() const {
404  }
405 
408  inline double normInf() const {
409  return fabs((*this)(indexMax()));
410  };
411 
414  double distance2(const LAP_DoubleVector& b) const {
415  return LAP_Vector<lapack_real>::distance2(*this,b);
416  }
419  inline double distance2(SPC::LAP_DoubleVector b) const {
420  if (b.get()!=null) return distance2(*b.get());
421  return 0;
422  };
423 
424 public:
425 
428  virtual tString toString() const;
429 
430 };
431 #endif
tLVectorIndex getCapacity() const
get the capacity
Definition: LAP_Vector.h:524
LAP_DoubleVector & operator-=(const double &s)
sub operator
Definition: LAP_DoubleVector.h:156
LAP_DoubleVector & operator=(const LAP_DoubleVector &s)
copy operator the view is taken into account
Definition: LAP_DoubleVector.h:120
this class describes the exceptions raised for LAP package
Definition: LAP_Exception.h:14
void scale(const lapack_real &alpha)
return this*=a the view is taken into account dscal blas method called
Definition: LAP_DoubleVector.h:320
LAP_DoubleVector & operator=(const vector< lapack_real > &s)
copy the vector of double
Definition: LAP_DoubleVector.h:113
double norm2() const
return the sqrt(sum([xi|^2)) dnrm2 blas method called
Definition: LAP_DoubleVector.h:396
static void swap(LAP_DoubleVector &x, LAP_DoubleVector &y)
swap the two vectors with the same length dswap method called
Definition: LAP_DoubleVector.h:352
void sub(const lapack_real &s)
sub operator
Definition: LAP_Vector.h:166
DEFINE_SVPTR(LAP_DoubleVector)
LAP_DoubleVector & operator/=(const LAP_DoubleVector &s)
division elementt by elementt vector operator
Definition: LAP_DoubleVector.h:169
void DoubleVectorSwap(const tLVectorIndex &nX, const tLVectorIncrement &incX, double *X, const tLVectorIncrement &incY, double *Y)
Definition: dvector_functions.cpp:165
Definition: LAP_DoubleVector.h:20
#define lapack_int
Definition: lapack_functions.h:7
tLVectorIndex indexMax() const
return the i such that |xi| is maximum idamax blas method called
Definition: LAP_DoubleVector.h:370
static SP::LAP_DoubleVector New(SPC::LAP_DoubleVector s)
create a new copy of s the view is taken into account
Definition: LAP_DoubleVector.h:82
T sum() const
compute the sum of the elements
Definition: LAP_Vector.hpp:170
tLVectorIndex getSize() const
get the size of the vector
Definition: LAP_ConstVector.h:170
T maxValue(tLVectorIndex &i) const
return the max value of the vector and the corresponding index
Definition: LAP_Vector.hpp:15
LAP_DoubleVector & operator*=(const lapack_real &s)
scale operator
Definition: LAP_DoubleVector.h:186
virtual tString toString() const
turn the class to string
Definition: LAP_DoubleVector.cpp:23
void DoubleVectorAdd(const tLVectorIndex &nX, const tLVectorIncrement &incX, const double *X, const double &alpha, const tLVectorIncrement &incY, double *y)
Definition: dvector_functions.cpp:94
#define lapack_real
Definition: lapack_functions.h:9
virtual void add(const tLVectorIndex &i, const lapack_real &v)
return this[i]+=v the view is taken into account
Definition: LAP_DoubleVector.h:308
#define null
Definition: types.h:13
const tLVectorIncrement & getIncrement() const
get the increment of the vector
Definition: LAP_Vector.h:529
double normInf() const
return the the maximum value of [xi|
Definition: LAP_DoubleVector.h:408
void DoubleVectorRotationPlane(double &dx, double &dy, double &c, double &s)
Definition: dvector_functions.cpp:160
LAP_DoubleVector & operator^=(const double &s)
power operator
Definition: LAP_DoubleVector.h:163
LAP_DoubleVector & operator/=(const lapack_real &s)
divide operator
Definition: LAP_DoubleVector.h:192
tLVectorIndex DoubleVectorIndexMax(const tLVectorIndex &nX, const tLVectorIncrement &incX, const double *x)
Definition: dvector_functions.cpp:175
tLVectorIndex getSize() const
get the size of the vector
Definition: LAP_Vector.h:519
double DoubleVectorNorm2(const tLVectorIndex &nX, const tLVectorIncrement &incX, const double *x)
Definition: dvector_functions.cpp:192
double norm1() const
return the sum(|xi|) dasum blas method called
Definition: LAP_DoubleVector.h:389
void copy(const LAP_ConstVector< lapack_real > &v)
copy the vector the view is set to [0,v.getSize()[ the viewed values of v is copied into this use (dc...
Definition: LAP_DoubleVector.h:234
static SP::LAP_DoubleVector New(const tLVectorIndex &s)
create a new vector of double of size s
Definition: LAP_DoubleVector.h:65
tReal distance2(const LAP_Vector< T > &a) const
compute the distance between this and a
Definition: LAP_Vector.h:583
static void rotate(LAP_DoubleVector &dx, LAP_DoubleVector &dy, const lapack_real &c, const lapack_real &s)
make a rotation of vector dx= c*dx+s*dy dy=-s*dx+c*dy the view is taken into account drot blas method...
void DoubleVectorScale(const tLVectorIndex &nX, const tLVectorIncrement &incX, double *X, const double &alpha)
Definition: dvector_functions.cpp:130
LAP_DoubleVector & operator*=(const LAP_DoubleVector &s)
division elementt by elementt vector operator
Definition: LAP_DoubleVector.h:175
static void buildRotation(lapack_real &dx, lapack_real &dy, lapack_real &c, lapack_real &s)
build rotation the view is taken into account drotg blas method called
Definition: LAP_DoubleVector.h:341
double product(const LAP_DoubleVector &v) const
return result= the view is taken into account ddot blas method called
Definition: LAP_DoubleVector.h:254
this class describes a vector of double
Definition: LAP_Vector.h:16
void power(const lapack_real &s)
power operator
Definition: LAP_Vector.h:178
double distance2(SPC::LAP_DoubleVector b) const
return the norm2 of (this-b)
Definition: LAP_DoubleVector.h:419
void DoubleVectorCopy(const tLVectorIndex &nx, const tLVectorIncrement &incx, const double *x, const tLVectorIncrement &incy, double *y)
Definition: dvector_functions.cpp:82
static double product(const LAP_DoubleVector &v, const LAP_DoubleVector &w)
Definition: LAP_DoubleVector.h:265
DEFINE_SPTR(LAP_DoubleVector)
LAP_DoubleVector & operator+=(const double &s)
add operator
Definition: LAP_DoubleVector.h:149
static SP::LAP_DoubleVector New(const LAP_DoubleVector &s)
create a new copy of s the view is taken into account
Definition: LAP_DoubleVector.h:74
void add(const lapack_real &alpha, const tLVectorIndex n, const lapack_real *x)
return this+=alpha. x the view is taken into account daxpy blas method called
Definition: LAP_DoubleVector.h:295
virtual void copy(const vector< T > &s)
copy the vector
Definition: LAP_Vector.h:250
LAP_Vector< lapack_real > & divideBy(const LAP_Vector< lapack_real > &s)
division elementt by elementt vector operator
Definition: LAP_Vector.h:225
#define tLVectorIndex
Definition: lapack_types.h:13
virtual tLVectorIndex getNullValuesNumber(const tReal &eps) const
Definition: LAP_DoubleVector.h:136
static SP::LAP_DoubleVector New()
create a new vector of double
Definition: LAP_DoubleVector.h:57
#define tString
Definition: types.h:49
const tLVectorIncrement & getIncrement() const
get the increment of the vector
Definition: LAP_ConstVector.h:175
LAP_DoubleVector & operator-=(const LAP_Vector< lapack_real > &s)
sub vector operator use daxpy blas method
Definition: LAP_DoubleVector.h:207
double DoubleVectorDot(const tLVectorIndex &nX, const tLVectorIncrement &incX, const double *x, const tLVectorIncrement &incY, const double *y)
Definition: dvector_functions.cpp:139
void multiplyBy(const LAP_Vector< lapack_real > &s)
multiplication element by element vector operator
Definition: LAP_Vector.h:208
LAP_DoubleVector & operator=(const lapack_real &s)
copy operator the view is taken into account
Definition: LAP_DoubleVector.h:106
double minValue(tLVectorIndex &i) const
set the i index such that xi is minimum and return its value
Definition: LAP_DoubleVector.h:382
void add(const T &s)
add operator
Definition: LAP_Vector.h:154
LAP_DoubleVector & operator=(const LAP_ConstDoubleVector &s)
copy operator the view is taken into account
Definition: LAP_DoubleVector.h:126
LAP_DoubleVector & operator+=(const LAP_Vector< lapack_real > &s)
add vector operator use daxpy blas method
Definition: LAP_DoubleVector.h:200
double sum() const
return the sum(xi)
Definition: LAP_DoubleVector.h:402
void init(const lapack_real &v)
init the value to v from the view
Definition: LAP_Vector.h:423
static SP::LAP_DoubleVector New(const vector< lapack_real > &vs)
create a new copy of s the view is taken into account
Definition: LAP_DoubleVector.h:95
double distance2(const LAP_DoubleVector &b) const
return the norm2 of (this-b)
Definition: LAP_DoubleVector.h:414
T minValue(tLVectorIndex &i) const
return the min value of the vector and the corresponding index
Definition: LAP_Vector.hpp:35
void copy(const LAP_Vector< lapack_real > &v)
copy the vector v into this. the view is set to [0,v.getSize()[ the viewed values of v is copied into...
Definition: LAP_DoubleVector.h:222
double maxValue(tLVectorIndex &i) const
set the i index such that xi is maximum and return its value
Definition: LAP_DoubleVector.h:377
virtual ~LAP_DoubleVector()
destroy a vector
Definition: LAP_DoubleVector.cpp:19
virtual void copy(const vector< lapack_real > &vs)
copy a vector of real
Definition: LAP_DoubleVector.h:241
Definition: LAP_ConstDoubleVector.h:25
LAP_DoubleVector()
build a vector
Definition: LAP_DoubleVector.cpp:3
#define tReal
Definition: types.h:18
double DoubleVectorNorm1(const tLVectorIndex &nX, const tLVectorIncrement &incX, const double *x)
Definition: dvector_functions.cpp:184
void add(const lapack_real &alpha, const LAP_Vector< lapack_real > &x)
return this+=alpha. x the view is taken into account daxpy blas method called
Definition: LAP_DoubleVector.h:279
void setSize(const tLVectorIndex &n)
set the view to [0,n[ by 1 increment if values is too small, re-alocate it
Definition: LAP_Vector.h:360
#define ASSERT_IN(a)
Definition: types.h:96
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:106