Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator > Class Template Reference

Sparse Array-matrix class. More...

#include <Matrix_ArraySparse.hxx>

List of all members.

Public Types

typedef Allocator::value_type value_type
typedef Allocator::pointer pointer
typedef Allocator::const_pointer const_pointer
typedef Allocator::reference reference
typedef Allocator::const_reference const_reference
typedef T entry_type
typedef T & access_type
typedef T const_access_type

Public Member Functions

 Matrix_ArraySparse ()
 Default constructor.
 Matrix_ArraySparse (int i, int j)
 Constructor.
 ~Matrix_ArraySparse ()
 Destructor.
void Clear ()
 Clears the matrix.
void Reallocate (int i, int j)
 Reallocates memory to resize the matrix.
void Resize (int i, int j)
 Reallocates additional memory to resize the matrix.
int GetM () const
 Returns the number of rows.
int GetN () const
 Returns the number of columns.
int GetM (const SeldonTranspose &status) const
 Returns the number of rows of the matrix possibly transposed.
int GetN (const SeldonTranspose &status) const
 Returns the number of columns of the matrix possibly transposed.
int GetNonZeros () const
 Returns the number of non-zero entries.
int GetDataSize () const
 Returns the number of elements stored in memory.
int * GetIndex (int i) const
 Returns (row or column) indices of non-zero entries in row.
T * GetData (int i) const
 Returns values of non-zero entries of a row/column.
Vector< T, VectSparse,
Allocator > * 
GetData () const
 Returns values of non-zero entries.
operator() (int i, int j) const
 Access operator.
T & Get (int i, int j)
 Access operator.
const T & Get (int i, int j) const
 Access operator.
T & Val (int i, int j)
 Access operator.
const T & Val (int i, int j) const
 Access operator.
void Set (int i, int j, const T &x)
 Sets an element of the matrix.
const T & Value (int num_row, int i) const
 Returns j-th non-zero value of row/column i.
T & Value (int num_row, int i)
 Returns j-th non-zero value of row/column i.
int Index (int num_row, int i) const
 Returns column/row number of j-th non-zero value of row/column i.
int & Index (int num_row, int i)
 Returns column/row number of j-th non-zero value of row/column i.
void SetData (int, int, Vector< T, VectSparse, Allocator > *)
 Redefines the matrix.
void SetData (int, int, T *, int *)
 Redefines a row/column of the matrix.
void Nullify (int i)
 Clears a row without releasing memory.
void Nullify ()
 Clears the matrix without releasing memory.
void Print () const
 Displays the matrix on the standard output.
void Assemble ()
 Assembles the matrix.
template<class T0 >
void RemoveSmallEntry (const T0 &epsilon)
 Removes small coefficients from entries.
void SetIdentity ()
 Matrix is initialized to the identity matrix.
void Zero ()
 Non-zero entries are set to 0 (but not removed).
void Fill ()
 Non-zero entries are filled with values 0, 1, 2, 3 ...
template<class T0 >
void Fill (const T0 &x)
 Non-zero entries are set to a given value x.
template<class T0 >
Matrix_ArraySparse< T, Prop,
Storage, Allocator > & 
operator= (const T0 &x)
 Non-zero entries are set to a given value x.
void FillRand ()
 Non-zero entries take a random value.
void Write (string FileName) const
 Writes the matrix in a file.
void Write (ostream &FileStream) const
 Writes the matrix to an output stream.
void WriteText (string FileName) const
 Writes the matrix in a file.
void WriteText (ostream &FileStream) const
 Writes the matrix to an output stream.
void Read (string FileName)
 Reads the matrix from a file.
void Read (istream &FileStream)
 Reads the matrix from an input stream.
void ReadText (string FileName)
 Reads the matrix from a file.
void ReadText (istream &FileStream)
 Reads the matrix from an input stream.

Protected Attributes

int m_
 Number of rows.
int n_
 Number of columns.
Vector< Vector< T, VectSparse,
Allocator >, VectFull,
NewAlloc< Vector< T,
VectSparse, Allocator > > > 
val_
 rows or columns

Detailed Description

template<class T, class Prop, class Storage, class Allocator = SELDON_DEFAULT_ALLOCATOR<T>>
class Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >

Sparse Array-matrix class.

Sparse matrices are defined by: (1) the number of rows and columns; (2) the number of non-zero entries; (3) an array of vectors ind ind(i) is a vector, which contains indices of columns of the row i (4) an array of vectors val : val(i) is a vector, which contains values of the row i

Definition at line 38 of file Matrix_ArraySparse.hxx.


Constructor & Destructor Documentation

template<class T , class Prop , class Storage , class Allocator >
Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >::Matrix_ArraySparse (  )  [inline]

