pdft.loss.topk_truncate#
- pdft.loss.topk_truncate(x, k, *, rtol=0.0)[source]#
Keep the k coefficients with largest absolute value; zero the rest.
Mirror of upstream src/loss.jl:28-63. Basis-agnostic (no frequency layout assumption).
- Parameters:
x (Array) – Input array of any shape.
k (int) – Number of coefficients to keep. Clamped to
x.sizeif larger. Returnsxunchanged when k >= x.size.rtol (float, optional) –
Half-width of the band around the k-th largest magnitude inside which entries count as tied, as a fraction of that magnitude. Ties are settled by position, the first in flattened order kept. The default 0 is upstream’s rule: only exactly equal magnitudes tie.
A band is what makes the choice reproducible where magnitudes are equal by symmetry and so differ only by rounding. The Fourier coefficients of a real image come in conjugate pairs; when the cut falls inside a pair, which of the two survives is decided at rtol=0 by the last bit, and changes with the device and the arithmetic.
- Returns:
Array – Same shape and dtype as
x; all but k entries are zero.- Return type: