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

[FIX] Fix const compatibility for the shape_iterator of the kmer_hash view. #1756

Merged
merged 3 commits into from
May 6, 2020

Conversation

smehringer
Copy link
Member

@smehringer smehringer commented Apr 22, 2020

When introducing the iterator test template to the kmer_view, the following does not compile:

  1. iterator urng_t const vs non-const comparison
    EXPECT_TRUE(std::ranges::begin(this->test_range) == std::ranges::cbegin(this->test_range));
  2. iterator const urng_t from iterator urng_t construction
    const_iterator_type it{std::ranges::begin(this->test_range)};

This PR introduces a custom constructor from the non-const version that fixes both problems.
.

@rrahn
Copy link
Contributor

rrahn commented Apr 22, 2020

It would be great to have a bug report for this, which also explains the rationale why this is missing etc. Also since you are now working on that but as part of which issue and which iteration?

@smehringer
Copy link
Member Author

Well, I only discovered this while investigating the coverage miss in #1654 (which was caused by not properly using the iterator_test_template). The minimiser view has the same bug but cannot be fixed before kmer_hash is fixed because it depends on the kmer_hash.
So should I link this to the minimiser view?

@smehringer smehringer requested review from a team and joergi-w and removed request for a team April 23, 2020 04:55
Copy link
Member

@joergi-w joergi-w left a comment

Choose a reason for hiding this comment

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

This PR introduces a template parameter to the comparison operators that fixes this.

I couldn't find the code for this... did you forget to commit something?

And please check the test again. I have tried hard to understand the iterator test template and probably I have missed it, but I couldn't find where you test the shape iterator and I was also expecting to see these lines somewhere that you claimed to fix in this PR:

EXPECT_TRUE(std::ranges::begin(this->test_range) == std::ranges::cbegin(this->test_range));
const_iterator_type it{std::ranges::begin(this->test_range)};

test/unit/range/views/view_kmer_hash_test.cpp Outdated Show resolved Hide resolved
@@ -211,6 +211,9 @@ class kmer_hash_view<urng_t>::shape_iterator
//!\brief The sentinel type of the underlying range.
using sentinel_t = std::ranges::sentinel_t<rng_t>;

template <typename urng2_t>
friend class shape_iterator;
Copy link
Member

Choose a reason for hiding this comment

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

I have 2 questions here:

  1. Why do we need the friend declaration, although shape_iterator is public?
  2. Neither in the modified test nor in the iterator test template the shape_iterator is used. How do you actually test the new functionality?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good question :)
So below, I introduced a new constructor from a shape_iterator which is specialised over a different urng_t. This implies that the two shape_iterators do not have the same type (differnet underlying type).
In order to copy over the members, I need to access them on rhs, but they are declared private. That's why I have to befriend every shape_iterator regardless of its underlying urng_t type in order to be able to access the private members.

Regarding the tests I answered below. If anything is still not clear please ask again :)

Copy link
Member

Choose a reason for hiding this comment

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

Ah thank you, I think I understand now: A class with different template arguments is considered a different class and therefore private and protected member access is prohibited.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes exactly

@smehringer
Copy link
Member Author

This PR introduces a template parameter to the comparison operators that fixes this.

I couldn't find the code for this... did you forget to commit something?

Sorry! I did not update the description! I had the templates there but it did not work because friendship is not transitive. Then Rene pointed out that I do not need to alter the comparison operators if I have the constructor because the constructor allows for implicit conversion.
So now it works with just the constructor.

And please check the test again. I have tried hard to understand the iterator test template and probably I have missed it, but I couldn't find where you test the shape iterator and I was also expecting to see these lines somewhere that you claimed to fix in this PR:

The iterator test template has a member that is test_range which I set to the views::kmer_hash. Now in the iterator test template I always take the begin and end of the kmer_hash view which returns a shape iterator.
So everything in the tests is operating on the shape_iterator. Does this make it clearer?

Copy link
Member

@joergi-w joergi-w left a comment

Choose a reason for hiding this comment

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

Thank you for the explanations and understanding my confusion :)
I think it's fine then!

@smehringer smehringer requested a review from rrahn April 23, 2020 10:58
@smehringer smehringer force-pushed the range_fix branch 2 times, most recently from 7ebe490 to fc17d23 Compare April 24, 2020 14:14
include/seqan3/range/views/kmer_hash.hpp Outdated Show resolved Hide resolved
include/seqan3/range/views/kmer_hash.hpp Outdated Show resolved Hide resolved
test/unit/range/views/view_kmer_hash_test.cpp Outdated Show resolved Hide resolved
test/unit/range/views/view_kmer_hash_test.cpp Outdated Show resolved Hide resolved
test/unit/range/views/view_kmer_hash_test.cpp Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented May 5, 2020

Codecov Report

Merging #1756 into master will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1756      +/-   ##
==========================================
+ Coverage   97.62%   97.64%   +0.01%     
==========================================
  Files         239      239              
  Lines        9061     9112      +51     
==========================================
+ Hits         8846     8897      +51     
  Misses        215      215              
Impacted Files Coverage Δ
include/seqan3/range/views/kmer_hash.hpp 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e9db871...f2ac635. Read the comment docs.

@smehringer smehringer requested a review from rrahn May 6, 2020 04:43
Copy link
Contributor

@rrahn rrahn left a comment

Choose a reason for hiding this comment

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

only one minor thing to avoid confusion about the return type of []-operator. 💅

include/seqan3/range/views/kmer_hash.hpp Outdated Show resolved Hide resolved
@smehringer
Copy link
Member Author

I rebased such that the individual commits can be merged as is afterwards.

@smehringer smehringer requested a review from rrahn May 6, 2020 11:15
@smehringer smehringer merged commit d6a971a into seqan:master May 6, 2020
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.

None yet

3 participants