[Boost-bugs] [Boost C++ Libraries] #3786: Incoherent views of various storage order

Subject: [Boost-bugs] [Boost C++ Libraries] #3786: Incoherent views of various storage order
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-12-21 06:15:34

#3786: Incoherent views of various storage order
 Reporter: Mathieu Leocmach <mathieu.leocmach@…> | Owner: garcia
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: multi_array
  Version: Boost 1.41.0 | Severity: Problem
 Keywords: |
 I have a 256x258 array with only the first 256 lines of interest.
 The flatten memory block contains then 256 interesting values, 2 craps,
 256 interesting values, 2 craps, etc.

 I want to access each column of the interesting block, then each line. For
 this I use :
  1. a view of the array with limited range in the second dimension
  2. a view of line-major ordered array reference to the same block of
 memory, with limited range in the first dimension

 Here is a test code:

 #include <algorithm>
 #include "boost/multi_array.hpp"

 using namespace boost;
 using namespace std;

 main () {
   // Create a 2D array that is 256 x 258
   typedef multi_array<float, 2> array_type;
   typedef multi_array_ref<float, 2> ref_type;
   typedef array_type::array_view<2>::type view_type;

   array<size_t, 3> paddedExt = {256,258};
   array_type A(paddedExt);

   /*Initialize the whole memory block with -1 */
   fill(A.origin(), A.origin()+A.num_elements(),-1.0);

   /*Fill the usefull part of the array by accessing data by column*/
   view_type B = A[indices[range()][range(0,256)]];
   for(view_type::iterator i=B.begin(); i!=B.end(); ++i)
     for(view_type::subarray<1>::type::iterator j=i->begin(); j!=i->end();
       *j = 1.0;

   /*Access usefull data by line*/
   ref_type C(A.origin(), paddedExt, fortran_storage_order);
   view_type D = C[indices[range(0,256)][range()]];
   for(view_type::iterator i=D.begin(); i!=D.end(); ++i)
     for(view_type::subarray<1>::type::iterator j=i->begin(); j!=i->end();



 This outputs a pretty high number of -1 ! More precisely, we have :
  * 256 values
  * 2 craps, 254 values
  * 2 values, 2 craps, 252 values
  * 4 values, 2 craps, 250 values
  * etc.
  * the last 2*256 good values are not output

 It's like the views have lost their index_bases somewhere on the way.

 I compiled and run this test under winXP, mingw32, gcc 3.4.5

Ticket URL: <https://svn.boost.org/trac/boost/ticket/3786>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:02 UTC