Skip to content

Commit a6eec1d

Browse files
Johannes Ball?copybara-github
authored andcommitted
Adds check for non-finite PMF values.
The PMF to CDF conversion isn't really time critical, since it's only performed once. So it makes sense to check for non-finite values due to numerical issues in the density model. PiperOrigin-RevId: 293431960 Change-Id: I72c068f18271954765a08db59bd270bb9d8c4836
1 parent 830265a commit a6eec1d

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

tensorflow_compression/cc/kernels/range_coding_helper_kernels.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@ class PmfToCdfOp : public OpKernel {
7878
CHECK_EQ(pmf.dimension(0), cdf.dimension(0));
7979
CHECK_EQ(pmf.dimension(1) + 1, cdf.dimension(1));
8080

81+
for (int64 i = 0; i < pmf.dimension(0); ++i) {
82+
for (int64 j = 0; j < pmf.dimension(1); ++j) {
83+
auto value = pmf(i, j);
84+
OP_REQUIRES(
85+
context, std::isfinite(value) && value >= 0,
86+
InvalidArgument("`pmf` has non-finite or negative element: ", value,
87+
". Please check for numerical problems in the "
88+
"probability computation."));
89+
}
90+
}
91+
8192
const double n = pmf.dimension(1);
8293
const int64 cost_per_unit = static_cast<int64>(50.0 * n * std::log2(n));
8394
thread::ThreadPool* thread_pool =

0 commit comments

Comments
 (0)