34 #ifndef AIMS_SPARSEMATRIX_SPARSEORDENSEMATRIX_H
35 #define AIMS_SPARSEMATRIX_SPARSEORDENSEMATRIX_H
63 virtual bool hasRow( int32_t )
const {
return true; }
67 virtual bool hasColumn( int32_t )
const {
return true; }
68 virtual std::vector<double> *
readRow( int32_t ,
bool store =
true )
69 { (void)(store);
return new std::vector<double>; }
72 { (void)(store);
return new std::vector<double>; }
77 { _keep_inf = keep_inf; _keep_nan = keep_nan; }
108 void setRow( int32_t s1,
const std::vector<double>& row );
109 void setColumn( int32_t s2,
const std::vector<double>& column );
111 std::vector<double>
getRow( int32_t i )
const;
136 std::vector<double> *
getReadRow( int32_t i,
bool store =
true );
149 template <
typename VectorType>
151 template <
typename VectorType>
154 void read(
const std::string& filename );
155 void write(
const std::string& filename,
202 const std::vector<int32_t> & size );
204 const std::vector<std::vector<int32_t> > & indices_along_dims );
216 template <
typename VectorType>
228 for( x=0; buf != end; buf += inc, ++x )
235 template <
typename VectorType>
240 return sparseMatrix()->getSparseColumn<VectorType>( i );
247 for( x=0; buf != end; buf += inc, ++x )
266 const double& thing2 );
270 const double& thing2 );
275 #ifndef DOXYGEN_HIDE_INTERNAL_CLASSES
284 {
return "SparseOrDenseMatrix"; }
289 return std::string(
"SparseOrDenseMatrix_") +
dataType();
MatrixLazyReader allows to read a row or a column from file, on demand.
virtual void freeRow(int32_t)
virtual void selectDimension(const std::vector< int32_t > &)
virtual bool hasRow(int32_t) const
tells if row s1 has already been read.
void setInfFiltering(bool keep_inf, bool keep_nan)
virtual bool hasColumn(int32_t) const
tells if column s2 has already been read.
virtual std::vector< double > * readColumn(int32_t, bool store=true)
virtual void freeColumn(int32_t)
virtual ~MatrixLazyReader()
virtual std::vector< double > * readRow(int32_t, bool store=true)
void read(const std::string &filename)
SparseOrDenseMatrix & operator+=(const SparseOrDenseMatrix &thing)
bool hasElement(int32_t i, int32_t j) const
SparseMatrixType asSparse(bool copy=false) const
get a shallow or deep copy in sparse shape
void setLazyReader(MatrixLazyReader *reader)
double operator()(int32_t i, int32_t j) const
DenseMatrixType asDense(bool copy=false) const
get a shallow or deep copy in dense shape
void setColumn(int32_t s2, const std::vector< double > &column)
SparseOrDenseMatrix(int32_t size1=1, int32_t size2=1)
SparseOrDenseMatrix(const SparseOrDenseMatrix &other)
void erase_element(int32_t i, int32_t j)
SparseMatrixType _sparsematrix
std::vector< double > getColumn(int32_t j) const
virtual ~SparseOrDenseMatrix()
SparseOrDenseMatrix & operator/=(double x)
SparseOrDenseMatrix * subMatrix(const std::vector< int32_t > &start, const std::vector< int32_t > &size)
void write(const std::string &filename, carto::Object options=carto::none()) const
carto::rc_ptr< SparseMatrix > SparseMatrixType
void setMatrix(SparseMatrixType matrix)
void readAll()
read all rows using lazy reading, using the MatrixLazyReader.
SparseOrDenseMatrix & operator-=(const SparseOrDenseMatrix &thing)
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.
void set_element(int32_t i, int32_t j, double x)
SparseOrDenseMatrix * subMatrix(const std::vector< std::vector< int32_t > > &indices_along_dims)
void setRow(int32_t s1, const std::vector< double > &row)
VectorType getSparseRow(int32_t i) const
SparseOrDenseMatrix & operator=(const SparseOrDenseMatrix &other)
carto::Object _fakeheader
const DenseMatrixType denseMatrix() const
MatrixLazyReader * _lazyreader
void reallocate(int32_t size1, int32_t size2)
const carto::Object header() const
VectorType getSparseColumn(int32_t i) const
DenseMatrixType denseMatrix()
MatrixLazyReader * lazyReader() const
carto::VolumeRef< double > DenseMatrixType
bool isOptimalShape() const
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.
SparseMatrixType sparseMatrix()
void setHeader(carto::Object ph)
unsigned long optimalShapeThreshold() const
below this number of non-nul elements, the optimal shape is sparse
void readRow(int32_t i)
read a row using lazy reading, using the MatrixLazyReader.
std::vector< int32_t > getSize() const
SparseOrDenseMatrix & operator*=(double x)
DenseMatrixType _densematrix
std::vector< double > getRow(int32_t i) const
void muteToOptimalShape()
mute to sparse or dense according to the less memory consuming
void setMatrix(DenseMatrixType matrix)
void readColumn(int32_t i)
read a column using lazy reading, using the MatrixLazyReader.
const SparseMatrixType sparseMatrix() const
int32_t getNonZeroElementCount() const
void freeColumn(int32_t i)
static std::string dataType()
static std::string name()
static std::string objectType()
const T & at(long x, long y=0, long z=0, long t=0) const
The class for EcatSino data write operation.
aims::SparseMatrix operator+(const aims::SparseMatrix &thing)
aims::SparseMatrix operator/(const aims::SparseMatrix &thing1, const double &thing2)
Quaternion operator*(const Quaternion &a, const Quaternion &b)
aims::SparseMatrix operator-(const aims::SparseMatrix &thing)
#define DECLARE_GENERIC_OBJECT_TYPE(T)