COPASI API  4.16.103
Public Types | Public Member Functions | Protected Attributes | Friends | List of all members
CMatrix< CType > Class Template Reference

#include <CStepMatrix.h>

Inheritance diagram for CMatrix< CType >:
Inheritance graph
[legend]
Collaboration diagram for CMatrix< CType >:
Collaboration graph
[legend]

Public Types

typedef CType elementType
 

Public Member Functions

bool applyPivot (const CVector< size_t > &pivot)
 
virtual CType * array ()
 
virtual const CType * array () const
 
 CMatrix (size_t rows=0, size_t cols=0)
 
 CMatrix (const CMatrix< CType > &src)
 
virtual size_t numCols () const
 
virtual size_t numRows () const
 
virtual elementTypeoperator() (const size_t &row, const size_t &col)
 
virtual const elementTypeoperator() (const size_t &row, const size_t &col) const
 
virtual CMatrix< CType > & operator= (const CMatrix< CType > &rhs)
 
virtual CMatrix< CType > & operator= (const CType &value)
 
virtual CType * operator[] (size_t row)
 
virtual const CType * operator[] (size_t row) const
 
virtual void resize (size_t rows, size_t cols, const bool &copy=false)
 
virtual size_t size () const
 
virtual ~CMatrix ()
 

Protected Attributes

CType * mArray
 
size_t mCols
 
size_t mRows
 

Friends

std::ostream & operator<< (std::ostream &os, const CMatrix< CType > &A)
 

Detailed Description

template<class CType>
class CMatrix< CType >

Template class CMatrix < class CType > This template class is a simple matrix class allowing standard C-style and fortran style access to the elements. It also supplies an ostream operator.

Definition at line 21 of file CStepMatrix.h.

Member Typedef Documentation

template<class CType>
typedef CType CMatrix< CType >::elementType

Definition at line 70 of file CMatrix.h.

Constructor & Destructor Documentation

template<class CType>
CMatrix< CType >::CMatrix ( size_t  rows = 0,
size_t  cols = 0 
)
inline

Default constructor

Parameters
size_trows (default = 0)
size_tcols (default = 0)

Definition at line 96 of file CMatrix.h.

96  :
97  mRows(0),
98  mCols(0),
99  mArray(NULL)
100  {
101  resize(rows, cols);
102  }
size_t mCols
Definition: CMatrix.h:82
CType * mArray
Definition: CMatrix.h:87
virtual void resize(size_t rows, size_t cols, const bool &copy=false)
Definition: CMatrix.h:151
size_t mRows
Definition: CMatrix.h:77
template<class CType>
CMatrix< CType >::CMatrix ( const CMatrix< CType > &  src)
inline

Copy constructor

Parameters
constCMatrix <CType> & src

Definition at line 108 of file CMatrix.h.

108  :
109  mRows(0),
110  mCols(0),
111  mArray(NULL)
112  {
113  resize(src.mRows, src.mCols);
114 
115  if (mRows && mCols)
116  memcpy(mArray, src.mArray, mRows * mCols * sizeof(CType));
117  }
size_t mCols
Definition: CMatrix.h:82
CType * mArray
Definition: CMatrix.h:87
virtual void resize(size_t rows, size_t cols, const bool &copy=false)
Definition: CMatrix.h:151
size_t mRows
Definition: CMatrix.h:77
template<class CType>
virtual CMatrix< CType >::~CMatrix ( )
inlinevirtual

Destructor.

Definition at line 122 of file CMatrix.h.

123  {
124  if (mArray)
125  delete [] mArray;
126  }
CType * mArray
Definition: CMatrix.h:87

Member Function Documentation

template<class CType>
bool CMatrix< CType >::applyPivot ( const CVector< size_t > &  pivot)
inline

Reorder the rows according to the provided pivots

Parameters
constCVector<size_t> & pivot
Returns
bool success

Definition at line 351 of file CMatrix.h.

Referenced by CExperiment::read().

352  {
353  if (pivot.size() != mRows) return false;
354 
355  CVector< bool > Applied(mRows);
356  Applied = false;
357  CType *pTmp = new CType[mCols];
358 
359  size_t i;
360  size_t to;
361  size_t from;
362 
363  for (i = 0; i < mRows; i++)
364  if (!Applied[i])
365  {
366  to = i;
367  from = pivot[i];
368 
369  if (to != from)
370  {
371  memcpy(pTmp, mArray + i * mCols, mCols * sizeof(CType));
372 
373  while (from != i)
374  {
375  memcpy(mArray + to * mCols, mArray + from * mCols, mCols * sizeof(CType));
376  Applied[to] = true;
377 
378  to = from;
379  from = pivot[to];
380  }
381 
382  memcpy(mArray + to * mCols, pTmp, mCols * sizeof(CType));
383  }
384 
385  Applied[to] = true;
386  }
387 
388  pdeletev(pTmp);
389  return true;
390  }
size_t mCols
Definition: CMatrix.h:82
CType * mArray
Definition: CMatrix.h:87
#define pdeletev(p)
Definition: copasi.h:216
size_t size() const
Definition: CVector.h:100
size_t mRows
Definition: CMatrix.h:77
template<class CType>
virtual CType* CMatrix< CType >::array ( )
inlinevirtual

Retrieve the array of the matrix elements. This is suitable for interfacing with clapack routines.

Returns
CType * array

Definition at line 337 of file CMatrix.h.

Referenced by CLinkMatrix::applyColumnPivot(), CLinkMatrix::applyRowPivot(), CLinkMatrix::build(), CBitPatternTreeMethod::buildFluxModes(), CBitPatternMethod::buildFluxModes(), CBitPatternMethod::buildKernelMatrix(), CBitPatternTreeMethod::buildKernelMatrix(), CSSAMethod::buildKineticMatrix(), CModel::buildMoieties(), CModel::buildStoi(), CSSAMethod::buildStoichiometry(), CEigen::calcEigenValues(), CFitProblem::calculate(), CLNAMethod::calculateCovarianceMatrixFull(), CLNAMethod::calculateCovarianceMatrixReduced(), CFitProblem::calculateCrossValidation(), CModel::calculateDerivatives(), CModel::calculateDerivativesX(), CModel::calculateElasticityMatrix(), CModel::calculateJacobian(), CModel::calculateJacobianX(), CBitPatternMethod::CalculateKernel(), CBitPatternTreeMethod::CalculateKernel(), CMathModel::calculateRootDerivatives(), CMathModel::calculateRootJacobian(), CFitProblem::calculateStatistics(), CExperiment::calculateStatistics(), CMCAMethod::calculateUnscaledConcentrationCC(), CMCAMethod::calculateUnscaledElasticities(), CMCAMethod::calculateUnscaledFluxCC(), CMCAMethod::checkSummationTheorems(), CStepMatrix::CStepMatrix(), CSSAMethod::decomposeJacobian(), CSSAMethod::diag(), CLyapWolfMethod::evalF(), CExperiment::getErrorMeanSD(), CExperiment::getErrorSum(), CModel::handleUnusedMetabolites(), COptMethodLevenbergMarquardt::hessian(), CExperiment::initializeScalingMatrix(), CEFMMethod::isValidProblem(), CLinkMatrix::leftMultiply(), CSparseMatrix::operator const CMatrix< C_FLOAT64 >(), CSparseMatrix::operator=(), COptMethodLevenbergMarquardt::optimise(), CBitPatternMethod::performRankTest(), CQSimpleSelectionTree::populateTree(), CSteadyStateTask::process(), CLinkMatrix::rightMultiply(), CMCAMethod::scaleMCA(), CCSPMethod::sminverse(), and CNewtonMethod::solveJacobianXeqB().

337 {return mArray;}
CType * mArray
Definition: CMatrix.h:87
template<class CType>
virtual const CType* CMatrix< CType >::array ( ) const
inlinevirtual

Retrieve the array of the matrix elements. This is suitable for interfacing with clapack routines.

Returns
const CType * array

Definition at line 344 of file CMatrix.h.

344 {return mArray;}
CType * mArray
Definition: CMatrix.h:87
template<class CType>
virtual size_t CMatrix< CType >::numCols ( ) const
inlinevirtual

The number of columns of the matrix

Returns
size_t cols

