Skip to content

Commit 2e8c34a

Browse files
committed
[tmva][sofie] Fix compiler warning in tests
The last commit that changed the tests left a compiler warning: ```txt In file included from /home/rembserj/code/root/root_src/tmva/sofie/test/TestCustomModelsFromONNX.cxx:3: /home/rembserj/code/root/root_src/tmva/sofie/test/test_helpers.h: In instantiation of ‘OutputType_t runModel(std::string, const std::string&, std::string, const Ts& ...) [with OutputType_t = std::vector<float>; Ts = {}; std::string = std::__cxx11::basic_string<char>]’: /home/rembserj/code/root/root_src/tmva/sofie/test/TestCustomModelsFromONNX.cxx:318:4: required from here 130 | auto output = runModel<OutputType>(#OutputType, _modelName, ""); | ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/rembserj/code/root/root_src/tmva/sofie/test/test_helpers.h:74:9: warning: variable ‘type_name’ set but not used [-Wunused-but-set-variable] 74 | auto type_name = []<typename T>() { | ^~~~~~~~~ /home/rembserj/code/root/root_src/tmva/sofie/test/test_helpers.h:107:9: warning: variable ‘first’ set but not used [-Wunused-but-set-variable] 107 | bool first = true; | ^~~~~ cc1plus: note: unrecognized command-line option ‘-Wno-unused-command-line-argument’ may have been intended to silence earlier diagnostics ``` This can be avoided by guarding the parameter pack expension in an if clause that checks if the size of the parameter pack is not empty.
1 parent 305c865 commit 2e8c34a

1 file changed

Lines changed: 28 additions & 25 deletions

File tree

tmva/sofie/test/test_helpers.h

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,6 @@ runModel(std::string outputTypeName, std::string const &modelName, std::string s
7070
outputTypeName = "std::tuple<std::vector<float>, std::vector<int64_t>>";
7171
}
7272

73-
// Helper: map C++ type -> string used in interpreter
74-
auto type_name = []<typename T>() {
75-
if constexpr (std::is_same_v<T, int>)
76-
return "int";
77-
else if constexpr (std::is_same_v<T, std::vector<float>>)
78-
return "std::vector<float>";
79-
else if constexpr (std::is_same_v<T, std::vector<int>>)
80-
return "std::vector<float>";
81-
else if constexpr (std::is_same_v<T, std::vector<int64_t>>)
82-
return "std::vector<int64_t>";
83-
else if constexpr (std::is_same_v<T, std::vector<uint8_t>>)
84-
return "std::vector<uint8_t>";
85-
else
86-
static_assert(!sizeof(T), "Input type not supported");
87-
};
88-
8973
std::stringstream cmd;
9074

9175
if (sessionArgs.empty()) {
@@ -104,15 +88,34 @@ runModel(std::string outputTypeName, std::string const &modelName, std::string s
10488
}
10589

10690
// Emit all inputs to s.infer(...)
107-
bool first = true;
108-
(
109-
[&] {
110-
if (!first)
111-
cmd << ", ";
112-
first = false;
113-
cmd << toInterpreter(inputs, type_name.template operator()<Ts>(), true);
114-
}(),
115-
...);
91+
if constexpr (sizeof...(Ts) > 0) {
92+
93+
// Helper: map C++ type -> string used in interpreter
94+
auto type_name = []<typename T>() {
95+
if constexpr (std::is_same_v<T, int>)
96+
return "int";
97+
else if constexpr (std::is_same_v<T, std::vector<float>>)
98+
return "std::vector<float>";
99+
else if constexpr (std::is_same_v<T, std::vector<int>>)
100+
return "std::vector<float>";
101+
else if constexpr (std::is_same_v<T, std::vector<int64_t>>)
102+
return "std::vector<int64_t>";
103+
else if constexpr (std::is_same_v<T, std::vector<uint8_t>>)
104+
return "std::vector<uint8_t>";
105+
else
106+
static_assert(!sizeof(T), "Input type not supported");
107+
};
108+
109+
bool first = true;
110+
(
111+
[&] {
112+
if (!first)
113+
cmd << ", ";
114+
first = false;
115+
cmd << toInterpreter(inputs, type_name.template operator()<Ts>(), true);
116+
}(),
117+
...);
118+
}
116119

117120
cmd << R"();
118121
std::swap(output, *)"

0 commit comments

Comments
 (0)