Push the given symbol on the stream, flushing out bits if possible. Args: symbol (int): symbol to encode with the AC. quantized_cdf (torch.Tensor): use `build_stable_quantized_cdf` to build this from your pdf estimate.
(self, symbol: int, quantized_cdf: torch.Tensor)
| 128 | break |
| 129 | |
| 130 | def push(self, symbol: int, quantized_cdf: torch.Tensor): |
| 131 | """Push the given symbol on the stream, flushing out bits |
| 132 | if possible. |
| 133 | |
| 134 | Args: |
| 135 | symbol (int): symbol to encode with the AC. |
| 136 | quantized_cdf (torch.Tensor): use `build_stable_quantized_cdf` |
| 137 | to build this from your pdf estimate. |
| 138 | """ |
| 139 | while self.delta < 2 ** self.total_range_bits: |
| 140 | self.low *= 2 |
| 141 | self.high = self.high * 2 + 1 |
| 142 | self.max_bit += 1 |
| 143 | |
| 144 | range_low = 0 if symbol == 0 else quantized_cdf[symbol - 1].item() |
| 145 | range_high = quantized_cdf[symbol].item() - 1 |
| 146 | effective_low = int(math.ceil(range_low * (self.delta / (2 ** self.total_range_bits)))) |
| 147 | effective_high = int(math.floor(range_high * (self.delta / (2 ** self.total_range_bits)))) |
| 148 | assert self.low <= self.high |
| 149 | self.high = self.low + effective_high |
| 150 | self.low = self.low + effective_low |
| 151 | assert self.low <= self.high, (effective_low, effective_high, range_low, range_high) |
| 152 | self._dbg.append((self.low, self.high)) |
| 153 | self._dbg2.append((self.low, self.high)) |
| 154 | outs = self._flush_common_prefix() |
| 155 | assert self.low <= self.high |
| 156 | assert self.max_bit >= -1 |
| 157 | assert self.max_bit <= 61, self.max_bit |
| 158 | return outs |
| 159 | |
| 160 | def flush(self): |
| 161 | """Flush the remaining information to the stream. |
no test coverage detected