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) {
68 auto ret = std::vector<ETensorType>(1,
input[0]);
87 throw std::runtime_error(
"TMVA Slice Op Input Tensor is not found in model");
90 std::vector<std::vector<size_t>> shapes;
94 std::vector<std::vector<IType>>
itensors(4);
97 for (
size_t i = 0; i <
fNames.size(); ++i) {
125 fSteps = std::vector<IType>(dim, 1);
126 fStart = std::vector<IType>(dim, 0);
127 fEnd = std::vector<IType>(dim, 0);
137 if (
iaxes.size() > 0) {
138 for (
size_t i = 0; i <
iaxes.size(); i++) {
142 throw std::runtime_error(
"TMVA Slice Op : invalid axis value " + std::to_string(
iaxes[i]) +
143 " for " + std::to_string(i));
155 }
else if (
isteps[i] < 0) {
160 throw std::runtime_error(
"TMVA Slice Op : invalid step value " + std::to_string(
isteps[i]) +
161 " for " + std::to_string(i));
181 std::vector<IType> indices;
183 indices.push_back(i);
185 for (
size_t i = 0; i < indices.size(); i++) {
191 for (
size_t i = 0; i < indices.size(); i++) {
222 throw std::runtime_error(
"TMVA SOFIE Slice Op called to Generate without being initialized first");
225 std::stringstream out;
228 out <<
SP <<
"///------- Slice operator\n" << std::endl;
231 std::vector<size_t> strides(ndim,1);
232 for (
int i =
int(ndim-2); i >=0 ; i--) {
237 out <<
SP <<
"size_t iOut = 0;\n";
238 std::string
MSP =
SP;
243 if (
idim < ndim-1) out <<
MSP <<
"size_t stride" <<
idim <<
" = " << strides[
idim] <<
"*i" <<
idim <<
";\n";
245 out <<
MSP <<
"size_t iInput = ";
246 for (
size_t idim = 0;
idim < ndim-1;
idim++) out <<
" stride" <<
idim <<
" + ";
248 out <<
"i" << ndim-1 <<
";\n";
249 out <<
MSP <<
"tensor_" <<
fNOutput <<
"[iOut++] = tensor_" <<
fNData <<
"[iInput];\n";
251 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) override
std::vector< ETensorType > TypeInference(std::vector< ETensorType > input) override
void Initialize(RModel &model) override
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)
std::string Generate(std::string OpName) override
ROperator_Slice(std::string nameData, std::vector< std::string > names, std::string nameOutput)
std::vector< std::string > fNames
std::vector< size_t > fShapeOutput
std::vector< std::string_view > fInputTensorNames
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 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