51 #include <visp/vpTime.h>
53 #include <visp/vpMatrix.h>
54 #include <visp/vpColVector.h>
55 #include <visp/vpParseArgv.h>
61 #define GETOPTARGS "h"
63 void usage(
const char *name,
const char *badparam);
64 bool getOptions(
int argc,
const char **argv);
65 bool testSvdOpenCvGSLCoherence(
double epsilon);
67 bool testRandom(
double epsilon);
75 void usage(
const char *name,
const char *badparam)
78 Test various svd decompositions.\n\
89 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
98 bool getOptions(
int argc,
const char **argv)
105 case 'h': usage(argv[0], NULL);
return false;
break;
108 usage(argv[0], optarg_);
113 if ((c == 1) || (c == -1)) {
115 usage(argv[0], NULL);
116 std::cerr <<
"ERROR: " << std::endl;
117 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
123 #define abs(x) ((x) < 0 ? - (x) : (x))
126 bool testRandom(
double epsilon)
131 for (
unsigned int i=0 ; i < L0.getRows() ; i++)
132 for (
unsigned int j=0 ; j < L0.getCols() ; j++)
133 L1[i][j] = L0[i][j] = (
double)rand()/(double)RAND_MAX;
136 vpMatrix V0(L0.getCols(), L0.getCols()) ;
138 vpMatrix V1(L1.getCols(), L1.getCols()) ;
149 for(
unsigned int i=0;i<6;i++)
150 error=std::max(abs(diff[i]),error);
152 return error<epsilon;
158 bool testSvdOpenCvGSLCoherence(
double epsilon)
160 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101) && defined (VISP_HAVE_GSL) // Require opencv >= 2.1.1
174 for (
unsigned int i=0 ; i < A.
getRows() ; i++)
175 for (
unsigned int j=0 ; j < A.
getCols() ; j++)
176 B[i][j] = A[i][j] = (
double)rand()/(double)RAND_MAX;
182 for (
unsigned int i=0 ; i < A.
getRows() ; i++){
183 error = error | (abs(wA[i]-wB[i])>epsilon);
194 main(
int argc,
const char ** argv)
198 if (getOptions(argc, argv) ==
false) {
203 for (
unsigned int i=0 ; i < L.getRows() ; i++)
204 for (
unsigned int j=0 ; j < L.getCols() ; j++)
205 L[i][j] = 2*i+j + cos((
double)(i+j))+((double)(i)) ;
208 std::cout <<
"--------------------------------------"<<std::endl ;
211 vpMatrix V(L.getCols(), L.getCols()) ;
217 std::cout <<
"svdNr Numerical recipes \n time " <<t << std::endl;
219 std::cout <<
"--------------------------------------"<<std::endl ;
227 std::cout <<
"svdGsl_mod \n time " <<t << std::endl;
230 std::cout <<
"--------------------------------------"<<std::endl ;
231 std::cout <<
"TESTING RANDOM MATRICES:" ;
234 for(
unsigned int i=0;i<2000;i++)
235 ret = ret & testRandom(0.00001);
237 std:: cout <<
"Success"<< std:: endl;
239 std:: cout <<
"Fail"<< std:: endl;
241 std::cout <<
"--------------------------------------"<<std::endl ;
244 std::cout <<
"--------------------------------------"<<std::endl ;
245 std::cout <<
"TESTING OPENCV-GSL coherence:" ;
248 for(
unsigned int i=0;i<1;i++)
249 ret2 = ret2 & testSvdOpenCvGSLCoherence(0.00001);
251 std:: cout <<
"Success"<< std:: endl;
253 std:: cout <<
"Fail"<< std:: endl;
255 std::cout <<
"--------------------------------------"<<std::endl ;
261 std::cout <<
"svdFlake\n time " <<t << std::endl;
266 std::cout <<
"Catch an exception: " << e << std::endl;
Definition of the vpMatrix class.
void resize(const unsigned int nrows, const unsigned int ncols, const bool nullify=true)
static vpColVector sort(const vpColVector &v)
sort the elements of vector v
error that can be emited by ViSP classes.
static double measureTimeMs()
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Class that provides a data structure for the column vectors as well as a set of operations on these v...
unsigned int getCols() const
Return the number of columns of the matrix.
unsigned int getRows() const
Return the number of rows of the matrix.
void resize(const unsigned int i, const bool flagNullify=true)