blocky/conv/feat_block.cc
2022-10-05 11:44:56 +09:00

59 lines
1.2 KiB
C++

#include <fstream>
#include <iostream>
#include <string>
#include <args.hxx>
#include "common.hh"
namespace param {
using namespace ::args;
ArgumentParser parser {
"converter: feature -> block"
};
HelpFlag help {
parser, "help", "display this menu", {'h', "help"},
};
ValueFlag<std::string> fmap {
parser, "path", "path to feature map", {"fmap"},
};
} // namespace param
static void Exec() {
std::ifstream fmap_st {args::get(param::fmap)};
Enforce(!!fmap_st, "fmap path is invalid");
const auto fmap = ReadMatrix<uint32_t>(fmap_st);
Enforce(fmap.size() > 0, "empty fmap");
for (auto& idxs : fmap) {
Enforce(idxs.size() > 0, "fmap has empty item");
}
size_t feat;
while (std::cin >> feat) {
Enforce(feat < fmap.size(), "feat overflow");
for (const auto idx : fmap[feat]) {
std::cout << idx << ' ';
}
std::cout << '\n';
}
}
int main(int argc, char** argv)
try {
param::parser.ParseCLI(argc, argv);
Exec();
return EXIT_SUCCESS;
} catch (const args::Help&) {
std::cout << param::parser << std::endl;
return EXIT_SUCCESS;
} catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
return EXIT_FAILURE;
}