Bug in "test_performance_matrix_times_vector" ?

Michael Lehn <[email protected]> Wed, 1 Sep 2004 11:07:55 +0200
Newsgroups gmane.comp.lib.daixtrose.bugs
Message-ID <[email protected]>
--Boundary-00=_rFZNBYi6j/5pfQs
Content-Type: text/plain;
  charset="us-ascii"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hi

I think there's a bug in "PerformanceOfMatrixTimesVector.C".  First I got an 
index out of range error (some for-loops started at 0).  Second the matrix 
and vector which you setup is probably not what you want, it contains only 
only one row with non-zeros.

I attached the sourcefile with some modifications.

Michael 


--Boundary-00=_rFZNBYi6j/5pfQs
Content-Type: text/x-c++src;
  charset="us-ascii";
  name="PerformanceOfMatrixTimesVector.C"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="PerformanceOfMatrixTimesVector.C"

#include "linalg/Linalg.h"

#include "boost/timer.hpp"

#include <map>
#include <list>
#include <cstddef>
#include <iostream>

typedef Linalg::Matrix<double, std::map<std::size_t, double> > Matrix;
typedef Linalg::Vector<double> Vector;

const int M=4000;
const int N=4000;

void daixtrose_mult_vec()
{
  Matrix A(M, N);
  Vector B(N), C(M);
  
  for(int i=1;i<=M;i++) {
      for(int j=1;j<=N;j++) {
          A(i,j) = i*N+j;
      }
  }
  for(int i=1;i<=N;i++) {
      B(i) = i;
  }

  //I'm desired in the running time of "mult"
  boost::timer t;
  using namespace Daixt::DefaultOps;
  C = A * B;
  std::cerr << "C = A * B took " << t.elapsed() << "s\n";
  /*
  std::cerr << "C = A * B took " << t.elapsed() << "s\n";
  std::cerr << "A = " << A << std::endl;
  std::cerr << "B = " << B << std::endl;
  std::cerr << "C = " << C << std::endl;
  */
}


double  A[M][N], B[N], C[M];

void c_mult_vec()
{
  for(int i=0;i<M;i++) {
      for(int j=0;j<N;j++) {
          A[i][j] = (i+1)*N+j+1;
      }
  }
  for(int i=0;i<N;i++)
  {
      B[i] = i+1;
  }

  //I'm desired in the running time of the code following.
  boost::timer t;
  for(int i=0;i<M;i++)
    for(int k=0;k<N;k++)
      C[i]+=A[i][k]*B[k]; 
  std::cerr << "C version took " << t.elapsed() << "s\n";
  
  /*
  for (int i=0; i<M; ++i) {
      std::cerr << C[i] << std::endl;
  }
  */
}

int main()
{
  try {
    daixtrose_mult_vec();
    c_mult_vec();
  }
  catch (std::exception& e) {
    std::cerr << "\nException:\n" << e.what() << std::endl;
    return EXIT_FAILURE; 
  }
}

--Boundary-00=_rFZNBYi6j/5pfQs--


-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click