Committed by
GitHub
parse option in64_t (#1089)
Signed-off-by: Manix <manickavela1998@gmail.com>
正在显示
2 个修改的文件
包含
42 行增加
和
0 行删除
| @@ -49,6 +49,11 @@ void ParseOptions::Register(const std::string &name, int32_t *ptr, | @@ -49,6 +49,11 @@ void ParseOptions::Register(const std::string &name, int32_t *ptr, | ||
| 49 | RegisterTmpl(name, ptr, doc); | 49 | RegisterTmpl(name, ptr, doc); |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | +void ParseOptions::Register(const std::string &name, int64_t *ptr, | ||
| 53 | + const std::string &doc) { | ||
| 54 | + RegisterTmpl(name, ptr, doc); | ||
| 55 | +} | ||
| 56 | + | ||
| 52 | void ParseOptions::Register(const std::string &name, uint32_t *ptr, | 57 | void ParseOptions::Register(const std::string &name, uint32_t *ptr, |
| 53 | const std::string &doc) { | 58 | const std::string &doc) { |
| 54 | RegisterTmpl(name, ptr, doc); | 59 | RegisterTmpl(name, ptr, doc); |
| @@ -126,6 +131,15 @@ void ParseOptions::RegisterSpecific(const std::string &name, | @@ -126,6 +131,15 @@ void ParseOptions::RegisterSpecific(const std::string &name, | ||
| 126 | } | 131 | } |
| 127 | 132 | ||
| 128 | void ParseOptions::RegisterSpecific(const std::string &name, | 133 | void ParseOptions::RegisterSpecific(const std::string &name, |
| 134 | + const std::string &idx, int64_t *i, | ||
| 135 | + const std::string &doc, bool is_standard) { | ||
| 136 | + int64_map_[idx] = i; | ||
| 137 | + std::ostringstream ss; | ||
| 138 | + ss << doc << " (int64, default = " << *i << ")"; | ||
| 139 | + doc_map_[idx] = DocInfo(name, ss.str(), is_standard); | ||
| 140 | +} | ||
| 141 | + | ||
| 142 | +void ParseOptions::RegisterSpecific(const std::string &name, | ||
| 129 | const std::string &idx, uint32_t *u, | 143 | const std::string &idx, uint32_t *u, |
| 130 | const std::string &doc, bool is_standard) { | 144 | const std::string &doc, bool is_standard) { |
| 131 | uint_map_[idx] = u; | 145 | uint_map_[idx] = u; |
| @@ -172,6 +186,7 @@ void ParseOptions::DisableOption(const std::string &name) { | @@ -172,6 +186,7 @@ void ParseOptions::DisableOption(const std::string &name) { | ||
| 172 | } | 186 | } |
| 173 | bool_map_.erase(name); | 187 | bool_map_.erase(name); |
| 174 | int_map_.erase(name); | 188 | int_map_.erase(name); |
| 189 | + int64_map_.erase(name); | ||
| 175 | uint_map_.erase(name); | 190 | uint_map_.erase(name); |
| 176 | float_map_.erase(name); | 191 | float_map_.erase(name); |
| 177 | double_map_.erase(name); | 192 | double_map_.erase(name); |
| @@ -411,6 +426,8 @@ void ParseOptions::PrintConfig(std::ostream &os) const { | @@ -411,6 +426,8 @@ void ParseOptions::PrintConfig(std::ostream &os) const { | ||
| 411 | os << (*bool_map_.at(key) ? "true" : "false"); | 426 | os << (*bool_map_.at(key) ? "true" : "false"); |
| 412 | } else if (int_map_.end() != int_map_.find(key)) { | 427 | } else if (int_map_.end() != int_map_.find(key)) { |
| 413 | os << (*int_map_.at(key)); | 428 | os << (*int_map_.at(key)); |
| 429 | + } else if (int64_map_.end() != int64_map_.find(key)) { | ||
| 430 | + os << (*int64_map_.at(key)); | ||
| 414 | } else if (uint_map_.end() != uint_map_.find(key)) { | 431 | } else if (uint_map_.end() != uint_map_.find(key)) { |
| 415 | os << (*uint_map_.at(key)); | 432 | os << (*uint_map_.at(key)); |
| 416 | } else if (float_map_.end() != float_map_.find(key)) { | 433 | } else if (float_map_.end() != float_map_.find(key)) { |
| @@ -533,6 +550,8 @@ bool ParseOptions::SetOption(const std::string &key, const std::string &value, | @@ -533,6 +550,8 @@ bool ParseOptions::SetOption(const std::string &key, const std::string &value, | ||
| 533 | *(bool_map_[key]) = ToBool(value); | 550 | *(bool_map_[key]) = ToBool(value); |
| 534 | } else if (int_map_.end() != int_map_.find(key)) { | 551 | } else if (int_map_.end() != int_map_.find(key)) { |
| 535 | *(int_map_[key]) = ToInt(value); | 552 | *(int_map_[key]) = ToInt(value); |
| 553 | + } else if (int64_map_.end() != int64_map_.find(key)) { | ||
| 554 | + *(int64_map_[key]) = ToInt64(value); | ||
| 536 | } else if (uint_map_.end() != uint_map_.find(key)) { | 555 | } else if (uint_map_.end() != uint_map_.find(key)) { |
| 537 | *(uint_map_[key]) = ToUint(value); | 556 | *(uint_map_[key]) = ToUint(value); |
| 538 | } else if (float_map_.end() != float_map_.find(key)) { | 557 | } else if (float_map_.end() != float_map_.find(key)) { |
| @@ -580,6 +599,15 @@ int32_t ParseOptions::ToInt(const std::string &str) const { | @@ -580,6 +599,15 @@ int32_t ParseOptions::ToInt(const std::string &str) const { | ||
| 580 | return ret; | 599 | return ret; |
| 581 | } | 600 | } |
| 582 | 601 | ||
| 602 | +int64_t ParseOptions::ToInt64(const std::string &str) const { | ||
| 603 | + int64_t ret = 0; | ||
| 604 | + if (!ConvertStringToInteger(str, &ret)) { | ||
| 605 | + SHERPA_ONNX_LOGE("Invalid integer int64 option \"%s\"", str.c_str()); | ||
| 606 | + exit(-1); | ||
| 607 | + } | ||
| 608 | + return ret; | ||
| 609 | +} | ||
| 610 | + | ||
| 583 | uint32_t ParseOptions::ToUint(const std::string &str) const { | 611 | uint32_t ParseOptions::ToUint(const std::string &str) const { |
| 584 | uint32_t ret = 0; | 612 | uint32_t ret = 0; |
| 585 | if (!ConvertStringToInteger(str, &ret)) { | 613 | if (!ConvertStringToInteger(str, &ret)) { |
| @@ -612,6 +640,8 @@ template void ParseOptions::RegisterTmpl(const std::string &name, bool *ptr, | @@ -612,6 +640,8 @@ template void ParseOptions::RegisterTmpl(const std::string &name, bool *ptr, | ||
| 612 | const std::string &doc); | 640 | const std::string &doc); |
| 613 | template void ParseOptions::RegisterTmpl(const std::string &name, int32_t *ptr, | 641 | template void ParseOptions::RegisterTmpl(const std::string &name, int32_t *ptr, |
| 614 | const std::string &doc); | 642 | const std::string &doc); |
| 643 | +template void ParseOptions::RegisterTmpl(const std::string &name, int64_t *ptr, | ||
| 644 | + const std::string &doc); | ||
| 615 | template void ParseOptions::RegisterTmpl(const std::string &name, uint32_t *ptr, | 645 | template void ParseOptions::RegisterTmpl(const std::string &name, uint32_t *ptr, |
| 616 | const std::string &doc); | 646 | const std::string &doc); |
| 617 | template void ParseOptions::RegisterTmpl(const std::string &name, float *ptr, | 647 | template void ParseOptions::RegisterTmpl(const std::string &name, float *ptr, |
| @@ -628,6 +658,9 @@ template void ParseOptions::RegisterStandard(const std::string &name, | @@ -628,6 +658,9 @@ template void ParseOptions::RegisterStandard(const std::string &name, | ||
| 628 | int32_t *ptr, | 658 | int32_t *ptr, |
| 629 | const std::string &doc); | 659 | const std::string &doc); |
| 630 | template void ParseOptions::RegisterStandard(const std::string &name, | 660 | template void ParseOptions::RegisterStandard(const std::string &name, |
| 661 | + int64_t *ptr, | ||
| 662 | + const std::string &doc); | ||
| 663 | +template void ParseOptions::RegisterStandard(const std::string &name, | ||
| 631 | uint32_t *ptr, | 664 | uint32_t *ptr, |
| 632 | const std::string &doc); | 665 | const std::string &doc); |
| 633 | template void ParseOptions::RegisterStandard(const std::string &name, | 666 | template void ParseOptions::RegisterStandard(const std::string &name, |
| @@ -647,6 +680,9 @@ template void ParseOptions::RegisterCommon(const std::string &name, | @@ -647,6 +680,9 @@ template void ParseOptions::RegisterCommon(const std::string &name, | ||
| 647 | int32_t *ptr, const std::string &doc, | 680 | int32_t *ptr, const std::string &doc, |
| 648 | bool is_standard); | 681 | bool is_standard); |
| 649 | template void ParseOptions::RegisterCommon(const std::string &name, | 682 | template void ParseOptions::RegisterCommon(const std::string &name, |
| 683 | + int64_t *ptr, const std::string &doc, | ||
| 684 | + bool is_standard); | ||
| 685 | +template void ParseOptions::RegisterCommon(const std::string &name, | ||
| 650 | uint32_t *ptr, | 686 | uint32_t *ptr, |
| 651 | const std::string &doc, | 687 | const std::string &doc, |
| 652 | bool is_standard); | 688 | bool is_standard); |
| @@ -63,6 +63,7 @@ class ParseOptions { | @@ -63,6 +63,7 @@ class ParseOptions { | ||
| 63 | 63 | ||
| 64 | void Register(const std::string &name, bool *ptr, const std::string &doc); | 64 | void Register(const std::string &name, bool *ptr, const std::string &doc); |
| 65 | void Register(const std::string &name, int32_t *ptr, const std::string &doc); | 65 | void Register(const std::string &name, int32_t *ptr, const std::string &doc); |
| 66 | + void Register(const std::string &name, int64_t *ptr, const std::string &doc); | ||
| 66 | void Register(const std::string &name, uint32_t *ptr, const std::string &doc); | 67 | void Register(const std::string &name, uint32_t *ptr, const std::string &doc); |
| 67 | void Register(const std::string &name, float *ptr, const std::string &doc); | 68 | void Register(const std::string &name, float *ptr, const std::string &doc); |
| 68 | void Register(const std::string &name, double *ptr, const std::string &doc); | 69 | void Register(const std::string &name, double *ptr, const std::string &doc); |
| @@ -134,6 +135,9 @@ class ParseOptions { | @@ -134,6 +135,9 @@ class ParseOptions { | ||
| 134 | /// Register int32_t variable | 135 | /// Register int32_t variable |
| 135 | void RegisterSpecific(const std::string &name, const std::string &idx, | 136 | void RegisterSpecific(const std::string &name, const std::string &idx, |
| 136 | int32_t *i, const std::string &doc, bool is_standard); | 137 | int32_t *i, const std::string &doc, bool is_standard); |
| 138 | + /// Register int64_t variable | ||
| 139 | + void RegisterSpecific(const std::string &name, const std::string &idx, | ||
| 140 | + int64_t *i, const std::string &doc, bool is_standard); | ||
| 137 | /// Register unsigned int32_t variable | 141 | /// Register unsigned int32_t variable |
| 138 | void RegisterSpecific(const std::string &name, const std::string &idx, | 142 | void RegisterSpecific(const std::string &name, const std::string &idx, |
| 139 | uint32_t *u, const std::string &doc, bool is_standard); | 143 | uint32_t *u, const std::string &doc, bool is_standard); |
| @@ -163,6 +167,7 @@ class ParseOptions { | @@ -163,6 +167,7 @@ class ParseOptions { | ||
| 163 | 167 | ||
| 164 | bool ToBool(std::string str) const; | 168 | bool ToBool(std::string str) const; |
| 165 | int32_t ToInt(const std::string &str) const; | 169 | int32_t ToInt(const std::string &str) const; |
| 170 | + int64_t ToInt64(const std::string &str) const; | ||
| 166 | uint32_t ToUint(const std::string &str) const; | 171 | uint32_t ToUint(const std::string &str) const; |
| 167 | float ToFloat(const std::string &str) const; | 172 | float ToFloat(const std::string &str) const; |
| 168 | double ToDouble(const std::string &str) const; | 173 | double ToDouble(const std::string &str) const; |
| @@ -170,6 +175,7 @@ class ParseOptions { | @@ -170,6 +175,7 @@ class ParseOptions { | ||
| 170 | // maps for option variables | 175 | // maps for option variables |
| 171 | std::unordered_map<std::string, bool *> bool_map_; | 176 | std::unordered_map<std::string, bool *> bool_map_; |
| 172 | std::unordered_map<std::string, int32_t *> int_map_; | 177 | std::unordered_map<std::string, int32_t *> int_map_; |
| 178 | + std::unordered_map<std::string, int64_t *> int64_map_; | ||
| 173 | std::unordered_map<std::string, uint32_t *> uint_map_; | 179 | std::unordered_map<std::string, uint32_t *> uint_map_; |
| 174 | std::unordered_map<std::string, float *> float_map_; | 180 | std::unordered_map<std::string, float *> float_map_; |
| 175 | std::unordered_map<std::string, double *> double_map_; | 181 | std::unordered_map<std::string, double *> double_map_; |
-
请 注册 或 登录 后发表评论