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); }
34 T &operator[](
unsigned y) {
return m_.
get(x_,y); }
36 void operator=(
const Column &r)=
delete;
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); }
140 constexpr UVect2 size()
const {
return {SX,SY}; }
147 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; }
149 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; }
160 template <
unsigned SZ>
172 loopMultiply<SZ,SX>::execute(*
this,m,ret);
192 template <
unsigned BX,
unsigned BY,
unsigned SX2,
unsigned SY2>
194 addGenBlock<BX,BY,SX2,SY2>(m,iSrc*BX,jSrc*BY,iDst*BX,jDst*BY);
197 template <
unsigned BX,
unsigned BY,
unsigned SX2,
unsigned SY2>
199 for (
unsigned i=iSrc,
id=iDst;i<(iSrc+BX);i++,
id++)
200 for (
unsigned j=jSrc,jd=jDst;j<(jSrc+BY);j++,jd++)
201 get(
id,jd) += m(i,j);
205 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; }
209 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; }
211 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; }
212 constexpr T minEntry()
const {
double ret=
limits<T>::max();
for (
unsigned i=0;i<SX;++i)
for (
unsigned j=0;j<SY;++j) ret=std::min(ret,t_[i][j]);
return ret; }
213 constexpr T maxEntry()
const {
double ret=
limits<T>::lowest();
for (
unsigned i=0;i<SX;++i)
for (
unsigned j=0;j<SY;++j) ret=std::max(ret,t_[i][j]);
return ret; }
221template <
class T,
unsigned SX,
unsigned SY>
236template <
class T,
unsigned SX>
249 constexpr Matrix(
const std::array<T,SX> &a) {
for (uint32 i=0;i<SX;++i) t_[i] = a[i]; }
250 constexpr Matrix(
const std::initializer_list<T> l) { uint32 i=0;
for (
auto &x : l) { t_[i] = x; ++i; } }
255 constexpr const T &
get(
unsigned x,[[maybe_unused]]
unsigned y)
const { assert(x<SX); assert(!y);
return t_[x]; }
257 constexpr const T &
get(
unsigned x)
const { assert(x<SX);
return t_[x]; }
259 constexpr T &
get(
unsigned x,[[maybe_unused]]
unsigned y) { assert(x<SX); assert(!y);
return t_[x]; }
261 constexpr T &
get(
unsigned x) { assert(x<SX);
return t_[x]; }
263 constexpr const T &
operator()(
unsigned x,
unsigned y)
const {
return get(x,y); }
270 constexpr UVect2 size()
const {
return {SX,1}; }
292 for (
unsigned i=0;i<SX;++i)
293 for (
unsigned j=0;j<SZ;++j)
300 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) {
301 addGenBlock<BX,BY,SX2,SY2>(m,iSrc*BX,jSrc*BY,iDst*BX,jDst*BY);
305 addGenBlock<BX,SX2>(m,iSrc*BX,iDst*BX);
308 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) {
309 for (
unsigned i=iSrc,
id=iDst;i<(iSrc+BX);i++,
id++)
310 for (
unsigned j=jSrc,jd=jDst;j<(jSrc+BY);j++,jd++)
311 get(
id,jd) += m(i,j);
315 for (
unsigned i=iSrc,
id=iDst;i<(iSrc+BX);i++,
id++)
320 T
maxNorm()
const { T ret(0);
for (
unsigned i=0;i<SX;++i) ret = std::max(ret,std::abs(t_[i]));
return ret; }
324 void set(
const T &t=T()) {
for (
unsigned i=0;i<SX;++i) t_[i] = t; }
325 constexpr T minEntry()
const {
double ret=
limits<T>::max();
for (
unsigned i=0;i<SX;++i) ret=std::min(ret,t_[i]);
return ret; }
326 constexpr T maxEntry()
const {
double ret=
limits<T>::lowest();
for (
unsigned i=0;i<SX;++i) ret=std::max(ret,t_[i]);
return ret; }
337template <
class T,
unsigned SX>
346 Column(
const Column &r) : x_(r.x_), m_(r.m_) { }
348 const T &operator[](
unsigned y)
const {
return m_.get(x_,y); }
350 T &operator[](
unsigned y) {
return m_.get(x_,y); }
352 void operator=(
const Column &r);
357 template <
unsigned SZ,
unsigned I,
unsigned J,
unsigned K>
361 return l.t_[index(SX-I,SX-K)]*m.t_[SX-K][SZ-J] + innerLoop<SZ,I,J,K-1>::execute(l,m);
364 template <
unsigned SZ,
unsigned I,
unsigned J>
365 class innerLoop<SZ,I,J,1> {
368 return l.t_[index(SX-I,SX-1)]*m.t_[SX-1][SZ-J];
371 template <
unsigned I,
unsigned K>
372 class innerLoop<1,I,1,K> {
375 return l.t_[index(SX-I,SX-K)]*m.t_[SX-K] + innerLoop<1,I,1,K-1>::execute(l,m);
378 template <
unsigned I>
379 class innerLoop<1,I,1,1> {
382 return l.t_[index(SX-I,SX-1)]*m.t_[SX-1];
386 template <
unsigned SZ,
unsigned I,
unsigned J>
387 class loop2Multiply {
390 ret.t_[SX-I][SZ-J] = innerLoop<SZ,I,J,SX>::execute(l,m);
391 loop2Multiply<SZ,I,J-1>::execute(l,m,ret);
394 template <
unsigned SZ,
unsigned I>
395 class loop2Multiply<SZ,I,1> {
398 ret.t_[SX-I][SZ-1] = innerLoop<SZ,I,1,SX>::execute(l,m);
401 template <
unsigned I>
402 class loop2Multiply<1,I,1> {
405 ret.t_[SX-I] = innerLoop<1,I,1,SX>::execute(l,m);
409 template <
unsigned SZ,
unsigned I>
413 loop2Multiply<SZ,I,SZ>::execute(l,m,ret);
414 loopMultiply<SZ,I-1>::execute(l,m,ret);
417 template <
unsigned SZ>
418 class loopMultiply<SZ,1> {
421 loop2Multiply<SZ,1,SZ>::execute(l,m,ret);
427 template <
unsigned I,
unsigned J,
unsigned K>
431 return l.t_[index(SX-I,SX-K)]*m.t_[index(SX-K,SX-J)] + innerLoopS<I,J,K-1>::execute(l,m);
435 template <
unsigned I,
unsigned J>
436 class innerLoopS<I,J,1> {
439 return l.t_[index(SX-I,SX-1)]*m.t_[index(SX-1,SX-J)];
445 template <
unsigned I,
unsigned J>
446 class loop2MultiplyS {
449 ret.t_[SX-I][SX-J] = innerLoopS<I,J,SX>::execute(l,m);
450 loop2MultiplyS<I,J-1>::execute(l,m,ret);
453 template <
unsigned I>
454 class loop2MultiplyS<I,1> {
457 ret.t_[SX-I][SX-1] = innerLoopS<I,1,SX>::execute(l,m);
461 template <
unsigned I>
462 class loopMultiplyS {
465 loop2MultiplyS<I,SX>::execute(l,m,ret);
466 loopMultiplyS<I-1>::execute(l,m,ret);
471 class loopMultiplyS<1> {
474 loop2MultiplyS<1,SX>::execute(l,m,ret);
494 const T &
get(
unsigned x,
unsigned y)
const {
return t_[index(x,y)]; }
496 T &
get(
unsigned x,
unsigned y) {
return t_[index(x,y)]; }
498 const Column
operator[](
unsigned y)
const {
return Column(y,*
this); }
505 constexpr UVect2 size()
const {
return {SX,SX}; }
532 loopMultiplyS<SX>::execute(*
this,m,ret);
546 loopMultiply<SZ,SX>::execute(*
this,m,ret);
571 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) {
572 addGenBlock<BX,BY,SX2,SY2>(m,iSrc*BX,jSrc*BY,iDst*BX,jDst*BY);
575 template <
unsigned BX,
unsigned BY,
unsigned SX2>
void addBlock(
const SymMatrix<T,SX2> &m,
unsigned iSrc,
unsigned jSrc,
unsigned iDst,
unsigned jDst) {
576 addGenBlock<BX,BY,SX2>(m,iSrc*BX,jSrc*BY,iDst*BX,jDst*BY);
579 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) {
580 for (
unsigned i=iSrc,
id=iDst;i<(iSrc+BX);i++,
id++) {
581 for (
unsigned j=jSrc,jd=jDst;j<(jSrc+BY);j++,jd++) {
583 get(
id,jd) += m(i,j);
588 template <
unsigned BX,
unsigned BY,
unsigned SX2>
void addGenBlock(
const SymMatrix<T,SX2> &m,
unsigned iSrc,
unsigned jSrc,
unsigned iDst,
unsigned jDst) {
589 for (
unsigned i=iSrc,
id=iDst;i<(iSrc+BX);i++,
id++) {
590 for (
unsigned j=jSrc,jd=jDst;j<(jSrc+BY);j++,jd++) {
592 get(
id,jd) += m(i,j);
598 T
maxNorm()
const { T ret(0);
for (
unsigned i=0;i<len_;++i) ret = std::max(std::abs(t_[i]),ret);
return ret; }
602 T
trace()
const { T tt = t_[0];
for (
unsigned i=1; i<SX; ++i) tt +=
get(i,i);
return tt; }
604 void set(
const T &t=T()) {
for (
unsigned i=0;i<len_;++i) t_[i] = t; }
605 constexpr T minEntry()
const {
double ret=
limits<T>::max();
for (
unsigned i=0;i<len_;++i) ret=std::min(ret,t_[i]);
return ret; }
606 constexpr T maxEntry()
const {
double ret=
limits<T>::lowest();
for (
unsigned i=0;i<len_;++i) ret=std::max(ret,t_[i]);
return ret; }
618 for (
unsigned i=0;i<SX;++i) {
620 for (
unsigned j=i+1;j<SX;++j) {
621 ret(i,j) = (m(i,j) + m(j,i)) * 0.5;
623 maxdif = std::max(std::abs(ret(i,j) - m(i,j)),maxdif);
633 static constexpr unsigned len_ = (SX*SX + SX) / 2;
634 static constexpr unsigned indexConst_ = 1 + 2*SX;
635 static constexpr unsigned index(
unsigned x,
unsigned y) {
636 unsigned x2 = x > y ? y : x;
637 unsigned y2 = x > y ? x : y;
638 unsigned i = (((indexConst_-x2)*x2)/2) + (y2-x2);
649template <
class T,
unsigned SX,
unsigned SY,
unsigned I,
unsigned J,
unsigned K>
656template <
class T,
unsigned SX,
unsigned SY,
unsigned I,
unsigned J>
660 return l.t_[SX-I][SY-1]*m.t_[m.index(SY-1,SY-J)];
664template <
class T,
unsigned SX,
unsigned SY,
unsigned I,
unsigned J>
672template <
class T,
unsigned SX,
unsigned SY,
unsigned I>
680template <
class T,
unsigned SX,
unsigned SY,
unsigned I>
688template <
class T,
unsigned SX,
unsigned SY>
696template <
class T,
unsigned SX,
unsigned SY>
719 using Matrix<T,S,1>::operator=;
720 using iterator = T *;
721 using const_iterator =
const T *;
736 iterator begin() {
return this->t_; }
737 iterator end() {
return this->t_+S; }
738 const_iterator begin()
const {
return this->t_; }
739 const_iterator end()
const {
return this->t_+S; }
758template <
unsigned SX,
unsigned SY=SX>
class DMatrix :
public Matrix<double,SX,SY> {
761 using Matrix<double,SX,SY>::operator=;
801 using VMatrix<double,S>::operator=;
817template <
class T,
unsigned S>
820 for (uint32 i=0;i<S;++i)
826double innerProduct(
const VMatrix<T,3> &v1,
const DVect3 &v2) {
828 for (
unsigned i=0;i<3;++i)
834double innerProduct(
const VMatrix<T,2> &v1,
const DVect2 &v2) {
836 for (
unsigned i=0;i<2;++i)
841template <
class T,
unsigned S>
844 for (uint32 i=0;i<S;++i) {
845 for (uint32 j=0;j<S;++j)
846 ret(i,j) = v1(i) * v2(j);
857 ret.
get(0,0) = v1.
x() * v2.
x();
858 ret.
get(0,1) = v1.
x() * v2.
y();
859 ret.
get(0,2) = v1.
x() * v2.
z();
860 ret.
get(1,0) = v1.
y() * v2.
x();
861 ret.
get(1,1) = v1.
y() * v2.
y();
862 ret.
get(1,2) = v1.
y() * v2.
z();
863 ret.
get(2,0) = v1.
z() * v2.
x();
864 ret.
get(2,1) = v1.
z() * v2.
y();
865 ret.
get(2,2) = v1.
z() * v2.
z();
875 ret.
get(0,0) = v1.
x() * v2.
x();
876 ret.
get(0,1) = v1.
x() * v2.
y();
877 ret.
get(1,0) = v1.
y() * v2.
x();
878 ret.
get(1,1) = v1.
y() * v2.
y();
888 T t = mat.
get(0,0) * (mat.
get(1,1) * mat.
get(2,2) - mat.
get(2,1) * mat.
get(1,2));
889 t -= mat.
get(1,0) * (mat.
get(0,1) * mat.
get(2,2) - mat.
get(2,1) * mat.
get(0,2));
890 t += mat.
get(2,0) * (mat.
get(0,1) * mat.
get(1,2) - mat.
get(1,1) * mat.
get(0,2));
899 return mat.
get(0,0) * mat.
get(1,1) - mat.
get(0,1) * mat.
get(1,0);
909 const T a11 = mat(0,0), a21 = mat(1,0), a31 = mat(2,0);
910 const T a12 = mat(0,1), a22 = mat(1,1), a32 = mat(2,1);
911 const T a13 = mat(0,2), a23 = mat(1,2), a33 = mat(2,2);
913 Matrix<T,3,3> rm = {{ a22*a33 - a32*a23,-a12*a33 + a32*a13, a12*a23 - a22*a13},
914 {-a21*a33 + a31*a23, a11*a33 - a31*a13,-a11*a23 + a21*a13},
915 { a21*a32 - a31*a22,-a11*a32 + a31*a12, a11*a22 - a21*a12}};
927 return rm / determinant(mat);
937 rm.
get(0,0) = mat.
get(1,1);
938 rm.
get(1,1) = mat.
get(0,0);
939 rm.
get(0,1) = mat.
get(0,1)*(-1);
940 rm.
get(1,0) = mat.
get(1,0)*(-1);
942 return rm / determinant(mat);
947constexpr std::tuple<Matrix<T,3,3>,
double> inverseDet(
const Matrix<T,3,3> &mat) {
949 const T &a11 = mat(0,0), a21 = mat(1,0), a31 = mat(2,0);
950 const T &a12 = mat(0,1), a22 = mat(1,1), a32 = mat(2,1);
951 const T &a13 = mat(0,2), a23 = mat(1,2), a33 = mat(2,2);
954 rm.
get(0,0) = a22*a33 - a32*a23;
955 rm.
get(1,0) = -a21*a33 + a31*a23;
956 rm.
get(2,0) = a21*a32 - a31*a22;
957 rm.
get(0,1) = -a12*a33 + a32*a13;
958 rm.
get(1,1) = a11*a33 - a31*a13;
959 rm.
get(2,1) = -a11*a32 + a31*a12;
960 rm.
get(0,2) = a12*a23 - a22*a13;
961 rm.
get(1,2) = -a11*a23 + a21*a13;
962 rm.
get(2,2) = a11*a22 - a21*a12;
964 double det = determinant(mat);
965 return {rm / det,det};
990template <
class T,
unsigned SX>
993 ret.
get(start) = v.
x();
994 ret.
get(start+1) = v.
y();
1000template <
unsigned SX>
constexpr DVMatrix<SX> toDVMatrix(
const DVect2 &v,
unsigned start=0) {
return toVMatrix<double,SX>(v,start); }
1003template <
class T,
unsigned SX>
1006 ret.
get(start) = v.
x();
1007 ret.
get(start+1) = v.
y();
1008 ret.
get(start+2) = v.
z();
1014template <
unsigned SX>
1022 v.
x()*m.
get(1,0) + v.
y()*m.
get(1,1));
1031 v.
x()*m.
get(1,0) + v.
y()*m.
get(1,1));
1040 v.
x()*m.
get(1,0) + v.
y()*m.
get(1,1) + v.
z()*m.
get(1,2),
1041 v.
x()*m.
get(2,0) + v.
y()*m.
get(2,1) + v.
z()*m.
get(2,2));
1050 v.
x()*m.
get(1,0) + v.
y()*m.
get(1,1) + v.
z()*m.
get(1,2),
1051 v.
x()*m.
get(2,0) + v.
y()*m.
get(2,1) + v.
z()*m.
get(2,2));
1094 (m.
get(0,1)+m.
get(1,0))*0.5,
1095 (m.
get(0,2)+m.
get(2,0))*0.5,
1096 (m.
get(1,2)+m.
get(2,1))*0.5);
1104 (m.
get(0,1)+m.
get(1,0))*0.5,
1119template <
class T,
unsigned SX>
1123template <
class T,
unsigned SX>
1135template <
class T,
unsigned SY>
1138template <
class T,
unsigned SY>
1141template <
class T,
unsigned SX>
1144template <
class T,
unsigned SX>
1147template <
class T,
unsigned SY>
1148constexpr void vectorToColumn(
Matrix<T,2,SY> &m,
const DVect2 &v,
unsigned col) { m(0,col) = v.x(); m(1,col) = v.y(); }
1150template <
class T,
unsigned SY>
1151constexpr 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(); }
1153template <
class T,
unsigned SX,
unsigned SY>
1156template <
class T,
unsigned SX>
1157void vectorToRow(
Matrix<T,SX,2> &m,
const DVect2 &v,
unsigned row) { m(row,0) = v.x(); m(row,1) = v.y(); }
1159template <
class T,
unsigned SX>
1160void 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(); }
1162template <
class T,
unsigned SX,
unsigned SY>
1165template <
class T,
unsigned SX,
unsigned SY>
1168 for (
unsigned i=0;i<SX;++i)
1175 ret[0] = s.
s11()*v[0] + s.
s12()*v[1] + s.
s13()*v[2];
1176 ret[1] = s.
s12()*v[0] + s.
s22()*v[1] + s.
s23()*v[2];
1177 ret[2] = s.
s13()*v[0] + s.
s23()*v[1] + s.
s33()*v[2];
1183 ret[0] = s.
s11()*v[0] + s.
s12()*v[1];
1184 ret[1] = s.
s12()*v[0] + s.
s22()*v[1];
DMatrix is a Matrix that defaults to type double...
Definition matrix.h:758
constexpr DMatrix()
Default constructor, no data initialization.
Definition matrix.h:763
constexpr DMatrix(const DMatrix< SX, SY > &m)
Copy constructor.
Definition matrix.h:768
constexpr const DMatrix< SX, SY > & operator=(const DMatrix< SX, SY > &m)
Equality operator.
Definition matrix.h:772
constexpr DMatrix(const Matrix< double, SX, SY > &m)
Copy constructor, for Matrix.
Definition matrix.h:770
DSymMatrix is a SymMatrix that defaults to type double...
Definition matrix.h:780
DSymMatrix(const double &t)
Explicit contructor, initializes all elements to t.
Definition matrix.h:785
const DSymMatrix< SX > & operator=(const DSymMatrix< SX > &m)
Equality operator.
Definition matrix.h:791
DSymMatrix(const SymMatrix< double, SX > &m)
Copy constructor, for SymMatrix.
Definition matrix.h:789
DSymMatrix(const DSymMatrix< SX > &m)
Copy constructor.
Definition matrix.h:787
const DSymMatrix< SX > & operator=(const SymMatrix< double, SX > &m)
Equality operator, for Matrix.
Definition matrix.h:793
DSymMatrix()
Default constructor, no data initialization.
Definition matrix.h:783
DVMatrix is a double version of VMatrix.
Definition matrix.h:798
constexpr DVMatrix(const DVMatrix< S > &m)
Copy constructor.
Definition matrix.h:808
constexpr DVMatrix(const Matrix< double, S, 1 > &m)
Copy constructor, for Matrix class.
Definition matrix.h:810
constexpr const T & operator()(unsigned x) const
() operator access to const get(x)
Definition matrix.h:265
constexpr Matrix(const Matrix< T, SX, 1 > &m)
Copy constructor.
Definition matrix.h:248
constexpr const Matrix< T, SX, 1 > & operator*=(const T &t)
In-place multiplication by a scalar.
Definition matrix.h:277
Matrix< T, SX, 1 > operator/(const T &t) const
Binary scalar division operator.
Definition matrix.h:288
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:255
constexpr const Matrix< T, SX, 1 > & operator/=(const T &t)
In-place division by a scalar.
Definition matrix.h:279
constexpr T & get(unsigned x)
Retrieve value at row x. Bounds checking is done in a debug compile.
Definition matrix.h:261
Matrix< T, SX, 1 > operator-(const Matrix< T, SX, 1 > &m) const
Binary subtraction operator.
Definition matrix.h:284
Matrix< T, SX, SZ > operator*(const Matrix< T, 1, SZ > &m) const
Binary matrix multiplication operator – simplest naive approach.
Definition matrix.h:290
Matrix< T, 1, SX > transpose() const
returns the transposed matrix of this matrix
Definition matrix.h:322
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:304
constexpr const T & operator()(unsigned x, unsigned y) const
() operator access to const get(x,y)
Definition matrix.h:263
Matrix< T, SX, 1 > operator*(const T &t) const
Binary scalar multiplication operator.
Definition matrix.h:286
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:308
void set(const T &t=T())
Sets all matrix elemnts to T.
Definition matrix.h:324
static Matrix< T, SX, 1 > identity()
Returns an identity matrix (or as close as you can get if not diagonal).
Definition matrix.h:329
constexpr T & operator()(unsigned x)
() operator access to get(x)
Definition matrix.h:269
T maxNorm() const
Returns the infinity norm of the matrix, or the maximum absolute magnitude of any element.
Definition matrix.h:320
constexpr const Matrix< T, SX, 1 > & operator=(const Matrix< T, SX, 1 > &m)
Equality operator.
Definition matrix.h:252
Matrix< T, SX, 1 > operator+(const Matrix< T, SX, 1 > &m) const
Binary addition operator.
Definition matrix.h:282
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:259
constexpr Matrix(const T &t)
Explicit constructor, initializes all elements to value t.
Definition matrix.h:246
constexpr const Matrix< T, SX, 1 > & operator-=(const Matrix< T, SX, 1 > &m)
In-place matrix subtraction.
Definition matrix.h:275
Matrix()
Default constructor, does nothing and no initialization.
Definition matrix.h:243
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:314
constexpr const T & get(unsigned x) const
Retrieve constant value at row x. Bounds checking is done in a debug compile.
Definition matrix.h:257
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:300
constexpr const Matrix< T, SX, 1 > & operator+=(const Matrix< T, SX, 1 > &m)
In-place matrix addition.
Definition matrix.h:273
constexpr T & operator()(unsigned x, unsigned y)
() operator access to get(x,y)
Definition matrix.h:267
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:156
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:198
Matrix< T, SX, SY > operator-(const Matrix< T, SX, SY > &m) const
Binary subtraction operator.
Definition matrix.h:154
constexpr const Matrix< T, SX, SY > & operator-=(const Matrix< T, SX, SY > &m)
In-place matrix subtraction.
Definition matrix.h:145
T maxNorm() const
Returns the infinity norm of the matrix, or the maximum absolute magnitude of any element.
Definition matrix.h:205
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:158
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:193
static constexpr Matrix< T, SX, SY > identity()
Returns an identity matrix (or as close as you can get if not diagonal).
Definition matrix.h:216
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:209
constexpr const Matrix< T, SX, SY > & operator+=(const Matrix< T, SX, SY > &m)
In-place matrix addition.
Definition matrix.h:143
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:207
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:211
constexpr const Matrix< T, SX, SY > & operator*=(const T &t)
In-place multiplication by a scalar.
Definition matrix.h:147
Matrix< T, SX, SY > operator+(const Matrix< T, SX, SY > &m) const
Binary addition operator.
Definition matrix.h:152
constexpr const Matrix< T, SX, SY > & operator/=(const T &t)
In-place division by a scalar.
Definition matrix.h:149
Matrix< T, SX, SZ > operator*(const Matrix< T, SY, SZ > &m) const
Binary matrix multiplication operator – simplest naive approach.
Definition matrix.h:161
A template-based symmetric matrix class, size fixed at compile time. This primitive template-based ma...
Definition matrix.h:338
SymMatrix< T, SX > operator/(const T &t) const
Binary scalar division operator for a symetric matrix.
Definition matrix.h:528
const T & operator()(unsigned x, unsigned y) const
() operator access to get(x,y)
Definition matrix.h:502
const SymMatrix< T, SX > & operator=(const SymMatrix< T, SX > &m)
Equality operator.
Definition matrix.h:491
SymMatrix(const T &t)
Explicit constructor, initializes all elements to value t.
Definition matrix.h:487
const SymMatrix< T, SX > & operator/=(const T &t)
In-place division by a scalar.
Definition matrix.h:514
SymMatrix< T, SX > operator-(const SymMatrix< T, SX > &m) const
Binary subtraction operator for a symetric matrix.
Definition matrix.h:521
const SymMatrix< T, SX > & operator*=(const T &t)
In-place multiplication by a scalar.
Definition matrix.h:512
T & get(unsigned x, unsigned y)
Retrieve value at row x column y. Bounds checking is done in a debug compile.
Definition matrix.h:496
SymMatrix(const SymMatrix< T, SX > &m)
Copy constructor.
Definition matrix.h:489
const SymMatrix< T, SX > & operator-=(const SymMatrix< T, SX > &m)
In-place matrix subtraction.
Definition matrix.h:510
Matrix< T, SX, SX > operator+(const Matrix< T, SX, SX > &m) const
Binary addition operator.
Definition matrix.h:519
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:498
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:575
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:588
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:494
static SymMatrix< T, SX > identity()
Returns an identity matrix (or as close as you can get if not diagonal).
Definition matrix.h:611
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:571
SymMatrix< T, SX > operator*(const T &t) const
Binary scalar multiplication operator for a symetric matrix.
Definition matrix.h:526
T & operator()(unsigned x, unsigned y)
() operator access to get(x,y)
Definition matrix.h:504
Matrix< T, SX, SX > operator-(const Matrix< T, SX, SX > &m) const
Binary subtraction operator.
Definition matrix.h:523
SymMatrix< T, SX > transpose() const
Return the transpose of the matrix.
Definition matrix.h:600
Matrix< T, SX, SX > toMatrix() const
Returns its copy.
Definition matrix.h:608
const SymMatrix< T, SX > & operator+=(const SymMatrix< T, SX > &m)
In-place matrix addition.
Definition matrix.h:508
static SymMatrix< T, SX > fromMatrix(const Matrix< T, SX, SX > &m)
Assign from full matrix.
Definition matrix.h:613
SymMatrix< T, SX > operator+(const SymMatrix< T, SX > &m) const
Binary addition operator for a symetric matris.
Definition matrix.h:517
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:602
Matrix< T, SX, SX > operator*(const SymMatrix< T, SX > &m) const
Binary matrix multiplication operator – simplest naive approach.
Definition matrix.h:530
Matrix< T, SX, SZ > operator*(const Matrix< T, SX, SZ > &m) const
Binary matrix multiplication operator – simplest naive approach.
Definition matrix.h:544
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:579
T maxNorm() const
Returns the infinity norm of the matrix, or the maximum absolute magnitude of any element.
Definition matrix.h:598
void set(const T &t=T())
Sets all matrix elements to t.
Definition matrix.h:604
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:500
SymMatrix()
Default constructor, does nothing and no initialization.
Definition matrix.h:484
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:716
constexpr VMatrix(const Matrix< T, S, 1 > &m)
Copy contructor, works on Matrix if SY is 1.
Definition matrix.h:730
constexpr T & operator[](unsigned x)
1D version of array operator, which currently unfortunately eliminates [x][0] syntax on VMatrix (may ...
Definition matrix.h:748
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:746
constexpr VMatrix(const VMatrix< T, S > &m)
Copy constructor.
Definition matrix.h:728
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:887
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:1136
constexpr Matrix< T, 3, 3 > inverse(const Matrix< T, 3, 3 > &mat)
Returns the inverse of a 3X3 Matrix.
Definition matrix.h:907
constexpr Vector3< T > operator*(const Matrix< T, 3, 3 > &m, const Vector3< T > &v)
Definition matrix.h:1038
constexpr DVMatrix< SX > toDVMatrix(const DVect2 &v, unsigned start=0)
Definition matrix.h:1000
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:855
constexpr VMatrix< T, 2 > toMatrix(const Vector2< T > &v)
Definition matrix.h:971
constexpr VMatrix< T, 3 > toMatrix(const Vector3< T > &v)
Definition matrix.h:981
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:1124
SymTensor toSymTensor(const DSymMatrix< 3 > &m)
Definition matrix.h:1112
SymTensor toSymTensor(const DMatrix< 3, 3 > &m)
Definition matrix.h:1090
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:991
constexpr Vector2< T > operator*(const Matrix< T, 2, 2 > &m, const Vector2< T > &v)
Definition matrix.h:1020
constexpr Vector2< T > operator*(const SymMatrix< T, 2 > &m, const Vector2< T > &v)
Definition matrix.h:1029
constexpr T determinant(const Matrix< T, 2, 2 > &mat)
Returns the determinant of a 2X2 Matrix.
Definition matrix.h:898
#define BASE_EXPORT
Definition basedef.h:24
Vector3< T > operator*(const SymMatrix< T, 3 > &m, const Vector3< T > &v)
Definition matrix.h:1048
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:1142
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:873
constexpr Matrix< T, 2, 2 > inverse(const Matrix< T, 2, 2 > &mat)
Returns the inverse of a 2X2 Matrix.
Definition matrix.h:935
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:1120
Vector2< T > toVector(const VMatrix< T, 2 > &m)
Converts a VMatrix to a Vector3, using three elements starting at index start.
Definition matrix.h:1128
A Symmetric 2nd order tensor.