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
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.axesisNone, axes are interpreted astuple(range(symmetry.degree)).
Returns
- :SymmetricTensor
The projected tensor, validated and wrapped as a SymmetricTensor.
Raises
- :SymmetryError
If
datahas incompatible dimensions forgroupaxes or if the projected result cannot be validated as symmetric forgroup.
Notes
symmetrize performs exact Reynolds averaging internally, billing
(|G| + 1) * numel(data) FLOPs:
|G|transposed add passes overnumelelementsone final scaling pass (divide by
|G|)
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