root icon indicating copy to clipboard operation
root copied to clipboard

[RF] Vectorize weight evaluation with ```RooDataHist::weights()```

Open HannaOlvhammar opened this issue 3 years ago • 10 comments

This PR improves the speed for evaluating weights in RooHistPdf and RooHistFunc for one dimensional histograms with no interpolation. In the future, RooDataHist::weights() will be extended to cover cases with higher dimensions and interpolation.

The function RooDataHist::weights() was implemented to enable vectorized evaluations of bin weights. In RooHistPdf it is implemented using the new function RooHistPdf::computeBatch(), which calls RooDataHist::weights() in the case of no interpolation and 1D histograms, and RooAbsReal::computeBatch() otherwise. In RooHistFunc::computeBatch, RooDataHist::weights() is called in the case of no interpolation and 1D histograms and is unchanged in the other cases.

RooDataHist::weights() splits the weight evaluation into two cases, depending on whether the bins have uniform width. When the bins are uniform, the bin width and thus the bin index are easily calculated. When they are not uniform, bin indices are stored as a vector using RooAbsBinning::binNumbers, (implemented in #11151) while the bin width is calculated using RooAbsBinning::array().

This Pull request:

Changes or fixes:

Checklist:

  • [x] tested changes locally
  • [ ] updated the docs (if necessary)

HannaOlvhammar avatar Aug 10 '22 15:08 HannaOlvhammar

Can one of the admins verify this patch?

phsft-bot avatar Aug 10 '22 15:08 phsft-bot

@phsft-bot build

guitargeek avatar Aug 10 '22 15:08 guitargeek

Starting build on ROOT-debian10-i386/soversion, ROOT-performance-centos8-multicore/cxx17, ROOT-ubuntu18.04/nortcxxmod, ROOT-ubuntu2004/python3, mac1015/cxx17, mac11/cxx14, windows10/cxx14 How to customize builds

phsft-bot avatar Aug 10 '22 15:08 phsft-bot

Build failed on ROOT-debian10-i386/soversion. Running on pcepsft10.dyndns.cern.ch:/build/workspace/root-pullrequests-build See console output.

Failing tests:

phsft-bot avatar Aug 10 '22 16:08 phsft-bot

Build failed on ROOT-ubuntu18.04/nortcxxmod. Running on sft-ubuntu-1804-2.cern.ch:/build/workspace/root-pullrequests-build See console output.

Failing tests:

phsft-bot avatar Aug 10 '22 16:08 phsft-bot

Build failed on ROOT-ubuntu2004/python3. Running on root-ubuntu-2004-1.cern.ch:/home/sftnight/build/workspace/root-pullrequests-build See console output.

Failing tests:

phsft-bot avatar Aug 10 '22 16:08 phsft-bot

Build failed on windows10/cxx14. Running on null:C:\build\workspace\root-pullrequests-build See console output.

Failing tests:

phsft-bot avatar Aug 10 '22 16:08 phsft-bot

Build failed on mac11/cxx14. Running on macphsft20.dyndns.cern.ch:/Users/sftnight/build/workspace/root-pullrequests-build See console output.

Failing tests:

phsft-bot avatar Aug 10 '22 17:08 phsft-bot

Build failed on mac1015/cxx17. Running on macitois22.dyndns.cern.ch:/Users/sftnight/build/workspace/root-pullrequests-build See console output.

Failing tests:

phsft-bot avatar Aug 10 '22 21:08 phsft-bot

Hello @HannaOlvhammar,

the ``` don't work in commit messages (at least the terminal and github don't react to them). I would recommend to remove them to make the commit message more readable. They are good for markdown-enabled things like the discussion on github or mattermost, though. 🙂 You're doing great with the commit message BTW. It's very informative. Maybe don't promise to do xxx in the message, though. If you don't manage to do it for some reason, the message will for all eternity promise that you will. You could e.g. say "this change will allow for vectorising xxxx"

hageboeck avatar Aug 11 '22 08:08 hageboeck

Thank you both for your comments! While making the changes I found better way to write RooDataHistweights(), mainly removing the check for uniform bins since, in the end, both the uniform and non-uniform binning cases were equally fast when applied to a histogram with uniform bins.

HannaOlvhammar avatar Aug 11 '22 12:08 HannaOlvhammar

@phsft-bot build

guitargeek avatar Aug 11 '22 12:08 guitargeek

Starting build on ROOT-debian10-i386/soversion, ROOT-performance-centos8-multicore/cxx17, ROOT-ubuntu18.04/nortcxxmod, ROOT-ubuntu2004/python3, mac1015/cxx17, mac11/cxx14, windows10/cxx14 How to customize builds

phsft-bot avatar Aug 11 '22 12:08 phsft-bot

Build failed on ROOT-performance-centos8-multicore/cxx17. Running on olbdw-01.cern.ch:/data/sftnight/workspace/root-pullrequests-build See console output.

Failing tests:

phsft-bot avatar Aug 11 '22 13:08 phsft-bot