QuOc

 

Public Member Functions | Protected Member Functions | Protected Attributes | Private Types

aol::SparseRow< DataType > Class Template Reference

#include <rows.h>

Inheritance diagram for aol::SparseRow< DataType >:
aol::Row< DataType >

List of all members.

Public Member Functions

 SparseRow ()
virtual ~SparseRow ()
DataType get (int, int J) const
DataType get (int J) const
void set (int, int J, DataType Value)
void set (int J, DataType Value)
int numNonZeroes () const
 return number of nonzero entries in the row (which is NOT the number of stored entries)
int numStoredEntries () const
DataType mult (const Vector< DataType > &Src, const int) const
DataType mult (const Vector< DataType > &src) const
virtual DataType multMaskedFunctorTrue (const Vector< DataType > &Src, int Row, const BitVector &Mask)
virtual DataType multMaskedFunctorFalse (const Vector< DataType > &Src, int Row, const BitVector &Mask)
virtual DataType multMaskedFunctorIdentity (const Vector< DataType > &Src, int Row, const BitVector &Mask)
virtual DataType multMaskedFunctorNegate (const Vector< DataType > &Src, int Row, const BitVector &Mask)
template<typename BitMaskFunctorType >
DataType multMasked (const Vector< DataType > &Src, int, const BitVector &Mask)
void scale (DataType factor)
DataType sum (int)
void scale (int, DataType factor)
 Scales row by factor, telling row it is the $I$th row.
void add (int, int J, DataType Value)
void add (int J, DataType Value)
void setZero ()
virtual void makeRowEntries (vector< typename Row< DataType >::RowEntry > &vec, const int) const
virtual void makeSortedRowEntries (vector< typename Row< DataType >::RowEntry > &vec, const int) const
 SparseMatrix has already sorted rows.
bool checkForNANsAndINFs () const
 ATTENTION: the name is misleading!
SparseRow< DataType > & operator= (const SparseRow< DataType > &from)
void eraseZeroEntries ()

Protected Member Functions

void initGetRowEntries () const
void getNextRowEntry (typename Row< DataType >::RowEntry &Entry, int) const

Protected Attributes

vector< qcCurMatrixEntryrow
vector< qcCurMatrixEntry >
::iterator 
lastReturnedRowEntry

Private Types

typedef Row< DataType >::RowEntry qcCurMatrixEntry

Detailed Description

template<typename DataType>
class aol::SparseRow< DataType >

class for general sparse rows that do not necessarily have a special structure

Definition at line 157 of file rows.h.


Member Typedef Documentation

template<typename DataType>
typedef Row<DataType>::RowEntry aol::SparseRow< DataType >::qcCurMatrixEntry [private]

Definition at line 160 of file rows.h.


Constructor & Destructor Documentation

template<typename DataType>
aol::SparseRow< DataType >::SparseRow (  )  [inline]

Definition at line 163 of file rows.h.

References aol::SparseRow< DataType >::initGetRowEntries().

template<typename DataType>
virtual aol::SparseRow< DataType >::~SparseRow (  )  [inline, virtual]

Definition at line 167 of file rows.h.

{}


Member Function Documentation

template<typename DataType>
void aol::SparseRow< DataType >::add ( int  ,
int  J,
DataType  Value 
) [inline, virtual]

Implements aol::Row< DataType >.

Definition at line 294 of file rows.h.

                                           {
    add ( J, Value );
  }

template<typename DataType>
void aol::SparseRow< DataType >::add ( int  J,
DataType  Value 
) [inline]

Definition at line 298 of file rows.h.

References aol::SparseRow< DataType >::row.

                                     {
    typename vector<qcCurMatrixEntry>::iterator it;
    if ( Value != 0.0 ) {
      for ( it = row.begin(); it != row.end() && it->col <= J; ++it ) {
        if ( ( *it ).col == J ) {
          ( *it ).value += Value;
          return;
        }
      }
      // Not found, insert before it
      row.insert ( it, qcCurMatrixEntry ( J, Value ) );
    }
  }

template<typename DataType>
bool aol::SparseRow< DataType >::checkForNANsAndINFs (  )  const [inline, virtual]

ATTENTION: the name is misleading!

Implements aol::Row< DataType >.

Definition at line 326 of file rows.h.

References aol::isFinite(), and aol::SparseRow< DataType >::row.

                                   {
    typename vector<qcCurMatrixEntry>::const_iterator it;
    for ( it = row.begin(); it != row.end(); ++it ) {
      if ( !aol::isFinite ( it->value ) ) {
        return true;
      }
    }
    return false;
  }

template<typename DataType>
void aol::SparseRow< DataType >::eraseZeroEntries (  )  [inline]

Definition at line 345 of file rows.h.

References aol::SparseRow< DataType >::row.

                            {
    for ( typename vector<qcCurMatrixEntry>::iterator it = row.begin(); it != row.end(); ) {
      if ( it->value == aol::NumberTrait<DataType>::zero ) {
        it = row.erase ( it );
      } else {
        ++it;
      }
    }
  }

