templatized test function
This commit is contained in:
parent
ff97af692d
commit
cbf123566c
1 changed files with 46 additions and 36 deletions
82
test.cpp
82
test.cpp
|
|
@ -123,53 +123,28 @@ double sum( const T& c )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template< typename T >
|
||||||
int main(int argc, char** argv)
|
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
|
typedef typename cholesky::Cholesky<T>::CovarMat CovarMat;
|
||||||
unsigned int N = 12; // variables number
|
typedef typename cholesky::Cholesky<T>::FactorMat FactorMat;
|
||||||
unsigned int F = 10; // range factor
|
|
||||||
unsigned int R = 1; // nb of repetitions
|
|
||||||
|
|
||||||
if( argc >= 2 ) {
|
cholesky::LLT<T> llt;
|
||||||
M = std::atoi(argv[1]);
|
cholesky::LLTabs<T> llta;
|
||||||
}
|
cholesky::LLTzero<T> lltz;
|
||||||
if( argc >= 3 ) {
|
cholesky::LDLT<T> ldlt;
|
||||||
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<real>::CovarMat CovarMat;
|
|
||||||
typedef cholesky::Cholesky<real>::FactorMat FactorMat;
|
|
||||||
|
|
||||||
cholesky::LLT<real> llt;
|
|
||||||
cholesky::LLTabs<real> llta;
|
|
||||||
cholesky::LLTzero<real> lltz;
|
|
||||||
cholesky::LDLT<real> ldlt;
|
|
||||||
|
|
||||||
unsigned int llt_fail = 0;
|
unsigned int llt_fail = 0;
|
||||||
std::vector<double> s0,s1,s2,s3;
|
std::vector<double> s0,s1,s2,s3;
|
||||||
for( unsigned int n=0; n<R; ++n ) {
|
for( unsigned int n=0; n<R; ++n ) {
|
||||||
|
|
||||||
// a random sample matrix
|
// a random sample matrix
|
||||||
ublas::matrix<real> S(M,N);
|
ublas::matrix<T> S(M,N);
|
||||||
for( unsigned int i=0; i<M; ++i) {
|
for( unsigned int i=0; i<M; ++i) {
|
||||||
for( unsigned int j=0; j<N; ++j) {
|
for( unsigned int j=0; j<N; ++j) {
|
||||||
S(i,j) = F * static_cast<real>(rand())/RAND_MAX;
|
S(i,j) = F * static_cast<T>(rand())/RAND_MAX;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -221,3 +196,38 @@ int main(int argc, char** argv)
|
||||||
std::cout << "\tLLTz: " << sum(s2)/R << std::endl;
|
std::cout << "\tLLTz: " << sum(s2)/R << std::endl;
|
||||||
std::cout << "\tLDLT: " << sum(s3)/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<float>(M,N,F,R,seed);
|
||||||
|
|
||||||
|
std::cout << std::endl << "DOUBLE" << std::endl;
|
||||||
|
test<double>(M,N,F,R,seed);
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue