Commit de62b8ac authored by Paul's avatar Paul
Browse files

Formatting

parent c20d0fc2
......@@ -55,21 +55,21 @@ struct argument_parser
{
std::vector<std::string> flags;
std::function<bool(argument_parser&, const std::vector<std::string>&)> action{};
std::string type = "";
std::string help = "";
std::string type = "";
std::string help = "";
std::string metavar = "";
unsigned nargs = 1;
unsigned nargs = 1;
};
template <class T, class... Fs>
void add(T& x, std::vector<std::string> flags, Fs... fs)
{
arguments.push_back({flags, [&](auto&&, const std::vector<std::string>& params) {
if(params.empty())
throw std::runtime_error("Flag with no value.");
x = value_parser<T>::apply(params.back());
return false;
}});
if(params.empty())
throw std::runtime_error("Flag with no value.");
x = value_parser<T>::apply(params.back());
return false;
}});
argument& arg = arguments.back();
arg.type = migraphx::get_type_name<T>();
......@@ -89,9 +89,7 @@ struct argument_parser
static auto nargs(unsigned n = 1)
{
return [=](auto&&, auto& arg) {
arg.nargs = n;
};
return [=](auto&&, auto& arg) { arg.nargs = n; };
}
template <class F>
......@@ -109,7 +107,7 @@ struct argument_parser
static auto do_action(F f)
{
return [=](auto&, auto& arg) {
arg.nargs = 0;
arg.nargs = 0;
arg.action = [&, f](auto& self, const std::vector<std::string>&) {
f(self);
return true;
......@@ -135,7 +133,7 @@ struct argument_parser
{
std::cout << std::endl;
std::string prefix = " ";
if (arg.flags.empty())
if(arg.flags.empty())
{
std::cout << prefix;
std::cout << arg.metavar;
......@@ -185,16 +183,14 @@ struct argument_parser
std::unordered_map<std::string, unsigned> keywords;
for(auto&& arg : arguments)
{
for(auto&& flag:arg.flags)
for(auto&& flag : arg.flags)
keywords[flag] = arg.nargs + 1;
}
auto arg_map = generic_parse(args, [&](std::string x) {
return keywords[x];
});
auto arg_map = generic_parse(args, [&](std::string x) { return keywords[x]; });
for(auto&& arg : arguments)
{
auto flags = arg.flags;
if (flags.empty())
if(flags.empty())
flags = {""};
for(auto&& flag : arg.flags)
{
......@@ -223,18 +219,17 @@ struct argument_parser
{
flag = x;
result[flag]; // Ensure the flag exists
if (k == 1)
if(k == 1)
flag = "";
else if (k == 2)
else if(k == 2)
clear = true;
else
clear = false;
}
else
{
result[flag].push_back(x);
if (clear)
if(clear)
flag = "";
clear = false;
}
......
......@@ -26,15 +26,15 @@ std::string command_name()
return name.substr(name.rfind("::") + 2);
}
template<class T>
void run_command(std::vector<std::string> args, bool add_help=false)
template <class T>
void run_command(std::vector<std::string> args, bool add_help = false)
{
T x;
argument_parser ap;
if (add_help)
if(add_help)
ap.add(nullptr, {"-h", "--help"}, ap.help("Show help"), ap.show_help());
x.parse(ap);
if (ap.parse(args))
if(ap.parse(args))
return;
x.run();
}
......@@ -43,9 +43,7 @@ template <class T>
int auto_register_command()
{
auto& m = get_commands();
m[command_name<T>()] = [](std::vector<std::string> args) {
run_command<T>(args, true);
};
m[command_name<T>()] = [](std::vector<std::string> args) { run_command<T>(args, true); };
return 0;
}
......
......@@ -21,22 +21,23 @@ struct loader
ap.add(type, {"--onnx"}, ap.help("Load as onnx"), ap.set_value("onnx"));
ap.add(type, {"--tf"}, ap.help("Load as tensorflow"), ap.set_value("tf"));
ap.add(is_nhwc, {"--nhwc"}, ap.help("Treat tensorflow format as nhwc"), ap.set_value(true));
ap.add(is_nhwc, {"--nchw"}, ap.help("Treat tensorflow format as nchw"), ap.set_value(false));
ap.add(
is_nhwc, {"--nchw"}, ap.help("Treat tensorflow format as nchw"), ap.set_value(false));
}
program load()
program load()
{
program p;
if (type.empty())
if(type.empty())
{
if (ends_with(file, ".onnx"))
if(ends_with(file, ".onnx"))
type = "onnx";
else
type = "tf";
}
if (type == "onnx")
if(type == "onnx")
p = parse_onnx(file);
else if (type == "tf")
else if(type == "tf")
p = parse_tf(file, is_nhwc);
return p;
}
......@@ -45,10 +46,7 @@ struct loader
struct read : command<read>
{
loader l;
void parse(argument_parser& ap)
{
l.parse(ap);
}
void parse(argument_parser& ap) { l.parse(ap); }
void run()
{
......
......@@ -23,9 +23,10 @@ using bool_c = std::integral_constant<bool, B>;
#ifdef CPPCHECK
#define MIGRAPHX_REQUIRES(...) class = void
#else
#define MIGRAPHX_REQUIRES(...) \
bool MIGRAPHX_REQUIRES_VAR()=true, \
typename std::enable_if<(MIGRAPHX_REQUIRES_VAR() && (migraphx::and_<__VA_ARGS__>{})), int>::type = 0
#define MIGRAPHX_REQUIRES(...) \
bool MIGRAPHX_REQUIRES_VAR() = true, \
typename std::enable_if<(MIGRAPHX_REQUIRES_VAR() && (migraphx::and_<__VA_ARGS__>{})), \
int>::type = 0
#endif
} // namespace MIGRAPHX_INLINE_NS
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment