32#include "DGtal/base/Common.h"
33#include "DGtal/math/linalg/SimpleMatrix.h"
34#include "DGtal/math/linalg/CStaticMatrix.h"
35#include "DGtal/math/linalg/CDenseMatrix.h"
36#include "DGtal/math/linalg/CStaticVector.h"
37#include "DGtal/math/linalg/CDenseVector.h"
38#include "DGtal/math/linalg/CLinearAlgebra.h"
39#include "DGtal/helpers/StdDefs.h"
54 unsigned int nbok = 0;
64 m34d.setComponent(1,2, 0.5);
67 nbok += (m34d(1,2) == 0.5) ? 1 : 0;
69 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
70 <<
"true == true" << std::endl;
75 matrix.constant(12.3);
79 res = res && (matrix(i,j) == 12.3);
82 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
83 <<
"all equals to 12.3" << std::endl;
93 unsigned int nbok = 0;
102 M34d m34dbis, resadd, ressub;
110 m34d.setComponent(i,j,i*j);
111 m34dbis.setComponent(i,j,i+j);
112 resadd.setComponent(i,j,i*j+i+j);
113 ressub.setComponent(i,j,i*j-(
double)i-(
double)j);
121 nbok += ((m34d + m34dbis) == resadd) ? 1 : 0;
123 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
124 <<
"ok" << std::endl;
125 nbok += ((m34dbis + m34d) == resadd) ? 1 : 0;
127 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
128 <<
"ok commutative" << std::endl;
132 nbok += (other == m34d) ? 1 : 0;
134 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
135 <<
"ok +=" << std::endl;
140 nbok += ((m34d - m34dbis) == ressub) ? 1 : 0;
145 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
146 <<
"ok simple" << std::endl;
150 nbok += ( (two*2.0) == four) ? 1 : 0;
153 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
154 <<
" [2]*2 == [4]" << std::endl;
156 nbok += ( two == four/2.0) ? 1 : 0;
159 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
160 <<
" [2]= [4]/2" << std::endl;
165 M43d transp = m34d.transpose();
166 nbok += (transp.transpose() == m34d) ? 1 : 0;
168 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
169 <<
"ok idem potent" << std::endl;
180 nbok += (two * one == eight33) ? 1 : 0;
182 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
183 <<
" [2]*[1] = [8]" << std::endl;
194 unsigned int nbok = 0;
207 nbok += (row[1] == 2 ) ? 1 : 0;
209 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
210 <<
" row value" << std::endl;
217 nbok += (col[1] == 2 ) ? 1 : 0;
219 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
220 <<
" col value" << std::endl;
233 nbok += (c == expected) ? 1 : 0;
235 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
236 <<
" mat*row^t" << std::endl;
244 unsigned int nbok = 0;
250 mat2.setComponent(1,1,2);
254 trace.
info() << mat2.determinant() << std::endl;
255 nbok += (mat2.determinant() == 2) ? 1 : 0;
257 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
258 <<
" 2" << std::endl;
264 mat.setComponent(1,1,2);
265 mat.setComponent(2,2,4);
269 nbok += (mat.determinant() == 8) ? 1 : 0;
271 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
272 <<
" 8" << std::endl;
279 mat44.setComponent(1,1,2);
280 mat44.setComponent(2,2,4);
281 mat44.setComponent(3,3,4);
285 trace.
info() << mat44.determinant() << std::endl;
286 nbok += (mat44.determinant() == 32) ? 1 : 0;
288 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
289 <<
" 32" << std::endl;
307 unsigned int nbok = 0;
315 mat2.setComponent(1,1,2);
321 trace.
info() << mat2.inverse() << std::endl;
322 nbok += (( mat2 * mat2.inverse() )== Id2 ) ? 1 : 0;
324 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
325 <<
" M*M^-1=Id" << std::endl;
334 for(
unsigned int i=0; i< 6; i++)
335 for(
unsigned int j=0; j< 6; j++)
342 trace.
info() <<
"M^-1=" <<mat.inverse() << std::endl;
343 trace.
info() <<
"det(M)= "<<mat.determinant() <<std::endl;
344 trace.
info() <<
"M*M^-1= "<<mat.inverse()*mat << std::endl;
356 unsigned int nbok = 0;
360 SimpleMatrix<double, 3, 3> mat = {1, 2, 3, 4, 5, 6, 7, 8, 9};
365 nbok += ( mat( 0, 0 ) == 1 ) ? 1 : 0;
367 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") ";
370 nbok += ( mat( 0, 1 ) == 2 ) ? 1 : 0;
372 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") ";
375 nbok += ( mat( 2, 2 ) == 9 ) ? 1 : 0;
377 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") ";
387 typedef Matrix::ColumnVector
Vector;
403int main(
int argc,
char** argv )
407 for (
int i = 0; i < argc; ++i )
414 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;
Aim: Implements basic operations that will be used in Point and Vector classes.
Aim: implements basic MxN Matrix services (M,N>=1).
ColumnVector column(const DGtal::Dimension j) const
RowVector row(const DGtal::Dimension i) const
void setComponent(const DGtal::Dimension i, const DGtal::Dimension j, const Component &aValue)
void constant(const Component &aScalar)
void beginBlock(const std::string &keyword="")
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::uint32_t Dimension
Aim: Represent any dynamic or static sized matrix having dense representation.
Aim: Represent any dynamic or static sized matrix having dense representation.
Aim: Check right multiplication between matrix and vector and internal matrix multiplication....
Aim: Represent any static sized matrix having sparse or dense representation.
Aim: Represent any static sized column vector having sparse or dense representation.
FreemanChain< int >::Vector Vector