COPASI API  4.16.103
CSparseMatrix.h
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/utilities/CSparseMatrix.h,v $
3 // $Revision: 1.7 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2011/10/25 17:15:54 $
7 // End CVS Header
8 
9 // Copyright (C) 2011 - 2010 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., University of Heidelberg, and The University
11 // of Manchester.
12 // All rights reserved.
13 
14 // Copyright (C) 2001 - 2007 by Pedro Mendes, Virginia Tech Intellectual
15 // Properties, Inc. and EML Research, gGmbH.
16 // All rights reserved.
17 
18 ///////////////////////////////////////////////////////////
19 // CSparseMatrix.h
20 // Implementation of the Class CSparseMatrix
21 // Created on: 29-Jun-2004 16:52:05
22 ///////////////////////////////////////////////////////////
23 
24 #ifndef COPASI_CSparseMatrix
25 #define COPASI_CSparseMatrix
26 
27 #include <vector>
28 #include <cstddef>
29 
31 class CSparseMatrix;
32 template < typename ValueType > class CMatrix;
33 
35 {
36  // Operations
37 private:
39 
40 public:
42  const size_t & rowIndex,
43  const size_t & colIndex,
44  const C_FLOAT64 & value);
45 
47 
48  const C_FLOAT64 & operator = (const C_FLOAT64 & value);
49  operator const C_FLOAT64 & () const;
50 
51  const size_t & row() const;
52  const size_t & col() const;
53 
54  static bool compareRow(const CSparseMatrixElement * pLhs,
55  const CSparseMatrixElement * pRhs);
56  static bool compareCol(const CSparseMatrixElement * pLhs,
57  const CSparseMatrixElement * pRhs);
58 
59  // Attributes
60 private:
62  const size_t & mRow;
63  const size_t & mCol;
65 };
66 
68 {
69  // Operations
70 public:
71  CSparseMatrix(const size_t & rows = 0,
72  const size_t & cols = 0);
75  bool resize(const size_t & rows, const size_t & columns);
76  const size_t & numRows() const;
77  const size_t & numCols() const;
78  size_t numNonZeros() const;
79 
80  const std::vector< std::vector< CSparseMatrixElement *> > & getColumns() const;
81  std::vector< std::vector< CSparseMatrixElement *> > & getColumns();
82  const std::vector< std::vector< CSparseMatrixElement *> > & getRows() const;
83  std::vector< std::vector< CSparseMatrixElement *> > & getRows();
84 
87  operator const CMatrix< C_FLOAT64 > () const;
88 
89  bool setTreshold(const C_FLOAT64 & threshold);
90  const C_FLOAT64 & getTreshold() const;
91 
92  CSparseMatrixElement & operator()(const size_t & row,
93  const size_t & col);
94 
95  const CSparseMatrixElement & operator()(const size_t & row,
96  const size_t & col) const;
97 
98  bool insert(const size_t & row,
99  const size_t & col,
100  const C_FLOAT64 & value);
101  bool remove(const size_t & row,
102  const size_t & col);
103 
104  friend std::ostream &operator <<(std::ostream &os,
105  const CSparseMatrix & A);
106 
107 private:
108  void cleanup();
109 
110  // Attributes
111 private:
113 
114  size_t mNumRows;
115  size_t mNumCols;
116 
117  std::vector< size_t > mRowIndex;
118  std::vector< size_t> mColIndex;
119 
120  std::vector< std::vector< CSparseMatrixElement *> > mRows;
121  std::vector< std::vector< CSparseMatrixElement *> > mCols;
122 
123  size_t mSearchRow;
124  size_t mSearchCol;
126 };
127 
129 {
130  // Attributes
131 private:
132  size_t mNumRows;
133  size_t mNumCols;
134  size_t * mpColumnStart;
135  size_t * mpRowIndex;
137 
138  // Operations
139 private:
141 
142  // Iterator
143 public:
144 #if (defined __GNUC__ && __GNUC__ < 3)
145  class const_row_iterator: public std::forward_iterator< C_FLOAT64, ptrdiff_t >
146 #else
148  public std::iterator< std::forward_iterator_tag, C_FLOAT64, ptrdiff_t >
149 #endif
150 
151  {
152  public:
153  /**
154  * Default constructor.
155  */
156  const_row_iterator(const CCompressedColumnFormat * pMatrix = NULL,
157  const size_t & rowIndex = C_INVALID_INDEX);
158 
159  /**
160  * Copy constructor
161  * @param const iterator & src
162  */
164 
165  /**
166  * Destructor
167  */
169 
170  /**
171  * Dereference operator * returns the node the iterator points to.
172  * @return C_FLOAT64 &
173  */
174  const C_FLOAT64 & operator*() const;
175 
176  /**
177  * Dereference operator * returns the node the iterator points to.
178  * @return C_FLOAT64 &
179  */
180  const C_FLOAT64 & operator->() const;
181 
182  /**
183  * Comparison operator !=
184  * @param const const_row_iterator & rhs
185  * @return bool not-equal
186  */
187  bool operator!=(const const_row_iterator & rhs);
188 
189  /**
190  * Assignement operator from a node to an iterator
191  * @param const const_row_iterator & rhs
192  * @return iterator &
193  */
195 
196  /**
197  * Prefix increment operator ++
198  * @return iterator &
199  */
201 
202  const size_t & getColumnIndex() const;
203 
204  private:
205  // Attributes
207 
208  size_t mRowIndex;
209 
210  const size_t *mpRowIndex;
211 
212  size_t mColumnIndex;
213 
214  const size_t *mpColumnIndex;
215 
217  };
218 
219  CCompressedColumnFormat(const size_t & rows,
220  const size_t & columns,
221  const size_t & nonZeros);
222  CCompressedColumnFormat(const CSparseMatrix & matrix);
224 
225  size_t numRows() const;
226  size_t numCols() const;
227  size_t numNonZeros() const;
228  const C_FLOAT64 * getValues() const;
229  C_FLOAT64 * getValues();
230  const size_t * getRowIndex() const;
231  size_t * getRowIndex();
232  const size_t * getColumnStart() const;
233  size_t * getColumnStart();
235 
236  const_row_iterator beginRow(const size_t & row) const;
237  const_row_iterator endRow(const size_t & row) const;
238 };
239 
240 #ifdef COPASI_DEBUG
241 bool SparseMatrixTest(const size_t & size,
242  const C_FLOAT64 & sparseness,
243  const unsigned C_INT32 & seed = 0,
244  const bool & RMP = true,
245  const bool & DGEMM = true,
246  const bool & SMP = true,
247  const bool & CCMP = true);
248 #endif
249 
250 #endif // COPASI_CSparseMatrix
const size_t & col() const
const C_FLOAT64 & operator=(const C_FLOAT64 &value)
const_row_iterator(const CCompressedColumnFormat *pMatrix=NULL, const size_t &rowIndex=C_INVALID_INDEX)
bool resize(const size_t &rows, const size_t &columns)
const CCompressedColumnFormat * mpMatrix
CSparseMatrix & operator=(const CCompressedColumnFormat &ccf)
const size_t * getColumnStart() const
CCompressedColumnFormat & operator=(const CSparseMatrix &ccf)
const C_FLOAT64 & getTreshold() const
const size_t & numCols() const
static bool compareRow(const CSparseMatrixElement *pLhs, const CSparseMatrixElement *pRhs)
CSparseMatrix & mMatrix
Definition: CSparseMatrix.h:61
friend std::ostream & operator<<(std::ostream &os, const CSparseMatrix &A)
const size_t & mRow
Definition: CSparseMatrix.h:62
const size_t & numRows() const
std::vector< std::vector< CSparseMatrixElement * > > mRows
#define C_INVALID_INDEX
Definition: copasi.h:222
bool operator!=(const const_row_iterator &rhs)
const_row_iterator beginRow(const size_t &row) const
#define C_INT32
Definition: copasi.h:90
static bool compareCol(const CSparseMatrixElement *pLhs, const CSparseMatrixElement *pRhs)
const std::vector< std::vector< CSparseMatrixElement * > > & getColumns() const
const std::vector< std::vector< CSparseMatrixElement * > > & getRows() const
const size_t * getRowIndex() const
const_row_iterator & operator=(const const_row_iterator &rhs)
CSparseMatrix(const size_t &rows=0, const size_t &cols=0)
const size_t & row() const
C_FLOAT64 mThreshold
std::vector< size_t > mColIndex
std::vector< size_t > mRowIndex
bool insert(const size_t &row, const size_t &col, const C_FLOAT64 &value)
size_t numNonZeros() const
#define C_FLOAT64
Definition: copasi.h:92
const size_t & mCol
Definition: CSparseMatrix.h:63
std::vector< std::vector< CSparseMatrixElement * > > mCols
bool setTreshold(const C_FLOAT64 &threshold)
CSparseMatrixElement & operator()(const size_t &row, const size_t &col)
const C_FLOAT64 * getValues() const
CSparseMatrixElement mElement
const_row_iterator endRow(const size_t &row) const
size_t numNonZeros() const