Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.

Figure out what to do about counting_iterator<float> #248

Closed
jaredhoberock opened this issue Nov 1, 2012 · 0 comments · Fixed by #257
Closed

Figure out what to do about counting_iterator<float> #248

jaredhoberock opened this issue Nov 1, 2012 · 0 comments · Fixed by #257
Labels
type: enhancement New feature or request.

Comments

@jaredhoberock
Copy link
Contributor

thrust::counting_iterator<float>::difference_type is float which means it is incompatible with OpenMP.

boost::counting_iterator<float>::difference_type is integral, but apparently not by design.

boost::counting_iterator<float> fails some requirements for random access iterators:

#include <boost/iterator/counting_iterator.hpp>
#include <iostream>

int main()
{
  boost::counting_iterator<float> first = 0;
  boost::counting_iterator<float> last = 0.5;

  std::cout << "first == last: " << (first == last)  << std::endl;
  std::cout << "first < last: "  << (first <  last)  << std::endl;
  std::cout << "last - first: "  << (last  -  first) << std::endl;

  return 0;
}

This program outputs:

first == last: 0
first < last: 0
last - first: 0

It's not consistent for the difference between the two iterators to be 0 and for the two iterators to be unequal.

thrust::counting_iterator<float>::difference_type could be integral, but for this to be consistent, its equality should be based on difference. This would imply

counting_iterator<float>(0) == counting_iterator<float>(0.5)

Which would introduce confusion. Moreover, it's not clear what to do for integers which not representable in floating point.

Reported here.

vamatya pushed a commit to STEllAR-GROUP/thrust that referenced this issue Feb 22, 2013
…difference_type and comparing them.

Add additional testing for these changes.

Reported by Ollie on thrust-users

Fixes NVIDIA#248
kshitij12345 pushed a commit to kshitij12345/thrust that referenced this issue Mar 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: enhancement New feature or request.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant