22 const std::string &option,
23 const std::string &default_value ) {
24 char **itr = std::find(argv, argv + argc, option);
25 if (itr != argv + argc && ++itr != argv + argc) {
26 return std::string(*itr);
33 const std::string &option,
34 const int default_value ) {
36 if (str.length() == 0) {
41 long l = std::strtol(str.c_str(), &end, 0);
42 if ((errno == ERANGE && l == LONG_MAX) || l > INT_MAX) {
44 }
else if ((errno == ERANGE && l == LONG_MIN) || l < INT_MIN) {
46 }
else if (*end !=
'\0') {
54 const std::string &option,
55 const double default_value ) {
57 if (str.length() == 0) {
62 double l = std::strtod(str.c_str(), &end);
63 if (errno == ERANGE && (l == HUGE_VAL || l == -HUGE_VAL)) {
65 }
else if (*end !=
'\0') {
74 const std::string &option,
75 const Eigen::VectorXd default_value
78 if (str.length() == 0 || (!(str.front() ==
'(' && str.back() ==
')') &&
79 !(str.front() ==
'[' && str.back() ==
']') &&
80 !(str.front() ==
'<' && str.back() ==
'>'))) {
83 std::vector<std::string> tokens =
85 Eigen::VectorXd vec(tokens.size());
86 for (
size_t i = 0; i < tokens.size(); i++) {
89 double l = std::strtod(tokens[i].c_str(), &end);
90 if (errno == ERANGE && (l == HUGE_VAL || l == -HUGE_VAL)) {
92 }
else if (*end !=
'\0') {
101 return std::find(argv, argv + argc, option) != argv + argc;
106 const std::vector<std::string> &options) {
107 for (
const auto &option : options) {
Helper functions for the ml ops.
int GetProgramOptionAsInt(int argc, char **argv, const std::string &option, const int default_value=0)
bool ProgramOptionExistsAny(int argc, char **argv, const std::vector< std::string > &options)
bool ProgramOptionExists(int argc, char **argv, const std::string &option)
std::string GetProgramOptionAsString(int argc, char **argv, const std::string &option, const std::string &default_value="")
void SplitString(std::vector< std::string > &tokens, const std::string &str, const std::string &delimiters=" ", bool trim_empty_str=true)
Eigen::VectorXd GetProgramOptionAsEigenVectorXd(int argc, char **argv, const std::string &option, const Eigen::VectorXd default_value=Eigen::VectorXd::Zero(0))
double GetProgramOptionAsDouble(int argc, char **argv, const std::string &option, const double default_value=0.0)
Generic file read and write utility for python interface.