in multiset_codec/rans.py [0:0]
def encode(ans_state, starts, freqs, precisions):
head, tail = ans_state
starts, freqs, precisions = map(atleast_1d, (starts, freqs, precisions))
idxs = head >= ((rans_l // precisions) << 32) * freqs
if np.any(idxs):
tail = stack_extend(tail, np.uint32(head[idxs]))
head = np.copy(head) # Ensure no side-effects
head[idxs] >>= 32
# calculate next state s' = 2^r * (s // p) + (s % p) + c
head_div_freqs, head_mod_freqs = np.divmod(head, freqs)
return head_div_freqs*precisions + head_mod_freqs + starts, tail