diff --git a/test.cpp b/test.cpp index 37de315..dd5a311 100644 --- a/test.cpp +++ b/test.cpp @@ -123,53 +123,28 @@ double sum( const T& c ) - -int main(int argc, char** argv) +template< typename T > +void test( unsigned int M, unsigned int N, unsigned int F, unsigned int R, unsigned int seed = time(0) ) { - srand(time(0)); + srand(seed); - unsigned int M = 10; // sample size - unsigned int N = 12; // variables number - unsigned int F = 10; // range factor - unsigned int R = 1; // nb of repetitions + typedef typename cholesky::Cholesky::CovarMat CovarMat; + typedef typename cholesky::Cholesky::FactorMat FactorMat; - if( argc >= 2 ) { - M = std::atoi(argv[1]); - } - if( argc >= 3 ) { - N = std::atoi(argv[2]); - } - if( argc >= 4 ) { - F = std::atoi(argv[3]); - } - if( argc >= 5 ) { - R = std::atoi(argv[4]); - } - - std::clog << "Usage: test [sample size] [variables number] [random range] [repetitions]" << std::endl; - std::clog << "\tsample size = " << M << std::endl; - std::clog << "\tmatrix size = " << N << std::endl; - std::clog << "\trandom range = " << F << std::endl; - std::clog << "\trepetitions = " << R << std::endl; - - typedef double real; - typedef cholesky::Cholesky::CovarMat CovarMat; - typedef cholesky::Cholesky::FactorMat FactorMat; - - cholesky::LLT llt; - cholesky::LLTabs llta; - cholesky::LLTzero lltz; - cholesky::LDLT ldlt; + cholesky::LLT llt; + cholesky::LLTabs llta; + cholesky::LLTzero lltz; + cholesky::LDLT ldlt; unsigned int llt_fail = 0; std::vector s0,s1,s2,s3; for( unsigned int n=0; n S(M,N); + ublas::matrix S(M,N); for( unsigned int i=0; i(rand())/RAND_MAX; + S(i,j) = F * static_cast(rand())/RAND_MAX; } } @@ -221,3 +196,38 @@ int main(int argc, char** argv) std::cout << "\tLLTz: " << sum(s2)/R << std::endl; std::cout << "\tLDLT: " << sum(s3)/R << std::endl; } + + +int main(int argc, char** argv) +{ + unsigned int seed = time(0); + unsigned int M = 10; // sample size + unsigned int N = 12; // variables number + unsigned int F = 10; // range factor + unsigned int R = 1; // nb of repetitions + + if( argc >= 2 ) { + M = std::atoi(argv[1]); + } + if( argc >= 3 ) { + N = std::atoi(argv[2]); + } + if( argc >= 4 ) { + F = std::atoi(argv[3]); + } + if( argc >= 5 ) { + R = std::atoi(argv[4]); + } + + std::clog << "Usage: test [sample size] [variables number] [random range] [repetitions]" << std::endl; + std::clog << "\tsample size = " << M << std::endl; + std::clog << "\tmatrix size = " << N << std::endl; + std::clog << "\trandom range = " << F << std::endl; + std::clog << "\trepetitions = " << R << std::endl; + + std::cout << std::endl << "FLOAT" << std::endl; + test(M,N,F,R,seed); + + std::cout << std::endl << "DOUBLE" << std::endl; + test(M,N,F,R,seed); +}