Simplify proximity_counter by inheritance from bin_counter - #125
Minsoo-Kang-space wants to merge 4 commits into
Conversation
| CML_ProximityCounter(const CML_ProximityCounter&) = delete; | ||
| CML_ProximityCounter& operator=(const CML_ProximityCounter&) = delete; | ||
| void insert(double value); | ||
| using CML_BinCounter::insert; |
There was a problem hiding this comment.
This isn't necessary. This line can be removed.
| 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; | ||
| } |
There was a problem hiding this comment.
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.
| the bin edge to accommodate that desired allowance. | ||
| *****************************************************************************/ | ||
| void | ||
| CML_BinCounter::apply_tolerance(double tol) |
There was a problem hiding this comment.
This function needs to be tested.
008c177 to
dd449ba
Compare
…remove deprecated variable for logging, improve readability
6179684 to
812b571
Compare
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