def _unpack()

in dict_minimize/core/_scipy.py [0:0]


def _unpack(x_vec: np.ndarray, from_np: Callable, shapes: OrderedDict, dtypes: OrderedDict) -> OrderedDict:
    """Invert `_pack` and get the dictionary of variables (in their original shapes) back."""
    assert isinstance(shapes, OrderedDict)

    total_size = np.sum([np.prod(ss, dtype=int) for ss in shapes.values()])
    assert x_vec.shape == (total_size,)

    start = 0
    x_dict = OrderedDict()
    for kk in shapes:
        ss = shapes[kk]
        end = start + np.prod(ss, dtype=int)

        x_dict[kk] = from_np(np.reshape(x_vec[start:end], ss, order="C"), dtypes[kk])
        start = end
    assert start == total_size
    assert list(x_dict.keys()) == list(shapes.keys())
    return x_dict