diff --git a/roofit/roofit/src/BatchHelpers.h b/roofit/roofit/src/BatchHelpers.h index 171a43de845e7..4eb7c15dcff81 100644 --- a/roofit/roofit/src/BatchHelpers.h +++ b/roofit/roofit/src/BatchHelpers.h @@ -76,13 +76,23 @@ class BracketAdapter { class BracketAdapterWithMask { public: - explicit BracketAdapterWithMask(double payload, RooSpan batch) noexcept : + BracketAdapterWithMask(double payload, const RooSpan& batch) noexcept : _isBatch(!batch.empty()), _payload(payload), _pointer(batch.empty() ? &_payload : batch.data()), _mask(batch.empty() ? 0 : ~static_cast(0)) { } + + BracketAdapterWithMask(const BracketAdapterWithMask& other) noexcept: + _isBatch(other._isBatch), + _payload(other._payload), + _pointer(other._isBatch ? other._pointer : &_payload), + _mask(other._mask) + { + } + + BracketAdapterWithMask& operator= (const BracketAdapterWithMask& other) = delete; inline double operator[](std::size_t i) const noexcept { return _pointer[ i & _mask]; diff --git a/roofit/roofit/src/RooPolynomial.cxx b/roofit/roofit/src/RooPolynomial.cxx index 2ea12185237b1..b9c3c993f85c6 100644 --- a/roofit/roofit/src/RooPolynomial.cxx +++ b/roofit/roofit/src/RooPolynomial.cxx @@ -29,16 +29,17 @@ The sum can be truncated at the low end. See the main constructor RooPolynomial::RooPolynomial(const char*, const char*, RooAbsReal&, const RooArgList&, Int_t) **/ -#include -#include - #include "RooPolynomial.h" #include "RooAbsReal.h" #include "RooArgList.h" #include "RooMsgService.h" +#include "BatchHelpers.h" #include "TError.h" +#include +#include +#include using namespace std; ClassImp(RooPolynomial); @@ -154,17 +155,22 @@ namespace PolynomialEvaluate{ void compute( size_t batchSize, const int lowestOrder, double * __restrict__ output, const double * __restrict__ const X, - const RooListProxy& coefList ) + const std::vector& coefList ) { - const int nCoef = coefList.getSize(); - const RooArgSet* normSet = coefList.nset(); - - double fill; - if (nCoef==0 && lowestOrder==0) fill = 0; - else if (nCoef==0 && lowestOrder>0) fill = 1.0; - else fill = static_cast(coefList[nCoef-1]).getVal(normSet); - for (size_t i=0; i0) { + for (size_t i=0; i=0; k-=2) { - double coef1 = static_cast(coefList[k+1]).getVal(normSet); - double coef2 = static_cast(coefList[ k ]).getVal(normSet); for (size_t i=0; i(coefList[0]).getVal(normSet); for (size_t i=0; i RooPolynomial::evaluateBatch(std::size_t begin, std::size_t batchSize) const { RooSpan xData = _x.getValBatch(begin, batchSize); batchSize = xData.size(); - auto output = _batchData.makeWritableBatchUnInit(begin, batchSize); - if (xData.empty()) { - throw std::logic_error("Requested a batch computation, but no batch data available."); + return {}; } - else { - PolynomialEvaluate::compute(batchSize, _lowestOrder, output.data(), xData.data(), _coefList); + + auto output = _batchData.makeWritableBatchUnInit(begin, batchSize); + const int nCoef = _coefList.getSize(); + const RooArgSet* normSet = _coefList.nset(); + std::vector coefList; + for (int i=0; i(_coefList[i]).getVal(normSet); + auto valBatch = static_cast(_coefList[i]).getValBatch(begin, batchSize, normSet); + coefList.push_back( BatchHelpers::BracketAdapterWithMask(val, valBatch) ); } + + PolynomialEvaluate::compute(batchSize, _lowestOrder, output.data(), xData.data(), coefList); + return output; }