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);
106 std::cout <<
"Matrix saved in matrix.mat file" << std::endl;
112 std::cout <<
"Matrix loaded from matrix.mat file: \n" << M1 << std::endl;
117 std::cout <<
"Matrix saved in matrix.yml file" << std::endl;
123 std::cout <<
"Matrix loaded from matrix.yml file: \n" << M2 << std::endl;
129 std::cout <<
"R: \n" << R << std::endl;
131 std::cout <<
"M1: \n" << M1 << std::endl;
133 std::cout <<
"M2: \n" << M2 << std::endl;
135 std::cout <<
"M3: \n" << M3 << std::endl;
137 std::cout <<
"M4: \n" << M4 << std::endl;
141 std::cout <<
"------------------------" << std::endl;
142 std::cout <<
"--- TEST PRETTY PRINT---" << std::endl;
143 std::cout <<
"------------------------" << std::endl;
147 std::cout <<
"call std::cout << M;" << std::endl;
148 std::cout << M << std::endl;
150 std::cout <<
"call M.print (std::cout, 4);" << std::endl;
151 M.
print (std::cout, 4);
153 std::cout <<
"------------------------" << std::endl;
159 std::cout <<
"call std::cout << M;" << std::endl;
161 std::cout <<
"call M.print (std::cout, 6);" << std::endl;
162 M.
print (std::cout, 6);
163 std::cout << std::endl;
165 std::cout <<
"------------------------" << std::endl;
169 std::cout <<
"call std::cout << M;" << std::endl;
170 std::cout << M << std::endl;
172 std::cout <<
"call M.print (std::cout, 10);" << std::endl;
173 M.print (std::cout, 10);
174 std::cout << std::endl;
176 std::cout <<
"call M.print (std::cout, 2);" << std::endl;
177 M.print (std::cout, 2);
178 std::cout << std::endl;
180 std::cout <<
"------------------------" << std::endl;
183 M[0][2]=-0.0000000876;
184 std::cout <<
"call std::cout << M;" << std::endl;
185 std::cout << M << std::endl;
187 std::cout <<
"call M.print (std::cout, 4);" << std::endl;
188 M.print (std::cout, 4);
189 std::cout << std::endl;
190 std::cout <<
"call M.print (std::cout, 10, \"M\");" << std::endl;
191 M.print (std::cout, 10,
"M");
192 std::cout << std::endl;
193 std::cout <<
"call M.print (std::cout, 20, \"M\");" << std::endl;
194 M.print (std::cout, 20,
"M");
195 std::cout << std::endl;
198 std::cout <<
"------------------------" << std::endl;
199 std::cout <<
"--- TEST RESIZE --------" << std::endl;
200 std::cout <<
"------------------------" << std::endl;
201 std::cout <<
"5x5" << std::endl;
203 std::cout << M << std::endl;
204 std::cout <<
"3x2" << std::endl;
206 std::cout << M << std::endl;
207 std::cout <<
"2x2" << std::endl;
209 std::cout << M << std::endl;
210 std::cout <<
"------------------------" << std::endl;
219 std::cout <<
"------------------------" << std::endl;
220 std::cout <<
"--- TEST vpRowVector * vpColVector" << std::endl;
221 std::cout <<
"------------------------" << std::endl;
234 r.print(std::cout, 2,
"r");
235 c.print(std::cout, 2,
"c");
236 std::cout <<
"r * c = " << rc << std::endl;
238 std::cout <<
"------------------------" << std::endl;
239 std::cout <<
"--- TEST vpRowVector * vpMatrix" << std::endl;
240 std::cout <<
"------------------------" << std::endl;
249 r.
print(std::cout, 2,
"r");
250 M.print(std::cout, 10,
"M");
251 std::cout <<
"r * M = " << rM << std::endl;
253 std::cout <<
"------------------------" << std::endl;
254 std::cout <<
"--- TEST vpGEMM " << std::endl;
255 std::cout <<
"------------------------" << std::endl;
270 vpGEMM(M, N, 2, C, 3, D, VP_GEMM_A_T);
271 std::cout << D << std::endl;
276 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)