Speed optimization for unbinned NaivePoisson background fit #109
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR provides a 25x speed improvement on my M3 MacBook Pro for the
interpolate()method of the unbinned NaivePoisson background fit.Details
The unbinned NaivePoisson background fit contains an
interpolate()method for retrieving background values. This method regenerates the same 1D spline from the underlying_timesand_ratesarrays each time it's called. This takes about 5 ms on my M3 MacBook Pro for 1000 sec of GBM data. Spline creation time should scale with the event number so it will be longer for higher rates and long time periods.This PR moves spline generation into the
fit()method so that it is only called once during the fit process. Subsequent calls tointerpolate()are therefore much faster since we don't need to regenerate the spline. This takes about 0.2 ms on my M3 MacBook Pro for 1000 sec of GBM data.The change shouldn't impact anything other than speed since the spline interpolation doesn't depend on the
tstart,tstoparguments ofinterpolate(). Unit tests passed successfully.Here is a plot showing the distributions of call times on my M3 MacBook Pro for main vs this PR:
