#include <Matrix.hpp>
|
| | Matrix () |
| |
| | Matrix (std::size_t num_rows, std::size_t num_cols, double the_value) |
| |
| | Matrix (std::size_t num_rows, std::size_t num_cols, const std::vector< double > &the_values) |
| |
| void | Assign (std::size_t num_rows, std::size_t num_cols, double the_value) |
| |
| void | Assign (std::size_t num_rows, std::size_t num_cols, const std::vector< double > &matrix_values) |
| |
| double | GetValue (std::size_t row, std::size_t col) const noexcept |
| |
| void | SetValue (std::size_t row, std::size_t col, double the_value) |
| |
| std::size_t | GetNumberOfColumns () const noexcept |
| |
| std::size_t | GetNumberOfRows () const noexcept |
| |
| std::size_t | Size () const noexcept |
| |
| bool | Empty () const noexcept |
| |
| void | AddConstantToDiagonal (double value, std::size_t offset=0, bool upper_triangle=true) |
| |
A class to store and operate on a 2D matrix. The matrix does not have to be square. The data is stored in a 1D vector row-wise.
◆ Matrix() [1/3]
| Unfit::Matrix::Matrix |
( |
| ) |
|
Constructor: (default) Override the default constructor to set the number of rows and columns to zero explicitly so we can't access any entries by accident.
◆ Matrix() [2/3]
| Unfit::Matrix::Matrix |
( |
std::size_t |
num_rows, |
|
|
std::size_t |
num_cols, |
|
|
double |
the_value |
|
) |
| |
Constructor: Creates a matrix with the specified dimensions (num_rows x num_cols) and initialises each of the entries to a constant value. This constant must be the same value type as is specified in the matrix template.
- Parameters
-
| num_rows | the number of rows in the resulting matrix |
| num_cols | the number of columns in the resulting matrix |
| the_value | a constant value to be assigned to all matrix entries |
◆ Matrix() [3/3]
| Unfit::Matrix::Matrix |
( |
std::size_t |
num_rows, |
|
|
std::size_t |
num_cols, |
|
|
const std::vector< double > & |
the_values |
|
) |
| |
Constructor: Creates a matrix with the specified dimensions (number_of_rows x number_of_columns) from a std::vector. Note that this does a copy construction such that the vector of values that was passed in remains unchanged. This is not as fast as a move construction via std::move, especially for large objects, but I suspect that this is the behaviour most users would expect. The vector of values must have the same value type as is specified in the matrix template.
- Parameters
-
| num_rows | the number of rows in the resulting matrix |
| num_cols | the number of columns in the resulting matrix |
| the_values | a constant value to be assigned to all matrix entries |
◆ AddConstantToDiagonal()
| void Unfit::Matrix::AddConstantToDiagonal |
( |
double |
value, |
|
|
std::size_t |
offset = 0, |
|
|
bool |
upper_triangle = true |
|
) |
| |
Add a given value to a matrix diagonal. If offset is 0 (the default value), this method will set the values along the main (leading) diagonal. Otherwise, if an offset of "n" is specified, it will set the values along the nth sub-diagonal. By default, the diagonal values will be set in the upper triangular part of the matrix, meaning that the offset represents a number of columns. If the diagonal of interest is in the lower triangular part of the matrix then just set the upper_triangular boolean to false. In this case the offset represents a number of rows. If an offset is specified that is larger than the matrix dimensions no values in the matrix are changed. If the offset is zero it does not matter if the upper_triangular argument is true or not. The value type for the new values must be the same as the value type in the matrix. Note that the matrix coordinates start from (0,0).
- Parameters
-
| value | the value to be set on the diagonal |
| offset | the distance from the main diagonal (optional, default = 0 = main diagonal) |
| upper_triangle | elect the direction for the offset (optional, default = true = upper triangle) |
◆ Assign() [1/2]
| void Unfit::Matrix::Assign |
( |
std::size_t |
num_rows, |
|
|
std::size_t |
num_cols, |
|
|
double |
the_value |
|
) |
| |
This method assigns and resizes the matrix to the corrected dimensions
- Parameters
-
| num_rows | the new number of rows in the resulting matrix |
| num_cols | the new number of columns in the resulting matrix |
| the_value | the value to be inserted into the matrix |
◆ Assign() [2/2]
| void Unfit::Matrix::Assign |
( |
std::size_t |
num_rows, |
|
|
std::size_t |
num_cols, |
|
|
const std::vector< double > & |
matrix_values |
|
) |
| |
This method assigns and resizes the matrix to the corrected dimensions
- Parameters
-
| num_rows | the new number of rows in the resulting matrix |
| num_cols | the new number of columns in the resulting matrix |
| matrix_values | the matrix vector to be inserted into the matrix |
◆ Empty()
| bool Unfit::Matrix::Empty |
( |
| ) |
const |
|
noexcept |
Get the number of entries in the stored matrix.
- Returns
- the number entries in the matrix
◆ GetNumberOfColumns()
| std::size_t Unfit::Matrix::GetNumberOfColumns |
( |
| ) |
const |
|
noexcept |
Get the number of columns in the stored matrix. The entries will be stored from 0 to rows-1.
- Returns
- the number columns in the matrix
◆ GetNumberOfRows()
| std::size_t Unfit::Matrix::GetNumberOfRows |
( |
| ) |
const |
|
noexcept |
Get the number of rows in the stored matrix. The entries will be stored from 0 to cols-1.
- Returns
- the number rows in the matrix
◆ GetValue()
| double Unfit::Matrix::GetValue |
( |
std::size_t |
row, |
|
|
std::size_t |
col |
|
) |
| const |
|
noexcept |
Get the value stored in the matrix at the position (row,column). Note: The matrix coordinates start from (0,0).
- Parameters
-
| row | the row number of the requested value |
| col | the column number of the requested value |
- Returns
- the value of the matrix at position (row,column)
◆ SetValue()
| void Unfit::Matrix::SetValue |
( |
std::size_t |
row, |
|
|
std::size_t |
col, |
|
|
double |
the_value |
|
) |
| |
Set the value stored in the matrix at the position (row,column). Note: The matrix coordinates start from (0,0).
- Parameters
-
| row | the row number of the requested value |
| col | the column number of the requested value |
| the_value | the value to be placed at (row,column) |
◆ Size()
| std::size_t Unfit::Matrix::Size |
( |
| ) |
const |
|
noexcept |
Get the number of entries in the stored matrix.
- Returns
- the number entries in the matrix
◆ number_of_columns_
| std::size_t Unfit::Matrix::number_of_columns_ |
|
private |
Number of columns in the matrix
◆ number_of_rows_
| std::size_t Unfit::Matrix::number_of_rows_ |
|
private |
Number of rows in the matrix
◆ values_
| std::vector<double> Unfit::Matrix::values_ |
Matrix entries stored row-wise in a 1D vector. Note that these values are public to allow direct (fast) access. This is fine for reading, but if you are writing here directly it is up to you to check you are within the bounds of the matrix.
The documentation for this class was generated from the following files: