mirror of
https://github.com/boostorg/multi_array.git
synced 2025-05-11 21:33:52 +00:00
Fixes #1127
array views were not handling negative strides properly. Thanks to Phil Richards for pointing that out. [SVN r38482]
This commit is contained in:
parent
13259f4def
commit
bcb10816f1
@ -437,13 +437,16 @@ protected:
|
||||
index start = current_range.get_start(default_start);
|
||||
index finish = current_range.get_finish(default_finish);
|
||||
index index_factor = current_range.stride();
|
||||
index len = (finish - start + (index_factor - 1)) / index_factor;
|
||||
|
||||
// integral trick for ceiling((finish-start) / index_factor)
|
||||
index shrinkage = index_factor > 0 ? 1 : -1;
|
||||
index len = (finish - start + (index_factor - shrinkage)) / index_factor;
|
||||
|
||||
BOOST_ASSERT(index_bases[n] <= start &&
|
||||
start <= index_bases[n]+index(extents[n]));
|
||||
BOOST_ASSERT(index_bases[n] <= finish &&
|
||||
finish <= index_bases[n]+index(extents[n]));
|
||||
BOOST_ASSERT(index_factor > 0);
|
||||
BOOST_ASSERT(index_factor != 0);
|
||||
|
||||
// the array data pointer is modified to account for non-zero
|
||||
// bases during slicing (see [Garcia] for the math involved)
|
||||
|
@ -90,6 +90,28 @@ void test_views(Array& A, const ViewTraits&) {
|
||||
BOOST_CHECK(B(elmts) == A[idx0+i][idx1+1][idx2+j*2]);
|
||||
}
|
||||
}
|
||||
|
||||
// Flip the third dimension
|
||||
{
|
||||
typename ViewTraits::array_view3 B = A[
|
||||
indices[range(idx0+0,idx0+2)]
|
||||
[range(idx1+0,idx1+2)]
|
||||
[range(idx2+2,idx2+0,-1)]
|
||||
];
|
||||
|
||||
// typename ViewTraits::array_view3 B =
|
||||
// A[indices[range(idx0+0,idx0+2)][idx1+1][range(idx2+0,idx2+4,2)]];
|
||||
|
||||
for (index i = 0; i != 2; ++i)
|
||||
for (index j = 0; j != 2; ++j)
|
||||
for (index k = 0; k != 2; ++k) {
|
||||
BOOST_CHECK(B[i][j][k] == A[idx0+i][idx1+j][idx2+2-k]);
|
||||
boost::array<index,3> elmts;
|
||||
elmts[0]=i; elmts[1]=j; elmts[2]=k;
|
||||
BOOST_CHECK(B(elmts) == A[idx0+i][idx1+j][idx2+2-k]);
|
||||
}
|
||||
}
|
||||
|
||||
++tests_run;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user