Skip to content

Commit 5a58529

Browse files
committed
[sofie] Remove ConvertShapeToString and ConvertDynamicShapeToLength
Remove the redundant `ConvertShapeToString` and `ConvertDynamicShapeToLength` functions, because there are alternatives with more expressive names: `ConvertDimShapeToString` and `ConvertDimShapeToLength`. Having the same functions with different names is just confusing.
1 parent ed429da commit 5a58529

27 files changed

+79
-89
lines changed

tmva/sofie/inc/TMVA/ROperator_BasicBinary.hxx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ public:
127127
}
128128
if (dynamicInputs & 1 && model.Verbose())
129129
std::cout << BinaryOperatorTrait<T, Op>::Name() << " : input " << fNA << " is dynamic "
130-
<< ConvertShapeToString(fDimShapeA) << std::endl;
130+
<< ConvertDimShapeToString(fDimShapeA) << std::endl;
131131
if (dynamicInputs & 2 && model.Verbose())
132132
std::cout << BinaryOperatorTrait<T, Op>::Name() << " : input " << fNB << " is dynamic "
133-
<< ConvertShapeToString(fDimShapeB) << std::endl;
133+
<< ConvertDimShapeToString(fDimShapeB) << std::endl;
134134

135135
// check if need to broadcast at initialization time if shapes are known and different
136136
// (we could broadcast the tensor tensor to maximum values of dynamic shapes - to be done)
@@ -259,8 +259,8 @@ public:
259259

260260
model.AddIntermediateTensor(fNY, model.GetTensorType(fNA), fDimShapeY);
261261
if (model.Verbose()) {
262-
std::cout << BinaryOperatorTrait<T, Op>::Name() << " : " << ConvertShapeToString(fDimShapeA) << " , "
263-
<< ConvertShapeToString(fDimShapeB) << " --> " << ConvertShapeToString(fDimShapeY) << std::endl;
262+
std::cout << BinaryOperatorTrait<T, Op>::Name() << " : " << ConvertDimShapeToString(fDimShapeA) << " , "
263+
<< ConvertDimShapeToString(fDimShapeB) << " --> " << ConvertDimShapeToString(fDimShapeY) << std::endl;
264264
}
265265
}
266266
}

tmva/sofie/inc/TMVA/ROperator_BasicNary.hxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ public:
194194
if (model.Verbose()) {
195195
std::cout << NaryOperatorTraits<T, Op>::Name() << " : ";
196196
if (fNInputs.size() == 2)
197-
std::cout << ConvertShapeToString(fShapeInputs[0]) << " , "
198-
<< ConvertShapeToString(fShapeInputs[1]);
199-
std::cout << " --> " << ConvertShapeToString(fDimShapeY) << std::endl;
197+
std::cout << ConvertDimShapeToString(fShapeInputs[0]) << " , "
198+
<< ConvertDimShapeToString(fShapeInputs[1]);
199+
std::cout << " --> " << ConvertDimShapeToString(fDimShapeY) << std::endl;
200200
}
201201
}
202202

tmva/sofie/inc/TMVA/ROperator_BatchNormalization.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public:
111111

112112
if (fShapeX.size() < 2 || fShapeX.size() > 4) {
113113
throw
114-
std::runtime_error("TMVA SOFIE BatchNormalization Op input tensor " + fNX + " fnx has wrong shape : " + ConvertShapeToString(fShapeX));
114+
std::runtime_error("TMVA SOFIE BatchNormalization Op input tensor " + fNX + " fnx has wrong shape : " + ConvertDimShapeToString(fShapeX));
115115
}
116116

117117
fShapeY = fShapeX;

tmva/sofie/inc/TMVA/ROperator_Comparision.hxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,9 @@ public:
276276

277277
model.AddIntermediateTensor(fNY, ETensorType::BOOL, fDimShapeY);
278278
if (model.Verbose()) {
279-
std::cout << ComparisionTrait<T, Op>::Name() << " : " << fNX1 << " " << ConvertShapeToString(fDimShapeX1) << " , "
280-
<< fNX2 << " " << ConvertShapeToString(fDimShapeX2) << " --> "
281-
<< fNY << " " << ConvertShapeToString(fDimShapeY) << std::endl;
279+
std::cout << ComparisionTrait<T, Op>::Name() << " : " << fNX1 << " " << ConvertDimShapeToString(fDimShapeX1) << " , "
280+
<< fNX2 << " " << ConvertDimShapeToString(fDimShapeX2) << " --> "
281+
<< fNY << " " << ConvertDimShapeToString(fDimShapeY) << std::endl;
282282
model.PrintIntermediateTensors();
283283
}
284284
}

tmva/sofie/inc/TMVA/ROperator_Concat.hxx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
for (size_t i = 0; i < inputs.size(); i++) {
116116
if (i > 0 && inputs[i].size() != inputs[i - 1].size())
117117
throw std::runtime_error("TMVA SOFIE Concat Op - input tensors have different shapes " + fInputs[i] + " : " +
118-
ConvertShapeToString(inputs[i]) + " and " + fInputs[i-1] + " : " + ConvertShapeToString(inputs[i - 1]));
118+
ConvertDimShapeToString(inputs[i]) + " and " + fInputs[i-1] + " : " + ConvertDimShapeToString(inputs[i - 1]));
119119
for (size_t iaxis = 0; iaxis < inputs[i].size(); iaxis++) {
120120
if ((int)iaxis == fAxis) {
121121
// support both integer and params shape for the concatenation axis
@@ -134,8 +134,8 @@
134134
}
135135
else if ((!inputs[i][iaxis].isParam && !ret[iaxis].isParam) && (inputs[i][iaxis].dim != ret[iaxis].dim)) {
136136
throw std::runtime_error("TMVA SOFIE Concat Op - input tensors have wrong shapes " +
137-
ConvertShapeToString(inputs[i]) + " and " +
138-
ConvertShapeToString(inputs[i - 1]));
137+
ConvertDimShapeToString(inputs[i]) + " and " +
138+
ConvertDimShapeToString(inputs[i - 1]));
139139
}
140140
else if (!inputs[i][iaxis].isParam && ret[iaxis].isParam){
141141
// if shape is not parametric use it
@@ -240,7 +240,7 @@
240240
model.AddShapeTensor(fOutput,outputData, false); // cannot be a scalar
241241
if (model.Verbose()) {
242242
std::cout << "output of Concat is a shape tensor " << ConvertShapeToString(outputShape) << " : "
243-
<< ConvertShapeToString(outputData) << " (shape)" << std::endl;
243+
<< ConvertDimShapeToString(outputData) << " (shape)" << std::endl;
244244
}
245245
fIsOutputConstant = true;
246246
}
@@ -256,7 +256,7 @@
256256
std::string Generate(std::string opName) override {
257257
opName = "op_" + opName;
258258
std::stringstream out;
259-
out<<"\n//--------- Concat " << opName << " --> " << fOutput << " " << ConvertShapeToString(fOutputShape) << "\n";
259+
out<<"\n//--------- Concat " << opName << " --> " << fOutput << " " << ConvertDimShapeToString(fOutputShape) << "\n";
260260

261261
if (fIsOutputConstant) return out.str();
262262

tmva/sofie/inc/TMVA/ROperator_Constant.hxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,15 @@ public:
141141
std::stringstream out;
142142
if (fIsOutputConstant) {
143143
if (fNX.empty())
144-
out << "// ---- Constant (no-op) " << opName << " --> " << fNY << " " << ConvertShapeToString(fDimOutputShape) << "\n";
144+
out << "// ---- Constant (no-op) " << opName << " --> " << fNY << " " << ConvertDimShapeToString(fDimOutputShape) << "\n";
145145
else
146-
out << "// ---- ConstantOfShape (no-op) " << opName << " --> " << fNY << " " << ConvertShapeToString(fDimOutputShape) << "\n";
146+
out << "// ---- ConstantOfShape (no-op) " << opName << " --> " << fNY << " " << ConvertDimShapeToString(fDimOutputShape) << "\n";
147147
return out.str();
148148
}
149149
// Only ConstantOfShape might require generation code
150150
// generate constant tensor according to input
151151

152-
out << "\n//--------- ConstantOfShape " << opName << " --> " << ConvertShapeToString(fDimOutputShape) << "\n";
152+
out << "\n//--------- ConstantOfShape " << opName << " --> " << ConvertDimShapeToString(fDimOutputShape) << "\n";
153153
// set shape values if needed
154154
if (fIsUndefinedInputShape) {
155155
for (size_t i = 0; i < fDimOutputShape.size(); i++) {

tmva/sofie/inc/TMVA/ROperator_Conv.hxx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ public:
241241
}
242242
fShapeX = model.GetDimTensorShape(fNX);
243243
if (fShapeX.size() < 3 || fShapeX.size() > 5) {
244-
std::cout << fNX << " : " << ConvertShapeToString(fShapeX) << std::endl;
244+
std::cout << fNX << " : " << ConvertDimShapeToString(fShapeX) << std::endl;
245245
throw
246246
std::runtime_error("TMVA SOFIE Conv Op input data tensor" + fNX + " is not of 3,4 or 5 dimensions");
247247
}
@@ -325,8 +325,8 @@ public:
325325
fInputTensorNames.emplace_back(imcol);
326326

327327
if (model.Verbose()) {
328-
std::cout << "Conv - " << fDim << " " << fNX << " : " << ConvertShapeToString(fShapeX)
329-
<< " --> " << fNY << " : " << ConvertShapeToString(fShapeY) << std::endl;
328+
std::cout << "Conv - " << fDim << " " << fNX << " : " << ConvertDimShapeToString(fShapeX)
329+
<< " --> " << fNY << " : " << ConvertDimShapeToString(fShapeY) << std::endl;
330330
}
331331
}
332332

@@ -348,7 +348,7 @@ public:
348348
else
349349
out << SP << "{\n";
350350
out << SP << SP << "float * data = TMVA::Experimental::SOFIE::UTILITY::UnidirectionalBroadcast(tensor_"
351-
<< fNB << ", " << ConvertShapeToString(shape) << ", " << ConvertShapeToString(fShapeY) << ");\n";
351+
<< fNB << ", " << ConvertShapeToString(shape) << ", " << ConvertDimShapeToString(fShapeY) << ");\n";
352352
out << SP << SP << "fTensor_" << fNB << ".resize(" << length << ");\n";
353353
out << SP << SP << "std::copy(data, data + " << length << ", fTensor_" << fNB << ".begin());\n";
354354
out << SP << SP << "tensor_" << fNB << " = fTensor_" << fNB << ".data();\n";

tmva/sofie/inc/TMVA/ROperator_Expand.hxx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ public:
120120
}
121121
fType = ConvertTypeToString(model.GetTensorType(fNX));
122122
if (model.Verbose()) {
123-
std::cout << "Expand - input " << fNX << " shape " << ConvertShapeToString(fShapeX) << " --> " << fNY << " shape "
124-
<< ConvertShapeToString(fShapeY) << (fIsOutputConstant ? ConvertValuesToString(model.GetTensorData<T>(fNY)) + " (constant)" : "") << std::endl;
123+
std::cout << "Expand - input " << fNX << " shape " << ConvertDimShapeToString(fShapeX) << " --> " << fNY << " shape "
124+
<< ConvertDimShapeToString(fShapeY) << (fIsOutputConstant ? ConvertValuesToString(model.GetTensorData<T>(fNY)) + " (constant)" : "") << std::endl;
125125
}
126126
}
127127

@@ -143,7 +143,7 @@ public:
143143
throw std::runtime_error("TMVA SOFIE Expand Op called to Generate without being initialized first");
144144
}
145145
std::stringstream out;
146-
out << SP << "\n//------ Expand " << opName << " --> " << ConvertShapeToString(fShapeY) << "\n";
146+
out << SP << "\n//------ Expand " << opName << " --> " << ConvertDimShapeToString(fShapeY) << "\n";
147147
// need to declare shape parameters for non initialized shapes
148148
if (!fInitializedShape) {
149149
for (size_t i = 0; i < fShapeDim.size(); i++) {
@@ -153,7 +153,7 @@ public:
153153
// No need to broadcast A if it's an initialized tensor or shapes are the same
154154
if (!fInitialized && fShapeX != fShapeY) {
155155
out << SP << "// Broadcasting uninitialized tensor " << fNX << "\n";
156-
out << SP << "TMVA::Experimental::SOFIE::UTILITY::UnidirectionalBroadcast(tensor_" << fNX << ", " << ConvertShapeToString(fShapeX) << ", " << ConvertShapeToString(fShapeY)
156+
out << SP << "TMVA::Experimental::SOFIE::UTILITY::UnidirectionalBroadcast(tensor_" << fNX << ", " << ConvertDimShapeToString(fShapeX) << ", " << ConvertDimShapeToString(fShapeY)
157157
<< ", tensor_"<<fNY<<");\n";
158158
}
159159
return out.str();

tmva/sofie/inc/TMVA/ROperator_Gather.hxx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ public:
5454
}
5555
fShapeX = model.GetDimTensorShape(fNX);
5656
if (model.Verbose())
57-
std::cout << "Gather - initial shape " << ConvertShapeToString(fShapeX) << " shape of indices "
58-
<< ConvertShapeToString(model.GetDimTensorShape(fNIndices)) << std::endl;
57+
std::cout << "Gather - initial shape " << ConvertDimShapeToString(fShapeX) << " shape of indices "
58+
<< ConvertDimShapeToString(model.GetDimTensorShape(fNIndices)) << std::endl;
5959
// fShapeIndices can be dynamic
6060
fShapeIndices = model.GetDimTensorShape(fNIndices);
6161
size_t q = fShapeIndices.size();
@@ -86,7 +86,7 @@ public:
8686
}
8787
// Output shape
8888
if (model.Verbose())
89-
std::cout << "Gather: q and r " << q << " " << r << " shape indices " << ConvertShapeToString(fShapeIndices) << std::endl;
89+
std::cout << "Gather: q and r " << q << " " << r << " shape indices " << ConvertDimShapeToString(fShapeIndices) << std::endl;
9090

9191
if (fShapeY.empty()) {
9292
fShapeY.resize(q + r - 1);
@@ -128,15 +128,15 @@ public:
128128
// shapeY can be scalar or vector of size1
129129
model.AddShapeTensor(fNY, outputData, fShapeY.size() == 0);
130130
if (model.Verbose())
131-
std::cout << "Gather: " << fNX << " " << ConvertShapeToString(fShapeX) << " -> " << fNY << " with shape " << ConvertShapeToString(fShapeY)
132-
<< " and values " << ConvertShapeToString(outputData) << " (shape) " << std::endl;
131+
std::cout << "Gather: " << fNX << " " << ConvertDimShapeToString(fShapeX) << " -> " << fNY << " with shape " << ConvertDimShapeToString(fShapeY)
132+
<< " and values " << ConvertDimShapeToString(outputData) << " (shape) " << std::endl;
133133
} else {
134134
int64_t value = static_cast<int64_t>(outputData[0].dim);
135135
auto shapeY = ConvertShapeToInt(fShapeY);
136136
model.AddConstantTensor(fNY, shapeY, &value);
137137
fIsOutputConstant = true;
138138
if (model.Verbose())
139-
std::cout << "Gather: " << fNX << " " << ConvertShapeToString(fShapeX) << " -> " << fNY << " with shape " << ConvertShapeToString(fShapeY)
139+
std::cout << "Gather: " << fNX << " " << ConvertDimShapeToString(fShapeX) << " -> " << fNY << " with shape " << ConvertDimShapeToString(fShapeY)
140140
<< " and values {" << value << "} (constant) " << std::endl;
141141
}
142142
}
@@ -145,15 +145,15 @@ public:
145145
model.AddIntermediateTensor(fNY, model.GetTensorType(fNX), fShapeY);
146146
fType = ConvertTypeToString(model.GetTensorType(fNX));
147147
if (model.Verbose())
148-
std::cout << "Gather: input " << fNX << " " << ConvertShapeToString(fShapeX) << " indices " << fNIndices << ConvertShapeToString(fShapeIndices)
149-
<< " -> " << fNY << " with shape " << ConvertShapeToString(fShapeY) << std::endl;
148+
std::cout << "Gather: input " << fNX << " " << ConvertDimShapeToString(fShapeX) << " indices " << fNIndices << ConvertDimShapeToString(fShapeIndices)
149+
<< " -> " << fNY << " with shape " << ConvertDimShapeToString(fShapeY) << std::endl;
150150
}
151151
}
152152

