Skip to content

feat: add show methods for spaces, tensors and BilinearOperator - #23

Merged
wardjm merged 1 commit into
mainfrom
show-methods
Jul 11, 2026
Merged

wardjm merged 1 commit into
mainfrom
show-methods

Conversation

@wardjm

@wardjm wardjm commented Jul 11, 2026

Copy link
Copy Markdown
Owner

Closes #15.

Base.show was defined only for LinearOperator and BettiSpectrum; everything else printed as the default struct dump, which for a tensor splats the whole coefficient vector into the REPL.

Adds compact show methods whose formats mirror the upstream Python __repr__s:

FunctionSpace(dim=50)
FormSpace(degree=1, dim=24)
DirectSumSpace(spaces=[FunctionSpace, VectorFieldSpace], dim=74)
ScalarFunction(space=FunctionSpace(dim=50), shape=(50,), batch_shape=())
DirectSumElement(space=DirectSumSpace(spaces=[FunctionSpace, VectorFieldSpace], dim=74), shape=(74,), batch_shape=())
LinearOperator(domain=FunctionSpace(dim=50), codomain=FunctionSpace(dim=50), shape=(50, 50))
BilinearOperator(domain_a=VectorFieldSpace(dim=24), domain_b=VectorFieldSpace(dim=24), codomain=VectorFieldSpace(dim=24), component_shape=(24, 24, 24))

The generic space/tensor methods sit in base_tensor_space.jl and base_tensor.jl; FormSpace and DirectSumSpace override them to carry the degree and the summand list. Coefficients are never printed. LinearOperators existing show is reformatted to the domain=/codomain= spelling, which the un-skipped upstream assertion requires.

Tests

The three previously-skipped repr assertions in test/test_pyclasses.jl are un-skipped, plus a show testset in test_tensor_algebra.jl covering what upstream does not check (FormSpace degree, DirectSumSpace summand list). Full suite: 2441 passing, up from 2417.

Note

Several @assert messages interpolate a space ("$(a.space)"), so their error text now reads FunctionSpace(dim=50) rather than a struct dump. An improvement, but a change beyond the REPL.

Only LinearOperator and BettiSpectrum had one; everything else fell back to
the default struct dump, which for a tensor splats the whole coefficient
vector into the REPL. Formats mirror the upstream Python `__repr__`s.

Un-skips the three repr assertions in the ported Python suite. Closes #15.
@wardjm
wardjm merged commit 24203ec into main Jul 11, 2026
2 checks passed
@wardjm
wardjm deleted the show-methods branch July 15, 2026 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add show methods for tensor spaces, tensors, BilinearOperator and DirectSumElement

1 participant