1#ifndef TMVA_SOFIE_ROPERATOR_Reduce
2#define TMVA_SOFIE_ROPERATOR_Reduce
16namespace Experimental{
21template <
typename T, EReduceOpMode Op>
65 throw std::runtime_error(
"TMVA SOFIE Reduce Op - invalid axes values " + std::to_string(
fAttrAxes[
j]));
74 for (
size_t j = 0;
j <
ax.size();
j++) {
78 for (
size_t k =
j+1; k <
ax.size(); k++)
91 throw std::runtime_error(
"TMVA SOFIE Reduce Op Input Tensor " +
fNX +
" is not found in model");
104 for (
size_t i = 0; i <
fAttrAxes.size(); i++)
118 throw std::runtime_error(
"TMVA SOFIE Reduce Op called to Generate without being initialized first");
136 std::stringstream out;
137 out <<
"\n//---- operator " <<
Name() <<
" " <<
opName <<
"\n";
142 for (
int k =
fShapeX.size()-1; k >= kmin; k--) {
152 for (
size_t k = 0; k <
fAttrAxes.size(); k++) {
168 out <<
SP <<
"for (size_t i = 0; i < " <<
outputLength <<
"; i++) {\n";
181 out <<
SP <<
SP <<
"}\n";
195 out <<
SP <<
"for (size_t i = 0; i < " <<
reducedLength <<
"; i++) {\n";
196 out <<
SP <<
SP <<
"for (size_t j = 0; j < " <<
outputLength <<
"; j++) {\n";
203 out <<
SP <<
SP <<
SP <<
"tensor_" <<
fNY <<
"[j] += tensor_" <<
fNX <<
"[i * " <<
outputLength <<
" + j] * tensor_"
205 out <<
SP <<
SP <<
"}\n";
208 out <<
SP <<
"for (size_t j = 0; i < " <<
outputLength <<
"; j++) {\n";
222 out <<
SP <<
"for (size_t i = 0; i < " <<
inputLength <<
"; i++) {\n";
227 out <<
SP <<
SP <<
"size_t outputIndex = 0;\n";
228 for (
size_t k = 0; k < dim; k++) {
232 out <<
SP <<
SP <<
"outputIndex += i_" << k <<
" * " <<
outputStrides[k] <<
";\n";
236 out <<
SP <<
SP <<
"// compute reduction....\n";
238 out <<
SP <<
SP <<
"tensor_" <<
fNY <<
"[outputIndex] *= tensor_" <<
fNX <<
"[i];\n";
240 out <<
SP <<
SP <<
"tensor_" <<
fNY <<
"[outputIndex] += tensor_" <<
fNX <<
"[i];\n";
242 out <<
SP <<
SP <<
"tensor_" <<
fNY <<
"[outputIndex] += tensor_" <<
fNX <<
"[i] * tensor_" <<
fNX
248 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
const ETensorType & GetTensorType(std::string name)
void AddIntermediateTensor(std::string tensor_name, ETensorType type, std::vector< Dim > dim_shape)
bool CheckIfTensorAlreadyExist(std::string tensor_name)
const std::vector< size_t > & GetTensorShape(std::string name)
std::shared_ptr< void > GetInitializedTensorData(std::string tensor_name)
std::string Generate(std::string opName)
std::vector< size_t > fShapeX
void Initialize(RModel &model)
ROperator_Reduce(int keepdims, std::vector< int64_t > attrAxes, std::string nameX, std::string nameAxes, std::string nameY)
EReduceOpMode fReduceOpMode
std::vector< int64_t > fAttrAxes
std::vector< size_t > fShapeY
std::vector< size_t > fShapeYNotPruned
std::vector< std::vector< size_t > > ShapeInference(std::vector< std::vector< size_t > > input)
std::vector< ETensorType > TypeInference(std::vector< ETensorType > input)
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< size_t > ComputeStrideFromShape(const std::vector< size_t > &shape)
compute stride of a tensor given its shape (assume layout is row-major)
std::string ConvertShapeToString(std::vector< size_t > shape)
std::size_t ConvertShapeToLength(std::vector< size_t > shape)
create variable transformations