21 template <
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); }
34 T &
operator[](
unsigned y) {
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>
193 addGenBlock<BX,BY,SX2,SY2>(m,iSrc*BX,jSrc*BY,iDst*BX,jDst*BY);
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; }
218 template <
class T,
unsigned SX,
unsigned SY>
233 template <
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) {
297 addGenBlock<BX,BY,SX2,SY2>(m,iSrc*BX,jSrc*BY,iDst*BX,jDst*BY);
301 addGenBlock<BX,SX2>(m,iSrc*BX,iDst*BX);
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; }
331 template <
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) {
565 addGenBlock<BX,BY,SX2,SY2>(m,iSrc*BX,jSrc*BY,iDst*BX,jDst*BY);
568 template <
unsigned BX,
unsigned BY,
unsigned SX2>
void addBlock(
const SymMatrix<T,SX2> &m,
unsigned iSrc,
unsigned jSrc,
unsigned iDst,
unsigned jDst) {
569 addGenBlock<BX,BY,SX2>(m,iSrc*BX,jSrc*BY,iDst*BX,jDst*BY);
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);
640 template <
class T,
unsigned SX,
unsigned SY,
unsigned I,
unsigned J,
unsigned K>
647 template <
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)];
655 template <
class T,
unsigned SX,
unsigned SY,
unsigned I,
unsigned J>
663 template <
class T,
unsigned SX,
unsigned SY,
unsigned I>
671 template <
class T,
unsigned SX,
unsigned SY,
unsigned I>
679 template <
class T,
unsigned SX,
unsigned SY>
687 template <
class T,
unsigned SX,
unsigned SY>
741 template <
unsigned SX,
unsigned SY=SX>
class DMatrix :
public Matrix<double,SX,SY> {
800 template <
class T,
unsigned S>
803 for (uint32 i=0;i<S;++i)
808 template <
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);
914 constexpr 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;
932 return {rm / det,det};
957 template <
class T,
unsigned SX>
960 ret.
get(start) = v.x();
961 ret.
get(start+1) = v.y();
967 template <
unsigned SX> constexpr
DVMatrix<SX> toDVMatrix(
const DVect2 &v,
unsigned start=0) {
return toVMatrix<double,SX>(v,start); }
970 template <
class T,
unsigned SX>
973 ret.
get(start) = v.x();
974 ret.
get(start+1) = v.y();
975 ret.
get(start+2) = v.z();
981 template <
unsigned SX>
988 Vector2<T> ret(v.x()*m.
get(0,0) + v.y()*m.
get(0,1),
989 v.x()*m.
get(1,0) + v.y()*m.
get(1,1));
997 Vector2<T> ret(v.x()*m.
get(0,0) + v.y()*m.
get(0,1),
998 v.x()*m.
get(1,0) + v.y()*m.
get(1,1));
1006 Vector3<T> ret(v.x()*m.
get(0,0) + v.y()*m.
get(0,1) + v.z()*m.
get(0,2),
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));
1016 Vector3<T> ret(v.x()*m.
get(0,0) + v.y()*m.
get(0,1) + v.z()*m.
get(0,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));
1024 template <
unsigned SX>
1026 static_assert(SX <= 3);
1027 static_assert(SX >= 2);
1029 ret.
get(0,0) = s.s11();
1030 ret.
get(0,1) = ret.
get(1,0) = s.s12();
1031 ret.
get(1,1) = s.s22();
1032 if constexpr (SX > 2) {
1033 ret.
get(0,2) = ret.
get(2,0) = s.s13();
1034 ret.
get(1,2) = ret.
get(2,1) = s.s23();
1035 ret.
get(2,2) = s.s33();
1056 SymTensor ret(m.
get(0,0),
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);
1066 SymTensor ret(m.
get(0,0),
1069 (m.
get(0,1)+m.
get(1,0))*0.5,
1078 SymTensor ret(m.
get(0,0),m.
get(1,1),m.
get(1,2),
1084 template <
class T,
unsigned SX>
1088 template <
class T,
unsigned SX>
1089 Vector3<T>
toVector3(
const VMatrix<T,SX> &m,
unsigned start=0) { Vector3<T> ret(m(start),m(start+1),m(start+2));
return ret; }
1100 template <
class T,
unsigned SY>
1103 template <
class T,
unsigned SY>
1106 template <
class T,
unsigned SX>
1109 template <
class T,
unsigned SX>
1112 template <
class T,
unsigned SY>
1113 constexpr
void vectorToColumn(
Matrix<T,2,SY> &m,
const DVect2 &v,
unsigned col) { m(0,col) = v.x(); m(1,col) = v.y(); }
1115 template <
class T,
unsigned SY>
1116 constexpr
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(); }
1118 template <
class T,
unsigned SX,
unsigned SY>
1121 template <
class T,
unsigned SX>
1122 void vectorToRow(
Matrix<T,SX,2> &m,
const DVect2 &v,
unsigned row) { m(row,0) = v.x(); m(row,1) = v.y(); }
1124 template <
class T,
unsigned SX>
1125 void 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(); }
1127 template <
class T,
unsigned SX,
unsigned SY>
1130 template <
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 DMatrix(const Matrix< double, SX, SY > &m)
Copy constructor, for Matrix.
Definition: matrix.h:753
constexpr const DMatrix< SX, SY > & operator=(const DMatrix< SX, SY > &m)
Equality operator.
Definition: matrix.h:755
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
DSymMatrix()
Default constructor, no data initialization.
Definition: matrix.h:766
const DSymMatrix< SX > & operator=(const SymMatrix< double, SX > &m)
Equality operator, for Matrix.
Definition: matrix.h:776
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
A specialization of the Matrix class for the case when SY=1.
Definition: matrix.h:234
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 multiplication operator.
Definition: matrix.h:282
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
constexpr T & operator()(unsigned x)
() operator access to get(x)
Definition: matrix.h:266
Matrix< T, SX, 1 > operator/(const T &t) const
Binary scalar division operator.
Definition: matrix.h:284
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
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
constexpr const Matrix< T, SX, 1 > & operator/=(const T &t)
In-place division by a scalar.
Definition: matrix.h:275
constexpr const T & operator()(unsigned x, unsigned y) const
() operator access to const get(x,y)
Definition: matrix.h:260
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
Matrix< T, SX, SZ > operator*(const Matrix< T, 1, SZ > &m) const
Binary matrix multiplication operator – simplest naive approach.
Definition: matrix.h:286
static Matrix< T, SX, 1 > identity()
Returns an identity matrix (or as close as you can get if not diagonal).
Definition: matrix.h:323
T maxNorm() const
Returns the infinity norm of the matrix, or the maximum absolute magnitude of any element.
Definition: matrix.h:316
constexpr const T & operator()(unsigned x) const
() operator access to const get(x)
Definition: matrix.h:262
constexpr const T & get(unsigned x,[[maybe_unused]] unsigned y) const
Retrieve constant value at row x column y. Bounds checking is done in a debug compile.
Definition: matrix.h:252
constexpr T & get(unsigned x,[[maybe_unused]] unsigned y)
Retrieve value at row x column y. Bounds checking is done in a debug compile.
Definition: matrix.h:256
constexpr const Matrix< T, SX, 1 > & operator+=(const Matrix< T, SX, 1 > &m)
In-place matrix addition.
Definition: matrix.h:269
constexpr const Matrix< T, SX, 1 > & operator-=(const Matrix< T, SX, 1 > &m)
In-place matrix subtraction.
Definition: matrix.h:271
Matrix< T, SX, 1 > operator-(const Matrix< T, SX, 1 > &m) const
Binary subtraction operator.
Definition: matrix.h:280
Matrix< T, 1, SX > transpose() const
returns the transposed matrix of this matrix
Definition: matrix.h:318
constexpr Matrix(const T &t)
Explicit constructor, initializes all elements to value t.
Definition: matrix.h:243
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 T & operator()(unsigned x, unsigned y)
() operator access to get(x,y)
Definition: matrix.h:264
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 T & get(unsigned x)
Retrieve value at row x. Bounds checking is done in a debug compile.
Definition: matrix.h:258
A template-based matrix class, size fixed at compile time. Defaults to symmetric sized matrix.
Definition: matrix.h:22
constexpr T & operator()(unsigned x, unsigned y)
() operator access to get(x,y)
Definition: matrix.h:139
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
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
T maxNorm() const
Returns the infinity norm of the matrix, or the maximum absolute magnitude of any element.
Definition: matrix.h:204
Matrix< T, SX, SZ > operator*(const Matrix< T, SY, SZ > &m) const
Binary matrix multiplication operator – simplest naive approach.
Definition: matrix.h:160
constexpr const T & operator()(unsigned x, unsigned y) const
() operator access to get(x,y)
Definition: matrix.h:137
constexpr Matrix(const Matrix< T, SX, SY > &m)
Copy constructor.
Definition: matrix.h:124
constexpr POPWARNING Matrix(const T &t)
Explicit constructor, initializes all elements to value t.
Definition: matrix.h:120
constexpr const Matrix< T, SX, SY > & operator-=(const Matrix< T, SX, SY > &m)
In-place matrix subtraction.
Definition: matrix.h:144
constexpr const Matrix< T, SX, SY > & operator=(const Matrix< T, SX, SY > &m)
Equality operator.
Definition: matrix.h:126
constexpr const Matrix< T, SX, SY > & operator+=(const Matrix< T, SX, SY > &m)
In-place matrix addition.
Definition: matrix.h:142
constexpr const Matrix< T, SX, SY > & operator/=(const T &t)
In-place division by a scalar.
Definition: matrix.h:148
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
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 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
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 Matrix< T, SX, SY > & operator*=(const T &t)
In-place multiplication by a scalar.
Definition: matrix.h:146
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
Matrix< T, SX, SY > operator-(const Matrix< T, SX, SY > &m) const
Binary subtraction operator.
Definition: matrix.h:153
Matrix< T, SX, SY > operator/(const T &t) const
Binary scalar division operator.
Definition: matrix.h:157
PUSHWARNING VSWARNING(26495) Matrix()
Default constructor, does nothing and no initialization.
Definition: matrix.h:115
Matrix< T, SX, SY > operator*(const T &t) const
Binary scalar multiplication operator.
Definition: matrix.h:155
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, SX, SY > operator+(const Matrix< T, SX, SY > &m) const
Binary addition operator.
Definition: matrix.h:151
A template-based symmetric matrix class, size fixed at compile time. This primitive template-based ma...
Definition: matrix.h:332
const SymMatrix< T, SX > & operator/=(const T &t)
In-place division by a scalar.
Definition: matrix.h:507
SymMatrix(const T &t)
Explicit constructor, initializes all elements to value t.
Definition: matrix.h:481
static SymMatrix< T, SX > fromMatrix(const Matrix< T, SX, SX > &m)
Assign from full matrix.
Definition: matrix.h:604
SymMatrix< T, SX > operator*(const T &t) const
Binary scalar multiplication operator for a symetric matrix.
Definition: matrix.h:519
Matrix< T, SX, SZ > operator*(const Matrix< T, SX, SZ > &m) const
Binary matrix multiplication operator – simplest naive approach.
Definition: matrix.h:537
const SymMatrix< T, SX > & operator*=(const T &t)
In-place multiplication by a scalar.
Definition: matrix.h:505
SymMatrix(const SymMatrix< T, SX > &m)
Copy constructor.
Definition: matrix.h:483
T & operator()(unsigned x, unsigned y)
() operator access to get(x,y)
Definition: matrix.h:498
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
SymMatrix< T, SX > transpose() const
Return the transpose of the matrix.
Definition: matrix.h:593
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 SymMatrix< T, SX > & operator+=(const SymMatrix< T, SX > &m)
In-place matrix addition.
Definition: matrix.h:501
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
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< 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 SymMatrix< T, SX > &m)
In-place matrix subtraction.
Definition: matrix.h:503
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
SymMatrix< T, SX > operator+(const SymMatrix< T, SX > &m) const
Binary addition operator for a symetric matris.
Definition: matrix.h:510
const SymMatrix< T, SX > & operator=(const SymMatrix< T, SX > &m)
Equality operator.
Definition: matrix.h:485
const T & operator()(unsigned x, unsigned y) const
() operator access to get(x,y)
Definition: matrix.h:496
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
Matrix< T, SX, SX > operator+(const Matrix< T, SX, SX > &m) const
Binary addition operator.
Definition: matrix.h:512
void set(const T &t=T())
Sets all matrix elements to t.
Definition: matrix.h:597
static SymMatrix< T, SX > identity()
Returns an identity matrix (or as close as you can get if not diagonal).
Definition: matrix.h:602
Matrix< T, SX, SX > toMatrix() const
Returns its copy.
Definition: matrix.h:599
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
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
Matrix< T, SX, SX > operator*(const SymMatrix< T, SX > &m) const
Binary matrix multiplication operator – simplest naive approach.
Definition: matrix.h:523
SymMatrix< T, SX > operator/(const T &t) const
Binary scalar division operator for a symetric matrix.
Definition: matrix.h:521
SymMatrix()
Default constructor, does nothing and no initialization.
Definition: matrix.h:478
Matrix< T, SX, SX > operator-(const Matrix< T, SX, SX > &m) const
Binary subtraction operator.
Definition: matrix.h:516
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
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
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
BASE_EXPORT DMatrix< 2, 2 > toMatrix2(const SymTensor &s)
Definition: matrix.cpp:16
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
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
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 DVMatrix< SX > toDVMatrix(const DVect2 &v, unsigned start=0)
Definition: matrix.h:967
constexpr VMatrix< T, 3 > toMatrix(const Vector3< T > &v)
Definition: matrix.h:948
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
SymTensor toSymTensor(const DSymMatrix< 3 > &m)
Definition: matrix.h:1077
SymTensor toSymTensor(const DMatrix< 3, 3 > &m)
Definition: matrix.h:1055
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
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
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 > 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
Vector3< T > operator*(const SymMatrix< T, 3 > &m, const Vector3< T > &v)
Definition: matrix.h:1015
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
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
A Symmetric 2nd order tensor.