From 903d5530e502f549b99d71143c2c29ebd9b80558 Mon Sep 17 00:00:00 2001 From: Segei L Kosakovsky Pond Date: Wed, 11 Nov 2020 14:27:49 -0500 Subject: [PATCH] Minor bug fixes --- src/core/likefunc.cpp | 2 +- src/core/matrix.cpp | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/core/likefunc.cpp b/src/core/likefunc.cpp index 79735b74d..7bd4f5dbd 100644 --- a/src/core/likefunc.cpp +++ b/src/core/likefunc.cpp @@ -5175,7 +5175,7 @@ bool CheckEqual (hyFloat a, hyFloat b, hyFloat tolerance) { a = (a>b)?(a-b)/a:(b-a)/a; return a>0.0 ? a<=tolerance : a>=-tolerance; } - return (b<=tolerance)&&(b>=-tolerance); + return fabs(b)<=tolerance; } //_______________________________________________________________________________________ diff --git a/src/core/matrix.cpp b/src/core/matrix.cpp index b6598e3f9..adc4d7079 100644 --- a/src/core/matrix.cpp +++ b/src/core/matrix.cpp @@ -2002,13 +2002,20 @@ bool _Matrix::AmISparseFast (_Matrix& whereTo) { bool _Matrix::IsValidTransitionMatrix() const { if (is_square() && is_numeric()) { long d = GetHDim(); - hyFloat * sums = new hyFloat [d] {0.0}; + hyFloat * sums = (hyFloat*)alloca (sizeof (hyFloat)*d); long idx = 0L; for (long r = 0L; r < d; r++) { for (long c = 0L; c < d; c++, idx++) { hyFloat term = theData[idx]; if (term < 0.0 || term > 1.0) { - delete [] sums; + if (CheckEqual(term, 0.0)) { + theData[idx] = 0.; + continue; + } + if (CheckEqual(term, 1.0)) { + theData[idx] = 1.; + continue; + } return false; } sums[r] += term; @@ -2016,11 +2023,9 @@ bool _Matrix::IsValidTransitionMatrix() const { } for (long r = 0L; r < d; r++) { if (!CheckEqual(1.0, sums[r])) { - delete [] sums; return false; } } - delete [] sums; return true; } return false;