1#ifndef TMVA_SOFIE_ROPERATOR_Reduce
2#define TMVA_SOFIE_ROPERATOR_Reduce
16namespace Experimental{
21template <EReduceOpMode Op>
68 throw std::runtime_error(
"TMVA SOFIE Reduce Op - invalid axes values " + std::to_string(
fAttrAxes[
j]));
77 for (
size_t j = 0;
j <
ax.size();
j++) {
81 for (
size_t k =
j+1; k <
ax.size(); k++)
94 throw std::runtime_error(
"TMVA SOFIE Reduce Op Input Tensor " +
fNX +
" is not found in model");
109 for (
size_t i = 0; i <
fAttrAxes.size(); i++)
139 std::stringstream out;
140 out <<
"\n//---- operator " <<
Name() <<
" " <<
opName <<
"\n";
145 for (
int k =
fShapeX.size()-1; k >= kmin; k--) {
155 for (
size_t k = 0; k <
fAttrAxes.size(); k++) {
178 out <<
SP <<
"for (size_t i = 0; i < " <<
outputLength <<
"; i++) {\n";
191 out <<
SP <<
SP <<
"}\n";
201 out <<
SP <<
"std::fill(tensor_" <<
fNY <<
", tensor_"<<
fNY <<
" + "<<
outputLength <<
", 1);\n";
203 out <<
SP <<
"std::fill(tensor_" <<
fNY <<
", tensor_"<<
fNY <<
" + "<<
outputLength <<
", 0);\n";
205 out <<
SP <<
"for (size_t i = 0; i < " <<
reducedLength <<
"; i++) {\n";
206 out <<
SP <<
SP <<
"for (size_t j = 0; j < " <<
outputLength <<
"; j++) {\n";
213 out <<
SP <<
SP <<
SP <<
"tensor_" <<
fNY <<
"[j] += tensor_" <<
fNX <<
"[i * " <<
outputLength <<
" + j] * tensor_"
215 out <<
SP <<
SP <<
"}\n";
218 out <<
SP <<
"for (size_t j = 0; j < " <<
outputLength <<
"; j++) {\n";
228 out <<
SP <<
"std::fill(tensor_" <<
fNY <<
", tensor_"<<
fNY <<
" + "<<
outputLength <<
", 1);\n";
232 out <<
SP <<
"for (size_t i = 0; i < " <<
inputLength <<
"; i++) {\n";
237 out <<
SP <<
SP <<
"size_t outputIndex = 0;\n";
238 for (
size_t k = 0; k < dim; k++) {
242 out <<
SP <<
SP <<
"outputIndex += i_" << k <<
" * " <<
outputStrides[k] <<
";\n";
246 out <<
SP <<
SP <<
"// compute reduction....\n";
248 out <<
SP <<
SP <<
"tensor_" <<
fNY <<
"[outputIndex] *= tensor_" <<
fNX <<
"[i];\n";
250 out <<
SP <<
SP <<
"tensor_" <<
fNY <<
"[outputIndex] += tensor_" <<
fNX <<
"[i];\n";
252 out <<
SP <<
SP <<
"tensor_" <<
fNY <<
"[outputIndex] += tensor_" <<
fNX <<
"[i] * tensor_" <<
fNX
258 out <<
SP <<
"for (size_t i = 0; i < " <<
outputLength <<
"; i++) {\n";
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
const_iterator begin() const
const_iterator end() const
void AddNeededStdLib(std::string libname)
std::vector< size_t > GetTensorShape(const std::string &name) const
std::vector< Dim > GetDimTensorShape(const std::string &name) const
bool IsDynamicTensor(const std::string &name) const
void AddIntermediateTensor(std::string tensor_name, ETensorType type, std::vector< Dim > dim_shape)
bool CheckIfTensorAlreadyExist(std::string tensor_name)
std::shared_ptr< void > GetInitializedTensorData(std::string tensor_name)
ETensorType GetTensorType(std::string name) const
std::vector< Dim > fShapeY
std::string Generate(std::string opName) override
std::vector< int64_t > fAttrAxes
std::vector< Dim > fShapeYNotPruned
std::vector< Dim > fShapeX
EReduceOpMode fReduceOpMode
void Initialize(RModel &model) override
ROperator_Reduce(int keepdims, std::vector< int64_t > attrAxes, std::string nameX, std::string nameAxes, std::string nameY)
std::vector< Dim > DoShapeInference(const std::vector< Dim > &input)
std::vector< std::string_view > fInputTensorNames
const std::string SP
space used to correctly indent the generated C++ code
bool fUseSession
flag to identify if using the session class
std::vector< std::string_view > fOutputTensorNames
std::vector< size_t > ComputeStrideFromShape(const std::vector< size_t > &shape)
compute stride of a tensor given its shape (assume layout is row-major)
std::string ConvertDimShapeToString(const std::vector< Dim > &shape)
std::size_t ConvertShapeToLength(const std::vector< size_t > &shape)
std::string ConvertDimShapeToLength(const std::vector< Dim > &shape)
create variable transformations