Program listing for file kernel/src/utils/SiconosAlgebra/SimpleMatrix.hpp#
Return to documentation for this file
1#ifndef __SimpleMatrix__
2#define __SimpleMatrix__
3
4#include <iosfwd>
5
6#include "SiconosAlgebraTypeDef.hpp"
7#include "SiconosFwd.hpp"
8#include "SiconosMatrix.hpp"
9#include "SiconosSerialization.hpp"
10#include "SiconosVector.hpp"
11#include "SiconosVisitor.hpp"
12
13class BlockVector;
14
15
16class SimpleMatrix : public SiconosMatrix {
17 protected:
18 ACCEPT_SERIALIZATION(SimpleMatrix);
19
20
21 MATRIX_UBLAS_TYPE mat;
22
23 private:
24
25 SP::VInt _ipiv;
26
27
28 bool _isPLUFactorized = false;
29
30
31 bool _isPLUFactorizedInPlace = false;
32
33
34 bool _isCholeskyFactorized = false;
35
36
37 bool _isCholeskyFactorizedInPlace = false;
38
39
40 bool _isQRFactorized = false;
41
42
43 bool _isPLUInversed = false;
44
45
46 SP::NumericsMatrix _numericsMatrix;
47
48
49
50
51
52
53
54
55
56
57
58 void private_prod(unsigned int startRow, const SiconosVector& x, SiconosVector& y,
59 bool init);
60
61
62 void private_addprod(unsigned int startRow, unsigned int startCol, const SiconosVector& x,
63 SiconosVector& res);
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82 public:
83
84 SimpleMatrix();
85
86
87 SimpleMatrix(unsigned int row, unsigned int col, siconos::UBLAS_TYPE typ = siconos::DENSE,
88 unsigned int upper = 1, unsigned int lower = 1);
89
90
91 SimpleMatrix(unsigned int row, unsigned int col, double inputValue,
92 siconos::UBLAS_TYPE typ = siconos::DENSE, unsigned int upper = 1,
93 unsigned int lower = 1);
94
95
96 SimpleMatrix(const SimpleMatrix& smat);
97
98
99 SimpleMatrix(const SimpleMatrix& A, const Index& coord);
100
101
102 SimpleMatrix(const SiconosMatrix& m);
103
104
105 SimpleMatrix(const DenseMat& m);
106
107
108 SimpleMatrix(const TriangMat& m);
109
110
111 SimpleMatrix(const SymMat& m);
112
113
114 SimpleMatrix(const BandedMat& m);
115
116
117 SimpleMatrix(const SparseMat& m);
118
119
120 SimpleMatrix(const SparseCoordinateMat& m);
121
122
123 SimpleMatrix(const ZeroMat& m);
124
125
126 SimpleMatrix(const IdentityMat& m);
127
128
129 SimpleMatrix(const std::string& file, bool ascii = true);
130
131
132 ~SimpleMatrix();
133
134
135 void updateNumericsMatrix() override;
136
137 NumericsMatrix* numericsMatrix() const override { return _numericsMatrix.get(); };
138
139
140 inline bool isPLUInversed() const override { return _isPLUInversed; }
141
142
143 inline bool isPLUFactorized() const override { return _isPLUFactorized; }
144
145
146 inline bool isPLUFactorizedInPlace() const override { return _isPLUFactorizedInPlace; }
147
148 inline bool isCholeskyFactorized() const override { return _isCholeskyFactorized; }
149
150
151 inline bool isCholeskyFactorizedInPlace() const { return _isCholeskyFactorizedInPlace; }
152
153
154 inline bool isQRFactorized() const { return _isQRFactorized; }
155
156 inline SP::VInt ipiv() const override { return _ipiv; }
157
158 bool checkSymmetry(double tol) const override;
159
160
161 const DenseMat getDense(unsigned int row = 0, unsigned int col = 0) const override;
162
163
164 const TriangMat getTriang(unsigned int row = 0, unsigned int col = 0) const override;
165
166
167 const SymMat getSym(unsigned int row = 0, unsigned int col = 0) const override;
168
169
170 const BandedMat getBanded(unsigned int row = 0, unsigned int col = 0) const override;
171
172
173 const SparseMat getSparse(unsigned int row = 0, unsigned int col = 0) const override;
174
175
176 const SparseCoordinateMat getSparseCoordinate(unsigned int row = 0,
177 unsigned int col = 0) const override;
178
179
180 const ZeroMat getZero(unsigned int row = 0, unsigned int col = 0) const override;
181
182
183 const IdentityMat getIdentity(unsigned int row = 0, unsigned int col = 0) const override;
184
185
186 DenseMat* dense(unsigned int row = 0, unsigned int col = 0) const override;
187
188
189 TriangMat* triang(unsigned int row = 0, unsigned int col = 0) const override;
190
191
192 SymMat* sym(unsigned int row = 0, unsigned int col = 0) const override;
193
194
195 BandedMat* banded(unsigned int row = 0, unsigned int col = 0) const override;
196
197
198 SparseMat* sparse(unsigned int row = 0, unsigned int col = 0) const override;
199
200
201 SparseCoordinateMat* sparseCoordinate(unsigned int row = 0,
202 unsigned int col = 0) const override;
203
204
205 ZeroMat* zero_mat(unsigned int row = 0, unsigned int col = 0) const override;
206
207
208 IdentityMat* identity(unsigned int row = 0, unsigned int col = 0) const override;
209
210
211 double* getArray(unsigned int row = 0, unsigned int col = 0) const override;
212
213
214 void zero() override;
215
216
217 void randomize() override;
218
219
220 void eye() override;
221
222
223 unsigned copyData(double* data) const;
224
225 void assign(const SimpleMatrix& smat);
226
227
228 unsigned int size(unsigned int index) const override;
229
230
231 void resize(unsigned int row, unsigned int col, unsigned int lower = 0,
232 unsigned int upper = 0, bool preserve = true) override;
233
234
235 double normInf() const override;
236
237
238 void normInfByColumn(SP::SiconosVector vIn) const;
239
240
241 double det() const;
242
243
244 void display() const override;
245
246 void displayExpert(bool brief = true) const override;
247
248 std::string toString() const override;
249
250
251 double& operator()(unsigned int i, unsigned int j) override;
252
253
254 double operator()(unsigned int i, unsigned int j) const override;
255
256
257 double getValue(unsigned int i, unsigned int j) const override;
258
259
260 void setValue(unsigned int i, unsigned int j, double value) override;
261
262
263 void setBlock(unsigned int posRow, unsigned int posCol, const SiconosMatrix& m);
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288 void getRow(unsigned int row, SiconosVector& vOut) const override;
289
290
291 void getCol(unsigned int col, SiconosVector& vOut) const override;
292
293
294 void setRow(unsigned int row, const SiconosVector& vIn) override;
295
296
297 void setCol(unsigned int col, const SiconosVector& vIn) override;
298
299
300 void getSubCol(unsigned int index, unsigned int pos, SP::SiconosVector vOut) const;
301
302
303 void getSubRow(unsigned int index, unsigned int pos, SP::SiconosVector vOut) const;
304
305
306 void setSubCol(unsigned int index, unsigned int pos, SP::SiconosVector vIn);
307
308
309 void setSubRow(unsigned int index, unsigned int pos, SP::SiconosVector vIn);
310
311
312 void addBlock(unsigned int i, unsigned int j, const SiconosMatrix& m);
313
314
315 void subBlock(unsigned int i, unsigned int j, const SiconosMatrix& m);
316
317
318 void trans() override;
319
320
321 void trans(const SiconosMatrix& mat) override;
322
323
324 SimpleMatrix& operator=(const SiconosMatrix& m) override;
325
326
327 SimpleMatrix& operator=(const SimpleMatrix& m);
328
329
330 SimpleMatrix& operator=(const DenseMat& m) override;
331
332
333 SimpleMatrix& operator+=(const SiconosMatrix& m) override;
334
335
336 SimpleMatrix& operator-=(const SiconosMatrix& m) override;
337
338
339 void PLUFactorizationInPlace() override;
340
341
342 void Factorize() override;
343
344
345 void PLUInverseInPlace() override;
346
347
348 void PLUForwardBackwardInPlace(SiconosMatrix& B) override;
349 void Solve(SiconosMatrix& B) override;
350
351
352 void PLUForwardBackwardInPlace(SiconosVector& B) override;
353 void Solve(SiconosVector& B) override;
354
355
356 void SolveByLeastSquares(SiconosMatrix& B);
357
358
359 void SolveByLeastSquares(SiconosVector& B);
360
361
362
363 void resetLU() override;
364
365
366
367 void resetCholesky();
368
369
370 void resetQR();
371
372
373 void resetFactorizationFlags() override;
374
375
376 ACCEPT_STD_VISITORS();
377
378 friend std::ostream& operator<<(std::ostream& os, const SimpleMatrix& sm);
379
380 friend const SimpleMatrix operator*(const SiconosMatrix&, double);
381
382 friend SP::SimpleMatrix operator*(const SP::SimpleMatrix, const SP::SimpleMatrix);
383
384 friend void operator+=(SP::SiconosMatrix, SP::SimpleMatrix);
385
386 friend SimpleMatrix operator*(double, const SiconosMatrix&);
387
388 friend const SimpleMatrix operator/(const SiconosMatrix&, double);
389
390 friend const SimpleMatrix operator+(const SiconosMatrix&, const SiconosMatrix&);
391
392 friend SP::SimpleMatrix operator+(const SP::SimpleMatrix, const SP::SimpleMatrix);
393
394 friend void add(const SiconosMatrix&, const SiconosMatrix&, SiconosMatrix&);
395
396 friend const SimpleMatrix operator-(const SiconosMatrix&, const SiconosMatrix&);
397
398 friend void sub(const SiconosMatrix&, const SiconosMatrix&, SiconosMatrix&);
399
400 friend bool operator==(const SiconosMatrix&, const SiconosMatrix&);
401
402 friend bool operator!=(const SiconosMatrix&, const SiconosMatrix&);
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437};
438
439#endif