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
0d59859c
Unverified
Commit
0d59859c
authored
Jul 19, 2019
by
Guolin Ke
Committed by
GitHub
Jul 19, 2019
Browse files
throw error when meet non ascii (#2229)
* throw error when meet non ascii * check ascii for config strings.
parent
0d02499e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
0 deletions
+17
-0
include/LightGBM/dataset.h
include/LightGBM/dataset.h
+5
-0
include/LightGBM/utils/common.h
include/LightGBM/utils/common.h
+9
-0
src/io/config.cpp
src/io/config.cpp
+3
-0
No files found.
include/LightGBM/dataset.h
View file @
0d59859c
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
#include <LightGBM/config.h>
#include <LightGBM/config.h>
#include <LightGBM/feature_group.h>
#include <LightGBM/feature_group.h>
#include <LightGBM/meta.h>
#include <LightGBM/meta.h>
#include <LightGBM/utils/common.h>
#include <LightGBM/utils/openmp_wrapper.h>
#include <LightGBM/utils/openmp_wrapper.h>
#include <LightGBM/utils/random.h>
#include <LightGBM/utils/random.h>
#include <LightGBM/utils/text_reader.h>
#include <LightGBM/utils/text_reader.h>
...
@@ -555,6 +556,10 @@ class Dataset {
...
@@ -555,6 +556,10 @@ class Dataset {
// replace ' ' in feature_names with '_'
// replace ' ' in feature_names with '_'
bool
spaceInFeatureName
=
false
;
bool
spaceInFeatureName
=
false
;
for
(
auto
&
feature_name
:
feature_names_
)
{
for
(
auto
&
feature_name
:
feature_names_
)
{
// check ascii
if
(
!
Common
::
CheckASCII
(
feature_name
))
{
Log
::
Fatal
(
"Do not support non-ascii characters in feature name."
);
}
if
(
feature_name
.
find
(
' '
)
!=
std
::
string
::
npos
)
{
if
(
feature_name
.
find
(
' '
)
!=
std
::
string
::
npos
)
{
spaceInFeatureName
=
true
;
spaceInFeatureName
=
true
;
std
::
replace
(
feature_name
.
begin
(),
feature_name
.
end
(),
' '
,
'_'
);
std
::
replace
(
feature_name
.
begin
(),
feature_name
.
end
(),
' '
,
'_'
);
...
...
include/LightGBM/utils/common.h
View file @
0d59859c
...
@@ -895,6 +895,15 @@ static T SafeLog(T x) {
...
@@ -895,6 +895,15 @@ static T SafeLog(T x) {
}
}
}
}
inline
bool
CheckASCII
(
const
std
::
string
&
s
)
{
for
(
auto
c
:
s
)
{
if
(
static_cast
<
unsigned
char
>
(
c
)
>
127
)
{
return
false
;
}
}
return
true
;
}
}
// namespace Common
}
// namespace Common
}
// namespace LightGBM
}
// namespace LightGBM
...
...
src/io/config.cpp
View file @
0d59859c
...
@@ -17,6 +17,9 @@ void Config::KV2Map(std::unordered_map<std::string, std::string>& params, const
...
@@ -17,6 +17,9 @@ void Config::KV2Map(std::unordered_map<std::string, std::string>& params, const
if
(
tmp_strs
.
size
()
==
2
)
{
if
(
tmp_strs
.
size
()
==
2
)
{
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
=
Common
::
RemoveQuotationSymbol
(
Common
::
Trim
(
tmp_strs
[
1
]));
if
(
!
Common
::
CheckASCII
(
key
)
||
!
Common
::
CheckASCII
(
value
))
{
Log
::
Fatal
(
"Do not support non-ascii characters in config."
);
}
if
(
key
.
size
()
>
0
)
{
if
(
key
.
size
()
>
0
)
{
auto
value_search
=
params
.
find
(
key
);
auto
value_search
=
params
.
find
(
key
);
if
(
value_search
==
params
.
end
())
{
// not set
if
(
value_search
==
params
.
end
())
{
// not set
...
...
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