C++ main module for mmsd Package  1.0
LAP_DoubleMatrixStorage.h
Go to the documentation of this file.
1 #ifndef LAP_MatrixStorage_H
2 #define LAP_MatrixStorage_H
3 
4 #include "LAP_Matrix.h"
5 #include "LAP_DoubleVector.h"
6 
7 
15 
17 
18  SP_OBJECT(LAP_DoubleMatrixStorage);
19 
20 public:
21  // ATTRIBUTES
22 
23 
24 
25  // to define zero value
26 
27 
28 private:
29  // ASSOCIATIONS
30 
31 
32 
35  SP::LAP_DoubleVector mValues;
36  // METHODS
37 
38 
39 protected:
40  // CONSTRUCTORS
43  mValues=LAP_DoubleVector::New();
44  }
45 
46 
47 
48 
49 
50  // DESTRUCTORS
54  }
55 
56 
57 
58 public:
59 
60  //-----------
61  // OPERATORS
62  // ----------
63 public:
64 
68  inline const double& operator[](const tLVectorIndex& index) const {
69  return (*mValues.get())[index];
70  };
74  inline double& operator[](const tLVectorIndex& index) {
75  return (*mValues.get())[index];
76  };
79  virtual double& operator()(const tLVectorIndex& i,const tLVectorIndex& j)=0;
80 
83  virtual const double& operator()(const tLVectorIndex& i,const tLVectorIndex& j) const=0;
84 
85  //copy method
86  //===========
87 
91  virtual tBoolean copy(const tBoolean& isSymmetric,
92  const tBoolean& isUpper,
93  const tBoolean& isTransposed,
94  const LAP_DoubleMatrixStorage& x) {
95  try {
96  getValues().copy(x.getValues());
97  } catch(std::exception e) {
98  cout << e.what()<<"\n";
99  return false;
100  }
101  return true;
102  }
103 
104 
105 
106  // ----------------
107  // MATRIX SETTINGS
108  // ----------------
109 
110 public:
111 
112 
113 public:
114 
115 
116 
117 
118 
119  //values settings
120  //===============
124  void init(const double& v) {
125  LAP_DoubleVector* vs=mValues.get();
126  if (vs!=null) vs->init(v);
127  }
128 
132  virtual void setValuesPointer(SP::LAP_DoubleVector v) {
133  if (v.get()==null)
134  throw CORE_Exception("math/linalg/core",
135  "LAP_DoubleMatrixStorage::setValuesPointer()",
136  "can not set a null values of a matrix");
137 
138  mValues=v;
139  };
140 
145  virtual void setValues(const tLVectorIndex& n,
146  const double* values) {
147  getValues().setValues(n,values);
148  }
149 
150  // dimension of values settings
151  // ===========================
155  virtual void setValuesNumber(const tLVectorIndex& n) {
156  getValues().setSize(n);
157  };
158 
159 
160 
161  // GET
162  // ===
166  tLVectorIndex i,n=mValues->getSize();
167  const double *vs=&(*mValues.get())[0];
168  tLVectorIndex s=0;
169  for (i=0;i<n;i++) {
170  if (fabs(*vs)<ZERO_EPSILON) s++;
171  vs++;
172  }
173  return s;
174  }
175 
179  return mValues->getSize();
180  }
183  inline tLVectorIndex getCapacity() const {
184  return mValues->getCapacity();
185  }
186 
189  inline double getFillRate() const {
190  return ((int) ((1.-((double)getNullValuesNumber())/((double)getValuesNumber()))*100000))/1000.;
191  }
192 
193 
194 
197  inline const LAP_DoubleVector& getValues() const {
198  return *mValues.get();
199  }
203  return *mValues.get();
204  };
205 
206  /* \brief get the vector values of the matrix as a shared pointer
207  */
208  virtual void getValuesPointer(SP::LAP_DoubleVector& v) {
209  v=mValues;
210  }
211 
212 
213 
214 
215  //computation method
218  virtual double trace() const=0;
219 
223  virtual void addDiagonal(const double& alpha)=0;
224 
230  virtual pair<tLVectorIndex,tLVectorIndex> computeBandsNumber() const=0;
231 
232 
233 
234 };
235 
236 #endif
LAP_DoubleVector & getValues()
get the vector values of the matrix
Definition: LAP_DoubleMatrixStorage.h:202
virtual double & operator()(const tLVectorIndex &i, const tLVectorIndex &j)=0
accessor of element at row i and column j taking into account the row
virtual double trace() const =0
compute the trace of the storage
virtual ~LAP_DoubleMatrixStorage()
destroy a matrix
Definition: LAP_DoubleMatrixStorage.h:53
virtual void setValuesPointer(SP::LAP_DoubleVector v)
set the vector values by reference
Definition: LAP_DoubleMatrixStorage.h:132
LAP_DoubleMatrixStorage()
build a matrix
Definition: LAP_DoubleMatrixStorage.h:42
Definition: LAP_DoubleVector.h:20
double getFillRate() const
get the fill rate of the matrix
Definition: LAP_DoubleMatrixStorage.h:189
#define tBoolean
Definition: types.h:48
static double ZERO_EPSILON
Definition: LAP_Object.h:21
#define null
Definition: types.h:13
tLVectorIndex getCapacity() const
get the capacity of values
Definition: LAP_DoubleMatrixStorage.h:183
void init(const double &v)
init the values
Definition: LAP_DoubleMatrixStorage.h:124
virtual void setValuesNumber(const tLVectorIndex &n)
set the values number
Definition: LAP_DoubleMatrixStorage.h:155
virtual void addDiagonal(const double &alpha)=0
add alpha to diagonal
virtual void getValuesPointer(SP::LAP_DoubleVector &v)
Definition: LAP_DoubleMatrixStorage.h:208
const double & operator[](const tLVectorIndex &index) const
get the value at index for reading
Definition: LAP_DoubleMatrixStorage.h:68
this class describes the exceptions raised for CORE package
Definition: CORE_Exception.h:15
This class is the base class of all lapack objects.
Definition: LAP_Object.h:17
virtual pair< tLVectorIndex, tLVectorIndex > computeBandsNumber() const =0
compute the bands number of the storage
virtual tBoolean copy(const tBoolean &isSymmetric, const tBoolean &isUpper, const tBoolean &isTransposed, const LAP_DoubleMatrixStorage &x)
copy the storage
Definition: LAP_DoubleMatrixStorage.h:91
tLVectorIndex getValuesNumber() const
get the number of values
Definition: LAP_DoubleMatrixStorage.h:178
#define tLVectorIndex
Definition: lapack_types.h:13
static SP::LAP_DoubleVector New()
create a new vector of double
Definition: LAP_DoubleVector.h:57
const LAP_DoubleVector & getValues() const
get the vector values of the matrix
Definition: LAP_DoubleMatrixStorage.h:197
void init(const T &v)
init the value to v from the view
Definition: LAP_Vector.h:423
void setValues(const tLVectorIndex &n, T *&values, const tBoolean &isReferenced)
Definition: LAP_Vector.h:270
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
virtual const T & get(const tLVectorIndex &i) const
get element at index i taking into account the view
Definition: LAP_Vector.h:513
Definition: LAP_DoubleMatrixStorage.h:16
double & operator[](const tLVectorIndex &index)
get the value at index fro writing
Definition: LAP_DoubleMatrixStorage.h:74
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
virtual void setValues(const tLVectorIndex &n, const double *values)
copy the values
Definition: LAP_DoubleMatrixStorage.h:145
virtual tLVectorIndex getNullValuesNumber() const
get the number of null values
Definition: LAP_DoubleMatrixStorage.h:165
DEFINE_SPTR(LAP_DoubleMatrixStorage)