Commit 538897a
Reorganize linear algebra (#2037)
* Move matrix decomposition Ops into a sub-module
* Move solve Ops into a sub-module
* Move misc solve Ops
* Move inverse Ops to sub-module
* Move matrix product Ops to sub-module
* Move matrix construction Ops to sub-module
* Move matrix summarization Ops to sub-module
* Re-import all public functions via `linalg.py`
* Issue depreciation warning when importing from nlinalg/slinalg
* Update rewrite imports to use _linalg locations
* Update link dispatch imports to use _linalg locations
* Update numba dispatch imports to use _linalg locations
* Organize linalg rewrites according to library
* Organize linalg dispatches according to library
* Organize numba dispatches according to library
* Organize linalg tests according to library
* Organize linalg rewrite tests according to library
* Rename tests/tensor/test_linalg -> tests/tensor/linalg
* Reorganize dispatch test according to library
* Clean up stale linalg imports
* Update docs
* Rename tests/link/*/test_linalg -> tests/link/*/linalg
* Remove stray empty test_linalg/__init__.py under numba linalg
* Update numba link CI part to new linalg/ directory
* Move solve rewrites under tensor/rewriting/linalg
The scan-tracking solve rewrites previously lived in
pytensor/tensor/_linalg/solve/rewriting.py and were registered via a
side-effect import chain from tensor/_linalg/__init__.py. That chain
was broken in the linalg reorg (the _linalg package init was emptied),
and registration only kept working incidentally because
tensor/linalg.py happens to import from _linalg.solve.
Move them into tensor/rewriting/linalg/solve.py alongside the other
solve rewrites. The imports also needed updating: the v3 file imported
via tensor.slinalg, which is now the deprecation shim and would emit
DeprecationWarnings on every load.
Also drop the speculative __all__ and inv_to_solve re-export from
tensor/rewriting/linalg/__init__.py; the one test that imported
inv_to_solve from there now imports it from .inverse directly.
* Stop importing from deprecated nlinalg/slinalg in unrelated tests
These three test files happened to import individual Ops/functions from
pytensor.tensor.{nlinalg,slinalg}. Since those modules are now
deprecation shims, every test run was emitting DeprecationWarnings for
imports that have nothing to do with testing the shim itself.
Retarget the imports to the new pytensor.tensor._linalg.* locations,
matching the convention used by the new tests/tensor/linalg/ tests.
* Stop importing from deprecated nlinalg/slinalg in legacy test suites
tests/tensor/test_nlinalg.py and tests/tensor/test_slinalg.py were left
untouched by the linalg reorg and still imported individual symbols
from pytensor.tensor.{nlinalg,slinalg}. With those modules now being
deprecation shims, every collection of these files emitted dozens of
DeprecationWarnings.
These files are not testing the deprecation shim itself — they're the
original Op test suites. Retarget the imports to the new
pytensor.tensor._linalg.* locations.
* Add targeted test for nlinalg/slinalg deprecation shim
Asserts that accessing a moved name on the deprecated module emits a
DeprecationWarning, that the shim forwards to the same object exposed
by the new pytensor.tensor.linalg public API, and that unknown names
still raise AttributeError. Also fixes a stale doc comment in
_linalg/summary.py that pointed at the old nlinalg path.
* Drop automodule from deprecated nlinalg/slinalg doc pages
The deprecation pages still carried `.. automodule:: pytensor.tensor.{nlinalg,slinalg} :members:` directives. Each automodule
walks the module's `__dir__`, which on the new shims returns every
moved name and triggers `__getattr__` per name — emitting a
DeprecationWarning per attribute on every doc build, and producing
duplicate doc entries that already exist on the new
:ref:`libdoc_linalg` page.
Drop the automodule blocks; the pages are now pure deprecation notices
that point at `pytensor.tensor.linalg`.
* Group linalg API docs by category and pin them to __all__
The linalg.rst page used `.. automodule:: pytensor.tensor.linalg
:members:`, which renders all 36 functions from `__all__` as one
unstructured alphabetical list. Replace it with hand-grouped sections
(Constructors / Decomposition / Inverse / Products / Solve / Summary)
that mirror the internal `_linalg/` package layout, using explicit
`autofunction::` directives.
To stop the rst from drifting away from the public API, add
`tests/tensor/linalg/test_doc_api.py`. It parses every
`.. autofunction:: pytensor.tensor.linalg.<name>` directive out of the
rst and asserts the resulting set is exactly equal to
`pytensor.tensor.linalg.__all__`. Any future addition or removal on
either side fails the test with a precise diff.
Op classes remain undocumented in the rst — the public surface is
intentionally functions only.
* Tweak linalg directory structure
---------
Co-authored-by: Ricardo Vieira <ricardo.vieira1994@gmail.com>1 parent 6f08a6e commit 538897a
File tree
154 files changed
+12013
-9062
lines changed- .github/workflows
- doc/library/tensor
- pytensor
- graph/rewriting
- link
- jax/dispatch
- linalg
- mlx/dispatch
- linalg
- numba/dispatch
- linalg
- decomposition
- solvers
- pytorch/dispatch
- linalg
- sparse
- tensor
- _linalg
- solve
- linalg
- decomposition
- solvers
- rewriting
- linalg
- xtensor
- tests
- benchmarks
- link
- jax
- linalg
- mlx/linalg
- numba
- linalg
- solvers
- pytorch
- linalg
- tensor
- linalg
- test_decomposition
- test_solvers
- rewriting
- linalg
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
154 files changed
+12013
-9062
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
| 104 | + | |
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
108 | | - | |
| 108 | + | |
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
| 1 | + | |
4 | 2 | | |
5 | 3 | | |
6 | | - | |
| 4 | + | |
7 | 5 | | |
8 | 6 | | |
9 | 7 | | |
10 | 8 | | |
11 | | - | |
| 9 | + | |
12 | 10 | | |
13 | 11 | | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | 1 | | |
4 | 2 | | |
5 | 3 | | |
6 | | - | |
| 4 | + | |
7 | 5 | | |
8 | 6 | | |
9 | 7 | | |
10 | 8 | | |
11 | | - | |
| 9 | + | |
12 | 10 | | |
13 | 11 | | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1495 | 1495 | | |
1496 | 1496 | | |
1497 | 1497 | | |
1498 | | - | |
| 1498 | + | |
1499 | 1499 | | |
1500 | 1500 | | |
1501 | 1501 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
287 | 287 | | |
288 | 288 | | |
289 | 289 | | |
290 | | - | |
| 290 | + | |
291 | 291 | | |
292 | 292 | | |
293 | 293 | | |
| |||
352 | 352 | | |
353 | 353 | | |
354 | 354 | | |
355 | | - | |
| 355 | + | |
356 | 356 | | |
357 | 357 | | |
358 | 358 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | 18 | | |
20 | 19 | | |
21 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
0 commit comments