Skip to content

fix(linalg): prepared operators declare their traits — PreparedOperator supertype, PreparedComposed/PreparedAdjoint islinear/isconstant #86

Closed

Description

@kylebeggs

Carved out of #73's gap list because it is an invariant hazard on its own.

  • PreparedOperator (src/linalg.jl:24) has no supertype, so islinear(P), isconstant(P) and adjoint(P) are MethodErrors.
  • PreparedComposed and PreparedAdjoint (src/linalg.jl:270,289) are <: AbstractOperator but declare no trait methods, so islinear on a prepared composed tree falls through to the false default in src/operators/abstract.jl.

"Traits default to the weaker claim" only protects you when the weaker claim is the declared one. Here a wrapper that forwards traits from P.op gets a wrong answer that degrades safely by accident rather than by design.

Fix

  • Give PreparedOperator a supertype (or forward islinear / isconstant / isselfadjoint / isdiagonal to P.op explicitly).
  • PreparedComposed: islinear = islinear(a) && islinear(b), same for isconstant, mirroring Composed in src/operators/algebra.jl:98-100.
  • PreparedAdjoint: forward to the wrapped operator, mirroring AdjointOp in src/operators/abstract.jl:191.
  • Tests in test/prepare_linalg.jl: traits of a prepared tree equal the traits of the unprepared tree for every combinator.

Also worth noting while here: isconstant is declared on every leaf and propagated through the algebra but consumed nowhere in src/. Its first consumer is the SciML isconstant / caching decision in #65.


🤖 Beep boop — Claude found the traits that forgot to speak; Kyle is not muttering defaults to himself.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions