Boost logo

Boost Users :

From: Dr Mark H Phillips (mark_at_[hidden])
Date: 2004-01-23 00:21:15


Hi,

I've recently found out about the existence of MultiArray and I
am quite impressed! I was thinking of implementing something
similar myself but now hopefully I don't have to! However I have
a few questions that I'm hoping someone can answer.

Question 1
----------

In the user documentation there is an example which has
some example code:

  for(index i = 0; i != 3; ++i)
    for(index j = 0; j != 4; ++j)
      for(index k = 0; k != 2; ++k)
        A[i][j][k] = values++;

Why can't you change the != into <? Ie, do:

  for(index i = 0; i < 3; ++i)
    for(index j = 0; j < 4; ++j)
      for(index k = 0; k < 2; ++k)
        A[i][j][k] = values++;

or can you? This would be more efficient I should think, and
requiring that index types be ordered shouldn't be too onerous
should it?

Question 2
----------

If I use the built-in "no-frills" C array type to represent a
2-dimensional array in row-major order, then I would access
an element (i, j) by doing:

  a[ &a[0] + i*n + j ]

where a is my m by n array. And if I wish to traverse a, in
row-major order, I can do:

  for (int* ip=&(a[0]); ip<&(a[n*m]); ip+=n) {
    for (int* ijp=&(ip[0]); ijp<&(ip[n]); ++ijp) {
      visit(ijp);
    }
  }

These are a very efficient ways of doing things, but it lacks
somewhat in ease-of-generalization and in readbility. This is where
the MultiArray library is useful. But do I lose in efficiency by
going to MultiArray? Ie, in the simple case where base is 0, stride
is 1, and when we traverse in row-major order, is the MultiArray
library smart enough to do compile-time optimizations to generate
code which is as efficient as the above?

I am guessing that this sort of approach is what the Blitz++ library
does??

Question 3
----------

Is it possible to construct a new
multi_array/multi_array_ref/const_multi_array_ref from an array_view
by doing a deep copy of the view?

A view is a nice way of looking at different parts of a MultiArray
object in a readable way, but sometimes you might wish to turn this
view into a more-efficiently represented object. Is this easy to do
in the MultiArray library?

Question 4
----------

Sometimes you might have an object starts off being mostly
accessed in row-major order, so you want a representation which works
efficiently for this use. But down the track you might wish to change
to mostly column-major access. Does MultiArray provide easy ways to
transform from one underlying representation to another?

Thanks,

Mark Phillips.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net