Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
tianlh
LightGBM-DCU
Commits
274f340a
Unverified
Commit
274f340a
authored
Jul 28, 2019
by
Guolin Ke
Committed by
GitHub
Jul 28, 2019
Browse files
allow passing empty value in parameters (#2289)
parent
207bb3ef
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
6 deletions
+9
-6
include/LightGBM/config.h
include/LightGBM/config.h
+4
-4
src/io/config.cpp
src/io/config.cpp
+5
-2
No files found.
include/LightGBM/config.h
View file @
274f340a
...
@@ -850,7 +850,7 @@ struct Config {
...
@@ -850,7 +850,7 @@ struct Config {
inline
bool
Config
::
GetString
(
inline
bool
Config
::
GetString
(
const
std
::
unordered_map
<
std
::
string
,
std
::
string
>&
params
,
const
std
::
unordered_map
<
std
::
string
,
std
::
string
>&
params
,
const
std
::
string
&
name
,
std
::
string
*
out
)
{
const
std
::
string
&
name
,
std
::
string
*
out
)
{
if
(
params
.
count
(
name
)
>
0
)
{
if
(
params
.
count
(
name
)
>
0
&&
!
params
.
at
(
name
).
empty
()
)
{
*
out
=
params
.
at
(
name
);
*
out
=
params
.
at
(
name
);
return
true
;
return
true
;
}
}
...
@@ -860,7 +860,7 @@ inline bool Config::GetString(
...
@@ -860,7 +860,7 @@ inline bool Config::GetString(
inline
bool
Config
::
GetInt
(
inline
bool
Config
::
GetInt
(
const
std
::
unordered_map
<
std
::
string
,
std
::
string
>&
params
,
const
std
::
unordered_map
<
std
::
string
,
std
::
string
>&
params
,
const
std
::
string
&
name
,
int
*
out
)
{
const
std
::
string
&
name
,
int
*
out
)
{
if
(
params
.
count
(
name
)
>
0
)
{
if
(
params
.
count
(
name
)
>
0
&&
!
params
.
at
(
name
).
empty
()
)
{
if
(
!
Common
::
AtoiAndCheck
(
params
.
at
(
name
).
c_str
(),
out
))
{
if
(
!
Common
::
AtoiAndCheck
(
params
.
at
(
name
).
c_str
(),
out
))
{
Log
::
Fatal
(
"Parameter %s should be of type int, got
\"
%s
\"
"
,
Log
::
Fatal
(
"Parameter %s should be of type int, got
\"
%s
\"
"
,
name
.
c_str
(),
params
.
at
(
name
).
c_str
());
name
.
c_str
(),
params
.
at
(
name
).
c_str
());
...
@@ -873,7 +873,7 @@ inline bool Config::GetInt(
...
@@ -873,7 +873,7 @@ inline bool Config::GetInt(
inline
bool
Config
::
GetDouble
(
inline
bool
Config
::
GetDouble
(
const
std
::
unordered_map
<
std
::
string
,
std
::
string
>&
params
,
const
std
::
unordered_map
<
std
::
string
,
std
::
string
>&
params
,
const
std
::
string
&
name
,
double
*
out
)
{
const
std
::
string
&
name
,
double
*
out
)
{
if
(
params
.
count
(
name
)
>
0
)
{
if
(
params
.
count
(
name
)
>
0
&&
!
params
.
at
(
name
).
empty
()
)
{
if
(
!
Common
::
AtofAndCheck
(
params
.
at
(
name
).
c_str
(),
out
))
{
if
(
!
Common
::
AtofAndCheck
(
params
.
at
(
name
).
c_str
(),
out
))
{
Log
::
Fatal
(
"Parameter %s should be of type double, got
\"
%s
\"
"
,
Log
::
Fatal
(
"Parameter %s should be of type double, got
\"
%s
\"
"
,
name
.
c_str
(),
params
.
at
(
name
).
c_str
());
name
.
c_str
(),
params
.
at
(
name
).
c_str
());
...
@@ -886,7 +886,7 @@ inline bool Config::GetDouble(
...
@@ -886,7 +886,7 @@ inline bool Config::GetDouble(
inline
bool
Config
::
GetBool
(
inline
bool
Config
::
GetBool
(
const
std
::
unordered_map
<
std
::
string
,
std
::
string
>&
params
,
const
std
::
unordered_map
<
std
::
string
,
std
::
string
>&
params
,
const
std
::
string
&
name
,
bool
*
out
)
{
const
std
::
string
&
name
,
bool
*
out
)
{
if
(
params
.
count
(
name
)
>
0
)
{
if
(
params
.
count
(
name
)
>
0
&&
!
params
.
at
(
name
).
empty
()
)
{
std
::
string
value
=
params
.
at
(
name
);
std
::
string
value
=
params
.
at
(
name
);
std
::
transform
(
value
.
begin
(),
value
.
end
(),
value
.
begin
(),
Common
::
tolower
);
std
::
transform
(
value
.
begin
(),
value
.
end
(),
value
.
begin
(),
Common
::
tolower
);
if
(
value
==
std
::
string
(
"false"
)
||
value
==
std
::
string
(
"-"
))
{
if
(
value
==
std
::
string
(
"false"
)
||
value
==
std
::
string
(
"-"
))
{
...
...
src/io/config.cpp
View file @
274f340a
...
@@ -14,9 +14,12 @@ namespace LightGBM {
...
@@ -14,9 +14,12 @@ namespace LightGBM {
void
Config
::
KV2Map
(
std
::
unordered_map
<
std
::
string
,
std
::
string
>&
params
,
const
char
*
kv
)
{
void
Config
::
KV2Map
(
std
::
unordered_map
<
std
::
string
,
std
::
string
>&
params
,
const
char
*
kv
)
{
std
::
vector
<
std
::
string
>
tmp_strs
=
Common
::
Split
(
kv
,
'='
);
std
::
vector
<
std
::
string
>
tmp_strs
=
Common
::
Split
(
kv
,
'='
);
if
(
tmp_strs
.
size
()
==
2
)
{
if
(
tmp_strs
.
size
()
==
2
||
tmp_strs
.
size
()
==
1
)
{
std
::
string
key
=
Common
::
RemoveQuotationSymbol
(
Common
::
Trim
(
tmp_strs
[
0
]));
std
::
string
key
=
Common
::
RemoveQuotationSymbol
(
Common
::
Trim
(
tmp_strs
[
0
]));
std
::
string
value
=
Common
::
RemoveQuotationSymbol
(
Common
::
Trim
(
tmp_strs
[
1
]));
std
::
string
value
=
""
;
if
(
tmp_strs
.
size
()
==
2
)
{
value
=
Common
::
RemoveQuotationSymbol
(
Common
::
Trim
(
tmp_strs
[
1
]));
}
if
(
!
Common
::
CheckASCII
(
key
)
||
!
Common
::
CheckASCII
(
value
))
{
if
(
!
Common
::
CheckASCII
(
key
)
||
!
Common
::
CheckASCII
(
value
))
{
Log
::
Fatal
(
"Do not support non-ascii characters in config."
);
Log
::
Fatal
(
"Do not support non-ascii characters in config."
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment