INMOST
A toolkit for distributed mathematical modeling
INMOST::Sparse::Row Class Reference

Class to store the sparse matrix row. More...

#include <inmost_sparse.h>

Classes

struct  entry_s
 Entry of the sparse matrix row. More...
 

Public Types

typedef struct INMOST::Sparse::Row::entry_s entry
 Entry of the sparse matrix row.
 
typedef Entries::iterator iterator
 Iterator over pairs of index and value.
 
typedef Entries::const_iterator const_iterator
 Iterator over constant pairs of index and value.
 
typedef Entries::reverse_iterator reverse_iterator
 Iterator over pairs of index and value running in backward direction.
 
typedef Entries::const_reverse_iterator const_reverse_iterator
 Iterator over constant pairs of index and value running in backward direction.
 

Public Member Functions

 Row ()
 Construct an empty row.
 
 Row (const Row &other)
 Copy all data from another row. More...
 
 Row (entry *pbegin, entry *pend)
 Construct a row from array of pairs of indices and values. More...
 
 ~Row ()
 Release all data.
 
Rowoperator= (Row const &other)
 Copy all data from another row. More...
 
INMOST_DATA_REAL_TYPE & operator[] (INMOST_DATA_ENUM_TYPE i)
 Finds and returns value with specified index. More...
 
INMOST_DATA_REAL_TYPE operator[] (INMOST_DATA_ENUM_TYPE i) const
 Finds and returns value with specified index. More...
 
INMOST_DATA_REAL_TYPE get_safe (INMOST_DATA_ENUM_TYPE i) const
 Finds and returns value with specified index. More...
 
void Clear ()
 Clear all data of the current row.
 
void Swap (Row &other)
 Exchange all the data with another row. More...
 
INMOST_DATA_ENUM_TYPE Size () const
 The size of the sparse row, i.e. the total number of nonzero elements.
 
bool Empty () const
 Checks are there any nonzero entries in the row.
 
INMOST_DATA_ENUM_TYPE & GetIndex (INMOST_DATA_ENUM_TYPE k)
 Retrieve an index corresponding to certain position in the array of pairs of index and value. More...
 
INMOST_DATA_REAL_TYPE & GetValue (INMOST_DATA_ENUM_TYPE k)
 Retrieve a value corresponding to certain position in the array of pairs of index and value. More...
 
INMOST_DATA_ENUM_TYPE GetIndex (INMOST_DATA_ENUM_TYPE k) const
 Retrieve an index corresponding to certain position in the array of pairs of index and value. More...
 
INMOST_DATA_REAL_TYPE GetValue (INMOST_DATA_ENUM_TYPE k) const
 Retrieve a value corresponding to certain position in the array of pairs of index and value. More...
 
iterator Begin ()
 Retrive interval of nonzeroes. More...
 
iterator End ()
 An iterator pointing behind the last position in the array of pairs of index and value.
 
const_iterator Begin () const
 An iterator pointing to the first position in the array of constant pairs of index and value.
 
const_iterator End () const
 An iterator pointing behind the last position in the array of constant pairs of index and value.
 
reverse_iterator rBegin ()
 An iterator pointing to the last position in the array of pairs of index and value.
 
reverse_iterator rEnd ()
 An iterator pointing before the first position in the array of pairs of index and value.
 
const_reverse_iterator rBegin () const
 An iterator pointing to the last position in the array of constant pairs of index and value.
 
const_reverse_iterator rEnd () const
 An iterator pointing before the first position in the array of constant pairs of index and value.
 
INMOST_DATA_REAL_TYPE RowVec (Vector &x) const
 Return the scalar product of the current sparse row by a dense Vector.
 
void MoveRow (Row &source)
 An optimized assignment of the row, when the content of the source row may not be preserved. More...
 
void Zero ()
 Set the vector entries by zeroes.
 
void Push (INMOST_DATA_ENUM_TYPE ind, INMOST_DATA_REAL_TYPE val)
 Push specified element into sparse row. More...
 
void Pop ()
 Remove last element.
 
void Resize (INMOST_DATA_ENUM_TYPE size)
 Resize row to specified size. More...
 
void Print (double eps=-1, std::ostream &sout=std::cout) const
 Output all entries of the row.
 
void Sort ()
 Sort row.
 
bool isSorted () const
 Check whether the row is sorted.
 

Static Public Member Functions

static __INLINE entry make_entry (INMOST_DATA_ENUM_TYPE ind, INMOST_DATA_REAL_TYPE val)
 Assemble an entry of entry_s type. More...
 
static void MergeSortedRows (INMOST_DATA_REAL_TYPE alpha, const Row &left, INMOST_DATA_REAL_TYPE beta, const Row &right, Row &output)
 Add up two rows. More...
 

Detailed Description

Class to store the sparse matrix row.

Represents a sparse vector and facilitates access to individual entries. This class is used in expressions of automatic differentiation.

Definition at line 161 of file inmost_sparse.h.

Constructor & Destructor Documentation

◆ Row() [1/2]

INMOST::Sparse::Row::Row ( const Row other)
inline

Copy all data from another row.

Parameters
otherAnother row.

Definition at line 201 of file inmost_sparse.h.

◆ Row() [2/2]

INMOST::Sparse::Row::Row ( entry pbegin,
entry pend 
)
inline

Construct a row from array of pairs of indices and values.

Parameters
pbeginPointer to the first position in array.
pendPointer behind the last position of array.

Definition at line 205 of file inmost_sparse.h.

Member Function Documentation

◆ Begin()

iterator INMOST::Sparse::Row::Begin ( )
inline

Retrive interval of nonzeroes.

An iterator pointing to the first position in the array of pairs of index and value.

Definition at line 275 of file inmost_sparse.h.

◆ get_safe()

INMOST_DATA_REAL_TYPE INMOST::Sparse::Row::get_safe ( INMOST_DATA_ENUM_TYPE  i) const
inline

Finds and returns value with specified index.

Returns zero if no entry was found.

Parameters
iIndex.
Returns
Value corresponding to specified index.

Definition at line 242 of file inmost_sparse.h.

◆ GetIndex() [1/2]

INMOST_DATA_ENUM_TYPE& INMOST::Sparse::Row::GetIndex ( INMOST_DATA_ENUM_TYPE  k)
inline

Retrieve an index corresponding to certain position in the array of pairs of index and value.

Parameters
kPosition in the array of pairs of index and value.
Returns
Index corresponding to the position in the array.

Definition at line 259 of file inmost_sparse.h.

◆ GetIndex() [2/2]

INMOST_DATA_ENUM_TYPE INMOST::Sparse::Row::GetIndex ( INMOST_DATA_ENUM_TYPE  k) const
inline

Retrieve an index corresponding to certain position in the array of pairs of index and value.

Parameters
kPosition in the array of pairs of index and value.
Returns
Index corresponding to the position in the array.

Definition at line 267 of file inmost_sparse.h.

◆ GetValue() [1/2]

INMOST_DATA_REAL_TYPE& INMOST::Sparse::Row::GetValue ( INMOST_DATA_ENUM_TYPE  k)
inline

Retrieve a value corresponding to certain position in the array of pairs of index and value.

Parameters
kPosition in the array of pairs of index and value.
Returns
Value corresponding to the position in the array.

Definition at line 263 of file inmost_sparse.h.

◆ GetValue() [2/2]

INMOST_DATA_REAL_TYPE INMOST::Sparse::Row::GetValue ( INMOST_DATA_ENUM_TYPE  k) const
inline

Retrieve a value corresponding to certain position in the array of pairs of index and value.

Parameters
kPosition in the array of pairs of index and value.
Returns
Value corresponding to the position in the array.

Definition at line 271 of file inmost_sparse.h.

◆ make_entry()

static __INLINE entry INMOST::Sparse::Row::make_entry ( INMOST_DATA_ENUM_TYPE  ind,
INMOST_DATA_REAL_TYPE  val 
)
inlinestatic

Assemble an entry of entry_s type.

Parameters
indIndex.
valValue.

Definition at line 180 of file inmost_sparse.h.

◆ MergeSortedRows()

static void INMOST::Sparse::Row::MergeSortedRows ( INMOST_DATA_REAL_TYPE  alpha,
const Row left,
INMOST_DATA_REAL_TYPE  beta,
const Row right,
Row output 
)
static

Add up two rows.

Performs operation output=alpha*left+beta*right.

Parameters
alphaCoefficient to multiply the left row.
leftThe left row.
betaCoefficient to multiply the right row.
rightThe right row.
outputRecord result in this vector.

◆ MoveRow()

void INMOST::Sparse::Row::MoveRow ( Row source)
inline

An optimized assignment of the row, when the content of the source row may not be preserved.

Parameters
sourceSource raw where to get the contents.

Definition at line 296 of file inmost_sparse.h.

◆ operator=()

Row& INMOST::Sparse::Row::operator= ( Row const &  other)
inline

Copy all data from another row.

Parameters
otherAnother row.

Definition at line 210 of file inmost_sparse.h.

◆ operator[]() [1/2]

INMOST_DATA_REAL_TYPE& INMOST::Sparse::Row::operator[] ( INMOST_DATA_ENUM_TYPE  i)
inline

Finds and returns value with specified index.

Adds a new entry if index was not found.

Warning
The operator [] should be used to fill the sparse matrix row, but not to routinely access individual elements of the row. You can use Sparse::Row::GetIndex and Sparse::Row::GetValue for rapid access to individual elements.
Parameters
iIndex.
Returns
Value corresponding to specified index.

Definition at line 217 of file inmost_sparse.h.

◆ operator[]() [2/2]

INMOST_DATA_REAL_TYPE INMOST::Sparse::Row::operator[] ( INMOST_DATA_ENUM_TYPE  i) const
inline

Finds and returns value with specified index.

Rises exception on debug and returns extra large value on release if index was not found.

Warning
The operator [] should be used to fill the sparse matrix row, but not to routinely access individual elements of the row. You can use Sparse::Row::GetIndex and Sparse::Row::GetValue for rapid access to individual elements.
Parameters
iIndex.
Returns
Value corresponding to specified index.

Definition at line 231 of file inmost_sparse.h.

◆ Push()

void INMOST::Sparse::Row::Push ( INMOST_DATA_ENUM_TYPE  ind,
INMOST_DATA_REAL_TYPE  val 
)
inline

Push specified element into sparse row.

This function should be used only if the index is not repeated in the row.

Definition at line 301 of file inmost_sparse.h.

◆ Resize()

void INMOST::Sparse::Row::Resize ( INMOST_DATA_ENUM_TYPE  size)
inline

Resize row to specified size.

It is intended to be used together with non-const Row::GetIndex and Row::GetValue that allow for the modification of individual entries.

Parameters
sizeNew size of the row.

Definition at line 308 of file inmost_sparse.h.

◆ Swap()

void INMOST::Sparse::Row::Swap ( Row other)
inline

Exchange all the data with another row.

Parameters
otherAnother row.

Definition at line 251 of file inmost_sparse.h.


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