|
Ublas : |
From: Fred (hakonbh_at_[hidden])
Date: 2006-08-16 15:18:05
Hi,
Could you help to decrease time of prod when I use the typedef defined in
the code below?
#include <boost/timer.hpp>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/matrix_sparse.hpp>
#include <boost/numeric/ublas/matrix_proxy.hpp>
#include <boost/numeric/ublas/vector_sparse.hpp>
#include <boost/numeric/ublas/vector_proxy.hpp>
#include <boost/numeric/ublas/vector_of_vector.hpp>
#include <boost/numeric/ublas/operation.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
typedef generalized_vector_of_vector< double, row_major,
boost::numeric::ublas::vector< compressed_vector<double> > > matrix;
typedef compressed_vector<double> vec_d;
// typedef matrix<double> matrix;
// typedef vector<double> vec_d;
boost::timer t1;
double t_final;
matrix m(3,3);
vec_d v(3);
vec_d result;
for (unsigned i = 0; i < std::min (m.size1 (), v.size ()); ++ i) {
for (unsigned j = 0; j < m.size2 (); ++ j)
m (i, j) = 3 * i + j;
v (i) = i;
}
std::cout << m << std::endl;
std::cout << v << std::endl;
int counter = 0;
for(int n=0; n<20 ; ++n)
{
for(int i=0; i<200 ; ++i)
{
t1.restart();
result = prod(m, v);
t_final = t1.elapsed();
if (t_final > 0.01)
{
std::cout << "time = " << t_final << std::endl;
counter++;
}
}
}
std::cout << "counter = " << counter << std::endl;
}
I don't understand why prod spends "0 sec" in some iterations and
"0.016sec" (in my computer) if variables are always the same...
Thank you for your time!
Frederico B. Teixeira
--- UFMG, Brazil