from typing import OrderedDict


def quant_params_vec2dict(keys, vals, search_clipping=False):
    """
    Convert the vector(s) created by quant_params_dict2vec to a dictionary of quantization parameters that
    the post-training quantizer API can digest
    """
    res = OrderedDict()
    for idx, k in enumerate(keys):
        if search_clipping and k.endswith('_min'):
            res[k[:-4]] = sorted((vals[idx], vals[idx + 1]))
        elif search_clipping and k.endswith('_max'):
            continue
        else:
            res[k] = abs(vals[idx])
    return res