From cdce21786828d5a2d8d1a28603d57afa5339841a Mon Sep 17 00:00:00 2001 From: wuciting Date: Fri, 7 Feb 2025 14:34:17 +0800 Subject: [PATCH 1/2] fix: cpp to_if_else missing check for threshold when missing_type is not none --- src/io/tree.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/io/tree.cpp b/src/io/tree.cpp index 975f09d209df..0bb1922babf0 100644 --- a/src/io/tree.cpp +++ b/src/io/tree.cpp @@ -531,19 +531,20 @@ std::string Tree::NumericalDecisionIfElse(int node) const { } if (missing_type == MissingType::Zero) { if (default_left) { - str_buf << "if (Tree::IsZero(fval)) {"; + str_buf << "if (Tree::IsZero(fval) || "; } else { - str_buf << "if (!Tree::IsZero(fval)) {"; + str_buf << "if (!Tree::IsZero(fval) && "; } } else if (missing_type == MissingType::NaN) { if (default_left) { - str_buf << "if (std::isnan(fval)) {"; + str_buf << "if (std::isnan(fval) || "; } else { - str_buf << "if (!std::isnan(fval)) {"; + str_buf << "if (!std::isnan(fval) && "; } } else { - str_buf << "if (fval <= " << threshold_[node] << ") {"; + str_buf << "if ("; } + str_buf << "fval <= " << threshold_[node] << ") {"; return str_buf.str(); } From d4fa792f83745ec6648a0dacde0f9e5ab4965456 Mon Sep 17 00:00:00 2001 From: wuciting Date: Fri, 7 Feb 2025 14:46:52 +0800 Subject: [PATCH 2/2] perf: code style --- src/io/tree.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/io/tree.cpp b/src/io/tree.cpp index 0bb1922babf0..85f859b1c5ab 100644 --- a/src/io/tree.cpp +++ b/src/io/tree.cpp @@ -529,20 +529,19 @@ std::string Tree::NumericalDecisionIfElse(int node) const { if (missing_type != MissingType::NaN) { str_buf << "if (std::isnan(fval)) fval = 0.0;"; } + str_buf << "if ("; if (missing_type == MissingType::Zero) { if (default_left) { - str_buf << "if (Tree::IsZero(fval) || "; + str_buf << "Tree::IsZero(fval) || "; } else { - str_buf << "if (!Tree::IsZero(fval) && "; + str_buf << "!Tree::IsZero(fval) && "; } } else if (missing_type == MissingType::NaN) { if (default_left) { - str_buf << "if (std::isnan(fval) || "; + str_buf << "std::isnan(fval) || "; } else { - str_buf << "if (!std::isnan(fval) && "; + str_buf << "!std::isnan(fval) && "; } - } else { - str_buf << "if ("; } str_buf << "fval <= " << threshold_[node] << ") {"; return str_buf.str();