36 #ifndef MAT_MATRIXBASE
37 #define MAT_MATRIXBASE
46 template<
typename Treal,
typename Tmatrix>
48 template<
typename Treal,
typename Tmatrix>
50 template<
typename Treal,
typename Tmatrix>
52 template<
typename Treal,
typename Tvector>
66 template<
typename Treal,
typename Tmatrix>
111 throw Failure(
"MatrixBase::operator== only implemented for k == 0");
131 this->
matrixPtr->write_to_buffer_count(ib_length, vb_length);
132 n_bytes = vb_length *
sizeof(Treal) + ib_length *
sizeof(
int);
176 if (mt.A.matrixPtr.haveDataStructureGet()) {
204 std::vector<int>
const & permutation,
205 std::vector<int> & newIndex) {
206 newIndex.resize(index.size());
207 for (
unsigned int i = 0; i < index.size(); ++i)
208 newIndex[i] = permutation[index[i]];
217 template<
typename Treal,
typename Tmatrix>
221 int type = (int)mattype;
222 file.write((
char*)&type,
sizeof(
int));
229 matrixPtr->writeToFile(file);
232 template<
typename Treal,
typename Tmatrix>
236 char type[
sizeof(int)];
237 file.read(type,
sizeof(
int));
238 if (((
int)*type) != mattype)
239 throw Failure(
"MatrixBase<Treal, Tmatrix>::"
240 "readFromFile(std::ifstream &, "
241 "matrix_type const): Wrong matrix type");
245 matrixPtr->readFromFile(file);
250 template<
typename Treal,
typename Tmatrix>
257 this->matrixPtr->write_to_buffer_count(ib_length, vb_length);
259 (
int)(vb_length *
sizeof(Treal) + ib_length *
sizeof(
int))) {
260 int* int_buf = (
int*)buffer;
261 int_buf[0] = mattype;
262 int_buf[1] = ib_length;
263 int_buf[2] = vb_length;
264 Treal* value_buf = (Treal*)&(int_buf[ib_length]);
268 this->matrixPtr->write_to_buffer(&int_buf[3], ib_length - 3,
269 value_buf, vb_length,
273 throw Failure(
"MatrixBase::write_to_buffer: Buffer is too small");
277 template<
typename Treal,
typename Tmatrix>
281 int* int_buf = (
int*)buffer;
282 if(int_buf[0] == mattype) {
283 int ib_length = int_buf[1];
284 int vb_length = int_buf[2];
287 Treal* value_buf = (Treal*)&(int_buf[ib_length]);
288 this->matrixPtr->read_from_buffer(&int_buf[3], ib_length - 3,
289 value_buf, vb_length,
293 throw Failure(
"MatrixBase::read_from_buffer: Wrong matrix type");
Normal matrix.
Definition: MatrixBase.h:47
MatrixBase< Treal, Tmatrix > & operator=(const MatrixBase< Treal, Tmatrix > &other)
Definition: MatrixBase.h:164
Treal trace() const
Definition: MatrixBase.h:95
ValidPtr< Tmatrix > matrixPtr
Definition: MatrixBase.h:151
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:279
FileWritable & operator=(FileWritable const &)
Definition: FileWritable.cc:337
Definition: MatrixBase.h:53
void clear()
Release memory for the information written to file.
Definition: MatrixBase.h:116
Describes dimensions of matrix and its blocks on all levels.
Definition: SizesAndBlocks.h:37
Tmatrix & getMatrix()
Definition: MatrixBase.h:145
MatrixBase(const MatrixBase< Treal, Tmatrix > &other)
Definition: MatrixBase.h:154
Definition: MatrixBase.h:54
void readFromFileBase(std::ifstream &file, matrix_type const mattype)
Definition: MatrixBase.h:234
std::string obj_type_id() const
Definition: MatrixBase.h:198
void write_to_buffer_count(int &n_bytes) const
Definition: MatrixBase.h:128
void getCols(SizesAndBlocks &colsCopy) const
Definition: MatrixBase.h:83
Smart pointer class to control access to object.
int get_nrows() const
Definition: MatrixBase.h:136
Upper non-unit triangular matrix.
Definition: MatrixBase.h:51
This proxy expresses the result of transposition of an object of type TX.
Definition: matrix_proxy.h:116
int get_ncols() const
Definition: MatrixBase.h:139
void add_identity(Treal alpha)
Definition: MatrixBase.h:99
MatrixBase< Treal, Tmatrix > & operator*=(Treal const alpha)
Definition: MatrixBase.h:102
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:199
void resetSizesAndBlocks(SizesAndBlocks const &newRows, SizesAndBlocks const &newCols)
Definition: MatrixBase.h:74
const Tobj & getConstRefForCopying() const
getConstRefForCopying() is provided to make it possible to copy the object also when it is written to...
Definition: ValidPtr.h:87
Write and read objects to/from file.
Definition: FileWritable.h:54
Base class for matrix API.
Definition: MatrixBase.h:67
bool is_empty() const
Check if matrix is empty.
Definition: MatrixBase.h:91
Tmatrix const & getMatrix() const
Definition: MatrixBase.h:144
bool inMemoryGet() const
Definition: ValidPtr.h:94
MatrixBase()
Definition: MatrixBase.h:153
void writeToFileBase(std::ofstream &file, matrix_type const mattype) const
Definition: MatrixBase.h:219
size_t memory_usage() const
Definition: MatrixBase.h:124
void write_to_buffer_base(void *buffer, const int n_bytes, const matrix_type mattype) const
Definition: MatrixBase.h:252
void haveDataStructureSet(bool val)
Definition: ValidPtr.h:97
matrix_type
Definition: MatrixBase.h:54
Abstract class for simple writing and reading of objects to/from file.
bool haveDataStructureGet() const
Definition: ValidPtr.h:100
void getRows(SizesAndBlocks &rowsCopy) const
Definition: MatrixBase.h:80
bool operator==(int k) const
Definition: MatrixBase.h:107
Definition: MatrixBase.h:54
Xtrans< TX > transpose(TX const &A)
Transposition.
Definition: matrix_proxy.h:129
Symmetric matrix.
Definition: MatrixBase.h:49
Definition: MatrixBase.h:54
Treal maxAbsValue() const
Get largest absolute value of matrix element in the matrix.
Definition: MatrixBase.h:148
MatrixBase< Treal, Tmatrix > & operator=(const Xtrans< MatrixGeneral< Treal, Tmatrix > > &mt)
Definition: MatrixBase.h:175
void inMemorySet(bool val)
Definition: ValidPtr.h:91
static void getPermutedIndexes(std::vector< int > const &index, std::vector< int > const &permutation, std::vector< int > &newIndex)
Definition: MatrixBase.h:203