1 #ifndef KINEMATICS_MATRIX_HPP 2 #define KINEMATICS_MATRIX_HPP 5 #include <initializer_list> 21 template<
typename T, std::
size_t m, std::
size_t n>
24 static_assert(std::is_arithmetic<T>::value,
25 "Matrix can only be declared with a type where " 26 "std::is_arithmetic is true.");
85 std::initializer_list<std::initializer_list<T>> matrix_data);
92 constexpr std::size_t
get_m()
const noexcept;
99 constexpr std::size_t
get_n()
const noexcept;
107 constexpr std::array<T, n>&
operator[](std::size_t pos) noexcept;
115 constexpr
const std::array<T, n>&
operator[](std::size_t pos)
const 125 constexpr std::array<T, n>&
at(std::size_t pos);
134 constexpr
const std::array<T, n>&
at(std::size_t pos)
const;
233 template<std::
size_t p>
245 template<std::
size_t p>
257 template<std::
size_t p>
273 template<std::
size_t y, std::
size_t x, std::
size_t p, std::
size_t q>
289 constexpr std::optional<Matrix<T, m, n>>
inverse()
const noexcept;
304 std::string
str()
const;
311 std::array<std::array<T, n>, m> data{};
322 template<
typename T, std::
size_t m, std::
size_t n>
333 template<
typename T, std::
size_t m, std::
size_t n>
344 template<
typename T, std::
size_t m, std::
size_t n>
355 template<
typename T, std::
size_t m, std::
size_t n>
366 template<
typename T, std::
size_t m, std::
size_t n>
377 template<
typename T, std::
size_t m, std::
size_t n>
388 template<
typename T, std::
size_t m, std::
size_t n>
399 template<
typename T, std::
size_t m, std::
size_t n>
409 template<
typename T, std::
size_t m, std::
size_t n>
410 std::ostream& operator<<(std::ostream& os, const Matrix<T, m, n>& mat);
415 #include "Matrix.ipp" constexpr Matrix< T, m, n > operator+(const Matrix< T, m, n > &mat) const noexcept
Add a matrix to another matrix. Returns a new matrix.
constexpr Matrix< T, m, n > operator/(const Matrix< T, m, n > &lhs, T rhs) noexcept
Divide every element of the matrix with a scalar. Doesn't modify original matrix. ...
constexpr bool operator==(const Matrix< T, m, n > &mat) const noexcept
Compare two matrices.
std::string str() const
Get a string representation.
constexpr Matrix< T, m, n > operator-(const Matrix< T, m, n > &mat) const noexcept
Subtract a matrix from another matrix. Returns a new matrix.
constexpr Matrix< T, m, n+p > horizontal_augment(const Matrix< T, m, p > &mat) const noexcept
Right augment the current matrix with the provided matrix.
constexpr T get_magnitude() const noexcept
Get the magnitude of the matrix. This is equivalent to the euclidean distance.
constexpr void operator/=(T scalar) noexcept
Divide every element of the matrix with a scalar.
constexpr Matrix< T, m+p, n > vertical_augment(const Matrix< T, p, n > &mat) const noexcept
Bottom augment the current matrix with the provided matrix.
constexpr std::array< T, n > & at(std::size_t pos)
Get row of matrix at pos. Throw out of range exception if out of range.
constexpr void operator-=(T scalar) noexcept
Subtract a scalar from every element of the matrix.
constexpr bool fuzzy_equal(const Matrix< T, m, n > &mat, T fuzz) const noexcept
Fuzzy compare 2 matrices.
constexpr std::array< T, n > & operator[](std::size_t pos) noexcept
Get row of matrix at pos. No bounds checkin.
constexpr std::optional< Matrix< T, m, n > > inverse() const noexcept
Get the inverse of the matrix, implemented by using gauss-jordan. This operation is only available fo...
constexpr bool operator!=(const Matrix< T, m, n > &mat) const noexcept
Compare two matrices.
Matrix< T, m, n > & operator=(const Matrix< T, m, n > &mat)=default
Default assignment operator.
constexpr std::size_t get_n() const noexcept
Get the amount of cols of the matrix.
constexpr Matrix< T, n, m > transpose() const noexcept
Transpose the matrix.
~Matrix()=default
Default destructor.
constexpr void operator*=(T scalar) noexcept
Multiply every element of the matrix with a scalar.
Matrix()=default
Create matrix with all elements set to 0.
static constexpr Matrix< T, m, n > get_identity() noexcept
Get identity matrix.
constexpr Matrix< T, p, q > slice() const noexcept
Create a new matrix from the current one where some columns and rows are sliced of.
constexpr std::size_t get_m() const noexcept
Get the amount of rows of the matrix.
Create a matrix with numerical values.
Definition: Matrix.hpp:22
constexpr Matrix< T, m, p > operator*(const Matrix< T, n, p > &mat) const noexcept
Multiply a matrix with the current matrix.
constexpr void operator+=(T scalar) noexcept
Add a scalar from every element of the matrix.