12#include <include/qlibs_types.hpp>
13#include <include/ffmath.hpp>
31 template <
size_t Rows,
size_t Cols>
33 template <
size_t R,
size_t C>
40 for (
size_t i = 0; i < Rows; ++i) {
41 for (
size_t j = 0; j < Cols; ++j) {
51 static_assert(Rows == Cols,
"Identity matrix must be square");
53 for (
size_t i = 0; i < Rows; ++i) {
54 for (
size_t j = 0; j < Cols; ++j) {
64 for (
size_t i = 0; i < Rows; ++i) {
65 for (
size_t j = 0; j < Cols; ++j) {
74 for (
size_t i = 0; i < Rows; ++i) {
75 for (
size_t j = 0; j < Cols; ++j) {
83 template <
typename... Args>
86 static_assert(
sizeof...(args) == Rows * Cols,
"Incorrect number of elements provided");
88 for (
size_t i = 0; i < Rows; ++i) {
89 for (
size_t j = 0; j < Cols; ++j) {
90 m[i][j] = elements[i * Cols + j];
107 return m[index / Cols][index % Cols];
112 return m[index / Cols][index % Cols];
118 for (
size_t i = 0; i < Rows; ++i) {
119 for (
size_t j = 0; j < Cols; ++j) {
120 m[i][j] = other.m[i][j];
129 for (
size_t i = 0; i < Rows; ++i) {
130 for (
size_t j = 0; j < Cols; ++j) {
131 result.m[i][j] = m[i][j] + other.m[i][j];
140 for (
size_t i = 0; i < Rows; ++i) {
141 for (
size_t j = 0; j < Cols; ++j) {
142 result.m[i][j] = m[i][j] - other.m[i][j];
152 for (
size_t i = 0; i < Rows; ++i) {
153 for (
size_t j = 0; j < N; ++j) {
155 for (
size_t k = 0; k < Cols; ++k) {
156 result.m[i][j] += m[i][k] * other.m[k][j];
167 for (
size_t i = 0; i < Rows; ++i) {
168 for (
size_t j = 0; j < Cols; ++j) {
169 result.m[i][j] = m[i][j] * scalar;
179 for (
size_t i = 0; i < Rows; ++i) {
180 for (
size_t j = 0; j < Cols; ++j) {
181 result.m[i][j] = m[i][j] / scalar;
191 for (
size_t i = 0; i < Rows; ++i) {
192 for (
size_t j = 0; j < Cols; ++j) {
193 result.m[i][j] = scalar * matrix.m[i][j];
214 for (
size_t i = 0; i < Rows; ++i) {
215 for (
size_t j = 0; j < Cols; ++j) {
216 result.m[i][j] = m[i][j] + scalar;
225 for (
size_t i = 0; i < Rows; ++i) {
226 for (
size_t j = 0; j < Cols; ++j) {
236 for (
size_t i = 0; i < Rows; ++i) {
237 for (
size_t j = 0; j < Cols; ++j) {
247 for (
size_t i = 0; i < Rows; ++i) {
248 for (
size_t j = 0; j < Cols; ++j) {
249 result.m[i][j] = m[i][j] - scalar;
258 for (
size_t i = 0; i < Rows; ++i) {
259 for (
size_t j = 0; j < Cols; ++j) {
269 for (
size_t i = 0; i < Rows; ++i) {
270 for (
size_t j = 0; j < Cols; ++j) {
279 for (
size_t i = 0; i < Rows; ++i) {
280 for (
size_t j = 0; j < Cols; ++j) {
281 m[i][j] += other.m[i][j];
289 for (
size_t i = 0; i < Rows; ++i) {
290 for (
size_t j = 0; j < Cols; ++j) {
291 m[i][j] -= other.m[i][j];
302 for (
size_t i = 0; i < Rows; ++i) {
303 for (
size_t j = 0; j < N; ++j) {
305 for (
size_t k = 0; k < Cols; ++k) {
306 result.m[i][j] += m[i][k] * other.m[k][j];
317 for (
size_t i = 0; i < Rows; ++i) {
318 for (
size_t j = 0; j < Cols; ++j) {
327 for (
size_t i = 0; i < Rows; ++i) {
328 for (
size_t j = 0; j < Cols; ++j) {
338 for (
size_t i = 0; i < Rows; ++i) {
339 for (
size_t j = 0; j < Cols; ++j) {
349 for (
size_t i = 0; i < Rows; ++i) {
350 for (
size_t j = 0; j < Cols; ++j) {
361 for (
size_t i = 0; i < Rows; ++i) {
362 for (
size_t j = 0; j < Cols; ++j) {
363 result.m[i][j] = scalar + matrix.m[i][j];
373 for (
size_t i = 0; i < Rows; ++i) {
374 for (
size_t j = 0; j < Cols; ++j) {
375 result.m[i][j] = scalar - matrix.m[i][j];
384 if (
this != &other) {
385 for (
size_t i = 0; i < Rows; ++i) {
386 for (
size_t j = 0; j < Cols; ++j) {
387 m[i][j] = other.m[i][j];
398 for (
size_t i = 0; i < Rows; ++i) {
399 for (
size_t j = 0; j < Cols; ++j) {
400 result.m[i][j] = -m[i][j];
409 for (
size_t i = 0; i < Rows; ++i) {
410 for (
size_t j = 0; j < Cols; ++j) {
411 std::cout << m[i][j] <<
" ";
413 std::cout << std::endl;
415 std::cout << std::endl;
421 for (
size_t i = 0; i < Rows; ++i) {
422 for (
size_t j = 0; j < Cols; ++j) {
423 transposed[j][i] = m[i][j];
443 static_assert(Rows == Cols,
"Inverse exists only for square matrices");
447 for (
size_t i = 0; i < Rows; ++i ) {
450 for (
size_t j = 0; j < Rows; ++j ) {
454 for (
size_t j = 0; j < Rows; ++j) {
457 for (
size_t k = 0; k < Rows; ++k ) {
458 X(j, k) -= factor * X(i, k);
459 I(j, k) -= factor * I(i, k);
471 real_t maxM =0.0_re, sum = 0.0_re;
473 for ( i = 0U ; i < Cols; i++ ) {
475 for ( j = 0U ; j < Rows ; ++j ) {
476 sum += ( m[i][j] < 0.0_re ) ? -m[i][j] : m[i][j];
481 maxM = ( sum > maxM ) ? sum : maxM;
Matrix object.
Definition mat.hpp:32
real_t & operator()(size_t row, size_t col)
Definition mat.hpp:100
mat< Rows, Cols > operator*(const real_t &scalar) const
Definition mat.hpp:164
mat< Rows, Cols > operator-() const
Definition mat.hpp:395
mat(const matSpecial type, const real_t value=1.0_re)
Definition mat.hpp:47
mat(const mat< Rows, Cols > &other)
Definition mat.hpp:116
mat< Rows, Cols > operator+(const real_t &scalar) const
Definition mat.hpp:211
mat< Rows, Cols > operator--(int)
Definition mat.hpp:266
mat< Rows, Cols > & operator-=(const real_t &scalar)
Definition mat.hpp:347
mat()
Definition mat.hpp:38
friend mat< Rows, Cols > operator-(const real_t &scalar, const mat< Rows, Cols > &matrix)
Definition mat.hpp:370
mat(Args... args)
Definition mat.hpp:84
real_t & operator()(size_t index)
Definition mat.hpp:105
void display() const
Definition mat.hpp:407
real_t * operator[](size_t index)
Definition mat.hpp:431
const real_t * operator[](size_t index) const
Definition mat.hpp:436
mat< Rows, Cols > operator/(const real_t &scalar) const
Definition mat.hpp:176
mat< Rows, Cols > & operator--()
Definition mat.hpp:256
const real_t & operator()(size_t index) const
Definition mat.hpp:110
mat< Rows, Cols > operator+(const mat< Rows, Cols > &other) const
Definition mat.hpp:126
mat< Rows, Cols > & operator/=(const real_t &scalar)
Definition mat.hpp:326
mat< Rows, Rows > inv() const
Definition mat.hpp:441
friend mat< Rows, Cols > operator+(const real_t &scalar, const mat< Rows, Cols > &matrix)
Definition mat.hpp:358
mat< Rows, Cols > & operator++()
Definition mat.hpp:223
mat< Rows, N > & operator*=(const mat< Cols, N > &other)
Definition mat.hpp:299
mat< Rows, N > operator*(const mat< Cols, N > &other) const
Definition mat.hpp:149
mat< Rows, Cols > & operator*=(const real_t &scalar)
Definition mat.hpp:316
mat< Rows, Cols > & operator-=(const mat< Rows, Cols > &other)
Definition mat.hpp:288
mat< Rows, Cols > operator++(int)
Definition mat.hpp:233
mat< Rows, Cols > operator-(const real_t &scalar) const
Definition mat.hpp:244
mat< Rows, Cols > & operator=(const mat< Rows, Cols > &other)
Definition mat.hpp:382
mat< Rows, Cols > & operator+=(const real_t &scalar)
Definition mat.hpp:336
mat< Cols, Rows > operator!() const
Definition mat.hpp:418
real_t normInf() const
Definition mat.hpp:468
friend mat< Rows, Cols > operator*(const real_t &scalar, const mat< Rows, Cols > &matrix)
Definition mat.hpp:188
mat< Rows, Cols > operator-(const mat< Rows, Cols > &other) const
Definition mat.hpp:137
mat< Rows, Cols > & operator+=(const mat< Rows, Cols > &other)
Definition mat.hpp:278
The qLibs++ library namespace.
Definition fp16.cpp:4
matSpecial
Definition mat.hpp:20
@ MAT_ZERO
Definition mat.hpp:21
@ MAT_MAGIC
Definition mat.hpp:24
@ MAT_ALL
Definition mat.hpp:23
@ MAT_IDENTITY
Definition mat.hpp:22
float real_t
A type to instantiate a real variable double-precision of 64-bits IEEE 754.
Definition qlibs_types.hpp:43