Operator reference¶
Base¶
The :class:LinearOperator base class.
LinearOperator
¶
Abstract base class for matrix-free finite-dimensional linear operators.
It follows in most parts the implementation of probnum.linops.LinearOperator
from ProbNum
(see also https://github.com/probabilistic-numerics/probnum/blob/main/src/probnum/linops/_linear_operator.py).
Design choices:
:class:LinearOperator\ s are defined to behave like a :class:jax.numpy.ndarray
and thus, they
- have :attr:
shape, :attr:dtype, :attr:ndim, and :attr:sizeattributes, - can be matrix multiplied (:code:
@) with a :class:numpy.ndarrayfrom left and right, following the same broadcasting rules as :func:numpy.matmul, - can be multiplied (:code:
*) by a scalar from the left and the right, - can be added to, subtracted from and matrix multiplied (:code:
@) with other :class:LinearOperatorinstances with appropriate :attr:shape, - can be transposed (:attr:
Tor :meth:transpose), and they - can be type-cast (:meth:
astype).
This is mostly implemented lazily, i.e. the result of these operations is a new,
composite :class:LinearOperator, that defers linear operations to the original
operators and combines the results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
ShapeLike
|
Shape of the linear operator. |
required |
dtype
|
DTypeLike
|
|
required |
See Also
aslinop : Transform into a LinearOperator
Notes
- A subclass is only required to implement :meth:
_matmat. Additionally, other methods like :meth:_solve, :meth:_inverse, :meth:_transpose, :meth:_cholesky, or :meth:_detshould be overwritten if more performant implementations are available. - Compared to probnum this implementation does not check for dtype to be numeric and not complexfloating.
- Matrix properties are tags.
Important:
- (...batch..., n, m) is the general shape assumption.
Source code in linox/operators/base.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 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 | |
T: LinearOperator
property
¶
Return the transpose of this operator, preserving structure where possible.
batch_ndim: int
property
¶
Number of batch dimensions of the linear operator.
batch_shape: tuple[int]
property
¶
Shape of the batch dimensions of the linear operator.
dtype: jnp.dtype
property
¶
Data type of the linear operator.
is_psd: bool
property
¶
Whether the operator is positive semi-definite.
is_symmetric: bool
property
¶
Whether the operator is symmetric.
ndim: int
property
¶
Number of linear operator dimensions.
Defined analogously to numpy.ndarray.ndim. TODO(2bys): Check with jnp.ndarray.ndim.
shape: tuple[int]
property
¶
Shape of the linear operator.
Defined as a tuple of the output and input dimension of operator.
size: int
property
¶
Product of the :attr:shape entries.
__call__(arr: BinaryOperandType) -> LinearOperator
¶
graph(**kwargs)
¶
graph_str(**kwargs)
¶
todense() -> jnp.ndarray
¶
Materialize this operator as a dense array.
Source code in linox/operators/base.py
transpose() -> LinearOperator
¶
Return the transpose of this operator.
Subclasses that know their own structure should override this and
return it (Diagonal returns itself, Kronecker returns a
Kronecker of transposed factors, and so on). The default is a lazy
wrapper that derives the adjoint from the forward matvec, so it never
materialises the dense matrix.
Source code in linox/operators/base.py
tree_flatten() -> tuple[tuple[any, ...], dict[str, any]]
classmethod
¶
Default implementation for PyTree flattening.
Subclasses should override this method to provide proper PyTree support.
Source code in linox/operators/base.py
tree_unflatten(aux_data: dict[str, any], children: tuple[any, ...]) -> LinearOperator
classmethod
¶
Default implementation for PyTree unflattening.
Source code in linox/operators/base.py
Basic¶
Dense Matrix operator.
Matrix
¶
Bases: LinearOperator
A linear operator defined via a matrix.
For a matrix :math:A, this represents the linear operator :math:x \mapsto Ax.
The action on a vector :math:x is given by matrix multiplication :math:Ax.
Args: A: The matrix defining the linear operator
Source code in linox/operators/dense.py
__T__() -> Matrix
¶
transpose() -> Matrix
¶
tree_flatten() -> tuple[tuple[any, ...], dict[str, any]]
¶
Flatten this operator into JAX pytree children and static data.
tree_unflatten(aux_data: dict[str, any], children: tuple[any, ...]) -> Matrix
classmethod
¶
Reconstruct this operator from JAX pytree children and static data.
Diagonal Linear Operators.
Diagonal
¶
Bases: LinearOperator
A linear operator defined via a diagonal matrix.
For a vector :math:d, this represents the diagonal matrix :math:\text{diag}(d).
The action on a vector :math:x is given by element-wise multiplication
:math:\text{diag}(d)x = d \odot x where :math:\odot denotes element-wise
multiplication.
Args: diag: The diagonal elements of the matrix
Source code in linox/operators/diagonal.py
is_psd: bool
property
¶
Whether every diagonal entry is non-negative.
Returns False for a traced diagonal rather than guessing: under
jax.jit the entries are tracers with no concrete ordering, so no
claim can be made. A bare except here previously swallowed every
error, including unrelated bugs.
is_symmetric: bool
property
¶
Whether this operator equals its own transpose (always true here).
diagonal() -> jax.Array
¶
transpose() -> Diagonal
¶
tree_flatten() -> tuple[tuple[any, ...], dict[str, any]]
¶
Flatten this operator into JAX pytree children and static data.
tree_unflatten(aux_data: dict[str, any], children: tuple[any, ...]) -> Diagonal
classmethod
¶
Reconstruct this operator from JAX pytree children and static data.
Source code in linox/operators/diagonal.py
Special Linear Operators (Identity, Zero, Scalar, Ones).
Identity
¶
Bases: LinearOperator
The identity operator.
This represents the identity matrix :math:I. The action on a vector :math:x is
given by :math:Ix = x, i.e., the identity operator leaves vectors unchanged.
Args: shape: The shape of the identity operator dtype: The data type of the identity operator. Defaults to JAX's current floating dtype (float64 under x64, else float32).
Source code in linox/operators/special.py
is_psd: bool
property
¶
Check if operator is positive semi-definite.
is_symmetric: bool
property
¶
Check if operator is symmetric.
transpose() -> Identity
¶
tree_flatten() -> tuple[tuple[any, ...], dict[str, any]]
¶
Flatten for JAX pytree registration.
tree_unflatten(aux_data: dict[str, any], children: tuple[any, ...]) -> Identity
classmethod
¶
Unflatten for JAX pytree registration.
Ones
¶
Bases: LinearOperator
The ones operator.
This represents the matrix :math:\mathbf{1}\mathbf{1}^T where :math:\mathbf{1}
is a vector of ones. The action on a vector :math:x is given by
:math:(\mathbf{1}\mathbf{1}^T)x = \mathbf{1}(\mathbf{1}^T x), i.e., it sums the
elements of :math:x and returns a vector of that sum.
Args: shape: The shape of the ones operator dtype: The data type of the ones operator. Defaults to JAX's current floating dtype (float64 under x64, else float32).
Source code in linox/operators/special.py
Scalar
¶
Bases: LinearOperator
A linear operator defined via a scalar.
For a scalar :math:\alpha, this represents :math:\alpha I where :math:I
is the identity matrix. The action on a vector :math:x is given by scalar
multiplication :math:(\alpha I)x = \alpha x.
Args: scalar: The scalar value defining the operator
Source code in linox/operators/special.py
is_psd: bool
property
¶
Check if operator is positive semi-definite.
is_symmetric: bool
property
¶
Check if operator is symmetric.
transpose() -> Scalar
¶
tree_flatten() -> tuple[tuple[any, ...], dict[str, any]]
¶
tree_unflatten(aux_data: dict[str, any], children: tuple[any, ...]) -> Scalar
classmethod
¶
Unflatten for JAX pytree registration.
Zero
¶
Bases: LinearOperator
The zero operator.
This represents the zero matrix :math:0. The action on a vector :math:x is
given by :math:0x = 0, i.e., the zero operator maps all vectors to zero.
Args: shape: The shape of the zero operator dtype: The data type of the zero operator. Defaults to JAX's current floating dtype (float64 under x64, else float32).
Source code in linox/operators/special.py
is_psd: bool
property
¶
Check if operator is positive semi-definite.
is_symmetric: bool
property
¶
Check if operator is symmetric.
transpose() -> Zero
¶
tree_flatten() -> tuple[tuple[any, ...], dict[str, any]]
¶
Flatten for JAX pytree registration.
tree_unflatten(aux_data: dict[str, any], children: tuple[any, ...]) -> Zero
classmethod
¶
Unflatten for JAX pytree registration.
Composition¶
Arithmetic operations for linear operators.
This module implements various arithmetic operations for linear operators, including:
- :class:
ScaledLinearOperator: Represents :math:\alpha Afor scalar :math:\alphaand operator :math:A - :class:
AddLinearOperator: Represents :math:A_1 + A_2 + \ldots + A_nfor operators :math:A_i - :class:
ProductLinearOperator: Represents :math:A_1A_2\ldots A_nfor operators :math:A_i - :class:
CongruenceTransform: Represents :math:ABA^Tfor operators :math:Aand :math:B - :class:
TransposedLinearOperator: Represents :math:A^Tfor operator :math:A - :class:
InverseLinearOperator: Represents :math:A^{-1}for operator :math:A
These operators can be combined to form complex linear transformations while maintaining efficient computation through lazy evaluation.
ScaledLinearOperator
¶
Bases: LinearOperator
Linear operator scaled with a scalar.
For a linear operator :math:A and scalar :math:\alpha, this represents
:math:\alpha A where :math:(\alpha A)x = \alpha(Ax) for any vector :math:x
Args: operator: A linear operator to be scaled scalar: A scalar value to multiply the operator with
Source code in linox/operators/arithmetic.py
is_psd: bool
property
¶
Whether the scaled operator is positive semi-definite.
is_symmetric: bool
property
¶
Whether the scaled operator is symmetric.
transpose() -> LinearOperator
¶
tree_flatten() -> tuple[tuple[any, ...], dict[str, any]]
¶
Flatten this operator into JAX pytree children and static data.
tree_unflatten(aux_data: dict[str, any], children: tuple[any, ...]) -> ScaledLinearOperator
classmethod
¶
Reconstruct this operator from JAX pytree children and static data.
Source code in linox/operators/arithmetic.py
AddLinearOperator
¶
Bases: LinearOperator
A linear operator formed by adding two or more linear operators together.
For linear operators :math:A_1, A_2, \ldots, A_n, this represents
:math:A_1 + A_2 + \ldots + A_nwhere
:math:(A_1 + A_2 + \ldots + A_n)x = A_1x + A_2x + \ldots + A_nx
for any vector :math:x
Args: *operator_list: Variable number of linear operators to be added
Source code in linox/operators/arithmetic.py
transpose() -> AddLinearOperator
¶
tree_flatten() -> tuple[tuple[any, ...], dict[str, any]]
¶
Flatten this operator into JAX pytree children and static data.
tree_unflatten(aux_data: dict[str, any], children: tuple[any, ...]) -> AddLinearOperator
classmethod
¶
Reconstruct this operator from JAX pytree children and static data.
Source code in linox/operators/arithmetic.py
ProductLinearOperator
¶
Bases: LinearOperator
Product of linear operators.
For linear operators :math:A_1, A_2, \ldots, A_n, this represents
:math:A_1A_2\ldots A_n where :math:(A_1A_2\ldots A_n)x = A_1(A_2(\ldots(A_nx)))
for any vector :math:x
Args: *operator_list: Variable number of linear operators to be multiplied
Source code in linox/operators/arithmetic.py
1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 | |
transpose() -> ProductLinearOperator
¶
tree_flatten() -> tuple[tuple[any, ...], dict[str, any]]
¶
Flatten this operator into JAX pytree children and static data.
tree_unflatten(aux_data: dict[str, any], children: tuple[any, ...]) -> ProductLinearOperator
classmethod
¶
Reconstruct this operator from JAX pytree children and static data.
TransposedLinearOperator
¶
Bases: LinearOperator
Transpose of a linear operator.
For a linear operator :math:A, this represents :math:A^T
where :math:(A^T)_{ij} = A_{ji} for all :math:i,j
Args: operator: A linear operator to be transposed
Source code in linox/operators/arithmetic.py
1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 | |
transpose() -> LinearOperator
¶
tree_flatten() -> tuple[tuple[any, ...], dict[str, any]]
¶
Flatten this operator into JAX pytree children and static data.
tree_unflatten(aux_data: dict[str, any], children: tuple[any, ...]) -> TransposedLinearOperator
classmethod
¶
Reconstruct this operator from JAX pytree children and static data.
Source code in linox/operators/arithmetic.py
InverseLinearOperator
¶
Bases: LinearOperator
Inverse of a linear operator.
For a linear operator :math:A, this represents :math:A^{-1}
where :math:A^{-1} is the unique operator such that :math:AA^{-1} = A^{-1}A = I
where :math:I is the identity operator
Args: operator: A linear operator to be inverted
Source code in linox/operators/arithmetic.py
1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 | |
transpose() -> LinearOperator
¶
Return the transpose of this operator.
Source code in linox/operators/arithmetic.py
tree_flatten() -> tuple[tuple[any, ...], dict[str, any]]
¶
Flatten this operator into JAX pytree children and static data.
Source code in linox/operators/arithmetic.py
tree_unflatten(aux_data: dict[str, any], children: tuple[any, ...]) -> InverseLinearOperator
classmethod
¶
Reconstruct this operator from JAX pytree children and static data.
Source code in linox/operators/arithmetic.py
PseudoInverseLinearOperator
¶
Bases: LinearOperator
Moore-Penrose pseudo-inverse A^+ of a linear operator.
Source code in linox/operators/arithmetic.py
transpose() -> LinearOperator
¶
Return the transpose of this operator.
Source code in linox/operators/arithmetic.py
tree_flatten() -> tuple[tuple[any, ...], dict[str, any]]
¶
Flatten this operator into JAX pytree children and static data.
tree_unflatten(aux_data: dict[str, any], children: tuple[any, ...]) -> PseudoInverseLinearOperator
classmethod
¶
Reconstruct this operator from JAX pytree children and static data.
Source code in linox/operators/arithmetic.py
CongruenceTransform
¶
Bases: ProductLinearOperator
:math:A B A^\top.
Source code in linox/operators/arithmetic.py
transpose() -> LinearOperator
¶
tree_flatten() -> tuple[tuple[any, ...], dict[str, any]]
¶
Flatten this operator into JAX pytree children and static data.
tree_unflatten(aux_data: dict[str, any], children: tuple[any, ...]) -> CongruenceTransform
classmethod
¶
Reconstruct this operator from JAX pytree children and static data.
Source code in linox/operators/arithmetic.py
Structured¶
Kronecker product operations for linear operators.
This module includes:
- :class:
Kronecker: Represents the Kronecker product :math:A \otimes Bof two linear operators :math:Aand :math:B - :class:
KroneckerSelectedEigenvectors: Matrix-free operator for selected eigenvectors of a Kronecker product - :func:
topk_eigh: Compute top-k or bottom-k eigenvalues/vectors of a Kronecker product without forming the full matrix
Kronecker
¶
Bases: LinearOperator
A Kronecker product of two linear operators.
Example usage:
A = jnp.array([[1, 2], [3, 4]], dtype=jnp.float32) B = jnp.array([[5, 6], [7, 8]], dtype=jnp.float32) op = Kronecker(A, B) vec = jnp.ones((4,)) result = op @ vec result_true = jnp.kron(A, B) @ vec jnp.allclose(result, result_true)
Source code in linox/operators/kron.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
A: LinearOperator
property
¶
First factor of the Kronecker product.
B: LinearOperator
property
¶
Second factor of the Kronecker product.
is_psd: bool
property
¶
Check if Kronecker product is positive semi-definite.
is_symmetric: bool
property
¶
Check if Kronecker product is symmetric.
shape: tuple[int, int]
property
¶
Shape of the Kronecker product.
trace() -> jax.Array
¶
Compute trace of Kronecker product: tr(A (x) B) = tr(A) tr(B).
Source code in linox/operators/kron.py
transpose() -> Kronecker
¶
tree_flatten() -> tuple[tuple, dict]
¶
tree_unflatten(aux_data: dict, children: tuple) -> Kronecker
classmethod
¶
KroneckerSelectedEigenvectors
¶
Bases: LinearOperator
Matrix-free operator for selected Kronecker eigenvectors.
Represents :math:Q_k where columns are
:math:q_A^{(i)} \otimes q_B^{(j)} \otimes \ldots for selected index tuples.
Never forms the full Kronecker product. For two factors A, B with
eigenvectors :math:Q_A, Q_B:
.. math:: Q_k \alpha = \text{vec}((U_B \odot \alpha) U_A^T)
where :math:U_A = Q_A[:, \text{selected}_A], :math:U_B = Q_B[:, \text{selected}_B].
Args: factor_vecs: List of (n_i, n_i) eigenvector matrices from each factor selected_indices: List of k tuples specifying which eigenvector combinations sort_indices: Sorting permutations applied to each factor's eigenvalues
Source code in linox/operators/kron.py
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 | |
factor_dims: list[int]
property
¶
Dimensions of each Kronecker factor.
k: int
property
¶
Number of selected eigenvector combinations.
num_factors: int
property
¶
Number of Kronecker factors.
transpose() -> KroneckerSelectedEigenvectorsTranspose
¶
tree_flatten() -> tuple[tuple, dict]
¶
Flatten for JAX pytree registration.
Source code in linox/operators/kron.py
tree_unflatten(aux_data: dict, children: tuple) -> KroneckerSelectedEigenvectors
classmethod
¶
Unflatten for JAX pytree registration.
Source code in linox/operators/kron.py
topk_eigh(op_or_factors, k: int, *, largest: bool = True, sigma2: float | jax.Array | None = None, include_noise_shift: bool = False, return_full_eigs: bool = False, mode: str = 'jax')
¶
Compute top-k eigenvalues/vectors of a Kronecker product.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
op_or_factors
|
LinearOperator or list[LinearOperator]
|
Either a Kronecker operator or a list of factor operators |
required |
k
|
int
|
Number of eigenvalues/vectors to compute |
required |
largest
|
bool
|
If True, compute largest eigenvalues; if False, compute smallest |
True
|
sigma2
|
float or Array
|
Noise variance for whitening |
None
|
include_noise_shift
|
bool
|
Whether to include noise shift in eigenvalues |
False
|
return_full_eigs
|
bool
|
If True, return full eigenvalue arrays for each factor |
False
|
mode
|
str
|
Computation mode |
"jax"
|
Returns:
| Name | Type | Description |
|---|---|---|
eigenvalues |
Array
|
Top-k eigenvalues |
eigenvectors |
LinearOperator
|
Top-k eigenvectors as a linear operator |
info |
KronTopkEighInfo
|
Factorized representation with additional information |
Source code in linox/operators/kron.py
978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 | |
Isotropic additive operators of the form s*I + A.
IsotropicAdditiveLinearOperator
¶
Bases: AddLinearOperator
Isotropic additive linear operator for matrices of the form.
A_iso := s I + A,
where s is a scalar (or a 0-arg scalar LinearOperator) and A is a
symmetric LinearOperator. This class exposes fast, matrix-free implementations
of common spectral transforms (inverse, pseudo-inverse, square root, log,
powers, exp, Cholesky-like factor) by working in the eigenbasis of A.
Core idea
If A = Q Λ Qᵀ is an eigendecomposition of A (with Λ diagonal and
Qᵀ Q = I), then
s I + A = Q (Λ + s I) Qᵀ,
so any spectral function f (e.g. inverse, sqrt, log, power, exp) satisfies
f(s I + A) = Q f(Λ + s I) Qᵀ,
which reduces the linear-algebra to elementwise operations on the eigenvalues.
This class computes/caches an (optionally truncated) eigendecomposition via
leigh(A) and then dispatches the following:
linverse: (s I + A)⁻¹ = (1/s) I − Q diag(λ / (s (λ + s))) Qᵀ (Woodbury / projector–complement split)lpinverse: pseudo-inverse using the same spectral formula with safe handling of zero/near-zero modes.lsqrt: (s I + A)^{1/2} = Q diag(√(λ + s)) Qᵀlcholesky: returns a factor L with L Lᵀ = s I + A, namely L = Q diag(√(λ + s)) (orthonormal “spectral” factor)llog: log(s I + A) = Q diag(log(λ + s)) Qᵀlpow: (s I + A)^p = Q diag((λ + s)^p) Qᵀdiagonal: diag(s I + A) = s · 1 + diag(A)ltrace: tr(s I + A) = s·n + tr(A) (with Hutchinson if needed)lexp: exp(s I + A) = Q diag(exp(λ + s)) Qᵀ
Projector / anti-projector view
When leigh returns a truncated eigenspace Q ∈ ℝ^{n×k} (k ≤ n),
let P := Q Qᵀ be the projector onto the retained subspace and
P⊥ := I − P the orthogonal complement. Then
(s I + A)⁻¹
= Q (Λ + s I)⁻¹ Qᵀ + (1/s) P⊥,
i.e. the inverse acts as (Λ + s I)⁻¹ on span(Q) and as (1/s) I on
its orthogonal complement. The implementation of linverse uses the
equivalent Woodbury form
(s I + A)⁻¹ = (1/s) [ I − Q diag(λ / (λ + s)) Qᵀ ].
If leigh is full-rank, then P = I and P⊥ = 0, which recovers the
usual full spectral formulas.
Caching notes
QandS(eigenvectors/eigenvalues) are cached lazily by_ensure_eigh(). Any operation that changes the operator should call_invalidate_cache().projector(Q Qᵀ) andcomplement(I − Q Qᵀ) are also cached on demand.
Arguments:
s : jax.Array
Scalar added to the diagonal (isotropic shift). May be wrapped into a
scalar ScaledLinearOperator(Identity, s).
A : LinearOperator
Symmetric linear operator (square).
Symmetry is **required and checked exactly**, including under
``jax.jit`` -- where it becomes a runtime error rather than a
trace-time one. The check costs nothing asymptotically: it runs in
:meth:`_ensure_eigh`, which is about to densify ``A`` for ``leigh``
regardless.
``_matmul`` and ``_todense`` stay permissive, since ``s*I + A`` is
computed correctly for any square ``A`` and ``smart_add`` routes every
``Identity + op`` sum through this class. Only the eigh-backed
shortcuts refuse.
Symmetry alone is enough for ``inverse``, ``eigh`` and ``slogdet``.
``sqrt``, ``lcholesky``, ``llog`` and fractional ``lpow`` additionally
require the *shifted* spectrum ``s + lambda`` to be non-negative
(strictly positive for the logarithm); that is checked per-operation
against the eigenvalues, which have already been computed by then.
Returns:
| Type | Description |
|---|---|
A LinearOperator supporting matrix-free application and spectral transforms
|
|
of ``s I + A`` via the multipledispatch functions listed above.
|
|
-------
|
|
Example:
n = 100 s = jnp.array(0.1) A = utils.as_linop(jnp.diag(jnp.linspace(0.0, 5.0, n))) # symmetric L = IsotropicAdditiveLinearOperator(s, A) x = jnp.ones((n,)) y = (linverse(L) @ x) # apply (s I + A)^{-1} to a vector d = diagonal(L) # exact diagonal z = (lsqrt(L) @ x) # apply (s I + A)^{1/2} to a vector
Source code in linox/operators/isotropic.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 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 | |
Q: LinearOperator
property
¶
Eigenvectors of A (computed lazily via leigh).
S: LinearOperator
property
¶
Eigenvalues of A (computed lazily via leigh).
complement: LinearOperator
property
¶
Orthogonal complement projector I - Q Q^T (cached).
operator: LinearOperator
property
¶
The base linear operator A.
projector: LinearOperator
property
¶
Projector onto the eigenspace Q Q^T (cached).
s: jax.Array
property
¶
Scalar operator component (s * I).
scalar: jax.Array
property
¶
Scalar value s from the isotropic shift.
shape: tuple[int, int]
property
¶
Shape of the operator.
tree_flatten() -> tuple[tuple, dict]
¶
Flatten this operator into JAX pytree children and static data.
tree_unflatten(aux_data, children)
classmethod
¶
Low rank representations as linear operators.
This module implements various low rank representations as linear operators, including:
- :class:
LowRank: Represents a low rank matrix :math:A = U \text{diag}(S) V^T - :class:
SymmetricLowRank: Represents a symmetric low rank matrix :math:A = U \text{diag}(S) U^T - :class:
IsotropicScalingPlusSymmetricLowRank: Represents :math:\sigma I + U \text{diag}(S) U^T - :class:
PositiveDiagonalPlusSymmetricLowRank: Represents :math:D + \alpha U \text{diag}(S) U^Twhere :math:Dis a positive diagonal matrix
IsotropicScalingPlusSymmetricLowRank
¶
Bases: AddLinearOperator
Isotropic scaling plus symmetric low rank operator.
For scalar :math:\sigma, matrix :math:U, and vector :math:S, this represents
:math:A = \sigma I + U \text{diag}(S) U^T. The action on a vector :math:x is
given by :math:Ax = \sigma x + U(S \odot (U^T x)) where :math:\odot denotes
element-wise multiplication.
Args:
scalar: Isotropic scaling factor :math:\sigma
U: Factor matrix
S: Vector of singular values
Source code in linox/operators/lowrank.py
S: jax.Array
property
¶
Singular values vector.
U: jax.Array
property
¶
Factor matrix.
lr_eigh: jax.Array
property
¶
Low rank eigendecomposition (U, S).
scalar: float
property
¶
Isotropic scaling factor.
transpose() -> IsotropicScalingPlusSymmetricLowRank
¶
tree_flatten() -> tuple[tuple[any, ...], dict[str, any]]
¶
Flatten for JAX pytree registration.
Source code in linox/operators/lowrank.py
tree_unflatten(aux_data: dict[str, any], children: tuple[any, ...]) -> IsotropicScalingPlusSymmetricLowRank
classmethod
¶
Unflatten for JAX pytree registration.
Source code in linox/operators/lowrank.py
LowRank
¶
Bases: LinearOperator
Low rank operator.
For matrices :math:U, :math:S, and :math:V, this represents the low rank
matrix :math:A = U \text{diag}(S) V^T. The action on a vector :math:x is given
by :math:Ax = U(S \odot (V^T x)) where :math:\odot denotes element-wise
multiplication.
Args: U: Left factor matrix S: Vector of singular values (optional, defaults to ones) V: Right factor matrix (optional, defaults to U)
Source code in linox/operators/lowrank.py
S: jax.Array
property
¶
Singular values vector.
U: jax.Array
property
¶
Left factor matrix.
V: jax.Array
property
¶
Right factor matrix (defaults to U if not provided).
transpose() -> LowRank
¶
tree_flatten() -> tuple[tuple[any, ...], dict[str, any]]
¶
tree_unflatten(aux_data: dict[str, any], children: tuple[any, ...]) -> LowRank
classmethod
¶
Unflatten for JAX pytree registration.
PositiveDiagonalPlusSymmetricLowRank
¶
Bases: AddLinearOperator
Positive diagonal plus symmetric low rank operator.
For positive diagonal matrix :math:D, matrix :math:U, vector :math:S, and
scalar :math:\alpha, this represents :math:A = D + \alpha U \text{diag}(S) U^T.
The action on a vector :math:x is given by
:math:Ax = Dx + \alpha U(S \odot (U^T x)) where :math:\odot denotes
element-wise multiplication.
Args:
diagonal: Positive diagonal matrix :math:D
low_rank: Symmetric low rank component :math:U \text{diag}(S) U^T
low_rank_scale: Scaling factor :math:\alpha (default: 1.0)
Source code in linox/operators/lowrank.py
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 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 | |
diagonal: jax.Array
property
¶
Diagonal component.
low_rank: SymmetricLowRank
property
¶
Low rank component.
low_rank_scale: float
property
¶
Scaling factor for low rank component.
transpose() -> PositiveDiagonalPlusSymmetricLowRank
¶
tree_flatten() -> tuple[tuple[any, ...], dict[str, any]]
¶
Flatten for JAX pytree registration.
Source code in linox/operators/lowrank.py
tree_unflatten(aux_data: dict[str, any], children: tuple[any, ...]) -> PositiveDiagonalPlusSymmetricLowRank
classmethod
¶
Unflatten for JAX pytree registration.
Source code in linox/operators/lowrank.py
SymmetricLowRank
¶
Bases: LowRank
Symmetric low rank operator.
For matrices :math:U and :math:S, this represents the symmetric low rank matrix
:math:A = U \text{diag}(S) U^T. The action on a vector :math:x is given by
:math:Ax = U(S \odot (U^T x)) where :math:\odot denotes element-wise
multiplication.
Args: U: Factor matrix S: Vector of singular values (optional, defaults to ones)
Source code in linox/operators/lowrank.py
_(A: PositiveDiagonalPlusSymmetricLowRank) -> tuple[jax.Array, jax.Array]
¶
Compute log-determinant using the Matrix Determinant Lemma.
|D + U S U^T| = |D| * |I + S U^T D^{-1} U| or |I + U S U^T D^{-1}| = |I + S U^T D^{-1} U| (Sylvester's determinant theorem)
Actually: |D + U S U^T| = |D| |I + S^{-1} + U^T D^{-1} U| wait no. Matrix Determinant Lemma: |A + U W V^T| = |D| |W| |W^{-1} + V^T A^{-1} U| Here A=D, W=S (diag), V=U, U=U. |D + U S U^T| = |D| |S| |S^{-1} + U^T D^{-1} U|
But S might be singular or non-invertible if used loosely. Alternative: |D + U S U^T| = |D| |I + S U^T D^{-1} U| Currently we assume S is diagonal vector.
C = S * (U^T D^{-1} U) inner = I + C
Source code in linox/operators/lowrank.py
Linear operator for representing an eigenvalue decomposition.
This module provides:
- :class:
EigenD: Represents a symmetric linear operator in its eigenvalue decomposition form :math:A = Q \Lambda Q^Twhere :math:Qis orthogonal and :math:\Lambdais diagonal. Both Q and Lambda are LinearOperators.
EigenD
¶
Bases: LinearOperator
A linear operator representing an eigenvalue decomposition.
Represents :math:A = Q \Lambda Q^T where :math:Q is orthogonal and
:math:\Lambda is diagonal. Both Q and Lambda are stored as LinearOperators,
enabling structured representations (e.g., Kronecker products of eigenvectors).
Args: Q: Orthogonal matrix of eigenvectors (LinearOperator or array) Lambda: Diagonal matrix of eigenvalues (LinearOperator or array)
Example: >>> import jax.numpy as jnp >>> from linox import Matrix, Diagonal, leigh >>> A = Matrix(jnp.diag(jnp.array([1.0, 2.0, 3.0]))) >>> lam, Q = leigh(A) >>> eigend = EigenD(Q, Diagonal(lam)) >>> # eigend represents A = Q @ diag(lam) @ Q.T
Source code in linox/operators/eigen.py
Lambda: LinearOperator
property
¶
The eigenvalue operator Lambda.
Q: LinearOperator
property
¶
The orthonormal eigenvector operator Q.
eigenvalues: jax.Array
property
¶
The eigenvalues, as a :class:jax.Array.
transpose() -> EigenD
¶
tree_flatten() -> tuple[tuple, dict]
¶
Flatten this operator into JAX pytree children and static data.
tree_unflatten(aux_data: dict, children: tuple) -> EigenD
classmethod
¶
Reconstruct this operator from JAX pytree children and static data.
Block matrix operations for linear operators.
This module implements various block matrix operations for linear operators, including:
- :class:
BlockMatrix: Represents a general block matrix :math:\begin{bmatrix} A_{11} & \cdots & A_{1n} \\ \vdots & \ddots & \vdots \\ A_{m1} & \cdots & A_{mn} \end{bmatrix} - :class:
BlockMatrix2x2: Represents a 2x2 block matrix :math:\begin{bmatrix} A & B \\ C & D \end{bmatrix} - :class:
BlockDiagonal: Represents a block diagonal matrix :math:\begin{bmatrix} A_1 & & \\ & \ddots & \\ & & A_n \end{bmatrix}
These operators allow efficient representation and computation of structured linear transformations through block matrix operations.
BlockDiagonal
¶
Bases: LinearOperator
Block diagonal matrix.
For linear operators :math:A_1, \ldots, A_n, this represents the block diagonal
matrix :math:\begin{bmatrix} A_1 & & \\ & \ddots & \\ & & A_n \end{bmatrix}
where :math:\begin{bmatrix} A_1 & & \\ & \ddots & \\ & & A_n \end{bmatrix}
\begin{bmatrix} x_1 \\ \vdots \\ x_n \end{bmatrix} =
\begin{bmatrix} A_1x_1 \\ \vdots \\ A_nx_n \end{bmatrix}
Args: *blocks: Variable number of linear operators to be placed on the diagonal. All blocks must have compatible shapes.
Source code in linox/operators/block.py
transpose() -> BlockDiagonal
¶
tree_flatten() -> tuple[tuple[any, ...], dict[str, any]]
¶
Flatten this operator into JAX pytree children and static data.
tree_unflatten(aux_data: dict[str, any], children: tuple[any, ...]) -> BlockDiagonal
classmethod
¶
Reconstruct this operator from JAX pytree children and static data.
BlockMatrix
¶
Bases: LinearOperator
A block matrix where each block is represented by a linear operator.
For linear operators :math:A_{ij}, this represents the block matrix
:math:\begin{bmatrix} A_{11} & \cdots & A_{1n} \\
\vdots & \ddots & \vdots \\ A_{m1} & \cdots & A_{mn} \end{bmatrix}
where each block :math:A_{ij} is a linear operator of compatible shape.
Args:
blocks: A nested list of LinearOperatorLike instances representing the blocks
of the matrix. Shapes must be valid such that creating a block matrix
is possible.
Source code in linox/operators/block.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
blocks: jnp.ndarray
property
¶
The blocks of the block matrix.
transpose() -> BlockMatrix
¶
Transpose the block matrix.
tree_flatten() -> tuple[tuple[any, ...], dict[str, any]]
¶
Flatten this operator into JAX pytree children and static data.
Source code in linox/operators/block.py
tree_unflatten(aux_data: dict[str, any], children: tuple[any, ...]) -> BlockMatrix
classmethod
¶
Reconstruct this operator from JAX pytree children and static data.
Source code in linox/operators/block.py
BlockMatrix2x2
¶
Bases: LinearOperator
2x2 Block Matrix.
For linear operators :math:A, B, C, D, this represents the block matrix
:math:\begin{bmatrix} A & B \\ C & D \end{bmatrix}
where :math:\begin{bmatrix} A & B \\ C & D \end{bmatrix}
\begin{bmatrix} x \\ y \end{bmatrix} =
\begin{bmatrix} Ax + By \\ Cx + Dy \end{bmatrix}
Args: A: The top-left block of the matrix. B: The top-right block of the matrix. C: The bottom-left block of the matrix. D: The bottom-right block of the matrix.
Source code in linox/operators/block.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
transpose() -> BlockMatrix2x2
¶
Return the transpose of this operator.
tree_flatten() -> tuple[tuple[any, ...], dict[str, any]]
¶
Flatten this operator into JAX pytree children and static data.
tree_unflatten(aux_data: dict[str, any], children: tuple[any, ...]) -> BlockMatrix2x2
classmethod
¶
Reconstruct this operator from JAX pytree children and static data.
Source code in linox/operators/block.py
Toeplitz matrix operators with FFT-based multiplication.
Provides efficient O(n log n) matrix-vector products for Toeplitz matrices using FFT-based circular convolution.
Toeplitz
¶
Bases: LinearOperator
Symmetric Toeplitz matrix represented by its first column/row v.
Source code in linox/operators/toeplitz.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
Permutation operations for linear operators.
This module implements permutation operations for linear operators, including:
- :class:
Permutation: Represents a permutation matrix :math:Pthat permutes the rows of a vector according to a given permutation
Permutation
¶
Bases: LinearOperator
A linear operator defined via a permutation matrix.
For a permutation vector :math:p, this represents the permutation matrix :math:P
where :math:P_{ij} = 1 if :math:j = p_i and :math:0 otherwise. The action on a
vector :math:x is given by :math:(Px)_i = x_{p_i}, i.e., it permutes the
elements of :math:x according to the permutation :math:p.
Args: perm: The permutation vector defining the operator perm_inv: The inverse permutation vector (optional, computed if not provided)
Source code in linox/operators/permutation.py
Triangular and Factor-based Linear Operators.
This module implements operators that are defined by their factors, such as:
- :class:Triangular: A triangular matrix (L or U)
- :class:CholeskyFactor: A specific lower triangular factor L from a Cholesky decomposition
- :class:PSDFromFactor: A positive semi-definite operator defined as A = L @ L.T
CholeskyFactor
¶
Bases: Triangular
A Cholesky factor L (lower triangular).
This operator represents the factor L such that A = L @ L.T.
It specializes solves to use solve_triangular.
Source code in linox/operators/factor.py
transpose() -> Triangular
¶
Return the transpose of this operator.
Source code in linox/operators/factor.py
PSDFromFactor
¶
Bases: LinearOperator
Positive Semi-Definite operator defined by a factor L: A = L @ L.T.
This is useful when we already have a matrix square root or Cholesky factor and want to represent the full covariance/operator without squaring it explicitly.
Source code in linox/operators/factor.py
Triangular
¶
Bases: LinearOperator
Triangular matrix operator.
Args: A: The triangular matrix data. lower: If True, A is lower triangular. If False, upper triangular.
Source code in linox/operators/factor.py
_(A: PSDFromFactor) -> tuple[jax.Array, jax.Array]
¶
log|A| = log|L L^T| = 2 log|L|.
Source code in linox/operators/factor.py
Kernels¶
Kernel-based linear operators with automatic structure detection.
Provides lazy kernel operators that avoid materializing full kernel matrices, with automatic selection of Toeplitz structure for stationary kernels on uniform grids.
KernelOperator
¶
Bases: LinearOperator
Base class for kernel-based linear operators.
Source code in linox/operators/kernel.py
ArrayKernel
¶
Bases: KernelOperator
Lazy kernel operator that NEVER materializes the full matrix.
All matrix-vector products are computed on-the-fly using lax.map for JIT compatibility. This operator is designed for large-scale problems where the full kernel matrix would exceed memory.
WARNING: Calling _todense() on large operators will cause OOM.
Args: kernel: Kernel function k(x, y) -> scalar x0: First set of points (n0, d) x1: Second set of points (n1, d), defaults to x0 if None chunk_size: Chunk size for chunked computation
Source code in linox/operators/kernel.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
transpose() -> ArrayKernel
¶
tree_flatten() -> tuple[tuple[any, ...], dict[str, any]]
¶
Flatten for JAX pytree registration.
The kernel function is static (placed in aux_data) so that the
operator can be passed through jax.jit.
Source code in linox/operators/kernel.py
tree_unflatten(aux_data: dict[str, any], children: tuple[any, ...]) -> ArrayKernel
classmethod
¶
Unflatten for JAX pytree registration.
Source code in linox/operators/kernel.py
ToeplitzKernel
¶
Bases: KernelOperator
Kernel operator using Toeplitz structure for O(n log n) matmul via FFT.
This operator is completely matrix-free - it only stores the Toeplitz vector and uses FFT-based multiplication. Suitable for: - Self-covariance (x1 == x0) - Uniform 1D grid - Stationary kernel k(x,y) = f(x-y)
Note: Since we use symmetric Toeplitz matrices, transpose() returns self.
Args: kernel: Stationary kernel function x0: Points array (n,) or (n, 1) - must be uniform 1D grid chunk_size: Chunk size (for compatibility, not used in Toeplitz matmul)
Source code in linox/operators/kernel.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | |
transpose() -> ToeplitzKernel
¶
tree_flatten() -> tuple[tuple[any, ...], dict[str, any]]
¶
Flatten for JAX pytree registration.
The kernel function is static (placed in aux_data) so that the
operator can be passed through jax.jit.
Source code in linox/operators/kernel.py
tree_unflatten(aux_data: dict[str, any], children: tuple[any, ...]) -> ToeplitzKernel
classmethod
¶
Unflatten for JAX pytree registration.
Source code in linox/operators/kernel.py
kernel_operator(kernel: Callable[[jax.Array, jax.Array], jax.Array], x0: jax.Array, x1: jax.Array | None = None, is_stationary: bool = False, assume_uniform: bool = False, chunk_size: int = 256) -> KernelOperator
¶
Create the optimal kernel operator based on structure detection.
Automatically selects ToeplitzKernel when: - Self-covariance (x1 is None or x1 is x0 - identity check only, no value comparison) - Points are uniform 1D grid (assume_uniform=True or host-side check for small n) - Kernel is stationary (is_stationary=True)
Otherwise creates a lazy ArrayKernel that never materializes the full matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kernel
|
Callable[[Array, Array], Array]
|
Kernel function k(x, y) -> scalar |
required |
x0
|
Array
|
First set of points |
required |
x1
|
Array
|
Second set of points (None for self-covariance) |
None
|
is_stationary
|
bool
|
True if kernel is stationary k(x,y) = f(x-y) |
False
|
assume_uniform
|
bool
|
True to skip uniformity check (use when creating grid with arange) |
False
|
chunk_size
|
int
|
Chunk size for lazy matmul computation |
256
|
Returns:
| Type | Description |
|---|---|
KernelOperator
|
Either ToeplitzKernel or ArrayKernel depending on structure |
Source code in linox/operators/kernel.py
Property wrappers¶
Property wrapper operators for symmetry and PSD assumptions.
This module provides lightweight wrapper operators that tag operands with semantic properties like symmetry (Sym) and positive semidefiniteness (PSD).
These wrappers enable specialized algorithm dispatch without modifying the underlying operator. They are compositional and may propagate under arithmetic operations.
See Also
ADR-0003 : Architecture decision record for PSD and symmetry wrappers.
Examples:
>>> import linox as lo
>>> K = lo.Diagonal(jnp.array([1.0, 2.0, 3.0]))
>>> K_psd = lo.PSD(K) # Promise that K is PSD
>>> K_psd.is_psd
True
PSD
¶
Bases: LinearOperator
Wrapper declaring an operator as positive semidefinite.
This is a semantic promise that x^T A x >= 0 for all x. The wrapper does not verify this numerically unless debug validation is performed.
PSD operators are also implicitly symmetric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
op
|
LinearOperator
|
The operator to wrap. Must be square. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
is_psd |
bool
|
Always True for PSD-wrapped operators. |
is_symmetric |
bool
|
Always True (PSD implies symmetric). |
wrapped |
LinearOperator
|
The underlying wrapped operator. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the operator is not square. |
See Also
Sym : Wrapper for symmetric operators. assume_psd : Convenience function to create PSD wrappers.
Examples:
>>> K = lo.Diagonal(jnp.array([1.0, 2.0, 3.0]))
>>> K_psd = lo.PSD(K)
>>> K_psd.is_psd
True
>>> K_psd.is_symmetric
True
Source code in linox/operators/wrappers.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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | |
is_psd: bool
property
¶
Return True, indicating this operator is declared PSD.
is_symmetric: bool
property
¶
Return True, since PSD operators are symmetric.
children() -> tuple[LinearOperator, ...]
¶
transpose() -> LinearOperator
¶
tree_flatten() -> tuple[tuple, dict]
¶
tree_unflatten(aux: dict, children: tuple) -> PSD
classmethod
¶
SPD
¶
Bases: PSD
Wrapper declaring an operator as symmetric positive definite.
This is a semantic promise that x^T A x > 0 for all x != 0 (strictly positive definite). SPD operators are a subset of PSD operators.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
op
|
LinearOperator
|
The operator to wrap. Must be square. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
is_spd |
bool
|
Always True for SPD-wrapped operators. |
is_psd |
bool
|
Always True (SPD implies PSD). |
is_symmetric |
bool
|
Always True (SPD implies symmetric). |
See Also
PSD : Wrapper for positive semidefinite operators. Sym : Wrapper for symmetric operators.
Examples:
>>> K = lo.Diagonal(jnp.array([1.0, 2.0, 3.0])) # All positive
>>> K_spd = lo.SPD(K)
>>> K_spd.is_spd
True
Source code in linox/operators/wrappers.py
Sym
¶
Bases: LinearOperator
Wrapper declaring an operator as symmetric (self-adjoint).
This is a semantic promise that A = A^T (or A = A^H for complex). The wrapper does not verify this numerically unless debug validation is performed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
op
|
LinearOperator
|
The operator to wrap. Must be square. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
is_symmetric |
bool
|
Always True for Sym-wrapped operators. |
wrapped |
LinearOperator
|
The underlying wrapped operator. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the operator is not square. |
See Also
PSD : Wrapper for positive semidefinite operators. assume_symmetric : Convenience function to create Sym wrappers.
Examples:
Source code in linox/operators/wrappers.py
is_psd: bool
property
¶
Return the PSD status of the wrapped operator.
is_symmetric: bool
property
¶
Return True, indicating this operator is declared symmetric.
children() -> tuple[LinearOperator, ...]
¶
transpose() -> LinearOperator
¶
tree_flatten() -> tuple[tuple, dict]
¶
tree_unflatten(aux: dict, children: tuple) -> Sym
classmethod
¶
_(a: PSD) -> LinearOperator
¶
assume_psd(op: LinearOperator) -> PSD
¶
Wrap an operator to declare it as positive semidefinite.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
op
|
LinearOperator
|
The operator to wrap. Must be square. |
required |
Returns:
| Type | Description |
|---|---|
PSD
|
The wrapped operator with is_psd=True and is_symmetric=True. |
See Also
PSD : The wrapper class. assume_symmetric : For symmetric operators without PSD guarantee.
Examples:
Source code in linox/operators/wrappers.py
assume_spd(op: LinearOperator) -> SPD
¶
Wrap an operator to declare it as symmetric positive definite.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
op
|
LinearOperator
|
The operator to wrap. Must be square. |
required |
Returns:
| Type | Description |
|---|---|
SPD
|
The wrapped operator with is_spd=True, is_psd=True, is_symmetric=True. |
See Also
SPD : The wrapper class. assume_psd : For positive semidefinite operators.
Examples:
Source code in linox/operators/wrappers.py
assume_symmetric(op: LinearOperator) -> Sym
¶
Wrap an operator to declare it as symmetric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
op
|
LinearOperator
|
The operator to wrap. Must be square. |
required |
Returns:
| Type | Description |
|---|---|
Sym
|
The wrapped operator with is_symmetric=True. |
See Also
Sym : The wrapper class. assume_psd : For positive semidefinite operators.
Examples:
>>> A = lo.Matrix(jnp.array([[1, 2], [2, 1]]))
>>> A_sym = lo.assume_symmetric(A)
>>> A_sym.is_symmetric
True