Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Add full pair iterator and for_each_full_pair #1973

Merged
merged 6 commits into from
Sep 18, 2024
Merged

Conversation

rprospero
Copy link
Contributor

This adds a FullPairIterator class and a for_each_full_pair algorithm that examines each ordered pair (as opposed to for_each_pair, which only examines unique unordered pairs).

src/classes/fullPairIterator.cpp Outdated Show resolved Hide resolved
Comment on lines 28 to 42
TEST(PairIterTest, FullPairs)
{
int x, y, size = 100;
FullPairIterator it(100);
for (x = 0; x < size; ++x)
{
for (y = 0; y < size; ++y)
{
auto [i, j] = *it;
EXPECT_EQ(i, x);
EXPECT_EQ(j, y);
++it;
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to suggest here that we do a less "pathological" test of the new iterator. Specifically something like taking a full (i.e. not halved) Array2D of random ints and get the sum through both the dumb double x,y loop as well as via the new iterator.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a whole argument for why we shouldn't do this, but now I think that you're right. My argument had been that using the sum test proves that every pair is visited, but doesn't prove that we visited them in the correct order. However, it then becomes a philospohical question of whether there is a correct order or if that should just be considered an implementation detail. I'm now leaning closer to making it an implementation detail, so none of the tests should depend on it.

Also add some comments so no one else wastes time trying to use the
iterator
Copy link
Member

@trisyoungs trisyoungs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think this all looks good, although I'm a bit foggy!

@rprospero rprospero merged commit 0dd660a into develop Sep 18, 2024
10 checks passed
@rprospero rprospero deleted the FullPair branch September 18, 2024 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants