def vec_ans_index_encoder_flush(instructions,
                                precision,
                                coding_shape,
                                overflow_width=OVERFLOW_WIDTH,
                                **kwargs):

    message = vrans.empty_message(coding_shape)
    overflow_push, _ = substack(codec=None, view_fun=overflow_view)
    # LIFO - last item compressed is first item decompressed
    for i in reversed(range(len(instructions))):

        start, freq, flag, precision_i, mask = instructions[i]

        if flag is False:
            message = vrans.push(message, start, freq, precision)
        else:
            # Substack on overflow values
            overflow_precision = precision_i
            message = overflow_push(message, start, freq, overflow_precision,
                                    mask)

    encoded = vrans.flatten(message)
    message_length = len(encoded)
    print('Symbol compressed to {:.3f} bits.'.format(32 * message_length))
    return encoded
Beispiel #2
0
def ans_index_encoder_flush(instructions, precision, overflow_width=OVERFLOW_WIDTH, **kwargs):

    message = vrans.empty_message(())

    # LIFO - last item compressed is first item decompressed
    for i in reversed(range(len(instructions))):

        start, freq, flag = instructions[i]

        if flag is False:
            message = vrans.push(message, start, freq, precision)
        else:
            message = vrans.push(message, start, freq, overflow_width)

    encoded = vrans.flatten(message)
    message_length = len(encoded)
    #print('Symbol compressed to {:.3f} bits.'.format(32 * message_length))
    return encoded
 def push(message, start, freq, precision, mask):
     head, tail = message
     view_fun_ = lambda x: view_fun(x, mask)
     subhead, update = compression_utils.view_update(head, view_fun_)
     subhead, tail = vrans.push((subhead, tail), start, freq, precision)
     return update(subhead), tail
 def push(message, symbol):
     start, freq = enc_statfun(symbol)
     return vrans.push(message, start, freq, precision)