Skip to content

Commit

Permalink
Fix division by zero during CJK training.
Browse files Browse the repository at this point in the history
  • Loading branch information
eighttails committed Apr 11, 2021
1 parent f77b1c6 commit 05eef74
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/textord/cjkpitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,13 @@ class LocalCorrelation {
float rc = 0;
int vote = 0;
for (int i = start; i < end; i++) {
rc += values_[i].vote * x * values_[i].y / values_[i].x;
vote += values_[i].vote;
if (values_[i].x != 0.0f) {
rc += values_[i].vote * x * values_[i].y / values_[i].x;
vote += values_[i].vote;
}
}

return rc / vote;
return vote == 0 ? 0.0f : rc / vote;
}

private:
Expand Down

0 comments on commit 05eef74

Please sign in to comment.