30
34
/// This Rmatrix class is the default implementation of the real matrix
31
/// interface. Internally, the matrix is represented as an array of rows.
32
/// Each row is represented as an array of t_real.
35
/// interface. The matrix is designed to support a sparse representation
36
/// the form of blocks aggregation. The block index is obtained from the
37
/// matrix index with the help of field index. The lower index is derived
38
/// from the lower 32 bits while the higher index is derived from the higher
39
/// 32 bits if needed. The implementation automatically adapt itself with
40
/// a 32 bits or 64 bits long integer. The lower 32 bits indexes are derived
41
/// as LB[4] (lower bottom - 4 bits), CB[8] (center-bottom 8 bits), CC[8]
42
/// (center-center 8 bits), CT[8] (center-top - 8 bits) and LT[4] (lower-top
43
/// 4 bits). The upper block (HB) has a variable size.
33
44
/// @author amaury darsch
35
46
class Rmatrix : public Rmi {
37
48
/// generate a random matrix by size
38
49
/// @param size the matrix size
50
/// @param rmin the minimum value
51
/// @param rmax the maximum value
52
static Rmatrix* random (const t_long size, const t_real rmin,
55
/// generate a random matrix by size
56
/// @param size the matrix size
57
/// @param rmin the minimum value
58
/// @param rmax the maximum value
39
59
/// @param ddom the diagonally dominant flag
60
static Rmatrix* random (const t_long size, const t_real rmin,
61
const t_real rmax, const bool ddom);
63
/// generate a sparse matrix by size
64
/// @param size the matrix size
40
65
/// @param rmin the minimum value
41
66
/// @param rmax the maximum value
42
static Rmatrix random (const t_long size, const bool ddom,
43
const t_real rmin, const t_real rmax);
67
/// @param nzsz the non zero size
68
static Rmatrix* sparse (const t_long size, const t_real rmin,
69
const t_real rmax, const t_long nzsz);
45
71
/// add a matrix with another one
46
72
/// @param mx the matrix argument
47
73
/// @param my the matrix argument
96
143
/// @param that the matrix to assign
97
144
Rmatrix& operator = (const Rmatrix& that);
99
/// set a matrix by position
146
/// @return the matrix row barrier
147
t_long getrowb (void) const;
149
/// @return the matrix column barrier
150
t_long getcolb (void) const;
152
/// return true if the matrix is null
153
bool isnil (void) const;
155
/// reset this matrix
158
/// clear this matrix
161
/// clear this matrix lower triangular part
164
/// resize this matrix
165
/// @param rsiz the new matrix row size
166
/// @param csiz the new matrix column size
167
void resize (const t_long rsiz, const t_long csiz);
169
/// compress the matrix if possible
170
bool compress (void);
172
/// create a zero identical matrix
173
Rmi* zeros (void) const;
175
/// copy a matrix row into a vector
176
/// @param row the row to copy
177
Rvi* cpr (const t_long row) const;
179
/// copy a matrix column into a vector
180
/// @param col the column to copy
181
Rvi* cpc (const t_long col) const;
183
/// @return a new iterator for this matrix
184
Iterator* makeit (void);
186
/// permutate this matrix
187
/// @param p the permutation object
188
Rmi* permutate (const Rpi& p) const;
190
/// reverse permutate this matrix
191
/// @param p the permutation object
192
Rmi* reverse (const Rpi& p) const;
195
/// no lock - clear a matrix zone
196
/// @param row the stating row
197
/// @param col the starting column
198
/// @param rsz the row size
199
/// @param csz the column size
200
void nlclear (const t_long row, const t_long col,
201
const t_long rsz, const t_long csz);
203
/// no lock - set a matrix by position
100
204
/// @param row the row position
101
205
/// @param col the column position
102
206
/// @param val the value to set
103
void set (const t_long row, const t_long col, const t_real val);
207
void nlset (const t_long row, const t_long col, const t_real val);
105
/// get a matrix value by position
209
/// no lock - get a matrix value by position
106
210
/// @param row the row position
107
211
/// @param col the column position
108
t_real get (const t_long row, const t_long col) const;
110
/// compare two matrices upto a precision
111
/// @param mx the matrix argument
112
bool cmp (const Rmi& x) const;
114
/// @return the matrix frobenius norm
115
t_real norm (void) const;
117
/// multiply a matrix with a vector and a scaling factor
118
/// @param r the result vector
119
/// @param x the vector argument
120
/// @param s the scaling factor
121
Rvi& mul (Rvi& r, const Rvi& x, const t_real s) const;
124
/// internally multiply a matrix with a vector, no lock
125
/// @param r the result vector
126
/// @param x the vector argument
127
/// @param s the scaling factor
128
Rvector& imul (Rvector& r, const Rvector& x, const t_real s) const;
212
t_real nlget (const t_long row, const t_long col) const;
214
/// no lock - perform a givens matrix update
215
/// @param i the row coordinate
216
/// @param j the column coordinate
217
/// @param c the givens ii/jj coefficient
218
/// @param s the givens ij/ji coefficient
219
/// @param pflg the partial flag
220
void nlgivens (const t_long i, const t_long j, const t_real c,
221
const t_real s, const bool pflg);
224
// make the matrix iterator a friend
225
friend class Rmatrixit;
131
228
/// create a new object in a generic way
132
229
/// @param argv the argument vector
133
230
static Object* mknew (Vector* argv);
232
/// @return true if the given quark is defined
233
bool isquark (const long quark, const bool hflg) const;
135
235
/// operate this object with another object
136
236
/// @param type the operator type
137
237
/// @param object the operand object
138
238
Object* oper (t_oper type, Object* object);
240
/// apply this object with a set of arguments and a quark
241
/// @param robj the current runnable
242
/// @param nset the current nameset
243
/// @param quark the quark to apply these arguments
244
/// @param argv the arguments to apply
245
Object* apply (Runnable* robj, Nameset* nset, const long quark,
249
/// The Rmatrixit class is the iterator for the real matrix class. Such
250
/// iterator is constructed with the "makeit" method. The iterator
251
/// is reset to the beginning of the matrix.
252
/// @author amaury darsch
254
class Rmatrixit : public Rmit {
256
/// the matrix to iterate
260
/// the original move row
262
/// the original move column
264
/// the hb block index
266
/// the lt block index
268
/// the ct block index
270
/// the cc block index
272
/// the cl block index
274
/// the lb block index
276
/// the hb mcnext barrier
278
/// the lt mcnext barrier
280
/// the ct mcnext barrier
282
/// the cc index barrier
284
/// the cb index barrier
286
/// the lb index barrier
288
/// the lt col max barrier
290
/// the ct col max barrier
292
/// the cc col max barrier
294
/// the cb col max barrier
296
/// the lb col max barrier
298
/// the lt col reset barrier
300
/// the ct col reset barrier
302
/// the cc col reset barrier
304
/// the cb col reset barrier
306
/// the lb col reset barrier
310
/// create a new iterator from a matrix
311
/// @param mobj the matrix to iterate
312
Rmatrixit (Rmatrix* vobj);
314
/// create a new iterator by type
315
/// @param mobj the matrix to iterate
316
/// @param rmit the matrix iterator type
317
Rmatrixit (Rmatrix* vobj, const t_rmit rmit);
319
/// destroy this matrix iterator
322
/// @return the class name
323
String repr (void) const;
325
/// reset the iterator to the begining
328
/// reset the iterator to the end
331
/// @return the object at the current position
332
Object* getobj (void) const;
335
/// no lock - move the matrix iterator to the next position
338
/// no lock - move the matrix iterator to the previous position
341
/// @return true if the iterator is at the end (no lock)
342
bool nlend (void) const;
344
/// no lock - move the iterator to a point
345
/// @param row the matrix row coordinate
346
/// @param col the matrix col coordinate
347
void nlmove (const t_long row, const t_long col);
349
/// @return the row coordinate at the iterator position (no lock)
350
t_long nlgrow (void) const;
352
/// @return the column coordinate at the iterator position (no lock)
353
t_long nlgcol (void) const;
355
/// set the matrix at the iterator position (no lock)
356
/// @param val the value to set
357
void nlsval (const t_real val);
359
/// @return the value at the iterator position (no lock)
360
t_real nlgval (void) const;
363
// move the iterator to the next position (no lock)
365
// move the iterator to the next row position (no lock)
367
// move the iterator to the next column position (no lock)
369
// move the iterator to the previous position (no lock)
371
// move the iterator to the previous row position (no lock)
373
// move the iterator to the previous column position (no lock)
377
// make the copy constructor private
378
Rmatrixit (const Rmatrixit&);
379
// make the assignment operator private
380
Rmatrixit& operator = (const Rmatrixit&);