Skip to content

Refactor matrix_ops public functions as backend-agnostic wrappers #22

@jc-macdonald

Description

@jc-macdonald

Summary

After extracting ScipyLinearBackend, replace the extracted implementation in matrix_ops.py with thin delegation to a module-default backend instance.

Implementation

from .backends import ScipyLinearBackend

_DEFAULT_BACKEND = ScipyLinearBackend()

def implicit_solve(left_op, right_op, x):
    """Solve L @ y = R @ x using the default backend."""
    return _DEFAULT_BACKEND.solve(left_op, right_op, x)

def clear_implicit_solver_cache():
    """Clear the default backend solver cache."""
    _DEFAULT_BACKEND.clear_cache()

What stays unchanged

  • Operator builders (build_laplacian_tridiag, build_implicit_euler_operators, etc.)
  • Stage operator factories (make_stage_operator_factory, make_constant_base_builder)
  • Grouping utilities, smooth(), kron_*
  • Operator type alias

Files to modify

  • src/op_engine/matrix_ops.py — replace extracted implementation with delegation

Acceptance criteria

  • from op_engine import implicit_solve, clear_implicit_solver_cache still works
  • Existing downstream code (flepimop2 adapter, examples) unaffected
  • All tests pass

Dependencies

Depends on: #20 (ScipyLinearBackend)
Parallel with: #21 (inject into CoreSolver)

Metadata

Metadata

Assignees

Labels

refactorCode reorganization without behavior change

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions