40#ifndef GEOGRAM_BASIC_MATRIX
41#define GEOGRAM_BASIC_MATRIX
45#include <initializer_list>
65 template <index_t DIM,
class FT>
93 for(
index_t i = 0; i < DIM; i++) {
94 for(
index_t j = 0; j < DIM; j++) {
105 Matrix(
const std::initializer_list< std::initializer_list<FT> >& Mi) {
133 for(
index_t i = 0; i < DIM; i++) {
134 for(
index_t j = 0; j < DIM; j++) {
135 coeff_[i][j] = FT(0);
146 for(
index_t i = 0; i < DIM; i++) {
147 for(
index_t j = 0; j < DIM; j++) {
148 coeff_[i][j] = (i == j) ? FT(1) : FT(0);
159 for(
index_t i = 0; i < DIM; i++) {
160 for(
index_t j = 0; j < DIM; j++) {
161 FT rhs = ((i == j) ? FT(1) : FT(0));
162 if(coeff_[i][j] != rhs) {
205 for(
index_t i = 0; i < DIM; i++) {
206 for(
index_t j = 0; j < DIM; j++) {
207 coeff_[i][j] += m.coeff_[i][j];
220 for(
index_t i = 0; i < DIM; i++) {
221 for(
index_t j = 0; j < DIM; j++) {
222 coeff_[i][j] -= m.coeff_[i][j];
236 for(
index_t i = 0; i < DIM; i++) {
237 for(
index_t j = 0; j < DIM; j++) {
252 for(
index_t i = 0; i < DIM; i++) {
253 for(
index_t j = 0; j < DIM; j++) {
319 for(
index_t i = 0; i < DIM; i++) {
320 for(
index_t j = 0; j < DIM; j++) {
321 result.coeff_[i][j] = FT(0);
322 for(
index_t k = 0; k < DIM; k++) {
323 result.coeff_[i][j] += coeff_[i][k] * m.coeff_[k][j];
355 FT val=FT(0.0), val2=FT(0.0);
360 for(
index_t i = 0; i != DIM; i++) {
363 for(
index_t j = i + 1; j != DIM; j++) {
364 if(fabs(tmp(j, i)) > fabs(val)) {
371 for(
index_t j = 0; j != DIM; j++) {
373 result(i, j) = result(ind, j);
374 result(ind, j) = val2;
376 tmp(i, j) = tmp(ind, j);
381 if(abs(val) <= min_val) {
385 for(
index_t j = 0; j != DIM; j++) {
390 for(
index_t j = 0; j != DIM; j++) {
395 for(
index_t k = 0; k != DIM; k++) {
396 tmp(j, k) -= tmp(i, k) * val;
397 result(j, k) -= result(i, k) * val;
411 for(
index_t i = 0; i < DIM; i++) {
412 for(
index_t j = 0; j < DIM; j++) {
413 result(i, j) = (* this)(j, i);
425 inline const FT*
data()
const {
426 return &(coeff_[0][0]);
436 return &(coeff_[0][0]);
447 for(
index_t i = 0; i < DIM; i++) {
448 for(
index_t j = 0; j <= i; j++) {
449 *store++ = coeff_[i][j];
469 template <index_t DIM,
class FT>
473 const char* sep =
"";
474 for(
index_t i = 0; i < DIM; i++) {
475 for(
index_t j = 0; j < DIM; j++) {
476 output << sep << m(i, j);
492 template <index_t DIM,
class FT>
496 for(
index_t i = 0; i < DIM; i++) {
497 for(
index_t j = 0; j < DIM; j++) {
519 template <index_t DIM,
class FT>
inline
521 for(
index_t i = 0; i < DIM; i++) {
523 for(
index_t j = 0; j < DIM; j++) {
524 y[i] += M(i, j) * x[j];
539 template <index_t DIM,
class FT>
inline
544 for(
index_t i = 0; i < DIM; i++) {
546 for(
index_t j = 0; j < DIM; j++) {
547 y[i] += M(i, j) * x[j];
563 template <index_t DIM,
class FT>
inline
568 for(
index_t i = 0; i < DIM; i++) {
570 for(
index_t j = 0; j < DIM; j++) {
571 y[i] += M(j, i) * x[j];
590 template <index_t DIM,
class FT>
591 [[deprecated(
"use operator*(matrix, vector) instead")]]
596 for(
index_t i = 0; i < DIM; i++) {
598 for(
index_t j = 0; j < DIM; j++) {
599 y[i] += M(i, j) * x[j];
#define geo_assert(x)
Verifies that a condition is met.
#define geo_debug_assert(x)
Verifies that a condition is met.
bool compute_inverse(matrix_type &result, value_type min_val=value_type(0)) const
Computes the inverse matrix.
matrix_type transpose() const
Computes the transposed matrix.
matrix_type & operator*=(FT val)
Multiplies by a scalar in place.
void get_lower_triangle(FT *store) const
Gets the lower triangle of the matrix.
matrix_type & operator-=(const matrix_type &m)
Subtracts a matrix in place.
Matrix(const FT *vals)
Constructs a matrix from an array of values.
index_t dimension() const
Gets the matrix dimension.
Matrix< DIM, FT > matrix_type
matrix_type operator+(const matrix_type &m) const
Adds 2 matrices.
const FT * data() const
Gets non-modifiable matrix data.
FT & operator()(index_t i, index_t j)
Gets a modifiable element.
matrix_type operator*(FT val) const
Multiplies a matrix by a scalar.
void load_zero()
Clears the matrix.
matrix_type & operator/=(FT val)
Divides by a scalar in place.
Matrix(const std::initializer_list< std::initializer_list< FT > > &Mi)
Constructs a matrix from 2d array of initializers.
bool is_identity() const
Tests whether a matrix is the identity matrix.
matrix_type operator-(const matrix_type &m) const
Subtracts 2 matrices.
void mult(const Matrix< DIM, FT > &M, const FT *x, FT *y)
Multiplies a matrix by a vector.
FT * data()
Gets modifiable matrix data.
matrix_type inverse() const
Computes the inverse matrix.
void load_identity()
Sets the matrix to identity.
Matrix()
Default constructor.
static constexpr index_t dim
matrix_type & operator+=(const matrix_type &m)
Adds a matrix in place.
matrix_type operator/(FT val) const
Divides a matrix by a scalar.
Common include file, providing basic definitions. Should be included before anything else by all head...
Global Vorpaline namespace.
std::istream & operator>>(std::istream &in, Quaternion &q)
Reads a Quaternion from a stream.
std::ostream & operator<<(std::ostream &out, const Quaternion &q)
Writes a Quaternion to a stream.
geo_index_t index_t
The type for storing and manipulating indices.
vecng< DIM, FT > mult(const Matrix< DIM, FT > &M, const vecng< DIM, FT > &x)
Computes a matrix vector product.
vecng< DIM, FT > operator*(const Matrix< DIM, FT > &M, const vecng< DIM, FT > &x)
Computes a matrix vector product.
Generic implementation of geometric vectors.