40#define G_CONSTRUCTOR "GMatrixSymmetric::GMatrixSymmetric(int&, int&)"
41#define G_MATRIX "GMatrixSymmetric::GMatrixSymmetric(GMatrix&)"
42#define G_SPARSEMATRIX "GMatrixSymmetric::GMatrixSymmetric(GSparseMatrix&)"
43#define G_OP_ADD "GMatrixSymmetric::operator+=(GMatrixSymmetric&)"
44#define G_OP_SUB "GMatrixSymmetric::operator-=(GMatrixSymmetric&)"
45#define G_OP_MUL_VEC "GMatrixSymmetric::operator*(GVector&)"
46#define G_OP_MAT_MUL "GMatrixSymmetric::operator*=(GMatrixSymmetric&)"
47#define G_AT "GMatrixSymmetric::at(int&, int&)"
48#define G_EXTRACT_ROW "GMatrixSymmetric::row(int&)"
49#define G_SET_ROW "GMatrixSymmetric::row(int&, GVector&)"
50#define G_EXTRACT_COLUMN "GMatrixSymmetric::column(int&)"
51#define G_SET_COLUMN "GMatrixSymmetric::column(int&, GVector&)"
52#define G_ADD_TO_ROW "GMatrixSymmetric::add_to_row(int&, GVector&)"
53#define G_ADD_TO_COLUMN "GMatrixSymmetric::add_to_column(int&, GVector&)"
54#define G_CHOL_DECOMP "GMatrixSymmetric::cholesky_decompose(int&)"
55#define G_CHOL_SOLVE "GMatrixSymmetric::cholesky_solver(GVector&, int&)"
56#define G_CHOL_INVERT "GMatrixSymmetric::cholesky_invert(int&)"
57#define G_COPY_MEMBERS "GMatrixSymmetric::copy_members(GMatrixSymmetric&)"
58#define G_ALLOC_MEMBERS "GMatrixSymmetric::alloc_members(int&, int&)"
97 #if defined(G_RANGE_CHECK)
100 "Please specify a non-negative number of rows.";
105 "negative. Please specify a non-negative number of "
142 for (
int col = 0; col <
m_cols; ++col) {
144 double value_ll = matrix(
row,col);
145 double value_ur = matrix(col,
row);
146 if (value_ll != value_ur) {
148 "matrix element at (row,column)=("+
152 "matrix element at (row,column)=("+
158 (*this)(
row, col) = matrix(
row, col);
187 for (
int col = 0; col <
m_cols; ++col) {
189 double value_ll = matrix(
row,col);
190 double value_ur = matrix(col,
row);
191 if (value_ll != value_ur) {
193 "matrix element at (row,column)=("+
197 "matrix element at (row,column)=("+
203 (*this)(
row, col) = matrix(
row, col);
261 if (
this != &matrix) {
331 const int& column)
const
362 "Please specify a vector of size "+
371 for (
int col = 0; col <
m_cols; ++col) {
372 sum += (*this)(
row,col) * vector[col];
396 double* ptr = matrix.
m_data;
397 for (
int i = 0; i < matrix.
m_elements; ++i, ++ptr) {
422 " differs from the expected number of "+
429 " differs from the expected number of "+
436 const double* src = matrix.
m_data;
483 " differs from the expected number of "+
490 " differs from the expected number of "+
497 const double* src = matrix.
m_data;
634 #if defined(G_RANGE_CHECK)
644 for (
int col = 0; col <
m_cols; ++col) {
645 result[col] = (*this)(
row,col);
664 #if defined(G_RANGE_CHECK)
689 #if defined(G_RANGE_CHECK)
726 #if defined(G_RANGE_CHECK)
738 "rows. Please specify a vector of size "+
769 #if defined(G_RANGE_CHECK)
781 "columns. Please specify a vector of size "+
807 #if defined(G_RANGE_CHECK)
820 "rows. Please specify a vector of size "+
901 double* dst = matrix.
m_data;
903 *dst++ = std::abs(*src++);
923 for (
int col = 0, i = 0; col <
m_cols; ++col) {
948 double off_diag = 0.0;
957 for (
int col =
row+1; col <
m_cols; ++col) {
963 double result = diag + 2.0 * off_diag;
984 for (
int col = 0; col <=
row; ++col) {
1008 for (
int col =
row; col <
m_cols; ++col) {
1048 int no_zeros = ((compress && (matrix.
m_num_inx == matrix.
m_rows)) || !compress);
1057 for (
int col =
row; col < matrix.
m_cols; ++col, ++ptr) {
1060 for (
int k = 0; k <
row; ++k) {
1066 std::string msg =
"Matrix is not positive definite, "
1068 " occured in row and column "+
1072 *ptr = std::sqrt(
sum);
1098 double* ptr = ptr_0 + *col_ptr;
1100 for (k = 0, k_ptr = matrix.
m_inx; k <
row; ++k, ++k_ptr) {
1101 int offset = matrix.
m_colstart[*k_ptr] - *k_ptr;
1103 matrix.
m_data[offset+*col_ptr];
1106 if (*row_ptr == *col_ptr) {
1108 std::string msg =
"Matrix is not positive definite, "
1110 " occured in row and column "+
1114 *ptr = std::sqrt(
sum);
1126 std::string msg =
"Matrix is not positive definite, all matrix "
1127 "elements are zero.";
1153 const bool& compress)
const
1159 "rows. Please specify a vector of size "+
1175 double sum = vector[
row];
1176 for (
int k = 0; k <
row; ++k) {
1187 sum -= *ptr++ * x[k];
1204 double sum = vector[*row_ptr];
1205 double* ptr =
m_data + *row_ptr;
1206 for (k = 0, k_ptr =
m_inx; k <
row; ++k, ++k_ptr) {
1214 double sum = x[*row_ptr];
1216 double* ptr = ptr_diag - *row_ptr;
1218 sum -= *(ptr + *k_ptr) * x[*k_ptr];
1220 x[*row_ptr] =
sum/(*ptr_diag);
1226 std::string msg =
"All matrix elements are zero.";
1256 int no_zeros = ((compress && (matrix.
m_num_inx == matrix.
m_rows)) || !compress);
1268 for (
int col =
row+1; col < matrix.
m_cols; ++col) {
1272 double* ptr1 = matrix.
m_data + col -
row;
1274 for (
int k =
row; k < col; ++k) {
1286 for (
int col =
row; col < matrix.
m_cols; ++col) {
1289 double* ptr1 = ptr + col -
row;
1291 for (
int k = col; k < matrix.
m_cols; ++k) {
1292 sum += *ptr1++ * *ptr2++;
1312 for (
row = 0, row_ptr = matrix.
m_inx;
1317 double* ptr_2 = ptr_diag - *row_ptr;
1318 *ptr_diag = 1.0/(*ptr_diag);
1321 col < matrix.
m_num_inx; ++col, ++col_ptr) {
1325 double* ptr_1 = matrix.
m_data + *col_ptr;
1327 k < col; ++k, ++k_ptr) {
1333 *(ptr_2 + *col_ptr) =
1339 for (
row = 0, row_ptr = matrix.
m_inx;
1342 double* ptr_1 = ptr_diag - *row_ptr;
1345 col < matrix.
m_num_inx; ++col, ++col_ptr) {
1350 for (k = col, k_ptr = matrix.
m_inx+col;
1352 sum += *(ptr_1 + *k_ptr) * *(ptr_2 + *k_ptr);
1356 *(ptr_1 + *col_ptr) =
sum;
1363 std::string msg =
"All matrix elements are zero.";
1384 result.append(
"=== GMatrixSymmetric ===");
1450 for (
int i = 0; i <
m_cols; ++i) {
1501 "specify a symmetric matrix.";
1514 m_data =
new double[elements];
1527 for (
int col = 1; col <=
m_cols; ++col) {
1563 for (col = 0; col <
row; ++col) {
1573 for (col =
row+1; col <
m_cols; ++col) {
1621 "the first matrix differs from number of "+
1623 "matrix. Please specify a second matrix with "+
1633 for (
int col = 0; col < matrix.
m_cols; ++col) {
1635 for (
int i = 0; i <
m_cols; ++i) {
1636 sum += (*this)(
row,i) * matrix(i,col);
Exception handler interface definition.
Sparse matrix class definition.
Symmetric matrix class definition.
Generic matrix class definition.
Vector class interface definition.
Abstract matrix base class interface definition.
const int & rows(void) const
Return number of matrix rows.
int m_num_rowsel
Number of selected rows (for compressed decomposition)
std::string print_col_compression(const GChatter &chatter=NORMAL) const
Print column compression scheme if it exists.
int m_cols
Number of columns.
int m_rows
Number of rows.
const int & columns(void) const
Return number of matrix columns.
virtual GMatrixBase & operator=(const GMatrixBase &matrix)
Assignment operator.
int * m_colsel
Column selection (for compressed decomposition)
double * m_data
Matrix data.
int m_num_colsel
Number of selected columns (for compressed decomposition)
std::string print_row_compression(const GChatter &chatter=NORMAL) const
Print row compression scheme if it exists.
std::string print_elements(const GChatter &chatter=NORMAL, const int &num=15) const
Print all matrix elements.
int m_alloc
Size of allocated matrix memory.
int * m_colstart
Column start indices (m_cols+1)
int * m_rowsel
Row selection (for compressed decomposition)
int m_elements
Number of elements stored in matrix.
Sparse matrix class interface definition.
Symmetric matrix class interface definition.
virtual void add_to_row(const int &row, const GVector &vector)
Add row to matrix elements.
void copy_members(const GMatrixSymmetric &matrix)
Copy class members.
GVector cholesky_solver(const GVector &vector, const bool &compress=true) const
Cholesky solver.
virtual GMatrixSymmetric operator-(void) const
Negate matrix elements.
virtual GMatrixSymmetric & operator-=(const GMatrixSymmetric &matrix)
Unary matrix subtraction operator.
GMatrix extract_lower_triangle(void) const
Extract lower triangle of matrix.
GMatrixSymmetric cholesky_decompose(const bool &compress=true) const
Return Cholesky decomposition.
virtual void clear(void)
Clear matrix.
GMatrixSymmetric cholesky_invert(const bool &compress=true) const
Invert matrix using a Cholesky decomposition.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print matrix.
virtual GVector operator*(const GVector &v) const
Vector multiplication.
GMatrixSymmetric(void)
Void constructor.
virtual void add_to_column(const int &column, const GVector &vector)
Add vector column into matrix.
GMatrixSymmetric invert(void) const
Return inverted matrix.
virtual double sum(void) const
Sum matrix elements.
virtual GVector row(const int &row) const
Extract row as vector from matrix.
GVector solve(const GVector &vector) const
Solves linear matrix equation.
virtual GVector column(const int &column) const
Extract column as vector from matrix.
void init_members(void)
Initialise class mambers.
virtual ~GMatrixSymmetric(void)
Destructor.
virtual double & at(const int &row, const int &column)
Return reference to matrix element.
virtual GMatrixSymmetric & operator=(const GMatrixSymmetric &matrix)
Matrix assignment operator.
virtual double fill(void) const
Determine fill of matrix.
virtual GMatrixSymmetric & operator+=(const GMatrixSymmetric &matrix)
Unary matrix addition operator.
void alloc_members(const int &rows, const int &columns)
Allocates matrix memory.
void free_members(void)
Delete class members.
int * m_inx
Index array of non-zero rows/columns.
GMatrix extract_upper_triangle(void) const
Extract upper triangle of matrix.
int m_num_inx
Number of indices in array.
GMatrixSymmetric abs(void) const
Return absolute of matrix.
void set_inx(void)
Set index selection.
virtual double & operator()(const int &row, const int &column)
Return reference to matrix element.
virtual GMatrixSymmetric * clone(void) const
Clone matrix.
Generic matrix class definition.
const int & size(void) const
Return size of vector.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.