refactor: Separate histogram calculation from PartialSet - #2216
Conversation
RobBuchananCompPhys
left a comment
There was a problem hiding this comment.
Looks good! Just a couple of comments including a suggestion that may/may not be worth implementing.
| for (auto &histo : fullHistograms_.linearArray()) | ||
| histo.zeroBins(); | ||
| for (auto &histo : boundHistograms_.linearArray()) | ||
| histo.zeroBins(); | ||
| for (auto &histo : unboundHistograms_.linearArray()) | ||
| histo.zeroBins(); |
There was a problem hiding this comment.
What do you think of a static method in Array2D, flatten, that takes a couple of Array2D<T>'s (like the above full/bound/unboundHistograms_) and flattens their linearArray()s into a single vector?
| for (auto &histo : fullHistograms_.linearArray()) | |
| histo.zeroBins(); | |
| for (auto &histo : boundHistograms_.linearArray()) | |
| histo.zeroBins(); | |
| for (auto &histo : unboundHistograms_.linearArray()) | |
| histo.zeroBins(); | |
| for (auto &histo : Array2D::flatten({fullHistograms_, boundHistograms_, unboundHistograms_})) | |
| histo.zeroBins(); |
I believe the helper method could be implemented like:
static std::vector<A> flatten(const std::vector<Array2D<A>> arrays)
{
std::vector<A> flat;
for (const auto &a : arrays)
flat.insert(flat.end(), a.begin(), a.end());
return flat;
}
There was a problem hiding this comment.
I see what you mean - in fact Adam's zip() operator would allow us to do this in one loop, albeit with three variables. Your suggestion makes a copy of the data, so unfortunately wouldn't have the intended result. I think I will leave this as-is for now, but your suggestion makes me think that some kind of function which takes a lambda and operates on every element in the Array2D would be useful to implement in the future (e.g. fullHistograms_.operate([](auto &histo) { histo.zeroBins(); }))
Co-authored-by: Tristan Youngs <trisyoungs@googlemail.com>
Co-authored-by: Tristan Youngs <trisyoungs@googlemail.com>
This PR splits the histograms for radial distribution function calculation out of
PartialSetinto their ownHistogramSetsince this represented a very specific set of data contained in a quite general-use class otherwise.Required by #2203.