Re: [eigen] Problem using Boost's zip_iterator on Eigen column vectors

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


Ah, sorry, didn't see your follow-up.  Yeah, that's the issue.

On Sun, Jun 30, 2024 at 5:51 PM Antonio Sanchez <cantonios@xxxxxxxxxx> wrote:
It must be your use of the boost zip iterator in general.  I've never used it before, but replacing the Eigen vector with std::vector results in the same issue.

https://godbolt.org/z/e137hEaj9

On Sat, Jun 29, 2024 at 9:30 PM Kip Warner <kip@xxxxxxxxxxxxxx> wrote:
Hello list,

I noticed today a problem in Boost's zip_iterator traversing well
beyond the end of a pair of equal dimension Eigen column vectors.

I've prepared a minimal below:

   #include <iostream>
   #include <Eigen/Core>
   #include <boost/iterator/zip_iterator.hpp>

   using namespace std;

   int main()
   {
       using ColumnVectorType = Eigen::Matrix<float, 32, 1>;

       ColumnVectorType FirstVector = ColumnVectorType::Zero();
       ColumnVectorType SecondVector = ColumnVectorType::Zero();

       const auto ZipperStart = boost::make_zip_iterator(
           boost::make_tuple(
               std::cbegin(FirstVector),
               std::cbegin(SecondVector)));

       // End...
       const auto ZipperEnd = boost::make_zip_iterator(
           boost::make_tuple(
               std::cend(FirstVector),
               std::cend(SecondVector)));

       int index = 0;

       for(auto Iterator = ZipperStart; ZipperStart != ZipperEnd; ++Iterator)
       {
           std::cout << "Iteration: " << index << std::endl;
         ++index;
       }

       return 0;
   }

Running the above via Godbolt results in iterating the body of the loop
thousands of times when I expected only 32.

   https://godbolt.org/z/fKG77s1ds

I then modified the above code to get rid of the second column vector
and the zip_iterator to iterate via the normal STL interface over the
single column vector. It executes as expected only 32 times.

This is probably just a problem with my usage, but I just wanted to let
the list know in case this is a bug.

--
Kip Warner
OpenPGP signed/encrypted mail preferred
https://www.thevertigo.com


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/