38 #ifndef MAT_MATRIXBASE 39 #define MAT_MATRIXBASE 48 template<
typename Treal,
typename Tmatrix>
50 template<
typename Treal,
typename Tmatrix>
52 template<
typename Treal,
typename Tmatrix>
54 template<
typename Treal,
typename Tvector>
68 template<
typename Treal,
typename Tmatrix>
113 throw Failure(
"MatrixBase::operator== only implemented for k == 0");
133 this->
matrixPtr->write_to_buffer_count(ib_length, vb_length);
134 n_bytes = vb_length *
sizeof(Treal) + ib_length *
sizeof(
int);
178 if (mt.A.matrixPtr.haveDataStructureGet()) {
184 *this->matrixPtr = *mt.A.matrixPtr;
206 std::vector<int>
const & permutation,
207 std::vector<int> & newIndex) {
208 newIndex.resize(index.size());
209 for (
unsigned int i = 0; i < index.size(); ++i)
210 newIndex[i] = permutation[index[i]];
219 template<
typename Treal,
typename Tmatrix>
223 int type = (int)mattype;
224 file.write((
char*)&type,
sizeof(
int));
231 matrixPtr->writeToFile(file);
234 template<
typename Treal,
typename Tmatrix>
238 char type[
sizeof(int)];
239 file.read(type,
sizeof(
int));
240 if (((
int)*type) != mattype)
241 throw Failure(
"MatrixBase<Treal, Tmatrix>::" 242 "readFromFile(std::ifstream &, " 243 "matrix_type const): Wrong matrix type");
247 matrixPtr->readFromFile(file);
252 template<
typename Treal,
typename Tmatrix>
259 this->matrixPtr->write_to_buffer_count(ib_length, vb_length);
261 (
int)(vb_length *
sizeof(Treal) + ib_length *
sizeof(
int))) {
262 int* int_buf = (
int*)buffer;
263 int_buf[0] = mattype;
264 int_buf[1] = ib_length;
265 int_buf[2] = vb_length;
266 Treal* value_buf = (Treal*)&(int_buf[ib_length]);
270 this->matrixPtr->write_to_buffer(&int_buf[3], ib_length - 3,
271 value_buf, vb_length,
275 throw Failure(
"MatrixBase::write_to_buffer: Buffer is too small");
279 template<
typename Treal,
typename Tmatrix>
283 int* int_buf = (
int*)buffer;
284 if(int_buf[0] == mattype) {
285 int ib_length = int_buf[1];
286 int vb_length = int_buf[2];
289 Treal* value_buf = (Treal*)&(int_buf[ib_length]);
290 this->matrixPtr->read_from_buffer(&int_buf[3], ib_length - 3,
291 value_buf, vb_length,
295 throw Failure(
"MatrixBase::read_from_buffer: Wrong matrix type");
Tmatrix const & getMatrix() const
Definition: MatrixBase.h:146
Normal matrix.
Definition: MatrixBase.h:49
MatrixBase< Treal, Tmatrix > & operator=(const MatrixBase< Treal, Tmatrix > &other)
Definition: MatrixBase.h:166
ValidPtr< Tmatrix > matrixPtr
Definition: MatrixBase.h:153
Proxy structs used by the matrix API.
void read_from_buffer_base(void *buffer, const int n_bytes, const matrix_type mattype)
Definition: MatrixBase.h:281
Treal maxAbsValue() const
Get largest absolute value of matrix element in the matrix.
Definition: MatrixBase.h:150
FileWritable & operator=(FileWritable const &)
Definition: FileWritable.cc:478
const Tobj & getConstRefForCopying() const
getConstRefForCopying() is provided to make it possible to copy the object also when it is written to...
Definition: ValidPtr.h:89
Class used to keep track of the block sizes used at different levels in the hierarchical matrix data ...
size_t memory_usage() const
Definition: MatrixBase.h:126
void getCols(SizesAndBlocks &colsCopy) const
Definition: MatrixBase.h:85
Definition: MatrixBase.h:55
void clear()
Release memory for the information written to file.
Definition: MatrixBase.h:118
Definition: allocate.cc:39
Describes dimensions of matrix and its blocks on all levels.
Definition: SizesAndBlocks.h:45
Tmatrix & getMatrix()
Definition: MatrixBase.h:147
MatrixBase(const MatrixBase< Treal, Tmatrix > &other)
Definition: MatrixBase.h:156
std::string obj_type_id() const
Definition: MatrixBase.h:200
Definition: MatrixBase.h:56
void readFromFileBase(std::ifstream &file, matrix_type const mattype)
Definition: MatrixBase.h:236
bool operator==(int k) const
Definition: MatrixBase.h:109
Smart pointer class to control access to object.
int get_ncols() const
Definition: MatrixBase.h:141
bool haveDataStructureGet() const
Definition: ValidPtr.h:102
void write_to_buffer_base(void *buffer, const int n_bytes, const matrix_type mattype) const
Definition: MatrixBase.h:254
Upper non-unit triangular matrix.
Definition: MatrixBase.h:53
This proxy expresses the result of transposition of an object of type TX.
Definition: matrix_proxy.h:118
void writeToFileBase(std::ofstream &file, matrix_type const mattype) const
Definition: MatrixBase.h:221
void add_identity(Treal alpha)
Definition: MatrixBase.h:101
MatrixBase< Treal, Tmatrix > & operator*=(Treal const alpha)
Definition: MatrixBase.h:104
void inMemorySet(bool inMem)
Make object invalid (false) via this function when object is written to file and valid (true) when ob...
Definition: MatrixBase.h:201
Treal trace() const
Definition: MatrixBase.h:97
void resetSizesAndBlocks(SizesAndBlocks const &newRows, SizesAndBlocks const &newCols)
Definition: MatrixBase.h:76
void write_to_buffer_count(int &n_bytes) const
Definition: MatrixBase.h:130
Write and read objects to/from file.
Definition: FileWritable.h:56
Base class for matrix API.
Definition: MatrixBase.h:69
bool is_empty() const
Check if matrix is empty.
Definition: MatrixBase.h:93
bool inMemoryGet() const
Definition: ValidPtr.h:96
void getRows(SizesAndBlocks &rowsCopy) const
Definition: MatrixBase.h:82
MatrixBase()
Definition: MatrixBase.h:155
void haveDataStructureSet(bool val)
Definition: ValidPtr.h:99
matrix_type
Definition: MatrixBase.h:56
Abstract class for simple writing and reading of objects to/from file.
Definition: MatrixBase.h:56
int get_nrows() const
Definition: MatrixBase.h:138
Xtrans< TX > transpose(TX const &A)
Transposition.
Definition: matrix_proxy.h:131
Symmetric matrix.
Definition: MatrixBase.h:51
Definition: MatrixBase.h:56
MatrixBase< Treal, Tmatrix > & operator=(const Xtrans< MatrixGeneral< Treal, Tmatrix > > &mt)
Definition: MatrixBase.h:177
void inMemorySet(bool val)
Definition: ValidPtr.h:93
static void getPermutedIndexes(std::vector< int > const &index, std::vector< int > const &permutation, std::vector< int > &newIndex)
Definition: MatrixBase.h:205