Skip to content

Commit

Permalink
Minor bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
spond committed Nov 11, 2020
1 parent ef0331b commit 903d553
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/core/likefunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

//_______________________________________________________________________________________
Expand Down
13 changes: 9 additions & 4 deletions src/core/matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2002,25 +2002,30 @@ 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;
}
}
for (long r = 0L; r < d; r++) {
if (!CheckEqual(1.0, sums[r])) {
delete [] sums;
return false;
}
}
delete [] sums;
return true;
}
return false;
Expand Down

0 comments on commit 903d553

Please sign in to comment.