Interface to GSL matrix.
More...
#include <yat/utility/Matrix.h>
|
| Matrix (void) |
| The default constructor.
|
|
| Matrix (const size_t &r, const size_t &c, double init_value=0) |
| Constructor allocating memory space for r times c elements, and sets all elements to init_value.
|
|
| Matrix (const Matrix &) |
| The copy constructor.
|
|
| Matrix (std::istream &, char sep='\0') throw (utility::IO_error, std::exception) |
| The istream constructor.
|
|
| ~Matrix (void) |
| The destructor.
|
|
void | all (const double value) |
|
iterator | begin (void) |
|
const_iterator | begin (void) const |
|
iterator | begin_column (size_t i) |
|
const_iterator | begin_column (size_t i) const |
|
iterator | begin_row (size_t i) |
|
const_iterator | begin_row (size_t i) const |
|
VectorView | column_view (size_t i) |
|
const VectorConstView | column_const_view (size_t) const |
|
size_t | columns (void) const |
|
void | div (const Matrix &b) |
|
iterator | end (void) |
|
const_iterator | end (void) const |
|
iterator | end_column (size_t i) |
|
const_iterator | end_column (size_t i) const |
|
iterator | end_row (size_t i) |
|
const_iterator | end_row (size_t i) const |
|
bool | equal (const Matrix &, const double precision=0) const |
| Check whether matrices are equal within a user defined precision, set by precision.
|
|
const gsl_matrix * | gsl_matrix_p (void) const |
|
gsl_matrix * | gsl_matrix_p (void) |
|
void | mul (const Matrix &b) |
|
void | resize (size_t r, size_t c, double init_value=0) |
| Resize Matrix.
|
|
size_t | rows (void) const |
|
VectorView | row_view (size_t) |
|
const VectorConstView | row_const_view (size_t) const |
|
void | swap_columns (const size_t i, const size_t j) |
| Swap columns i and j.
|
|
void | swap_rowcol (const size_t i, const size_t j) |
| Swap row i and column j.
|
|
void | swap_rows (const size_t i, const size_t j) |
| Swap rows i and j.
|
|
void | transpose (void) |
| Transpose the matrix.
|
|
double & | operator() (size_t row, size_t column) |
| Element access operator.
|
|
const double & | operator() (size_t row, size_t column) const |
| Element access operator.
|
|
bool | operator== (const Matrix &other) const |
| Comparison operator. Takes squared time.
|
|
bool | operator!= (const Matrix &other) const |
| Comparison operator. Takes squared time.
|
|
const Matrix & | operator= (const Matrix &other) |
| The assignment operator.
|
|
const Matrix & | operator+= (const Matrix &b) |
| Add and assign operator.
|
|
const Matrix & | operator+= (const double d) |
| Add and assign operator.
|
|
const Matrix & | operator-= (const Matrix &) |
| Subtract and assign operator.
|
|
const Matrix & | operator-= (const double d) |
| Subtract and assign operator.
|
|
const Matrix & | operator*= (const Matrix &) |
| Multiply and assignment operator.
|
|
const Matrix & | operator*= (double d) |
| Multiply and assignment operator.
|
|
Interface to GSL matrix.
For the time being 'double' is the only type supported.
- [File streams] Reading and writing vectors to file streams
- are of course supported. These are implemented without using GSL functionality, and thus binary read and write to streams are not supported.
- Note
- All GSL matrix related functions are not implement but most functionality defined for GSL matrices can be achieved with this interface class. Most notable GSL functionality not supported are no binary file support and views on arrays, utility::vectors, gsl_vectors, diagonals, subdiagonals, and superdiagonals.
Mutable iterator that iterates over one column
Read-only iterator that iterates over one column
Read-only iterator that iterates over all elements
const_reference type is const double&
- Since
- New in yat 0.5
Read-only iterator that iterates over one row
Mutable iterator that iterates over all elements
reference type is double&
- Since
- New in yat 0.5
Mutable iterator that iterates over one row
value_type is double
- Since
- New in yat 0.5
theplu::yat::utility::Matrix::Matrix |
( |
void |
| ) |
|
The default constructor.
This constructor does not initialize underlying (essential) structures.
theplu::yat::utility::Matrix::Matrix |
( |
const size_t & |
r, |
|
|
const size_t & |
c, |
|
|
double |
init_value = 0 |
|
) |
| |
Constructor allocating memory space for r times c elements, and sets all elements to init_value.
If r is zero c must be zero and vice versa.
- Exceptions
-
theplu::yat::utility::Matrix::Matrix |
( |
const Matrix & |
| ) |
|
The copy constructor.
- Exceptions
-
A | GSL_error is indirectly thrown if memory allocation fails. |
theplu::yat::utility::Matrix::Matrix |
( |
std::istream & |
, |
|
|
char |
sep = '\0' |
|
) |
| throw (utility::IO_error, std::exception) |
|
explicit |
The istream constructor.
The std::istream will be interpreted as outlined here:
Missing values, i.e. empty elements, are treated as NaN values (std::numeric_limits<double>::quiet_NaN() to be specific).
Matrix rows are separated with the new line character.
Column element separation has two modes depending on the value of sep.
- If sep is the default '\0' value then column elements are separated with white space characters except the new line character. Multiple sequential white space characters are treated as one separator.
- Setting sep to something else than the default value will change the behaviour to use the sep character as the separator between column elements. Multiple sequential sep characters will be treated as separating elements with missing values.
End of input is the end of file marker and this treatment cannot be redefined using the provided API.
- Exceptions
-
GSL_error | if memory allocation fails, IO_error if unexpected input is found in the input stream. |
void theplu::yat::utility::Matrix::all |
( |
const double |
value | ) |
|
Set all elements to value.
iterator theplu::yat::utility::Matrix::begin |
( |
void |
| ) |
|
Iterator iterates along a row. When end of row is reached it jumps to beginning of next row.
- Returns
- iterator pointing to upper-left element.
Iterator iterates along a row. When end of row is reached it jumps to beginning of next row.
- Returns
- const_iterator pointing to upper-left element.
iterator theplu::yat::utility::Matrix::begin_column |
( |
size_t |
i | ) |
|
Iterator iterates along a column.
- Returns
- iterator pointing to first element of column i.
const_iterator theplu::yat::utility::Matrix::begin_column |
( |
size_t |
i | ) |
const |
Iterator iterates along a column.
- Returns
- const_iterator pointing to first element of column i.
iterator theplu::yat::utility::Matrix::begin_row |
( |
size_t |
i | ) |
|
Iterator iterates along a row.
- Returns
- iterator pointing to first element of row i.
const_iterator theplu::yat::utility::Matrix::begin_row |
( |
size_t |
i | ) |
const |
Iterator iterates along a row.
- Returns
- const_iterator pointing to first element of row i.
const VectorConstView theplu::yat::utility::Matrix::column_const_view |
( |
size_t |
| ) |
const |
- Returns
- const vector view of column i
VectorView theplu::yat::utility::Matrix::column_view |
( |
size_t |
i | ) |
|
- Returns
- Vector view of column i
size_t theplu::yat::utility::Matrix::columns |
( |
void |
| ) |
const |
- Returns
- The number of columns in the matrix.
void theplu::yat::utility::Matrix::div |
( |
const Matrix & |
b | ) |
|
Elementwise division of the elements of the calling matrix by the elements of matrix b, . The result is stored into the calling matrix.
- Exceptions
-
iterator theplu::yat::utility::Matrix::end |
( |
void |
| ) |
|
- Returns
- iterator pointing to end of matrix
- Returns
- const_iterator pointing to end of matrix
iterator theplu::yat::utility::Matrix::end_column |
( |
size_t |
i | ) |
|
- Returns
- iterator pointing to end of column i
const_iterator theplu::yat::utility::Matrix::end_column |
( |
size_t |
i | ) |
const |
- Returns
- const_iterator pointing to end of column i
iterator theplu::yat::utility::Matrix::end_row |
( |
size_t |
i | ) |
|
- Returns
- iterator pointing to end of row i
const_iterator theplu::yat::utility::Matrix::end_row |
( |
size_t |
i | ) |
const |
- Returns
- const_iterator pointing to end of row i
bool theplu::yat::utility::Matrix::equal |
( |
const Matrix & |
, |
|
|
const double |
precision = 0 |
|
) |
| const |
Check whether matrices are equal within a user defined precision, set by precision.
- Returns
- True if each element deviates less or equal than d. If any matrix contain a NaN, false is always returned.
- See Also
- operator== and operator!=
const gsl_matrix* theplu::yat::utility::Matrix::gsl_matrix_p |
( |
void |
| ) |
const |
- Returns
- A const pointer to the internal GSL matrix.
gsl_matrix* theplu::yat::utility::Matrix::gsl_matrix_p |
( |
void |
| ) |
|
- Returns
- A pointer to the internal GSL matrix.
void theplu::yat::utility::Matrix::mul |
( |
const Matrix & |
b | ) |
|
Multiply the elements of Matrix b with the elements of the calling Matrix , . The result is stored into the calling Matrix.
- Exceptions
-
bool theplu::yat::utility::Matrix::operator!= |
( |
const Matrix & |
other | ) |
const |
Comparison operator. Takes squared time.
Checks are performed with exact matching, i.e., rounding off effects may destroy comparison. Use the equal function for comparing elements within a user defined precision.
- Returns
- False if all elements are equal otherwise true.
- See Also
- equal
double& theplu::yat::utility::Matrix::operator() |
( |
size_t |
row, |
|
|
size_t |
column |
|
) |
| |
Element access operator.
- Returns
- Reference to the element position (row, column).
- Exceptions
-
If | GSL range checks are enabled in the underlying GSL library a GSL_error exception is thrown if either index is out of range. |
const double& theplu::yat::utility::Matrix::operator() |
( |
size_t |
row, |
|
|
size_t |
column |
|
) |
| const |
Element access operator.
- Returns
- Const reference to the element position (row, column).
- Exceptions
-
If | GSL range checks are enabled in the underlying GSL library a GSL_error exception is thrown if either index is out of range. |
const Matrix& theplu::yat::utility::Matrix::operator*= |
( |
const Matrix & |
| ) |
|
Multiply and assignment operator.
- Returns
- Const reference to the resulting Matrix.
- Note
- invalidates views and iterators
- Exceptions
-
const Matrix& theplu::yat::utility::Matrix::operator*= |
( |
double |
d | ) |
|
Multiply and assignment operator.
Multiply the elements of the left hand side Matrix with a scalar d, .
- Exceptions
-
const Matrix& theplu::yat::utility::Matrix::operator+= |
( |
const Matrix & |
b | ) |
|
Add and assign operator.
Elementwise addition of the elements of Matrix b to the left hand side Matrix , .
- Returns
- A const reference to the resulting Matrix.
- Exceptions
-
const Matrix& theplu::yat::utility::Matrix::operator+= |
( |
const double |
d | ) |
|
Add and assign operator.
Add the scalar value d to the left hand side Matrix, .
const Matrix& theplu::yat::utility::Matrix::operator-= |
( |
const Matrix & |
| ) |
|
Subtract and assign operator.
Elementwise subtraction of the elements of Matrix b to the left hand side Matrix , .
- Returns
- A const reference to the resulting Matrix.
- Exceptions
-
const Matrix& theplu::yat::utility::Matrix::operator-= |
( |
const double |
d | ) |
|
Subtract and assign operator.
Subtract the scalar value d to the left hand side Matrix, .
const Matrix& theplu::yat::utility::Matrix::operator= |
( |
const Matrix & |
other | ) |
|
The assignment operator.
- Note
- If lhs needs to be resized, views and iterators are invalidated.
- Returns
- A const reference to the resulting Matrix.
bool theplu::yat::utility::Matrix::operator== |
( |
const Matrix & |
other | ) |
const |
Comparison operator. Takes squared time.
Checks are performed with exact matching, i.e., rounding off effects may destroy comparison. Use the equal function for comparing elements within a user defined precision.
- Returns
- True if all elements are equal otherwise false.
- See Also
- equal
void theplu::yat::utility::Matrix::resize |
( |
size_t |
r, |
|
|
size_t |
c, |
|
|
double |
init_value = 0 |
|
) |
| |
Resize Matrix.
All elements are set to init_value.
If r is zero c must be zero and vice versa.
- Note
- underlying GSL matrix is destroyed and views and iterators are invalidated
const VectorConstView theplu::yat::utility::Matrix::row_const_view |
( |
size_t |
| ) |
const |
- Returns
- const vector view of i
VectorView theplu::yat::utility::Matrix::row_view |
( |
size_t |
| ) |
|
size_t theplu::yat::utility::Matrix::rows |
( |
void |
| ) |
const |
- Returns
- The number of rows in the matrix.
void theplu::yat::utility::Matrix::swap_columns |
( |
const size_t |
i, |
|
|
const size_t |
j |
|
) |
| |
Swap columns i and j.
- Exceptions
-
void theplu::yat::utility::Matrix::swap_rowcol |
( |
const size_t |
i, |
|
|
const size_t |
j |
|
) |
| |
Swap row i and column j.
The Matrix must be square.
- Exceptions
-
GSL_error | if either index is out of bounds, or if matrix is not square. |
void theplu::yat::utility::Matrix::swap_rows |
( |
const size_t |
i, |
|
|
const size_t |
j |
|
) |
| |
Swap rows i and j.
- Exceptions
-
void theplu::yat::utility::Matrix::transpose |
( |
void |
| ) |
|
Transpose the matrix.
- Note
- Unless matrix is square, views and iterators are invalidated.
- Exceptions
-
GSL_error | if memory allocation fails for the new transposed matrix. |
bool isnull |
( |
const Matrix & |
| ) |
|
|
related |
Check if all elements of the Matrix are zero.
- Returns
- True if all elements in the Matrix is zero, false otherwise.
Get the maximum value of the Matrix.
- Returns
- The maximum value of the Matrix.
Get the minimum value of the Matrix.
- Returns
- The minimum value of the Matrix.
void minmax_index |
( |
const Matrix & |
, |
|
|
std::pair< size_t, size_t > & |
min, |
|
|
std::pair< size_t, size_t > & |
max |
|
) |
| |
|
related |
Locate the maximum and minimum element in the Matrix.
- Returns
- The indices to the element with the minimum and maximum values of the Matrix, respectively.
- Note
- Lower index has precedence (searching in row-major order).
Create a Matrix flag indicating NaN's in another Matrix templat.
The flag Matrix is changed to contain 1's and 0's only. A 1 means that the corresponding element in the templat Matrix is valid and a zero means that the corresponding element is a NaN.
- Note
- Space for Matrix flag is reallocated to fit the size of Matrix templat if sizes mismatch.
- Returns
- True if the templat Matrix contains at least one NaN.
Exchange all elements between the matrices by copying.
The two matrices must have the same size.
- Exceptions
-
double trace |
( |
const Matrix & |
| ) |
|
|
related |
Trace of matrix.
- Returns
- sum of diagonal elements
- Since
- New in yat 0.9
The documentation for this class was generated from the following file: