range_coding_ops.cc: UnboundedIndexRangeEncode Documentation on overflow flag
Hey there!
In line 171 of range_coding_ops.cc, it says
When a value from
datais in the interval[offset[i], offset[i] + m - 2), then the value is range encoded using the CDF values. The last entry in each CDF (the one atm - 1) is an overflow code.
However, you usually refer to m, the size of the CDF, as the number of interval boundaries CDF has, not the number of intervals (unless I'm very much mistaken here). So the CDF has m-1, intervals, the last one of which has the index m-2, which then closes the interval [offset[i], offset[i] + m - 2) so that the CDF is complete.
From the implementation in https://github.com/tensorflow/compression/blob/master/tensorflow_compression/cc/kernels/unbounded_index_range_coding_kernels.cc#L209:
const int32 max_value = cdf_size(cdf_index) - 2;
So, as far as I can tell, the implementation is m-2 for the overflow flag and I think it would be clearer to state it in the documentation as well.
This is a small issue, but it can be confusing if someone is trying to understand or implement your coding protocol ;)
@ssjhv: Can you comment on this?
This may just be an off-by-one error in the documentation…
I think the documentation was trying to the overflow code is the symbol corresponding to (m-1)-th column value in the CDF (line 157)
cdf[..., m-1] / 2^precision = Pr(X < m-1) = Pr(X <= m-2)
But I agree that the documentation can improve, since the actual value that gets encoded is m-2.
s/was trying to/was trying to say that/
Should be fixed in commit f09afc8606f897fb0a087b7fd6d6e457065a1bcd. Please reopen if this doesn't resolve it.