baybe.searchspace.utils.select_via_flat_index

baybe.searchspace.utils.select_via_flat_index(flat_idx: int, /, groups: Sequence[Sequence[_T]])[source]

Select one element per group using a flat Cartesian-product index.

Maps a single integer index over the Cartesian product of groups to the corresponding element from each group via numpy.unravel_index().

Examples

>>> groups = [[0, 1], ["a", "b"]]
>>> select_via_flat_index(0, groups)
[0, 'a']
>>> select_via_flat_index(1, groups)
[0, 'b']
>>> select_via_flat_index(2, groups)
[1, 'a']
>>> select_via_flat_index(3, groups)
[1, 'b']
Parameters:
  • flat_idx (int) – The flat index into the Cartesian product of all groups.

  • groups (Sequence[Sequence[TypeVar(_T)]]) – The groups to select from, one element selected per group.

Return type:

list[TypeVar(_T)]

Returns:

A list of selected elements, one per group.