template<typename DataType>
DataType aol::SparseRow< DataType >::get ( int  ,
int  J 
) const [inline, virtual]

Implements aol::Row< DataType >.

Definition at line 169 of file rows.h.

                                     {
    return ( get ( J ) );
  }

template<typename DataType>
DataType aol::SparseRow< DataType >::get ( int  J  )  const [inline]

Definition at line 173 of file rows.h.

References aol::SparseRow< DataType >::row.

                               {
    typename vector<qcCurMatrixEntry>::const_iterator it;
    for ( it = row.begin(); it != row.end() && it->col <= J; ++it ) {
      if ( ( *it ).col == J ) {
        return ( *it ).value;
      }
    }
    return 0;
  }

template<typename DataType>
void aol::SparseRow< DataType >::getNextRowEntry ( typename Row< DataType >::RowEntry Entry,
int   
) const [inline, protected]

Definition at line 360 of file rows.h.

References aol::Row< DataType >::RowEntry::col, aol::SparseRow< DataType >::lastReturnedRowEntry, aol::SparseRow< DataType >::row, and aol::Row< DataType >::RowEntry::value.

                                                                                  { // i is ignored
    if ( lastReturnedRowEntry != row.end() ) {
      Entry.col = ( *lastReturnedRowEntry ).col;
      Entry.value = ( *lastReturnedRowEntry ).value;
      lastReturnedRowEntry++;
    } else {
      Entry.col = -1;
      Entry.value = 0;
    }
  }

template<typename DataType>
void aol::SparseRow< DataType >::initGetRowEntries (  )  const [inline, protected, virtual]
template<typename DataType>
virtual void aol::SparseRow< DataType >::makeRowEntries ( vector< typename Row< DataType >::RowEntry > &  vec,
const   int 
) const [inline, virtual]

Definition at line 316 of file rows.h.

References aol::SparseRow< DataType >::row.

                                                                                                           {
    vec = row;
  }

template<typename DataType>
virtual void aol::SparseRow< DataType >::makeSortedRowEntries ( vector< typename Row< DataType >::RowEntry > &  vec,
const   int 
) const [inline, virtual]

SparseMatrix has already sorted rows.

Definition at line 321 of file rows.h.

References aol::SparseRow< DataType >::row.

                                                                                                                 {
    vec = row;
  }

template<typename DataType>
DataType aol::SparseRow< DataType >::mult ( const Vector< DataType > &  src  )  const [inline]

Definition at line 235 of file rows.h.

References aol::SparseRow< DataType >::mult().

                                                      {
    return ( mult ( src, 0 ) ); // or any other index instead of 0
  }

template<typename DataType>
DataType aol::SparseRow< DataType >::mult ( const Vector< DataType > &  Src,
const   int 
) const [inline, virtual]

row-vector scalar multiplication

Implements aol::Row< DataType >.

Definition at line 226 of file rows.h.

References aol::Vector< _DataType >::get(), and aol::SparseRow< DataType >::row.

Referenced by aol::SparseRow< DataType >::mult().

                                                                           {
    typename vector<qcCurMatrixEntry>::const_iterator it;

    DataType dst = ZOTrait<DataType>::zero;
    for ( it = row.begin(); it != row.end(); ++it )
      dst += ( *it ).value * Src.get ( ( *it ).col );
    return ( dst );
  }

template<typename DataType>
template<typename BitMaskFunctorType >
DataType aol::SparseRow< DataType >::multMasked ( const Vector< DataType > &  Src,
int  ,
const BitVector Mask 
) [inline]

