Skip to content

Commit

Permalink
SliceIterator::end() fix (#97)
Browse files Browse the repository at this point in the history
* fix problem with 0-size slices and end() sentinels

* adds basic test for slice ietrator fix
  • Loading branch information
weefuzzy authored Feb 14, 2022
1 parent a4bb226 commit 6c921e1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
9 changes: 4 additions & 5 deletions include/data/FluidTensor_Support.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,10 @@ struct SliceIterator

mIndexes[0] = s.extents[0];

// size = s.size;
if (!s.transposed) // Not transposed
endoffset = s.strides[0] * s.extents[0];
else // transposed
endoffset = s.strides[N - 1] * s.extents[N - 1];
if (!s.transposed)
endoffset = s.strides[0] * s.size ;
else
endoffset = s.strides[N - 1] * s.size;
mPtr = end ? base + s.start + endoffset : base + s.start;
}

Expand Down
26 changes: 26 additions & 0 deletions tests/data/TestFluidTensorSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,29 @@ TEST_CASE("SliceIterator does strided iteration","[FluidTensorSupport]"){
REQUIRE(std::equal(colIterator,end,colData.begin()));
}
}



TEST_CASE("SliceIterator end() does sensible things","[FluidTensorSupport]"){

std::array<int,10> data{0,1,2,3,4,5,6,7,8,9};
fluid::FluidTensorView<int,2> view{data.data(),0,1,10};
auto size = GENERATE(0,1,2,3,4,5,6,7,8,9);

using Iterator = fluid::impl::SliceIterator<int,1>;
FluidTensorSlice<1> s(size);

auto colIterator = Iterator(s,data.data());
auto end = Iterator(s,data.data(), true);
size_t distance=std::distance(colIterator,end);

CHECK(size == distance);

auto slice = view(Slice(0),Slice(0,size));
distance=std::distance(slice.begin(),slice.end());
CHECK(size == distance);




}

0 comments on commit 6c921e1

Please sign in to comment.