Skip to content

Matrix

Matrix<T> is a templated storage container for storing numerical data. It can handle any type T of values except bool but is recommended for the arithmetic types. For storing bool vdata and other uses see Table container.

The data inside of the Matrix container is manipulated using a number of dedicated methods:

Constructors

cpp
Matrix();

Default constructor. Constructs empty matrix.

cpp
Matrix(const Matrix<T>& rhs);

Copy constructor. Initializes current container with the copy of rhs.

cpp
Matrix(const size_t N, const size_t M);

Constructor. Allocates internal storage to the specified dimensions (N,M).

cpp
void Allocate(const size_t N, const size_t M);

Allocates internal storage to the specified table dimensions (N,M).

cpp
void Reallocate(const size_t N, const size_t M);

Reallocates internal storage to new dimensions. Previously stored data is erased.

Data access and manipulation

cpp
T const& operator()(const size_t n, const size_t m) const;

One-directional access operator. Returns constant reference to the matrix element (n,m).

cpp
T& operator()(const size_t n, const size_t m);

Bi-directional access operator. Returns reference to the matrix element (n,m).

cpp
void set(const size_t n, const size_t m, const T value);

Sets matrix element (n,m) to the specified value.

cpp
void set_to_value(const T value);

Sets all matrix elements to the specified value.

cpp
void add(const size_t n, const size_t m, const T value);

Adds value to the matrix element (n,m).

cpp
T get(const size_t n, const size_t m) const;

Returns the value of the matrix element (n,m).

cpp
T get_min() const;

Returns the value of the minimum element of the matrix.

cpp
T get_max() const;

Returns the value of the maximum element of the matrix.

cpp
>static Matrix<T> max(const Matrix<T>& M1, const Matrix<T>& M2);

Returns matrix containing maximum elements between the two matrices.

cpp
static Matrix<T> min(const Matrix<T>& M1, const  Matrix<T>& M2);

Returns matrix containing minimum elements between the two matrices.

cpp
T* data();

Raw data access.

Container properties

cpp
size_t size_tot();

Total size of the internal storage.

cpp
size_t sizeN() const;

Returns first dimension of the stored matrix.

cpp
size_t sizeM() const;

Returns second dimension of the stored matrix.

cpp
bool IsNotAllocated() const;

Returns true if matrix is not allocated (internal storage size is zero).

cpp
bool IsAllocated() const;

Returns true if matrix is allocated (internal storage size is not zero).

Arithmetic operations

cpp
Matrix<T> operator*(const Matrix<T>& rhs) const;

Returns matrix dot product between the current matrix and rhs.

cpp
Matrix<T> operator+(const Matrix<T>& rhs);

Returns a matrix containing the sum of two matrices.

cpp
Matrix<T>& operator+=(const Matrix<T>& rhs);

Adds rhs to the current matrix. For empty matrices assumes zeros.

cpp
Matrix<T>& operator=(const Matrix<T>& rhs);

Assignment operator. Assigns the content of rhs to the current matrix.

Output

cpp
std::string print(void) const;

Returns formatted string with matrix content.

Released under the GNU GPLv3 License.