Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
xuning
/
sherpaonnx
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Manix
2024-07-08 13:07:30 +0530
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
GitHub
2024-07-08 15:37:30 +0800
Commit
d6fbecd947a63f84176f3a2a30501dbaa111f7b9
d6fbecd9
1 parent
5817d6c3
parse option in64_t (#1089)
Signed-off-by: Manix <manickavela1998@gmail.com>
隐藏空白字符变更
内嵌
并排对比
正在显示
2 个修改的文件
包含
42 行增加
和
0 行删除
sherpa-onnx/csrc/parse-options.cc
sherpa-onnx/csrc/parse-options.h
sherpa-onnx/csrc/parse-options.cc
查看文件 @
d6fbecd
...
...
@@ -49,6 +49,11 @@ void ParseOptions::Register(const std::string &name, int32_t *ptr,
RegisterTmpl
(
name
,
ptr
,
doc
);
}
void
ParseOptions
::
Register
(
const
std
::
string
&
name
,
int64_t
*
ptr
,
const
std
::
string
&
doc
)
{
RegisterTmpl
(
name
,
ptr
,
doc
);
}
void
ParseOptions
::
Register
(
const
std
::
string
&
name
,
uint32_t
*
ptr
,
const
std
::
string
&
doc
)
{
RegisterTmpl
(
name
,
ptr
,
doc
);
...
...
@@ -126,6 +131,15 @@ void ParseOptions::RegisterSpecific(const std::string &name,
}
void
ParseOptions
::
RegisterSpecific
(
const
std
::
string
&
name
,
const
std
::
string
&
idx
,
int64_t
*
i
,
const
std
::
string
&
doc
,
bool
is_standard
)
{
int64_map_
[
idx
]
=
i
;
std
::
ostringstream
ss
;
ss
<<
doc
<<
" (int64, default = "
<<
*
i
<<
")"
;
doc_map_
[
idx
]
=
DocInfo
(
name
,
ss
.
str
(),
is_standard
);
}
void
ParseOptions
::
RegisterSpecific
(
const
std
::
string
&
name
,
const
std
::
string
&
idx
,
uint32_t
*
u
,
const
std
::
string
&
doc
,
bool
is_standard
)
{
uint_map_
[
idx
]
=
u
;
...
...
@@ -172,6 +186,7 @@ void ParseOptions::DisableOption(const std::string &name) {
}
bool_map_
.
erase
(
name
);
int_map_
.
erase
(
name
);
int64_map_
.
erase
(
name
);
uint_map_
.
erase
(
name
);
float_map_
.
erase
(
name
);
double_map_
.
erase
(
name
);
...
...
@@ -411,6 +426,8 @@ void ParseOptions::PrintConfig(std::ostream &os) const {
os
<<
(
*
bool_map_
.
at
(
key
)
?
"true"
:
"false"
);
}
else
if
(
int_map_
.
end
()
!=
int_map_
.
find
(
key
))
{
os
<<
(
*
int_map_
.
at
(
key
));
}
else
if
(
int64_map_
.
end
()
!=
int64_map_
.
find
(
key
))
{
os
<<
(
*
int64_map_
.
at
(
key
));
}
else
if
(
uint_map_
.
end
()
!=
uint_map_
.
find
(
key
))
{
os
<<
(
*
uint_map_
.
at
(
key
));
}
else
if
(
float_map_
.
end
()
!=
float_map_
.
find
(
key
))
{
...
...
@@ -533,6 +550,8 @@ bool ParseOptions::SetOption(const std::string &key, const std::string &value,
*
(
bool_map_
[
key
])
=
ToBool
(
value
);
}
else
if
(
int_map_
.
end
()
!=
int_map_
.
find
(
key
))
{
*
(
int_map_
[
key
])
=
ToInt
(
value
);
}
else
if
(
int64_map_
.
end
()
!=
int64_map_
.
find
(
key
))
{
*
(
int64_map_
[
key
])
=
ToInt64
(
value
);
}
else
if
(
uint_map_
.
end
()
!=
uint_map_
.
find
(
key
))
{
*
(
uint_map_
[
key
])
=
ToUint
(
value
);
}
else
if
(
float_map_
.
end
()
!=
float_map_
.
find
(
key
))
{
...
...
@@ -580,6 +599,15 @@ int32_t ParseOptions::ToInt(const std::string &str) const {
return
ret
;
}
int64_t
ParseOptions
::
ToInt64
(
const
std
::
string
&
str
)
const
{
int64_t
ret
=
0
;
if
(
!
ConvertStringToInteger
(
str
,
&
ret
))
{
SHERPA_ONNX_LOGE
(
"Invalid integer int64 option
\"
%s
\"
"
,
str
.
c_str
());
exit
(
-
1
);
}
return
ret
;
}
uint32_t
ParseOptions
::
ToUint
(
const
std
::
string
&
str
)
const
{
uint32_t
ret
=
0
;
if
(
!
ConvertStringToInteger
(
str
,
&
ret
))
{
...
...
@@ -612,6 +640,8 @@ template void ParseOptions::RegisterTmpl(const std::string &name, bool *ptr,
const
std
::
string
&
doc
);
template
void
ParseOptions
::
RegisterTmpl
(
const
std
::
string
&
name
,
int32_t
*
ptr
,
const
std
::
string
&
doc
);
template
void
ParseOptions
::
RegisterTmpl
(
const
std
::
string
&
name
,
int64_t
*
ptr
,
const
std
::
string
&
doc
);
template
void
ParseOptions
::
RegisterTmpl
(
const
std
::
string
&
name
,
uint32_t
*
ptr
,
const
std
::
string
&
doc
);
template
void
ParseOptions
::
RegisterTmpl
(
const
std
::
string
&
name
,
float
*
ptr
,
...
...
@@ -628,6 +658,9 @@ template void ParseOptions::RegisterStandard(const std::string &name,
int32_t
*
ptr
,
const
std
::
string
&
doc
);
template
void
ParseOptions
::
RegisterStandard
(
const
std
::
string
&
name
,
int64_t
*
ptr
,
const
std
::
string
&
doc
);
template
void
ParseOptions
::
RegisterStandard
(
const
std
::
string
&
name
,
uint32_t
*
ptr
,
const
std
::
string
&
doc
);
template
void
ParseOptions
::
RegisterStandard
(
const
std
::
string
&
name
,
...
...
@@ -647,6 +680,9 @@ template void ParseOptions::RegisterCommon(const std::string &name,
int32_t
*
ptr
,
const
std
::
string
&
doc
,
bool
is_standard
);
template
void
ParseOptions
::
RegisterCommon
(
const
std
::
string
&
name
,
int64_t
*
ptr
,
const
std
::
string
&
doc
,
bool
is_standard
);
template
void
ParseOptions
::
RegisterCommon
(
const
std
::
string
&
name
,
uint32_t
*
ptr
,
const
std
::
string
&
doc
,
bool
is_standard
);
...
...
sherpa-onnx/csrc/parse-options.h
查看文件 @
d6fbecd
...
...
@@ -63,6 +63,7 @@ class ParseOptions {
void
Register
(
const
std
::
string
&
name
,
bool
*
ptr
,
const
std
::
string
&
doc
);
void
Register
(
const
std
::
string
&
name
,
int32_t
*
ptr
,
const
std
::
string
&
doc
);
void
Register
(
const
std
::
string
&
name
,
int64_t
*
ptr
,
const
std
::
string
&
doc
);
void
Register
(
const
std
::
string
&
name
,
uint32_t
*
ptr
,
const
std
::
string
&
doc
);
void
Register
(
const
std
::
string
&
name
,
float
*
ptr
,
const
std
::
string
&
doc
);
void
Register
(
const
std
::
string
&
name
,
double
*
ptr
,
const
std
::
string
&
doc
);
...
...
@@ -134,6 +135,9 @@ class ParseOptions {
/// Register int32_t variable
void
RegisterSpecific
(
const
std
::
string
&
name
,
const
std
::
string
&
idx
,
int32_t
*
i
,
const
std
::
string
&
doc
,
bool
is_standard
);
/// Register int64_t variable
void
RegisterSpecific
(
const
std
::
string
&
name
,
const
std
::
string
&
idx
,
int64_t
*
i
,
const
std
::
string
&
doc
,
bool
is_standard
);
/// Register unsigned int32_t variable
void
RegisterSpecific
(
const
std
::
string
&
name
,
const
std
::
string
&
idx
,
uint32_t
*
u
,
const
std
::
string
&
doc
,
bool
is_standard
);
...
...
@@ -163,6 +167,7 @@ class ParseOptions {
bool
ToBool
(
std
::
string
str
)
const
;
int32_t
ToInt
(
const
std
::
string
&
str
)
const
;
int64_t
ToInt64
(
const
std
::
string
&
str
)
const
;
uint32_t
ToUint
(
const
std
::
string
&
str
)
const
;
float
ToFloat
(
const
std
::
string
&
str
)
const
;
double
ToDouble
(
const
std
::
string
&
str
)
const
;
...
...
@@ -170,6 +175,7 @@ class ParseOptions {
// maps for option variables
std
::
unordered_map
<
std
::
string
,
bool
*>
bool_map_
;
std
::
unordered_map
<
std
::
string
,
int32_t
*>
int_map_
;
std
::
unordered_map
<
std
::
string
,
int64_t
*>
int64_map_
;
std
::
unordered_map
<
std
::
string
,
uint32_t
*>
uint_map_
;
std
::
unordered_map
<
std
::
string
,
float
*>
float_map_
;
std
::
unordered_map
<
std
::
string
,
double
*>
double_map_
;
...
...
请
注册
或
登录
后发表评论