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; }
95 void reallocate( int32_t size1, int32_t size2 );
100 std::vector<int32_t>
getSize()
const;
102 bool hasElement( int32_t i, int32_t j )
const;
104 double operator()( int32_t i, int32_t j )
const;
106 void set_element( int32_t i, int32_t j,
double x );
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;
112 std::vector<double>
getColumn( int32_t j )
const;
136 std::vector<double> *
getReadRow( int32_t i,
bool store =
true );
141 std::vector<double> *
getReadColumn( 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,
165 void setMatrix( SparseMatrixType matrix );
166 void setMatrix( DenseMatrixType matrix );
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();
297 #endif // DOXYGEN_HIDE_INTERNAL_CLASSES #define DECLARE_GENERIC_OBJECT_TYPE(T)
const DenseMatrixType denseMatrix() const
void write(const std::string &filename, carto::Object options=carto::none()) const
static std::string dataType()
void reallocate(int32_t size1, int32_t size2)
std::vector< int32_t > getSize() const
void setColumn(int32_t s2, const std::vector< double > &column)
static std::string objectType()
void muteToOptimalShape()
mute to sparse or dense according to the less memory consuming
bool isOptimalShape() const
void readAll()
read all rows using lazy reading, using the MatrixLazyReader.
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.
std::vector< double > getRow(int32_t i) const
virtual std::vector< double > * readRow(int32_t, bool store=true)
void erase_element(int32_t i, int32_t j)
SparseOrDenseMatrix & operator*=(double x)
The class for EcatSino data write operation.
SparseMatrixType _sparsematrix
SparseOrDenseMatrix & operator/=(double x)
VectorType getSparseColumn(int32_t i) const
static std::string name()
void setInfFiltering(bool keep_inf, bool keep_nan)
DenseMatrixType asDense(bool copy=false) const
get a shallow or deep copy in dense shape
SparseOrDenseMatrix & operator+=(const SparseOrDenseMatrix &thing)
virtual bool hasRow(int32_t) const
tells if row s1 has already been read.
const T & at(long x, long y=0, long z=0, long t=0) const
void setRow(int32_t s1, const std::vector< double > &row)
DenseMatrixType denseMatrix()
VectorType getSparseRow(int32_t i) const
DenseMatrixType _densematrix
virtual bool hasColumn(int32_t) const
tells if column s2 has already been read.
double operator()(int32_t i, int32_t j) const
SparseOrDenseMatrix & operator-=(const SparseOrDenseMatrix &thing)
MatrixLazyReader * _lazyreader
Volume< T > copy(const Volume< T > &src)
void set_element(int32_t i, int32_t j, double x)
void setHeader(carto::Object ph)
virtual ~MatrixLazyReader()
SparseMatrixType asSparse(bool copy=false) const
get a shallow or deep copy in sparse shape
virtual void freeRow(int32_t)
aims::SparseMatrix operator/(const aims::SparseMatrix &thing1, const double &thing2)
const SparseMatrixType sparseMatrix() const
carto::VolumeRef< double > DenseMatrixType
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.
unsigned long optimalShapeThreshold() const
below this number of non-nul elements, the optimal shape is sparse
int32_t getNonZeroElementCount() const
aims::SparseMatrix operator+(const aims::SparseMatrix &thing)
aims::SparseMatrix operator-(const aims::SparseMatrix &thing)
SparseOrDenseMatrix(int32_t size1=1, int32_t size2=1)
virtual std::vector< double > * readColumn(int32_t, bool store=true)
MatrixLazyReader * lazyReader() const
void read(const std::string &filename)
void setLazyReader(MatrixLazyReader *reader)
Object none()
Pointer to an empty aims::StructuringElement.
bool hasElement(int32_t i, int32_t j) const
MatrixLazyReader allows to read a row or a column from file, on demand.
virtual void selectDimension(const std::vector< int32_t > &)
std::vector< double > getColumn(int32_t j) const
carto::Object _fakeheader
virtual void freeColumn(int32_t)
SparseOrDenseMatrix * subMatrix(const std::vector< int32_t > &start, const std::vector< int32_t > &size)
Quaternion operator*(const Quaternion &a, const Quaternion &b)
SparseOrDenseMatrix & operator=(const SparseOrDenseMatrix &other)
carto::rc_ptr< SparseMatrix > SparseMatrixType
virtual ~SparseOrDenseMatrix()
SparseMatrixType sparseMatrix()
void setMatrix(SparseMatrixType matrix)