|
Ublas : |
From: Gunter Winkler (guwi17_at_[hidden])
Date: 2007-05-30 18:12:32
Am Mittwoch, 30. Mai 2007 21:37 schrieb Albert Strasheim:
> Do you have any other suggestions for how to accomplish this without
> needing extra memory?
Another note. The noalias speeds up both version:
* without noalias() (g++ -O2 -DNDEBUG)
for loop: 1.4 s
outer_prod: failed
* with noalias()
for loop: 1.1 s
outer_prod: 1.1 s
(I see _no_ time difference)
#include <boost/timer.hpp>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/matrix_proxy.hpp>
#include <boost/numeric/ublas/vector.hpp>
using namespace boost::numeric::ublas;
int main(int argc, char* argv[])
{
matrix<double> A(scalar_matrix<double>(196608, 1024, 1.0));
vector<double> b(scalar_vector<double>(A.size2(),1.0));
scalar_vector<double> e(A.size1(), 1.0);
boost::timer t;
t.restart();
#if 1
noalias( A ) += outer_prod(e, b);
#else
for (std::size_t i = 0; i < A.size1(); ++i)
{
noalias( row(A, i) ) += b;
}
#endif
std::cout << "time " << t.elapsed() << " s\n";
return 0;
}
mfg
Gunter