48 template<
typename Treal,
typename Tmatrix>
50 template<
typename Treal,
typename Tmatrix>
51 class MatrixSymmetric;
52 template<
typename Treal,
typename Tmatrix>
53 class MatrixTriangular;
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()) {
182 Tmatrix::transpose(*mt.A.matrixPtr, *this->matrixPtr);
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");
Abstract class for simple writing and reading of objects to/from file.
Class used to keep track of the block sizes used at different levels in the hierarchical matrix data ...
Smart pointer class to control access to object.
Write and read objects to/from file.
Definition FileWritable.h:56
FileWritable & operator=(FileWritable const &)
Definition FileWritable.cc:478
Base class for matrix API.
Definition MatrixBase.h:69
MatrixBase< Treal, Tmatrix > & operator*=(Treal const alpha)
Definition MatrixBase.h:104
size_t memory_usage() const
Definition MatrixBase.h:126
int get_ncols() const
Definition MatrixBase.h:141
bool is_empty() const
Check if matrix is empty.
Definition MatrixBase.h:93
void getCols(SizesAndBlocks &colsCopy) const
Definition MatrixBase.h:85
bool operator==(int k) const
Definition MatrixBase.h:109
std::string obj_type_id() const
Definition MatrixBase.h:200
Tmatrix const & getMatrix() const
Definition MatrixBase.h:146
static void getPermutedIndexes(std::vector< int > const &index, std::vector< int > const &permutation, std::vector< int > &newIndex)
Definition MatrixBase.h:205
void read_from_buffer_base(void *buffer, const int n_bytes, const matrix_type mattype)
Definition MatrixBase.h:281
int get_nrows() const
Definition MatrixBase.h:138
MatrixBase(const MatrixBase< Treal, Tmatrix > &other)
Definition MatrixBase.h:156
void add_identity(Treal alpha)
Definition MatrixBase.h:101
void writeToFileBase(std::ofstream &file, matrix_type const mattype) const
Definition MatrixBase.h:221
Tmatrix & getMatrix()
Definition MatrixBase.h:147
Treal trace() const
Definition MatrixBase.h:97
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
MatrixBase< Treal, Tmatrix > & operator=(const MatrixBase< Treal, Tmatrix > &other)
Definition MatrixBase.h:166
void getRows(SizesAndBlocks &rowsCopy) const
Definition MatrixBase.h:82
Treal maxAbsValue() const
Get largest absolute value of matrix element in the matrix.
Definition MatrixBase.h:150
void resetSizesAndBlocks(SizesAndBlocks const &newRows, SizesAndBlocks const &newCols)
Definition MatrixBase.h:76
void clear()
Release memory for the information written to file.
Definition MatrixBase.h:118
MatrixBase< Treal, Tmatrix > & operator=(const Xtrans< MatrixGeneral< Treal, Tmatrix > > &mt)
Definition MatrixBase.h:177
void write_to_buffer_base(void *buffer, const int n_bytes, const matrix_type mattype) const
Definition MatrixBase.h:254
void write_to_buffer_count(int &n_bytes) const
Definition MatrixBase.h:130
ValidPtr< Tmatrix > matrixPtr
Definition MatrixBase.h:153
void readFromFileBase(std::ifstream &file, matrix_type const mattype)
Definition MatrixBase.h:236
MatrixBase()
Definition MatrixBase.h:155
Normal matrix.
Definition MatrixGeneral.h:59
Symmetric matrix.
Definition MatrixSymmetric.h:68
Upper non-unit triangular matrix.
Definition MatrixTriangular.h:59
Describes dimensions of matrix and its blocks on all levels.
Definition SizesAndBlocks.h:45
Smart pointer class to control access to object.
Definition ValidPtr.h:50
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
void haveDataStructureSet(bool val)
Definition ValidPtr.h:99
bool haveDataStructureGet() const
Definition ValidPtr.h:102
void inMemorySet(bool val)
Definition ValidPtr.h:93
bool inMemoryGet() const
Definition ValidPtr.h:96
Proxy structs used by the matrix API.
Definition allocate.cc:39
matrix_type
Definition MatrixBase.h:56
@ matrix_triang
Definition MatrixBase.h:56
@ matrix_matr
Definition MatrixBase.h:56
@ matrix_symm
Definition MatrixBase.h:56
normalMatrix MatrixGeneral
Definition random_matrices.h:74
This proxy expresses the result of transposition of an object of type TX.
Definition matrix_proxy.h:118