14#include "../utils/concepts.h"
26template <
typename _Tp,
size_t _rows,
size_t _cols = _rows>
27class mat :
public vec<vec<_Tp, _cols>, _rows> {
68 :
vec<
vec<_Tp, _cols>, _rows>(o) {}
77 template <
size_t _ncols>
81 for (
size_t i = 0; i < _rows; i++) {
82 for (
size_t j = 0; j < _ncols; j++) {
83 for (
size_t k = 0; k < _cols; k++) {
84 res[i][j] += this->
data[i][k] * other[k][j];
99 requires(_VTp::length == _rows) &&
102 constexpr _VTp
operator^(
const _VTp& other)
const {
104 for (
size_t i = 0; i < _rows; i++) {
105 for (
size_t j = 0; j < _cols; j++) {
106 res[i] += this->
data[i][j] * other[j];
119 for (
size_t i = 0; i < _rows; i++) {
120 for (
size_t j = 0; j < _cols; j++) {
121 res[j][i] = this->
data[i][j];
128 requires(_rows == _cols)
130 const _Tp
det = this->
det();
132 for (
size_t i = 0; i < _rows; ++i) {
133 for (
size_t j = 0; j < _cols; ++j) {
135 mat<_Tp, _rows - 1, _cols - 1> submat;
137 for (
size_t k = 0; k < _rows; ++k) {
138 if (k == i)
continue;
140 for (
size_t l = 0; l < _cols; ++l) {
141 if (l == j)
continue;
142 submat[sub_i][sub_j++] = this->
data[k][l];
147 _Tp cofactor = ((i + j) % 2 == 0 ? 1 : -1) * submat.
det();
148 adjugate[j][i] = cofactor;
151 return adjugate /
det;
170 size_t n = _rows < _cols ? _rows : _cols;
171 for (
size_t i = 0; i < n; i++) {
183 requires(_rows == _cols)
185 if constexpr (_rows == 1) {
186 return this->
data[0][0];
187 }
else if constexpr (_rows == 2) {
188 return this->
data[0][0] * this->
data[1][1] -
189 this->
data[0][1] * this->
data[1][0];
192 for (
size_t j = 0; j < _rows; j++) {
193 mat<_Tp, _rows - 1, _cols - 1> submat;
194 for (
size_t i = 1; i < _rows; i++) {
195 for (
size_t k = 0; k < j; k++) {
196 submat[i - 1][k] = this->
data[i][k];
198 for (
size_t k = j + 1; k < _cols; k++) {
199 submat[i - 1][k - 1] = this->
data[i][k];
203 ((j % 2 == 0) ? 1 : -1) * this->
data[0][j] * submat.
det();
constexpr mat< _Tp, _cols, _rows > inv() const
static constexpr mat< _Tp, _rows, _cols > eye()
Create an identity matrix
constexpr mat< _Tp, _cols, _rows > T() const
Transpose operator
static constexpr vec2< size_t > shape
Shape of the matrix (rows x columns)
static constexpr mat< _Tp, _rows, _cols > ones()
Create a matrix filled with ones
constexpr _Tp det() const
Compute determinant of the matrix
constexpr mat< _Tp, _rows, _ncols > operator^(const mat< _Tp, _cols, _ncols > &other) const
Matrix multiplication operator
constexpr vec()
Construct a zero-initialized vector Notw: _Tp must be default constructible
constexpr const _Tp * begin() const
Get pointer to the beginning of the data array
_Tp data[_length]
Component storage array
constexpr const _Tp * end() const
Get pointer to the end of the data array
Declaration of vector, matrix, quaternion, and complex classes
Compiler-specific type information handling for MSVC