Opened 13 years ago
#3786 new Bugs
Incoherent views of various storage order
Reported by: | Owned by: | Ronald Garcia | |
---|---|---|---|
Milestone: | To Be Determined | Component: | multi_array |
Version: | Boost 1.41.0 | Severity: | Problem |
Keywords: | Cc: |
Description
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 :
- a view of the array with limited range in the second dimension
- 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; int 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) *j = 1.0; /*Access usefull data by line*/ paddedExt[0]=258; paddedExt[1]=256; 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(); ++j) output(*j); return EXIT_SUCCESS; }
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
Note:
See TracTickets
for help on using tickets.