diff --git a/roofit/roofit/src/RooArgusBG.cxx b/roofit/roofit/src/RooArgusBG.cxx index 94aabcd46565c..34566c24d37dc 100644 --- a/roofit/roofit/src/RooArgusBG.cxx +++ b/roofit/roofit/src/RooArgusBG.cxx @@ -90,7 +90,7 @@ Double_t RooArgusBG::evaluate() const { //////////////////////////////////////////////////////////////////////////////// -namespace ArgusBatchEvaluate { +namespace { //Author: Emmanouil Michalainas, CERN 19 AUGUST 2019 template @@ -112,26 +112,26 @@ void compute( size_t batchSize, RooSpan 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 (m0), - BracketAdapter (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 (m0), + BracketAdapter (c), BracketAdapter (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; } diff --git a/roofit/roofit/src/RooBernstein.cxx b/roofit/roofit/src/RooBernstein.cxx index 11af91fc108f1..2f3fd74d1a6cc 100644 --- a/roofit/roofit/src/RooBernstein.cxx +++ b/roofit/roofit/src/RooBernstein.cxx @@ -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, @@ -192,17 +192,15 @@ void compute( size_t batchSize, double xmax, double xmin, RooSpan 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; } diff --git a/roofit/roofit/src/RooBifurGauss.cxx b/roofit/roofit/src/RooBifurGauss.cxx index 072567420be4b..36a50e3f29b96 100644 --- a/roofit/roofit/src/RooBifurGauss.cxx +++ b/roofit/roofit/src/RooBifurGauss.cxx @@ -81,7 +81,7 @@ Double_t RooBifurGauss::evaluate() const { //////////////////////////////////////////////////////////////////////////////// -namespace BifurGaussBatchEvaluate { +namespace { //Author: Emmanouil Michalainas, CERN 20 AUGUST 2019 template @@ -107,26 +107,26 @@ void compute( size_t batchSize, RooSpan 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 (mean), - BracketAdapter (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 (mean), + BracketAdapter (sigmaL), BracketAdapter (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; } diff --git a/roofit/roofit/src/RooBreitWigner.cxx b/roofit/roofit/src/RooBreitWigner.cxx index c2f3bac33223c..d362c74559d1d 100644 --- a/roofit/roofit/src/RooBreitWigner.cxx +++ b/roofit/roofit/src/RooBreitWigner.cxx @@ -68,7 +68,7 @@ Double_t RooBreitWigner::evaluate() const //////////////////////////////////////////////////////////////////////////////// -namespace BreitWignerBatchEvaluate { +namespace { //Author: Emmanouil Michalainas, CERN 21 August 2019 template @@ -85,17 +85,19 @@ void compute( size_t batchSize, RooSpan 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(mean), BracketAdapter(width)); } @@ -117,10 +119,6 @@ RooSpan 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; } diff --git a/roofit/roofit/src/RooBukinPdf.cxx b/roofit/roofit/src/RooBukinPdf.cxx index c29c44e8c45ef..d48fca199caad 100644 --- a/roofit/roofit/src/RooBukinPdf.cxx +++ b/roofit/roofit/src/RooBukinPdf.cxx @@ -143,7 +143,7 @@ Double_t RooBukinPdf::evaluate() const //////////////////////////////////////////////////////////////////////////////////////// -namespace BukinBatchEvaluate { +namespace { //Author: Emmanouil Michalainas, CERN 26 JULY 2019 template @@ -192,30 +192,30 @@ void compute( size_t batchSize, RooSpan 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 (Xp), - BracketAdapter (sigp), - BracketAdapter (xi), - BracketAdapter (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 (Xp), + BracketAdapter (sigp), + BracketAdapter (xi), + BracketAdapter (rho1), BracketAdapter (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; } diff --git a/roofit/roofit/src/RooCBShape.cxx b/roofit/roofit/src/RooCBShape.cxx index 39af587490ed4..bb3fad55172f0 100644 --- a/roofit/roofit/src/RooCBShape.cxx +++ b/roofit/roofit/src/RooCBShape.cxx @@ -93,7 +93,7 @@ Double_t RooCBShape::evaluate() const { //////////////////////////////////////////////////////////////////////////////// -namespace CBShapeBatchEvaluate { +namespace { //Author: Emmanouil Michalainas, CERN 21 August 2019 template @@ -121,16 +121,15 @@ void compute( size_t batchSize, RooSpan 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 (m0), BracketAdapter (sigma), @@ -139,11 +138,11 @@ RooSpan 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; } diff --git a/roofit/roofit/src/RooChebychev.cxx b/roofit/roofit/src/RooChebychev.cxx index a2afc8323c319..9cb296a028f3d 100644 --- a/roofit/roofit/src/RooChebychev.cxx +++ b/roofit/roofit/src/RooChebychev.cxx @@ -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, @@ -223,17 +223,15 @@ void compute( size_t batchSize, double xmax, double xmin, RooSpan 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; } //////////////////////////////////////////////////////////////////////////////// diff --git a/roofit/roofit/src/RooChiSquarePdf.cxx b/roofit/roofit/src/RooChiSquarePdf.cxx index 39a8b2fc0dcfa..34dce5d8302c7 100644 --- a/roofit/roofit/src/RooChiSquarePdf.cxx +++ b/roofit/roofit/src/RooChiSquarePdf.cxx @@ -65,7 +65,7 @@ Double_t RooChiSquarePdf::evaluate() const //////////////////////////////////////////////////////////////////////////////// -namespace ChiSquarePdfBatchEvaluate { +namespace { //Author: Emmanouil Michalainas, CERN 28 Aug 2019 template @@ -103,15 +103,17 @@ void compute( size_t batchSize, RooSpan 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(_ndof)); } @@ -121,10 +123,6 @@ RooSpan 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; } diff --git a/roofit/roofit/src/RooExponential.cxx b/roofit/roofit/src/RooExponential.cxx index f6425c073dba3..dc211f52756d4 100644 --- a/roofit/roofit/src/RooExponential.cxx +++ b/roofit/roofit/src/RooExponential.cxx @@ -91,10 +91,9 @@ Double_t RooExponential::analyticalIntegral(Int_t code, const char* rangeName) c namespace { template -void compute(RooSpan output, Tx x, Tc c) { - const int n = output.size(); +void compute(size_t n, double* __restrict output, Tx x, Tc c) { - for (int i = 0; i < n; ++i) { //CHECK_VECTORISE + for (size_t i = 0; i < n; ++i) { //CHECK_VECTORISE output[i] = _rf_fast_exp(x[i]*c[i]); } } @@ -108,26 +107,26 @@ void compute(RooSpan output, Tx x, Tc c) { /// \return A span with the computed values. RooSpan RooExponential::evaluateBatch(std::size_t begin, std::size_t batchSize) const { - auto output = _batchData.makeWritableBatchUnInit(begin, batchSize); - - //Now explicitly write down all possible template instantiations of compute() above: + using namespace BatchHelpers; auto xData = x.getValBatch(begin, batchSize); auto cData = c.getValBatch(begin, batchSize); - const bool batchX = !xData.empty(); const bool batchC = !cData.empty(); - if (batchX && !batchC) { - compute(output, xData, BatchHelpers::BracketAdapter(c)); - } else if (!batchX && batchC) { - compute(output, BatchHelpers::BracketAdapter(x), cData); - } else if (!batchX && !batchC) { - compute(output, - BatchHelpers::BracketAdapter(x), - BatchHelpers::BracketAdapter(c)); - } else { - compute(output, xData, cData); + if (!batchX && !batchC) { + return {}; } + batchSize = findSize({ xData, cData }); + auto output = _batchData.makeWritableBatchUnInit(begin, batchSize); + if (batchX && !batchC ) { + compute(batchSize, output.data(), xData, BracketAdapter(c)); + } + else if (!batchX && batchC ) { + compute(batchSize, output.data(), BracketAdapter(x), cData); + } + else if (batchX && batchC ) { + compute(batchSize, output.data(), xData, cData); + } return output; } diff --git a/roofit/roofit/src/RooGamma.cxx b/roofit/roofit/src/RooGamma.cxx index db5cac0f06436..b3328ee54c6a5 100644 --- a/roofit/roofit/src/RooGamma.cxx +++ b/roofit/roofit/src/RooGamma.cxx @@ -95,7 +95,7 @@ Double_t RooGamma::evaluate() const //////////////////////////////////////////////////////////////////////////////// -namespace GammaBatchEvaluate { +namespace { //Author: Emmanouil Michalainas, CERN 22 August 2019 template @@ -148,16 +148,15 @@ void compute( size_t batchSize, RooSpan RooGamma::evaluateBatch(std::size_t begin, std::size_t batchSize) const { using namespace BatchHelpers; - using namespace GammaBatchEvaluate; EvaluateInfo info = getInfo( {&x, &gamma, &beta, &mu}, begin, batchSize ); - auto output = _batchData.makeWritableBatchUnInit(begin, batchSize); - - auto xData = x.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 && !xData.empty()) { + 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 (gamma), BracketAdapter (beta), diff --git a/roofit/roofit/src/RooLandau.cxx b/roofit/roofit/src/RooLandau.cxx index 2bf7e77201749..e59a923cf0874 100644 --- a/roofit/roofit/src/RooLandau.cxx +++ b/roofit/roofit/src/RooLandau.cxx @@ -61,7 +61,7 @@ Double_t RooLandau::evaluate() const //////////////////////////////////////////////////////////////////////////////// -namespace LandauBatchEvaluate { +namespace { //Author: Emmanouil Michalainas, CERN 26 JULY 2019 /* Actual computation of Landau(x,mean,sigma) in a vectorization-friendly way @@ -175,17 +175,19 @@ void compute( size_t batchSize, RooSpan RooLandau::evaluateBatch(std::size_t begin, std::size_t batchSize) const { using namespace BatchHelpers; - using namespace LandauBatchEvaluate; auto xData = x.getValBatch(begin, batchSize); auto meanData = mean.getValBatch(begin, batchSize); auto sigmaData = sigma.getValBatch(begin, batchSize); + const bool batchX = !xData.empty(); + const bool batchMean = !meanData.empty(); + const bool batchSigma = !sigmaData.empty(); + if (!batchX && !batchMean && !batchSigma) { + return {}; + } batchSize = findSize({ xData, meanData, sigmaData }); auto output = _batchData.makeWritableBatchUnInit(begin, batchSize); - const bool batchX = !xData.empty(); - const bool batchMean = !meanData.empty(); - const bool batchSigma = !sigmaData.empty(); if (batchX && !batchMean && !batchSigma ) { compute(batchSize, output.data(), xData, BracketAdapter(mean), BracketAdapter(sigma)); } @@ -207,10 +209,6 @@ RooSpan RooLandau::evaluateBatch(std::size_t begin, std::size_t batchSiz else if (batchX && batchMean && batchSigma ) { compute(batchSize, output.data(), xData, meanData, sigmaData); } - else{ - throw std::logic_error("Requested a batch computation, but no batch data available."); - } - return output; } diff --git a/roofit/roofit/src/RooPoisson.cxx b/roofit/roofit/src/RooPoisson.cxx index d3046bd8e5bae..2dc1d55dd060c 100644 --- a/roofit/roofit/src/RooPoisson.cxx +++ b/roofit/roofit/src/RooPoisson.cxx @@ -75,11 +75,10 @@ Double_t RooPoisson::evaluate() const namespace { template -void compute(RooSpan output, Tx x, TMean mean, +void compute(const size_t n, double* __restrict output, Tx x, TMean mean, const bool protectNegative, const bool noRounding) { - const int n = output.size(); - for (int i = 0; i < n; ++i) { //CHECK_VECTORISE + for (size_t i = 0; i < n; ++i) { //CHECK_VECTORISE const double x_i = noRounding ? x[i] : floor(x[i]); // The std::lgamma yields different values than in the scalar implementation. // Need to check which one is more accurate. @@ -88,7 +87,7 @@ void compute(RooSpan output, Tx x, TMean mean, } - for (int i = 0; i < n; ++i) { //CHECK_VECTORISE + for (size_t i = 0; i < n; ++i) { //CHECK_VECTORISE const double x_i = noRounding ? x[i] : floor(x[i]); const double logMean = _rf_fast_log(mean[i]); const double logPoisson = x_i * logMean - mean[i] - output[i]; @@ -111,27 +110,27 @@ void compute(RooSpan output, Tx x, TMean mean, //////////////////////////////////////////////////////////////////////////////// /// Compute Poisson values in batches. RooSpan RooPoisson::evaluateBatch(std::size_t begin, std::size_t batchSize) const { - auto output = _batchData.makeWritableBatchUnInit(begin, batchSize); + using namespace BatchHelpers; auto xData = x.getValBatch(begin, batchSize); auto meanData = mean.getValBatch(begin, batchSize); - const bool batchX = !xData.empty(); const bool batchMean = !meanData.empty(); - if (batchX && batchMean) { - compute(output, xData, meanData, _protectNegative, _noRounding); - } else if (batchX && !batchMean) { - compute(output, xData, BatchHelpers::BracketAdapter(mean), _protectNegative, _noRounding); - } - else if (!batchX && batchMean) { - compute(output, BatchHelpers::BracketAdapter(x), meanData, _protectNegative, _noRounding); - } else if (!batchX && !batchMean) { - compute(output, BatchHelpers::BracketAdapter(x), BatchHelpers::BracketAdapter(mean), _protectNegative, _noRounding); - } else { - //Should not happen - assert(false); + if (!batchX && !batchMean) { + return {}; } + batchSize = findSize({ xData, meanData }); + auto output = _batchData.makeWritableBatchUnInit(begin, batchSize); + if (batchX && !batchMean ) { + compute(batchSize, output.data(), xData, BracketAdapter(mean), _protectNegative, _noRounding); + } + else if (!batchX && batchMean ) { + compute(batchSize, output.data(), BracketAdapter(x), meanData, _protectNegative, _noRounding); + } + else if (batchX && batchMean ) { + compute(batchSize, output.data(), xData, meanData, _protectNegative, _noRounding); + } return output; }