Linear Operator¶
linear_operator
¶
Checked linear actions and explicit eager solve diagnostics.
Actions may use a native array namespace. The solver callback boundary in this module is deliberately eager NumPy; it does not install an AD rule or transfer arrays between devices. No action is materialized by probing basis vectors.
ActionOperator(shape, dtype, namespace, matvec, transpose_matvec=None)
dataclass
¶
Caller-owned, real linear action at a fixed linearization/context.
matvec maps (shape[1],) to (shape[0],) without changing namespace,
dtype or device. Matrix application applies that callback column by column.
transpose_matvec represents the Euclidean transpose of the same
fixed map, not an inverse or a weighted adjoint. Linearity and the correctness
of the transpose are the provider's obligations; neither is inferred from
a numerical probe. Only real float32/float64 actions are supported.
Attributes:
| Name | Type | Description |
|---|---|---|
shape |
tuple[int, int]
|
Output and input dimensions. |
dtype |
object
|
Native real floating dtype shared by inputs and outputs. |
namespace |
Any
|
Array-API namespace returned by :func: |
matvec |
Callable[[Array], Array]
|
Linear vector application. |
transpose_matvec |
Callable[[Array], Array] | None
|
Optional Euclidean transpose vector application. |
T
property
¶
Return the explicitly supplied real Euclidean transpose.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If no transpose callback was supplied. |
__matmul__(other)
¶
Apply the action without densifying or coercing the input.
Returns:
| Type | Description |
|---|---|
Array
|
Vector or matrix of independent output columns. |
Source code in src/op_engine/linear_operator.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | |
__post_init__()
¶
Validate static metadata and callback availability.
Raises:
| Type | Description |
|---|---|
ValueError
|
If dimensions are invalid. |
TypeError
|
If dtype or callbacks are unsupported. |
Source code in src/op_engine/linear_operator.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
ApplicableOperator
¶
Bases: Protocol
Shape-bearing operator with vector and column-matrix application.
dtype
property
¶
Return the operator's native real floating dtype.
shape
property
¶
Return the two-dimensional operator shape.
__matmul__(other)
¶
Apply the operator to a vector or matrix of independent columns.
Source code in src/op_engine/linear_operator.py
39 40 41 | |
LinearSolveCandidate(value, success, iterations, message='')
dataclass
¶
Callback output before the engine verifies the original residual.
success reports the solver's own termination status. A false status
cannot be overridden by a small residual. Iterations use the concrete
callback's declared unit and must fit its requested budget.
LinearSolveDiagnostics(converged, residual_norm, tolerance, iterations, message)
dataclass
¶
Eager convergence evidence, one entry per RHS column (one for vectors).
LinearSolveError(result)
¶
Bases: RuntimeError
A checked eager solve failed; result retains per-column evidence.
Retain the failed result and identify failed RHS columns.
Source code in src/op_engine/linear_operator.py
255 256 257 258 259 260 261 262 | |
LinearSolveOptions(rtol=1e-08, atol=1e-10, max_iterations=100)
dataclass
¶
Per-column true-residual tolerance and callback iteration budget.
A column passes when ||b - A x||_2 <= max(atol, rtol * ||b||_2).
max_iterations counts the callback's documented iteration unit; a
concrete adapter must declare whether this means inner steps or cycles.
__post_init__()
¶
Validate static tolerances and iteration budget.
Raises:
| Type | Description |
|---|---|
ValueError
|
If a tolerance or iteration budget is invalid. |
Source code in src/op_engine/linear_operator.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |
LinearSolveRequest(operator, rhs, options=LinearSolveOptions(), preconditioner=None, context=None)
dataclass
¶
Explicit eager solve inputs; assembly and cache ownership stay external.
preconditioner is an optional approximate inverse action with the same
square shape, namespace and dtype as the operator. The concrete solver must
document its side and use, or reject it. context is caller-owned metadata
identifying mesh, coefficients, stage size/scale and preconditioner version.
A callback that caches preparation must invalidate whenever any of these
change. The engine creates no cache for this callback path.
LinearSolveResult(value, diagnostics)
dataclass
¶
Candidate solution with independently recomputed residual diagnostics.
require_linear_converged(result)
¶
Return a successful eager solution or raise with per-column diagnostics.
Raises:
| Type | Description |
|---|---|
LinearSolveError
|
If any RHS column failed the checked solve. |
Source code in src/op_engine/linear_operator.py
343 344 345 346 347 348 349 350 351 | |
solve_linear(request, solver)
¶
Call an eager solver and verify every original, unpreconditioned residual.
Returns:
| Type | Description |
|---|---|
LinearSolveResult
|
Candidate solution and per-column diagnostics, including failures. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If namespace, dtype or callback metadata is invalid. |
ValueError
|
If operator/RHS/result dimensions or iteration counts disagree. |
Source code in src/op_engine/linear_operator.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | |