Itasca C++ Interface
Loading...
Searching...
No Matches
matrix.h
Go to the documentation of this file.
1#pragma once
8#ifdef __LINUX
9#include <string.h>
10#endif
11
12#include "symtensor.h"
13#include <cassert>
14
21template <class T,unsigned SX,unsigned SY=SX>
22class Matrix {
23private:
25 class Column {
26 public:
28 constexpr Column(unsigned x,Matrix<T,SX,SY> &m) : x_(x), m_(m) { }
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); }
35 private:
36 void operator=(const Column &r)=delete;
37 unsigned x_;
39 };
40 // Using template-meta programming to unroll innermost loop of matrix multiply
41 template <unsigned SZ,unsigned I,unsigned J,unsigned K>
42 class innerLoop {
43 public:
44 static double execute(const Matrix<T,SX,SY> &l,const Matrix<T,SY,SZ> &m) {
45 return l.t_[SX-I][SY-K]*m.t_[SY-K][SZ-J] + innerLoop<SZ,I,J,K-1>::execute(l,m);
46 }
47 };
48 template <unsigned SZ,unsigned I,unsigned J> // Termination specialization
49 class innerLoop<SZ,I,J,1> {
50 public:
51 static double execute(const Matrix<T,SX,SY> &l,const Matrix<T,SY,SZ> &m) {
52 return l.t_[SX-I][SY-1]*m.t_[SY-1][SZ-J];
53 }
54 };
55 template <unsigned I,unsigned K> // Specialization for column matrix (SZ=1)
56 class innerLoop<1,I,1,K> {
57 public:
58 static double execute(const Matrix<T,SX,SY> &l,const Matrix<T,SY,1> &m) {
59 return l.t_[SX-I][SY-K]*m.t_[SY-K] + innerLoop<1,I,1,K-1>::execute(l,m);
60 }
61 };
62 template <unsigned I> // termination specialization for column matrix specialization
63 class innerLoop<1,I,1,1> {
64 public:
65 static double execute(const Matrix<T,SX,SY> &l,const Matrix<T,SY,1> &m) {
66 return l.t_[SX-I][SY-1]*m.t_[SY-1];
67 }
68 };
69 // Using template meta-programming to unroll second loop of matrix multiply.
70 template <unsigned SZ,unsigned I,unsigned J>
71 class loop2Multiply {
72 public:
73 static void execute(const Matrix<T,SX,SY> &l,const Matrix<T,SY,SZ> &m,Matrix<T,SX,SZ> &ret) {
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);
76 }
77 };
78 template <unsigned SZ,unsigned I> // Termination specialization
79 class loop2Multiply<SZ,I,1> {
80 public:
81 static void execute(const Matrix<T,SX,SY> &l,const Matrix<T,SY,SZ> &m,Matrix<T,SX,SZ> &ret) {
82 ret.t_[SX-I][SZ-1] = innerLoop<SZ,I,1,SY>::execute(l,m);
83 }
84 };
85 template <unsigned I> // Column matrix specialization (SZ=1)
86 class loop2Multiply<1,I,1> {
87 public:
88 static void execute(const Matrix<T,SX,SY> &l,const Matrix<T,SY,1> &m,Matrix<T,SX,1> &ret) {
89 ret.t_[SX-I] = innerLoop<1,I,1,SY>::execute(l,m);
90 }
91 };
92 // Using template meta-programming to unroll outermost loop of matrix multiply.
93 template <unsigned SZ,unsigned I>
94 class loopMultiply {
95 public:
96 static void execute(const Matrix<T,SX,SY> &l,const Matrix<T,SY,SZ> &m,Matrix<T,SX,SZ> &ret) {
97 loop2Multiply<SZ,I,SZ>::execute(l,m,ret);
98 loopMultiply<SZ,I-1>::execute(l,m,ret);
99 }
100 };
101 template <unsigned SZ> // Termination specialization
102 class loopMultiply<SZ,1> {
103 public:
104 static void execute(const Matrix<T,SX,SY> &l,const Matrix<T,SY,SZ> &m,Matrix<T,SX,SZ> &ret) {
105 loop2Multiply<SZ,1,SZ>::execute(l,m,ret);
106 }
107 };
108
109public:
111#ifdef _DEBUG
112 Matrix() { set(initVal<T>()); }
113#else
114PUSHWARNING
115VSWARNING(26495) // Initialization warning - on purpose
117POPWARNING
118#endif
120 explicit constexpr Matrix(const T &t) { set(t); }
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);
124 constexpr Matrix(const Matrix<T,SX,SY> &m) { operator=(m); }
126 constexpr const Matrix<T,SX,SY> &operator=(const Matrix<T,SX,SY> &m) { for (unsigned i=0;i<SX;++i) for (unsigned j=0;j<SY;++j) t_[i][j] = m.t_[i][j]; return *this; }
127
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); }
139 constexpr T & operator()(unsigned x,unsigned y) { return get(x,y); }
140 constexpr UVect2 size() const { return {SX,SY}; }
141
143 constexpr const Matrix<T,SX,SY> &operator+=(const Matrix<T,SX,SY> &m) { for (unsigned i=0;i<SX;++i) for (unsigned j=0;j<SY;++j) t_[i][j] += m.t_[i][j]; return *this; }
145 constexpr const Matrix<T,SX,SY> &operator-=(const Matrix<T,SX,SY> &m) { for (unsigned i=0;i<SX;++i) for (unsigned j=0;j<SY;++j) t_[i][j] -= m.t_[i][j]; return *this; }
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; }
150
152 Matrix<T,SX,SY> operator+(const Matrix<T,SX,SY> &m) const { Matrix<T,SX,SY> ret; for (unsigned i=0;i<SX;++i) for (unsigned j=0;j<SY;++j) ret.t_[i][j] = t_[i][j] + m.t_[i][j]; return ret; }
154 Matrix<T,SX,SY> operator-(const Matrix<T,SX,SY> &m) const { Matrix<T,SX,SY> ret; for (unsigned i=0;i<SX;++i) for (unsigned j=0;j<SY;++j) ret.t_[i][j] = t_[i][j] - m.t_[i][j]; return ret; }
156 Matrix<T,SX,SY> operator*(const T &t) const { Matrix<T,SX,SY> ret; for (unsigned i=0;i<SX;++i) for (unsigned j=0;j<SY;++j) ret.t_[i][j] = t_[i][j] * t; return ret; }
158 Matrix<T,SX,SY> operator/(const T &t) const { Matrix<T,SX,SY> ret; for (unsigned i=0;i<SX;++i) for (unsigned j=0;j<SY;++j) ret.t_[i][j] = t_[i][j] / t; return ret; }
160 template <unsigned SZ>
162 Matrix<T,SX,SZ> ret;
163 // OK - we are using template expansion to do loop unrolling at compile time. Fun!
164 //for (unsigned i=0;i<SX;++i) { // ROWS OF FIRST
165 // for (unsigned j=0;j<SZ;++j) { // COLUMNS OF SECOND
166 // T &val = ret.get(i,j);
167 // val = 0;
168 // for (unsigned k=0;k<SY;++k) // Add up
169 // val += get(i,k)*m.get(k,j);
170 // }
171 //}
172 loopMultiply<SZ,SX>::execute(*this,m,ret);
173 return ret;
174 }
176 //template <class T>
177 //Matrix<T,SX,1> operator*(const Matrix<T,SY,1> &m) const {
178 // Matrix<T,SX,1> ret;
179 // // OK - we are using template expansion to do loop unrolling at compile time. Fun!
180 // //for (unsigned i=0;i<SX;++i) { // ROWS OF FIRST
181 // // T &val = ret.get(i,0);
182 // // val = 0.0;
183 // // for (unsigned k=0;k<SY;++k) // Add up
184 // // val += get(i,k)*m.get(k,0);
185 // //}
186 // loopMultiply<1,SX>::execute(*this,m,ret);
187 // return ret;
188 //}
189
190 // Block operations
192 template <unsigned BX,unsigned BY,unsigned SX2,unsigned SY2>
193 void addBlock(const Matrix<T,SX2,SY2> &m,unsigned iSrc,unsigned jSrc,unsigned iDst,unsigned jDst) {
194 addGenBlock<BX,BY,SX2,SY2>(m,iSrc*BX,jSrc*BY,iDst*BX,jDst*BY);
195 }
197 template <unsigned BX,unsigned BY,unsigned SX2,unsigned SY2>
198 void addGenBlock(const Matrix<T,SX2,SY2> &m,unsigned iSrc,unsigned jSrc,unsigned iDst,unsigned jDst) {
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);
202 }
203
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; }
207 Matrix<T,SY,SX> transpose() const { Matrix<T,SY,SX> ret; for (unsigned i=0;i<SX;++i) for (unsigned j=0;j<SY;++j) ret(j,i) = 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; }
214
216 static constexpr Matrix<T,SX,SY> identity() { Matrix<T,SX,SY> ret(0.0); for (unsigned i=0;i<std::min(SX,SY);++i) ret(i,i) = 1.0; return ret; }
217
218 T t_[SX][SY];
219};
220
221template <class T,unsigned SX,unsigned SY>
222constexpr Matrix<T,SX,SY>::Matrix(const std::initializer_list<std::initializer_list<T>> l) {
223 uint32 i=0;
224 for (auto &y : l) {
225 uint32 j = 0;
226 for (auto &x : y) {
227 t_[i][j] = x;
228 ++j;
229 }
230 ++i;
231 }
232}
233
234
236template <class T,unsigned SX>
237class Matrix<T,SX,1> {
238public:
240#ifdef _DEBUG
241 Matrix() { set(initVal<T>()); }
242#else
243 Matrix() { }
244#endif
246 constexpr explicit Matrix(const T &t) { set(t); }
248 constexpr Matrix(const Matrix<T,SX,1> &m) { operator=(m); }
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; } }
252 constexpr const Matrix<T,SX,1> &operator=(const Matrix<T,SX,1> &m) { for (uint32 i=0;i<SX;++i) t_[i] = m.t_[i]; return *this; }
253
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); }
265 constexpr const T & operator()(unsigned x) const { return get(x); }
267 constexpr T & operator()(unsigned x,unsigned y) { return get(x,y); }
269 constexpr T & operator()(unsigned x) { return get(x); }
270 constexpr UVect2 size() const { return {SX,1}; }
271
273 constexpr const Matrix<T,SX,1> &operator+=(const Matrix<T,SX,1> &m) { for (unsigned i=0;i<SX;++i) t_[i] += m.t_[i]; return *this; }
275 constexpr const Matrix<T,SX,1> &operator-=(const Matrix<T,SX,1> &m) { for (unsigned i=0;i<SX;++i) t_[i] -= m.t_[i]; return *this; }
277 constexpr const Matrix<T,SX,1> &operator*=(const T &t) { for (unsigned i=0;i<SX;++i) t_[i] *= t; return *this; }
279 constexpr const Matrix<T,SX,1> &operator/=(const T &t) { for (unsigned i=0;i<SX;++i) t_[i] /= t; return *this; }
280
282 Matrix<T,SX,1> operator+(const Matrix<T,SX,1> &m) const { Matrix<T,SX,1> ret; for (unsigned i=0;i<SX;++i) ret.t_[i] = t_[i] + m.t_[i]; return ret; }
284 Matrix<T,SX,1> operator-(const Matrix<T,SX,1> &m) const { Matrix<T,SX,1> ret; for (unsigned i=0;i<SX;++i) ret.t_[i] = t_[i] - m.t_[i]; return ret; }
286 Matrix<T,SX,1> operator*(const T &t) const { Matrix<T,SX,1> ret; for (unsigned i=0;i<SX;++i) ret.t_[i] = t_[i] * t; return ret; }
288 Matrix<T,SX,1> operator/(const T &t) const { Matrix<T,SX,1> ret; for (unsigned i=0;i<SX;++i) ret.t_[i] = t_[i] / t; return ret; }
290 template <unsigned SZ> Matrix<T,SX,SZ> operator*(const Matrix<T,1,SZ> &m) const {
291 Matrix<T,SX,SZ> ret;
292 for (unsigned i=0;i<SX;++i) // ROWS OF FIRST
293 for (unsigned j=0;j<SZ;++j) // COLUMNS OF SECOND
294 ret.get(i,j) = get(i,0)*m.get(0,j);
295 return ret;
296 }
297
298 // Block operations
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);
302 }
304 template <unsigned BX,unsigned SX2> void addBlock(const Matrix<T,SX2,1> &m,unsigned iSrc,unsigned iDst) {
305 addGenBlock<BX,SX2>(m,iSrc*BX,iDst*BX);
306 }
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);
312 }
314 template <unsigned BX,unsigned SX2> void addGenBlock(const Matrix<T,SX2,1> &m,unsigned iSrc,unsigned iDst) {
315 for (unsigned i=iSrc,id=iDst;i<(iSrc+BX);i++,id++)
316 get(id) += m(i);
317 }
318
320 T maxNorm() const { T ret(0); for (unsigned i=0;i<SX;++i) ret = std::max(ret,std::abs(t_[i])); return ret; }
322 Matrix<T,1,SX> transpose() const { Matrix<T,1,SX> ret; for (unsigned i=0;i<SX;++i) ret(0,i) = 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; }
327
329 static Matrix<T,SX,1> identity() { Matrix<T,SX,1> ret(0.0); ret.t_[0] = 1.0; return ret; }
330 T t_[SX];
331};
332
337template <class T,unsigned SX>
339private:
341 class Column {
342 public:
344 Column(unsigned x,SymMatrix<T,SX> &m) : x_(x), m_(m) { }
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); }
351 private:
352 void operator=(const Column &r); // DISALLOWED
353 unsigned x_;
354 SymMatrix<T,SX> &m_;
355 };
356 // Using template-meta programming to unroll innermost loop of matrix multiply
357 template <unsigned SZ,unsigned I,unsigned J,unsigned K>
358 class innerLoop {
359 public:
360 static double execute(const SymMatrix<T,SX> &l,const Matrix<T,SX,SZ> &m) {
361 return l.t_[index(SX-I,SX-K)]*m.t_[SX-K][SZ-J] + innerLoop<SZ,I,J,K-1>::execute(l,m);
362 }
363 };
364 template <unsigned SZ,unsigned I,unsigned J> // Termination specialization
365 class innerLoop<SZ,I,J,1> {
366 public:
367 static double execute(const SymMatrix<T,SX> &l,const Matrix<T,SX,SZ> &m) {
368 return l.t_[index(SX-I,SX-1)]*m.t_[SX-1][SZ-J];
369 }
370 };
371 template <unsigned I,unsigned K> // Specialization for column matrix (SZ=1)
372 class innerLoop<1,I,1,K> {
373 public:
374 static double execute(const SymMatrix<T,SX> &l,const Matrix<T,SX,1> &m) {
375 return l.t_[index(SX-I,SX-K)]*m.t_[SX-K] + innerLoop<1,I,1,K-1>::execute(l,m);
376 }
377 };
378 template <unsigned I> // termination specialization for column matrix specialization
379 class innerLoop<1,I,1,1> {
380 public:
381 static double execute(const SymMatrix<T,SX> &l,const Matrix<T,SX,1> &m) {
382 return l.t_[index(SX-I,SX-1)]*m.t_[SX-1];
383 }
384 };
385 // Using template meta-programming to unroll second loop of matrix multiply.
386 template <unsigned SZ,unsigned I,unsigned J>
387 class loop2Multiply {
388 public:
389 static void execute(const SymMatrix<T,SX> &l,const Matrix<T,SX,SZ> &m,Matrix<T,SX,SZ> &ret) {
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);
392 }
393 };
394 template <unsigned SZ,unsigned I> // Termination specialization
395 class loop2Multiply<SZ,I,1> {
396 public:
397 static void execute(const SymMatrix<T,SX> &l,const Matrix<T,SX,SZ> &m,Matrix<T,SX,SZ> &ret) {
398 ret.t_[SX-I][SZ-1] = innerLoop<SZ,I,1,SX>::execute(l,m);
399 }
400 };
401 template <unsigned I> // Column matrix specialization (SZ=1)
402 class loop2Multiply<1,I,1> {
403 public:
404 static void execute(const SymMatrix<T,SX> &l,const Matrix<T,SX,1> &m,Matrix<T,SX,1> &ret) {
405 ret.t_[SX-I] = innerLoop<1,I,1,SX>::execute(l,m);
406 }
407 };
408 // Using template meta-programming to unroll outermost loop of matrix multiply.
409 template <unsigned SZ,unsigned I>
410 class loopMultiply {
411 public:
412 static void execute(const SymMatrix<T,SX> &l,const Matrix<T,SX,SZ> &m,Matrix<T,SX,SZ> &ret) {
413 loop2Multiply<SZ,I,SZ>::execute(l,m,ret);
414 loopMultiply<SZ,I-1>::execute(l,m,ret);
415 }
416 };
417 template <unsigned SZ> // Termination specialization
418 class loopMultiply<SZ,1> {
419 public:
420 static void execute(const SymMatrix<T,SX> &l,const Matrix<T,SX,SZ> &m,Matrix<T,SX,SZ> &ret) {
421 loop2Multiply<SZ,1,SZ>::execute(l,m,ret);
422 }
423 };
424
425
426 // Using template-meta programming to unroll innermost loop of matrix multiply
427 template <unsigned I,unsigned J,unsigned K>
428 class innerLoopS {
429 public:
430 static double execute(const SymMatrix<T,SX> &l,const SymMatrix<T,SX> &m) {
431 return l.t_[index(SX-I,SX-K)]*m.t_[index(SX-K,SX-J)] + innerLoopS<I,J,K-1>::execute(l,m);
432 }
433 };
434
435 template <unsigned I,unsigned J> // Termination specialization
436 class innerLoopS<I,J,1> {
437 public:
438 static double execute(const SymMatrix<T,SX> &l,const SymMatrix<T,SX> &m) {
439 return l.t_[index(SX-I,SX-1)]*m.t_[index(SX-1,SX-J)];
440 // what is X here? seems undefined??
441 }
442 };
443
444 // Using template meta-programming to unroll second loop of matrix multiply.
445 template <unsigned I,unsigned J>
446 class loop2MultiplyS {
447 public:
448 static void execute(const SymMatrix<T,SX> &l,const SymMatrix<T,SX> &m,Matrix<T,SX,SX> &ret) {
449 ret.t_[SX-I][SX-J] = innerLoopS<I,J,SX>::execute(l,m);
450 loop2MultiplyS<I,J-1>::execute(l,m,ret);
451 }
452 };
453 template <unsigned I> // Termination specialization
454 class loop2MultiplyS<I,1> {
455 public:
456 static void execute(const SymMatrix<T,SX> &l,const SymMatrix<T,SX> &m,Matrix<T,SX,SX> &ret) {
457 ret.t_[SX-I][SX-1] = innerLoopS<I,1,SX>::execute(l,m);
458 }
459 };
460 // Using template meta-programming to unroll outermost loop of matrix multiply.
461 template <unsigned I>
462 class loopMultiplyS {
463 public:
464 static void execute(const SymMatrix<T,SX> &l,const SymMatrix<T,SX> &m,Matrix<T,SX,SX> &ret) {
465 loop2MultiplyS<I,SX>::execute(l,m,ret);
466 loopMultiplyS<I-1>::execute(l,m,ret);
467 }
468 };
469#ifndef __LINUX
470 template <> // Termination specialization
471 class loopMultiplyS<1> {
472 public:
473 static void execute(const SymMatrix<T,SX> &l,const SymMatrix<T,SX> &m,Matrix<T,SX,SX> &ret) {
474 loop2MultiplyS<1,SX>::execute(l,m,ret);
475 }
476 };
477#endif
478
479public:
481#ifdef _DEBUG
482 SymMatrix() { set(initVal<T>()); }
483#else
485#endif
487 explicit SymMatrix(const T &t) { set(t); }
489 SymMatrix(const SymMatrix<T,SX> &m) { memcpy(t_,m.t_,sizeof(T)*len_); }
491 const SymMatrix<T,SX> &operator=(const SymMatrix<T,SX> &m) { memcpy(t_,m.t_,sizeof(T)*len_); return *this; }
492
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); }
500 Column operator[](unsigned y) { return Column(y,*this); }
502 const T & operator()(unsigned x,unsigned y) const { return get(x,y); }
504 T & operator()(unsigned x,unsigned y) { return get(x,y); }
505 constexpr UVect2 size() const { return {SX,SX}; }
506
508 const SymMatrix<T,SX> &operator+=(const SymMatrix<T,SX> &m) { for (unsigned i=0;i<len_;++i) t_[i] += m.t_[i]; return *this; }
510 const SymMatrix<T,SX> &operator-=(const SymMatrix<T,SX> &m) { for (unsigned i=0;i<len_;++i) t_[i] -= m.t_[i]; return *this; }
512 const SymMatrix<T,SX> &operator*=(const T &t) { for (unsigned i=0;i<len_;++i) t_[i] *= t; return *this; }
514 const SymMatrix<T,SX> &operator/=(const T &t) { for (unsigned i=0;i<len_;++i) t_[i] /= t; return *this; }
515
517 SymMatrix<T,SX> operator+(const SymMatrix<T,SX> &m) const { SymMatrix<T,SX> ret; for (unsigned i=0;i<len_;++i) ret.t_[i] = t_[i] + m.t_[i]; return ret; }
519 Matrix<T,SX,SX> operator+(const Matrix<T,SX,SX> &m) const { Matrix<T,SX,SX> ret; for (unsigned i=0;i<SX;++i) for (unsigned j=0;j<SX;++j) ret(i,j) = get(i,j) + m.get(i,j); return ret; }
521 SymMatrix<T,SX> operator-(const SymMatrix<T,SX> &m) const { SymMatrix<T,SX> ret; for (unsigned i=0;i<len_;++i) ret.t_[i] = t_[i] - m.t_[i]; return ret; }
523 Matrix<T, SX, SX> operator-(const Matrix<T, SX, SX>& m) const { Matrix<T, SX, SX> ret; for (unsigned i = 0; i < SX; ++i) for (unsigned j = 0; j < SX; ++j) ret(i, j) = get(i, j) - m.get(i, j); return ret; }
524
526 SymMatrix<T,SX> operator*(const T &t) const { SymMatrix<T,SX> ret; for (unsigned i=0;i<len_;++i) ret.t_[i] = t_[i] * t; return ret; }
528 SymMatrix<T,SX> operator/(const T &t) const { SymMatrix<T,SX> ret; for (unsigned i=0;i<len_;++i) ret.t_[i] = t_[i] / t; return ret; }
531 Matrix<T,SX,SX> ret;
532 loopMultiplyS<SX>::execute(*this,m,ret);
533 //for (unsigned i=0;i<SX;++i) { // ROWS OF FIRST
534 // for (unsigned j=0;j<SX;++j) { // COLUMNS OF SECOND
535 // T &val = ret.get(i,j);
536 // val = 0.0;
537 // for (unsigned k=0;k<SX;++k) // Add up
538 // val += get(i,k)*m.get(k,j);
539 // }
540 //}
541 return ret;
542 }
544 template <unsigned SZ> Matrix<T,SX,SZ> operator*(const Matrix<T,SX,SZ> &m) const {
545 Matrix<T,SX,SZ> ret;
546 loopMultiply<SZ,SX>::execute(*this,m,ret);
547 //for (unsigned i=0;i<SX;++i) { // ROWS OF FIRST
548 // for (unsigned j=0;j<SY;++j) { // COLUMNS OF SECOND
549 // T &val = ret.get(i,j);
550 // val = 0.0;
551 // for (unsigned k=0;k<SX;++k) // Add up
552 // val += get(i,k)*m.get(k,j);
553 // }
554 //}
555 return ret;
556 }
558 //template <> Matrix<T,SX,1> operator*(const Matrix<T,SX,1> &m) const {
559 // Matrix<T,SX,1> ret;
560 // for (unsigned i=0;i<SX;++i) { // ROWS OF FIRST
561 // T &val = ret.get(i,0);
562 // val = 0.0;
563 // for (unsigned k=0;k<SX;++k) // Add up
564 // val += get(i,k)*m.get(k,0);
565 // }
566 // return ret;
567 //}
568
569 // Block operations
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);
573 }
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);
577 }
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++) {
582 if (id<=jd)
583 get(id,jd) += m(i,j);
584 }
585 }
586 }
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++) {
591 if (id<=jd)
592 get(id,jd) += m(i,j);
593 }
594 }
595 }
596
598 T maxNorm() const { T ret(0); for (unsigned i=0;i<len_;++i) ret = std::max(std::abs(t_[i]),ret); return ret; }
600 SymMatrix<T,SX> transpose() const { return *this; }
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; }
608 Matrix<T,SX,SX> toMatrix() const { Matrix<T,SX,SX> ret; for (unsigned i=0;i<SX;++i) for (unsigned j=0;j<SX;++j) ret(i,j)=get(i,j); return ret; }
609
611 static SymMatrix<T,SX> identity() { SymMatrix<T,SX> ret(0.0); for (unsigned i=0;i<SX;++i) ret(i,i) = 1.0; return ret; }
614 SymMatrix<T,SX> ret;
615#ifdef _DEBUG
616 double maxdif = 0.0;
617#endif
618 for (unsigned i=0;i<SX;++i) {
619 ret(i,i) = m(i,i);
620 for (unsigned j=i+1;j<SX;++j) {
621 ret(i,j) = (m(i,j) + m(j,i)) * 0.5;
622#ifdef _DEBUG
623 maxdif = std::max(std::abs(ret(i,j) - m(i,j)),maxdif);
624#endif
625 }
626 }
627#ifdef _DEBUG
628 assert(maxdif <= ret.maxNorm()*limits<float>::epsilon());
629#endif
630 return ret;
631 }
632
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);
639 return i;
640 }
641
642 T t_[len_];
643};
644
645// MOO NOTE!:: There are optimizations that can be made here!
648// Using template-meta programming to unroll innermost loop of matrix multiply
649template <class T,unsigned SX,unsigned SY,unsigned I,unsigned J,unsigned K>
651public:
652 static double execute(const Matrix<T,SX,SY> &l,const SymMatrix<T,SY> &m) {
653 return l.t_[SX-I][SY-K]*m.t_[m.index(SY-K,SY-J)] + innerLoopMS<T,SX,SY,I,J,K-1>::execute(l,m);
654 }
655};
656template <class T,unsigned SX,unsigned SY,unsigned I,unsigned J> // Termination specialization
657class innerLoopMS<T,SX,SY,I,J,1> {
658public:
659 static double execute(const Matrix<T,SX,SY> &l,const SymMatrix<T,SY> &m) {
660 return l.t_[SX-I][SY-1]*m.t_[m.index(SY-1,SY-J)];
661 }
662};
663// Using template meta-programming to unroll second loop of matrix multiply.
664template <class T,unsigned SX,unsigned SY,unsigned I,unsigned J>
666public:
667 static void execute(const Matrix<T,SX,SY> &l,const SymMatrix<T,SY> &m,Matrix<T,SX,SY> &ret) {
668 ret.t_[SX-I][SY-J] = innerLoopMS<T,SX,SY,I,J,SY>::execute(l,m);
670 }
671};
672template <class T,unsigned SX,unsigned SY,unsigned I> // Termination specialization
673class loop2MultiplyMS<T,SX,SY,I,1> {
674public:
675 static void execute(const Matrix<T,SX,SY> &l,const SymMatrix<T,SY> &m,Matrix<T,SX,SY> &ret) {
676 ret.t_[SX-I][SY-1] = innerLoopMS<T,SX,SY,I,1,SY>::execute(l,m);
677 }
678};
679// Using template meta-programming to unroll outermost loop of matrix multiply.
680template <class T,unsigned SX,unsigned SY,unsigned I>
682public:
683 static void execute(const Matrix<T,SX,SY> &l,const SymMatrix<T,SY> &m,Matrix<T,SX,SY> &ret) {
686 }
687};
688template <class T,unsigned SX,unsigned SY> // Termination specialization
689class loopMultiplyMS<T,SX,SY,1> {
690public:
691 static void execute(const Matrix<T,SX,SY> &l,const SymMatrix<T,SY> &m,Matrix<T,SX,SY> &ret) {
693 }
694};
695
696template <class T,unsigned SX,unsigned SY>
697Matrix<T,SX,SY> operator*(const Matrix<T,SX,SY> &m,const SymMatrix<T,SY> &s) {
698 Matrix<T,SX,SY> ret;
700 //for (unsigned i=0;i<SX;++i) { // ROWS OF FIRST
701 // for (unsigned j=0;j<SY;++j) { // COLUMNS OF SECOND
702 // T &val = ret.get(i,j);
703 // val = 0.0;
704 // for (unsigned k=0;k<SY;++k) // Add up
705 // val += m.get(i,k)*s.get(k,j);
706 // }
707 //}
708 return ret;
709}
710
716template <class T,unsigned S> class VMatrix : public Matrix<T,S,1> {
717public:
718 using Matrix<T,S,1>::Matrix;
719 using Matrix<T,S,1>::operator=;
720 using iterator = T *;
721 using const_iterator = const T *;
722
724 //constexpr VMatrix() : Matrix<T,S,1>() { }
726 //explicit constexpr VMatrix(const T &t) : Matrix<T,S,1>(t) { }
728 constexpr VMatrix(const VMatrix<T,S> &m) : Matrix<T,S,1>(m) { }
730 constexpr VMatrix(const Matrix<T,S,1> &m) : Matrix<T,S,1>(m) { }
732 constexpr const VMatrix<T,S> &operator=(const VMatrix<T,S> &m) { Matrix<T,S,1>::operator=(m); return *this; }
734 constexpr const VMatrix<T,S> &operator=(const Matrix<T,S,1> &m) { Matrix<T,S,1>::operator=(m); return *this; }
735
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; }
740
742 //const T & get(unsigned x) const { return Matrix<T,S,1>::get(x,0); }
744 //T & get(unsigned x) { return Matrix<T,S,1>::get(x,0); }
746 constexpr const T &operator[](unsigned x) const { return this->get(x); }
748 constexpr T & operator[](unsigned x) { return this->get(x); }
750 //const T & operator()(unsigned x) const { return get(x); }
752 //T & operator()(unsigned x) { return get(x); }
753};
754
758template <unsigned SX,unsigned SY=SX> class DMatrix : public Matrix<double,SX,SY> {
759public:
760 using Matrix<double,SX,SY>::Matrix;
761 using Matrix<double,SX,SY>::operator=;
763 constexpr DMatrix() : Matrix<double,SX,SY>() { }
764 //explicit constexpr DMatrix(const double t[SX][SY]) : Matrix<double,SX,SY>(t) { }
766 //explicit constexpr DMatrix(const double &t) : Matrix<double,SX,SY>(t) { }
768 constexpr DMatrix(const DMatrix<SX,SY> &m) : Matrix<double,SX,SY>(m) { }
770 constexpr DMatrix(const Matrix<double,SX,SY> &m) : Matrix<double,SX,SY>(m) { }
772 constexpr const DMatrix<SX,SY> &operator=(const DMatrix<SX,SY> &m) { Matrix<double,SX,SY>::operator=(m); return *this; }
774 //constexpr const DMatrix<SX,SY> &operator=(const Matrix<double,SX,SY> &m) { Matrix<double,SX,SY>::operator=(m); return *this; }
775};
776
780template <unsigned SX> class DSymMatrix : public SymMatrix<double,SX> {
781public:
783 DSymMatrix() : SymMatrix<double,SX>() { }
785 explicit DSymMatrix(const double &t) : SymMatrix<double,SX>(t) { }
787 DSymMatrix(const DSymMatrix<SX> &m) : SymMatrix<double,SX>(m) { }
789 DSymMatrix(const SymMatrix<double,SX> &m) : SymMatrix<double,SX>(m) { }
794};
795
798template <unsigned S> class DVMatrix : public VMatrix<double,S> {
799public:
800 using VMatrix<double,S>::VMatrix;
801 using VMatrix<double,S>::operator=;
802
804 //DVMatrix() : VMatrix<double,S>() { }
806 //explicit DVMatrix(const double &d) : VMatrix<double,S>(d) { }
808 constexpr DVMatrix(const DVMatrix<S> &m) : VMatrix<double,S>(m) { }
810 constexpr DVMatrix(const Matrix<double,S,1> &m) : VMatrix<double,S>(m) { }
812 const DVMatrix<S> &operator=(const DVMatrix<S> &m) { VMatrix<double,S>::operator=(m); return *this; }
814 const DVMatrix<S> &operator=(const Matrix<double,S,1> &m) { VMatrix<double,S>::operator=(m); return *this; }
815};
816
817template <class T,unsigned S>
818double innerProduct(const VMatrix<T,S> &v1,const VMatrix<T,S> &v2) {
819 double d=0.0;
820 for (uint32 i=0;i<S;++i)
821 d += v1(i)*v2(i);
822 return d;
823}
824
825template <class T>
826double innerProduct(const VMatrix<T,3> &v1,const DVect3 &v2) {
827 double d=0.0;
828 for (unsigned i=0;i<3;++i)
829 d += v1(i)*v2[i];
830 return d;
831}
832
833template <class T>
834double innerProduct(const VMatrix<T,2> &v1,const DVect2 &v2) {
835 double d=0.0;
836 for (unsigned i=0;i<2;++i)
837 d += v1(i)*v2[i];
838 return d;
839}
840
841template <class T,unsigned S>
842Matrix<T,S,S> outerProduct(const VMatrix<T,S> &v1,const VMatrix<T,S> &v2) {
843 Matrix<T,S,S> ret;
844 for (uint32 i=0;i<S;++i) {
845 for (uint32 j=0;j<S;++j)
846 ret(i,j) = v1(i) * v2(j);
847 }
848 return ret;
849}
850
854template <class T>
856 Matrix<T,3,3> ret;
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();
866 return ret;
867}
868
872template <class T>
874 Matrix<T,2,2> ret;
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();
879 return ret;
880}
881
886template <class T>
887constexpr T determinant(const Matrix<T,3,3> &mat) {
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));
891 return t;
892}
893
897template <class T>
898constexpr T determinant(const Matrix<T,2,2> &mat) {
899 return mat.get(0,0) * mat.get(1,1) - mat.get(0,1) * mat.get(1,0);
900}
901
906template <class T>
907constexpr Matrix<T,3,3> inverse(const Matrix<T,3,3> &mat) {
908 // First calculate the adjoint
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);
912
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}};
916 //Matrix<T,3,3> rm;
917 //rm.get(0,0) = a22*a33 - a32*a23;
918 //rm.get(1,0) = -a21*a33 + a31*a23;
919 //rm.get(2,0) = a21*a32 - a31*a22;
920 //rm.get(0,1) = -a12*a33 + a32*a13;
921 //rm.get(1,1) = a11*a33 - a31*a13;
922 //rm.get(2,1) = -a11*a32 + a31*a12;
923 //rm.get(0,2) = a12*a23 - a22*a13;
924 //rm.get(1,2) = -a11*a23 + a21*a13;
925 //rm.get(2,2) = a11*a22 - a21*a12;
926 // Divide by the determinant
927 return rm / determinant(mat);
928}
929
934template <class T>
935constexpr Matrix<T,2,2> inverse(const Matrix<T,2,2> &mat) {
936 Matrix<T,2,2> rm;
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);
941 //Divide by the determinant
942 return rm / determinant(mat);
943}
944
945// Returns both inverse and determinant (Before inverse).
946template <class T>
947constexpr std::tuple<Matrix<T,3,3>,double> inverseDet(const Matrix<T,3,3> &mat) {
948 // First calculate the adjoint
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);
952
953 Matrix<T,3,3> rm;
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;
963 // Divide by the determinant
964 double det = determinant(mat);
965 return {rm / det,det};
966}
967
970template <class T>
971constexpr VMatrix<T,2> toMatrix(const Vector2<T> &v) {
972 VMatrix<T,2> ret;
973 ret.get(0) = v.x();
974 ret.get(1) = v.y();
975 return ret;
976}
977
980template <class T>
981constexpr VMatrix<T,3> toMatrix(const Vector3<T> &v) {
982 VMatrix<T,3> ret;
983 ret.get(0) = v.x();
984 ret.get(1) = v.y();
985 ret.get(2) = v.z();
986 return ret;
987}
988
990template <class T,unsigned SX>
991constexpr VMatrix<T,SX> toVMatrix(const Vector2<T> &v,unsigned start=0) {
992 VMatrix<T,SX> ret(0.0);
993 ret.get(start) = v.x();
994 ret.get(start+1) = v.y();
995 return ret;
996}
997
1000template <unsigned SX> constexpr DVMatrix<SX> toDVMatrix(const DVect2 &v,unsigned start=0) { return toVMatrix<double,SX>(v,start); }
1001
1003template <class T,unsigned SX>
1004constexpr VMatrix<T,SX> toVMatrix(const Vector3<T> &v,unsigned start=0) {
1005 VMatrix<T,SX> ret(0.0);
1006 ret.get(start) = v.x();
1007 ret.get(start+1) = v.y();
1008 ret.get(start+2) = v.z();
1009 return ret;
1010}
1011
1014template <unsigned SX>
1015DVMatrix<SX> constexpr toDVMatrix(const DVect3 &v,unsigned start=0) { return toVMatrix<double,SX>(v,start); }
1016
1019template <class T>
1020constexpr Vector2<T> operator*(const Matrix<T,2,2> &m,const Vector2<T> &v) {
1021 Vector2<T> ret(v.x()*m.get(0,0) + v.y()*m.get(0,1),
1022 v.x()*m.get(1,0) + v.y()*m.get(1,1));
1023 return ret;
1024}
1025
1028template <class T>
1029constexpr Vector2<T> operator*(const SymMatrix<T,2> &m,const Vector2<T> &v) {
1030 Vector2<T> ret(v.x()*m.get(0,0) + v.y()*m.get(0,1),
1031 v.x()*m.get(1,0) + v.y()*m.get(1,1));
1032 return ret;
1033}
1034
1037template <class T>
1038constexpr Vector3<T> operator*(const Matrix<T,3,3> &m,const Vector3<T> &v) {
1039 Vector3<T> ret(v.x()*m.get(0,0) + v.y()*m.get(0,1) + v.z()*m.get(0,2),
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));
1042 return ret;
1043}
1044
1047template <class T>
1049 Vector3<T> ret(v.x()*m.get(0,0) + v.y()*m.get(0,1) + v.z()*m.get(0,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));
1052 return ret;
1053}
1054
1057//template <unsigned SX>
1058//DSymMatrix<SX> toSymMatrix(const SymTensor &s) {
1059// static_assert(SX <= 3);
1060// static_assert(SX >= 2);
1061// DSymMatrix<SX> ret;
1062// ret.get(0,0) = s.s11();
1063// ret.get(0,1) = ret.get(1,0) = s.s12();
1064// ret.get(1,1) = s.s22();
1065// if constexpr (SX > 2) {
1066// ret.get(0,2) = ret.get(2,0) = s.s13();
1067// ret.get(1,2) = ret.get(2,1) = s.s23();
1068// ret.get(2,2) = s.s33();
1069// }
1070// return ret;
1071//}
1072
1075BASE_EXPORT DMatrix<3,3> toMatrix3(const SymTensor &s);
1076BASE_EXPORT DMatrix<2,2> toMatrix2(const SymTensor &s);
1077
1080BASE_EXPORT DMatrix<2,2> toMatrix2(const SymTensor &s);
1081
1084BASE_EXPORT DSymMatrix<3> toSymMatrix3(const SymTensor &s);
1085BASE_EXPORT DSymMatrix<2> toSymMatrix2(const SymTensor &s);
1086
1091 SymTensor ret(m.get(0,0),
1092 m.get(1,1),
1093 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);
1097 return ret;
1098}
1099
1100inline SymTensor toSymTensor(const DMatrix<2,2> &m) {
1101 SymTensor ret(m.get(0,0),
1102 m.get(1,1),
1103 0.0,
1104 (m.get(0,1)+m.get(1,0))*0.5,
1105 0.0,
1106 0.0);
1107 return ret;
1108}
1109
1113 SymTensor ret(m.get(0,0),m.get(1,1),m.get(1,2),
1114 m.get(0,1),m.get(0,2),m.get(1,2));
1115 return ret;
1116}
1117
1119template <class T,unsigned SX>
1120Vector2<T> toVector2(const VMatrix<T,SX> &m,unsigned start=0) { Vector2<T> ret(m(start),m(start+1)); return ret; }
1121
1123template <class T,unsigned SX>
1124Vector3<T> toVector3(const VMatrix<T,SX> &m,unsigned start=0) { Vector3<T> ret(m(start),m(start+1),m(start+2)); return ret; }
1125
1127template <class T>
1128Vector2<T> toVector(const VMatrix<T,2> &m) { Vector2<T> ret(m(0),m(1)); return ret; }
1129
1131template <class T>
1132Vector3<T> toVector(const VMatrix<T,3> &m) { Vector3<T> ret(m(0),m(1),m(2)); return ret; }
1133
1135template <class T,unsigned SY>
1136Vector2<T> columnToVector(const Matrix<T,2,SY> &m,unsigned col) { Vector2<T> ret(m(0,col),m(1,col)); return ret; }
1138template <class T,unsigned SY>
1139Vector3<T> columnToVector(const Matrix<T,3,SY> &m,unsigned col) { Vector3<T> ret(m(0,col),m(1,col),m(2,col)); return ret; }
1141template <class T,unsigned SX>
1142Vector2<T> rowToVector(const Matrix<T,SX,2> &m,unsigned row) { Vector2<T> ret(m(row,0),m(row,1)); return ret; }
1144template <class T,unsigned SX>
1145Vector3<T> rowToVector(const Matrix<T,SX,3> &m,unsigned row) { Vector3<T> ret(m(row,0),m(row,1),m(row,2)); return ret; }
1146
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(); }
1149
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(); }
1152
1153template <class T,unsigned SX,unsigned SY>
1154constexpr void vectorToColumn(Matrix<T,SX,SY> &m,const VMatrix<T,SX> &v,unsigned col) { for (uint32 i=0;i<SX;++i) m(i,col) = v(i); }
1155
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(); }
1158
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(); }
1161
1162template <class T,unsigned SX,unsigned SY>
1163constexpr void vectorToRow(Matrix<T,SX,SY> &m,const VMatrix<T,SY> &v,unsigned row) { for (uint32 j=0;j<SY;++j) m(row,j) = v(j); }
1164
1165template <class T,unsigned SX,unsigned SY>
1166VMatrix<T,SX> column(const Matrix<T,SX,SY> &m,unsigned c) {
1167 VMatrix<T,SX> ret;
1168 for (unsigned i=0;i<SX;++i)
1169 ret(i) = m(i,c);
1170 return ret;
1171}
1172
1173inline DVMatrix<3> operator *(const SymTensor &s,const DVMatrix<3> &v) {
1174 DVMatrix<3> ret;
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];
1178 return ret;
1179}
1180
1181inline DVMatrix<2> operator *(const SymTensor &s,const DVMatrix<2> &v) {
1182 DVMatrix<2> ret;
1183 ret[0] = s.s11()*v[0] + s.s12()*v[1];
1184 ret[1] = s.s12()*v[0] + s.s22()*v[1];
1185 return ret;
1186}
1187
1189// EoF
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
Definition matrix.h:650
debug checked shorthand for std::numeric_limits<T>::
Definition limit.h:25
Definition matrix.h:665
Definition matrix.h:681
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.