aimsdata 6.0.0
Neuroimaging data handling
aims::SparseOrDenseMatrix Class Reference

#include <aims/sparsematrix/sparseordensematrix.h>

Inheritance diagram for aims::SparseOrDenseMatrix:
Collaboration diagram for aims::SparseOrDenseMatrix:

Classes

class  MatrixLazyReader
 MatrixLazyReader allows to read a row or a column from file, on demand. More...
 

Public Types

typedef carto::VolumeRef< double > DenseMatrixType
 
typedef carto::rc_ptr< SparseMatrixSparseMatrixType
 
- Public Types inherited from carto::RCObject
typedef int RefCounterType
 

Public Member Functions

 SparseOrDenseMatrix (int32_t size1=1, int32_t size2=1)
 
 SparseOrDenseMatrix (const SparseOrDenseMatrix &other)
 
virtual ~SparseOrDenseMatrix ()
 
SparseOrDenseMatrixoperator= (const SparseOrDenseMatrix &other)
 
void reallocate (int32_t size1, int32_t size2)
 
int32_t getSize1 () const
 
int32_t getSize2 () const
 
int32_t getNonZeroElementCount () const
 
std::vector< int32_t > getSize () const
 
bool hasElement (int32_t i, int32_t j) const
 
double operator() (int32_t i, int32_t j) const
 
void erase_element (int32_t i, int32_t j)
 
void set_element (int32_t i, int32_t j, double x)
 
void setRow (int32_t s1, const std::vector< double > &row)
 
void setColumn (int32_t s2, const std::vector< double > &column)
 
std::vector< double > getRow (int32_t i) const
 
std::vector< double > getColumn (int32_t j) const
 
void readRow (int32_t i)
 read a row using lazy reading, using the MatrixLazyReader.
 
void readColumn (int32_t i)
 read a column using lazy reading, using the MatrixLazyReader.
 
std::vector< double > * getReadRow (int32_t i, bool store=true)
 Get row, read it if it is not in memory, and optionally store it for later access.
 
std::vector< double > * getReadColumn (int32_t i, bool store=true)
 Get column, read it if it is not in memory, and optionally store it for later access.
 
void readAll ()
 read all rows using lazy reading, using the MatrixLazyReader.
 
void freeRow (int32_t i)
 
void freeColumn (int32_t i)
 
template<typename VectorType>
VectorType getSparseRow (int32_t i) const
 
template<typename VectorType>
VectorType getSparseColumn (int32_t i) const
 
void read (const std::string &filename)
 
void write (const std::string &filename, carto::Object options=carto::none()) const
 
bool isDense () const
 
SparseMatrixType sparseMatrix ()
 
const SparseMatrixType sparseMatrix () const
 
DenseMatrixType denseMatrix ()
 
const DenseMatrixType denseMatrix () const
 
void setMatrix (SparseMatrixType matrix)
 
void setMatrix (DenseMatrixType matrix)
 
carto::Object header ()
 
const carto::Object header () const
 
void setHeader (carto::Object ph)
 
SparseMatrixType asSparse (bool copy=false) const
 get a shallow or deep copy in sparse shape
 
DenseMatrixType asDense (bool copy=false) const
 get a shallow or deep copy in dense shape
 
void muteToDense ()
 
void muteToSparse ()
 
void muteToOptimalShape ()
 mute to sparse or dense according to the less memory consuming
 
bool isOptimalShape () const
 
unsigned long optimalShapeThreshold () const
 below this number of non-nul elements, the optimal shape is sparse
 
SparseOrDenseMatrixoperator+= (const SparseOrDenseMatrix &thing)
 
SparseOrDenseMatrixoperator-= (const SparseOrDenseMatrix &thing)
 
SparseOrDenseMatrixoperator*= (double x)
 
SparseOrDenseMatrixoperator/= (double x)
 
void setLazyReader (MatrixLazyReader *reader)
 
MatrixLazyReaderlazyReader () const
 
SparseOrDenseMatrixsubMatrix (const std::vector< int32_t > &start, const std::vector< int32_t > &size)
 
SparseOrDenseMatrixsubMatrix (const std::vector< std::vector< int32_t > > &indices_along_dims)
 
- Public Member Functions inherited from carto::RCObject
 RCObject ()
 
 RCObject (const RCObject &)
 
RCObjectoperator= (const RCObject &)
 
virtual ~RCObject ()
 

Protected Attributes

SparseMatrixType _sparsematrix
 
DenseMatrixType _densematrix
 
carto::Object _fakeheader
 
MatrixLazyReader_lazyreader
 

Detailed Description

Definition at line 45 of file sparseordensematrix.h.

Member Typedef Documentation

◆ DenseMatrixType

◆ SparseMatrixType

Constructor & Destructor Documentation

◆ SparseOrDenseMatrix() [1/2]

aims::SparseOrDenseMatrix::SparseOrDenseMatrix ( int32_t size1 = 1,
int32_t size2 = 1 )

◆ SparseOrDenseMatrix() [2/2]

aims::SparseOrDenseMatrix::SparseOrDenseMatrix ( const SparseOrDenseMatrix & other)

References SparseOrDenseMatrix().

◆ ~SparseOrDenseMatrix()

virtual aims::SparseOrDenseMatrix::~SparseOrDenseMatrix ( )
virtual

Member Function Documentation

◆ asDense()

DenseMatrixType aims::SparseOrDenseMatrix::asDense ( bool copy = false) const

get a shallow or deep copy in dense shape

◆ asSparse()

SparseMatrixType aims::SparseOrDenseMatrix::asSparse ( bool copy = false) const

get a shallow or deep copy in sparse shape

◆ denseMatrix() [1/2]

DenseMatrixType aims::SparseOrDenseMatrix::denseMatrix ( )
inline

Definition at line 162 of file sparseordensematrix.h.

References _densematrix.

Referenced by getSparseColumn(), and getSparseRow().

◆ denseMatrix() [2/2]

const DenseMatrixType aims::SparseOrDenseMatrix::denseMatrix ( ) const
inline

Definition at line 163 of file sparseordensematrix.h.

References _densematrix.

◆ erase_element()

void aims::SparseOrDenseMatrix::erase_element ( int32_t i,
int32_t j )

◆ freeColumn()

void aims::SparseOrDenseMatrix::freeColumn ( int32_t i)

◆ freeRow()

void aims::SparseOrDenseMatrix::freeRow ( int32_t i)

◆ getColumn()

std::vector< double > aims::SparseOrDenseMatrix::getColumn ( int32_t j) const

◆ getNonZeroElementCount()

int32_t aims::SparseOrDenseMatrix::getNonZeroElementCount ( ) const

◆ getReadColumn()

std::vector< double > * aims::SparseOrDenseMatrix::getReadColumn ( int32_t i,
bool store = true )

Get column, read it if it is not in memory, and optionally store it for later access.

The returned vector has to be freed after use.

◆ getReadRow()

std::vector< double > * aims::SparseOrDenseMatrix::getReadRow ( int32_t i,
bool store = true )

Get row, read it if it is not in memory, and optionally store it for later access.

The returned vector has to be freed after use.

◆ getRow()

std::vector< double > aims::SparseOrDenseMatrix::getRow ( int32_t i) const

◆ getSize()

std::vector< int32_t > aims::SparseOrDenseMatrix::getSize ( ) const

◆ getSize1()

int32_t aims::SparseOrDenseMatrix::getSize1 ( ) const

◆ getSize2()

int32_t aims::SparseOrDenseMatrix::getSize2 ( ) const

◆ getSparseColumn()

template<typename VectorType>
VectorType aims::SparseOrDenseMatrix::getSparseColumn ( int32_t i) const
inline

◆ getSparseRow()

template<typename VectorType>
VectorType aims::SparseOrDenseMatrix::getSparseRow ( int32_t i) const
inline

◆ hasElement()

bool aims::SparseOrDenseMatrix::hasElement ( int32_t i,
int32_t j ) const

◆ header() [1/2]

carto::Object aims::SparseOrDenseMatrix::header ( )

◆ header() [2/2]

const carto::Object aims::SparseOrDenseMatrix::header ( ) const

◆ isDense()

bool aims::SparseOrDenseMatrix::isDense ( ) const
inline

Definition at line 158 of file sparseordensematrix.h.

References _densematrix.

Referenced by getSparseColumn(), and getSparseRow().

◆ isOptimalShape()

bool aims::SparseOrDenseMatrix::isOptimalShape ( ) const

◆ lazyReader()

MatrixLazyReader * aims::SparseOrDenseMatrix::lazyReader ( ) const
inline

Definition at line 198 of file sparseordensematrix.h.

References _lazyreader.

◆ muteToDense()

void aims::SparseOrDenseMatrix::muteToDense ( )

◆ muteToOptimalShape()

void aims::SparseOrDenseMatrix::muteToOptimalShape ( )

mute to sparse or dense according to the less memory consuming

◆ muteToSparse()

void aims::SparseOrDenseMatrix::muteToSparse ( )

◆ operator()()

double aims::SparseOrDenseMatrix::operator() ( int32_t i,
int32_t j ) const

◆ operator*=()

SparseOrDenseMatrix & aims::SparseOrDenseMatrix::operator*= ( double x)

References SparseOrDenseMatrix().

◆ operator+=()

SparseOrDenseMatrix & aims::SparseOrDenseMatrix::operator+= ( const SparseOrDenseMatrix & thing)

References SparseOrDenseMatrix().

