C++ main module for mmsd Package  1.0
LAP_DoubleFullStorage.h
Go to the documentation of this file.
1 #ifndef LAP_DoubleFullStorage_H
2 #define LAP_DoubleFullStorage_H
3 
5 
6 #include "LAP_Matrix.h"
7 #include "LAP_DoubleVector.h"
9 
10 
11 #include "LAP_2DView.h"
12 
14 
28 
30 
31  SP_OBJECT(LAP_DoubleFullStorage);
32 
33 
34 
35  // ATTRIBUTES
36 public:
37 
38 private:
39 
40  //the size of rows
41  tLVectorIndex mRowSize;
42 
43  // ASSOCIATIONS
46  LAP_2DView mView;
47 
48 
49 
50  // METHOD
51 
52 
53 public:
54  // CONSTRUCTORS
57  mRowSize=0;
58  }
59 
60  // DESTRUCTORS
64  }
65 
66 
67 
68  // -------------
69  // NEW METHODS
70  // -------------
71 public:
72 
75  inline static SP::LAP_DoubleFullStorage New() {
76  SP::LAP_DoubleFullStorage p(new LAP_DoubleFullStorage(),
78  p->setThis(p);
79  return p;
80  };
81 
82  //-----------
83  // OPERATORS
84  // ----------
87  virtual double& operator()(const tLVectorIndex& i,const tLVectorIndex& j) {
88  return (*this)[mRowSize*getViewIndex(LAP_Matrix::COL,j)+getViewIndex(LAP_Matrix::ROW,i)];
89  };
90 
93  virtual const double& operator()(const tLVectorIndex& i,const tLVectorIndex& j) const {
94  return (*this)[mRowSize*getViewIndex(LAP_Matrix::COL,j)+getViewIndex(LAP_Matrix::ROW,i)];
95  };
96 
97  //scalar operators
98  //================
101  LAP_DoubleFullStorage& operator*=(const double& s);
104  LAP_DoubleFullStorage& operator/=(const double& s);
107  LAP_DoubleFullStorage& operator+=(const double& s);
110  LAP_DoubleFullStorage& operator-=(const double& s);
113  LAP_DoubleFullStorage& operator^=(const double& s);
114 
115  //full matrix operator
116  //====================
117 
121 
131 
132 
133 
134 
135  // ----------------
136  // MATRIX SETTINGS
137  // ----------------
138 public:
139 
140 
143  virtual tBoolean copy(const tBoolean& isSymmetric,
144  const tBoolean& isUpper,
145  const tBoolean& isTransposed,
146  const LAP_DoubleMatrixStorage& x);
147 
150  tBoolean copyFullStorage(const tBoolean& isSymmetric,
151  const tBoolean& isUpper,
152  const tLVectorIndex &nViewedRows,
153  const tLVectorIndex &nViewedCols,
154  const tLVectorIncrement& incx,
155  const tLVectorIndex &ldx,
156  const double * x);
159  tBoolean copyPackStorage(const tBoolean& isSymmetric,
160  const tBoolean& isUpper,
161  const tLVectorIndex &nX,
162  const double * x);
163 
166  tBoolean copyBandStorage(const tBoolean& isSymmetric,
167  const tBoolean& isUpper,
168  const tLVectorIndex &nX,
169  const tLVectorIndex &nUpperBands,
170  const tLVectorIndex &nLowerBands,
171  const double * x);
172 
173 
174  //set the values from vectors
175  //===========================
176 
177 public:
180  virtual void setValuesPointer(SP::LAP_DoubleVector v) {
181  mRowSize=(tLVectorIndex) (sqrt(v->getSize())+0.5);
183  resetView();
184  }
185 
188  virtual void setValuesPointer(const tLVectorIndex& rowSize,SP::LAP_DoubleVector v) {
189  mRowSize=rowSize;
191  resetView();
192  }
195  virtual void setValues(const tLVectorIndex& n,
196  const double* values) {
197  mRowSize=(tLVectorIndex) (sqrt(n)+0.5);
199  resetView();
200  }
203  virtual void setValues(const tLVectorIndex& rowSize,
204  const tLVectorIndex& n,
205  const double* values) {
206  mRowSize=rowSize;
208  resetView();
209  }
210 
213  virtual void setValuesNumber(const tLVectorIndex& nRows,const tLVectorIndex& n) {
214  mRowSize=nRows;
216  resetView();
217  };
218 
221  virtual void setValuesNumber(const tLVectorIndex& n) {
222  mRowSize=(tLVectorIndex) (sqrt(n)+0.5);
224  resetView();
225  };
226 
227 
228 
229  // view setting
230  // =============
235  inline tBoolean setView(const tFlag& k,
236  const tLVectorIndex& start,
237  const tLVectorIndex& end,
238  const tLVectorIndex& increment) {
239  tLVectorIndex s=mRowSize;
240  if (k!=0) s=getValuesNumber()/mRowSize;
241 
242  if (increment==0) return false;
243  if (end<start) return false;
244  if (end-increment>s) return false;
245  mView[k].setView(start,end,increment);
246  return true;
247  };
248 
251  inline void resetView() {
252  mView.setView(LAP_Matrix::ROW,0,mRowSize,1);
253  mView.setView(LAP_Matrix::COL,0,getValuesNumber()/mRowSize,1);
254  };
255  // view getting
256  // =============
260  inline tLVectorIndex getViewSize(const tFlag& d) const {
261  return mView.getSize(d);
262  };
266  inline const tLVectorIncrement& getIncrement(const tFlag& d) const {
267  return mView.getIncrement(d);
268  };
272  inline const tLVectorIndex& getStart(const tFlag& d) const {
273  return mView.getStart(d);
274  };
279  inline tLVectorIndex getViewIndex(const tLVectorIndex& k,const tLVectorIndex& i) const {
280  return (mView[k].getStart()+i*mView[k].getIncrement());
281  }
282 
287  };
292  };
293 
297  return mRowSize*getIncrement(LAP_Matrix::COL);
298  }
303  }
304 
307  inline tBoolean isSubmatrixView() const {
308  return
309  (mView[LAP_Matrix::ROW].getStart()!=0) ||
310  (mView[LAP_Matrix::ROW].getEnd()!=mRowSize) ||
311  (mView[LAP_Matrix::COL].getStart()!=0) ||
312  (mView[LAP_Matrix::COL].getEnd()!=getValuesNumber()/mRowSize);
313 
314  };
315 
316 
317  //values getting
318  // =============
319 
320 
323  inline tLVectorIndex getRowSize() const {
324  return mRowSize;
325  }
326 
327 
330  virtual void addDiagonal(const double& alpha);
331 
334  virtual double trace() const;
335 
339  virtual void getRowByReference(const tLVectorIndex& i,LAP_DoubleVector& v);
343  virtual void getRowByReference(const tLVectorIndex& i,LAP_ConstDoubleVector& v) const;
344 
348  virtual void getColumnByReference(const tLVectorIndex& j,LAP_DoubleVector& v);
352  virtual void getColumnByReference(const tLVectorIndex& j,LAP_ConstDoubleVector& v) const;
355  void removeColumn(const tLVectorIndex& j);
356 
359  void reverseColumns();
362  void swapColumns(const tLVectorIndex& i,const tLVectorIndex& j);
363 
364  // Merging methods
365  // ===============
366 
370  inline void concat(const double& alpha,const LAP_DoubleFullStorage& X,
371  const double& beta, const LAP_DoubleFullStorage& Y) {
372 
373  getValues().merge(alpha,X.getValues(),beta,Y.getValues());
374  }
375 
376 
377  // ------------------------
378  // operation on matrix
379  // ------------------------
380 public:
381 
382  /* \brief compute the bands number
383  * @param eps:absolute module to detect null value
384  * @return a pair whose firest element is the number of upper bands and the second the lower bands number
385  */
386  virtual pair<tLVectorIndex,tLVectorIndex> computeBandsNumber() const;
387  /* \brief compute the bands number
388  * @param eps:absolute module to detect null value
389  * @return a pair whose firest element is the number of upper bands and the second the lower bands number
390  */
391  static pair<tLVectorIndex,tLVectorIndex> computeBandsNumber(const tBoolean& isUpper,
392  const tLVectorIndex& nRows,
393  const tLVectorIndex& nCols,
394  const tLVectorIncrement& inc,
395  const tLVectorIndex& ldx,
396  const double* x,
397  const tReal& eps);
398 
399 
400  //operator with packed storage
401  //============================
404  LAP_DoubleFullStorage& multiplyBy(const tBoolean& isPackedSymmetric,const LAP_DoublePackedStorage& s);
405 
408  LAP_DoubleFullStorage& divideBy(const tBoolean& isPackedSymmetric,const LAP_DoublePackedStorage& s);
411  LAP_DoubleFullStorage& add(const tBoolean& isPackedSymmetric,const LAP_DoublePackedStorage& s);
414  LAP_DoubleFullStorage& sub(const tBoolean& isPackedSymmetric,const LAP_DoublePackedStorage& s);
415 
416 
417 
418 };
419 #endif
LAP_DoubleFullStorage & multiplyBy(const tBoolean &isPackedSymmetric, const LAP_DoublePackedStorage &s)
multiply the matrices viewed term by term taking into account the view
Definition: LAP_DoubleFullStorage.cpp:701
tLVectorIndex getViewIndex(const tLVectorIndex &k, const tLVectorIndex &i) const
get the view index of col or row
Definition: LAP_DoubleFullStorage.h:279
this class describes a packed storage by column
Definition: LAP_DoublePackedStorage.h:21
virtual void setValuesPointer(SP::LAP_DoubleVector v)
set the vector values by reference
Definition: LAP_DoubleMatrixStorage.h:132
static const tFlag COL
Definition: LAP_Matrix.h:22
Definition: LAP_DoubleVector.h:20
const tLVectorIncrement & getRowIncrement() const
get the row increment ie the memory distance between M(i,j) & M(i+1,j)
Definition: LAP_DoubleFullStorage.h:301
virtual ~LAP_DoubleFullStorage()
destroy a matrix
Definition: LAP_DoubleFullStorage.h:63
virtual tLVectorIndex getViewedRowsNumber() const
get the lines number of the matrix from view
Definition: LAP_DoubleFullStorage.h:285
tBoolean copyPackStorage(const tBoolean &isSymmetric, const tBoolean &isUpper, const tLVectorIndex &nX, const double *x)
copy packed storage
Definition: LAP_DoubleFullStorage.cpp:153
void resetView()
reset view
Definition: LAP_DoubleFullStorage.h:251
#define tBoolean
Definition: types.h:48
tBoolean isSubmatrixView() const
return true if the matrix is the sub matrix view
Definition: LAP_DoubleFullStorage.h:307
static const tFlag ROW
Definition: LAP_Matrix.h:21
void removeColumn(const tLVectorIndex &j)
remove the column at index j
Definition: LAP_DoubleFullStorage.cpp:1128
virtual void addDiagonal(const double &alpha)
add alpha to the diagnal element
Definition: LAP_DoubleFullStorage.cpp:977
const tLVectorIndex & getStart(const tFlag &d) const
get the start index of the view of the matrix
Definition: LAP_DoubleFullStorage.h:272
LAP_DoubleFullStorage & add(const tBoolean &isPackedSymmetric, const LAP_DoublePackedStorage &s)
add the matrices viewed term by term taking into account the view
Definition: LAP_DoubleFullStorage.cpp:845
tLVectorIndex getRowSize() const
get rows number
Definition: LAP_DoubleFullStorage.h:323
virtual void getRowByReference(const tLVectorIndex &i, LAP_DoubleVector &v)
get the row by reference the values of v pointer to the values of the column j of this ...
Definition: LAP_DoubleFullStorage.cpp:1038
virtual void setValuesNumber(const tLVectorIndex &n)
set the values number
Definition: LAP_DoubleMatrixStorage.h:155
virtual void setValues(const tLVectorIndex &n, const double *values)
copy the values to the matrix values
Definition: LAP_DoubleFullStorage.h:195
tBoolean copyBandStorage(const tBoolean &isSymmetric, const tBoolean &isUpper, const tLVectorIndex &nX, const tLVectorIndex &nUpperBands, const tLVectorIndex &nLowerBands, const double *x)
copy banded storage
Definition: LAP_DoubleFullStorage.cpp:207
LAP_DoubleFullStorage & operator^=(const double &s)
sub s to the matrix viewed term by term taking into account the view
Definition: LAP_DoubleFullStorage.cpp:352
DEFINE_SPTR(LAP_DoubleFullStorage)
virtual const double & operator()(const tLVectorIndex &i, const tLVectorIndex &j) const
accessor of element at row i and column j
Definition: LAP_DoubleFullStorage.h:93
void swapColumns(const tLVectorIndex &i, const tLVectorIndex &j)
swap the column i & j
Definition: LAP_DoubleFullStorage.cpp:1175
void merge(const T &alpha, const LAP_Vector< T > &x, const T &beta, const LAP_Vector< T > &y)
this is the merging of 2 vectors This = [alpha.x,beta.y]
Definition: LAP_Vector.hpp:96
tBoolean setView(const tFlag &k, const tLVectorIndex &start, const tLVectorIndex &end, const tLVectorIndex &increment)
set the the view the row/column element considered are in [start,end[ with increment inc ...
Definition: LAP_DoubleFullStorage.h:235
LAP_DoubleFullStorage & divideBy(const tBoolean &isPackedSymmetric, const LAP_DoublePackedStorage &s)
divide the matrices viewed term by term taking into account the view
Definition: LAP_DoubleFullStorage.cpp:770
virtual void setValuesNumber(const tLVectorIndex &nRows, const tLVectorIndex &n)
set the values number
Definition: LAP_DoubleFullStorage.h:213
virtual tLVectorIndex getViewedColumnsNumber() const
get the columns number of the matrix from view
Definition: LAP_DoubleFullStorage.h:290
void setView(const tFlag &k, const tLVectorIndex &start, const tLVectorIndex &end, const tLVectorIncrement &inc)
set the indices in direction k
Definition: LAP_2DView.h:97
void reverseColumns()
reverese the column order
Definition: LAP_DoubleFullStorage.cpp:1136
virtual void setValuesPointer(const tLVectorIndex &rowSize, SP::LAP_DoubleVector v)
set the values of without copying
Definition: LAP_DoubleFullStorage.h:188
virtual double & operator()(const tLVectorIndex &i, const tLVectorIndex &j)
accessor of element at row i and column j taking into account the row
Definition: LAP_DoubleFullStorage.h:87
Definition: LAP_DoubleFullStorage.h:29
virtual double trace() const
return the sum of the diagonal element
Definition: LAP_DoubleFullStorage.cpp:1005
virtual void setValues(const tLVectorIndex &rowSize, const tLVectorIndex &n, const double *values)
copy the values to the matrix values without taking account of the view
Definition: LAP_DoubleFullStorage.h:203
const tLVectorIndex & getStart(const tFlag &d) const
get the start index in direction k
Definition: LAP_2DView.h:122
tLVectorIndex getValuesNumber() const
get the number of values
Definition: LAP_DoubleMatrixStorage.h:178
LAP_DoubleFullStorage & operator/=(const double &s)
divide by s the matrix viewed term by term taking into account the view
Definition: LAP_DoubleFullStorage.cpp:449
virtual tBoolean copy(const tBoolean &isSymmetric, const tBoolean &isUpper, const tBoolean &isTransposed, const LAP_DoubleMatrixStorage &x)
copy he viewed terms of the matrix to this
Definition: LAP_DoubleFullStorage.cpp:12
#define tLVectorIndex
Definition: lapack_types.h:13
const tLVectorIncrement & getIncrement(const tFlag &d) const
get increment in direction k
Definition: LAP_2DView.h:117
const tLVectorIndex & getEnd(const tFlag &d) const
get the end index in direction k
Definition: LAP_2DView.h:127
LAP_DoubleFullStorage & operator*=(const double &s)
multiply by s the matrix viewed term by term taking into account the view
Definition: LAP_DoubleFullStorage.cpp:420
const LAP_DoubleVector & getValues() const
get the vector values of the matrix
Definition: LAP_DoubleMatrixStorage.h:197
LAP_DoubleFullStorage & operator+=(const double &s)
add s to the matrix viewed term by term taking into account the view
Definition: LAP_DoubleFullStorage.cpp:460
LAP_DoubleFullStorage()
build a matrix
Definition: LAP_DoubleFullStorage.h:56
virtual pair< tLVectorIndex, tLVectorIndex > computeBandsNumber() const
compute the bands number of the storage
Definition: LAP_DoubleFullStorage.cpp:1202
virtual void setValuesNumber(const tLVectorIndex &n)
set the values number
Definition: LAP_DoubleFullStorage.h:221
This class is a matrix view.
Definition: LAP_2DView.h:14
virtual void setValuesPointer(SP::LAP_DoubleVector v)
set the values of without copying
Definition: LAP_DoubleFullStorage.h:180
static SP::LAP_DoubleFullStorage New()
create a new full storage class
Definition: LAP_DoubleFullStorage.h:75
tBoolean copyFullStorage(const tBoolean &isSymmetric, const tBoolean &isUpper, const tLVectorIndex &nViewedRows, const tLVectorIndex &nViewedCols, const tLVectorIncrement &incx, const tLVectorIndex &ldx, const double *x)
copy full storage
Definition: LAP_DoubleFullStorage.cpp:49
LAP_DoubleFullStorage & sub(const tBoolean &isPackedSymmetric, const LAP_DoublePackedStorage &s)
sub the matrices viewed term by term taking into account the view
Definition: LAP_DoubleFullStorage.cpp:910
virtual void getColumnByReference(const tLVectorIndex &j, LAP_DoubleVector &v)
get the column by reference the values of v pointer to the values of the column j of this ...
Definition: LAP_DoubleFullStorage.cpp:1097
LAP_DoubleFullStorage & operator-=(const double &s)
sub s to the matrix viewed term by term taking into account the view
Definition: LAP_DoubleFullStorage.cpp:487
#define tLVectorIncrement
Definition: lapack_types.h:16
tLVectorIndex getLeadingDimension() const
get the leading dimension ie the memory distance between M(i,j) & M(i,j+1)
Definition: LAP_DoubleFullStorage.h:296
Definition: LAP_ConstDoubleVector.h:25
Definition: LAP_DoubleMatrixStorage.h:16
#define tReal
Definition: types.h:18
const tLVectorIncrement & getIncrement(const tFlag &d) const
get the increment of the view of the matrix
Definition: LAP_DoubleFullStorage.h:266
tLVectorIndex getSize(const tFlag &d) const
Definition: LAP_2DView.h:133
void concat(const double &alpha, const LAP_DoubleFullStorage &X, const double &beta, const LAP_DoubleFullStorage &Y)
concat This-> [alpha X, beta Y] add the colmuns of Y to the columns of X to becomes A ...
Definition: LAP_DoubleFullStorage.h:370
virtual void setValues(const tLVectorIndex &n, const double *values)
copy the values
Definition: LAP_DoubleMatrixStorage.h:145
tLVectorIndex getViewSize(const tFlag &d) const
get the length of the view of the matrix
Definition: LAP_DoubleFullStorage.h:260
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:106
#define tFlag
Definition: types.h:14