Skip to content

Commit

Permalink
[RF] EvaluateBatch() now returns empty span in abscence of any batches.
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmanouil Michalainas authored and hageboeck committed Oct 9, 2019
1 parent b57da2a commit f02dc04
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 152 deletions.
32 changes: 16 additions & 16 deletions roofit/roofit/src/RooArgusBG.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Double_t RooArgusBG::evaluate() const {

////////////////////////////////////////////////////////////////////////////////

namespace ArgusBatchEvaluate {
namespace {
//Author: Emmanouil Michalainas, CERN 19 AUGUST 2019

template<class Tm, class Tm0, class Tc, class Tp>
Expand All @@ -112,26 +112,26 @@ void compute( size_t batchSize,

RooSpan<double> RooArgusBG::evaluateBatch(std::size_t begin, std::size_t batchSize) const {
using namespace BatchHelpers;
using namespace ArgusBatchEvaluate;

EvaluateInfo info = getInfo( {&m,&m0,&c,&p}, begin, batchSize );
auto output = _batchData.makeWritableBatchUnInit(begin, info.size);
auto mData = m.getValBatch(begin, info.size);

EvaluateInfo info = getInfo( {&m, &m0, &c, &p}, begin, batchSize );
if (info.nBatches == 0) {
throw std::logic_error("Requested a batch computation, but no batch data available.");
return {};
}
else if (info.nBatches==1 && !mData.empty()) {
compute(info.size, output.data(), mData.data(),
BracketAdapter<double> (m0),
BracketAdapter<double> (c),
auto output = _batchData.makeWritableBatchUnInit(begin, batchSize);
auto mData = m.getValBatch(begin, info.size);

if (info.nBatches==1 && !mData.empty()) {
compute(info.size, output.data(), mData.data(),
BracketAdapter<double> (m0),
BracketAdapter<double> (c),
BracketAdapter<double> (p));
}
else {
compute(info.size, output.data(),
BracketAdapterWithMask (m,m.getValBatch(begin,batchSize)),
BracketAdapterWithMask (m0,m0.getValBatch(begin,batchSize)),
BracketAdapterWithMask (c,c.getValBatch(begin,batchSize)),
BracketAdapterWithMask (p,p.getValBatch(begin,batchSize)));
compute(info.size, output.data(),
BracketAdapterWithMask (m,m.getValBatch(begin,info.size)),
BracketAdapterWithMask (m0,m0.getValBatch(begin,info.size)),
BracketAdapterWithMask (c,c.getValBatch(begin,info.size)),
BracketAdapterWithMask (p,p.getValBatch(begin,info.size)));
}
return output;
}
Expand Down
18 changes: 8 additions & 10 deletions roofit/roofit/src/RooBernstein.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Double_t RooBernstein::evaluate() const

////////////////////////////////////////////////////////////////////////////////

namespace BernsteinEvaluate {
namespace {
//Author: Emmanouil Michalainas, CERN 16 AUGUST 2019

void compute( size_t batchSize, double xmax, double xmin,
Expand Down Expand Up @@ -192,17 +192,15 @@ void compute( size_t batchSize, double xmax, double xmin,

RooSpan<double> RooBernstein::evaluateBatch(std::size_t begin, std::size_t batchSize) const {
auto 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.");
}
else {
const double xmax = _x.max();
const double xmin = _x.min();
BernsteinEvaluate::compute(batchSize, xmax, xmin, output.data(), xData.data(), _coefList);
return {};
}

batchSize = xData.size();
auto output = _batchData.makeWritableBatchUnInit(begin, batchSize);
const double xmax = _x.max();
const double xmin = _x.min();
compute(batchSize, xmax, xmin, output.data(), xData.data(), _coefList);
return output;
}

Expand Down
32 changes: 16 additions & 16 deletions roofit/roofit/src/RooBifurGauss.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Double_t RooBifurGauss::evaluate() const {

////////////////////////////////////////////////////////////////////////////////

namespace BifurGaussBatchEvaluate {
namespace {
//Author: Emmanouil Michalainas, CERN 20 AUGUST 2019

template<class Tx, class Tm, class Tsl, class Tsr>
Expand All @@ -107,26 +107,26 @@ void compute( size_t batchSize,

RooSpan<double> RooBifurGauss::evaluateBatch(std::size_t begin, std::size_t batchSize) const {
using namespace BatchHelpers;
using namespace BifurGaussBatchEvaluate;

EvaluateInfo info = getInfo( {&x,&mean,&sigmaL,&sigmaR}, begin, batchSize );
auto output = _batchData.makeWritableBatchUnInit(begin, info.size);
auto xData = x.getValBatch(begin, info.size);

EvaluateInfo info = getInfo( {&x, &mean, &sigmaL, &sigmaR}, begin, batchSize );
if (info.nBatches == 0) {
throw std::logic_error("Requested a batch computation, but no batch data available.");
return {};
}
else if (info.nBatches==1 && !xData.empty()) {
compute(info.size, output.data(), xData.data(),
BracketAdapter<double> (mean),
BracketAdapter<double> (sigmaL),
auto output = _batchData.makeWritableBatchUnInit(begin, batchSize);
auto xData = x.getValBatch(begin, info.size);

if (info.nBatches==1 && !xData.empty()) {
compute(info.size, output.data(), xData.data(),
BracketAdapter<double> (mean),
BracketAdapter<double> (sigmaL),
BracketAdapter<double> (sigmaR));
}
else {
compute(info.size, output.data(),
BracketAdapterWithMask (x,x.getValBatch(begin,batchSize)),
BracketAdapterWithMask (mean,mean.getValBatch(begin,batchSize)),
BracketAdapterWithMask (sigmaL,sigmaL.getValBatch(begin,batchSize)),
BracketAdapterWithMask (sigmaR,sigmaR.getValBatch(begin,batchSize)));
compute(info.size, output.data(),
BracketAdapterWithMask (x,x.getValBatch(begin,info.size)),
BracketAdapterWithMask (mean,mean.getValBatch(begin,info.size)),
BracketAdapterWithMask (sigmaL,sigmaL.getValBatch(begin,info.size)),
BracketAdapterWithMask (sigmaR,sigmaR.getValBatch(begin,info.size)));
}
return output;
}
Expand Down
16 changes: 7 additions & 9 deletions roofit/roofit/src/RooBreitWigner.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Double_t RooBreitWigner::evaluate() const

////////////////////////////////////////////////////////////////////////////////

namespace BreitWignerBatchEvaluate {
namespace {
//Author: Emmanouil Michalainas, CERN 21 August 2019

template<class Tx, class Tmean, class Twidth>
Expand All @@ -85,17 +85,19 @@ void compute( size_t batchSize,

RooSpan<double> RooBreitWigner::evaluateBatch(std::size_t begin, std::size_t batchSize) const {
using namespace BatchHelpers;
using namespace BreitWignerBatchEvaluate;
auto xData = x.getValBatch(begin, batchSize);
auto meanData = mean.getValBatch(begin, batchSize);
auto widthData = width.getValBatch(begin, batchSize);
const bool batchX = !xData.empty();
const bool batchMean = !meanData.empty();
const bool batchWidth = !widthData.empty();

if (!batchX && !batchMean && !batchWidth) {
return {};
}
batchSize = findSize({ xData, meanData, widthData });
auto output = _batchData.makeWritableBatchUnInit(begin, batchSize);

const bool batchX = !xData.empty();
const bool batchMean = !meanData.empty();
const bool batchWidth = !widthData.empty();
if (batchX && !batchMean && !batchWidth ) {
compute(batchSize, output.data(), xData, BracketAdapter<double>(mean), BracketAdapter<double>(width));
}
Expand All @@ -117,10 +119,6 @@ RooSpan<double> RooBreitWigner::evaluateBatch(std::size_t begin, std::size_t bat
else if (batchX && batchMean && batchWidth ) {
compute(batchSize, output.data(), xData, meanData, widthData);
}
else{
throw std::logic_error("Requested a batch computation, but no batch data available.");
}

return output;
}

Expand Down
40 changes: 20 additions & 20 deletions roofit/roofit/src/RooBukinPdf.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Double_t RooBukinPdf::evaluate() const

////////////////////////////////////////////////////////////////////////////////////////

namespace BukinBatchEvaluate {
namespace {
//Author: Emmanouil Michalainas, CERN 26 JULY 2019

template<class Tx, class TXp, class TSigp, class Txi, class Trho1, class Trho2>
Expand Down Expand Up @@ -192,30 +192,30 @@ void compute( size_t batchSize,

RooSpan<double> RooBukinPdf::evaluateBatch(std::size_t begin, std::size_t batchSize) const {
using namespace BatchHelpers;
using namespace BukinBatchEvaluate;

EvaluateInfo info = getInfo( {&x,&Xp,&sigp,&xi,&rho1,&rho2}, begin, batchSize );
auto output = _batchData.makeWritableBatchUnInit(begin, info.size);
auto xData = x.getValBatch(begin, info.size);

EvaluateInfo info = getInfo( {&x, &Xp, &sigp, &xi, &rho1, &rho2}, begin, batchSize );
if (info.nBatches == 0) {
throw std::logic_error("Requested a batch computation, but no batch data available.");
return {};
}
else if (info.nBatches==1 && !xData.empty()) {
compute(info.size, output.data(), xData.data(),
BracketAdapter<double> (Xp),
BracketAdapter<double> (sigp),
BracketAdapter<double> (xi),
BracketAdapter<double> (rho1),
auto output = _batchData.makeWritableBatchUnInit(begin, batchSize);
auto xData = x.getValBatch(begin, info.size);

if (info.nBatches==1 && !xData.empty()) {
compute(info.size, output.data(), xData.data(),
BracketAdapter<double> (Xp),
BracketAdapter<double> (sigp),
BracketAdapter<double> (xi),
BracketAdapter<double> (rho1),
BracketAdapter<double> (rho2));
}
else {
compute(info.size, output.data(),
BracketAdapterWithMask (x,x.getValBatch(begin,batchSize)),
BracketAdapterWithMask (Xp,Xp.getValBatch(begin,batchSize)),
BracketAdapterWithMask (sigp,sigp.getValBatch(begin,batchSize)),
BracketAdapterWithMask (xi,xi.getValBatch(begin,batchSize)),
BracketAdapterWithMask (rho1,rho1.getValBatch(begin,batchSize)),
BracketAdapterWithMask (rho2,rho2.getValBatch(begin,batchSize)));
compute(info.size, output.data(),
BracketAdapterWithMask (x,x.getValBatch(begin,info.size)),
BracketAdapterWithMask (Xp,Xp.getValBatch(begin,info.size)),
BracketAdapterWithMask (sigp,sigp.getValBatch(begin,info.size)),
BracketAdapterWithMask (xi,xi.getValBatch(begin,info.size)),
BracketAdapterWithMask (rho1,rho1.getValBatch(begin,info.size)),
BracketAdapterWithMask (rho2,rho2.getValBatch(begin,info.size)));
}
return output;
}
23 changes: 11 additions & 12 deletions roofit/roofit/src/RooCBShape.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Double_t RooCBShape::evaluate() const {

////////////////////////////////////////////////////////////////////////////////

namespace CBShapeBatchEvaluate {
namespace {
//Author: Emmanouil Michalainas, CERN 21 August 2019

template<class Tm, class Tm0, class Tsigma, class Talpha, class Tn>
Expand Down Expand Up @@ -121,16 +121,15 @@ void compute( size_t batchSize,

RooSpan<double> RooCBShape::evaluateBatch(std::size_t begin, std::size_t batchSize) const {
using namespace BatchHelpers;
using namespace CBShapeBatchEvaluate;

EvaluateInfo info = getInfo( {&m, &m0, &sigma, &alpha, &n}, begin, batchSize );
auto output = _batchData.makeWritableBatchUnInit(begin, batchSize);

auto mData = m.getValBatch(begin, info.size);
if (info.nBatches == 0) {
throw std::logic_error("Requested a batch computation, but no batch data available.");
return {};
}
else if (info.nBatches==1 && !mData.empty()) {
auto output = _batchData.makeWritableBatchUnInit(begin, batchSize);
auto mData = m.getValBatch(begin, info.size);

if (info.nBatches==1 && !mData.empty()) {
compute(info.size, output.data(), mData.data(),
BracketAdapter<double> (m0),
BracketAdapter<double> (sigma),
Expand All @@ -139,11 +138,11 @@ RooSpan<double> RooCBShape::evaluateBatch(std::size_t begin, std::size_t batchSi
}
else {
compute(info.size, output.data(),
BracketAdapterWithMask (m,m.getValBatch(begin,batchSize)),
BracketAdapterWithMask (m0,m0.getValBatch(begin,batchSize)),
BracketAdapterWithMask (sigma,sigma.getValBatch(begin,batchSize)),
BracketAdapterWithMask (alpha,alpha.getValBatch(begin,batchSize)),
BracketAdapterWithMask (n,n.getValBatch(begin,batchSize)));
BracketAdapterWithMask (m,m.getValBatch(begin,info.size)),
BracketAdapterWithMask (m0,m0.getValBatch(begin,info.size)),
BracketAdapterWithMask (sigma,sigma.getValBatch(begin,info.size)),
BracketAdapterWithMask (alpha,alpha.getValBatch(begin,info.size)),
BracketAdapterWithMask (n,n.getValBatch(begin,info.size)));
}
return output;
}
Expand Down
18 changes: 8 additions & 10 deletions roofit/roofit/src/RooChebychev.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ Double_t RooChebychev::evaluate() const

////////////////////////////////////////////////////////////////////////////////

namespace ChebychevEvaluate {
namespace {
//Author: Emmanouil Michalainas, CERN 12 AUGUST 2019

void compute( size_t batchSize, double xmax, double xmin,
Expand Down Expand Up @@ -223,17 +223,15 @@ void compute( size_t batchSize, double xmax, double xmin,

RooSpan<double> RooChebychev::evaluateBatch(std::size_t begin, std::size_t batchSize) const {
auto 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.");
}
else {
const Double_t xmax = _x.max(_refRangeName?_refRangeName->GetName() : nullptr);
const Double_t xmin = _x.min(_refRangeName?_refRangeName->GetName() : nullptr);
ChebychevEvaluate::compute(batchSize, xmax, xmin, output.data(), xData.data(), _coefList);
return {};
}

batchSize = xData.size();
auto output = _batchData.makeWritableBatchUnInit(begin, batchSize);
const Double_t xmax = _x.max(_refRangeName?_refRangeName->GetName() : nullptr);
const Double_t xmin = _x.min(_refRangeName?_refRangeName->GetName() : nullptr);
compute(batchSize, xmax, xmin, output.data(), xData.data(), _coefList);
return output;
}
////////////////////////////////////////////////////////////////////////////////
Expand Down
14 changes: 6 additions & 8 deletions roofit/roofit/src/RooChiSquarePdf.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Double_t RooChiSquarePdf::evaluate() const

////////////////////////////////////////////////////////////////////////////////

namespace ChiSquarePdfBatchEvaluate {
namespace {
//Author: Emmanouil Michalainas, CERN 28 Aug 2019

template<class T_x, class T_ndof>
Expand Down Expand Up @@ -103,15 +103,17 @@ void compute( size_t batchSize,

RooSpan<double> RooChiSquarePdf::evaluateBatch(std::size_t begin, std::size_t batchSize) const {
using namespace BatchHelpers;
using namespace ChiSquarePdfBatchEvaluate;
auto _xData = _x.getValBatch(begin, batchSize);
auto _ndofData = _ndof.getValBatch(begin, batchSize);
const bool batch_x = !_xData.empty();
const bool batch_ndof = !_ndofData.empty();

if (!batch_x && !batch_ndof) {
return {};
}
batchSize = findSize({ _xData, _ndofData });
auto output = _batchData.makeWritableBatchUnInit(begin, batchSize);

const bool batch_x = !_xData.empty();
const bool batch_ndof = !_ndofData.empty();
if (batch_x && !batch_ndof ) {
compute(batchSize, output.data(), _xData, BracketAdapter<double>(_ndof));
}
Expand All @@ -121,10 +123,6 @@ RooSpan<double> RooChiSquarePdf::evaluateBatch(std::size_t begin, std::size_t ba
else if (batch_x && batch_ndof ) {
compute(batchSize, output.data(), _xData, _ndofData);
}
else{
throw std::logic_error("Requested a batch computation, but no batch data available.");
}

return output;
}

Expand Down
Loading

0 comments on commit f02dc04

Please sign in to comment.