7

I'm wondering a simple way to find the maximum/minimum element of a boost multiarray, an object of 3 indices as the following:

int iDepth=10,iWidth=10,iHeight=10;
boost::multi_array<GLfloat, 3> image(boost::extents[iDepth][iWidth][iHeight]);
linello
  • 8,451
  • 18
  • 63
  • 109

3 Answers3

2

This should work :

std::max_element( image.origin(), image.origin() + image.num_elements());
tunc
  • 519
  • 6
  • 18
0

Using member data() is more correct because:

  1. ensures that image is actually a contiguous (compact array).
  2. scans from the beginning of the array, even if the first elements is not [0][0].... (origin() means the address of [0][0]... even if the array "starts" at a different point, e.g. [1][1]....
std::max_element( image.data(), image.data() + image.num_elements());
alfC
  • 14,261
  • 4
  • 67
  • 118
-2

Did you try something like:

std::max_element( image.begin(), image.end());
Cătălin Pitiș
  • 14,123
  • 2
  • 39
  • 62