51 #include <visp/vpTime.h>
53 #include <visp/vpMatrix.h>
54 #include <visp/vpColVector.h>
55 #include <visp/vpParseArgv.h>
61 #define GETOPTARGS "h"
68 void usage(
const char *name,
const char *badparam)
71 Test various svd decompositions.\n\
82 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
91 bool getOptions(
int argc,
const char **argv)
98 case 'h': usage(argv[0], NULL);
return false;
break;
101 usage(argv[0], optarg);
106 if ((c == 1) || (c == -1)) {
108 usage(argv[0], NULL);
109 std::cerr <<
"ERROR: " << std::endl;
110 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
116 #define abs(x) ((x) < 0 ? - (x) : (x))
120 bool testRandom(
double epsilon)
125 for (
unsigned int i=0 ; i < L0.getRows() ; i++)
126 for (
unsigned int j=0 ; j < L0.getCols() ; j++)
127 L1[i][j] = L0[i][j] = (
double)rand()/(double)RAND_MAX;
132 vpMatrix V0(L0.getCols(), L0.getCols()) ;
134 vpMatrix V1(L1.getCols(), L1.getCols()) ;
145 for(
unsigned int i=0;i<6;i++)
146 error=std::max(abs(diff[i]),error);
148 return error<epsilon;
154 bool testSvdOpenCvGSLCoherence(
double epsilon){
155 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101) && defined (VISP_HAVE_GSL) // Require opencv >= 2.1.1
169 for (
unsigned int i=0 ; i < A.
getRows() ; i++)
170 for (
unsigned int j=0 ; j < A.
getCols() ; j++)
171 B[i][j] = A[i][j] = (
double)rand()/(double)RAND_MAX;
177 for (
unsigned int i=0 ; i < A.
getRows() ; i++){
178 error = error | (abs(wA[i]-wB[i])>epsilon);
189 main(
int argc,
const char ** argv)
192 if (getOptions(argc, argv) ==
false) {
198 for (i=0 ; i < L.getRows() ; i++)
199 for (j=0 ; j < L.getCols() ; j++)
200 L[i][j] = 2*i+j + cos((
double)(i+j))+((double)(i)) ;
203 std::cout <<
"--------------------------------------"<<std::endl ;
206 vpMatrix V(L.getCols(), L.getCols()) ;
212 std::cout <<
"svdNr Numerical recipes \n time " <<t << std::endl;
214 std::cout <<
"--------------------------------------"<<std::endl ;
222 std::cout <<
"svdGsl_mod \n time " <<t << std::endl;
225 std::cout <<
"--------------------------------------"<<std::endl ;
226 std::cout <<
"TESTING RANDOM MATRICES:" ;
229 for(
int i=0;i<2000;i++)
230 ret = ret & testRandom(0.00001);
232 std:: cout <<
"Success"<< std:: endl;
234 std:: cout <<
"Fail"<< std:: endl;
236 std::cout <<
"--------------------------------------"<<std::endl ;
239 std::cout <<
"--------------------------------------"<<std::endl ;
240 std::cout <<
"TESTING OPENCV-GSL coherence:" ;
244 ret2 = ret2 & testSvdOpenCvGSLCoherence(0.00001);
246 std:: cout <<
"Success"<< std:: endl;
248 std:: cout <<
"Fail"<< std:: endl;
250 std::cout <<
"--------------------------------------"<<std::endl ;
256 std::cout <<
"svdFlake\n time " <<t << 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
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)