blocky/conv/feat_block.cc

58 lines
1.3 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 = ReadTensor3<uint32_t>(fmap_st);
Enforce(fmap.size() > 0 && fmap[0].size() > 0, "empty fmap");
for (auto& fmap_t : fmap) {
Enforce(fmap_t.size() == fmap[0].size(), "fmap is broken");
}
for (size_t feat, t = 0; std::cin >> feat; ++t) {
const auto tidx = t % fmap.size();
Enforce(feat < fmap[tidx].size(), "feat overflow");
for (const auto idx : fmap[tidx][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;
}