◆ operator-=()

SparseOrDenseMatrix & aims::SparseOrDenseMatrix::operator-= ( const SparseOrDenseMatrix & thing)

References SparseOrDenseMatrix().

◆ operator/=()

SparseOrDenseMatrix & aims::SparseOrDenseMatrix::operator/= ( double x)

◆ operator=()

SparseOrDenseMatrix & aims::SparseOrDenseMatrix::operator= ( const SparseOrDenseMatrix & other)

References SparseOrDenseMatrix().

◆ optimalShapeThreshold()

unsigned long aims::SparseOrDenseMatrix::optimalShapeThreshold ( ) const

below this number of non-nul elements, the optimal shape is sparse

References SparseOrDenseMatrix().

◆ read()

void aims::SparseOrDenseMatrix::read ( const std::string & filename)

◆ readAll()

void aims::SparseOrDenseMatrix::readAll ( )

read all rows using lazy reading, using the MatrixLazyReader.

The default implementation does just nothing.

◆ readColumn()

void aims::SparseOrDenseMatrix::readColumn ( int32_t i)

read a column using lazy reading, using the MatrixLazyReader.

The default implementation does just nothing.

If "vector" is not Null, the read vector is "returned" in vector. In such a case, the vector has to be freed after use. If store is false and vector is not null, the vector is read (potentially from disk) but not kept in the matrix.

◆ readRow()

void aims::SparseOrDenseMatrix::readRow ( int32_t i)

read a row using lazy reading, using the MatrixLazyReader.

The default implementation does just nothing.

If "vector" is not Null, the read vector is "returned" in vector. In such a case, the vector has to be freed after use. If store is false and vector is not null, the vector is read (potentially from disk) but not kept in the matrix.

◆ reallocate()

void aims::SparseOrDenseMatrix::reallocate ( int32_t size1,
int32_t size2 )

◆ set_element()

void aims::SparseOrDenseMatrix::set_element ( int32_t i,
int32_t j,
double x )

◆ setColumn()

void aims::SparseOrDenseMatrix::setColumn ( int32_t s2,
const std::vector< double > & column )

◆ setHeader()

void aims::SparseOrDenseMatrix::setHeader ( carto::Object ph)

◆ setLazyReader()

void aims::SparseOrDenseMatrix::setLazyReader ( MatrixLazyReader * reader)
inline

Definition at line 193 of file sparseordensematrix.h.

References _lazyreader.

◆ setMatrix() [1/2]

void aims::SparseOrDenseMatrix::setMatrix ( DenseMatrixType matrix)

◆ setMatrix() [2/2]

void aims::SparseOrDenseMatrix::setMatrix ( SparseMatrixType matrix)

◆ setRow()

void aims::SparseOrDenseMatrix::setRow ( int32_t s1,
const std::vector< double > & row )

◆ sparseMatrix() [1/2]

SparseMatrixType aims::SparseOrDenseMatrix::sparseMatrix ( )
inline

Definition at line 160 of file sparseordensematrix.h.

References _sparsematrix.

Referenced by getSparseColumn(), and getSparseRow().

◆ sparseMatrix() [2/2]

const SparseMatrixType aims::SparseOrDenseMatrix::sparseMatrix ( ) const
inline

Definition at line 161 of file sparseordensematrix.h.

References _sparsematrix.

◆ subMatrix() [1/2]

SparseOrDenseMatrix * aims::SparseOrDenseMatrix::subMatrix ( const std::vector< int32_t > & start,
const std::vector< int32_t > & size )

References SparseOrDenseMatrix().

◆ subMatrix() [2/2]

SparseOrDenseMatrix * aims::SparseOrDenseMatrix::subMatrix ( const std::vector< std::vector< int32_t > > & indices_along_dims)

References SparseOrDenseMatrix().

◆ write()

void aims::SparseOrDenseMatrix::write ( const std::string & filename,
carto::Object options = carto::none() ) const

References carto::none().

Member Data Documentation

◆ _densematrix

DenseMatrixType aims::SparseOrDenseMatrix::_densematrix
protected

Definition at line 209 of file sparseordensematrix.h.

Referenced by denseMatrix(), denseMatrix(), and isDense().

◆ _fakeheader

carto::Object aims::SparseOrDenseMatrix::_fakeheader
protected

Definition at line 210 of file sparseordensematrix.h.

◆ _lazyreader

MatrixLazyReader* aims::SparseOrDenseMatrix::_lazyreader
protected

Definition at line 211 of file sparseordensematrix.h.

Referenced by lazyReader(), and setLazyReader().

◆ _sparsematrix

SparseMatrixType aims::SparseOrDenseMatrix::_sparsematrix
protected

Definition at line 208 of file sparseordensematrix.h.

Referenced by sparseMatrix(), and sparseMatrix().


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