Jive reference manual
List of all members | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes
jive::algebra::SparseMatrix Class Referenceabstract

Encapsulates a sparse matrix. More...

Inheritance diagram for jive::algebra::SparseMatrix:
Inheritance graph

Public Types

typedef SparseMatrix Self
 The type of this class. More...
 
typedef jem::numeric::SparseMatrix< double > RawMatrix
 A type containing the sparse matrix data. More...
 
typedef RawMatrix::Structure Structure
 A type representing the structure of a sparse matrix. More...
 
- Public Types inherited from jive::algebra::AbstractMatrix
typedef AbstractMatrix Self
 The type of this class. More...
 
typedef jem::Tuple< int, 2 > Shape
 A type representing the shape of a matrix. More...
 
typedef util::Vector Vector
 A vector type. More...
 

Public Member Functions

virtual Shape shape () const
 Returns the shape of this sparse matrix. More...
 
void setMatrix (const RawMatrix &mat)=0
 Sets the sparse matrix encapsulated by this object. More...
 
const RawMatrixgetMatrix () const =0
 Returns the sparse matrix encapsulated by this object. More...
 
void SparseMatrix::handleNewValues ()
 Notifies this object that the contents of the sparse matrix have been modified. More...
 
const VectorgetValues () const
 Returns a reference to the sparse matrix values. More...
 
Structure getStructure () const
 Returns the structure of this sparse matrix. More...
 
virtual jem::ClassgetClass () const
 Returns the Class instance representing the runtime class of this object. More...
 
virtual void readFrom (jem::io::ObjectInput &in)
 
virtual void writeTo (jem::io::ObjectOutput &out) const
 
virtual jem::Ref< jem::Objectclone () const
 
virtual void matmul (const Vector &lhs, const Vector &rhs) const
 Matrix-vector multiplication. More...
 
- Public Member Functions inherited from jive::algebra::AbstractMatrix
bool isSquare () const
 Tests whether this matrix is square. More...
 
- Public Member Functions inherited from jem::Object
virtual String toString () const
 Returns a short textual description of this object. More...
 
virtual long hashValue () const
 Returns a hash value for this object. More...
 
virtual bool equals (const Ref< Object > &obj) const
 Tests whether two objects are equal. More...
 
Ref< Objectclone () const
 Returns a copy of this object. More...
 

Static Public Member Functions

static jem::ClassgetType ()
 
- Static Public Member Functions inherited from jive::algebra::AbstractMatrix
static jem::ClassgetType ()
 
- Static Public Member Functions inherited from jem::Object
static ClassgetType ()
 Returns the Class instance representing the Object class. More...
 

Public Attributes

jem::util::Event< Self & > newStructureEvent
 Signals that the structure of this sparse matrix has been modified. More...
 
- Public Attributes inherited from jive::algebra::AbstractMatrix
jem::util::Event< Self & > newShapeEvent
 Signals that the shape of this matrix has changed. More...
 
jem::util::Event< Self & > newValuesEvent
 Signals that the contents of this matrix have been modified. More...
 

Additional Inherited Members

- Protected Member Functions inherited from jem::Collectable
 Collectable ()
 Creates an empty Collectable. More...
 
 ~Collectable ()
 Frees resources. More...
 
- Protected Member Functions inherited from jem::Clonable
virtual ~Clonable ()
 
virtual void emitVTable_ ()
 
- Protected Member Functions inherited from jem::Interface
virtual ~Interface ()
 Empty destructor. More...
 
- Protected Member Functions inherited from jem::io::Serializable
virtual ~Serializable ()
 
virtual void emitVtableFunc_ ()
 

Detailed Description

The abstract class SparseMatrix encapsulates a sparse matrix. Since it is derived from the AbstractMatrix class, an instance of the SparseMatrix class can be used wherever an instance of the AbstractMatrix class is required.

The SparseMatrix class itself has no data; derived classes are responsible for storing the actual sparse matrix and any additional data structures that they require.

Member Typedef Documentation

The Self type is a convenient synonym for SparseMatrix.

The RawMatrix type represents the sparse matrix that is encapsulated by a SparseMatrix object. It is an alias for jem::numeric::SparseMatrix<double>.

