Skip to content

Commit 3f05469

Browse files
committed
Fix the warning related to Multi-directional Broadcasting
1 parent a2150e5 commit 3f05469

File tree

3 files changed

+29
-31
lines changed

3 files changed

+29
-31
lines changed

tmva/sofie/inc/TMVA/SOFIE_common.hxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ ETensorType GetTemplatedType(T /*obj*/ ){
105105
namespace UTILITY{
106106
template<typename T>
107107
T* Unidirectional_broadcast(const T* original_data, const std::vector<size_t> original_shape, const std::vector<size_t> target_shape);
108-
template <typename T>
109-
std::vector<size_t> Multidirectional_broadcast(const T* original_data, std::vector<size_t> input1_shape, std::vector<size_t> input2_shape);
108+
109+
std::vector<size_t> Multidirectional_broadcast(std::vector<size_t> input1_shape, std::vector<size_t> input2_shape);
110110
std::string Clean_name(std::string input_tensor_name);
111111

112112

tmva/sofie/src/SOFIE_common.cxx

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -135,41 +135,21 @@ T* UTILITY::Unidirectional_broadcast(const T* original_data, const std::vector<s
135135
return new_datavector;
136136
}
137137

138-
template <typename T>
139-
std::vector<size_t> UTILITY::Multidirectional_broadcast(const T* original_data, std::vector<size_t> input1_shape, std::vector<size_t> input2_shape)
138+
139+
140+
std::vector<size_t> UTILITY::Multidirectional_broadcast(std::vector<size_t> input1_shape, std::vector<size_t> input2_shape)
140141
{
141142
std::vector<size_t> input_shape = (input1_shape > input2_shape)?input1_shape:input2_shape;
142143
std::vector<size_t> output_shape(input_shape);
143144

144-
//check if both the input have same shape, nothing to do directly return the output_shape as the same shape.
145-
if(input1_shape.size() == input2_shape.size()){
146-
if(input1_shape == input2_shape){
147-
return output_shape;
148-
}
149-
else{
150-
//Check the shape values, if input1[i] not equal to input2[i] we have the result shape equal to input1[i] if input2[i] = 1 or viceversa
151-
for(size_t j = 0; j < input1_shape.size() ; j++){
152-
if(input1_shape[j] == input2_shape[j]){
153-
output_shape[j] = input1_shape[j];
154-
}
155-
else if(input1_shape[j] > input2_shape[j] && input2_shape[j] == 1){
156-
output_shape[j] = input1_shape[j];
157-
}
158-
else if(input2_shape[j] > input1_shape[j] && input1_shape[j] == 1){
159-
output_shape[j] = input2_shape[j];
160-
}
161-
}
162-
return output_shape;
163-
}
164-
}
165-
else if(input1_shape.size() < input2_shape.size()){
145+
if(input1_shape.size() < input2_shape.size()){
166146
// Check if input1_shape.size() < input2_shape.size() we insert in the shape vector values of 1 at the beginning of the tensor until input1_shape.size() == input2_shape.size()
167147
auto it = input1_shape.begin();
168148
while (input1_shape.size() < input2_shape.size()) {
169149
it = input1_shape.insert(it, 1);
170150
}
171151
if(input1_shape.size()==input1_shape.size()){
172-
UTILITY::Multidirectional_broadcast(original_data,input1_shape,input2_shape);
152+
UTILITY::Multidirectional_broadcast(input1_shape,input2_shape);
173153
}
174154
}
175155
else if(input2_shape.size() < input1_shape.size()){
@@ -179,9 +159,28 @@ std::vector<size_t> UTILITY::Multidirectional_broadcast(const T* original_data,
179159
it = input2_shape.insert(it, 1);
180160
}
181161
if(input1_shape.size()==input1_shape.size()){
182-
UTILITY::Multidirectional_broadcast(original_data,input1_shape,input2_shape);
162+
UTILITY::Multidirectional_broadcast(input1_shape,input2_shape);
183163
}
184164
}
165+
//check if both the input have same shape, nothing to do directly return the output_shape as the same shape.
166+
else if(input1_shape.size() == input2_shape.size()){
167+
if(input1_shape != input2_shape){
168+
//Check the shape values, if input1[i] not equal to input2[i] we have the result shape equal to input1[i] if input2[i] = 1 or viceversa
169+
for(size_t j = 0; j < input1_shape.size() ; j++){
170+
if(input1_shape[j] == input2_shape[j]){
171+
output_shape[j] = input1_shape[j];
172+
}
173+
else if(input1_shape[j] > input2_shape[j] && input2_shape[j] == 1){
174+
output_shape[j] = input1_shape[j];
175+
}
176+
else if(input2_shape[j] > input1_shape[j] && input1_shape[j] == 1){
177+
output_shape[j] = input2_shape[j];
178+
}
179+
}
180+
}
181+
182+
}
183+
return output_shape;
185184

186185
}
187186

@@ -192,7 +191,6 @@ std::string UTILITY::Clean_name(std::string input_tensor_name){
192191
}
193192

194193
template float* UTILITY::Unidirectional_broadcast(const float* original_data, const std::vector<size_t> original_shape, const std::vector<size_t> target_shape);
195-
template std::vector<size_t> UTILITY::Multidirectional_broadcast(const float* original_data, std::vector<size_t> input1_shape, std::vector<size_t> input2_shape);
196194

197195
}//SOFIE
198196
}//Experimental

tmva/sofie_parsers/src/RModelParser_ONNX.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ std::unique_ptr<ROperator> make_ROperator_BasicBinary(const onnx::NodeProto& nod
4040
} else {
4141
// check if input tensor is an initialized tensor
4242
bool isInitializer = false;
43-
for (int i=0; i < graphproto.initializer_size(); i++){
44-
if (input_name == graphproto.initializer(i).name()) {
43+
for (int j=0; j < graphproto.initializer_size(); j++){
44+
if (input_name == graphproto.initializer(j).name()) {
4545
isInitializer = true;
4646
break;
4747
}

0 commit comments

Comments
 (0)