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
21ee5947
Commit
21ee5947
authored
Jan 04, 2017
by
Guolin Ke
Browse files
fix double to string precision (std::numeric_limits<double>::digits10 + 2)
parent
dd425973
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
7 additions
and
7 deletions
+7
-7
include/LightGBM/utils/common.h
include/LightGBM/utils/common.h
+4
-4
src/io/tree.cpp
src/io/tree.cpp
+2
-2
tests/python_package_test/test_basic.py
tests/python_package_test/test_basic.py
+1
-1
No files found.
include/LightGBM/utils/common.h
View file @
21ee5947
...
...
@@ -247,7 +247,7 @@ inline static std::string ArrayToString(const std::vector<T>& arr, char delimite
return
std
::
string
(
""
);
}
std
::
stringstream
str_buf
;
str_buf
<<
std
::
setprecision
(
std
::
numeric_limits
<
double
>::
digits10
+
1
);
str_buf
<<
std
::
setprecision
(
std
::
numeric_limits
<
double
>::
digits10
+
2
);
str_buf
<<
arr
[
0
];
for
(
size_t
i
=
1
;
i
<
arr
.
size
();
++
i
)
{
str_buf
<<
delimiter
;
...
...
@@ -262,7 +262,7 @@ inline static std::string ArrayToString(const std::vector<T>& arr, size_t n, cha
return
std
::
string
(
""
);
}
std
::
stringstream
str_buf
;
str_buf
<<
std
::
setprecision
(
std
::
numeric_limits
<
double
>::
digits10
+
1
);
str_buf
<<
std
::
setprecision
(
std
::
numeric_limits
<
double
>::
digits10
+
2
);
str_buf
<<
arr
[
0
];
for
(
size_t
i
=
1
;
i
<
std
::
min
(
n
,
arr
.
size
());
++
i
)
{
str_buf
<<
delimiter
;
...
...
@@ -312,7 +312,7 @@ inline static std::string Join(const std::vector<T>& strs, const char* delimiter
return
std
::
string
(
""
);
}
std
::
stringstream
str_buf
;
str_buf
<<
std
::
setprecision
(
std
::
numeric_limits
<
double
>::
digits10
+
1
);
str_buf
<<
std
::
setprecision
(
std
::
numeric_limits
<
double
>::
digits10
+
2
);
str_buf
<<
strs
[
0
];
for
(
size_t
i
=
1
;
i
<
strs
.
size
();
++
i
)
{
str_buf
<<
delimiter
;
...
...
@@ -329,7 +329,7 @@ inline static std::string Join(const std::vector<T>& strs, size_t start, size_t
start
=
std
::
min
(
start
,
static_cast
<
size_t
>
(
strs
.
size
())
-
1
);
end
=
std
::
min
(
end
,
static_cast
<
size_t
>
(
strs
.
size
()));
std
::
stringstream
str_buf
;
str_buf
<<
std
::
setprecision
(
std
::
numeric_limits
<
double
>::
digits10
+
1
);
str_buf
<<
std
::
setprecision
(
std
::
numeric_limits
<
double
>::
digits10
+
2
);
str_buf
<<
strs
[
start
];
for
(
size_t
i
=
start
+
1
;
i
<
end
;
++
i
)
{
str_buf
<<
delimiter
;
...
...
src/io/tree.cpp
View file @
21ee5947
...
...
@@ -152,7 +152,7 @@ std::string Tree::ToString() {
std
::
string
Tree
::
ToJSON
()
{
std
::
stringstream
str_buf
;
str_buf
<<
std
::
setprecision
(
std
::
numeric_limits
<
double
>::
digits10
+
1
);
str_buf
<<
std
::
setprecision
(
std
::
numeric_limits
<
double
>::
digits10
+
2
);
str_buf
<<
"
\"
num_leaves
\"
:"
<<
num_leaves_
<<
","
<<
std
::
endl
;
str_buf
<<
"
\"
tree_structure
\"
:"
<<
NodeToJSON
(
0
)
<<
std
::
endl
;
...
...
@@ -162,7 +162,7 @@ std::string Tree::ToJSON() {
std
::
string
Tree
::
NodeToJSON
(
int
index
)
{
std
::
stringstream
str_buf
;
str_buf
<<
std
::
setprecision
(
std
::
numeric_limits
<
double
>::
digits10
+
1
);
str_buf
<<
std
::
setprecision
(
std
::
numeric_limits
<
double
>::
digits10
+
2
);
if
(
index
>=
0
)
{
// non-leaf
str_buf
<<
"{"
<<
std
::
endl
;
...
...
tests/python_package_test/test_basic.py
View file @
21ee5947
...
...
@@ -47,7 +47,7 @@ class TestBasic(unittest.TestCase):
pred_from_model_file
=
bst
.
predict
(
X_test
)
self
.
assertEqual
(
len
(
pred_from_matr
),
len
(
pred_from_model_file
))
for
preds
in
zip
(
pred_from_matr
,
pred_from_model_file
):
self
.
assert
Almost
Equal
(
*
preds
,
places
=
15
)
self
.
assertEqual
(
*
preds
)
print
(
"----------------------------------------------------------------------"
)
...
...
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