1#ifndef TMVA_SOFIE_ROPERATOR_SLICE
2#define TMVA_SOFIE_ROPERATOR_SLICE
12namespace Experimental{
17template <
typename T,
typename IType>
42 ROperator_Slice(std::string nameData, std::vector<std::string> names, std::string nameOutput)
43 :
fNData(UTILITY::Clean_name(nameData)),
44 fNOutput(UTILITY::Clean_name(nameOutput))
47 for (
size_t i = 0; i < names.size(); ++i) {
52 if (names.size() == 3 && names[2] !=
"axes") {
58 ROperator_Slice(std::string nameData, std::vector<IType> starts, std::vector<IType> ends, std::vector<IType> axes, std::string nameOutput)
59 :
fNData(UTILITY::Clean_name(nameData)),
60 fNOutput(UTILITY::Clean_name(nameOutput))
69 auto ret = std::vector<ETensorType>(1,
input[0]);
75 auto & input_shape =
input[0];
77 std::vector<std::vector<size_t>> ret(1, input_shape);
78 auto & output_shape = ret[0];
79 for (
size_t i = 0; i < input_shape.size(); i++) {
88 throw std::runtime_error(
"TMVA Slice Op Input Tensor is not found in model");
91 std::vector<std::vector<size_t>>
shapes;
95 std::vector<std::vector<IType>> itensors(4);
98 for (
size_t i = 0; i <
fNames.size(); ++i) {
100 std::cout <<
" i " << i <<
" getting data for tensor " <<
fNames[i] << std::endl;
102 auto tensor =
static_cast<IType *
>(dptr.get());
104 assert(
vec.size() == 1);
105 itensors[i] = std::vector<IType>(tensor, tensor +
vec[0]);
116 fSteps = std::vector<size_t>(dim, 1);
117 fStart = std::vector<size_t>(dim, 0);
120 auto istart = itensors[0];
121 auto iend = itensors[1];
122 auto iaxes = itensors[2];
123 auto isteps = itensors[3];
127 if (iaxes.size() > 0) {
128 for (
size_t i = 0; i < iaxes.size(); i++) {
130 if (iaxes[i] < 0) iaxes[i] = dim + iaxes[i];
131 size_t jaxis =
static_cast<size_t>(iaxes[i]);
132 assert(jaxis < dim - 1);
135 IType start = (istart[i] > 0) ? istart[i] : imax + istart[i];
136 if (start < 0) start = 0;
137 if (start >
static_cast<IType
>(imax))
140 IType ie = (iend[i] > 0) ? iend[i] : imax + iend[i];
142 if (ie >
static_cast<IType
>(imax))
146 if (isteps.size() > 0) {
149 throw std::runtime_error(
"TMVA Slice Op : negative steps not supported");
151 fSteps[jaxis] = isteps[i];
162 OpName =
"op_" + OpName;
164 throw std::runtime_error(
"TMVA SOFIE Slice Op called to Generate without being initialized first");
167 std::stringstream out;
170 out <<
SP <<
"///------- Slice operator\n" << std::endl;
173 std::vector<size_t> strides(ndim,1);
174 for (
int i =
int(ndim-2); i >=0 ; i--) {
178 out <<
SP <<
"size_t iOut = 0;\n";
179 std::string MSP =
SP;
180 for (
size_t idim = 0; idim < ndim; idim++) {
181 out << MSP <<
"for (size_t i" << idim <<
" = " <<
fStart[idim] <<
"; i" << idim <<
" < " <<
fEnd[idim]
182 <<
"; i" << idim <<
"+= " <<
fSteps[idim] <<
") {\n";
184 if (idim < ndim-1) out << MSP <<
"size_t stride" << idim <<
" = " << strides[idim] <<
"*i" << idim <<
";\n";
186 out << MSP <<
"size_t iInput = ";
187 for (
size_t idim = 0; idim < ndim-1; idim++) out <<
" stride" << idim <<
" + ";
189 out <<
"i" << ndim-1 <<
";\n";
190 out << MSP <<
"fTensor_" <<
fNOutput <<
"[iOut++] = fTensor_" <<
fNData <<
"[iInput];\n";
191 for (
size_t idim = 0; idim < ndim; idim++) {
192 MSP = MSP.replace(0,
SP.length(),
"");
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
const ETensorType & GetTensorType(std::string name)
void AddIntermediateTensor(std::string tensor_name, ETensorType type, std::vector< std::size_t > 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::vector< size_t > fShapeOutput
std::vector< std::string > fNames
std::vector< size_t > fEnd
std::vector< std::vector< IType > > fAttributes
ROperator_Slice(std::string nameData, std::vector< IType > starts, std::vector< IType > ends, std::vector< IType > axes, std::string nameOutput)
std::vector< size_t > fStart
void Initialize(RModel &model)
std::vector< std::vector< size_t > > ShapeInference(std::vector< std::vector< size_t > > input)
std::vector< size_t > fSteps
std::vector< ETensorType > TypeInference(std::vector< ETensorType > input)
std::string Generate(std::string OpName)
std::vector< size_t > fShapeInput
ROperator_Slice(std::string nameData, std::vector< std::string > names, std::string nameOutput)
const std::string SP
space used to correctly indent the generated C++ code
std::string Clean_name(std::string input_tensor_name)
create variable transformations