Skip to content

spline_coeff: bound="zero" is silently treated as dct1 (bit-identical results) #65

Description

@balbasty

Found during an adversarial autograd review of fastfields-torch#28 (see fastfields-torch#29).

Problem

spline_coeff accepts bound=Bound.Zero (0) but produces results bit-identical to bound=Bound.DCT1 (2). The caller asks for zero-padding and silently gets whole-point mirroring instead — a wrong answer with no diagnostic.

Built the operator matrix column-by-column through the torch binding (N=16, float64):

order=2 max|M_zero - M_dct1| = 0.000e+00 bitwise identical: True
order=3 max|M_zero - M_dct1| = 0.000e+00 bitwise identical: True
order=5 max|M_zero - M_dct1| = 0.000e+00 bitwise identical: True
order=7 max|M_zero - M_dct1| = 0.000e+00 bitwise identical: True

For contrast, zero genuinely differs from the other bounds, so this is specifically an alias to dct1 and not a degenerate operator:

max|M_zero - M_dct2| = 5.885e-01
max|M_zero - M_replicate| = 5.885e-01
max|M_zero - M_dft| = 4.641e-01

Reference behaviour

jitfields does not have this problem because it refuses the bound outright — jitfields/splinc.py:

bounds_ok= ('dct1', 'dct2', 'dft', 'replicate')
...
raiseValueError(f'`spline_coeff` only implemented for bounds {bounds_ok} but got: {bound}')

So zero is simply not an implemented boundary condition for the prefilter, and the native layer should say so rather than falling through to the DCT-I path. dst1/dst2/nocheck already raise from the binding — zero is the one that slips through.

Impact

Silent wrong forward results for anyone passing bound="zero" to spline_coeff/spline_coeff_ on any backend. It also produced a wrong gradient on torch, though that half is now handled downstream.

Mitigation already in place (downstream only)

fastfields-torch#29 rejects the unimplemented bounds at the Python entry point, mirroring jitfields' checkbound. That protects the torch backend only — fastfields.numpy and fastfields.cupy still expose the aliased behaviour, and the right place for the check is the native/binding layer.

Suggested fix

Validate the bound in the splinc path and raise for anything outside {dct1, dct2, dft, replicate} (skipping the check for orders 0/1, where the prefilter is the identity and the bound is irrelevant).

🤖 Generated with Claude Code

https://claude.ai/code/session_016AjQcY78NgbagPSbPJRr6Z

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions