1#ifndef TMVA_SOFIE_ROPERATOR_BatchNormalization 
    2#define TMVA_SOFIE_ROPERATOR_BatchNormalization 
   13namespace Experimental{
 
   59      if(std::is_same<T, float>::value){
 
   64            std::runtime_error(
"TMVA SOFIE Encountered unsupported type parsing a BatchNormalization operator");
 
 
   75      if (
input.size() != 5 ) {
 
   77         std::runtime_error(
"TMVA SOFIE BatchNormalization Op Shape inference need 5 input tensors");
 
   79      for(
size_t i = 0; i < 
input.size(); i++) {
 
   82            std::runtime_error(
"TMVA SOFIE BatchNormalization Op Shape inference only accept tensor with 4 dimensions");
 
 
   93            std::runtime_error(
"TMVA SOFIE BatchNormalization op Input Tensor " + 
fNX + 
" fnx is not found in model");
 
   97            std::runtime_error(
"TMVA SOFIE BatchNormalization op Input Tensor " + 
fNScale + 
" fns is not found in model");
 
  101            std::runtime_error(
"TMVA SOFIE BatchNormalization op Input Tensor " + 
fNB + 
" fnb is not found in model");
 
  105            std::runtime_error(
"TMVA SOFIE BatchNormalization op Input Tensor " + 
fNMean + 
" fnm is not found in model");
 
  109            std::runtime_error(
"TMVA SOFIE BatchNormalization op Input Tensor " + 
fNVar + 
" fnv is not found in model");
 
  137         if (
fType == 
"float") {
 
  146            size_t bs = 0, ch = 0, 
h = 0, 
w = 0;
 
  159            for (
bs = 1; 
bs < batchSize; 
bs++) {
 
  166            for (
size_t i = 0; i < 
n; i++) {
 
 
  190         throw std::runtime_error(
"TMVA SOFIE Batch Normalization called to Generate without being initialized first");
 
  193      std::stringstream out;
 
  202      out << 
"\n\n//---- BatchNorm\n";
 
  204      out << 
SP << 
"constexpr int "<<
OpName<< 
"_incx = 1;\n";
 
  205      out << 
SP << 
"constexpr int "<<
OpName<< 
"_incy = 1;\n";
 
  206      out << 
SP << 
"BLAS::scopy_(&" << 
OpName << 
"_N, " << 
"tensor_" << 
fNX << 
", &" << 
OpName << 
"_incx," << 
"tensor_" << 
fNY << 
", &" << 
OpName << 
"_incy);\n\n";
 
  209      out << 
SP << 
"float "<<
OpName<< 
"_alpha = -1;\n";
 
  210      out << 
SP << 
"BLAS::saxpy_(&" << 
OpName << 
"_N, &" << 
OpName << 
"_alpha, " << 
"tensor_" << 
fNMean << 
", &" << 
OpName << 
"_incx," 
  211         << 
"tensor_" << 
fNY <<
", &" << 
OpName << 
"_incy);\n\n ";
 
  214      out << 
SP << 
"for (size_t i = 0; i < " << 
n << 
"; i++) {\n";
 
  216      out << 
SP << 
SP << 
"tensor_" << 
fNY << 
"[i] *= tensor_" << 
fNScale << 
"[i]; \n";
 
  220      out << 
SP <<
OpName<< 
"_alpha = 1;\n";
 
  221      out << 
SP << 
"BLAS::saxpy_(&" << 
OpName << 
"_N, &" << 
OpName << 
"_alpha, " << 
"tensor_" << 
fNB << 
", &" << 
OpName << 
"_incx, " 
  222         << 
"tensor_" << 
fNY << 
", &" << 
OpName << 
"_incy);\n\n";
 
  226         out << 
SP << 
SP << 
"tensor_" << 
fNY << 
"[id] = ((tensor_" << 
fNY << 
"[id] > 0 )? tensor_" << 
fNY << 
"[id] : 0);\n";
 
 
  232   std::vector<std::string> 
GetBlasRoutines()
 override { 
return { std::string(
"Copy"), std::string(
"Axpy") }; }
 
 
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
 
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
 
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
 
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
 
void AddIntermediateTensor(std::string tensor_name, ETensorType type, std::vector< Dim > dim_shape)
 
bool CheckIfTensorAlreadyExist(std::string tensor_name)
 
const ETensorType & GetTensorType(std::string name) const
 
const std::vector< size_t > & GetTensorShape(std::string name) const
 
std::shared_ptr< void > GetInitializedTensorData(std::string tensor_name)
 
void UpdateInitializedTensor(std::string tensor_name, ETensorType type, std::vector< std::size_t > shape, std::shared_ptr< void > data)
 
std::vector< size_t > fShapeScale
 
std::vector< std::string > GetBlasRoutines() override
 
void Initialize(RModel &model) override
 
ROperator_BatchNormalization()=delete
 
std::vector< size_t > fShapeY
 
std::vector< size_t > fShapeX
 
std::vector< size_t > fShapeB
 
std::vector< size_t > fShapeMean
 
std::size_t ftraining_mode
 
std::vector< std::vector< size_t > > ShapeInference(std::vector< std::vector< size_t > > input) override
 
std::string Generate(std::string OpName) override
 
ROperator_BatchNormalization(float epsilon, float momentum, std::size_t training_mode, std::string nameX, std::string nameScale, std::string nameB, std::string nameMean, std::string nameVar, std::string nameY, EActivationType activation=EActivationType::UNDEFINED)
 
std::vector< ETensorType > TypeInference(std::vector< ETensorType > input) override
 
std::vector< size_t > fShapeVar
 
EActivationType fActivation
 
std::vector< std::string_view > fInputTensorNames
 
const std::string SP
space used to correctly indent the generated C++ code
 
std::vector< std::string_view > fOutputTensorNames
 
std::string ConvertShapeToString(std::vector< size_t > shape)
 
std::size_t ConvertShapeToLength(std::vector< size_t > shape)
 
create variable transformations