44 #include <visp3/core/vpConfig.h>
45 #include <visp3/core/vpDebug.h>
46 #include <visp3/core/vpMath.h>
47 #include <visp3/core/vpHomogeneousMatrix.h>
48 #include <visp3/core/vpVelocityTwistMatrix.h>
49 #include <visp3/core/vpGEMM.h>
54 bool test(
const std::string &s,
const vpMatrix &M,
const std::vector<double> &bench)
56 static unsigned int cpt = 0;
57 std::cout <<
"** Test " << ++cpt << std::endl;
58 std::cout << s <<
"(" << M.
getRows() <<
"," << M.
getCols() <<
") = \n" << M << std::endl;
59 if(bench.size() != M.
size()) {
60 std::cout <<
"Test fails: bad size wrt bench" << std::endl;
63 for (
unsigned int i=0; i<M.
size(); i++) {
64 if (std::fabs(M.
data[i]-bench[i]) > std::fabs(M.
data[i])*std::numeric_limits<double>::epsilon()) {
65 std::cout <<
"Test fails: bad content" << std::endl;
81 std::vector<double> bench(6, 1);
83 if (test(
"M1", M1, bench) ==
false)
86 if (test(
"M2", M2, bench) ==
false)
92 for(
unsigned int i=0; i<M.
getRows(); i++) {
93 for(
unsigned int j=0; j<M.
getCols(); j++) {
98 M.
print (std::cout, 4);
101 N.
init(M, 0, 1, 2, 3);
103 N.
print (std::cout, 4);
104 std::string header(
"My 4-by-5 matrix\nwith a second line");
108 std::cout <<
"Matrix saved in matrix.mat file" << std::endl;
116 std::cout <<
"Matrix loaded from matrix.mat file with header \"" << header_ <<
"\": \n" << M1 << std::endl;
119 if (header != std::string(header_)) {
120 std::cout <<
"Bad header in matrix.mat" << std::endl;
126 std::cout <<
"Matrix saved in matrix.bin file" << std::endl;
132 std::cout <<
"Matrix loaded from matrix.bin file with header \"" << header_ <<
"\": \n" << M1 << std::endl;
135 if (header != std::string(header_)) {
136 std::cout <<
"Bad header in matrix.bin" << std::endl;
142 std::cout <<
"Matrix saved in matrix.yml file" << std::endl;
149 std::cout <<
"Matrix loaded from matrix.yml file with header \"" << header_ <<
"\": \n" << M2 << std::endl;
152 if (header != std::string(header_)) {
153 std::cout <<
"Bad header in matrix.mat" << std::endl;
160 std::cout <<
"R: \n" << R << std::endl;
162 std::cout <<
"M1: \n" << M1 << std::endl;
164 std::cout <<
"M2: \n" << M2 << std::endl;
166 std::cout <<
"M3: \n" << M3 << std::endl;
168 std::cout <<
"M4: \n" << M4 << std::endl;
172 std::cout <<
"------------------------" << std::endl;
173 std::cout <<
"--- TEST PRETTY PRINT---" << std::endl;
174 std::cout <<
"------------------------" << std::endl;
178 std::cout <<
"call std::cout << M;" << std::endl;
179 std::cout << M << std::endl;
181 std::cout <<
"call M.print (std::cout, 4);" << std::endl;
182 M.
print (std::cout, 4);
184 std::cout <<
"------------------------" << std::endl;
190 std::cout <<
"call std::cout << M;" << std::endl;
192 std::cout <<
"call M.print (std::cout, 6);" << std::endl;
193 M.
print (std::cout, 6);
194 std::cout << std::endl;
196 std::cout <<
"------------------------" << std::endl;
200 std::cout <<
"call std::cout << M;" << std::endl;
201 std::cout << M << std::endl;
203 std::cout <<
"call M.print (std::cout, 10);" << std::endl;
204 M.print (std::cout, 10);
205 std::cout << std::endl;
207 std::cout <<
"call M.print (std::cout, 2);" << std::endl;
208 M.print (std::cout, 2);
209 std::cout << std::endl;
211 std::cout <<
"------------------------" << std::endl;
214 M[0][2]=-0.0000000876;
215 std::cout <<
"call std::cout << M;" << std::endl;
216 std::cout << M << std::endl;
218 std::cout <<
"call M.print (std::cout, 4);" << std::endl;
219 M.print (std::cout, 4);
220 std::cout << std::endl;
221 std::cout <<
"call M.print (std::cout, 10, \"M\");" << std::endl;
222 M.print (std::cout, 10,
"M");
223 std::cout << std::endl;
224 std::cout <<
"call M.print (std::cout, 20, \"M\");" << std::endl;
225 M.print (std::cout, 20,
"M");
226 std::cout << std::endl;
229 std::cout <<
"------------------------" << std::endl;
230 std::cout <<
"--- TEST RESIZE --------" << std::endl;
231 std::cout <<
"------------------------" << std::endl;
232 std::cout <<
"5x5" << std::endl;
234 std::cout << M << std::endl;
235 std::cout <<
"3x2" << std::endl;
237 std::cout << M << std::endl;
238 std::cout <<
"2x2" << std::endl;
240 std::cout << M << std::endl;
241 std::cout <<
"------------------------" << std::endl;
250 std::cout <<
"------------------------" << std::endl;
251 std::cout <<
"--- TEST vpRowVector * vpColVector" << std::endl;
252 std::cout <<
"------------------------" << std::endl;
265 r.print(std::cout, 2,
"r");
266 c.print(std::cout, 2,
"c");
267 std::cout <<
"r * c = " << rc << std::endl;
269 std::cout <<
"------------------------" << std::endl;
270 std::cout <<
"--- TEST vpRowVector * vpMatrix" << std::endl;
271 std::cout <<
"------------------------" << std::endl;
280 r.
print(std::cout, 2,
"r");
281 M.print(std::cout, 10,
"M");
282 std::cout <<
"r * M = " << rM << std::endl;
284 std::cout <<
"------------------------" << std::endl;
285 std::cout <<
"--- TEST vpGEMM " << std::endl;
286 std::cout <<
"------------------------" << std::endl;
301 vpGEMM(M, N, 2, C, 3, D, VP_GEMM_A_T);
302 std::cout << D << std::endl;
304 std::cout <<
"All tests succeed" << std::endl;
309 std::cout <<
"Catch an exception: " << e << std::endl;
Implementation of a matrix and operations on matrices.
static bool loadMatrix(const std::string &filename, vpArray2D< double > &M, const bool binary=false, char *header=NULL)
void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify=true)
Implementation of row vector and the associated operations.
error that can be emited by ViSP classes.
Type * data
Address of the first element of the data array.
unsigned int size() const
Return the number of elements of the 2D array.
unsigned int getCols() const
Return the number of columns of the 2D array.
Implementation of a rotation matrix and operations on such kind of matrices.
void init(const vpMatrix &M, unsigned int r, unsigned int c, unsigned int nrows, unsigned int ncols)
Implementation of a velocity twist matrix and operations on such kind of matrices.
unsigned int getRows() const
Return the number of rows of the 2D array.
int print(std::ostream &s, unsigned int length, char const *intro=0) const
static double rad(double deg)
void resize(const unsigned int i, const bool flagNullify=true)
void vpGEMM(const vpArray2D< double > &A, const vpArray2D< double > &B, const double &alpha, const vpArray2D< double > &C, const double &beta, vpArray2D< double > &D, const unsigned int &ops=0)
Implementation of column vector and the associated operations.
int print(std::ostream &s, unsigned int length, char const *intro=0) const
static bool saveMatrixYAML(const std::string &filename, const vpArray2D< double > &M, const char *header="")
static bool saveMatrix(const std::string &filename, const vpArray2D< double > &M, const bool binary=false, const char *header="")
static bool loadMatrixYAML(const std::string &filename, vpArray2D< double > &M, char *header=NULL)