C++ main module for emicrom Package  1.0
MATH_MaskMatrix.h
Go to the documentation of this file.
1 #ifndef MATH_MaskMatrix_H
2 #define MATH_MaskMatrix_H
3 
4 #include "MATH_Matrix.h"
5 
6 #include "CORE_Array.h"
7 
8 #include "MATH_MaskVector.h"
9 
10 
18 
19 class MATH_MaskMatrix : public MATH_Matrix {
21 
22 private:
23 
24 
25 
26 
27 protected:
31 
32  }
33 
34 
35 
36  // DESTRUCTORS
37 
38 
41  virtual ~MATH_MaskMatrix(void) {
42  }
43 
44 public:
45 
46 
47 
48  //SET Methods
49  //===========
50 
51 
52 
53 
54  //GET Methods
55  //===========
56 
57 
58  //arithmetic methods
59  //==================
60 
61 public:
62 
69  virtual void product(const tReal& alpha,const MATH_Vector& x,const tReal& beta, MATH_Vector& y) const {
70  if (beta==0) {
71  product(alpha,x,y);
72  return;
73  }
74 
75  if (alpha==0) {
76  y.dot(beta);
77  return;
78  }
79  //verify the size of X
80  tUIndex nX=x.getSize();
81  if (nX!=getColumnsNumber())
82  throw CORE_Exception("emicrom/math/solver",
83  "MATH_MaskMatrix::product(beta,X,alpha,Y)",
84  "error in dimension of vector X "+CORE_Integer::toString(nX)+" != "+
86 
87  //verify the size of B = size of X
88  tUIndex nY=y.getSize();
89  if (nY!=getRowsNumber())
90  throw CORE_Exception("emicrom/math/solver",
91  "MATH_MaskMatrix::product(beta,X,alpha,Y)",
92  "error in dimension of vector Y "+CORE_Integer::toString(nY)+" != "+
94 
95  //get the increment 1 by default except for mask vector X
96  tUCInt incx=1;
97  tUIndex sx=0;
98  const MATH_MaskVector* mv=dynamic_cast<const MATH_MaskVector*>(&x);
99  if (mv!=null) {
100  incx=mv->getIncrement();
101  sx=mv->getStartIndex();
102  }
103  //get the increment 1 by default except for mask vector Y
104  tUCInt incy=1;
105  tUIndex sy=0;
106  mv=dynamic_cast<const MATH_MaskVector*>(&y);
107  if (mv!=null) {
108  incy=mv->getIncrement();
109  sy=mv->getStartIndex();
110  }
111  const tReal *x0=&x[sx];
112  tReal *y0=&y[sy];
113  if (x0==y0) {
114  throw CORE_Exception("emicrom/math/solver",
115  "MATH_MaskMatrix::product(beta,X,alpha,Y)",
116  "Y pointer must be different from X pointer is not a real field");
117  }
118 
119  //compute the product
120  product(nX,alpha,incx,x0,beta,incy,y0);
121  }
122 
130  virtual void product(const tReal& alpha,const MATH_Vector& x,MATH_Vector& y) const {
131 
132  //pathological cases
133  if (alpha==0) {
134  y.setSize(getRowsNumber());
135  y.init(0);
136  return;
137  }
138 
139  if (alpha==1) {
140  product(x,y);
141  return;
142  }
143 
144  //set the size of y
145  y.setSize(getRowsNumber());
146 
147  //verify the size of X
148  tUIndex nX=x.getSize();
149  if (nX!=getColumnsNumber())
150  throw CORE_Exception("emicrom/math/solver",
151  "MATH_MaskMatrix::product(beta,X,Y)",
152  "error in dimension of vector X: "+CORE_Integer::toString(nX)+" != "+
154 
155  //get the increment 1 by default except for mask vector X
156  tUCInt incx=1;
157  tUIndex sx=0;
158  const MATH_MaskVector* mv=dynamic_cast<const MATH_MaskVector*>(&x);
159  if (mv!=null) {
160  incx=mv->getIncrement();
161  sx=mv->getStartIndex();
162  }
163  //get the increment 1 by default except for mask vector Y
164  tUCInt incy=1;
165  tUIndex sy=0;
166  mv=dynamic_cast<const MATH_MaskVector*>(&y);
167  if (mv!=null) {
168  incy=mv->getIncrement();
169  sy=mv->getStartIndex();
170  }
171 
172  const tReal *x0=&x[sx];
173  tReal *y0=&y[sy];
174  if (x0==y0) {
175  throw CORE_Exception("emicrom/math/solver",
176  "MATH_MaskMatrix::product(alpha,X,Y)",
177  "Y pointer must be different from X pointer is not a real field");
178  }
179  //compute the product
180  product(nX,alpha,incx,x0,0.,incy,y0);
181 
182  }
183 
188  virtual void product(const MATH_Vector& x,MATH_Vector& y) const {
189  //verify the size of X
190  tUIndex nX=x.getSize();
191  if (nX!=getColumnsNumber())
192  throw CORE_Exception("emicrom/math/solver",
193  "MATH_MaskMatrix::product(X,Y)",
194  "error in dimension of vector X "+CORE_Integer::toString(nX)+" != "+
196  //set the size of y
197  y.setSize(getRowsNumber());
198 
199  //get the increment 1 by default except for mask vector X
200  tUCInt incx=1;
201  tUIndex sx=0;
202  const MATH_MaskVector* mv=dynamic_cast<const MATH_MaskVector*>(&x);
203  if (mv!=null) {
204  incx=mv->getIncrement();
205  sx=mv->getStartIndex();
206  }
207  //get the increment 1 by default except for mask vector Y
208  tUCInt incy=1;
209  tUIndex sy=0;
210  mv=dynamic_cast<const MATH_MaskVector*>(&y);
211  if (mv!=null) {
212  incy=mv->getIncrement();
213  sy=mv->getStartIndex();
214  }
215  const tReal *x0=&x[sx];
216  tReal *y0=&y[sy];
217  if (x0==y0) {
218  throw CORE_Exception("emicrom/math/solver",
219  "MATH_MaskMatrix::product(X,Y)",
220  "Y pointer must be different from X pointer is not a real field");
221  }
222  //compute the product
223  product(nX,1.,incx,x0,0.,incy,y0);
224 
225  }
226 protected:
236  virtual void product(const tUIndex& n,
237  const tReal& alpha,
238  const tUSInt& incX,
239  const tReal* x,
240  const tReal& beta,
241  const tUSInt& incY,tReal* y) const=0;
242 
243 
244 
245 };
246 #endif
virtual ~MATH_MaskMatrix(void)
destroy a vector
Definition: MATH_MaskMatrix.h:41
This class describes a general matrix interface used in solver.
Definition: MATH_Matrix.h:20
SP_OBJECT(MATH_MaskMatrix)
virtual tUIndex getRowsNumber() const =0
get the rows number of the matrix
#define tUCInt
Definition: types.h:21
#define tUSInt
Definition: types.h:28
tString toString() const
return the string associated to the integer
Definition: CORE_Integer.h:106
Definition: MATH_MaskVector.h:16
#define null
Definition: types.h:144
virtual void product(const tReal &alpha, const MATH_Vector &x, MATH_Vector &y) const
Y=alpha.T.x where T is this.
Definition: MATH_MaskMatrix.h:130
virtual void product(const tReal &alpha, const MATH_Vector &x, const tReal &beta, MATH_Vector &y) const
y:=alpha T . x + beta Y where T is this
Definition: MATH_MaskMatrix.h:69
virtual void init(const tReal &alpha)
init the value to alpha
Definition: MATH_Vector.cpp:12
this class describes the exceptions raised for CORE package
Definition: CORE_Exception.h:15
This class impements the MATH_MaskMatrix whci deals with mask vector.
Definition: MATH_MaskMatrix.h:19
const tUIndex & getStartIndex() const
get the start index of the vector
Definition: MATH_MaskVector.h:125
virtual tReal dot(const MATH_Vector &x) const
s=x^t.T where T is this
Definition: MATH_Vector.cpp:480
This class describes a masked vector.
Definition: MATH_Vector.h:16
virtual void product(const MATH_Vector &x, MATH_Vector &y) const
b=T.x where T is this
Definition: MATH_MaskMatrix.h:188
const tUSInt & getIncrement() const
get the increment of the vector
Definition: MATH_MaskVector.h:119
MATH_MaskMatrix(void)
create a Mask Matrix
Definition: MATH_MaskMatrix.h:30
virtual tUIndex getSize() const =0
get the utile size of the vector
#define tUIndex
Definition: types.h:126
DEFINE_SPTR(MATH_MaskMatrix)
virtual void setSize(const tUIndex &n)=0
set the size of the vector
virtual tUIndex getColumnsNumber() const =0
get the columns number of the matrix
#define tReal
Definition: types.h:118