Go to the documentation of this file. 1 #ifndef EAGINE_MATH_MATRIX_GAUSS_HPP
9 #define EAGINE_MATH_MATRIX_GAUSS_HPP
11 #include "../compare.hpp"
20 template <
typename T,
int Ca,
int Cb,
int R,
bool V>
25 const auto is_zero = [](T x) noexcept {
26 return are_equal(x, T(0));
29 for(
int i = 0; i < R; ++i) {
32 for(
int k = i + 1; k < R; ++k) {
34 swap(a._v[k], a._v[i]);
35 swap(b._v[k], b._v[i]);
44 const auto inv_d = T(1) / d;
49 for(
int k = i + 1; k < R; ++k) {
52 a._v[k] -= a._v[i] * d;
53 b._v[k] -= b._v[i] * d;
63 template <
typename T,
int Ca,
int Cb,
int R,
bool V>
78 template <
typename T,
int Ca,
int Cb,
int R,
bool V>
93 template <
typename T,
int Ca,
int Cb,
int R,
bool V>
111 template <
typename T,
int Ca,
int Cb,
int R,
bool V>
118 for(
int i = R - 1; i > 0; --i) {
119 for(
int k = 0; k < i; ++k) {
120 const T d = a._v[k][i];
121 if(!are_equal(d, T(0))) {
122 a._v[k] -= a._v[i] * d;
123 b._v[k] -= b._v[i] * d;
137 template <
typename T,
int Ca,
int Cb,
int R,
bool V>
153 template <
typename T,
int Ca,
int Cb,
int R,
bool V>
169 template <
typename T,
int Ca,
int Cb,
int R,
bool V>
185 #endif // EAGINE_MATH_MATRIX_GAUSS_HPP
static auto is_zero(const vector< T, N, V > &v) noexcept -> bool
Tests if a vector has zero lenght.
Definition: vector.hpp:287
static auto gauss_elimination(matrix< T, Ca, R, true, V > &a, matrix< T, Cb, R, true, V > &b) noexcept -> bool
Implements gaussian elimination on matrices a and b.
Definition: matrix_gauss.hpp:21
static auto reorder(const matrix< T, C, R, RM, V > &m) noexcept -> matrix< T, C, R, !RM, V >
Returns a matrix reordered (switches row/column major).
Definition: matrix.hpp:314
Math-related code is placed in this namespace.
Definition: eagine.hpp:48
static auto gauss_jordan_elimination(matrix< T, Ca, R, true, V > &a, matrix< T, Cb, R, true, V > &b) noexcept -> bool
Implements gauss-jordan elimination on matrices a and b.
Definition: matrix_gauss.hpp:112
Basic RxC matrix implementation template.
Definition: fwd.hpp:25