20 std::vector<T> m_data;
30 if (defaultVal ==
nullptr) {
36 iii <= m_size.
x()*m_size.
y();
39 m_data[iii] = T(_defaultVal++);
48 Matrix(int32_t _width=0, int32_t _heigh=0, T* _defaultVal=
nullptr) :
49 m_size(_width, _heigh),
51 if (_defaultVal ==
nullptr) {
57 iii <= m_size.
x()*m_size.
y();
60 m_data[iii] = T(_defaultVal++);
67 template<
class ETK_TYPE_MATRIX_2>
70 etk::
Vector2D<T>(_obj.m_size.x()* _obj.m_size.y()) {
73 iii <= m_size.
x()*m_size.
y();
76 m_data[iii] = T(_obj.m_data[iii]);
107 iii <= m_size.
x()*m_size.
y();
120 return (m_data == _obj.m_data);
129 return (m_data != _obj.m_data);
142 if (m_size != _obj.m_size) {
144 etk::Matrix<T> tmpMatrix(std::max(m_size.
x(),_obj.m_size.
x()), std::max(m_size.
y(),_obj.m_size.
y()));
145 for (int32_t jjj=0; jjj< m_size.
y(); jjj++) {
146 T* tmpPointer = tmpMatrix[jjj];
147 T* tmpPointerIn = (*this)[jjj];
148 for (int32_t iii=0; iii< m_size.
x(); iii++) {
149 tmpPointer[iii] = tmpPointerIn[iii];
152 for (int32_t jjj=0; jjj< _obj.m_size.
y(); jjj++) {
153 T* tmpPointer = tmpMatrix[jjj];
154 T* tmpPointerIn = _obj[jjj];
155 for (int32_t iii=0; iii< _obj.m_size.
x(); iii++) {
156 tmpPointer[iii] += tmpPointerIn[iii];
160 m_size = tmpMatrix.m_size;
161 m_data = tmpMatrix.m_data;
164 for (int32_t iii=0; iii< m_data.size(); iii++) {
165 m_data[iii] += _obj.m_data[iii];
196 if (m_size != _obj.m_size) {
198 etk::Matrix<T> tmpMatrix(std::max(m_size.
x(),_obj.m_size.
x()), std::max(m_size.
y(),_obj.m_size.
y()));
199 for (int32_t jjj=0; jjj< m_size.
y; jjj++) {
200 T* tmpPointer = tmpMatrix[jjj];
201 T* tmpPointerIn = (*this)[jjj];
202 for (int32_t iii=0; iii< m_size.
x(); iii++) {
203 tmpPointer[iii] = tmpPointerIn[iii];
206 for (int32_t jjj=0; jjj< _obj.m_size.
y(); jjj++) {
207 T* tmpPointer = tmpMatrix[jjj];
208 T* tmpPointerIn = _obj[jjj];
209 for (int32_t iii=0; iii< _obj.m_size.
x(); iii++) {
210 tmpPointer[iii] -= tmpPointerIn[iii];
214 m_size = tmpMatrix.m_size;
215 m_data = tmpMatrix.m_data;
218 for (int32_t iii=0; iii< m_data.size(); iii++) {
219 m_data[iii] -= _obj.m_data[iii];
245 if( m_size.
x() != _obj.m_size.
y()
246 || m_size.
y() != _obj.m_size.
x()) {
251 for (int32_t jjj=0; jjj< _obj.m_size.
y(); jjj++) {
252 for (int32_t iii=0; iii< _obj.m_size.
x(); iii++) {
254 for (int32_t kkk=0; kkk< _obj.m_size.
x(); kkk++) {
255 tmpVal += (*this)[jjj][iii+kkk] * _obj[jjj+kkk][iii];
257 tmpMatrix[jjj][iii] = tmpVal;
261 m_data = tmpMatrix.m_data;
284 return &m_data[_yyy*m_size.
x()];
295 return &m_data[_yyy*m_size.
x()];
306 return m_data[_pos.
y()*m_size.
x() + _pos.
x()];
317 return m_data[_pos.
y()*m_size.
x() + _pos.
x()];
329 return m_data[_yyy*m_size.
x() + _xxx];
337 for (int32_t iii=0; iii<m_data.Size(); iii++) {
338 tmp.m_data[iii] = -m_data[iii];
349 for (int32_t jjj=0; jjj< m_size.
y(); jjj++) {
350 for (int32_t iii=0; iii< m_size.
x(); iii++) {
351 tmpMatrix(jjj,iii) = (*this)(iii,jjj);
374 for(int32_t iii=0; iii<m_data.size(); iii++) {
375 tmpVal = m_data[iii];
376 if (tmpVal < 0 && (tmpVal & ~(~0 << _decalage))) {
377 tmpVal = tmpVal >> _decalage;
380 tmpVal = tmpVal >> _decalage;
382 tmppp.m_data[iii] = tmpVal;
393 for(int32_t iii=0; iii<m_data.size(); iii++) {
394 tmppp.m_data[iii] = ( m_data[iii]+(1<<(_decalage-1)) ) >> _decalage;
405 for(int32_t iii=0; iii<m_data.m_size.x() && iii<tmppp.m_size.
x(); iii++) {
406 for(int32_t jjj=0; jjj<m_data.m_size.y() && jjj<tmppp.m_size.
y(); jjj++) {
407 tmppp(iii,jjj) = (*this)(iii,jjj);
421 if (_np < 1 || _nq < 1) {
422 TK_WARNING(
"bad index array sizes");
425 for (int32_t iii=0; iii<_np; iii++) {
426 for (int32_t jjj=0; jjj<_nq; jjj++) {
428 || _p[i] >= m_size.
x()
430 || _q[i] >= m_size.
y()) {
431 TK_WARNING(
"bad index arrays");
433 tmppp(iii,jjj) = (*this)(_p[i],_q[j]);
449 if (m_size.
x() != m_size.
y()) {
450 TK_WARNING(
"better to do with square Matrix");
452 for (int32_t iii=0; iii<m_size.
x(); iii++) {
453 for (int32_t jjj=iii+1; jjj<m_size.
y(); jjj++)
454 m_data[iii*m_size.
x() + jjj] = 0;
469 if (m_size.
x() != m_size.
y()) {
470 TK_WARNING(
"better to do with square Matrix");
472 for (int32_t iii=0; iii<m_size.
x(); iii++) {
473 for (int32_t jjj=0; jjj<m_size.
y() && jjj<iii; jjj++)
474 m_data[iii*m_size.
x() + jjj] = 0;
483 for(int32_t iii=0; iii<m_data.size(); iii++) {
493 if (m_size != _input.m_size) {
494 TK_WARNING(
"better to do with same size Matrix");
498 iii < m_data.size() && iii < _input.m_data.size();
500 T diff = m_data[iii] - _input.m_data[iii];
522 for (int32_t iii=0; iii< m_size.
x()*m_size.
y(); iii++) {
537 for (int32_t iii=0; iii< std::mim(m_size.
x(), m_size.
y()); iii++) {
538 (*this)(iii,iii) = (T)1;
const T & x() const
Get X value.
Definition: Vector2D.hpp:467
Matrix< T > operator*(const Matrix< T > &_obj)
Operator* Multiplication an other matrix with this one.
Definition: Matrix.hpp:269
void eye()
Clear and set the diagonal at 1.
Definition: Matrix.hpp:544
const Matrix< T > & operator*=(const Matrix< T > &_obj)
Operator*= Multiplication an other matrix with this one.
Definition: Matrix.hpp:244
Matrix(const Matrix< ETK_TYPE_MATRIX_2 > &_obj)
Copy contructor with ETK_TYPE_MATRIX_2 type matrix input.
Definition: Matrix.hpp:68
void clearUpperTriangle()
Clear the Upper triangle of the current Matrix.
Definition: Matrix.hpp:448
Matrix< T > transpose() const
Transpose Matrix.
Definition: Matrix.hpp:346
Matrix< T > operator-() const
Operator- Multiply with -1.
Definition: Matrix.hpp:335
const Matrix< T > & operator+=(const Matrix< T > &_obj)
Operator+= Addition an other matrix with this one.
Definition: Matrix.hpp:141
Matrix< T > round(int32_t _decalage) const
generate a devide of the curent Matrix with the specify power of 2
Definition: Matrix.hpp:391
bool operator==(const Matrix< T > &_obj) const
Equality compare operator with an other object.
Definition: Matrix.hpp:119
const uivec2 & size() const
Get the size of the current Matrix.
Definition: Matrix.hpp:552
basic namespace of the etk library. (it might contain all the etk fuctions/class/structures without m...
Definition: Archive.hpp:16
Matrix< T > resize(etk::Vector2D< int32_t > _size) const
Generate a resised matrix.
Definition: Matrix.hpp:403
Matrix< T > select(int32_t _np, int32_t *_p, int32_t _nq, int32_t *_q) const
Select element in the matrix from a list of element Ids.
Definition: Matrix.hpp:420
T maxDifference(const Matrix< T > &_input) const
Return the maximum of the diff for this Matrix.
Definition: Matrix.hpp:492
Matrix(const ivec2 &_size, T *_defaultVal=nullptr)
Contructor that create a Vector with a specific size and specific raw data.
Definition: Matrix.hpp:27
void makeRandom(float _range)
Generate a compleate random Matrix.
Definition: Matrix.hpp:482
Matrix(int32_t _width=0, int32_t _heigh=0, T *_defaultVal=nullptr)
default contructor that create a Vector with a specific size and specific raw data ...
Definition: Matrix.hpp:48
void identity()
Set the matrix identity.
Definition: Matrix.hpp:535
const Matrix< T > & operator=(const Matrix< T > &_obj)
Operator= Asign the current object with an other object.
Definition: Matrix.hpp:89
void clear()
Clear all the matrix.
Definition: Matrix.hpp:520
const T & y() const
Get Y value.
Definition: Vector2D.hpp:474
Matrix< T > fix(int32_t _decalage) const
generate a devide of the curent Matrix with the specify power of 2
Definition: Matrix.hpp:371
void clearLowerTriangle()
Clear the Lower triangle of the current Matrix.
Definition: Matrix.hpp:468
const Matrix< T > & operator-=(const Matrix< T > &_obj)
Operator+= Addition an other matrix with this one.
Definition: Matrix.hpp:195
2 dimention matrix template to manage simpliest algo
Definition: Matrix.hpp:17
virtual ~Matrix()=default
Virtualisation of destructor.
T & operator()(size_t _xxx, size_t _yyy)
Operator() Access at the element at a specific position.
Definition: Matrix.hpp:328
bool operator!=(const Matrix< T > &_obj) const
In-Equality compare operator with an other object.
Definition: Matrix.hpp:128
Matrix< T > operator+(const Matrix< T > &_obj)
Operator+= Addition an other matrix with this one.
Definition: Matrix.hpp:180
const T * operator[](int32_t _yyy) const
Operator[] Access at the first element (const pointer) of a line.
Definition: Matrix.hpp:283
Matrix< T > convolution(Matrix< T > &_obj) const
Create a convolution on the matrix : set convolution on the lines.
Definition: Matrix.hpp:361