1#ifndef TMVA_SOFIE_ROPERATOR_RESHAPE
2#define TMVA_SOFIE_ROPERATOR_RESHAPE
14namespace Experimental{
96 std::cout <<
"WARNING: TMVA Reshape Op : output shape has zero value at index " << i <<
97 " but input shape has a different rank than output shape" << std::endl;
99 throw std::runtime_error(
"TMVA Reshape Op : output shape has zero value at index " + std::to_string(i) +
100 " but input shape does not have corresponding index");
103 }
else if (
output_shape[i].dim ==
static_cast<size_t>(-1)) {
109 throw std::runtime_error(
"TMVA Reshape Op : zero value in shape is not allowed when there is also a -1 in shape");
145 [](
unsigned char x) { return std::isspace(x); }),
token.
end());
150 if ((
il %
tl) == 0) {
166 if (
res_shape.find(
'*') != std::string::npos)
215 for (
size_t i = 0; i < axes.size(); i++) {
219 throw std::runtime_error(
"TMVA Squeeze Op : Invalid axis value " + std::to_string(axes[i]) +
223 std::sort(axes.begin(), axes.end(), std::greater<int>());
224 for (
auto & axis : axes) {
237 for (
auto &
a : axes) {
238 int64_t i =
static_cast<int64_t
>(
a);
240 throw std::runtime_error(
"TMVA Unsqueeze Op - axes input is not in correct range");
249 throw std::runtime_error(
"TMVA Reshape Op : Invalid ReshapeOpMode");
257 std::cout <<
"initialize reshape op type " <<
fOpMode <<
" - for input " <<
fNData
258 <<
" to shape given by " <<
fNInput2 << std::endl;
260 if (model.CheckIfTensorAlreadyExist(
fNData) ==
false) {
262 throw std::runtime_error(
"TMVA Reshape Op Input Tensor " +
fNData +
" is not found in model");
268 if (model.CheckIfTensorAlreadyExist(
fNInput2)) {
269 if (model.IsInitializedTensor(
fNInput2)) {
272 auto values =
static_cast<int64_t *
>(
dptr.get());
273 auto vec = model.GetTensorShape(
fNInput2);
279 fShape = std::vector<int64_t>(values, values +
n);
281 fAttrAxes = std::vector<int64_t>(values, values +
n);
286 model.SetNotWritableInitializedTensor(
fNInput2);
287 }
else if (model.IsShapeTensor(
fNInput2)) {
296 if (model.IsDynamicTensor(
fNInput2)) {
297 throw std::runtime_error(
"TMVA Reshape Op 2nd input Tensor " +
fNInput2 +
" cannot have dynamic shape");
306 throw std::runtime_error(
"TMVA Reshape Op 2nd input Tensor " +
fNInput2 +
" is not found in model");
314 throw std::runtime_error(
"TMVA Reshape Op : Invalid Input/Attribute data");
319 auto inputData =
static_cast<int64_t*
>(model.GetInitializedTensorData(
fNData).get());
322 throw std::runtime_error(
"TMVA Reshape Op : Invalid Input/Output lengths");
324 if (model.Verbose()) {
335 if (model.Verbose()) {
351 std::stringstream out;
352 std::string
opType =
"Reshape";
366 out <<
"//----------------output is a shape tensor----------\n";
380 out <<
SP <<
"if (tensor_" <<
fNInput2 <<
"[" << i <<
"] <= 0 ) "
391 out <<
SP <<
SP <<
"throw std::runtime_error(\"TMVA SOFIE Reshape " <<
opName <<
" output length "
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 char Point_t Rectangle_t WindowAttributes_t Float_t r
const_iterator begin() const
const_iterator end() const
std::vector< Dim > fShapeInput
std::vector< int64_t > fShape
ROperator_Reshape(ReshapeOpMode opMode, std::vector< int64_t > attrAxes, std::string nameData, std::string nameOutput)
void Initialize(RModel &model) override
std::vector< Dim > fShapeOutput
ROperator_Reshape(ReshapeOpMode opMode, int attr_value, std::string nameData, std::string nameInput2, std::string nameOutput)
std::vector< Dim > DoShapeInference(const std::vector< Dim > &input_shape, const std::vector< Dim > &target_shape)
std::vector< Dim > fOutputShapeData
std::vector< int64_t > fAttrAxes
std::string Generate(std::string opName) override
std::vector< std::string_view > fInputTensorNames
bool fIsOutputParamShape
flag to identify of the output represents a parametric shape (can be known at compile time)
bool fIsOutputConstant
flag to identify if operator has a constant output (no need to generate code)
const std::string SP
space used to correctly indent the generated C++ code
std::vector< std::string_view > fOutputTensorNames
std::string ConvertDimShapeToString(const std::vector< Dim > &shape)
std::size_t ConvertShapeToLength(const std::vector< size_t > &shape)
std::string ConvertValuesToString(size_t n, const T *data, size_t maxprint=-1)
std::vector< size_t > ConvertShapeToInt(const std::vector< Dim > &shape)
Convert shape based on Dim to integer format.
std::string ConvertDimShapeToLength(const std::vector< Dim > &shape)
bool IsInteger(const std::string &s)
create variable transformations