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
b028ac5f
Commit
b028ac5f
authored
Oct 20, 2016
by
Guolin Ke
Browse files
refine logic for na, nan and inf processing.
parent
670a1d70
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
26 deletions
+16
-26
include/LightGBM/utils/common.h
include/LightGBM/utils/common.h
+16
-26
No files found.
include/LightGBM/utils/common.h
View file @
b028ac5f
...
...
@@ -8,6 +8,7 @@
#include <vector>
#include <sstream>
#include <cstdint>
#include <algorithm>
namespace
LightGBM
{
...
...
@@ -140,35 +141,24 @@ inline static const char* Atof(const char* p, double* out) {
// Return signed and scaled floating point result.
*
out
=
sign
*
(
frac
?
(
value
/
scale
)
:
(
value
*
scale
));
}
else
{
if
(
*
p
==
'n'
||
*
p
==
'N'
)
{
++
p
;
if
(
!
(
*
p
==
'a'
||
*
p
==
'A'
))
{
Log
::
Stderr
(
"meet error while parsing string to float, expect a nan here"
);
}
++
p
;
if
(
!
(
*
p
==
'n'
||
*
p
==
'N'
))
{
Log
::
Stderr
(
"meet error while parsing string to float, expect a nan here"
);
}
++
p
;
// default convert nan to 0
size_t
cnt
=
0
;
while
(
*
(
p
+
cnt
)
!=
'\0'
&&
*
(
p
+
cnt
)
!=
' '
&&
*
(
p
+
cnt
)
!=
'\t'
&&
*
(
p
+
cnt
)
!=
','
&&
*
(
p
+
cnt
)
!=
'\n'
&&
*
(
p
+
cnt
)
!=
'\r'
&&
*
(
p
+
cnt
)
!=
':'
)
{
++
cnt
;
}
std
::
string
tmp_str
(
p
,
cnt
);
std
::
transform
(
tmp_str
.
begin
(),
tmp_str
.
end
(),
tmp_str
.
begin
(),
::
tolower
);
if
(
tmp_str
==
std
::
string
(
"na"
)
||
tmp_str
==
std
::
string
(
"nan"
))
{
*
out
=
0
;
}
else
if
(
*
p
==
'i'
||
*
p
==
'I'
)
{
++
p
;
if
(
!
(
*
p
==
'n'
||
*
p
==
'N'
))
{
Log
::
Stderr
(
"meet error while parsing string to float, expect a inf here"
);
}
++
p
;
if
(
!
(
*
p
==
'f'
||
*
p
==
'F'
))
{
Log
::
Stderr
(
"meet error while parsing string to float, expect a inf here"
);
}
++
p
;
// default inf
}
else
if
(
tmp_str
==
std
::
string
(
"inf"
)
||
tmp_str
==
std
::
string
(
"infinity"
))
{
*
out
=
sign
*
1e308
;
}
else
{
if
(
*
p
!=
'\0'
)
{
Log
::
Stderr
(
"Meet unknow characters while parsing string to float"
);
}
else
{
Log
::
Stderr
(
"Unknow token %s in data file"
,
tmp_str
.
c_str
());
}
p
+=
cnt
;
}
while
(
*
p
==
' '
)
{
...
...
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