Merge pull request #13940 from alalek:fix_13914

This commit is contained in:
Alexander Alekhin 2019-03-01 19:32:36 +00:00
commit f0179f96a7

View File

@ -205,11 +205,14 @@ public:
for( j = 0; j < vcount; j++ ) for( j = 0; j < vcount; j++ )
{ {
Qfloat t = results[j]; Qfloat t = results[j];
Qfloat e = std::exp(std::abs(t)); Qfloat e = std::exp(std::abs(t)); // Inf value is possible here
if( t > 0 ) Qfloat r = (Qfloat)((e - 1.) / (e + 1.)); // NaN value is possible here (Inf/Inf or similar)
results[j] = (Qfloat)((e - 1.)/(e + 1.)); if (cvIsNaN(r))
else r = std::numeric_limits<Qfloat>::infinity();
results[j] = (Qfloat)((1. - e)/(1. + e)); if (t < 0)
r = -r;
CV_DbgAssert(!cvIsNaN(r));
results[j] = r;
} }
} }
@ -327,7 +330,7 @@ public:
const Qfloat max_val = (Qfloat)(FLT_MAX*1e-3); const Qfloat max_val = (Qfloat)(FLT_MAX*1e-3);
for( int j = 0; j < vcount; j++ ) for( int j = 0; j < vcount; j++ )
{ {
if( results[j] > max_val ) if (!(results[j] <= max_val)) // handle NaNs too
results[j] = max_val; results[j] = max_val;
} }
} }
@ -1949,6 +1952,7 @@ public:
const DecisionFunc& df = svm->decision_func[dfi]; const DecisionFunc& df = svm->decision_func[dfi];
sum = -df.rho; sum = -df.rho;
int sv_count = svm->getSVCount(dfi); int sv_count = svm->getSVCount(dfi);
CV_DbgAssert(sv_count > 0);
const double* alpha = &svm->df_alpha[df.ofs]; const double* alpha = &svm->df_alpha[df.ofs];
const int* sv_index = &svm->df_index[df.ofs]; const int* sv_index = &svm->df_index[df.ofs];
for( k = 0; k < sv_count; k++ ) for( k = 0; k < sv_count; k++ )