153153
std::string Generate(std::string opName) override {
154154
opName = "op_" + opName;
155155
std::stringstream out;
156-
out << "//--------- Gather " << opName << " --> " << fNY << " " << ConvertShapeToString(fShapeY) << "\n";
156+
out << "//--------- Gather " << opName << " --> " << fNY << " " << ConvertDimShapeToString(fShapeY) << "\n";
157157
if (fIsOutputConstant) {
158158
// no code to generate here for constant output. Tensor output is defined in Session constructor
159159
out << "//--------------------(constant)----------\n";

tmva/sofie/inc/TMVA/ROperator_GatherND.hxx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public:
4444
}
4545
fShapeX = model.GetDimTensorShape(fNX);
4646
if (model.Verbose())
47-
std::cout << "GatherND - initial shape " << ConvertShapeToString(fShapeX) << " shape of indices "
48-
<< ConvertShapeToString(model.GetDimTensorShape(fNIndices)) << std::endl;
47+
std::cout << "GatherND - initial shape " << ConvertDimShapeToString(fShapeX) << " shape of indices "
48+
<< ConvertDimShapeToString(model.GetDimTensorShape(fNIndices)) << std::endl;
4949
// fShapeIndices can be dynamic
5050
fShapeIndices = model.GetDimTensorShape(fNIndices);
5151
size_t q = fShapeIndices.size();
@@ -64,8 +64,8 @@ public:
6464
if (fBatchDims > 0) {
6565
for (size_t i = 0; i < fBatchDims; i++) {
6666
if (fShapeX[i] != fShapeIndices[i]) {
67-
std::cout << " input shape " << ConvertShapeToString(fShapeX) << " "
68-
<< " index shape " << ConvertShapeToString(fShapeIndices) << std::endl;
67+
std::cout << " input shape " << ConvertDimShapeToString(fShapeX) << " "
68+
<< " index shape " << ConvertDimShapeToString(fShapeIndices) << std::endl;
6969
throw std::runtime_error("TMVA SOFIE GatherND : invalid input or index shape for " + std::to_string(i));
7070
}
7171
}
@@ -89,9 +89,9 @@ public:
8989
fShapeY = std::vector<Dim>(fShapeIndices.begin(), fShapeIndices.end() - 1);
9090
fShapeY.insert(fShapeY.end(), fShapeX.begin() + fBatchDims + last_index_shape, fShapeX.end());
9191
if (fShapeY.size() != output_rank) {
92-
std::cout << " input shape " << ConvertShapeToString(fShapeX) << " "
93-
<< " index shape " << ConvertShapeToString(fShapeIndices)
94-
<< " output shape " << ConvertShapeToString(fShapeY)
92+
std::cout << " input shape " << ConvertDimShapeToString(fShapeX) << " "
93+
<< " index shape " << ConvertDimShapeToString(fShapeIndices)
94+
<< " output shape " << ConvertDimShapeToString(fShapeY)
9595
<< " and output rank should be " << output_rank << std::endl;
9696
throw std::runtime_error("TMVA SOFIE GatherND : Something is wrong in initialization ");
9797
}
@@ -101,8 +101,8 @@ public:
101101
model.AddIntermediateTensor(fNY, model.GetTensorType(fNX), fShapeY);
102102
fType = ConvertTypeToString(model.GetTensorType(fNX));
103103
if (model.Verbose())
104-
std::cout << "GatherND: input " << fNX << " " << ConvertShapeToString(fShapeX) << " indices " << fNIndices << ConvertShapeToString(fShapeIndices)
105-
<< " -> " << fNY << " with shape " << ConvertShapeToString(fShapeY) << std::endl;
104+
std::cout << "GatherND: input " << fNX << " " << ConvertDimShapeToString(fShapeX) << " indices " << fNIndices << ConvertDimShapeToString(fShapeIndices)
105+
<< " -> " << fNY << " with shape " << ConvertDimShapeToString(fShapeY) << std::endl;
106106
}
107107

108108

@@ -176,7 +176,7 @@ public:
176176
}
177177
opName = "op_" + opName;
178178
std::stringstream out;
179-
out << "//--------- GatherND " << opName << " --> " << ConvertShapeToString(fShapeY) << "\n";
179+
out << "//--------- GatherND " << opName << " --> " << ConvertDimShapeToString(fShapeY) << "\n";
180180
// The shape of the output is q + r - 1
181181
size_t r = fShapeX.size();
182182
// Indices of shape q

0 commit comments

Comments
 (0)