Module phiml.math.perm
Functions related to tensor permutation.
Functions
def all_permutations(dims: phiml.math._shape.Shape, list_dim=(~permᵈ=None), index_dim: Optional[phiml.math._shape.Shape] = (indexᶜ=None), convert=False) ‑> phiml.math._tensors.Tensor-
Returns a
Tensorcontaining all possible permutation indices ofdimsalonglist_dim.Args
dims- Dims along which elements are permuted.
list_dim- Single dim along which to list the permutations.
index_dim- Dim listing vector components for multi-dim permutations. Can be
Noneifdims.rank == 1. convert- Whether to convert the permutations to the default backend. If
False, the result is backed by NumPy.
Returns
Permutations as a single index
Tensor. def optimal_perm(cost_matrix: phiml.math._tensors.Tensor)-
Given a pair-wise cost matrix of two equal-size vectors, finds the optimal permutation to apply to one vector (corresponding to the dual dim of
cost_matrix) in order to obtain the minimum total cost for a bijective map.Args
cost_matrix- Pair-wise cost matrix. Must be a square matrix with a dual and primal dim.
Returns
dual_perm- Permutation that, when applied along the vector corresponding to the dual dim in
cost_matrix, yields the minimum cost. cost- Optimal cost vector, listed along primal dim of
cost_matrix.
def pick_random(value: ~TensorOrTree, dim: Union[str, Sequence[+T_co], set, phiml.math._shape.Shape, Callable, None], count: Union[int, phiml.math._shape.Shape, None] = 1, weight: Optional[phiml.math._tensors.Tensor] = None, same_selection_dims: Union[str, Sequence[+T_co], set, phiml.math._shape.Shape, Callable, None] = <function non_batch>, selections: phiml.math._shape.Shape = ()) ‑> ~TensorOrTree-
Pick one or multiple random entries from
value.Args
value- Tensor or tree. When containing multiple tensors, the corresponding entries are picked on all tensors that have
dim. You can passrange(the type) to retrieve the picked indices. dim- Dimension along which to pick random entries.
Shapewith one dim. count- Number of entries to pick. When specified as a
Shape, lists picked values alongcountinstead ofdim. weight- Probability weight of each item along
dim. Will be normalized to sum to 1. same_selection_dims- Dims along which to use the same random selection for each element. All other dims except
dimare treated as batch. selections- Additional dims to generate more random subsets. These will be part of the output.
Returns
Tensoror tree equal tovalue. def random_permutation(*shape: Union[phiml.math._shape.Shape, Any], dims=<function non_batch>, index_dim=(indexᶜ=None)) ‑> phiml.math._tensors.Tensor-
Generate random permutations of the integers between 0 and the size of
shape.When multiple dims are given, the permutation is randomized across all of them and tensor of multi-indices is returned.
Batch dims result in batches of permutations.
Args
*shapeShapeof the result tensor, includingdimsand batches.*dims- Sequence dims for an individual permutation. The total
Shape.volumedefines the maximum integer. All other dims fromshapeare treated as batch.
Returns
Tensor