The Structure type encapsulates the non-zero pattern of a parse matrix. It is an alias for jem::numeric::SparseStructure.

Member Function Documentation

virtual Shape jive::algebra::SparseMatrix::shape ( ) const
virtual

Retruns the shape of this sparse matrix. The implementation of this function provided by the SparseMatrix class simply executes:

return getMatrix().shape();

Derived classes may provide a more efficient implementation.

Returns
The shape of this sparse matrix.

Implements jive::algebra::AbstractMatrix.

void jive::algebra::SparseMatrix::setMatrix ( const RawMatrix mat)
pure virtual

Assigns the sparse matrix encapsulated by this object the value mat. For performance reasons, the matrix mat may be copied by reference. This means that the original matrix should not be modified after calling this function.

An implementation of this function should emit the event newStructureEvent. If the new matrix has a different shape than the current matrix, then this function should also emit the event newShapeEvent. Otherwise, it should emit the event newValuesEvent.

Parameters
mat- the sparse matrix that is to be copied into this SparseMatrix object.
const RawMatrix& jive::algebra::SparseMatrix::getMatrix ( ) const
pure virtual

Returns a reference to the sparse matrix encapulated by this object. The reference remains valid until this object is destroyed or until the setMatrix() member function is called.

The structure of the returned matrix may not be modified. That is, you may not modify the contents of the row offset and column index arrays. You may modify the matrix values, provided that you call the function handleNewValues() afterwards.

Returns
A shallow copy of the sparse matrix encapsulated by this object.
void jive::algebra::SparseMatrix::SparseMatrix::handleNewValues ( )

Notifies this object that its sparse matrix values have been modified and that it should update its internal data structures, if necessary. An implementation of this function should emit the event newValuesEvent.

The implementation provided by the SparseMatrix class simply calls newValuesEvent.emit().

const Vector& jive::algebra::SparseMatrix::getValues ( ) const

Returns a reference to a Vector that contains the values of the sparse matrix encapsulated by this object. The contents of the vector may be modified, provided that the function handleNewValues() is called afterwards.

This function is equivalent with:

return this->getMatrix().getValues();
Returns
A reference to the values of this sparse matrix.
Structure jive::algebra::SparseMatrix::getStructure ( ) const

Returns the non-zero pattern of the sparse matrix encapsulated by this object. The contents of returned Structure object may not be modified.

This function simply executes

Returns
The structure of this sparse matrix.
static jem::Class* jive::algebra::SparseMatrix::getType ( )
static
virtual jem::Class* jive::algebra::SparseMatrix::getClass ( ) const
virtual

Returns a pointer to the Class instance representing the runtime class of this object. If T denotes the runtime class of this object, then this function is equivalent with T::getType(). The pointer is valid during the entire lifetime of the program.

Returns
A pointer to the Class instance representing the runtime class of this object.

Reimplemented from jive::algebra::AbstractMatrix.

virtual void jive::algebra::SparseMatrix::readFrom ( jem::io::ObjectInput in)
virtual

Implements jem::io::Serializable.

virtual void jive::algebra::SparseMatrix::writeTo ( jem::io::ObjectOutput out) const
virtual

Implements jem::io::Serializable.

virtual jem::Ref<jem::Object> jive::algebra::SparseMatrix::clone ( ) const
virtual

Implements jem::Clonable.

virtual void jive::algebra::SparseMatrix::matmul ( const Vector lhs,
const Vector rhs 
) const
virtual

Multiplies the vector rhs with this matrix and stores the result in the vector lhs. The sizes of the two vectors must be compatible with the shape of this matrix.

Parameters
lhs- the result vector.
rhs- the vector to be multiplied by this matrix.
Precondition
lhs.size() == shape()[0] &&
rhs.size() == shape()[1]

Implements jive::algebra::AbstractMatrix.

Member Data Documentation

jem::util::Event<Self&> jive::algebra::SparseMatrix::newStructureEvent

The newStructureEvent is emitted whenever the structure of this sparse matrix has been modified. The argument of the event is a reference to this SparseMatrix object.