GammaLib 2.1.0.dev
Loading...
Searching...
No Matches
GMatrixSparse.hpp
Go to the documentation of this file.
1/***************************************************************************
2 * GMatrixSparse.hpp - Sparse matrix class *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2006-2025 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- *
6 * *
7 * This program is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19 * *
20 ***************************************************************************/
21/**
22 * @file GMatrixSparse.hpp
23 * @brief Sparse matrix class definition
24 * @author Juergen Knoedlseder
25 */
26
27#ifndef GMATRIXSPARSE_HPP
28#define GMATRIXSPARSE_HPP
29
30/* __ Includes ___________________________________________________________ */
31#include <string>
32#include "GMatrixBase.hpp"
33
34/* __ Definitions ________________________________________________________ */
35#define G_SPARSE_MATRIX_DEFAULT_MEM_BLOCK 512 // Default Memory block size
36#define G_SPARSE_MATRIX_DEFAULT_STACK_ENTRIES 1000 // Max # of stack entries
37#define G_SPARSE_MATRIX_DEFAULT_STACK_SIZE 512 // Max # of stack elements
38
39/* __ Forward declarations _______________________________________________ */
40class GMatrix;
42class GMatrixSparse;
43class GVector;
44class GVectorSparse;
45class GSparseSymbolic;
46class GSparseNumeric;
47
48
49/***********************************************************************//**
50 * @class GMatrixSparse
51 *
52 * @brief Sparse matrix class interface definition
53 *
54 * This class implements a sparse matrix. The class only stores non-zero
55 * elements, which can considerably reduce the memory requirements for large
56 * systems that are sparsely filled. Also the computations will be faster
57 * because only non-zero elements will be used in the operations.
58 *
59 * For a description of the common matrix methods, please refer to the
60 * GMatrixBase class.
61 *
62 * The class has been inspired from the code CSparse that can be downloaded
63 * from http://www.cise.ufl.edu/research/sparse/CSparse/ which has been
64 * written by Timothy A. Davis to accompany his book "Direct Methods for
65 * Sparse Linear Systems". In the CSparse code, a sparse matrix is
66 * implemented by the structure cs_sparse. The members of this
67 * structure map as follows to the members of the GMatrixSparse class:
68 *
69 * <table border>
70 * <tr>
71 * <td><b>CSparse</b></td>
72 * <td><b>GMatrixSparse</b></td>
73 * <td><b>Dimension</b></td>
74 * <td><b>Description</b></td>
75 * </tr>
76 * <tr>
77 * <td>nzmax</td>
78 * <td>m_elements</td>
79 * <td>n.a.</td>
80 * <td>Maximum number of entries</td>
81 * </tr>
82 * <tr>
83 * <td>m</td>
84 * <td>m_rows</td>
85 * <td>n.a.</td>
86 * <td>Number of rows</td>
87 * </tr>
88 * <tr>
89 * <td>n</td>
90 * <td>m_cols</td>
91 * <td>n.a.</td>
92 * <td>Number of columns</td>
93 * </tr>
94 * <tr>
95 * <td>*p</td>
96 * <td>*m_colstart</td>
97 * <td>m_cols+1</td>
98 * <td>Column pointers (index of first element of each column in
99 * m_data array)</td>
100 * </tr>
101 * <tr>
102 * <td>*i</td>
103 * <td>*m_rowinx</td>
104 * <td>m_elements</td>
105 * <td>Row indices for all non-zero elements</td>
106 * </tr>
107 * <tr>
108 * <td>*x</td>
109 * <td>*m_data</td>
110 * <td>m_elements</td>
111 * <td>Numerical values of all non-zero elements</td>
112 * </tr>
113 * </table>
114 *
115 * Matrix allocation is done using the constructors
116 *
117 * GMatrixSparse sparsematrix(rows, columns);
118 * GMatrixSparse sparsematrix(rows, columns, elements);
119 * GMatrixSparse sparsematrix(matrix);
120 * GMatrixSparse sparsematrix(sparsematrix);
121 * GMatrixSparse sparsematrix(symmetricmatrix);
122 *
123 * where @p rows and @p columns specify the number of rows and columns of
124 * the matrix and @p elements is the size of the memory that should be
125 * pre-allocated for matrix storage (optional). Storage conversion
126 * constructors exist that allow allocating a sparse matrix by copying from
127 * a general matrix of type GMatrix and a symmetric matrix of type
128 * GMatrixSymmetric.
129 *
130 * Because the location of a specific matrix element is not necessarily known
131 * in advance, the class implements a so called pending element for matrix
132 * element setting. A pending element is an element that is scheduled for
133 * insertion in the matrix, but which has not yet been inserted. The matrix
134 * element access operators () and at() return the reference to this pending
135 * element if a memory location for a given row and column does not yet
136 * exist. The protected method fill_pending() is then called before all
137 * operations that are done on the matrix to insert the element before the
138 * operation is executed.
139 *
140 * Another mechanism that has been implemented to speed up the fill of the
141 * sparse matrix is a "fill stack" that is used for insertion or addition
142 * of matrix columns by the
143 *
144 * matrix.column(index, vector);
145 * matrix.column(index, values, rows, number);
146 * matrix.add_to_column(index, vector);
147 * matrix.add_to_column(index, values, rows, number);
148 *
149 * methods. The fill stack is a buffer that implements a queue for columns
150 * that are to be inserted into the matrix. This is more efficient than
151 * insertion of elements one by one, as every insertion of an element may
152 * require to shift all elements back by one memory location.
153 *
154 * The fill stack is used as follows:
155 *
156 * matrix.stack_init(size, entries);
157 * ...
158 * matrix.column(index, vector); // (or one of the other column methods)
159 * ...
160 * matrix.stack_flush();
161 * ...
162 * matrix.stack_destroy();
163 *
164 * The stack_init(size, entries) method initialises the fill stack, where
165 * @p size is the size of the allocated memory buffer and @p entries is the
166 * maximum number of entries (i.e. columns) that will be held by the buffer.
167 * If @p size is set to 0 (the default value), a default @p size value of
168 * 512 is used. If @p entries is set to 0 (the default value), the number of
169 * matrix columns is taken as default @p entries value. Note that a too large
170 * number of elements will produce some overhead due to fill stack
171 * management, hence @p entries should not exceed a value of the order of
172 * 10-100.
173 *
174 * The stack_flush() method flushes the stack, which is mandatory before any
175 * usage of the matrix. Note that the fill stack IS NOT INSERTED AUTOMATICALLY
176 * before any matrix operation, hence manual stack flushing is needed to make
177 * all filled matrix elements available for usage. The stack_destroy() method
178 * will flush the stack and free all stack elements. This method
179 * should be called once no filling is required anymore. If stack_destroy()
180 * is called immediately after filling, no call to stack_flush() is needed as
181 * the stack_destroy() method flushes the stack before destroying it. The
182 * matrix stack is also destroyed by the sparse matrix destructor, hence
183 * manual stack destruction is not mandatory.
184 *
185 * Except for *m_rowinx which is implemented on the level of GMatrixSparse,
186 * all other members are implemented by the base class GMatrixBase.
187 ***************************************************************************/
189
190 // Friend classes
191 friend class GSparseSymbolic;
192 friend class GSparseNumeric;
193
194 // Some friend functions that we should not expose ... but I don't
195 // know what to do with them as they are also needed by GSparseSymbolic,
196 // yet they have to access low-level stuff from the matrix class, hence
197 // they need to be friends ...
198 friend GMatrixSparse cs_symperm(const GMatrixSparse& matrix, const int* pinv);
199 friend GMatrixSparse cs_transpose(const GMatrixSparse& matrix, int values);
200 friend double cs_cumsum(int* p, int* c, int n);
201
202public:
203 // Constructors and destructors
204 GMatrixSparse(void);
205 explicit GMatrixSparse(const int& rows, const int& columns,
206 const int& elements = 0);
207 GMatrixSparse(const GMatrix& matrix);
208 GMatrixSparse(const GMatrixSparse& matrix);
209 GMatrixSparse(const GMatrixSymmetric& matrix);
210 virtual ~GMatrixSparse(void);
211
212 // Implemented pure virtual base class operators
213 virtual double& operator()(const int& row, const int& column);
214 virtual const double& operator()(const int& row, const int& column) const;
215 virtual GVector operator*(const GVector& vector) const;
216
217 // Overloaded virtual base class operators
218 virtual bool operator==(const GMatrixSparse& matrix) const;
219 virtual bool operator!=(const GMatrixSparse& matrix) const;
220
221 // Other operators
222 virtual GMatrixSparse& operator=(const GMatrixSparse& matrix);
223 virtual GMatrixSparse& operator=(const double& value);
224 virtual GMatrixSparse operator+(const GMatrixSparse& matrix) const;
225 virtual GMatrixSparse operator+(const double& scalar) const;
226 virtual GMatrixSparse operator-(const GMatrixSparse& matrix) const;
227 virtual GMatrixSparse operator-(const double& scalar) const;
228 virtual GMatrixSparse operator*(const GMatrixSparse& matrix) const;
229 virtual GMatrixSparse operator-(void) const;
230 virtual GMatrixSparse& operator+=(const GMatrixSparse& matrix);
231 virtual GMatrixSparse& operator+=(const double& scalar);
232 virtual GMatrixSparse& operator-=(const GMatrixSparse& matrix);
233 virtual GMatrixSparse& operator-=(const double& scalar);
234 virtual GMatrixSparse& operator*=(const GMatrixSparse& matrix);
235 virtual GMatrixSparse& operator*=(const double& scalar);
236 virtual GMatrixSparse& operator/=(const double& scalar);
237
238 // Implemented pure virtual base class methods
239 virtual void clear(void);
240 virtual GMatrixSparse* clone(void) const;
241 virtual std::string classname(void) const;
242 virtual double& at(const int& row, const int& column);
243 virtual const double& at(const int& row, const int& column) const;
244 virtual GVector row(const int& row) const;
245 virtual void row(const int& row, const GVector& vector);
246 virtual GVector column(const int& column) const;
247 virtual void column(const int& column, const GVector& vector);
248 virtual void add_to_row(const int& row, const GVector& vector);
249 virtual void add_to_column(const int& column, const GVector& vector);
250 virtual double fill(void) const;
251 virtual double min(void) const;
252 virtual double max(void) const;
253 virtual double sum(void) const;
254 virtual std::string print(const GChatter& chatter = NORMAL) const;
255
256 // Other methods
257 void column(const int& column, const double* values,
258 const int* rows, int number);
259 void add_to_column(const int& column, const GVectorSparse& vector);
260 void add_to_column(const int& column, const double* values,
261 const int* rows, int number);
262 void multiply_column(const int& column, const GVector& vector);
263 GMatrixSparse transpose(void) const;
264 GMatrixSparse invert(void) const;
265 GVector solve(const GVector& vector) const;
266 GMatrixSparse abs(void) const;
267 GMatrixSparse cholesky_decompose(const bool& compress = true) const;
268 GVector cholesky_solver(const GVector& vector, const bool& compress = true) const;
269 GMatrixSparse cholesky_invert(const bool& compress = true) const;
270 void set_mem_block(const int& block);
271 void stack_init(const int& size = 0, const int& entries = 0);
272 int stack_push_column(const GVector& vector, const int& col);
273 int stack_push_column(const double* values, const int* rows,
274 const int& number, const int& col);
275 void stack_flush(void);
276 void stack_destroy(void);
277
278 // Low-level access methods that avoid vector allocation
279 void column_to_vector(const int& column, GVector* vector) const;
280 void column_to_vector(const int& column, GVectorSparse* vector) const;
281
282 // Column filling low-level methods
283 void colfill_init(void) const;
284 void colfill_set_column(const int& column, const GVector& vector);
285 void colfill_set_column(const int& column, const GVectorSparse& vector);
286 void colfill_flush(void);
287
288private:
289 // Private methods
290 void init_members(void);
291 void copy_members(const GMatrixSparse& m);
292 void free_members(void);
293 void free_colfill_members(void) const;
294 void alloc_members(const int& rows, const int& cols, const int& elements = 0);
295 void init_stack_members(void);
296 void free_stack_members(void);
297 int get_index(const int& row, const int& column) const;
298 void fill_pending(void);
299 void alloc_elements(int start, const int& num);
300 void free_elements(const int& start, const int& num);
301 void remove_zero_row_col(void);
302 void insert_zero_row_col(const int& rows, const int& cols);
303 void mix_column_prepare(const int* src1_row, int src1_num,
304 const int* src2_row, int src2_num,
305 int* num_1, int* num_2, int* num_mix);
306 void mix_column(const double* src1_data, const int* src1_row, int src1_num,
307 const double* src2_data, const int* src2_row, int src2_num,
308 double* dst_data, int* dst_row, int* dst_num);
309 void insert_row(const int& row, const GVector& vector, const bool& add);
310
311 // Private data members
312 int* m_rowinx; //!< Row-indices of all elements
313 double m_zero; //!< The zero element (needed for data access)
314 double m_fill_val; //!< Element to be filled
315 int m_fill_row; //!< Row into which element needs to be filled
316 int m_fill_col; //!< Column into which element needs to be filled
317 int m_mem_block; //!< Memory block to be allocated at once
318 GSparseSymbolic* m_symbolic; //!< Holds GSparseSymbolic object after decomposition
319 GSparseNumeric* m_numeric; //!< Holds GSparseNumeric object after decomposition
320
321 // Fill-stack
322 int m_stack_max_entries; //!< Maximum number of entries in the stack
323 int m_stack_size; //!< Maximum number of elements in the stack
324 int m_stack_entries; //!< Number of entries in the stack
325 int* m_stack_colinx; //!< Column index for each entry [m_stack_entries]
326 int* m_stack_start; //!< Start in stack for each entry [m_stack_entries+1]
327 double* m_stack_data; //!< Stack data [m_stack_size]
328 int* m_stack_rowinx; //!< Stack row indices [m_stack_size]
329 int* m_stack_work; //!< Stack flush integer working array [m_cols]
330 int* m_stack_rows; //!< Stack push integer working array [m_cols]
331 double* m_stack_values; //!< Stack push double buffer [m_cols]
332
333 // Quick column fill low-level data members
334 mutable int* m_columns_length; //!< Length of all columns
335 mutable int** m_columns_rowinx; //!< Row indices for all columns
336 mutable double** m_columns_data; //!< Data for all columns
337};
338
339
340/***********************************************************************//**
341 * @brief Return class name
342 *
343 * @return String containing the class name ("GMatrixSparse").
344 ***************************************************************************/
345inline
346std::string GMatrixSparse::classname(void) const
347{
348 return ("GMatrixSparse");
349}
350
351
352/***********************************************************************//**
353 * @brief Set memory block size
354 *
355 * @param[in] block Memory block size.
356 *
357 * Sets the size of the memory block that will be allocated at once.
358 ***************************************************************************/
359inline
360void GMatrixSparse::set_mem_block(const int& block)
361{
362 m_mem_block = (block > 0) ? block : 1;
363 return;
364}
365
366
367/***********************************************************************//**
368 * @brief Binary matrix addition
369 *
370 * @param[in] matrix Matrix.
371 * @return Result of matrix addition.
372 *
373 * Returns the sum of two matrices. The method makes use of the unary
374 * addition operator.
375 ***************************************************************************/
376inline
378{
379 GMatrixSparse result = *this;
380 result += matrix;
381 return result;
382}
383
384
385/***********************************************************************//**
386 * @brief Binary matrix scalar addition
387 *
388 * @param[in] scalar Scalar.
389 * @return Matrix with @p scalar added.
390 *
391 * Returns a matrix where a @p scalar has been added to each matrix element.
392 ***************************************************************************/
393inline
394GMatrixSparse GMatrixSparse::operator+(const double& scalar) const
395{
396 GMatrixSparse result = *this;
397 result += scalar;
398 return result;
399}
400
401
402/***********************************************************************//**
403 * @brief Binary matrix subtraction
404 *
405 * @param[in] matrix Matrix.
406 * @return Result of matrix subtraction.
407 *
408 * Returns the difference between two matrices. The method makes use of the
409 * unary subtraction operator.
410 ***************************************************************************/
411inline
413{
414 GMatrixSparse result = *this;
415 result -= matrix;
416 return result;
417}
418
419
420/***********************************************************************//**
421 * @brief Binary matrix scalar subtraction
422 *
423 * @param[in] scalar Scalar.
424 * @return Matrix with @p scalar subtracted.
425 *
426 * Returns a matrix where a @p scalar has been subtracted from each matrix
427 * element.
428 ***************************************************************************/
429inline
430GMatrixSparse GMatrixSparse::operator-(const double& scalar) const
431{
432 GMatrixSparse result = *this;
433 result -= scalar;
434 return result;
435}
436
437
438/***********************************************************************//**
439 * @brief Binary matrix multiplication
440 *
441 * @param[in] matrix Matrix.
442 * @return Result of matrix multiplication.
443 *
444 * Returns the product of two matrices. The method makes use of the unary
445 * multiplication operator.
446 ***************************************************************************/
447inline
449{
450 GMatrixSparse result = *this;
451 result *= matrix;
452 return result;
453}
454
455
456/***********************************************************************//**
457 * @brief Scale matrix elements
458 *
459 * @param[in] scalar Scale factor.
460 * @return Matrix with elements multiplied by @p scalar.
461 *
462 * Returns a matrix where all elements have been multiplied by the specified
463 * @p scalar value.
464 ***************************************************************************/
465inline
467{
468 fill_pending();
469 scale_elements(scalar);
470 return *this;
471}
472
473
474/***********************************************************************//**
475 * @brief Divide matrix elements
476 *
477 * @param[in] scalar Scalar.
478 * @return Matrix with elements divided by @p scalar.
479 *
480 * Returns a matrix where all elements have been divided by the specified
481 * @p scalar value.
482 ***************************************************************************/
483inline
485{
486 *this *= 1.0/scalar;
487 return *this;
488}
489
490
491/***********************************************************************//**
492 * @brief Multiply matrix by scalar
493 *
494 * @param[in] matrix Matrix.
495 * @param[in] scalar Scalar.
496 * @return Matrix divided by @p scalar.
497 ***************************************************************************/
498inline
499GMatrixSparse operator*(const GMatrixSparse& matrix, const double& scalar)
500{
501 GMatrixSparse result = matrix;
502 //result.fill_pending();
503 result *= scalar;
504 return result;
505}
506
507
508/***********************************************************************//**
509 * @brief Multiply matrix by scalar
510 *
511 * @param[in] scalar Scalar.
512 * @param[in] matrix Matrix.
513 * @return Matrix divided by @p scalar.
514 ***************************************************************************/
515inline
516GMatrixSparse operator*(const double& scalar, const GMatrixSparse& matrix)
517{
518 GMatrixSparse result = matrix;
519 //result.fill_pending();
520 result *= scalar;
521 return result;
522}
523
524
525/***********************************************************************//**
526 * @brief Divide matrix by scalar
527 *
528 * @param[in] matrix Matrix.
529 * @param[in] scalar Scalar.
530 * @return Matrix divided by @p scalar.
531 ***************************************************************************/
532inline
533GMatrixSparse operator/(const GMatrixSparse& matrix, const double& scalar)
534{
535 GMatrixSparse result = matrix;
536 //result.fill_pending();
537 result /= scalar;
538 return result;
539}
540
541#endif /* GMATRIXSPARSE_HPP */
Abstract matrix base class definition.
GMatrixSparse operator*(const GMatrixSparse &matrix, const double &scalar)
Multiply matrix by scalar.
GMatrixSparse operator/(const GMatrixSparse &matrix, const double &scalar)
Divide matrix by scalar.
GChatter
Definition GTypemaps.hpp:33
@ NORMAL
Definition GTypemaps.hpp:36
Abstract matrix base class interface definition.
void scale_elements(const double &scalar)
Scale all matrix elements with a scalar.
const int & rows(void) const
Return number of matrix rows.
const int & size(void) const
Return number of matrix elements.
const int & columns(void) const
Return number of matrix columns.
Sparse matrix class interface definition.
virtual GVector column(const int &column) const
Extract column as vector from matrix.
double ** m_columns_data
Data for all columns.
GMatrixSparse transpose(void) const
Return transposed matrix.
void stack_destroy(void)
Destroy matrix stack.
virtual void add_to_column(const int &column, const GVector &vector)
Add vector column into matrix.
virtual void clear(void)
Clear matrix.
void free_colfill_members(void) const
Delete quick column filling class members.
void stack_init(const int &size=0, const int &entries=0)
Initialises matrix filling stack.
void column_to_vector(const int &column, GVector *vector) const
Extract matrix into vector.
virtual GMatrixSparse * clone(void) const
Clone matrix.
void free_members(void)
Delete class members.
GSparseSymbolic * m_symbolic
Holds GSparseSymbolic object after decomposition.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print matrix.
virtual ~GMatrixSparse(void)
Destructor.
GMatrixSparse abs(void) const
Return absolute of matrix.
void init_members(void)
Initialise class mambers.
void insert_zero_row_col(const int &rows, const int &cols)
Insert zero rows and columns.
GMatrixSparse cholesky_invert(const bool &compress=true) const
Invert matrix using a Cholesky decomposition.
virtual double fill(void) const
Returns fill of matrix.
void init_stack_members(void)
Initialise fill stack.
void remove_zero_row_col(void)
Remove rows and columns with zeros.
GMatrixSparse invert(void) const
Return inverted matrix.
friend GMatrixSparse cs_transpose(const GMatrixSparse &matrix, int values)
int m_mem_block
Memory block to be allocated at once.
virtual GMatrixSparse & operator+=(const GMatrixSparse &matrix)
Unary matrix addition operator.
virtual bool operator!=(const GMatrixSparse &matrix) const
Non-equality operator.
GMatrixSparse cholesky_decompose(const bool &compress=true) const
Return Cholesky decomposition.
virtual double & operator()(const int &row, const int &column)
Return reference to matrix element.
virtual double sum(void) const
Sum matrix elements.
int ** m_columns_rowinx
Row indices for all columns.
void mix_column(const double *src1_data, const int *src1_row, int src1_num, const double *src2_data, const int *src2_row, int src2_num, double *dst_data, int *dst_row, int *dst_num)
Mix of sparse columns.
virtual std::string classname(void) const
Return class name.
virtual GMatrixSparse operator+(const GMatrixSparse &matrix) const
Binary matrix addition.
GVector solve(const GVector &vector) const
Solves linear matrix equation.
int m_stack_max_entries
Maximum number of entries in the stack.
virtual double min(void) const
Return minimum matrix element.
int * m_stack_colinx
Column index for each entry [m_stack_entries].
virtual GVector row(const int &row) const
Extract row as vector from matrix.
double m_zero
The zero element (needed for data access)
void multiply_column(const int &column, const GVector &vector)
Multiply matrix column with vector.
double * m_stack_values
Stack push double buffer [m_cols].
GVector cholesky_solver(const GVector &vector, const bool &compress=true) const
Cholesky solver.
void stack_flush(void)
Flush matrix stack.
GSparseNumeric * m_numeric
Holds GSparseNumeric object after decomposition.
int m_stack_size
Maximum number of elements in the stack.
int * m_stack_rowinx
Stack row indices [m_stack_size].
friend double cs_cumsum(int *p, int *c, int n)
cs_cumsum
int m_fill_col
Column into which element needs to be filled.
void set_mem_block(const int &block)
Set memory block size.
int * m_rowinx
Row-indices of all elements.
friend GMatrixSparse cs_symperm(const GMatrixSparse &matrix, const int *pinv)
cs_symperm
void alloc_members(const int &rows, const int &cols, const int &elements=0)
Allocate matrix.
void free_stack_members(void)
Delete fill-stack class members.
void colfill_set_column(const int &column, const GVector &vector)
Set column for column filling.
int * m_columns_length
Length of all columns.
void colfill_flush(void)
Flush column filling memory into sparse matrix.
virtual GMatrixSparse operator-(void) const
Negate matrix elements.
void colfill_init(void) const
Initialise memory for column filling.
int m_stack_entries
Number of entries in the stack.
virtual double & at(const int &row, const int &column)
Return reference to matrix element.
int stack_push_column(const GVector &vector, const int &col)
Push a vector column on the matrix stack.
virtual GMatrixSparse & operator/=(const double &scalar)
Divide matrix elements.
virtual GVector operator*(const GVector &vector) const
Vector multiplication.
GMatrixSparse(void)
Void matrix constructor.
virtual double max(void) const
Return maximum matrix element.
void alloc_elements(int start, const int &num)
Allocate memory for new matrix elements.
virtual GMatrixSparse & operator-=(const GMatrixSparse &matrix)
Unary matrix subtraction operator.
int * m_stack_start
Start in stack for each entry [m_stack_entries+1].
virtual GMatrixSparse & operator=(const GMatrixSparse &matrix)
Matrix assignment operator.
int m_fill_row
Row into which element needs to be filled.
void mix_column_prepare(const int *src1_row, int src1_num, const int *src2_row, int src2_num, int *num_1, int *num_2, int *num_mix)
Prepare mix of sparse columns.
void free_elements(const int &start, const int &num)
Free memory for obsolete matrix elements.
virtual GMatrixSparse & operator*=(const GMatrixSparse &matrix)
Unary matrix multiplication operator.
double m_fill_val
Element to be filled.
double * m_stack_data
Stack data [m_stack_size].
int * m_stack_rows
Stack push integer working array [m_cols].
void copy_members(const GMatrixSparse &m)
Copy class members.
void insert_row(const int &row, const GVector &vector, const bool &add)
Insert row in matrix.
int get_index(const int &row, const int &column) const
Determines element index for (row,column)
virtual bool operator==(const GMatrixSparse &matrix) const
Equalty operator.
virtual void add_to_row(const int &row, const GVector &vector)
Add row to matrix elements.
int * m_stack_work
Stack flush integer working array [m_cols].
void fill_pending(void)
Fills pending matrix element.
Symmetric matrix class interface definition.
Generic matrix class definition.
Definition GMatrix.hpp:79
Sparse matrix numeric analysis class.
Sparse matrix symbolic analysis class.
Sparse vector class.
Vector class.
Definition GVector.hpp:46