Avoid generating NaNs in UnwoundPathSum (#3943)

* Avoid generating NaNs in UnwoundPathSum.

Kudos to Jakub Zakrzewski for tracking down the bug.

* Add a test
This commit is contained in:
Kodi Arfer
2019-01-03 18:04:46 -05:00
committed by Philip Hyunsu Cho
parent 55bc149efb
commit 6a569b8cd9
2 changed files with 37 additions and 1 deletions

View File

@@ -293,9 +293,12 @@ bst_float UnwoundPathSum(const PathElement *unique_path, unsigned unique_depth,
total += tmp;
next_one_portion = unique_path[i].pweight - tmp * zero_fraction * ((unique_depth - i)
/ static_cast<bst_float>(unique_depth + 1));
} else {
} else if (zero_fraction != 0) {
total += (unique_path[i].pweight / zero_fraction) / ((unique_depth - i)
/ static_cast<bst_float>(unique_depth + 1));
} else {
CHECK_EQ(unique_path[i].pweight, 0)
<< "Unique path " << i << " must have zero weight";
}
}
return total;