compression icon indicating copy to clipboard operation
compression copied to clipboard

range_coding_ops.cc: UnboundedIndexRangeEncode Documentation on overflow flag

Open kloppjp opened this issue 7 years ago • 5 comments

Hey there!

In line 171 of range_coding_ops.cc, it says

When a value from data is 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 at m - 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 ;)

kloppjp avatar Nov 23 '19 09:11 kloppjp

@ssjhv: Can you comment on this?

jonaballe avatar Nov 27 '19 01:11 jonaballe

This may just be an off-by-one error in the documentation…

jonaballe avatar Nov 27 '19 01:11 jonaballe

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.

ssjhv avatar Feb 06 '20 01:02 ssjhv

s/was trying to/was trying to say that/

ssjhv avatar Feb 06 '20 01:02 ssjhv

Should be fixed in commit f09afc8606f897fb0a087b7fd6d6e457065a1bcd. Please reopen if this doesn't resolve it.

jonaballe avatar Mar 12 '20 17:03 jonaballe