Default constructor.

Builds an empty matrix.

Definition at line 30 of file Matrix_ArraySparse.cxx.

template<class T , class Prop , class Storage , class Allocator >
Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >::Matrix_ArraySparse ( int  i,
int  j 
) [inline]

Constructor.

Builds a i by j sparse matrix.

Parameters:
i number of rows.
j number of columns.

Definition at line 46 of file Matrix_ArraySparse.cxx.


Member Function Documentation

template<class T , class Prop , class Storage , class Allocator >
void Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >::Assemble (  ) 

Assembles the matrix.

All the column/row numbers are sorted. If same column/row numbers exist, values are added.

Warning:
If you are using the methods AddInteraction, you don't need to call that method.

Definition at line 627 of file Matrix_ArraySparse.cxx.

template<class T , class Prop , class Storage , class Allocator >
void Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >::Clear (  )  [inline]

Clears the matrix.

This methods is equivalent to the destructor. On exit, the matrix is empty (0 by 0).

Definition at line 68 of file Matrix_ArraySparse.cxx.

template<class T , class Prop , class Storage , class Allocator >
T & Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >::Get ( int  i,
int  j 
) [inline]

Access operator.

Returns the value of element (i, j).

Parameters:
i row index.
j column index.
Returns:
Element (i, j) of the matrix.

Reimplemented in Seldon::Matrix< T, Prop, ArrayColSymSparse, Allocator >, and Seldon::Matrix< T, Prop, ArrayRowSymSparse, Allocator >.

Definition at line 305 of file Matrix_ArraySparse.cxx.

template<class T , class Prop , class Storage , class Allocator >
const T & Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >::Get ( int  i,
int  j 
) const [inline]

Access operator.

Returns the value of element (i, j).

Parameters:
i row index.
j column index.
Returns:
Element (i, j) of the matrix.

Reimplemented in Seldon::Matrix< T, Prop, ArrayColSymSparse, Allocator >, and Seldon::Matrix< T, Prop, ArrayRowSymSparse, Allocator >.

Definition at line 333 of file Matrix_ArraySparse.cxx.

template<class T , class Prop , class Storage , class Allocator >
T * Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >::GetData ( int  i  )  const [inline]

Returns values of non-zero entries of a row/column.

Parameters:
[in] i row (or column) number.
Returns:
The array of values of non-zero entries of row/column i.

Definition at line 243 of file Matrix_ArraySparse.cxx.

template<class T , class Prop , class Storage , class Allocat >
Vector< T, VectSparse, Allocat > * Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocat >::GetData (  )  const [inline]

Returns values of non-zero entries.

Returns:
Array of sparse rows There is a different array for each row/column.

Definition at line 256 of file Matrix_ArraySparse.cxx.

template<class T , class Prop , class Storage , class Allocator >
int Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >::GetDataSize (  )  const [inline]

Returns the number of elements stored in memory.

Returns the number of elements stored in memory, i.e. the number of non-zero entries.

Returns:
The number of elements stored in memory.

Definition at line 215 of file Matrix_ArraySparse.cxx.

template<class T , class Prop , class Storage , class Allocator >
int * Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >::GetIndex ( int  i  )  const [inline]

Returns (row or column) indices of non-zero entries in row.

Parameters:
[in] i row (or column) number.
Returns:
The array of column (or row) indices of non-zero entries of row (or column) i.

Definition at line 229 of file Matrix_ArraySparse.cxx.

template<class T , class Prop , class Storage , class Allocator >
int Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >::GetM (  )  const [inline]

Returns the number of rows.

Returns:
the number of rows.

Definition at line 143 of file Matrix_ArraySparse.cxx.

template<class T , class Prop , class Storage , class Allocator >
int Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >::GetM ( const SeldonTranspose status  )  const [inline]

Returns the number of rows of the matrix possibly transposed.

Parameters:
status assumed status about the transposition of the matrix.
Returns:
The number of rows of the possibly-transposed matrix.

Definition at line 167 of file Matrix_ArraySparse.cxx.

template<class T , class Prop , class Storage , class Allocator >
int Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >::GetN (  )  const [inline]

Returns the number of columns.

Returns:
the number of columns.

Definition at line 154 of file Matrix_ArraySparse.cxx.

template<class T , class Prop , class Storage , class Allocator >
int Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >::GetN ( const SeldonTranspose status  )  const [inline]

Returns the number of columns of the matrix possibly transposed.

Parameters:
status assumed status about the transposition of the matrix.
Returns:
The number of columns of the possibly-transposed matrix.

Definition at line 183 of file Matrix_ArraySparse.cxx.

template<class T , class Prop , class Storage , class Allocator >
int Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >::GetNonZeros (  )  const [inline]

Returns the number of non-zero entries.

Returns:
The number of non-zero entries.

Definition at line 197 of file Matrix_ArraySparse.cxx.

template<class T , class Prop , class Storage , class Allocator >
int Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >::Index ( int  i,
int  j 
) const [inline]

Returns column/row number of j-th non-zero value of row/column i.

Parameters:
[in] i row/column number.
[in] j local number.
Returns:
Column/row number of j-th non-zero value of row/column i.

Definition at line 485 of file Matrix_ArraySparse.cxx.

template<class T , class Prop , class Storage , class Allocator >
int & Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >::Index ( int  i,
int  j 
) [inline]

Returns column/row number of j-th non-zero value of row/column i.

Parameters:
[in] i row/column number.
[in] j local number.
Returns:
Column/row number of j-th non-zero value of row/column i.

Definition at line 512 of file Matrix_ArraySparse.cxx.

template<class T , class Prop , class Storage , class Allocator >
void Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >::Nullify ( int  i  )  [inline]

Clears a row without releasing memory.

On exit, the row is empty and the memory has not been released. It is useful for low level manipulations on a Matrix instance.

Definition at line 552 of file Matrix_ArraySparse.cxx.

template<class T , class Prop , class Storage , class Allocator >
void Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >::Nullify (  )  [inline]

Clears the matrix without releasing memory.

On exit, the matrix is empty and the memory has not been released. It is useful for low level manipulations on a Matrix instance.

Definition at line 580 of file Matrix_ArraySparse.cxx.

template<class T , class Prop , class Storage , class Allocator >
T Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >::operator() ( int  i,
int  j 
) const [inline]

Access operator.

Returns the value of element (i, j).

Parameters:
[in] i row index.
[in] j column index.
Returns:
Element (i, j) of the matrix.

Reimplemented in Seldon::Matrix< T, Prop, ArrayColSymSparse, Allocator >, and Seldon::Matrix< T, Prop, ArrayRowSymSparse, Allocator >.

Definition at line 276 of file Matrix_ArraySparse.cxx.

template<class T , class Prop , class Storage , class Allocator >
void Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >::Print (  )  const

Displays the matrix on the standard output.

Displays elements on the standard output, in text format. Each row is displayed on a single line and elements of a row are delimited by tabulations.

Definition at line 600 of file Matrix_ArraySparse.cxx.

template<class T , class Prop , class Storage , class Allocator >
void Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >::Read ( istream &  FileStream  ) 

Reads the matrix from an input stream.

Reads a matrix in binary format from an input stream. The number of rows (integer) and the number of columns (integer) are read and matrix elements are then read in the same order as it should be in memory (e.g. row-major storage).

Parameters:
FileStream output file name.

Definition at line 882 of file Matrix_ArraySparse.cxx.

template<class T , class Prop , class Storage , class Allocator >
void Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >::Read ( string  FileName  ) 

Reads the matrix from a file.

Reads a matrix stored in binary format in a file. The number of rows (integer) and the number of columns (integer) are read and matrix elements are then read in the same order as it should be in memory (e.g. row-major storage).

Parameters:
FileName output file name.

Definition at line 854 of file Matrix_ArraySparse.cxx.

template<class T , class Prop , class Storage , class Allocator >
void Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >::ReadText ( string  FileName  ) 

Reads the matrix from a file.

Reads the matrix from a file in text format.

Parameters:
FileName input file name.

Definition at line 920 of file Matrix_ArraySparse.cxx.

template<class T , class Prop , class Storage , class Allocator >
void Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >::ReadText ( istream &  FileStream  ) 

Reads the matrix from an input stream.

Reads a matrix from a stream in text format.

Parameters:
FileStream input stream.

Definition at line 945 of file Matrix_ArraySparse.cxx.

template<class T , class Prop , class Storage , class Allocator >
void Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >::Reallocate ( int  i,
int  j 
) [inline]

Reallocates memory to resize the matrix.

On exit, the matrix is a i x j matrix.

Parameters:
i number of rows.
j number of columns.
Warning:
Data is lost.

Definition at line 88 of file Matrix_ArraySparse.cxx.

template<class T , class Prop , class Storage , class Allocator >
template<class T0 >
void Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >::RemoveSmallEntry ( const T0 &  epsilon  ) 

Removes small coefficients from entries.

Parameters:
[in] epsilon entries whose values are below epsilon are removed.

Definition at line 641 of file Matrix_ArraySparse.cxx.

template<class T , class Prop , class Storage , class Allocator >
void Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >::Resize ( int  i,
int  j 
)

Reallocates additional memory to resize the matrix.

On exit, the matrix is a i x j matrix.

Parameters:
i number of rows.
j number of columns. Data is kept

Definition at line 109 of file Matrix_ArraySparse.cxx.

template<class T, class Prop , class Storage , class Allocator >
void Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >::Set ( int  i,
int  j,
const T &  x 
) [inline]

Sets an element of the matrix.

Parameters:
i row index.
j column index.
x new value for the matrix element (i, j).

Reimplemented in Seldon::Matrix< T, Prop, ArrayColSymSparse, Allocator >, and Seldon::Matrix< T, Prop, ArrayRowSymSparse, Allocator >.

Definition at line 418 of file Matrix_ArraySparse.cxx.

template<class T, class Prop , class Storage , class Allocator>
void Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >::SetData ( int  m,
int  n,
Vector< T, VectSparse, Allocator > *  val 
) [inline]

Redefines the matrix.

Parameters:
[in] m new number of rows.
[in] n new number of columns.
[in] val array of sparse rows/columns.

Definition at line 566 of file Matrix_ArraySparse.cxx.

template<class T, class Prop , class Storage , class Allocator>
void Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >::SetData ( int  i,
int  n,
T *  val,
int *  ind 
) [inline]

Redefines a row/column of the matrix.

Parameters:
[in] i row/col number
[in] n number of non-zero entries in the row
[in] val values
[in] ind column numbers

Definition at line 540 of file Matrix_ArraySparse.cxx.

template<class T , class Prop , class Storage , class Allocator >
T & Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >::Val ( int  i,
int  j 
) [inline]

Access operator.

Returns the value of element (i, j).

Parameters:
i row index.
j column index.
Returns:
Element (i, j) of the matrix.

Reimplemented in Seldon::Matrix< T, Prop, ArrayColSymSparse, Allocator >, and Seldon::Matrix< T, Prop, ArrayRowSymSparse, Allocator >.

Definition at line 361 of file Matrix_ArraySparse.cxx.

template<class T , class Prop , class Storage , class Allocator >
const T & Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >::Val ( int  i,
int  j 
) const [inline]

Access operator.

Returns the value of element (i, j).

Parameters:
i row index.
j column index.
Returns:
Element (i, j) of the matrix.

Reimplemented in Seldon::Matrix< T, Prop, ArrayColSymSparse, Allocator >, and Seldon::Matrix< T, Prop, ArrayRowSymSparse, Allocator >.

Definition at line 390 of file Matrix_ArraySparse.cxx.

template<class T , class Prop , class Storage , class Allocator >
T & Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >::Value ( int  i,
int  j 
) [inline]

Returns j-th non-zero value of row/column i.

Parameters:
[in] i row/column number.
[in] j local number.
Returns:
j-th non-zero entry of row/column i.

Definition at line 459 of file Matrix_ArraySparse.cxx.

template<class T , class Prop , class Storage , class Allocator >
const T & Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >::Value ( int  i,
int  j 
) const [inline]

Returns j-th non-zero value of row/column i.

Parameters:
[in] i row/column number.
[in] j local number.
Returns:
j-th non-zero entry of row/column i.

Definition at line 432 of file Matrix_ArraySparse.cxx.

template<class T , class Prop , class Storage , class Allocator >
void Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >::Write ( ostream &  FileStream  )  const

Writes the matrix to an output stream.

Stores the matrix in a file in binary format. The number of rows (integer) and the number of columns (integer) are written and matrix elements are then written in the same order as in memory (e.g. row-major storage).

Parameters:
FileStream output file name.

Definition at line 748 of file Matrix_ArraySparse.cxx.

template<class T , class Prop , class Storage , class Allocator >
void Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >::Write ( string  FileName  )  const

Writes the matrix in a file.

Stores the matrix in a file in binary format. The number of rows (integer) and the number of columns (integer) are written and matrix elements are then written in the same order as in memory (e.g. row-major storage).

Parameters:
FileName output file name.

Definition at line 720 of file Matrix_ArraySparse.cxx.

template<class T , class Prop , class Storage , class Allocator >
void Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >::WriteText ( ostream &  FileStream  )  const

Writes the matrix to an output stream.

Stores the matrix in a file in ascii format. The entries are written in coordinate format (row column value). 1-index convention is used.

Parameters:
FileStream output file name.

Definition at line 800 of file Matrix_ArraySparse.cxx.

template<class T , class Prop , class Storage , class Allocator >
void Seldon::Matrix_ArraySparse< T, Prop, Storage, Allocator >::WriteText ( string  FileName  )  const

Writes the matrix in a file.

Stores the matrix in a file in ascii format. The entries are written in coordinate format (row column value). 1-index convention is used.

Parameters:
FileName output file name.

Definition at line 775 of file Matrix_ArraySparse.cxx.


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