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:
committed by
Philip Hyunsu Cho
parent
55bc149efb
commit
6a569b8cd9
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user