1#ifndef TMVA_SOFIE_ROPERATOR_SLICE
2#define TMVA_SOFIE_ROPERATOR_SLICE
13namespace Experimental{
18template <
typename IType>
49 for (
size_t i = 0; i < names.size(); ++i) {
66 auto ret = std::vector<ETensorType>(1,
input[0]);
85 throw std::runtime_error(
"TMVA Slice Op Input Tensor is not found in model");
88 std::vector<std::vector<size_t>> shapes;
92 std::vector<std::vector<IType>>
itensors(4);
95 for (
size_t i = 0; i <
fNames.size(); ++i) {
123 fSteps = std::vector<IType>(dim, 1);
124 fStart = std::vector<IType>(dim, 0);
125 fEnd = std::vector<IType>(dim, 0);
135 if (
iaxes.size() > 0) {
136 for (
size_t i = 0; i <
iaxes.size(); i++) {
140 throw std::runtime_error(
"TMVA Slice Op : invalid axis value " + std::to_string(
iaxes[i]) +
141 " for " + std::to_string(i));
153 }
else if (
isteps[i] < 0) {
158 throw std::runtime_error(
"TMVA Slice Op : invalid step value " + std::to_string(
isteps[i]) +
159 " for " + std::to_string(i));
179 std::vector<IType> indices;
181 indices.push_back(i);
183 for (
size_t i = 0; i < indices.size(); i++) {
189 for (
size_t i = 0; i < indices.size(); i++) {
220 throw std::runtime_error(
"TMVA SOFIE Slice Op called to Generate without being initialized first");
223 std::stringstream out;
226 out <<
SP <<
"///------- Slice operator\n" << std::endl;
229 std::vector<size_t> strides(ndim,1);
230 for (
int i =
int(ndim-2); i >=0 ; i--) {
235 out <<
SP <<
"size_t iOut = 0;\n";
236 std::string
MSP =
SP;
241 if (
idim < ndim-1) out <<
MSP <<
"size_t stride" <<
idim <<
" = " << strides[
idim] <<
"*i" <<
idim <<
";\n";
243 out <<
MSP <<
"size_t iInput = ";
244 for (
size_t idim = 0;
idim < ndim-1;
idim++) out <<
" stride" <<
idim <<
" + ";
246 out <<
"i" << ndim-1 <<
";\n";
247 out <<
MSP <<
"tensor_" <<
fNOutput <<
"[iOut++] = tensor_" <<
fNData <<
"[iInput];\n";
249 MSP =
MSP.replace(0,
SP.length(),
"");
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 WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
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)
void AddConstantTensor(std::string tensor_name, ETensorType type, std::vector< std::size_t > shape, std::shared_ptr< void > data)
bool IsInitializedTensor(const std::string &name) const
const std::vector< size_t > & GetTensorShape(std::string name)
std::shared_ptr< void > GetInitializedTensorData(std::string tensor_name)
std::vector< IType > fStart
std::vector< std::vector< IType > > fAttributes
std::vector< std::vector< size_t > > ShapeInference(std::vector< std::vector< size_t > > input)
std::vector< ETensorType > TypeInference(std::vector< ETensorType > input)
std::vector< IType > fSteps
std::vector< IType > fEnd
std::vector< size_t > fShapeInput
ROperator_Slice(std::string nameData, std::vector< IType > starts, std::vector< IType > ends, std::vector< IType > axes, std::string nameOutput)
void Initialize(RModel &model)
ROperator_Slice(std::string nameData, std::vector< std::string > names, std::string nameOutput)
std::string Generate(std::string OpName)
std::vector< std::string > fNames
std::vector< size_t > fShapeOutput
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::string Clean_name(std::string input_tensor_name)
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 ConvertValuesToString(size_t n, const T *data)
std::string ConvertShapeToString(std::vector< size_t > shape)
std::size_t ConvertShapeToLength(std::vector< size_t > shape)
create variable transformations