pdft.loss.topk_truncate

Contents

pdft.loss.topk_truncate#

pdft.loss.topk_truncate(x, k)[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.size if larger. Returns x unchanged when k >= x.size.

Returns:

Array – Same shape and dtype as x; all but k entries are zero.

Return type:

Array