masked row-vector scalar mulitplication (if desired only include nodes that are (not) masked

Definition at line 255 of file rows.h.

References aol::Vector< _DataType >::get(), and aol::SparseRow< DataType >::row.

                                                 {

    BitMaskFunctorType maskFunctor;
    DataType dst = ZOTrait<DataType>::zero;
    typename vector<qcCurMatrixEntry>::const_iterator it;

    for ( it = row.begin(); it != row.end(); ++it )
      if ( maskFunctor ( Mask[ ( *it ).col] ) )     // i.e. this node is to be included
        dst += ( *it ).value * Src.get ( ( *it ).col );
    return ( dst );
  }

template<typename DataType>
virtual DataType aol::SparseRow< DataType >::multMaskedFunctorFalse ( const Vector< DataType > &  Src,
int  Row,
const BitVector Mask 
) [inline, virtual]

Implements aol::Row< DataType >.

Definition at line 242 of file rows.h.

                                                                                                           {
    return multMasked<BitMaskFunctorFalse> ( Src, Row, Mask );
  }

template<typename DataType>
virtual DataType aol::SparseRow< DataType >::multMaskedFunctorIdentity ( const Vector< DataType > &  Src,
int  Row,
const BitVector Mask 
) [inline, virtual]

Implements aol::Row< DataType >.

Definition at line 245 of file rows.h.

                                                                                                              {
    return multMasked<BitMaskFunctorIdentity> ( Src, Row, Mask );
  }

template<typename DataType>
virtual DataType aol::SparseRow< DataType >::multMaskedFunctorNegate ( const Vector< DataType > &  Src,
int  Row,
const BitVector Mask 
) [inline, virtual]

Implements aol::Row< DataType >.

Definition at line 248 of file rows.h.

                                                                                                            {
    return multMasked<BitMaskFunctorNegate> ( Src, Row, Mask );
  }

template<typename DataType>
virtual DataType aol::SparseRow< DataType >::multMaskedFunctorTrue ( const Vector< DataType > &  Src,
int  Row,
const BitVector Mask 
) [inline, virtual]

Implements aol::Row< DataType >.

Definition at line 239 of file rows.h.

                                                                                                          {
    return multMasked<BitMaskFunctorTrue> ( Src, Row, Mask );
  }

template<typename DataType>
int aol::SparseRow< DataType >::numNonZeroes (  )  const [inline, virtual]

return number of nonzero entries in the row (which is NOT the number of stored entries)

Implements aol::Row< DataType >.

Definition at line 210 of file rows.h.

References aol::SparseRow< DataType >::row.

                             {
    typename vector<qcCurMatrixEntry>::const_iterator it;
    int nNonZeroes = 0;
    for ( it = row.begin(); it != row.end(); ++it ) {
      if ( it->value != aol::NumberTrait<DataType>::zero )
        ++nNonZeroes;
    }
    return nNonZeroes;
  }

template<typename DataType>
int aol::SparseRow< DataType >::numStoredEntries (  )  const [inline, virtual]

Reimplemented from aol::Row< DataType >.

Definition at line 220 of file rows.h.

References aol::SparseRow< DataType >::row.

                               {
    return static_cast<int> ( row.size() );
  }

template<typename DataType>
SparseRow<DataType>& aol::SparseRow< DataType >::operator= ( const SparseRow< DataType > &  from  )  [inline]

Definition at line 338 of file rows.h.

References aol::SparseRow< DataType >::lastReturnedRowEntry, and aol::SparseRow< DataType >::row.

                                                                     {
    this->row = from.row;
    lastReturnedRowEntry = from.lastReturnedRowEntry;
    return ( *this );
  }

template<typename DataType>
void aol::SparseRow< DataType >::scale ( int  I,
DataType  factor 
) [inline, virtual]

Scales row by factor, telling row it is the $I$th row.

Implements aol::Row< DataType >.

Definition at line 290 of file rows.h.

References aol::SparseRow< DataType >::scale().

                                       {
    scale ( factor );
  }

template<typename DataType>
void aol::SparseRow< DataType >::scale ( DataType  factor  )  [inline]

row is mapped to scalar * row

Reimplemented from aol::Row< DataType >.

Definition at line 271 of file rows.h.

References aol::SparseRow< DataType >::row.

Referenced by aol::SparseRow< DataType >::scale().

                                 {
    typename vector<qcCurMatrixEntry>::iterator it;
    for ( it = row.begin(); it != row.end(); ++it ) {
      ( *it ).value *= factor;
    }
  }

template<typename DataType>
void aol::SparseRow< DataType >::set ( int  ,
int  J,
DataType  Value 
) [inline, virtual]

Implements aol::Row< DataType >.

Definition at line 183 of file rows.h.

                                           {
    set ( J, Value );
  }

template<typename DataType>
void aol::SparseRow< DataType >::set ( int  J,
DataType  Value 
) [inline]

Definition at line 187 of file rows.h.

References aol::SparseRow< DataType >::row.

                                     {
    typename vector<qcCurMatrixEntry>::iterator it;
    if ( Value != 0.0 ) {
      for ( it = row.begin(); it != row.end() && it->col <= J; ++it ) {
        if ( ( *it ).col == J ) {
          ( *it ).value = Value;
          return;
        }
      }

      // Not found, insert before it
      row.insert ( it, qcCurMatrixEntry ( J, Value ) );
    } else {
      for ( it = row.begin(); it != row.end() && it->col <= J; ++it ) {
        if ( ( *it ).col == J ) {
          row.erase ( it );
          break;
        }
      }
    }
  }

template<typename DataType>
void aol::SparseRow< DataType >::setZero (  )  [inline, virtual]

Implements aol::Row< DataType >.

Definition at line 312 of file rows.h.

References aol::SparseRow< DataType >::row.

                 {
    row.erase ( row.begin(), row.end() );
  }

template<typename DataType>
DataType aol::SparseRow< DataType >::sum ( int   )  [inline, virtual]

computes row sum

Implements aol::Row< DataType >.

Definition at line 280 of file rows.h.

References aol::SparseRow< DataType >::row.

                       {
    // I is ignored
    typename vector<qcCurMatrixEntry>::iterator it;
    DataType result = 0;
    for ( it = row.begin(); it != row.end(); ++it ) {
      result += ( *it ).value;
    }
    return ( result );
  }


Member Data Documentation


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

Generated on Fri Sep 9 2011 21:09:14 for QuocMesh by doxygen 1.7.1