Boost logo

Boost :

Subject: Re: [boost] [histogram] Working with standard algorithms
From: Bjorn Reese (breese_at_[hidden])
Date: 2017-11-26 11:51:44


On 11/20/2017 12:51 PM, Hans Dembinski wrote:

> I totally see the point for partial_sum. Could you also provide a code example for how you would like to compute the cosine similarity?

A working example using cosine similarity is too large to include here,
but the crux of it is to calculate the cosine similarity between a
histogram h1 and all other histograms in order to determine which of
these other histograms is closest to h1. Anyways, it was just an
example of where it makes sense to use std::inner_product() on two
histograms.

> I think we need several iterators then. The current axis iterators iterate over the bins definition, not really over the bin content of the histogram itself. I chose the current iterators in this way, because I believe this scheme generalises well to the multi-dimensional case. I wouldn't replace these iterators, because they seem useful to me, but additional iterators that iterate over the bin values and play well with algorithms are also clearly needed.
I would rename the current indexing iterator so something like
bin_iterator because it does something special:

   using bin_iterator = unspecified;
   bin_iterator bin_begin() const;
   bin_iterator bin_end() const;

The iterator (and reverse_iterator) types can then be used to traverse
the content.

> - What should this do if h is 2d? The same? If yes, in which order should the 2d array be iterated over?

I would let axis iterators traverse only along the axis. If we need
something to traverse all elements within a multi-dimensional array,
then we probably need something else, such as mdspan [1].

[1] https://github.com/kokkos/array_ref/blob/master/proposals/P0009.rst

> - Writable iterators?

Good argument for const iterators (variance calculation.)


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk