beanmachine.ppl.inference.proposer.utils module

class beanmachine.ppl.inference.proposer.utils.DictToVecConverter(example_dict: Dict[beanmachine.ppl.inference.proposer.utils.KeyType, torch.Tensor])

Bases: Generic[beanmachine.ppl.inference.proposer.utils.KeyType]

A utility class to convert a dictionary of Tensors into a single flattened Tensor or the other way around.

Parameters
  • example_dict – A dict that will be used to determine the order of the

  • Tensor. (keys and the size of the flattened) –

to_dict(vec_in: torch.Tensor) Dict[beanmachine.ppl.inference.proposer.utils.KeyType, torch.Tensor]

Reconstruct a dictionary out of a flattened Tensor

to_vec(dict_in: Dict[beanmachine.ppl.inference.proposer.utils.KeyType, torch.Tensor]) torch.Tensor

Concatenate the entries of a dictionary to a flattened Tensor