Skip to content

Improve STL exercise #222

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 3 commits into from
Aug 12, 2022
Merged

Conversation

bernhardmgruber
Copy link
Contributor

  • Prefix STL calls with std::
  • Add const to variables with are not mutated
  • Add lambda based alternative solution

* Prefix STL calls with std::
* Add const to variables with are not mutated
* Add lambda based alternative solution
Copy link
Contributor

@hageboeck hageboeck left a comment

Choose a reason for hiding this comment

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

I might have found a bug, please check.

Comment on lines +44 to +45
const T sum = std::reduce(diffs.begin()+1, diffs.end(), T());
const T sumsq = std::reduce(diffs.begin()+1, diffs.end(), T(), sumsquare<T>());
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const T sum = std::reduce(diffs.begin()+1, diffs.end(), T());
const T sumsq = std::reduce(diffs.begin()+1, diffs.end(), T(), sumsquare<T>());
const T sum = std::reduce(diffs.begin(), diffs.end(), T());
const T sumsq = std::reduce(diffs.begin(), diffs.end(), T(), sumsquare<T>());

Why do you skip the first element? Was this meant to be

    const T sum = std::reduce(diffs.begin(), diffs.end(), diffs[0]);

?

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 think this is correct, since std::adjacent_difference only writes differences starting at element 1. So diffs[0] is just v[0] and diffs[1] is the first difference (v[1] - v[0]).

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I ignored where those values came from. This is correct, but not very intuitive without any explanation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With your suggestions (that I committed), this is resolved now I guess?

bernhardmgruber and others added 2 commits August 12, 2022 14:55
Co-authored-by: Stephan Hageboeck <stephan.hageboeck@cern.ch>
Co-authored-by: Stephan Hageboeck <stephan.hageboeck@cern.ch>
@bernhardmgruber bernhardmgruber merged commit 82f23c3 into hsf-training:master Aug 12, 2022
@bernhardmgruber bernhardmgruber deleted the ref branch August 12, 2022 13:58
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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy