1 | /*
|
---|
2 | * MatrixContent.hpp
|
---|
3 | *
|
---|
4 | * Created on: Jul 2, 2010
|
---|
5 | * Author: crueger
|
---|
6 | */
|
---|
7 |
|
---|
8 | #ifndef MATRIXCONTENT_HPP_
|
---|
9 | #define MATRIXCONTENT_HPP_
|
---|
10 |
|
---|
11 | /** MatrixContent is a wrapper for gsl_matrix.
|
---|
12 | *
|
---|
13 | * The GNU Scientific Library contaisn some very well written routines for
|
---|
14 | * linear algebra problems. However, it's syntax is C and hence it does not
|
---|
15 | * lend itself to readable written code, i.e. C = A * B, where A, B, and C
|
---|
16 | * are all matrices. Writing code this way is very convenient, concise and
|
---|
17 | * also in the same manner as one would type in MatLab.
|
---|
18 | * However, with C++ and its feature to overload functions and its operator
|
---|
19 | * functions such syntax is easy to create.
|
---|
20 | *
|
---|
21 | * Hence, this class is a C++ wrapper to gsl_matrix. There already some other
|
---|
22 | * libraries, however they fall short for the following reasons:
|
---|
23 | * -# gslwrap: not very well written and uses floats instead of doubles
|
---|
24 | * -# gslcpp: last change is from 2007 and only very few commits
|
---|
25 | * -# o2scl: basically, the same functionality as gsl only written in C++,
|
---|
26 | * however it uses GPLv3 license which is inconvenient for MoleCuilder.
|
---|
27 | *
|
---|
28 | * <h1>Howto use MatrixContent</h1>
|
---|
29 | *
|
---|
30 | * One should not use MatrixContent directly but either have it as a member
|
---|
31 | * variable in a specialized class or inherit from it.
|
---|
32 | *
|
---|
33 | */
|
---|
34 |
|
---|
35 | #include <gsl/gsl_matrix.h>
|
---|
36 |
|
---|
37 | class Vector;
|
---|
38 |
|
---|
39 | class MatrixContent
|
---|
40 | {
|
---|
41 | friend Vector operator*(const MatrixContent &mat,const Vector &vec);
|
---|
42 | friend class RealSpaceMatrix;
|
---|
43 | friend class LinearSystemOfEquations;
|
---|
44 |
|
---|
45 | friend class MatrixContentTest;
|
---|
46 | friend class MatrixContentSymmetricTest;
|
---|
47 | public:
|
---|
48 | MatrixContent(size_t rows, size_t columns);
|
---|
49 | MatrixContent(size_t rows, size_t columns, const double *src);
|
---|
50 | MatrixContent(gsl_matrix *&src);
|
---|
51 | MatrixContent(const MatrixContent &src);
|
---|
52 | MatrixContent(const MatrixContent *src);
|
---|
53 | ~MatrixContent();
|
---|
54 |
|
---|
55 | // Accessing
|
---|
56 | double &at(size_t i, size_t j);
|
---|
57 | const double at(size_t i, size_t j) const;
|
---|
58 | void set(size_t i, size_t j, const double value);
|
---|
59 | void setFromDoubleArray(double * x);
|
---|
60 |
|
---|
61 | // Exchanging elements
|
---|
62 | bool SwapRows(size_t i, size_t j);
|
---|
63 | bool SwapColumns(size_t i, size_t j);
|
---|
64 | bool SwapRowColumn(size_t i, size_t j);
|
---|
65 |
|
---|
66 | // Transformations
|
---|
67 | MatrixContent transpose() const;
|
---|
68 | MatrixContent &transpose();
|
---|
69 | gsl_vector* transformToEigenbasis();
|
---|
70 |
|
---|
71 | // Properties
|
---|
72 | bool IsNull() const;
|
---|
73 | bool IsPositive() const;
|
---|
74 | bool IsNegative() const;
|
---|
75 | bool IsNonNegative() const;
|
---|
76 | bool IsPositiveDefinite() const;
|
---|
77 | double Determinant() const;
|
---|
78 |
|
---|
79 | // Initializing
|
---|
80 | void setIdentity();
|
---|
81 | void setZero();
|
---|
82 | void setValue(double _value);
|
---|
83 |
|
---|
84 | // Operators
|
---|
85 | MatrixContent &operator=(const MatrixContent &src);
|
---|
86 | const MatrixContent &operator+=(const MatrixContent &rhs);
|
---|
87 | const MatrixContent &operator-=(const MatrixContent &rhs);
|
---|
88 | const MatrixContent &operator*=(const MatrixContent &rhs);
|
---|
89 | const MatrixContent operator*(const MatrixContent &rhs) const;
|
---|
90 | const MatrixContent &operator*=(const double factor);
|
---|
91 | bool operator==(const MatrixContent &rhs) const;
|
---|
92 |
|
---|
93 | protected:
|
---|
94 | double *Pointer(size_t m, size_t n);
|
---|
95 | const double *const_Pointer(size_t m, size_t n) const;
|
---|
96 |
|
---|
97 | private:
|
---|
98 | gsl_matrix * content;
|
---|
99 | const size_t rows; // store for internal purposes
|
---|
100 | const size_t columns; // store for internal purposes
|
---|
101 | };
|
---|
102 |
|
---|
103 | const MatrixContent operator*(const double factor,const MatrixContent& mat);
|
---|
104 | const MatrixContent operator*(const MatrixContent &mat,const double factor);
|
---|
105 | Vector operator*(const MatrixContent &mat,const Vector &vec);
|
---|
106 |
|
---|
107 | #endif /* MATRIXCONTENT_HPP_ */
|
---|