flopscope.

flopscope.numpy.symmetrize

fnp.symmetrize(data: 'np.ndarray', *, symmetry) -> 'SymmetricTensor'[flopscope source]

Project an array onto the invariant subspace of a permutation group.

Adapted from NumPy docs np.symmetrize

Areacore
Typecustom
NumPy Refnp.symmetrize
Cost
per-operation
Flopscope Context

Reynolds projection onto a permutation group's invariant subspace. Cost: (|G|+1)*numel (|G| transposed adds + scaling pass; transpose/zeros free; validation uncounted).

This applies Reynolds symmetrization:

R_G(T) = (1 / |G|) * sum_{g in G} g · T

Parameters

data:array_like

Input array to project.

symmetry:SymmetryGroup

Symmetry group to average over. If symmetry.axes is None, axes are interpreted as tuple(range(symmetry.degree)).

Returns

:SymmetricTensor

The projected tensor, validated and wrapped as a SymmetricTensor.

Raises

:SymmetryError

If data has incompatible dimensions for group axes or if the projected result cannot be validated as symmetric for group.

Notes

symmetrize performs exact Reynolds averaging internally, billing (|G| + 1) * numel(data) FLOPs:

Internal validation runs but is NOT billed (decision D1).

where |G| is the group order and numel = data.size.

The canonical pattern for generating random data with symmetry is:

fnp.random.symmetric(shape, symmetry_group, distribution=...).

Examples

>>> import flopscope as flops
>>> import flopscope.numpy as fnp
>>> data = fnp.random.randn(4, 4)
>>> S = flops.symmetrize(data, symmetry=flops.SymmetryGroup.symmetric(axes=(0, 1)))
>>> S.is_symmetric((0, 1))
True