Skip to content

Add approximate counting C++ sample code #834

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

Merged
merged 2 commits into from
Aug 24, 2021

Conversation

mika314
Copy link
Contributor

@mika314 mika314 commented Aug 22, 2021

No description provided.

@Amaras Amaras added the Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.) label Aug 22, 2021
@Amaras
Copy link
Member

Amaras commented Aug 22, 2021

Thanks for the PR.
As for my previous review on #835, I'm not comfortable reviewing templated C++ code, so no approving review for me, even if I like your code.

auto approximate_count(int n_items, int a) {
auto v = 0;
for (auto i = 0; i < n_items; ++i)
v = increment(v, a);
Copy link
Contributor

Choose a reason for hiding this comment

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

I have a warning for double to int conversion, because v is of type int and increment returns a double, which would round down the values.

I'm guessing it should be auto v = 0.0 instead?

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 want to reproduce the issue, what compiler are you using, and compilation flags?

// - n_items: number of items to count and loop over
// - a: a scaling value for the logarithm based on Morris's paper
// It returns n(v,a), the approximate count
auto approximate_count(int n_items, int a) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I have a warning on ligne 56 about double to int conversion for the value a. A double is given in, and then it's passed to functions that require it to be double. Maybe it should be double a?

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 want to reproduce the issue, what compiler are you using, and compilation flags?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, I was using GCC with "g++ -std=c++17 -Wall -Wextra -Wshadow -Wnon-virtual-dtor -Wold-style-cast -Wcast-align -Wunused -Woverloaded-virtual -Wpedantic -Wconversion -Wsign-conversion -Wnull-dereference -Wdouble-promotion -Wformat=2"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it should be double, I am extremely confused about how it passed the last test case with a=0.5. Let me spend some time with the test cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mitia, I fix warnings also found the bug in the test.

Copy link
Contributor Author

@mika314 mika314 Aug 23, 2021

Choose a reason for hiding this comment

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

I filed the similar issue on Julia code:
#843

Copy link
Member

@leios leios left a comment

Choose a reason for hiding this comment

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

Looks good! Thanks for the submission and thanks @ShadowMitia for the review!

@leios leios merged commit 10d3f99 into algorithm-archivists:master Aug 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants