Re: [eigen] New true array class ?

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


Quoting Gael Guennebaud <gael.guennebaud@xxxxxxxxx>:

this is because this was not implemented. done now for sin, cos, exp,
log, abs, and sqrt. feel free to send a patch to support more (I've no
time right now)

Thanks a lot. Perfect.

One more question, the attached test try to compare std::valarray & Eigen::Array for a simple computation.
Eigen::Array is much slower than std::valrray.

It seems that Array copy constructor is called too many times (and posix_memalign with it).

Do you have any idea from where it comes from ?
Is it because of missed inlining ?


Boris.

// g++ -Wall -Wextra -O3 -DNDEBUG -march=native -mtune=native -o test test.cpp -I/home/mansencal/tools/eigen 

#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <vector>

#include <valarray>

#include <Eigen/Core>

#include <sys/time.h>




template <typename V>
void
bench()
{
  const size_t SIZE = 2048;

  const size_t NB_TESTS = 12;
  std::vector<double> times(NB_TESTS);

  double sum = 0;

  for (size_t j=0; j<NB_TESTS; ++j) {


    V  v1(SIZE), v2(SIZE), v3(SIZE);

    for (size_t i=0; i<SIZE; ++i) {
      v1[i] = i/2+M_PI/4;
      v2[i] = i/3-M_PI/7;
      v3[i] = 0.3;
    }

    const size_t NB_REPEATS = 2000;

    V  v4 = v1;

    struct timeval t0, t1;
    gettimeofday(&t0, NULL);

    for (size_t i=0; i<NB_REPEATS; ++i) {

      V  v4 = v1 * M_PI * (v2 * 0.321) * (0.5 * v2);
      v3 += v4;
    }
    gettimeofday(&t1, NULL);
    const double elapsed = (t1.tv_sec-t0.tv_sec)*1000.0 + (t1.tv_usec-t0.tv_usec)/1000.0;

    times[j] = elapsed;

    for (size_t i=0; i<SIZE; ++i)
      sum += v3[i];
  }

  std::sort(times.begin(), times.end());
  const double timeInS = times[times.size()/2];


  std::cerr<<"sum="<<sum<<std::endl;
  std::cerr<<"time: "<<timeInS<<"ms"<<std::endl;
  std::cerr<<std::endl;

}

EIGEN_DONT_INLINE
void
bench_1()
{
  bench<std::valarray<double> >();
}

EIGEN_DONT_INLINE
void
bench_2()
{
  bench<Eigen::ArrayXd >();
}


EIGEN_DONT_INLINE
void
bench_all()
{
  bench_1();

  bench_2();
}

int
main()
{
  bench_all();

  return 0;
}


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/