Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/operators/types/bilinear.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ end
component_shape(B::BilinearOperator) =
(space_dim(B.codomain), space_dim(B.domain_a), space_dim(B.domain_b))

function Base.show(io::IO, B::BilinearOperator)
print(io, "BilinearOperator(domain_a=", B.domain_a, ", domain_b=", B.domain_b,
", codomain=", B.codomain, ", component_shape=", component_shape(B), ")")
end

"""Weak-form component 3-tensor."""
function weak(B::BilinearOperator)
B._weak !== nothing && return B._weak
Expand Down
4 changes: 2 additions & 2 deletions src/operators/types/linear.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ function LinearOperator(domain::AbstractTensorSpace, codomain::AbstractTensorSpa
end

function Base.show(io::IO, L::LinearOperator)
print(io, "LinearOperator($(typeof(L.domain)) → $(typeof(L.codomain)), ",
"shape=($(space_dim(L.codomain)), $(space_dim(L.domain))))")
print(io, "LinearOperator(domain=", L.domain, ", codomain=", L.codomain,
", shape=(", space_dim(L.codomain), ", ", space_dim(L.domain), "))")
end

"""Operator matrix in weak (bilinear-form) representation."""
Expand Down
7 changes: 7 additions & 0 deletions src/tensors/base_tensor/base_tensor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
"""Pointwise data of a tensor at the sample points, shape `(batch..., n·C)`."""
to_pointwise_basis(t::AbstractTensor) = _to_pointwise_basis(t.coeffs, t.space)

# ── Display ────────────────────────────────────────────────────────────────────
# Coefficients are deliberately not printed: a tensor carries one per basis
# function per component, which swamps the REPL to no purpose.
Base.show(io::IO, t::AbstractTensor) =
print(io, nameof(typeof(t)), "(space=", t.space, ", shape=", size(t.coeffs),
", batch_shape=", batch_shape(t), ")")

# ── Linear structure ───────────────────────────────────────────────────────────
Base.:-(t::AbstractTensor) = wrap(t.space, -t.coeffs)

Expand Down
6 changes: 6 additions & 0 deletions src/tensors/base_tensor/base_tensor_space.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ function Base.zeros(space::AbstractTensorSpace, batch::Tuple=())
return wrap(space, zeros(Float64, batch..., space_dim(space)))
end

# ── Display ────────────────────────────────────────────────────────────────────
# Concrete spaces carrying extra structure (a form degree, a list of summands)
# override this; everything else is just its name and its coefficient dimension.
Base.show(io::IO, space::AbstractTensorSpace) =
print(io, nameof(typeof(space)), "(dim=", space_dim(space), ")")

# ── Equality / hashing (used as cache keys) ────────────────────────────────────
function Base.:(==)(a::AbstractTensorSpace, b::AbstractTensorSpace)
a === b && return true
Expand Down
5 changes: 5 additions & 0 deletions src/tensors/direct_sum/direct_sum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ end

space_dim(ds::DirectSumSpace) = sum(space_dim(s) for s in ds.spaces)

function Base.show(io::IO, ds::DirectSumSpace)
parts = join((nameof(typeof(s)) for s in ds.spaces), ", ")
print(io, "DirectSumSpace(spaces=[", parts, "], dim=", space_dim(ds), ")")
end

# Offset ranges for splitting the coefficient vector into summands.
function _coeff_ranges(ds::DirectSumSpace)
ranges = UnitRange{Int}[]
Expand Down
3 changes: 3 additions & 0 deletions src/tensors/forms/forms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ end
space_degree(space::FormSpace) = space.degree
degree(f::Form) = f.space.degree

Base.show(io::IO, space::FormSpace) =
print(io, "FormSpace(degree=", space.degree, ", dim=", space_dim(space), ")")

cdc_components(space::FormSpace) = gamma_coords_compound(space.dg.cache, space.degree)[2]

function wrap(space::FormSpace, coeffs::AbstractArray)
Expand Down
29 changes: 22 additions & 7 deletions test/test_pyclasses.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
# error paths. It runs over the same d = 1..4 config sweep (see pysuite.jl).
#
# Purely Python-shaped tests are skipped with a note where they appear: numpy ufunc
# dispatch (`np.multiply(..., where=...)`), `repr` string contents (Julia defines
# `show` only for LinearOperator), the numpy RuntimeWarning check, and the
# dispatch (`np.multiply(..., where=...)`), the numpy RuntimeWarning check, and the
# `MockDiffusionGeometry` subclass (Julia has no subclassing; the behaviours it
# probes are exercised against a real geometry instead).

Expand Down Expand Up @@ -521,8 +520,12 @@ end
@test coeffs(components[2]) ≈ c2
end

# Upstream also asserts on `repr(element)`. Julia defines `show` only for
# LinearOperator, so there is no equivalent to check.
@testset "repr includes space" begin
rep = repr(zeros(s1 + s2))
@test occursin("DirectSumElement(", rep)
@test occursin("space=DirectSumSpace(", rep)
@test occursin("spaces=[FunctionSpace, VectorFieldSpace]", rep)
end
end
end

Expand Down Expand Up @@ -782,10 +785,16 @@ end
@test coeffs(out) ≈ expected
end
end

@testset "repr includes spaces" begin
rep = repr(identity_operator(sp))
@test occursin("LinearOperator(", rep)
@test occursin("domain=FunctionSpace(dim=", rep)
@test occursin("codomain=FunctionSpace(dim=", rep)
end
end

# Skipped: `repr(op)` contents (Julia's `show` for LinearOperator has a different
# format), and the numpy RuntimeWarning check, which has no Julia analogue.
# Skipped: the numpy RuntimeWarning check, which has no Julia analogue.
end

# ── test_operators_spectral.py ────────────────────────────────────────────────
Expand Down Expand Up @@ -1201,7 +1210,13 @@ end
@test coeffs(B(x, y)) ≈ coeffs(Bt(y, x))
end

# Skipped: `repr(B)` contents — Julia defines no `show` for BilinearOperator.
@testset "repr includes domains" begin
rep = repr(lie_bracket(dg))
@test occursin("BilinearOperator(", rep)
@test occursin("domain_a=VectorFieldSpace(dim=", rep)
@test occursin("domain_b=VectorFieldSpace(dim=", rep)
@test occursin("codomain=VectorFieldSpace(dim=", rep)
end
end
end

Expand Down
14 changes: 14 additions & 0 deletions test/test_tensor_algebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,18 @@
@test aeq(Xu.coeffs, X.coeffs)
@test aeq(fu.coeffs, f.coeffs)
end

@testset "show" begin
fs, vfs = function_space(dg), vector_field_space(dg)
@test repr(fs) == "FunctionSpace(dim=$(space_dim(fs)))"
@test repr(form_space(dg, 2)) == "FormSpace(degree=2, dim=$(space_dim(form_space(dg, 2))))"
@test repr(vfs + fs) ==
"DirectSumSpace(spaces=[VectorFieldSpace, FunctionSpace], dim=$(space_dim(vfs + fs)))"

# A tensor shows its space and batch shape, never its coefficients.
@test repr(w2) == "Form(space=$(repr(w2.space)), shape=$(size(w2.coeffs)), batch_shape=())"
batched = wrap(fs, zeros(3, space_dim(fs)))
@test repr(batched) ==
"ScalarFunction(space=$(repr(fs)), shape=(3, $(space_dim(fs))), batch_shape=(3,))"
end
end
Loading