cms-nanoAOD / correctionlib

A generic correction library
https://cms-nanoaod.github.io/correctionlib/
BSD 3-Clause "New" or "Revised" License
16 stars 22 forks source link

Optimize Binning correction in case of uniform bins #181

Closed eguiraud closed 1 year ago

eguiraud commented 1 year ago

This patch teaches the Binning correction type to detect whether the specified binning is uniform or not. If it is, at evaluation time the is found via a simple arithmetic operation rather than via binary search.

For now I have not written new tests because the existing cases in test_core.py already cover uniform as well as non-uniform binning. I can add ad-hoc tests if necessary.

I have not run any benchmarks yet: I wanted to see first whether the design is green-lit first :smile: This design introduces an extra branch ("is binning uniform?") inside Binning::child, which runs in the hot loop. The only way I can think of removing the branch, however, is to introduce one extra correction type, UniformBinning -- which would require a much larger patch. Not sure if worth it?

eguiraud commented 1 year ago

Force-pushed to fix conflicts with trunk.

eguiraud commented 1 year ago

As per our discussion I changed the approach to solving this. The new implementation is at #186 .