|
Boost : |
From: tknapen (toon.knapen_at_[hidden])
Date: 2001-12-21 03:42:33
--- In boost_at_y..., Ron Garcia <garcia_at_c...> wrote:
> Hi,
>
> I have uploaded a library called multi_array to the files directory.
2 questions:
1) performance
Have you measered performance compared to plain C-arrays ?
I just wrote a small test in 2 minutes and have some strange results.
The C-array indexing takes 0.9 seconds where-as the multi-array takes
2.92 seconds. (see below for small test program). Can this be due to
the []-indexing.
2) subviews with other value_type
Apparantly, when creating a sub-view, the value_type is automatically
the same as the value_type of the original matrix. Is it possible to
take e.g. a double-view on a complex matrix ?
----------------------
#include "boost/multi_array.hpp"
#include <boost/timer.hpp>
#include <iostream>
#include <cassert>
static const int size = 100;
int
ma () {
typedef boost::multi_array<double, 3> array;
array A(boost::extents[size][size][size]);
// Assign values to the elements
int values = 0;
for(array::index i = 0; i != size; ++i)
for(array::index j = 0; j != size; ++j)
for(array::index k = 0; k != size; ++k)
A[i][j][k] = values++;
// Verify values
int verify = 0;
for(array::index i = 0; i != size; ++i)
for(array::index j = 0; j != size; ++j)
for(array::index k = 0; k != size; ++k)
assert(A[i][j][k] == verify++);
return 0;
}
int ca()
{
double A[size*size*size];
// Assign values to the elements
int values = 0;
for(int i = 0; i != size; ++i)
for(int j = 0; j != size; ++j)
for(int k = 0; k != size; ++k)
A[(((i*size)+j)*size)+k] = values++;
// Verify values
int verify = 0;
for(int i = 0; i != size; ++i)
for(int j = 0; j != size; ++j)
for(int k = 0; k != size; ++k)
assert( A[(((i*size)+j)*size)+k] == verify++ );
return 0;
}
int main()
{
boost::timer t;
for(int i = 0; i < 10 ; ++i ) ca();
std::cout << t.elapsed() << std::endl;
t.restart();
for(int i = 0; i < 10 ; ++i ) ma();
std::cout << t.elapsed() << std::endl;
t.restart();
for(int i = 0; i < 10 ; ++i ) ca();
std::cout << t.elapsed() << std::endl;
return 0;
}
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk