21template <
class T,
unsigned SX,
unsigned SY=SX>
30 constexpr Column(
const Column &r) : x_(r.x_), m_(r.m_) { }
32 constexpr const T &
operator[](
unsigned y)
const {
return m_.
get(x_,y); }
41 template <
unsigned SZ,
unsigned I,
unsigned J,
unsigned K>
45 return l.t_[SX-I][SY-K]*m.t_[SY-K][SZ-J] + innerLoop<SZ,I,J,K-1>::execute(l,m);
48 template <
unsigned SZ,
unsigned I,
unsigned J>
49 class innerLoop<SZ,I,J,1> {
52 return l.t_[SX-I][SY-1]*m.t_[SY-1][SZ-J];
55 template <
unsigned I,
unsigned K>
56 class innerLoop<1,I,1,K> {
59 return l.t_[SX-I][SY-K]*m.t_[SY-K] + innerLoop<1,I,1,K-1>::execute(l,m);
63 class innerLoop<1,I,1,1> {
66 return l.t_[SX-I][SY-1]*m.t_[SY-1];
70 template <
unsigned SZ,
unsigned I,
unsigned J>
74 ret.t_[SX-I][SZ-J] = innerLoop<SZ,I,J,SY>::execute(l,m);
75 loop2Multiply<SZ,I,J-1>::execute(l,m,ret);
78 template <
unsigned SZ,
unsigned I>
79 class loop2Multiply<SZ,I,1> {
82 ret.t_[SX-I][SZ-1] = innerLoop<SZ,I,1,SY>::execute(l,m);
86 class loop2Multiply<1,I,1> {
89 ret.t_[SX-I] = innerLoop<1,I,1,SY>::execute(l,m);
93 template <
unsigned SZ,
unsigned I>
97 loop2Multiply<SZ,I,SZ>::execute(l,m,ret);
98 loopMultiply<SZ,I-1>::execute(l,m,ret);
101 template <
unsigned SZ>
102 class loopMultiply<SZ,1> {
105 loop2Multiply<SZ,1,SZ>::execute(l,m,ret);
121 explicit constexpr Matrix(
const std::array<std::array<T,SY>,SX> &a) {
for (
unsigned i=0;i<SX;++i)
for (
unsigned j=0;j<SY;++j) t_[i][j] = a[i][j]; }
122 constexpr Matrix(
const std::initializer_list<std::initializer_list<T>> l);
129 constexpr const T &
get(
unsigned x,
unsigned y)
const { assert(x<SX); assert(y<SY);
return t_[x][y]; }
131 constexpr T &
get(
unsigned x,
unsigned y) { assert(x<SX); assert(y<SY);
return t_[x][y]; }
133 constexpr const Column
operator[](
unsigned y)
const {
return Column(y,*
this); }
135 constexpr Column
operator[](
unsigned y) {
return Column(y,*
this); }
137 constexpr const T &
operator()(
unsigned x,
unsigned y)
const {
return get(x,y); }
146 constexpr const Matrix<T,SX,SY> &
operator*=(
const T &t) {
for (
unsigned i=0;i<SX;++i)
for (
unsigned j=0;j<SY;++j) t_[i][j] *= t;
return *
this; }
148 constexpr const Matrix<T,SX,SY> &
operator/=(
const T &t) {
for (
unsigned i=0;i<SX;++i)
for (
unsigned j=0;j<SY;++j) t_[i][j] /= t;
return *
this; }
159 template <
unsigned SZ>
171 loopMultiply<SZ,SX>::execute(*
this,m,ret);
191 template <
unsigned BX,
unsigned BY,
unsigned SX2,
unsigned SY2>
196 template <
unsigned BX,
unsigned BY,
unsigned SX2,
unsigned SY2>
198 for (
unsigned i=iSrc,
id=iDst;i<(iSrc+BX);i++,
id++)
199 for (
unsigned j=jSrc,jd=jDst;j<(jSrc+BY);j++,jd++)
200 get(
id,jd) += m(i,j);
204 T
maxNorm()
const { T ret(0);
for (
unsigned i=0;i<SX;++i)
for (
unsigned j=0;j<SY;++j) ret =
std::max(ret,std::abs(t_[i][j]));
return ret; }
208 T
trace()
const { T tt = t_[0][0];
unsigned len =
std::min(SX,SY);
for (
unsigned i=1; i<len; ++i) tt += t_[i][i];
return tt; }
210 constexpr void set(
const T &t=T()) {
for (
unsigned i=0;i<SX;++i)
for (
unsigned j=0;j<SY;++j) t_[i][j] = t; }
218template <
class T,
unsigned SX,
unsigned SY>
233template <
class T,
unsigned SX>
246 constexpr Matrix(
const std::array<T,SX> &a) {
for (uint32 i=0;i<SX;++i) t_[i] = a[i]; }
247 constexpr Matrix(
const std::initializer_list<T> l) { uint32 i=0;
for (
auto &x : l) { t_[i] = x; ++i; } }
252 constexpr const T &
get(
unsigned x,[[maybe_unused]]
unsigned y)
const { assert(x<SX); assert(!y);
return t_[x]; }
254 constexpr const T &
get(
unsigned x)
const { assert(x<SX);
return t_[x]; }
256 constexpr T &
get(
unsigned x,[[maybe_unused]]
unsigned y) { assert(x<SX); assert(!y);
return t_[x]; }
258 constexpr T &
get(
unsigned x) { assert(x<SX);
return t_[x]; }
260 constexpr const T &
operator()(
unsigned x,
unsigned y)
const {
return get(x,y); }
288 for (
unsigned i=0;i<SX;++i)
289 for (
unsigned j=0;j<SZ;++j)
296 template <
unsigned BX,
unsigned BY,
unsigned SX2,
unsigned SY2>
void addBlock(
const Matrix<T,SX2,SY2> &m,
unsigned iSrc,
unsigned jSrc,
unsigned iDst,
unsigned jDst) {
304 template <
unsigned BX,
unsigned BY,
unsigned SX2,
unsigned SY2>
void addGenBlock(
const Matrix<T,SX2,SY2> &m,
unsigned iSrc,
unsigned jSrc,
unsigned iDst,
unsigned jDst) {
305 for (
unsigned i=iSrc,
id=iDst;i<(iSrc+BX);i++,
id++)
306 for (
unsigned j=jSrc,jd=jDst;j<(jSrc+BY);j++,jd++)
307 get(
id,jd) += m(i,j);
311 for (
unsigned i=iSrc,
id=iDst;i<(iSrc+BX);i++,
id++)
316 T
maxNorm()
const { T ret(0);
for (
unsigned i=0;i<SX;++i) ret =
std::max(ret,std::abs(t_[i]));
return ret; }
320 void set(
const T &t=T()) {
for (
unsigned i=0;i<SX;++i) t_[i] = t; }
331template <
class T,
unsigned SX>
340 Column(
const Column &r) : x_(r.x_), m_(r.m_) { }
342 const T &
operator[](
unsigned y)
const {
return m_.get(x_,y); }
344 T &
operator[](
unsigned y) {
return m_.get(x_,y); }
351 template <
unsigned SZ,
unsigned I,
unsigned J,
unsigned K>
355 return l.t_[index(SX-I,SX-K)]*m.t_[SX-K][SZ-J] + innerLoop<SZ,I,J,K-1>::execute(l,m);
358 template <
unsigned SZ,
unsigned I,
unsigned J>
359 class innerLoop<SZ,I,J,1> {
362 return l.t_[index(SX-I,SX-1)]*m.t_[SX-1][SZ-J];
365 template <
unsigned I,
unsigned K>
366 class innerLoop<1,I,1,K> {
369 return l.t_[index(SX-I,SX-K)]*m.t_[SX-K] + innerLoop<1,I,1,K-1>::execute(l,m);
372 template <
unsigned I>
373 class innerLoop<1,I,1,1> {
376 return l.t_[index(SX-I,SX-1)]*m.t_[SX-1];
380 template <
unsigned SZ,
unsigned I,
unsigned J>
381 class loop2Multiply {
384 ret.t_[SX-I][SZ-J] = innerLoop<SZ,I,J,SX>::execute(l,m);
385 loop2Multiply<SZ,I,J-1>::execute(l,m,ret);
388 template <
unsigned SZ,
unsigned I>
389 class loop2Multiply<SZ,I,1> {
392 ret.t_[SX-I][SZ-1] = innerLoop<SZ,I,1,SX>::execute(l,m);
395 template <
unsigned I>
396 class loop2Multiply<1,I,1> {
399 ret.t_[SX-I] = innerLoop<1,I,1,SX>::execute(l,m);
403 template <
unsigned SZ,
unsigned I>
407 loop2Multiply<SZ,I,SZ>::execute(l,m,ret);
408 loopMultiply<SZ,I-1>::execute(l,m,ret);
411 template <
unsigned SZ>
412 class loopMultiply<SZ,1> {
415 loop2Multiply<SZ,1,SZ>::execute(l,m,ret);
421 template <
unsigned I,
unsigned J,
unsigned K>
425 return l.t_[index(SX-I,SX-K)]*m.t_[index(SX-K,SX-J)] + innerLoopS<I,J,K-1>::execute(l,m);
429 template <
unsigned I,
unsigned J>
430 class innerLoopS<I,J,1> {
433 return l.t_[index(SX-I,SX-1)]*m.t_[index(SX-1,SX-J)];
439 template <
unsigned I,
unsigned J>
440 class loop2MultiplyS {
443 ret.t_[SX-I][SX-J] = innerLoopS<I,J,SX>::execute(l,m);
444 loop2MultiplyS<I,J-1>::execute(l,m,ret);
447 template <
unsigned I>
448 class loop2MultiplyS<I,1> {
451 ret.t_[SX-I][SX-1] = innerLoopS<I,1,SX>::execute(l,m);
455 template <
unsigned I>
456 class loopMultiplyS {
459 loop2MultiplyS<I,SX>::execute(l,m,ret);
460 loopMultiplyS<I-1>::execute(l,m,ret);
465 class loopMultiplyS<1> {
468 loop2MultiplyS<1,SX>::execute(l,m,ret);
488 const T &
get(
unsigned x,
unsigned y)
const {
return t_[index(x,y)]; }
490 T &
get(
unsigned x,
unsigned y) {
return t_[index(x,y)]; }
492 const Column
operator[](
unsigned y)
const {
return Column(y,*
this); }
525 loopMultiplyS<SX>::execute(*
this,m,ret);
539 loopMultiply<SZ,SX>::execute(*
this,m,ret);
564 template <
unsigned BX,
unsigned BY,
unsigned SX2,
unsigned SY2>
void addBlock(
const Matrix<T,SX2,SY2> &m,
unsigned iSrc,
unsigned jSrc,
unsigned iDst,
unsigned jDst) {
568 template <
unsigned BX,
unsigned BY,
unsigned SX2>
void addBlock(
const SymMatrix<T,SX2> &m,
unsigned iSrc,
unsigned jSrc,
unsigned iDst,
unsigned jDst) {
572 template <
unsigned BX,
unsigned BY,
unsigned SX2,
unsigned SY2>
void addGenBlock(
const Matrix<T,SX2,SY2> &m,
unsigned iSrc,
unsigned jSrc,
unsigned iDst,
unsigned jDst) {
573 for (
unsigned i=iSrc,
id=iDst;i<(iSrc+BX);i++,
id++) {
574 for (
unsigned j=jSrc,jd=jDst;j<(jSrc+BY);j++,jd++) {
576 get(
id,jd) += m(i,j);
581 template <
unsigned BX,
unsigned BY,
unsigned SX2>
void addGenBlock(
const SymMatrix<T,SX2> &m,
unsigned iSrc,
unsigned jSrc,
unsigned iDst,
unsigned jDst) {
582 for (
unsigned i=iSrc,
id=iDst;i<(iSrc+BX);i++,
id++) {
583 for (
unsigned j=jSrc,jd=jDst;j<(jSrc+BY);j++,jd++) {
585 get(
id,jd) += m(i,j);
591 T
maxNorm()
const { T ret(0);
for (
unsigned i=0;i<len_;++i) ret =
std::max(std::abs(t_[i]),ret);
return ret; }
595 T
trace()
const { T tt = t_[0];
for (
unsigned i=1; i<SX; ++i) tt +=
get(i,i);
return tt; }
597 void set(
const T &t=T()) {
for (
unsigned i=0;i<len_;++i) t_[i] = t; }
609 for (
unsigned i=0;i<SX;++i) {
611 for (
unsigned j=i+1;j<SX;++j) {
612 ret(i,j) = (m(i,j) + m(j,i)) * 0.5;
614 maxdif =
std::max(std::abs(ret(i,j) - m(i,j)),maxdif);
624 static constexpr unsigned len_ = (SX*SX + SX) / 2;
625 static constexpr unsigned indexConst_ = 1 + 2*SX;
626 static constexpr unsigned index(
unsigned x,
unsigned y) {
627 unsigned x2 = x > y ? y : x;
628 unsigned y2 = x > y ? x : y;
629 unsigned i = (((indexConst_-x2)*x2)/2) + (y2-x2);
640template <
class T,
unsigned SX,
unsigned SY,
unsigned I,
unsigned J,
unsigned K>
644 return l.t_[SX-I][SY-K]*m.t_[m.index(SY-K,SY-J)] + innerLoopMS<T,SX,SY,I,J,K-1>::execute(l,m);
647template <
class T,
unsigned SX,
unsigned SY,
unsigned I,
unsigned J>
651 return l.t_[SX-I][SY-1]*m.t_[m.index(SY-1,SY-J)];
655template <
class T,
unsigned SX,
unsigned SY,
unsigned I,
unsigned J>
659 ret.t_[SX-I][SY-J] = innerLoopMS<T,SX,SY,I,J,SY>::execute(l,m);
660 loop2MultiplyMS<T,SX,SY,I,J-1>::execute(l,m,ret);
663template <
class T,
unsigned SX,
unsigned SY,
unsigned I>
667 ret.t_[SX-I][SY-1] = innerLoopMS<T,SX,SY,I,1,SY>::execute(l,m);
671template <
class T,
unsigned SX,
unsigned SY,
unsigned I>
675 loop2MultiplyMS<T,SX,SY,I,SY>::execute(l,m,ret);
676 loopMultiplyMS<T,SX,SY,I-1>::execute(l,m,ret);
679template <
class T,
unsigned SX,
unsigned SY>
683 loop2MultiplyMS<T,SX,SY,1,SY>::execute(l,m,ret);
687template <
class T,
unsigned SX,
unsigned SY>
690 loopMultiplyMS<T,SX,SY,SX>::execute(m,s,ret);
710 using Matrix<T,S,1>::operator=;
741template <
unsigned SX,
unsigned SY=SX>
class DMatrix :
public Matrix<double,SX,SY> {
744 using Matrix<double,SX,SY>::operator=;
784 using VMatrix<double,S>::operator=;
800template <
class T,
unsigned S>
803 for (uint32 i=0;i<S;++i)
808template <
class T,
unsigned S>
811 for (uint32 i=0;i<S;++i) {
812 for (uint32 j=0;j<S;++j)
813 ret(i,j) = v1(i) * v2(j);
824 ret.
get(0,0) = v1.
x() * v2.
x();
825 ret.
get(0,1) = v1.
x() * v2.
y();
826 ret.
get(0,2) = v1.
x() * v2.
z();
827 ret.
get(1,0) = v1.
y() * v2.
x();
828 ret.
get(1,1) = v1.
y() * v2.
y();
829 ret.
get(1,2) = v1.
y() * v2.
z();
830 ret.
get(2,0) = v1.
z() * v2.
x();
831 ret.
get(2,1) = v1.
z() * v2.
y();
832 ret.
get(2,2) = v1.
z() * v2.
z();
842 ret.
get(0,0) = v1.
x() * v2.
x();
843 ret.
get(0,1) = v1.
x() * v2.
y();
844 ret.
get(1,0) = v1.
y() * v2.
x();
845 ret.
get(1,1) = v1.
y() * v2.
y();
855 T t = mat.
get(0,0) * (mat.
get(1,1) * mat.
get(2,2) - mat.
get(2,1) * mat.
get(1,2));
856 t -= mat.
get(1,0) * (mat.
get(0,1) * mat.
get(2,2) - mat.
get(2,1) * mat.
get(0,2));
857 t += mat.
get(2,0) * (mat.
get(0,1) * mat.
get(1,2) - mat.
get(1,1) * mat.
get(0,2));
866 return mat.
get(0,0) * mat.
get(1,1) - mat.
get(0,1) * mat.
get(1,0);
876 const T a11 = mat(0,0), a21 = mat(1,0), a31 = mat(2,0);
877 const T a12 = mat(0,1), a22 = mat(1,1), a32 = mat(2,1);
878 const T a13 = mat(0,2), a23 = mat(1,2), a33 = mat(2,2);
880 Matrix<T,3,3> rm = {{ a22*a33 - a32*a23,-a12*a33 + a32*a13, a12*a23 - a22*a13},
881 {-a21*a33 + a31*a23, a11*a33 - a31*a13,-a11*a23 + a21*a13},
882 { a21*a32 - a31*a22,-a11*a32 + a31*a12, a11*a22 - a21*a12}};
904 rm.
get(0,0) = mat.
get(1,1);
905 rm.
get(1,1) = mat.
get(0,0);
906 rm.
get(0,1) = mat.
get(0,1)*(-1);
907 rm.
get(1,0) = mat.
get(1,0)*(-1);
914constexpr std::tuple<Matrix<T,3,3>,
double> inverseDet(
const Matrix<T,3,3> &mat) {
916 const T &a11 = mat(0,0), a21 = mat(1,0), a31 = mat(2,0);
917 const T &a12 = mat(0,1), a22 = mat(1,1), a32 = mat(2,1);
918 const T &a13 = mat(0,2), a23 = mat(1,2), a33 = mat(2,2);
921 rm.
get(0,0) = a22*a33 - a32*a23;
922 rm.
get(1,0) = -a21*a33 + a31*a23;
923 rm.
get(2,0) = a21*a32 - a31*a22;
924 rm.
get(0,1) = -a12*a33 + a32*a13;
925 rm.
get(1,1) = a11*a33 - a31*a13;
926 rm.
get(2,1) = -a11*a32 + a31*a12;
927 rm.
get(0,2) = a12*a23 - a22*a13;
928 rm.
get(1,2) = -a11*a23 + a21*a13;
929 rm.
get(2,2) = a11*a22 - a21*a12;
931 double det = determinant(mat);
932 return {rm / det,det};
957template <
class T,
unsigned SX>
960 ret.
get(start) = v.
x();
961 ret.
get(start+1) = v.
y();
970template <
class T,
unsigned SX>
973 ret.
get(start) = v.
x();
974 ret.
get(start+1) = v.
y();
975 ret.
get(start+2) = v.
z();
981template <
unsigned SX>
989 v.
x()*m.
get(1,0) + v.
y()*m.
get(1,1));
998 v.
x()*m.
get(1,0) + v.
y()*m.
get(1,1));
1007 v.
x()*m.
get(1,0) + v.
y()*m.
get(1,1) + v.
z()*m.
get(1,2),
1008 v.
x()*m.
get(2,0) + v.
y()*m.
get(2,1) + v.
z()*m.
get(2,2));
1017 v.
x()*m.
get(1,0) + v.
y()*m.
get(1,1) + v.
z()*m.
get(1,2),
1018 v.
x()*m.
get(2,0) + v.
y()*m.
get(2,1) + v.
z()*m.
get(2,2));
1024template <
unsigned SX>
1026 static_assert(SX <= 3);
1027 static_assert(SX >= 2);
1032 if constexpr (SX > 2) {
1059 (m.
get(0,1)+m.
get(1,0))*0.5,
1060 (m.
get(0,2)+m.
get(2,0))*0.5,
1061 (m.
get(1,2)+m.
get(2,1))*0.5);
1069 (m.
get(0,1)+m.
get(1,0))*0.5,
1084template <
class T,
unsigned SX>
1088template <
class T,
unsigned SX>
1100template <
class T,
unsigned SY>
1103template <
class T,
unsigned SY>
1106template <
class T,
unsigned SX>
1109template <
class T,
unsigned SX>
1112template <
class T,
unsigned SY>
1113constexpr void vectorToColumn(
Matrix<T,2,SY> &m,
const DVect2 &v,
unsigned col) { m(0,col) = v.x(); m(1,col) = v.y(); }
1115template <
class T,
unsigned SY>
1116constexpr void vectorToColumn(
Matrix<T,3,SY> &m,
const DVect3 &v,
unsigned col) { m(0,col) = v.x(); m(1,col) = v.y(); m(2,col) = v.z(); }
1118template <
class T,
unsigned SX,
unsigned SY>
1121template <
class T,
unsigned SX>
1122void vectorToRow(
Matrix<T,SX,2> &m,
const DVect2 &v,
unsigned row) { m(row,0) = v.x(); m(row,1) = v.y(); }
1124template <
class T,
unsigned SX>
1125void vectorToRow(
Matrix<T,SX,3> &m,
const DVect3 &v,
unsigned row) { m(row,0) = v.x(); m(row,1) = v.y(); m(row,2) = v.z(); }
1127template <
class T,
unsigned SX,
unsigned SY>
1130template <
class T,
unsigned SX,
unsigned SY>
1133 for (
unsigned i=0;i<SX;++i)
DMatrix is a Matrix that defaults to type double...
Definition matrix.h:741
constexpr DMatrix()
Default constructor, no data initialization.
Definition matrix.h:746
constexpr DMatrix(const DMatrix< SX, SY > &m)
Copy constructor.
Definition matrix.h:751
constexpr const DMatrix< SX, SY > & operator=(const DMatrix< SX, SY > &m)
Equality operator.
Definition matrix.h:755
constexpr DMatrix(const Matrix< double, SX, SY > &m)
Copy constructor, for Matrix.
Definition matrix.h:753
DSymMatrix is a SymMatrix that defaults to type double...
Definition matrix.h:763
DSymMatrix(const double &t)
Explicit contructor, initializes all elements to t.
Definition matrix.h:768
const DSymMatrix< SX > & operator=(const DSymMatrix< SX > &m)
Equality operator.
Definition matrix.h:774
DSymMatrix(const SymMatrix< double, SX > &m)
Copy constructor, for SymMatrix.
Definition matrix.h:772
DSymMatrix(const DSymMatrix< SX > &m)
Copy constructor.
Definition matrix.h:770
const DSymMatrix< SX > & operator=(const SymMatrix< double, SX > &m)
Equality operator, for Matrix.
Definition matrix.h:776
DSymMatrix()
Default constructor, no data initialization.
Definition matrix.h:766
DVMatrix is a double version of VMatrix.
Definition matrix.h:781
constexpr DVMatrix(const DVMatrix< S > &m)
Copy constructor.
Definition matrix.h:791
constexpr DVMatrix(const Matrix< double, S, 1 > &m)
Copy constructor, for Matrix class.
Definition matrix.h:793
constexpr const T & operator()(unsigned x) const
() operator access to const get(x)
Definition matrix.h:262
constexpr Matrix(const Matrix< T, SX, 1 > &m)
Copy constructor.
Definition matrix.h:245
constexpr const Matrix< T, SX, 1 > & operator*=(const T &t)
In-place multiplication by a scalar.
Definition matrix.h:273
Matrix< T, SX, 1 > operator/(const T &t) const
Binary scalar division operator.
Definition matrix.h:284
constexpr const T & get(unsigned x, unsigned y) const
Retrieve constant value at row x column y. Bounds checking is done in a debug compile.
Definition matrix.h:252
constexpr const Matrix< T, SX, 1 > & operator/=(const T &t)
In-place division by a scalar.
Definition matrix.h:275
constexpr T & get(unsigned x)
Retrieve value at row x. Bounds checking is done in a debug compile.
Definition matrix.h:258
Matrix< T, SX, 1 > operator-(const Matrix< T, SX, 1 > &m) const
Binary subtraction operator.
Definition matrix.h:280
Matrix< T, SX, SZ > operator*(const Matrix< T, 1, SZ > &m) const
Binary matrix multiplication operator – simplest naive approach.
Definition matrix.h:286
Matrix< T, 1, SX > transpose() const
returns the transposed matrix of this matrix
Definition matrix.h:318
void addBlock(const Matrix< T, SX2, 1 > &m, unsigned iSrc, unsigned iDst)
Adds a block to this matrix from matrix m using the block size BX from block indice iSrc to indice iD...
Definition matrix.h:300
constexpr const T & operator()(unsigned x, unsigned y) const
() operator access to const get(x,y)
Definition matrix.h:260
Matrix< T, SX, 1 > operator*(const T &t) const
Binary scalar multiplication operator.
Definition matrix.h:282
void addGenBlock(const Matrix< T, SX2, SY2 > &m, unsigned iSrc, unsigned jSrc, unsigned iDst, unsigned jDst)
Adds a block to this matrix from matrix m using the block size (BX,BY), from normal not block indices...
Definition matrix.h:304
void set(const T &t=T())
Sets all matrix elemnts to T.
Definition matrix.h:320
static Matrix< T, SX, 1 > identity()
Returns an identity matrix (or as close as you can get if not diagonal).
Definition matrix.h:323
constexpr T & operator()(unsigned x)
() operator access to get(x)
Definition matrix.h:266
T maxNorm() const
Returns the infinity norm of the matrix, or the maximum absolute magnitude of any element.
Definition matrix.h:316
constexpr const Matrix< T, SX, 1 > & operator=(const Matrix< T, SX, 1 > &m)
Equality operator.
Definition matrix.h:249
Matrix< T, SX, 1 > operator+(const Matrix< T, SX, 1 > &m) const
Binary addition operator.
Definition matrix.h:278
constexpr T & get(unsigned x, unsigned y)
Retrieve value at row x column y. Bounds checking is done in a debug compile.
Definition matrix.h:256
constexpr Matrix(const T &t)
Explicit constructor, initializes all elements to value t.
Definition matrix.h:243
constexpr const Matrix< T, SX, 1 > & operator-=(const Matrix< T, SX, 1 > &m)
In-place matrix subtraction.
Definition matrix.h:271
Matrix()
Default constructor, does nothing and no initialization.
Definition matrix.h:240
void addGenBlock(const Matrix< T, SX2, 1 > &m, unsigned iSrc, unsigned iDst)
Adds a block to this matrix from matrix m using the block size BX from normal non block indice iSrc t...
Definition matrix.h:310
constexpr const T & get(unsigned x) const
Retrieve constant value at row x. Bounds checking is done in a debug compile.
Definition matrix.h:254
void addBlock(const Matrix< T, SX2, SY2 > &m, unsigned iSrc, unsigned jSrc, unsigned iDst, unsigned jDst)
Adds a block to this matrix from matrix m using the block size (BX,BY), from block indices (iSrc,...
Definition matrix.h:296
constexpr const Matrix< T, SX, 1 > & operator+=(const Matrix< T, SX, 1 > &m)
In-place matrix addition.
Definition matrix.h:269
constexpr T & operator()(unsigned x, unsigned y)
() operator access to get(x,y)
Definition matrix.h:264
A template-based matrix class, size fixed at compile time. Defaults to symmetric sized matrix.
Definition matrix.h:22
Matrix< T, SX, SY > operator*(const T &t) const
Binary scalar multiplication operator.
Definition matrix.h:155
void addGenBlock(const Matrix< T, SX2, SY2 > &m, unsigned iSrc, unsigned jSrc, unsigned iDst, unsigned jDst)
Adds a block to this matrix from matrix m using the block size (BX,BY), from normal not block indices...
Definition matrix.h:197
Matrix< T, SX, SY > operator-(const Matrix< T, SX, SY > &m) const
Binary subtraction operator.
Definition matrix.h:153
constexpr const Matrix< T, SX, SY > & operator-=(const Matrix< T, SX, SY > &m)
In-place matrix subtraction.
Definition matrix.h:144
T maxNorm() const
Returns the infinity norm of the matrix, or the maximum absolute magnitude of any element.
Definition matrix.h:204
constexpr const Matrix< T, SX, SY > & operator=(const Matrix< T, SX, SY > &m)
Equality operator.
Definition matrix.h:126
constexpr T & operator()(unsigned x, unsigned y)
() operator access to get(x,y)
Definition matrix.h:139
POPWARNING constexpr Matrix(const T &t)
Explicit constructor, initializes all elements to value t.
Definition matrix.h:120
constexpr Matrix(const Matrix< T, SX, SY > &m)
Copy constructor.
Definition matrix.h:124
Matrix< T, SX, SY > operator/(const T &t) const
Binary scalar division operator.
Definition matrix.h:157
void addBlock(const Matrix< T, SX2, SY2 > &m, unsigned iSrc, unsigned jSrc, unsigned iDst, unsigned jDst)
Adds a block to this matrix from matrix m using the block size (BX,BY), from block indices (iSrc,...
Definition matrix.h:192
static constexpr Matrix< T, SX, SY > identity()
Returns an identity matrix (or as close as you can get if not diagonal).
Definition matrix.h:213
PUSHWARNING Matrix()
Default constructor, does nothing and no initialization.
Definition matrix.h:116
T trace() const
Return the trace of the matrix or the sum of the diagonal components. Works also if the matrix is not...
Definition matrix.h:208
constexpr const Matrix< T, SX, SY > & operator+=(const Matrix< T, SX, SY > &m)
In-place matrix addition.
Definition matrix.h:142
constexpr const Column operator[](unsigned y) const
Array access operator returns a Column helper class, which has it's own [] operator to access a colum...
Definition matrix.h:133
constexpr const T & get(unsigned x, unsigned y) const
Retrieve value at row x column y. Bounds checking is done in a debug compile.
Definition matrix.h:129
Matrix< T, SY, SX > transpose() const
Return the transpose of the matrix.
Definition matrix.h:206
constexpr T & get(unsigned x, unsigned y)
Retrieve value at row x column y. Bounds checking is done in a debug compile.
Definition matrix.h:131
constexpr const T & operator()(unsigned x, unsigned y) const
() operator access to get(x,y)
Definition matrix.h:137
constexpr Column operator[](unsigned y)
Array access operator returns a Column helper class, which has it's own [] operator to access a colum...
Definition matrix.h:135
constexpr void set(const T &t=T())
Set all entries in the matrix to t.
Definition matrix.h:210
constexpr const Matrix< T, SX, SY > & operator*=(const T &t)
In-place multiplication by a scalar.
Definition matrix.h:146
Matrix< T, SX, SY > operator+(const Matrix< T, SX, SY > &m) const
Binary addition operator.
Definition matrix.h:151
constexpr const Matrix< T, SX, SY > & operator/=(const T &t)
In-place division by a scalar.
Definition matrix.h:148
Matrix< T, SX, SZ > operator*(const Matrix< T, SY, SZ > &m) const
Binary matrix multiplication operator – simplest naive approach.
Definition matrix.h:160
A template-based symmetric matrix class, size fixed at compile time. This primitive template-based ma...
Definition matrix.h:332
SymMatrix< T, SX > operator/(const T &t) const
Binary scalar division operator for a symetric matrix.
Definition matrix.h:521
const T & operator()(unsigned x, unsigned y) const
() operator access to get(x,y)
Definition matrix.h:496
const SymMatrix< T, SX > & operator=(const SymMatrix< T, SX > &m)
Equality operator.
Definition matrix.h:485
SymMatrix(const T &t)
Explicit constructor, initializes all elements to value t.
Definition matrix.h:481
const SymMatrix< T, SX > & operator/=(const T &t)
In-place division by a scalar.
Definition matrix.h:507
SymMatrix< T, SX > operator-(const SymMatrix< T, SX > &m) const
Binary subtraction operator for a symetric matrix.
Definition matrix.h:514
const SymMatrix< T, SX > & operator*=(const T &t)
In-place multiplication by a scalar.
Definition matrix.h:505
T & get(unsigned x, unsigned y)
Retrieve value at row x column y. Bounds checking is done in a debug compile.
Definition matrix.h:490
SymMatrix(const SymMatrix< T, SX > &m)
Copy constructor.
Definition matrix.h:483
const SymMatrix< T, SX > & operator-=(const SymMatrix< T, SX > &m)
In-place matrix subtraction.
Definition matrix.h:503
Matrix< T, SX, SX > operator+(const Matrix< T, SX, SX > &m) const
Binary addition operator.
Definition matrix.h:512
const Column operator[](unsigned y) const
Array access operator returns a Column helper class, which has it's own [] operator to access a colum...
Definition matrix.h:492
void addBlock(const SymMatrix< T, SX2 > &m, unsigned iSrc, unsigned jSrc, unsigned iDst, unsigned jDst)
Adds a block to this matrix from matrix m using the block size (BX,BY), from block indices (iSrc,...
Definition matrix.h:568
void addGenBlock(const SymMatrix< T, SX2 > &m, unsigned iSrc, unsigned jSrc, unsigned iDst, unsigned jDst)
Adds a block to this matrix from matrix m using the block size (BX,BY), from normal not block indices...
Definition matrix.h:581
const T & get(unsigned x, unsigned y) const
Retrieve value at row x column y. Bounds checking is done in a debug compile.
Definition matrix.h:488
static SymMatrix< T, SX > identity()
Returns an identity matrix (or as close as you can get if not diagonal).
Definition matrix.h:602
void addBlock(const Matrix< T, SX2, SY2 > &m, unsigned iSrc, unsigned jSrc, unsigned iDst, unsigned jDst)
Adds a block to this matrix from matrix m using the block size (BX,BY), from block indices (iSrc,...
Definition matrix.h:564
SymMatrix< T, SX > operator*(const T &t) const
Binary scalar multiplication operator for a symetric matrix.
Definition matrix.h:519
T & operator()(unsigned x, unsigned y)
() operator access to get(x,y)
Definition matrix.h:498
Matrix< T, SX, SX > operator-(const Matrix< T, SX, SX > &m) const
Binary subtraction operator.
Definition matrix.h:516
SymMatrix< T, SX > transpose() const
Return the transpose of the matrix.
Definition matrix.h:593
Matrix< T, SX, SX > toMatrix() const
Returns its copy.
Definition matrix.h:599
const SymMatrix< T, SX > & operator+=(const SymMatrix< T, SX > &m)
In-place matrix addition.
Definition matrix.h:501
static SymMatrix< T, SX > fromMatrix(const Matrix< T, SX, SX > &m)
Assign from full matrix.
Definition matrix.h:604
SymMatrix< T, SX > operator+(const SymMatrix< T, SX > &m) const
Binary addition operator for a symetric matris.
Definition matrix.h:510
T trace() const
Return the trace of the matrix or the sum of the diagonal components. Works also if the matrix is not...
Definition matrix.h:595
Matrix< T, SX, SX > operator*(const SymMatrix< T, SX > &m) const
Binary matrix multiplication operator – simplest naive approach.
Definition matrix.h:523
Matrix< T, SX, SZ > operator*(const Matrix< T, SX, SZ > &m) const
Binary matrix multiplication operator – simplest naive approach.
Definition matrix.h:537
void addGenBlock(const Matrix< T, SX2, SY2 > &m, unsigned iSrc, unsigned jSrc, unsigned iDst, unsigned jDst)
Adds a block to this matrix from matrix m using the block size (BX,BY), from normal not block indices...
Definition matrix.h:572
T maxNorm() const
Returns the infinity norm of the matrix, or the maximum absolute magnitude of any element.
Definition matrix.h:591
void set(const T &t=T())
Sets all matrix elements to t.
Definition matrix.h:597
Column operator[](unsigned y)
Array access operator returns a Column helper class, which has it's own [] operator to access a colum...
Definition matrix.h:494
SymMatrix()
Default constructor, does nothing and no initialization.
Definition matrix.h:478
A symmetric 2nd order tensor.
Definition symtensor.h:22
const double & s23() const
Component access, note that s12 is equivalent to s21 (for instance).
Definition symtensor.h:50
const double & s22() const
Component access, note that s12 is equivalent to s21 (for instance).
Definition symtensor.h:46
const double & s33() const
Component access, note that s12 is equivalent to s21 (for instance).
Definition symtensor.h:47
const double & s13() const
Component access, note that s12 is equivalent to s21 (for instance).
Definition symtensor.h:49
const double & s11() const
Component access, note that s12 is equivalent to s21 (for instance).
Definition symtensor.h:45
const double & s12() const
Component access, note that s12 is equivalent to s21 (for instance).
Definition symtensor.h:48
A 1-Dimensional version of Matrix, to represent a vector.
Definition matrix.h:707
constexpr VMatrix(const Matrix< T, S, 1 > &m)
Copy contructor, works on Matrix if SY is 1.
Definition matrix.h:718
constexpr T & operator[](unsigned x)
1D version of array operator, which currently unfortunately eliminates [x][0] syntax on VMatrix (may ...
Definition matrix.h:731
constexpr const T & operator[](unsigned x) const
1D version of array operator, which currently unfortunately eliminates [x][0] syntax on VMatrix (may ...
Definition matrix.h:729
constexpr VMatrix(const VMatrix< T, S > &m)
Copy constructor.
Definition matrix.h:716
2D vector utility class.
Definition vect.h:34
constexpr const T & x() const
X component access.
Definition vect.h:58
constexpr const T & y() const
Y component access.
Definition vect.h:60
3D vector utility class.
Definition vect.h:163
constexpr const T & y() const
The y-component of the vector.
Definition vect.h:186
constexpr const T & x() const
The x-component of the vector.
Definition vect.h:184
constexpr const T & z() const
The z-component of the vector.
Definition vect.h:188
debug checked shorthand for std::numeric_limits<T>::
Definition limit.h:25
constexpr T determinant(const Matrix< T, 3, 3 > &mat)
Returns the determinant of a 3X3 Matrix.
Definition matrix.h:854
Vector2< T > columnToVector(const Matrix< T, 2, SY > &m, unsigned col)
returns in a Vector2<t> the column col from matrix Matrix<T,SX,2>
Definition matrix.h:1101
constexpr Matrix< T, 3, 3 > inverse(const Matrix< T, 3, 3 > &mat)
Returns the inverse of a 3X3 Matrix.
Definition matrix.h:874
constexpr Vector3< T > operator*(const Matrix< T, 3, 3 > &m, const Vector3< T > &v)
Definition matrix.h:1005
constexpr DVMatrix< SX > toDVMatrix(const DVect2 &v, unsigned start=0)
Definition matrix.h:967
Matrix< T, 3, 3 > outerProduct(const Vector3< T > &v1, const Vector3< T > &v2)
Creates a 3X3 Matrix from the outer product of two Vector3 types.
Definition matrix.h:822
constexpr VMatrix< T, 2 > toMatrix(const Vector2< T > &v)
Definition matrix.h:938
DSymMatrix< SX > toSymMatrix(const SymTensor &s)
Definition matrix.h:1025
constexpr VMatrix< T, 3 > toMatrix(const Vector3< T > &v)
Definition matrix.h:948
Vector3< T > toVector3(const VMatrix< T, SX > &m, unsigned start=0)
Converts a VMatrix to a Vector3, using three elements starting at index start.
Definition matrix.h:1089
SymTensor toSymTensor(const DSymMatrix< 3 > &m)
Definition matrix.h:1077
SymTensor toSymTensor(const DMatrix< 3, 3 > &m)
Definition matrix.h:1055
constexpr VMatrix< T, SX > toVMatrix(const Vector2< T > &v, unsigned start=0)
Converts a Vector2 into a VMatrix of arbitrary size, at an arbitrary starting index.
Definition matrix.h:958
constexpr Vector2< T > operator*(const Matrix< T, 2, 2 > &m, const Vector2< T > &v)
Definition matrix.h:987
constexpr Vector2< T > operator*(const SymMatrix< T, 2 > &m, const Vector2< T > &v)
Definition matrix.h:996
constexpr T determinant(const Matrix< T, 2, 2 > &mat)
Returns the determinant of a 2X2 Matrix.
Definition matrix.h:865
#define BASE_EXPORT
Definition basedef.h:24
Vector3< T > operator*(const SymMatrix< T, 3 > &m, const Vector3< T > &v)
Definition matrix.h:1015
Vector2< T > rowToVector(const Matrix< T, SX, 2 > &m, unsigned row)
returns in a Vector2<t> the row row from matrix Matrix<T,SX,2>
Definition matrix.h:1107
Matrix< T, 2, 2 > outerProduct(const Vector2< T > &v1, const Vector2< T > &v2)
Creates a 2X2 Matrix from the outer product of two Vector2 types.
Definition matrix.h:840
constexpr Matrix< T, 2, 2 > inverse(const Matrix< T, 2, 2 > &mat)
Returns the inverse of a 2X2 Matrix.
Definition matrix.h:902
Vector2< T > toVector2(const VMatrix< T, SX > &m, unsigned start=0)
Converts a VMatrix to a Vector2, using two elements starting at index start.
Definition matrix.h:1085
Vector2< T > toVector(const VMatrix< T, 2 > &m)
Converts a VMatrix to a Vector3, using three elements starting at index start.
Definition matrix.h:1093
A Symmetric 2nd order tensor.
constexpr Vector2< T > max(const Vector2< T > &v1, const Vector2< T > &v2)
Template specialization for max, min.
Definition vect.h:433
constexpr Vector2< T > min(const Vector2< T > &v1, const Vector2< T > &v2)
Template specialization for max, min.
Definition vect.h:435