Skip to content

fix: read static shapes in spectral pooling and accept layer kwargs - #42

Open
ColumbusLabs wants to merge 1 commit into
JesperDramsch:mainfrom
ColumbusLabs:fix/spectral-pooling-shape
Open

ColumbusLabs wants to merge 1 commit into
JesperDramsch:mainfrom
ColumbusLabs:fix/spectral-pooling-shape

Conversation

@ColumbusLabs

@ColumbusLabs ColumbusLabs commented Oct 14, 2026 •

Copy link
Copy Markdown

Fixes #36

SpectralPooling1D and SpectralPooling2D could not be used with TensorFlow's Keras:

  • call() read x._keras_shape, which only standalone Keras 1 set, so both layers raised AttributeError when called.
  • SpectralPooling1D.__init__ took topf as a named argument with an unused default and then looked for it in **kwargs, so SpectralPooling1D(topf=...) always raised "Must provide either topf= or gamma= !".
  • Neither layer passed its kwargs to Layer.__init__, so name= and the other standard layer arguments were dropped.

Changes (complexnn/pool.py only)

  • Both layers read the static shape with tuple(x.shape) via a small _static_shape helper, which raises a ValueError if a spatial dimension is None (the masks are built from the static size).
  • Both __init__ methods take topf=None and gamma=None explicitly and forward the remaining kwargs to super().__init__. Calling with neither still raises the same RuntimeError.
  • The fft module is untouched.

Tests

  • New tests/test_pool.py: builds and trains a one-step model with each layer using topf= and gamma=, checks the output mask, checks name= is forwarded, and checks the ValueError for an unknown spatial dimension.
  • TestNoKerasShapeWrites in tests/test_public_api.py is now TestNoKerasShapeUse and also catches reads of _keras_shape, not just writes.

pytest tests/test_pool.py tests/test_public_api.py:

Configuration main (new tests applied) this branch
Python 3.13, TensorFlow 2.21.0 (Keras 3) 8 failed, 3 passed 11 passed
Python 3.11, TensorFlow 2.15.1 + tf-keras, TF_USE_LEGACY_KERAS=1 8 failed, 3 passed 11 passed

ruff check and ruff format --check pass on the changed files.

@ColumbusLabs ColumbusLabs changed the title Title fix: read static shapes in spectral pooling and accept layer kwargs Oct 14, 2026

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spectral pooling layers read the standalone Keras attribute _keras_shape, and SpectralPooling1D rejects topf

1 participant