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);
 
  117    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]; }
 
  118    constexpr Matrix(
const std::initializer_list<std::initializer_list<T>> l);
 
  121    constexpr const T & 
get(
unsigned x,
unsigned y)
 const { assert(x<SX);  assert(y<SY); 
return t_[x][y]; }
 
  123    constexpr T &       
get(
unsigned x,
unsigned y) { assert(x<SX);  assert(y<SY); 
return t_[x][y]; }
 
  127    constexpr Column       
operator[](
unsigned y) { 
return Column(y,*
this); }
 
  129    constexpr const T & 
operator()(
unsigned x,
unsigned y)
 const { 
return get(x,y); }
 
  132    constexpr UVect2 size()
 const { 
return {SX,SY}; }
 
  139    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; }
 
  141    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; }
 
  152    template <
unsigned SZ>
 
  156        loopMultiply<SZ,SX>::execute(*
this,m,ret);
 
 
  162    template <
unsigned BX,
unsigned BY,
unsigned SX2,
unsigned SY2>
 
  164        addGenBlock<BX,BY,SX2,SY2>(m,iSrc*BX,jSrc*BY,iDst*BX,jDst*BY);
 
 
  167    template <
unsigned BX,
unsigned BY,
unsigned SX2,
unsigned SY2>
 
  169        for (
unsigned i=iSrc,
id=iDst;i<(iSrc+BX);i++,
id++)
 
  170            for (
unsigned j=jSrc,jd=jDst;j<(jSrc+BY);j++,jd++)
 
  171                get(
id,jd) += m(i,j);
 
 
  175    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; }
 
  179    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; }
 
  181    constexpr void set(
const T &t=T{}) { std::fill(&t_[0][0], &t_[0][0]+(SX*SY),t); }
 
  182    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; }
 
  183    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; }
 
 
  191template <
class T,
unsigned SX,
unsigned SY>
 
  206template <
class T,
unsigned SX>
 
  216    constexpr Matrix(
const std::array<T,SX> &a) { 
for (uint32 i=0;i<SX;++i) t_[i] = a[i]; }
 
  217    constexpr Matrix(
const std::initializer_list<T> l) { uint32 i=0; 
for (
auto &x : l) { t_[i] = x; ++i; } }
 
  220    constexpr const T & 
get(
unsigned x,[[maybe_unused]] 
unsigned y)
 const { assert(x<SX);  assert(!y); 
return t_[x]; }
 
  222    constexpr const T & 
get(
unsigned x)
 const { assert(x<SX);  
return t_[x]; }
 
  224    constexpr T &       
get(
unsigned x,[[maybe_unused]] 
unsigned y) { assert(x<SX);  assert(!y); 
return t_[x]; }
 
  226    constexpr T &       
get(
unsigned x) { assert(x<SX); 
return t_[x]; }
 
  228    constexpr const T & 
operator()(
unsigned x,
unsigned y)
 const { 
return get(x,y); }
 
  231    constexpr const T & 
operator[](
unsigned x)
 const { 
return get(x); }
 
  237    constexpr UVect2 size()
 const { 
return {SX,1}; }
 
  259        for (
unsigned i=0;i<SX;++i) 
 
  260            for (
unsigned j=0;j<SZ;++j) 
 
 
  267    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) {
 
  268        addGenBlock<BX,BY,SX2,SY2>(m,iSrc*BX,jSrc*BY,iDst*BX,jDst*BY);
 
 
  272        addGenBlock<BX,SX2>(m,iSrc*BX,iDst*BX);
 
 
  275    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) {
 
  276        for (
unsigned i=iSrc,
id=iDst;i<(iSrc+BX);i++,
id++)
 
  277            for (
unsigned j=jSrc,jd=jDst;j<(jSrc+BY);j++,jd++)
 
  278                get(
id,jd) += m(i,j);
 
 
  282        for (
unsigned i=iSrc,
id=iDst;i<(iSrc+BX);i++,
id++)
 
 
  287    T 
maxNorm()
 const { T ret(0);  
for (
unsigned i=0;i<SX;++i) ret = std::max(ret,std::abs(t_[i]));  
return ret; }
 
  291    constexpr void set(
const T &t=T{}) { std::fill(&t_[0],&t_[0]+SX,t); }
 
  292    constexpr T minEntry()
 const { 
double ret=
limits<T>::max(); 
for (
unsigned i=0;i<SX;++i) ret=std::min(ret,t_[i]);  
return ret; }
 
  293    constexpr T maxEntry()
 const { 
double ret=
limits<T>::lowest(); 
for (
unsigned i=0;i<SX;++i) ret=std::max(ret,t_[i]);  
return ret; }
 
 
  304template <
class T,
unsigned SX>
 
  313        Column(
const Column &r) : x_(r.x_), m_(r.m_) { }
 
  315        const T &operator[](
unsigned y)
 const { 
return m_.get(x_,y); }
 
  317        T &operator[](
unsigned y) { 
return m_.get(x_,y); }
 
  319        void operator=(
const Column &r); 
 
  324    template <
unsigned SZ,
unsigned I,
unsigned J,
unsigned K>
 
  328            return l.t_[index(SX-I,SX-K)]*m.t_[SX-K][SZ-J] + innerLoop<SZ,I,J,K-1>::execute(l,m);
 
  331    template <
unsigned SZ,
unsigned I,
unsigned J> 
 
  332    class innerLoop<SZ,I,J,1> {
 
  335            return l.t_[index(SX-I,SX-1)]*m.t_[SX-1][SZ-J];
 
  338    template <
unsigned I,
unsigned K> 
 
  339    class innerLoop<1,I,1,K> {
 
  342            return l.t_[index(SX-I,SX-K)]*m.t_[SX-K] + innerLoop<1,I,1,K-1>::execute(l,m);
 
  345    template <
unsigned I>  
 
  346    class innerLoop<1,I,1,1> {
 
  349            return l.t_[index(SX-I,SX-1)]*m.t_[SX-1];
 
  353    template <
unsigned SZ,
unsigned I,
unsigned J>
 
  354    class loop2Multiply {
 
  357            ret.t_[SX-I][SZ-J] = innerLoop<SZ,I,J,SX>::execute(l,m);
 
  358            loop2Multiply<SZ,I,J-1>::execute(l,m,ret);
 
  361    template <
unsigned SZ,
unsigned I>  
 
  362    class loop2Multiply<SZ,I,1> {
 
  365            ret.t_[SX-I][SZ-1] = innerLoop<SZ,I,1,SX>::execute(l,m);
 
  368    template <
unsigned I>  
 
  369    class loop2Multiply<1,I,1> {
 
  372            ret.t_[SX-I] = innerLoop<1,I,1,SX>::execute(l,m);
 
  376    template <
unsigned SZ,
unsigned I>
 
  380            loop2Multiply<SZ,I,SZ>::execute(l,m,ret);
 
  381            loopMultiply<SZ,I-1>::execute(l,m,ret);
 
  384    template <
unsigned SZ> 
 
  385    class loopMultiply<SZ,1> {
 
  388            loop2Multiply<SZ,1,SZ>::execute(l,m,ret);
 
  394    template <
unsigned I,
unsigned J,
unsigned K>
 
  398            return l.t_[index(SX-I,SX-K)]*m.t_[index(SX-K,SX-J)] + innerLoopS<I,J,K-1>::execute(l,m);
 
  402    template <
unsigned I,
unsigned J> 
 
  403    class innerLoopS<I,J,1> {
 
  406            return l.t_[index(SX-I,SX-1)]*m.t_[index(SX-1,SX-J)];
 
  412    template <
unsigned I,
unsigned J>
 
  413    class loop2MultiplyS {
 
  416            ret.t_[SX-I][SX-J] = innerLoopS<I,J,SX>::execute(l,m);
 
  417            loop2MultiplyS<I,J-1>::execute(l,m,ret);
 
  420    template <
unsigned I>  
 
  421    class loop2MultiplyS<I,1> {
 
  424            ret.t_[SX-I][SX-1] = innerLoopS<I,1,SX>::execute(l,m);
 
  428    template <
unsigned I>
 
  429    class loopMultiplyS {
 
  432            loop2MultiplyS<I,SX>::execute(l,m,ret);
 
  433            loopMultiplyS<I-1>::execute(l,m,ret);
 
  438    class loopMultiplyS<1> {
 
  441            loop2MultiplyS<1,SX>::execute(l,m,ret);
 
  455    const T & 
get(
unsigned x,
unsigned y)
 const { 
return t_[index(x,y)]; }
 
  457    T &       
get(
unsigned x,
unsigned y) { 
return t_[index(x,y)]; }
 
  459    const Column 
operator[](
unsigned y)
 const { 
return Column(y,*
this); }
 
  466    constexpr UVect2 size()
 const { 
return {SX,SX}; }
 
  493        loopMultiplyS<SX>::execute(*
this,m,ret);
 
 
  499        loopMultiply<SZ,SX>::execute(*
this,m,ret);
 
 
  505    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) {
 
  506        addGenBlock<BX,BY,SX2,SY2>(m,iSrc*BX,jSrc*BY,iDst*BX,jDst*BY);
 
 
  509    template <
unsigned BX,
unsigned BY,
unsigned SX2> 
void addBlock(
const SymMatrix<T,SX2> &m,
unsigned iSrc,
unsigned jSrc,
unsigned iDst,
unsigned jDst) {
 
  510        addGenBlock<BX,BY,SX2>(m,iSrc*BX,jSrc*BY,iDst*BX,jDst*BY);
 
 
  513    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) {
 
  514        for (
unsigned i=iSrc,
id=iDst;i<(iSrc+BX);i++,
id++) {
 
  515            for (
unsigned j=jSrc,jd=jDst;j<(jSrc+BY);j++,jd++) {
 
  517                    get(
id,jd) += m(i,j);
 
 
  522    template <
unsigned BX,
unsigned BY,
unsigned SX2> 
void addGenBlock(
const SymMatrix<T,SX2> &m,
unsigned iSrc,
unsigned jSrc,
unsigned iDst,
unsigned jDst) {
 
  523        for (
unsigned i=iSrc,
id=iDst;i<(iSrc+BX);i++,
id++) {
 
  524            for (
unsigned j=jSrc,jd=jDst;j<(jSrc+BY);j++,jd++) {
 
  526                    get(
id,jd) += m(i,j);
 
 
  532    T 
maxNorm()
 const { T ret(0);  
for (
unsigned i=0;i<len_;++i) ret = std::max(std::abs(t_[i]),ret);  
return ret; }
 
  536    T 
trace()
 const { T tt = t_[0]; 
for (
unsigned i=1; i<SX; ++i) tt += 
get(i,i); 
return tt; }
 
  538    constexpr void set(
const T &t=T{}) { std::fill(&t_[0],&t_[0]+len_,t); }
 
  539    constexpr T minEntry()
 const { 
double ret=
limits<T>::max(); 
for (
unsigned i=0;i<len_;++i) ret=std::min(ret,t_[i]);  
return ret; }
 
  540    constexpr T maxEntry()
 const { 
double ret=
limits<T>::lowest(); 
for (
unsigned i=0;i<len_;++i) ret=std::max(ret,t_[i]);  
return ret; }
 
  552        for (
unsigned i=0;i<SX;++i) {
 
  554            for (
unsigned j=i+1;j<SX;++j) {
 
  555                ret(i,j) = (m(i,j) + m(j,i)) * 0.5;
 
  557                maxdif = std::max(std::abs(ret(i,j) - m(i,j)),maxdif);
 
 
  567    static constexpr unsigned len_ = (SX*SX + SX) / 2;
 
  568    static constexpr unsigned indexConst_ = 1 + 2*SX;
 
  569    static constexpr unsigned index(
unsigned x,
unsigned y) {
 
  570        unsigned x2 = x > y ? y : x;
 
  571        unsigned y2 = x > y ? x : y;
 
  572        unsigned i = (((indexConst_-x2)*x2)/2) + (y2-x2);
 
 
  583template <
class T,
unsigned SX,
unsigned SY,
unsigned I,
unsigned J,
unsigned K>
 
  590template <
class T,
unsigned SX,
unsigned SY,
unsigned I,
unsigned J> 
 
  594        return l.t_[SX-I][SY-1]*m.t_[m.index(SY-1,SY-J)];
 
 
  598template <
class T,
unsigned SX,
unsigned SY,
unsigned I,
unsigned J>
 
  606template <
class T,
unsigned SX,
unsigned SY,
unsigned I>  
 
  614template <
class T,
unsigned SX,
unsigned SY,
unsigned I>
 
  622template <
class T,
unsigned SX,
unsigned SY> 
 
  630template <
class T,
unsigned SX,
unsigned SY>
 
  642template <
class T,
unsigned S> 
 
  646    using Matrix<T,S,1>::operator=;
 
  647    using iterator = T *;
 
  648    using const_iterator = 
const T *;
 
  655    iterator begin() { 
return this->t_; }
 
  656    iterator end() { 
return this->t_+S; }
 
  657    const_iterator begin()
 const { 
return this->t_; }
 
  658    const_iterator end()
 const { 
return this->t_+S; }
 
 
  667template <
unsigned SX,
unsigned SY=SX>  
 
  671template <
unsigned SX> 
 
  678template <
class T,
unsigned S>
 
  681    for (uint32 i=0;i<S;++i)
 
  687double innerProduct(
const VMatrix<T,3> &v1,
const DVect3 &v2) {
 
  689    for (
unsigned i=0;i<3;++i)
 
  695double innerProduct(
const VMatrix<T,2> &v1,
const DVect2 &v2) {
 
  697    for (
unsigned i=0;i<2;++i)
 
  702template <
class T,
unsigned S>
 
  705    for (uint32 i=0;i<S;++i) {
 
  706        for (uint32 j=0;j<S;++j)
 
  707            ret(i,j) = v1(i) * v2(j);
 
  718    ret.
get(0,0) = v1.
x() * v2.
x();
 
  719    ret.
get(0,1) = v1.
x() * v2.
y();
 
  720    ret.
get(0,2) = v1.
x() * v2.
z();
 
  721    ret.
get(1,0) = v1.
y() * v2.
x();
 
  722    ret.
get(1,1) = v1.
y() * v2.
y();
 
  723    ret.
get(1,2) = v1.
y() * v2.
z();
 
  724    ret.
get(2,0) = v1.
z() * v2.
x();
 
  725    ret.
get(2,1) = v1.
z() * v2.
y();
 
  726    ret.
get(2,2) = v1.
z() * v2.
z();
 
 
  736    ret.
get(0,0) = v1.
x() * v2.
x();
 
  737    ret.
get(0,1) = v1.
x() * v2.
y();
 
  738    ret.
get(1,0) = v1.
y() * v2.
x();
 
  739    ret.
get(1,1) = v1.
y() * v2.
y();
 
 
  749    T t = mat.
get(0,0) * (mat.
get(1,1) * mat.
get(2,2) - mat.
get(2,1) * mat.
get(1,2));
 
  750    t -= mat.
get(1,0) * (mat.
get(0,1) * mat.
get(2,2) - mat.
get(2,1) * mat.
get(0,2));
 
  751    t += mat.
get(2,0) * (mat.
get(0,1) * mat.
get(1,2) - mat.
get(1,1) * mat.
get(0,2));
 
 
  760    return mat.
get(0,0) * mat.
get(1,1) - mat.
get(0,1) * mat.
get(1,0);
 
 
  770    const T a11 = mat(0,0), a21 = mat(1,0), a31 = mat(2,0);
 
  771    const T a12 = mat(0,1), a22 = mat(1,1), a32 = mat(2,1);
 
  772    const T a13 = mat(0,2), a23 = mat(1,2), a33 = mat(2,2);
 
  774    Matrix<T,3,3> rm = {{ a22*a33 - a32*a23,-a12*a33 + a32*a13, a12*a23 - a22*a13},
 
  775                        {-a21*a33 + a31*a23, a11*a33 - a31*a13,-a11*a23 + a21*a13},
 
  776                        { a21*a32 - a31*a22,-a11*a32 + a31*a12, a11*a22 - a21*a12}};
 
  777    return rm / determinant(mat);
 
 
  787    rm.
get(0,0) = mat.
get(1,1);
 
  788    rm.
get(1,1) = mat.
get(0,0);
 
  789    rm.
get(0,1) = mat.
get(0,1)*(-1);
 
  790    rm.
get(1,0) = mat.
get(1,0)*(-1);
 
  792    return rm / determinant(mat);
 
 
  797constexpr std::tuple<Matrix<T,3,3>,
double> inverseDet(
const Matrix<T,3,3> &mat) {
 
  799    const T &a11 = mat(0,0), a21 = mat(1,0), a31 = mat(2,0);
 
  800    const T &a12 = mat(0,1), a22 = mat(1,1), a32 = mat(2,1);
 
  801    const T &a13 = mat(0,2), a23 = mat(1,2), a33 = mat(2,2);
 
  804    rm.
get(0,0) = a22*a33 - a32*a23;
 
  805    rm.
get(1,0) = -a21*a33 + a31*a23;
 
  806    rm.
get(2,0) = a21*a32 - a31*a22;
 
  807    rm.
get(0,1) = -a12*a33 + a32*a13;
 
  808    rm.
get(1,1) = a11*a33 - a31*a13;
 
  809    rm.
get(2,1) = -a11*a32 + a31*a12;
 
  810    rm.
get(0,2) = a12*a23 - a22*a13;
 
  811    rm.
get(1,2) = -a11*a23 + a21*a13;
 
  812    rm.
get(2,2) = a11*a22 - a21*a12;
 
  814    double det = determinant(mat);
 
  815    return {rm / det,det};
 
  840template <
class T,
unsigned SX>
 
  843    ret.
get(start) = v.
x();
 
  844    ret.
get(start+1) = v.
y();
 
 
  850template <
unsigned SX> 
constexpr DVMatrix<SX> toDVMatrix(
const DVect2 &v,
unsigned start=0) { 
return toVMatrix<double,SX>(v,start); }
 
  853template <
class T,
unsigned SX>
 
  856    ret.
get(start) = v.
x();
 
  857    ret.
get(start+1) = v.
y();
 
  858    ret.
get(start+2) = v.
z();
 
 
  864template <
unsigned SX>
 
  872        v.
x()*m.
get(1,0) + v.
y()*m.
get(1,1));
 
 
  881                   v.
x()*m.
get(1,0) + v.
y()*m.
get(1,1));
 
 
  891                   v.
x()*m.
get(2,0) + v.
y()*m.
get(2,1) + v.
z()*m.
get(2,2));
 
 
  901                   v.
x()*m.
get(2,0) + v.
y()*m.
get(2,1) + v.
z()*m.
get(2,2));
 
 
  926                  (m.
get(0,1)+m.
get(1,0))*0.5,
 
  927                  (m.
get(0,2)+m.
get(2,0))*0.5,
 
  928                  (m.
get(1,2)+m.
get(2,1))*0.5);
 
  936                  (m.
get(0,1)+m.
get(1,0))*0.5,
 
  951template <
class T,
unsigned SX>
 
  955template <
class T,
unsigned SX>
 
  967template <
class T,
unsigned SY>
 
  970template <
class T,
unsigned SY>
 
  973template <
class T,
unsigned SX>
 
  976template <
class T,
unsigned SX>
 
  979template <
class T,
unsigned SY>
 
  980constexpr void vectorToColumn(
Matrix<T,2,SY> &m,
const DVect2 &v,
unsigned col) { m(0,col) = v.x();  m(1,col) = v.y(); }
 
  982template <
class T,
unsigned SY>
 
  983constexpr 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(); }
 
  985template <
class T,
unsigned SX,
unsigned SY>
 
  988template <
class T,
unsigned SX>
 
  989void vectorToRow(
Matrix<T,SX,2> &m,
const DVect2 &v,
unsigned row) { m(row,0) = v.x();  m(row,1) = v.y(); }
 
  991template <
class T,
unsigned SX>
 
  992void 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(); }
 
  994template <
class T,
unsigned SX,
unsigned SY>
 
  997template <
class T,
unsigned SX,
unsigned SY>
 
 1000    for (
unsigned i=0;i<SX;++i)
 
 1007    ret[0] = s.
s11()*v[0] + s.
s12()*v[1] + s.
s13()*v[2];
 
 1008    ret[1] = s.
s12()*v[0] + s.
s22()*v[1] + s.
s23()*v[2];
 
 1009    ret[2] = s.
s13()*v[0] + s.
s23()*v[1] + s.
s33()*v[2];
 
 1015    ret[0] = s.
s11()*v[0] + s.
s12()*v[1];
 
 1016    ret[1] = s.
s12()*v[0] + s.
s22()*v[1];
 
constexpr const T & operator()(unsigned x) const
() operator access to const get(x)
Definition matrix.h:230
constexpr const Matrix< T, SX, 1 > & operator*=(const T &t)
In-place multiplication by a scalar.
Definition matrix.h:244
Matrix< T, SX, 1 > operator/(const T &t) const
Binary scalar division operator.
Definition matrix.h:255
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:220
constexpr const Matrix< T, SX, 1 > & operator/=(const T &t)
In-place division by a scalar.
Definition matrix.h:246
constexpr T & get(unsigned x)
Retrieve value at row x. Bounds checking is done in a debug compile.
Definition matrix.h:226
Matrix< T, SX, 1 > operator-(const Matrix< T, SX, 1 > &m) const
Binary subtraction operator.
Definition matrix.h:251
Matrix< T, SX, SZ > operator*(const Matrix< T, 1, SZ > &m) const
Binary matrix multiplication operator – simplest naive approach.
Definition matrix.h:257
Matrix< T, 1, SX > transpose() const
returns the transposed matrix of this matrix
Definition matrix.h:289
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:271
constexpr const T & operator()(unsigned x, unsigned y) const
() operator access to const get(x,y)
Definition matrix.h:228
Matrix< T, SX, 1 > operator*(const T &t) const
Binary scalar multiplication operator.
Definition matrix.h:253
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:275
static Matrix< T, SX, 1 > identity()
Returns an identity matrix (or as close as you can get if not diagonal).
Definition matrix.h:296
constexpr T & operator()(unsigned x)
() operator access to get(x)
Definition matrix.h:235
T maxNorm() const
Returns the infinity norm of the matrix, or the maximum absolute magnitude of any element.
Definition matrix.h:287
constexpr Matrix()
Default constructor, does nothing and no initialization.
Definition matrix.h:210
Matrix< T, SX, 1 > operator+(const Matrix< T, SX, 1 > &m) const
Binary addition operator.
Definition matrix.h:249
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:224
constexpr Matrix(const T &t)
Explicit constructor, initializes all elements to value t.
Definition matrix.h:215
constexpr void set(const T &t=T{})
Sets all matrix elemnts to T.
Definition matrix.h:291
constexpr const Matrix< T, SX, 1 > & operator-=(const Matrix< T, SX, 1 > &m)
In-place matrix subtraction.
Definition matrix.h:242
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:281
constexpr const T & get(unsigned x) const
Retrieve constant value at row x. Bounds checking is done in a debug compile.
Definition matrix.h:222
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:267
constexpr const Matrix< T, SX, 1 > & operator+=(const Matrix< T, SX, 1 > &m)
In-place matrix addition.
Definition matrix.h:240
constexpr T & operator()(unsigned x, unsigned y)
() operator access to get(x,y)
Definition matrix.h:233
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:148
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:168
Matrix< T, SX, SY > operator-(const Matrix< T, SX, SY > &m) const
Binary subtraction operator.
Definition matrix.h:146
constexpr const Matrix< T, SX, SY > & operator-=(const Matrix< T, SX, SY > &m)
In-place matrix subtraction.
Definition matrix.h:137
T maxNorm() const
Returns the infinity norm of the matrix, or the maximum absolute magnitude of any element.
Definition matrix.h:175
constexpr T & operator()(unsigned x, unsigned y)
() operator access to get(x,y)
Definition matrix.h:131
constexpr Matrix()
Default constructor, does nothing and no initialization.
Definition matrix.h:111
constexpr Matrix(const T &t)
Explicit constructor, initializes all elements to value t.
Definition matrix.h:116
Matrix< T, SX, SY > operator/(const T &t) const
Binary scalar division operator.
Definition matrix.h:150
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:163
static constexpr Matrix< T, SX, SY > identity()
Returns an identity matrix (or as close as you can get if not diagonal).
Definition matrix.h:186
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:179
constexpr void set(const T &t=T{})
Set all entries in the matrix to t.
Definition matrix.h:181
constexpr const Matrix< T, SX, SY > & operator+=(const Matrix< T, SX, SY > &m)
In-place matrix addition.
Definition matrix.h:135
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:125
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:121
constexpr Matrix< T, SX, SZ > operator*(const Matrix< T, SY, SZ > &m) const
Binary matrix multiplication operator – simplest naive approach.
Definition matrix.h:153
Matrix< T, SY, SX > transpose() const
Return the transpose of the matrix.
Definition matrix.h:177
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:123
constexpr const T & operator()(unsigned x, unsigned y) const
() operator access to get(x,y)
Definition matrix.h:129
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:127
constexpr const Matrix< T, SX, SY > & operator*=(const T &t)
In-place multiplication by a scalar.
Definition matrix.h:139
Matrix< T, SX, SY > operator+(const Matrix< T, SX, SY > &m) const
Binary addition operator.
Definition matrix.h:144
constexpr const Matrix< T, SX, SY > & operator/=(const T &t)
In-place division by a scalar.
Definition matrix.h:141
A template-based symmetric matrix class, size fixed at compile time. This primitive template-based ma...
Definition matrix.h:305
constexpr Matrix< T, SX, SX > operator*(const SymMatrix< T, SX > &m) const
Binary matrix multiplication operator – simplest naive approach.
Definition matrix.h:491
SymMatrix< T, SX > operator/(const T &t) const
Binary scalar division operator for a symetric matrix.
Definition matrix.h:489
const T & operator()(unsigned x, unsigned y) const
() operator access to get(x,y)
Definition matrix.h:463
constexpr Matrix< T, SX, SZ > operator*(const Matrix< T, SX, SZ > &m) const
Binary matrix multiplication operator – simplest naive approach.
Definition matrix.h:497
SymMatrix(const T &t)
Explicit constructor, initializes all elements to value t.
Definition matrix.h:452
const SymMatrix< T, SX > & operator/=(const T &t)
In-place division by a scalar.
Definition matrix.h:475
SymMatrix< T, SX > operator-(const SymMatrix< T, SX > &m) const
Binary subtraction operator for a symetric matrix.
Definition matrix.h:482
const SymMatrix< T, SX > & operator*=(const T &t)
In-place multiplication by a scalar.
Definition matrix.h:473
T & get(unsigned x, unsigned y)
Retrieve value at row x column y. Bounds checking is done in a debug compile.
Definition matrix.h:457
const SymMatrix< T, SX > & operator-=(const SymMatrix< T, SX > &m)
In-place matrix subtraction.
Definition matrix.h:471
Matrix< T, SX, SX > operator+(const Matrix< T, SX, SX > &m) const
Binary addition operator.
Definition matrix.h:480
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:459
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:509
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:522
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:455
static SymMatrix< T, SX > identity()
Returns an identity matrix (or as close as you can get if not diagonal).
Definition matrix.h:545
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:505
SymMatrix< T, SX > operator*(const T &t) const
Binary scalar multiplication operator for a symetric matrix.
Definition matrix.h:487
T & operator()(unsigned x, unsigned y)
() operator access to get(x,y)
Definition matrix.h:465
Matrix< T, SX, SX > operator-(const Matrix< T, SX, SX > &m) const
Binary subtraction operator.
Definition matrix.h:484
SymMatrix< T, SX > transpose() const
Return the transpose of the matrix.
Definition matrix.h:534
Matrix< T, SX, SX > toMatrix() const
Returns its copy.
Definition matrix.h:542
constexpr void set(const T &t=T{})
Sets all matrix elements to t.
Definition matrix.h:538
const SymMatrix< T, SX > & operator+=(const SymMatrix< T, SX > &m)
In-place matrix addition.
Definition matrix.h:469
static SymMatrix< T, SX > fromMatrix(const Matrix< T, SX, SX > &m)
Assign from full matrix.
Definition matrix.h:547
SymMatrix< T, SX > operator+(const SymMatrix< T, SX > &m) const
Binary addition operator for a symetric matris.
Definition matrix.h:478
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:536
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:513
T maxNorm() const
Returns the infinity norm of the matrix, or the maximum absolute magnitude of any element.
Definition matrix.h:532
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:461
A symmetric 2nd order tensor.
Definition symtensor.h:22
double s33() const
Component access, note that s12 is equivalent to s21 (for instance).
Definition symtensor.h:42
double s12() const
Component access, note that s12 is equivalent to s21 (for instance).
Definition symtensor.h:43
double s11() const
Component access, note that s12 is equivalent to s21 (for instance).
Definition symtensor.h:40
double s22() const
Component access, note that s12 is equivalent to s21 (for instance).
Definition symtensor.h:41
double s23() const
Component access, note that s12 is equivalent to s21 (for instance).
Definition symtensor.h:45
double s13() const
Component access, note that s12 is equivalent to s21 (for instance).
Definition symtensor.h:44
A 1-Dimensional version of Matrix, to represent a vector.
Definition matrix.h:643
constexpr T & operator[](unsigned x)
1D version of array operator, which currently unfortunately eliminates [x][0] syntax on VMatrix (may ...
Definition matrix.h:663
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:661
2D vector utility class.
Definition vect.h:32
constexpr const T & x() const
X component access.
Definition vect.h:53
constexpr const T & y() const
Y component access.
Definition vect.h:55
3D vector utility class.
Definition vect.h:150
constexpr const T & y() const
The y-component of the vector.
Definition vect.h:169
constexpr const T & x() const
The x-component of the vector.
Definition vect.h:167
constexpr const T & z() const
The z-component of the vector.
Definition vect.h:171
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:748
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:968
constexpr Matrix< T, 3, 3 > inverse(const Matrix< T, 3, 3 > &mat)
Returns the inverse of a 3X3 Matrix.
Definition matrix.h:768
constexpr Vector3< T > operator*(const Matrix< T, 3, 3 > &m, const Vector3< T > &v)
Definition matrix.h:888
constexpr DVMatrix< SX > toDVMatrix(const DVect2 &v, unsigned start=0)
Definition matrix.h:850
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:716
constexpr VMatrix< T, 2 > toMatrix(const Vector2< T > &v)
Definition matrix.h:821
constexpr VMatrix< T, 3 > toMatrix(const Vector3< T > &v)
Definition matrix.h:831
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:956
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:841
constexpr Vector2< T > operator*(const Matrix< T, 2, 2 > &m, const Vector2< T > &v)
Definition matrix.h:870
constexpr Vector2< T > operator*(const SymMatrix< T, 2 > &m, const Vector2< T > &v)
Definition matrix.h:879
constexpr T determinant(const Matrix< T, 2, 2 > &mat)
Returns the determinant of a 2X2 Matrix.
Definition matrix.h:759
#define BASE_EXPORT
Definition basedef.h:25
Vector3< T > operator*(const SymMatrix< T, 3 > &m, const Vector3< T > &v)
Definition matrix.h:898
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:974
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:734
constexpr Matrix< T, 2, 2 > inverse(const Matrix< T, 2, 2 > &mat)
Returns the inverse of a 2X2 Matrix.
Definition matrix.h:785
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:952
Vector2< T > toVector(const VMatrix< T, 2 > &m)
Converts a VMatrix to a Vector3, using three elements starting at index start.
Definition matrix.h:960
A Symmetric 2nd order tensor.