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

Observe multiple from generic input iterators #537

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sjanel
Copy link
Contributor

@sjanel sjanel commented Nov 11, 2021

Addition of an observe method from generic input iterator, with a new unit test.

@sjanel sjanel force-pushed the feature/summaryhistogramenhancedapi branch from 355fced to a7460b8 Compare November 23, 2021 08:10
@sjanel
Copy link
Contributor Author

sjanel commented Feb 27, 2022

Hi, no thoughts about this PR? Thanks

@waldheinz
Copy link

waldheinz commented Mar 22, 2022

Not that my opinion matters here but I had a look anyway, and I like it. 😄

Still, I think this would be even better if

  • there were multiple commits and
  • in the ObserveMultiple method I'd probably like to have the bucket count check upfront, using std::distance(from, end) != bucket_counts_.size(). This way the check is not duplicated and moved out of the loop. Also, we prevent messing up the internal state (in case the "late" check finds that this was in fact invalid input).

@sjanel
Copy link
Contributor Author

sjanel commented Mar 22, 2022

Not that my opinion matters here but I had a look anyway, and I like it. smile

Still, I think this would be even better if

  • there were multiple commits and
  • in the ObserveMultiple method I'd probably like to have the bucket count check upfront, using std::distance(from, end) != bucket_counts_.size(). This way the check is not duplicated and moved out of the loop. Also, we prevent messing up the internal state (in case the "late" check finds that this was in fact invalid input).

Thanks for your remarks!
OK for the split of commits. For the second point, for generic code it's better to iterate only once on the elements as if the iterator is not random access type (for instance, forward iterator only), it may:

  • introduce performance degradation for non random access iterators, but, even worse:
  • have unexpected side effects (or even maybe not possible for some complex iterators) if elements are looped twice.

To leverage above issues coming with generic iterators, I may specialize the function for random access iterators with your proposal. WDYT?

@gjasny
Copy link
Collaborator

gjasny commented Mar 27, 2022

Hello,
would you please split your PR into smaller pieces? That eases review and discussion.
Thanks,
Gregor

@sjanel
Copy link
Contributor Author

sjanel commented Mar 28, 2022

Hi,

OK, here is the first extracted PR with move constructors.

@sjanel sjanel force-pushed the feature/summaryhistogramenhancedapi branch from 0a84248 to 7e32408 Compare April 3, 2022 17:43
@sjanel sjanel changed the title Improve Summary and Histogram API Observe multiple from generic input iterators Apr 3, 2022
@sjanel sjanel force-pushed the feature/summaryhistogramenhancedapi branch from 7e32408 to 76880ac Compare April 3, 2022 18:12
@waldheinz
Copy link

To leverage above issues coming with generic iterators, I may specialize the function for random access iterators with your proposal. WDYT?

The use case I have in mind for the extended API would use an std::array or maybe a std::vector to feed the new method, where an iterator is basically a pointer and std::distance boils down to a subtraction. For those cases doing the check upfront (or maybe even not at all; just mention it's UB in the documentation) would be preferable.

I see there are situations where it's not so clear and a single forward iteration would be preferable. But then I still think the method should either throw an exception on illegal arguments or succeed completely. The proposed implementation would throw an exception after the "damage" has already been done, when some samples have already been merged into the histogram. I consider this problematic. But OTOH I really don't know what to do with this kind of iterators. Maybe it's better to use the old API in this case?

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.

3 participants