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