Definition at line 144 of file CMatrix.h.

Referenced by CLinkMatrix::applyColumnPivot(), CLinkMatrix::applyRowPivot(), CLinkMatrix::build(), CBitPatternMethod::buildFluxModeMatrix(), CBitPatternTreeMethod::buildFluxModes(), CBitPatternMethod::buildFluxModes(), CBitPatternMethod::buildKernelMatrix(), CBitPatternTreeMethod::buildKernelMatrix(), CModel::buildRedStoi(), CEigen::calcEigenValues(), CFitProblem::calculate(), CLNAMethod::calculateCovarianceMatrixReduced(), CFitProblem::calculateCrossValidation(), CModel::calculateElasticityMatrix(), CBitPatternMethod::CalculateKernel(), CBitPatternTreeMethod::CalculateKernel(), CExperiment::calculateStatistics(), CMCAMethod::calculateUnscaledConcentrationCC(), CMCAMethod::calculateUnscaledFluxCC(), CMCAMethod::checkSummationTheorems(), CBitPatternMethod::combine(), CExperiment::compile(), CMCAMethod::createLinkMatrix(), CStepMatrix::CStepMatrix(), CSSAMethod::decomposeJacobian(), CExperiment::getErrorMeanSD(), CExperiment::getErrorSum(), CModel::handleUnusedMetabolites(), COptMethodLevenbergMarquardt::hessian(), CBitPatternMethod::initialize(), CBitPatternTreeMethod::initialize(), CExperiment::initializeScalingMatrix(), CEFMMethod::isValidProblem(), CLinkMatrix::leftMultiply(), LUfactor(), CLinkMatrixView::numCols(), CSparseMatrix::operator=(), CHybridMethod::outputDebug(), CHybridMethodODE45::outputDebug(), CHybridMethodLSODA::outputDebug(), CBitPatternMethod::performRankTest(), CExperiment::printResult(), CMCAMethod::resizeAllMatrices(), CLinkMatrix::rightMultiply(), CMCAMethod::scaleMCA(), CCSPMethod::setVectors(), CNewtonMethod::solveJacobianXeqB(), CExperiment::storeExtendedTimeSeriesData(), CExperiment::sumOfSquares(), CExperiment::sumOfSquaresStore(), CExperiment::updateFittedPointValues(), and CExperiment::updateFittedPointValuesFromExtendedTimeSeries().

144 {return mCols;}
size_t mCols
Definition: CMatrix.h:82
template<class CType>
virtual size_t CMatrix< CType >::numRows ( ) const
inlinevirtual
template<class CType>
virtual elementType& CMatrix< CType >::operator() ( const size_t &  row,
const size_t &  col 
)
inlinevirtual

Retrieve a matrix element using c-style indexing.

Parameters
constsize_t & row
constsize_t & col
Returns
const elementType & element

Definition at line 312 of file CMatrix.h.

314  {
315  assert(row < mRows && col < mCols);
316  return *(mArray + row * mCols + col);
317  }
size_t mCols
Definition: CMatrix.h:82
CType * mArray
Definition: CMatrix.h:87
size_t mRows
Definition: CMatrix.h:77
template<class CType>
virtual const elementType& CMatrix< CType >::operator() ( const size_t &  row,
const size_t &  col 
) const
inlinevirtual

Retrieve a matrix element using c-style indexing.

Parameters
constsize_t & row
constsize_t & col
Returns
const elementType & element

Definition at line 325 of file CMatrix.h.

327  {
328  assert(row < mRows && col < mCols);
329  return *(mArray + row * mCols + col);
330  }
size_t mCols
Definition: CMatrix.h:82
CType * mArray
Definition: CMatrix.h:87
size_t mRows
Definition: CMatrix.h:77
template<class CType>
virtual CMatrix<CType>& CMatrix< CType >::operator= ( const CMatrix< CType > &  rhs)
inlinevirtual

Assignment operator

Parameters
constCMatrix <CType> & rhs
Returns
CMatrix <CType> & lhs

Definition at line 222 of file CMatrix.h.

223  {
224  if (mRows != rhs.mRows || mCols != rhs.mCols)
225  resize(rhs.mRows, rhs.mCols);
226 
227  memcpy(mArray, rhs.mArray, mRows * mCols * sizeof(CType));
228 
229  return *this;
230  }
size_t mCols
Definition: CMatrix.h:82
CType * mArray
Definition: CMatrix.h:87
virtual void resize(size_t rows, size_t cols, const bool &copy=false)
Definition: CMatrix.h:151
size_t mRows
Definition: CMatrix.h:77
template<class CType>
virtual CMatrix<CType>& CMatrix< CType >::operator= ( const CType &  value)
inlinevirtual

Assignment operator

Parameters
constCType & value
Returns
CMatrix <CType> & lhs

Definition at line 237 of file CMatrix.h.

238  {
239  CType * pIt = mArray;
240  CType * pEnd = pIt + mRows * mCols;
241 
242  for (; pIt != pEnd; ++pIt) *pIt = value;
243 
244  return *this;
245  }
size_t mCols
Definition: CMatrix.h:82
CType * mArray
Definition: CMatrix.h:87
size_t mRows
Definition: CMatrix.h:77
template<class CType>
virtual CType* CMatrix< CType >::operator[] ( size_t  row)
inlinevirtual

Retrieve a row of the matrix using c-style indexing

Parameters
size_trow
Returns
CType * row

Definition at line 295 of file CMatrix.h.

296  {return mArray + row * mCols;}
size_t mCols
Definition: CMatrix.h:82
CType * mArray
Definition: CMatrix.h:87
template<class CType>
virtual const CType* CMatrix< CType >::operator[] ( size_t  row) const
inlinevirtual

Retrieve a row of the matrix using c-style indexing

Parameters
size_trow
Returns
const CType * row

Definition at line 303 of file CMatrix.h.

304  {return mArray + row * mCols;}
size_t mCols
Definition: CMatrix.h:82
CType * mArray
Definition: CMatrix.h:87
template<class CType>
virtual void CMatrix< CType >::resize ( size_t  rows,
size_t  cols,
const bool &  copy = false 
)
inlinevirtual

Resize the matrix. The previous content is lost

Parameters
size_trows
size_tcols

Definition at line 151 of file CMatrix.h.

Referenced by CCSPMethod::basisRefinement(), CBitPatternMethod::buildKernelMatrix(), CBitPatternTreeMethod::buildKernelMatrix(), CSSAMethod::buildKineticMatrix(), CModel::buildRedStoi(), CModel::buildStoi(), CSSAMethod::buildStoichiometry(), CEigen::calcEigenValues(), CLNAMethod::calculateCovarianceMatrixFull(), CLNAMethod::calculateCovarianceMatrixReduced(), CModel::calculateJacobian(), CModel::calculateJacobianX(), CBitPatternMethod::CalculateKernel(), CBitPatternTreeMethod::CalculateKernel(), CMathModel::calculateRootJacobian(), CFitProblem::calculateStatistics(), CMCAMethod::calculateUnscaledConcentrationCC(), CTimeSeries::clear(), CMatrix< CFitConstraint * >::CMatrix(), CTimeSeries::compile(), CMCAMethod::createLinkMatrix(), CCSPMethod::CSPImportanceIndex(), CCSPMethod::CSPParticipationIndex(), CCSPMethod::CSPradicalPointer(), CCSPMethod::cspstep(), CSSAMethod::decomposeJacobian(), CSSAMethod::diag(), CTimeSeries::increaseAllocation(), COptMethodPS::initialize(), COptMethodLevenbergMarquardt::initialize(), COptMethodNelderMead::initialize(), CFitProblem::initialize(), CSteadyStateTask::initialize(), CExperiment::initializeScalingMatrix(), CTSSAMethod::integrationMethodStart(), CLinkMatrix::leftMultiply(), CTSSAMethod::mat_anal_fast_space(), CTSSAMethod::mat_anal_mod(), CTSSAMethod::mat_anal_mod_space(), CILDMMethod::newton(), CILDMModifiedMethod::newton_new(), CSparseMatrix::operator const CMatrix< C_FLOAT64 >(), CMatrix< CFitConstraint * >::operator=(), CCSPMethod::predifineAnnotation(), CCSPMethod::printResult(), CExperiment::read(), CMCAMethod::resizeAllMatrices(), CLNAMethod::resizeAllMatrices(), CLinkMatrix::rightMultiply(), CILDMModifiedMethod::setAnnotationM(), CILDMMethod::setAnnotationM(), CCSPMethod::setAnnotationM(), CCSPMethod::sminverse(), CILDMMethod::start(), CILDMModifiedMethod::start(), CCSPMethod::start(), CLyapWolfMethod::start(), CILDMMethod::step(), CILDMModifiedMethod::step(), CCSPMethod::step(), CTSSAMethod::sylvester(), CSteadyStateTask::updateMatrices(), and CCSPMethod::yCorrection().

152  {
153  if (rows != mRows || cols != mCols)
154  {
155  size_t OldRows = mRows;
156  size_t OldCols = mCols;
157  CType * OldArray = mArray;
158  mArray = NULL;
159 
160  if (rows != 0 && cols != 0)
161  {
162  try
163  {
164  // We need to detect size_t overflow
165  if ((C_FLOAT64) rows * (C_FLOAT64) cols * (C_FLOAT64) sizeof(CType) >= (C_FLOAT64) std::numeric_limits< size_t >::max())
166  {
167  mArray = NULL;
168  }
169  else
170  {
171  mArray = new CType[rows * cols];
172  }
173  }
174 
175  catch (...)
176  {
177  mArray = NULL;
178  }
179 
180  if (mArray == NULL)
181  {
182  mRows = 0;
183  mCols = 0;
184 
185  CCopasiMessage(CCopasiMessage::EXCEPTION, MCopasiBase + 1, rows * cols * sizeof(CType));
186  }
187 
188  if (copy &&
189  mArray != NULL &&
190  OldArray != NULL)
191  {
192  // We copy the top left matrix (min(rows, OldRows), min(cols, OldCols);
193  size_t CopiedRows = std::min(rows, OldRows);
194  size_t CopiedColumns = std::min(cols, OldCols);
195 
196  CType * pOldRow = OldArray;
197  CType * pOldRowEnd = pOldRow + CopiedRows * OldCols;
198  CType * pRow = mArray;
199 
200  for (; pOldRow != pOldRowEnd; pOldRow += OldCols, pRow += cols)
201  {
202  memcpy(pRow, pOldRow, CopiedColumns * sizeof(CType));
203  }
204  }
205  }
206 
207  if (OldArray)
208  {
209  delete [] OldArray;
210  }
211  }
212 
213  mRows = rows;
214  mCols = cols;
215  }
size_t mCols
Definition: CMatrix.h:82
CType * mArray
Definition: CMatrix.h:87
#define MCopasiBase
#define C_FLOAT64
Definition: copasi.h:92
size_t mRows
Definition: CMatrix.h:77
#define min(a, b)
Definition: f2c.h:175
#define max(a, b)
Definition: f2c.h:176
template<class CType>
virtual size_t CMatrix< CType >::size ( ) const
inlinevirtual

Friends And Related Function Documentation

template<class CType>
std::ostream& operator<< ( std::ostream &  os,
const CMatrix< CType > &  A 
)
friend

Output stream operator

Parameters
ostream& os
constCMatrix< CType > & A
Returns
ostream & os

Definition at line 809 of file CMatrix.h.

810 {
811  os << "Matrix(" << A.mRows << "x" << A.mCols << ")" << std::endl;
812 
813  size_t i, j;
814  CType * tmp = A.mArray;
815 
816  for (i = 0; i < A.mRows; i++)
817  {
818  for (j = 0; j < A.mCols; j++)
819  os << "\t" << *(tmp++);
820 
821  os << std::endl;
822  }
823 
824  return os;
825 }
size_t mCols
Definition: CMatrix.h:82
CType * mArray
Definition: CMatrix.h:87
size_t mRows
Definition: CMatrix.h:77

Member Data Documentation

template<class CType>
CType* CMatrix< CType >::mArray
protected
template<class CType>
size_t CMatrix< CType >::mCols
protected
template<class CType>
size_t CMatrix< CType >::mRows
protected

The documentation for this class was generated from the following files: