Skip to content

Simplify proximity_counter by inheritance from bin_counter - #125

Draft
Minsoo-Kang-space wants to merge 4 commits into
mainfrom
utilities-bin_counter
Draft

Minsoo-Kang-space wants to merge 4 commits into
mainfrom
utilities-bin_counter

Conversation

@Minsoo-Kang-space

@Minsoo-Kang-space Minsoo-Kang-space commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Turn proximity counter into an extension of bin-counter and save a bunch of code by adding the bin limits.

Updating documentation and comments
Adding apply tolerance function
Adding sorting mechanism to proximity target counter

Comment thread models/utilities/bin_counter/include/bin_counter.hh Outdated
Comment thread models/utilities/bin_counter/include/proximity_counter.hh Outdated
CML_ProximityCounter(const CML_ProximityCounter&) = delete;
CML_ProximityCounter& operator=(const CML_ProximityCounter&) = delete;
void insert(double value);
using CML_BinCounter::insert;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This isn't necessary. This line can be removed.

Comment thread models/utilities/bin_counter/src/bin_counter.cc
Comment on lines +246 to +252
if (bins[0].bin_floor != std::numeric_limits<double>::lowest()) {
bins[0].bin_floor -= tol;
}
for (size_t ii = 0; ii < nbin; ii++) {
bins[ii].bin_ceil =
bins[ii+1].bin_floor = bins[ii].bin_ceil - tol;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is an out-of-bounds read when ii == nbin - 1 on the last iteration.

All this loop is intending to do is to decrement the floor and ceiling of bins which aren't the first or last bin by tol. There's no reason to assign ceilings to floors. This could be rewritten to something like

// Double-check, this probably only works if nbin >= 2
for (auto bin = std::next(bins.begin()), end = std::prev(bins.end()); bin != end; ++bin) {
  bin->bin_floor -= tol;
  bin->bin_ceil -= tol;
}
bins[0].bin_ceil -= tol;
bins[nbin - 1].bin_floor -= tol;

if (bins[0].bin_floor != std::numeric_limits<double>::lowest()) {
  bins[0].bin_floor -= tol;
  bins[nbin - 1].bin_ceil -= tol;
}

Regardless, there's definitely future work here to better determine if the dataset has overflow bins or not. Comparing against the lowest double should be a static analysis warning and it's not obvious to someone reading this function why you're comparing against std::numeric_limits<double>::lowest() at first glance. Realistically the boundaries should just be infinity because subtracting a finite number will never change them and you can directly tell that they're overflow bins with std::isinf(). But like I said, that's a refactor for a separate PR.

Comment thread models/utilities/bin_counter/include/proximity_counter.hh Outdated
the bin edge to accommodate that desired allowance.
*****************************************************************************/
void
CML_BinCounter::apply_tolerance(double tol)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This function needs to be tested.

Comment thread models/utilities/bin_counter/src/proximity_counter.cc Outdated
@Minsoo-Kang-space Minsoo-Kang-space changed the title Enhanced Logging Model Content from ramtares_main Change proximity_counter to inherit from bin_counter for simplicity Oct 1, 2026
@Minsoo-Kang-space Minsoo-Kang-space changed the title Change proximity_counter to inherit from bin_counter for simplicity Simplify proximity_counter by inheritance from bin_counter Oct 1, 2026

This branch has not been deployed

No deployments
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