Sparse Matrix. More...

#include <rsparsematrix.h>

Inheritance diagram for RSparseMatrix:
[legend]
Collaboration diagram for RSparseMatrix:
[legend]

Public Member Functions

virtual void Clear (double val=NAN, bool clean=false)
 
int Compare (const RSparseMatrix &matrix) const
 
RCursor< RSparseVectorGetLines (void) const
 
size_t GetNbVectors (void) const
 
virtual tType GetType (void) const
 
RSparseVectorGetValue (size_t i) const
 
virtual void Init (double val)
 
bool IsIn (size_t i) const
 
virtual double operator() (size_t i, size_t j) const
 
virtual double & operator() (size_t i, size_t j)
 
RSparseMatrixoperator= (const RSparseMatrix &matrix)
 
const RSparseVectoroperator[] (size_t i) const
 
RSparseVectoroperator[] (size_t i)
 
 RSparseMatrix (size_t nblines, size_t nbcols, bool alllines=true, size_t init=20)
 
 RSparseMatrix (const RSparseMatrix &src)
 
virtual void VerifySize (size_t newlines, size_t newcols, bool fill=false, double val=NAN)
 
virtual ~RSparseMatrix (void)
 
- Public Member Functions inherited from RGenericMatrix
virtual void Add (size_t i, size_t j, double val)
 
int Compare (const RGenericMatrix &matrix) const
 
size_t GetNbCols (void) const
 
size_t GetNbLines (void) const
 
RGenericMatrixoperator= (const RGenericMatrix &matrix)
 
template<class S >
void Print (S &stream, const RString &name, const char *format="%E", size_t colsize=12) const
 
 RGenericMatrix (size_t size)
 
 RGenericMatrix (size_t lines, size_t cols)
 
 RGenericMatrix (const RGenericMatrix &matrix)
 
virtual ~RGenericMatrix (void)
 

Protected Attributes

bool AllLines
 
size_t InitNbCols
 
- Protected Attributes inherited from RGenericMatrix
size_t NbCols
 
size_t NbLines
 
- Protected Attributes inherited from iRContainer< C >
size_t IncPtr
 
size_t LastPtr
 
size_t MaxPtr
 
size_t NbPtr
 
C ** Tab
 

Additional Inherited Members

- Public Types inherited from RGenericMatrix
enum  tType {
  tNormal, tDiagonal, tLowerTriangular, tUpperTriangular,
  tSymmetric, tSparse, tSparseSymmetric, tMax
}
 
- Protected Member Functions inherited from RContainer< RSparseVector, true, true >
void Clear (size_t m=0, size_t i=0, bool force=false)
 
int Compare (const RContainer< RSparseVector, true, true > &) const
 
void Copy (const RContainer< RSparseVector, a, true > &src)
 
void DeletePtr (const TUse &tag, bool sortkey, bool del, size_t min=0, size_t max=0)
 
void DeletePtr (const TUse &tag, bool sortkey, size_t min=0, size_t max=0)
 
void DeletePtr (const TUse &tag, size_t min=0, size_t max=0)
 
void DeletePtrAt (size_t pos, bool shift, bool del)
 
void DeletePtrAt (size_t pos, bool shift)
 
void DeletePtrAt (size_t pos)
 
void Exchange (size_t pos1, size_t pos2)
 
size_t GetIncNb (void) const
 
size_t GetIndex (const TUse &tag, bool &find, size_t min=0, size_t max=0) const
 
RSparseVectorGetInsertPtr (const TUse &tag, size_t min=0, size_t max=0)
 
RSparseVectorGetInsertPtr (const TUse &tag, bool sortkey, size_t min=0, size_t max=0)
 
RSparseVectorGetInsertPtrAt (const TUse &tag, size_t pos)
 
size_t GetMaxNb (void) const
 
size_t GetMaxPos (void) const
 
size_t GetNb (void) const
 
RSparseVectorGetPtr (const TUse &tag, bool sortkey, size_t min=0, size_t max=0) const
 
RSparseVectorGetPtr (const TUse &tag, size_t min=0, size_t max=0) const
 
const RSparseVectorGetPtrAt (size_t idx) const
 
RSparseVectorGetPtrAt (size_t idx)
 
RContainer< RSparseVector,
false, true > * 
GetPtrs (const TUse &tag, size_t min=0, size_t max=0) const
 
size_t GetTab (const void **tab, size_t min=0, size_t max=0) const
 
size_t GetTab (void **tab, size_t min=0, size_t max=0)
 
size_t GetTab (const RSparseVector **tab, size_t min=0, size_t max=0) const
 
size_t GetTab (RSparseVector **tab, size_t min=0, size_t max=0)
 
void InsertPtr (RSparseVector *ins, bool del=false, size_t min=0, size_t max=0)
 
void InsertPtrAt (RSparseVector *ins, size_t pos, bool del)
 
void InsertPtrAt (RSparseVector *ins, size_t pos)
 
void Inter (const iRContainer< RSparseVector > &src1, const iRContainer< RSparseVector > &src2)
 
bool IsIn (const TUse &tag, bool sortkey, size_t min=0, size_t max=0) const
 
bool IsIn (const TUse &tag, size_t min=0, size_t max=0) const
 
RContaineroperator+= (const RContainer< RSparseVector, a, o > &src)
 
RContaineroperator= (const RContainer< RSparseVector, true, true > &src)
 
RContaineroperator= (const RContainer< RSparseVector, false, true > &src)
 
const RSparseVectoroperator[] (size_t idx) const
 
RSparseVectoroperator[] (size_t idx)
 
 RContainer (const RContainer< RSparseVector, true, true > &src)
 
 RContainer (const RContainer< RSparseVector, false, true > &src)
 
 RContainer (size_t m, size_t i=0)
 
void ReOrder (int sortOrder(const void *, const void *))
 
void ReOrder (int sortOrder(const void *, const void *), size_t min, size_t max)
 
void ReOrder (void)
 
void Shift (size_t idx, bool reverse)
 
void Transfer (RContainer< RSparseVector, a, o > &src)
 
void Union (const iRContainer< RSparseVector > &src1, const iRContainer< RSparseVector > &src2)
 
bool VerifyIndex (size_t idx) const
 
void VerifyTab (size_t max=0)
 
virtual ~RContainer (void)
 
- Protected Member Functions inherited from iRContainer< C >
iRContainerAdd (const iRContainer< C > &src)
 
void Create (const iRContainer< C > &src)
 
void DeepCopy (const iRContainer< C > &src)
 
iRContainerNormalCopy (const iRContainer< C > &src)
 
void Clear (size_t m=0, size_t i=0, bool force=false)
 
void Copy (const iRContainer< C > &src)
 
void DeletePtr (const TUse &tag, bool sortkey, bool del, size_t min=0, size_t max=0)
 
void DeletePtr (const TUse &tag, bool sortkey, size_t min=0, size_t max=0)
 
void DeletePtr (const TUse &tag, size_t min=0, size_t max=0)
 
void DeletePtrAt (size_t pos, bool shift)
 
void DeletePtrAt (size_t pos)
 
void DeletePtrAt (size_t pos, bool shift, bool del)
 
void Exchange (size_t pos1, size_t pos2)
 
size_t GetIncNb (void) const
 
size_t GetIndex (const TUse &tag, bool &find, size_t min=0, size_t max=0) const
 
size_t GetIndex (bool order, const TUse &tag, bool &find, size_t min=0, size_t max=0) const
 
C * GetInsertPtr (const TUse &tag, bool sortkey, size_t min=0, size_t max=0)
 
C * GetInsertPtr (const TUse &tag, size_t min=0, size_t max=0)
 
C * GetInsertPtrAt (const TUse &tag, size_t pos)
 
size_t GetMaxNb (void) const
 
size_t GetMaxPos (void) const
 
size_t GetNb (void) const
 
C * GetPtr (const TUse &tag, bool sortkey, size_t min=0, size_t max=0) const
 
C * GetPtr (const TUse &tag, size_t min=0, size_t max=0) const
 
const C * GetPtrAt (size_t idx) const
 
C * GetPtrAt (size_t idx)
 
size_t GetTab (const C **tab, size_t min=0, size_t max=0) const
 
size_t GetTab (C **tab, size_t min=0, size_t max=0)
 
size_t GetTab (const void **tab, size_t min=0, size_t max=0) const
 
size_t GetTab (void **tab, size_t min=0, size_t max=0)
 
void InsertPtr (C *ins, bool del=false, size_t min=0, size_t max=0)
 
void InsertPtrAt (C *ins, size_t pos, bool del)
 
void InsertPtrAt (C *ins, size_t pos)
 
void Inter (const iRContainer< C > &src1, const iRContainer< C > &src2)
 
bool IsIn (const TUse &tag, size_t min=0, size_t max=0) const
 
bool IsIn (const TUse &tag, bool sortkey, size_t min=0, size_t max=0) const
 
iRContaineroperator+= (const iRContainer< C > &src)
 
iRContaineroperator= (const iRContainer< C > &src)
 
const C * operator[] (size_t idx) const
 
C * operator[] (size_t idx)
 
void ReOrder (int sortOrder(const void *, const void *), size_t min, size_t max)
 
void ReOrder (int sortOrder(const void *, const void *))
 
void ReOrder (void)
 
void Shift (size_t idx, bool reverse)
 
void Transfer (iRContainer< C > &src)
 
void Union (const iRContainer< C > &src1, const iRContainer< C > &src2)
 
bool VerifyIndex (size_t idx) const
 
void VerifyTab (size_t max=0)
 
virtual ~iRContainer (void)
 
- Static Protected Member Functions inherited from RContainer< RSparseVector, true, true >
static int SortOrder (const void *a, const void *b)
 
- Static Protected Member Functions inherited from iRContainer< C >
static int SortOrder (const void *a, const void *b)
 

Detailed Description

Sparse Matrix.

The RSparseMatrix provides a representation for a sparse matrix. The matrix is coded as a container of RSparseVector. The matrix can be created so that to each line a vector is always build to speed up the access.

Here is an example of code:

RSparseMatrix a(6,3); // Matrix initially contains 6 lines and 3 values per line (<>3 columns).
a(0,2)=0.2;
a(1,5)=1.5;
a(2,0)=1.0;
a(5,1)=5.1;
for(size_t i=0;i<6;i++)
{
for(size_t j=0;j<6;j++)
cout<<static_cast<const RSparseMatrix&>(a)(i,j)<<"\t";
cout<<endl;
}

An important aspect is the use of static_cast<const RSparseMatrix&> to ensure the call of the const version of the operator(). If static_cast<const RSparseMatrix&> is not used, the different elements are created with uninitialized values.

Constructor & Destructor Documentation

RSparseMatrix ( size_t  nblines,
size_t  nbcols,
bool  alllines = true,
size_t  init = 20 
)

Construct a sparse matrix.

Parameters
nblinesNumber of lines (not the number of vectors).
nbcolsNumber of columns (not the number of elements in each vector).
alllinesAll lines have a vector.
initInitial number of elements to reserve for each line.
RSparseMatrix ( const RSparseMatrix src)

Copy constructor of a sparse matrix.

Parameters
srcSparse matrix used as source.
virtual ~RSparseMatrix ( void  )
virtual

Destruct the sparse matrix.

Member Function Documentation

int Compare ( const RSparseMatrix matrix) const

Compare method used by RContainer.

Parameters
matrixMatrix to compare with.
Returns
always -1.
virtual void Clear ( double  val = NAN,
bool  clean = false 
)
virtual

Clear the matrix. All the elements are removed.

Parameters
valValue eventually used to assign to the elements (not used for sparse matrix).
cleanClean eventually only the memory.

Reimplemented from RGenericMatrix.

virtual void Init ( double  val)
virtual

Initialize the matrix with a given value. It uses the operator(i,j) to initialize the different elements.

Parameters
valValue to assign.

Reimplemented from RGenericMatrix.

virtual void VerifySize ( size_t  newlines,
size_t  newcols,
bool  fill = false,
double  val = NAN 
)
virtual

Verify if the matrix has a given size, and increase them if necessary.

Parameters
newlinesNew line number.
newcolsNew column number.
fillElements must be filled with a value (Not used for sparse matrix).
valValue used eventually to fill the elements created (Not used for sparse matrix).

Implements RGenericMatrix.

virtual tType GetType ( void  ) const
virtual

Get the type of the matrix.

Implements RGenericMatrix.

Reimplemented in RSparseSymmetricMatrix.

size_t GetNbVectors ( void  ) const

Get the number of vectors contained in the matrix. If the matrix does not create a vector for each line, the number of vectors does not correspond to the number of lines of the matrix.

RCursor<RSparseVector> GetLines ( void  ) const

Get a cursor over the vectors of the matrix.

RSparseMatrix& operator= ( const RSparseMatrix matrix)

The assignment operator.

Parameters
matrixSparse Matrix used as source.
virtual double operator() ( size_t  i,
size_t  j 
) const
virtual

Return a specific element of the matrix (const version).

Parameters
iLine number of the element.
jColumn number of the element.

Implements RGenericMatrix.

Reimplemented in RSparseSymmetricMatrix.

virtual double& operator() ( size_t  i,
size_t  j 
)
virtual

Return a specific element of the matrix.

Parameters
iLine number of the element.
jColumn number of the element.

Implements RGenericMatrix.

Reimplemented in RSparseSymmetricMatrix.

const RSparseVector* operator[] ( size_t  i) const

Return the vector at a given line from the matrix (const version).

Parameters
iLine number of the vector.
RSparseVector* operator[] ( size_t  i)

Return the vector at a given line from the matrix.

Parameters
iLine number of the vector.
bool IsIn ( size_t  i) const

Verify if a given index has a vector defined in the matrix.

Parameters
iIndex.
Returns
true or false.
RSparseVector* GetValue ( size_t  i) const

Get a pointer over the vector at a given index.

Parameters
iIndex.
Returns
Pointer or null if the index hasn't no vector.

Member Data Documentation

bool AllLines
protected

All lines have an entry.

size_t InitNbCols
protected

Initial number of values to reserve for each line.