Skip to content

Commit

Permalink
Fix issue #4186, replace CMath::is_infinity with std::isinf (#4213)
Browse files Browse the repository at this point in the history
* Fix issue #4186, drop CMath::is_infinity

* delete the is_infinity function in math.h

* update src/gpl
  • Loading branch information
sunalbert authored and karlnapf committed Apr 2, 2018
1 parent c8fee5d commit bccd76c
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/gpl
Submodule gpl updated 1 files
+3 −3 shogun/lib/external/ssl.cpp
2 changes: 1 addition & 1 deletion src/shogun/machine/gp/KLDualInferenceMethod.cpp
Expand Up @@ -174,7 +174,7 @@ float64_t CKLDualInferenceMethodMinimizer::evaluate(void *obj, const float64_t *
REQUIRE(obj_prt, "The instance object passed to L-BFGS optimizer should not be NULL\n");

float64_t cost=obj_prt->m_fun->get_cost();
if (CMath::is_nan(cost) || CMath::is_infinity(cost))
if (CMath::is_nan(cost) || std::isinf(cost))
return cost;
//get the gradient wrt variable_new
SGVector<float64_t> grad=obj_prt->m_fun->get_gradient();
Expand Down
5 changes: 0 additions & 5 deletions src/shogun/mathematics/Math.cpp
Expand Up @@ -216,11 +216,6 @@ int CMath::is_nan(double f)
return std::isnan(f);
}

int CMath::is_infinity(double f)
{
return std::isinf(f);
}

int CMath::is_finite(double f)
{
return std::isfinite(f);
Expand Down
3 changes: 0 additions & 3 deletions src/shogun/mathematics/Math.h
Expand Up @@ -1737,9 +1737,6 @@ class CMath : public CSGObject
/// checks whether a float is finite
static int is_finite(double f);

/// checks whether a float is infinity
static int is_infinity(double f);

/// checks whether a float is nan
static int is_nan(double f);

Expand Down
2 changes: 1 addition & 1 deletion src/shogun/modelselection/GradientModelSelection.cpp
Expand Up @@ -189,7 +189,7 @@ float64_t CGradientModelSelection::get_cost(SGVector<float64_t> model_vars, SGVe

float64_t cost = SGVector<float64_t>::sum(value);

if (CMath::is_nan(cost) || CMath::is_infinity(cost))
if (CMath::is_nan(cost) || std::isinf(cost))
{
if (m_machine_eval->get_evaluation_direction()==ED_MINIMIZE)
return cost;
Expand Down
2 changes: 1 addition & 1 deletion src/shogun/optimization/lbfgs/LBFGSMinimizer.cpp
Expand Up @@ -187,7 +187,7 @@ float64_t CLBFGSMinimizer::evaluate(void *obj, const float64_t *variable,

float64_t cost=obj_prt->m_fun->get_cost();

if (CMath::is_nan(cost) || CMath::is_infinity(cost))
if (CMath::is_nan(cost) || std::isinf(cost))
return cost;

//get the gradient wrt variable_new
Expand Down
4 changes: 2 additions & 2 deletions src/shogun/optimization/lbfgs/lbfgs.cpp
Expand Up @@ -655,7 +655,7 @@ static int32_t line_search_backtracking(

for(index_t j=0; j<n; j++)
{
if (CMath::is_nan(s[j]) || CMath::is_infinity(s[j]))
if (CMath::is_nan(s[j]) || std::isinf(s[j]))
return LBFGSERR_INVALID_VALUE;
}

Expand All @@ -668,7 +668,7 @@ static int32_t line_search_backtracking(
/* Evaluate the function and gradient values. */
*f = cd->proc_evaluate(cd->instance, x, g.vector, cd->n, *stp);
++count;
if (CMath::is_nan(*f) || CMath::is_infinity(*f))
if (CMath::is_nan(*f) || std::isinf(*f))
*stp*=decay;
else
break;
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/mathematics/Math_unittest.cc
Expand Up @@ -180,7 +180,7 @@ TEST(CMath, strtofloat)
EXPECT_TRUE(CMath::is_nan(float_result));

EXPECT_TRUE(CMath::strtof("inf", &float_result));
EXPECT_TRUE(CMath::is_infinity(float_result));
EXPECT_TRUE(std::isinf(float_result));

EXPECT_TRUE(CMath::strtof("-inf", &float_result));
EXPECT_DOUBLE_EQ(-CMath::INFTY, float_result);
Expand All @@ -196,7 +196,7 @@ TEST(CMath, strtodouble)
EXPECT_TRUE(CMath::is_nan(double_result));

EXPECT_TRUE(CMath::strtod("inf", &double_result));
EXPECT_TRUE(CMath::is_infinity(double_result));
EXPECT_TRUE(std::isinf(double_result));

EXPECT_TRUE(CMath::strtod("-inf", &double_result));
EXPECT_DOUBLE_EQ(-CMath::INFTY, double_result);
Expand All @@ -212,7 +212,7 @@ TEST(CMath, strtolongdouble)
EXPECT_TRUE(CMath::is_nan(long_double_result));

EXPECT_TRUE(CMath::strtold("inf", &long_double_result));
EXPECT_TRUE(CMath::is_infinity(long_double_result));
EXPECT_TRUE(std::isinf(long_double_result));

EXPECT_TRUE(CMath::strtold("-inf", &long_double_result));
EXPECT_DOUBLE_EQ(-CMath::INFTY, long_double_result);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/mathematics/Statistics_unittest.cc
Expand Up @@ -733,7 +733,7 @@ TEST(Statistics, vector_mean_overflow_test)
SGVector<float64_t> a(10);
a.set_const(std::numeric_limits<float64_t>::max());
#ifdef _MSC_VER
EXPECT_TRUE(CMath::is_infinity(CStatistics::mean(a)));
EXPECT_TRUE(std::isinf(CStatistics::mean(a)));
#else
EXPECT_EQ(std::numeric_limits<float64_t>::max(), CStatistics::mean(a));
#endif
Expand Down

0 comments on commit bccd76c

Please sign in to comment.