YODA::Axis< T, isCAxis< T > > Class Template Reference Continuous axis with floating-point-type edges. More...
Detailed Descriptiontemplate<typename T> class YODA::Axis< T, isCAxis< T > > Continuous axis with floating-point-type edges. Definition at line 326 of file BinnedAxis.h. Member Typedef Documentation◆ CAxisT
template<typename T >
Definition at line 331 of file BinnedAxis.h. ◆ const_iterator
template<typename T >
Definition at line 330 of file BinnedAxis.h. ◆ ContainerT
template<typename T >
Definition at line 329 of file BinnedAxis.h. ◆ EdgeT
template<typename T >
Definition at line 328 of file BinnedAxis.h. Constructor & Destructor Documentation◆ Axis() [1/7]
template<typename T >
Nullary constructor for unique pointers etc. Definition at line 334 of file BinnedAxis.h. 334 {
335 _updateEdges({});
336 _setEstimator();
337 }
◆ Axis() [2/7]
template<typename T >
Concept check shall appear inside body of type's member function or outside of type, since otherwise type is considered incomplete.
Definition at line 560 of file BinnedAxis.h. 560 {
565 static_assert(MetaUtils::checkConcept<Axis<EdgeT>, YODAConcepts::AxisImpl>(),
566 "Axis<T> should implement Axis concept.");
567
568 _est = other._est;
569 _edges = other._edges;
570 _maskedBins = other._maskedBins;
571 }
◆ Axis() [3/7]
template<typename T >
Definition at line 341 of file BinnedAxis.h. 342 : _est(other._est),
343 _maskedBins(std::move(other._maskedBins)),
344 _edges(std::move(other._edges)) {}
◆ Axis() [4/7]
template<typename T >
Constructs continuous Axis from a vector.
Definition at line 642 of file BinnedAxis.h. 642 {
645
646 _updateEdges(std::move(edges));
647
648 _setEstimator();
649 }
std::vector< EdgeT > edges() const noexcept Returns a copy of all axis edges. Includes -inf and +inf edges. Definition BinnedAxis.h:702 ◆ Axis() [5/7]
template<typename T >
Constructs continuous Axis from an initializer list.
Definition at line 652 of file BinnedAxis.h. ◆ Axis() [6/7]
template<typename T >
Merge if equal
In case there have been merges. +1 to account for +inf. Definition at line 594 of file BinnedAxis.h. 594 {
595 if (binsEdges.empty()) throw BinningError("Expected at least one discrete edge");
596
597 std::sort(binsEdges.begin(), binsEdges.end(), [](auto &left, auto &right) {
598 return left.first < right.first;
599 });
600
601 _edges.resize(binsEdges.size()*2+2);
602
603 _edges[0] = -std::numeric_limits<double>::infinity();
604
605
606 /* Edges pairs from binsEdges vector
613 */
614
615 size_t i = 1;
616 for (const auto& pair : binsEdges) {
617 if (!fuzzyGtrEquals(pair.first, _edges[i-1])) throw BinningError("Bin edges shouldn't intersect");
618 if (i == 1 && std::isinf(pair.first) && pair.first < 0) {
619 _edges[i++] = pair.second;
620 continue;
621 }
623 _edges[i++] = pair.second;
624 continue;
625 }
626 if (i != 1 && pair.first > _edges[i-1]) {
628 _maskedBins.emplace_back(i-1);
629 }
630 _edges[i++] = pair.first;
631 _edges[i++] = pair.second;
632 }
633
634 _edges[i] = std::numeric_limits<double>::infinity();
635
636 _edges.resize(i+1);
637
638 _setEstimator();
639 }
std::enable_if_t< std::is_arithmetic_v< N1 > &&std::is_arithmetic_v< N2 >, bool > fuzzyGtrEquals(N1 a, N2 b, double tolerance=1e-5) Compare two numbers for >= with a degree of fuzziness. Definition MathUtils.h:125 std::enable_if_t< std::is_arithmetic_v< N1 > &&std::is_arithmetic_v< N2 > &&(std::is_floating_point_v< N1 >||std::is_floating_point_v< N2 >), bool > fuzzyEquals(N1 a, N2 b, double tolerance=1e-5) Compare two numbers for equality with a degree of fuzziness. Definition MathUtils.h:96 References YODA::fuzzyEquals(), and YODA::fuzzyGtrEquals(). ◆ Axis() [7/7]
template<typename T >
Definition at line 574 of file BinnedAxis.h. 574 {
575 if(upper <= lower)
576 throw(std::logic_error("Upper bound should be larger than lower."));
577 _edges.resize(nBins+1+2);
578 double step = (upper - lower) / nBins;
579
580 _edges[0] = -std::numeric_limits<double>::infinity();
581
582 _edges[1] = lower;
583
584 for(size_t i = 2; i < _edges.size()-1; i++) {
585 _edges[i] = _edges[i-1] + step;
586 }
587
588 _edges[_edges.size()-1] = std::numeric_limits<double>::infinity();
589
590 _setEstimator();
591 }
Member Function Documentation◆ begin()
template<typename T >
Returns the const begin iterator for the edges container. Definition at line 425 of file BinnedAxis.h. 425{ return _edges.cbegin(); }
◆ edge()
template<typename T >
Returns edge corresponding to index. Definition at line 697 of file BinnedAxis.h. 697 {
698 return this->_edges.at(i);
699 }
◆ edges()
template<typename T >
Returns a copy of all axis edges. Includes -inf and +inf edges. Definition at line 702 of file BinnedAxis.h. 702 {
703 return this->_edges;
704 }
◆ end()
template<typename T >
Returns the const end iterator for the edges container. Definition at line 428 of file BinnedAxis.h. 428{ return _edges.cend(); }
◆ hasSameEdges()
template<typename T >
Check if two BinnedAxis objects have the same edges.
Definition at line 707 of file BinnedAxis.h. 707 {
712 }
713 return true;
714 }
size_t numBins(const bool includeOverflows=false) const noexcept Returns amount of bins in axis. Definition BinnedAxis.h:691 References YODA::fuzzyEquals(). ◆ index()
template<typename T >
Bin searcher. Handles low-level bin lookups using a hybrid algorithm that is considerably faster for regular (logarithmic or linear) and near-regular binnings. Comparable performance for irregular binnings. The reason this works is that linear search is faster than bisection search up to about 32-64 elements. So we make a guess, and we then do a linear search. If that fails, then we bisect on the remainder, terminating once bisection search has got the range down to about 32. So we actually pay for the fanciness of predicting the bin out of speeding up the bisection search by finishing it with a linear search. So in most cases, we get constant-time lookups regardless of the space. Definition at line 663 of file BinnedAxis.h. 663 {
664 if (_edges.size() <= 2) throw BinningError("Axis initialised without specifying edges");
665 // Check overflows
666 if (std::isinf(x)) { return x < 0? 0 : _edges.size() - 2; }
667 // Get initial estimate
669 // Return now if this is the correct bin
671
672 // Otherwise refine the estimate, if x is not exactly on a bin edge
679 }
680
683 }
References YODA::SEARCH_SIZElc. ◆ isSubsetEdges()
template<typename T >
Check if other axis edges are a subset of edges of this one.
Skip if any of axes only has two limit edges
Since one of the axes consists only of limits (-inf, +inf), it's a subset of the other one Definition at line 740 of file BinnedAxis.h. 740 {
742
744 if (_edges.size() > 2 && other._edges.size() > 2) {
746 return std::includes(std::next(_edges.begin()), std::prev(_edges.end()),
747 std::next(other._edges.begin()), std::prev(other._edges.end()));
748 }
749
752 return true;
753 }
bool hasSameEdges(const Axis< EdgeT, CAxisT > &other) const noexcept Check if two BinnedAxis objects have the same edges. Definition BinnedAxis.h:707 ◆ maskedBins()
template<typename T >
◆ max()
template<typename T >
Max of bin side on this axis. Definition at line 503 of file BinnedAxis.h. 503 {
504 return _edges[binNum+1];
505 }
◆ mergeBins()
template<typename T >
Merges bins, e.g. removes edges in between.
Definition at line 756 of file BinnedAxis.h. 756 {
757 if (_edges.size() <= 2) throw BinningError("Axis initialised without specifying edges");
758 if (mergeRange.second < mergeRange.first) throw RangeError("Upper index comes before lower index");
759 if (mergeRange.second >= numBins(true)) throw RangeError("Upper index exceeds last visible bin");
760 _edges.erase(_edges.begin()+mergeRange.first+1, _edges.begin() + mergeRange.second + 1);
761 // masked bins above the merge range need to be re-indexed
762 // masked bins within the merge range need to be unmasked
763 std::vector<size_t> toRemove;
764 size_t mrange = mergeRange.second - mergeRange.first;
765 for (size_t i = 0; i < _maskedBins.size(); ++i) {
766 if (_maskedBins[i] > mergeRange.second) _maskedBins[i] -= mrange;
767 else if (_maskedBins[i] >= mergeRange.first) toRemove.push_back(_maskedBins[i]);
768 }
769 if (toRemove.size()) {
770 _maskedBins.erase(
771 std::remove_if(_maskedBins.begin(), _maskedBins.end(), [&](const auto& idx) {
772 return std::find(toRemove.begin(), toRemove.end(), idx) != toRemove.end();
773 }), _maskedBins.end());
774 }
775 }
◆ mid()
template<typename T >
Mid of bin side on this axis.
Definition at line 514 of file BinnedAxis.h. 514 {
516 if(binNum == 0)
517 return std::numeric_limits<EdgeT>::min();
519 return std::numeric_limits<EdgeT>::max();
520
523 }
◆ min()
template<typename T >
Min of bin side on this axis. Definition at line 509 of file BinnedAxis.h. 509 {
510 return _edges[binNum];
511 }
◆ numBins()
template<typename T >
Returns amount of bins in axis. Definition at line 691 of file BinnedAxis.h. 691 {
692 if (_edges.size() < 3) return includeOverflows? 1 : 0; // no visible bin edge
693 return this->_edges.size() - (includeOverflows? 1 : 3); // has 2 extra edges for +-inf
694 }
References YODA::Axis< T, typename >::size(). ◆ operator=() [1/2]
template<typename T >
Definition at line 372 of file BinnedAxis.h. 372 {
373 if (this != &other) {
374 _est = std::move(other._est);
375 _maskedBins = std::move(other._maskedBins);
376 _edges = std::move(other._edges);
377 }
378 return *this;
379 }
◆ operator=() [2/2]
template<typename T >
Definition at line 363 of file BinnedAxis.h. 363 {
364 if (this != &other) {
365 _est = other._est;
366 _maskedBins = other._maskedBins;
367 _edges = other._edges;
368 }
369 return *this;
370 }
◆ sharedEdges()
template<typename T >
Find edges which are shared between BinnedAxis objects, within numeric tolerance.
Skip if any of axes only has two limit edges Definition at line 717 of file BinnedAxis.h. 717 {
718 std::vector<T> intersection;
719
721 if (_edges.size() > 2 && other._edges.size() > 2) {
722 std::set_intersection(std::next(_edges.begin()), std::prev(_edges.end()),
723 std::next(other._edges.begin()), std::prev(other._edges.end()),
724 std::back_inserter(intersection));
725 }
726
727 std::vector<T> rtn;
728 rtn.reserve(intersection.size()+2);
729
731 rtn.insert(std::next(rtn.begin()),
732 std::make_move_iterator(intersection.begin()),
733 std::make_move_iterator(intersection.end()));
735
736 return rtn;
737 }
◆ size()
template<typename T >
Returns amount of bins in axis. Definition at line 686 of file BinnedAxis.h. ◆ type()
template<typename T >
◆ width()
template<typename T >
Width of bin side on this axis. Definition at line 498 of file BinnedAxis.h. 498 {
499 return _edges[binNum+1] - _edges[binNum];
500 }
◆ widths()
template<typename T >
Definition at line 484 of file BinnedAxis.h. 484 {
485 // number of widths = number of edges - 1
486 // unless you exclude under-/overflow
487 size_t offset = includeOverflows? 1 : 3;
488 std::vector<T> ret(_edges.size()-offset);
489 size_t start = 1 + !includeOverflows;
492 ret[i-start] = _edges[i] - _edges[i-1];
493 }
494 return ret;
495 }
const_iterator end() const Returns the const end iterator for the edges container. Definition BinnedAxis.h:428 The documentation for this class was generated from the following file:
Generated on Mon Oct 28 2024 13:47:24 for YODA - Yet more Objects for Data Analysis by 1.9.8 |