Skip to content

Commit 124a34b

Browse files
authored
Reorganize docs, include README sections in docs (#40)
* Reorganize docs TOC * Add README sections to the documentation
1 parent 1ccb5f6 commit 124a34b

File tree

13 files changed

+103
-58
lines changed

13 files changed

+103
-58
lines changed

README.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
[![Conda](https://img.shields.io/conda/v/gpytorch/linear_operator.svg)](https://anaconda.org/gpytorch/linear_operator)
99
[![PyPI](https://img.shields.io/pypi/v/linear_operator.svg)](https://pypi.org/project/linear_operator)
1010

11+
12+
<!-- docs_intro_start -->
13+
1114
LinearOperator is a PyTorch package for abstracting away the linear algebra routines needed for structured matrices (or operators).
1215

1316
**This package is in beta.**
@@ -21,6 +24,8 @@ Package development TODOs:
2124
- [ ] Add algebraic routines for generic rectangular operators
2225
- [ ] Add sparse operators
2326

27+
<!-- docs_intro_end -->
28+
2429
To get started, run either
2530
```sh
2631
pip install linear_operator
@@ -29,6 +34,10 @@ conda install linear_operator -c gpytorch
2934
```
3035
or [see below](#installation) for more detailed instructions.
3136

37+
38+
<!-- docs_index_start -->
39+
40+
3241
## Why LinearOperator
3342
Before describing what linear operators are and why they make a useful abstraction, it's easiest to see an example.
3443
Let's say you wanted to compute a matrix solve:
@@ -122,7 +131,12 @@ A = LowRankRootLinearOperator(C) + DiagLinearOperator(d) # represents a 10M x 1
122131
torch.linalg.solve(A, b) # computes A^{-1} b efficiently!
123132
```
124133

125-
### What is a Linear Operator?
134+
135+
<!-- docs_index_end -->
136+
<!-- docs_about_start -->
137+
138+
139+
## What is a Linear Operator?
126140
A linear operator is a generalization of a matrix.
127141
It is a linear function that is defined in by its application to a vector.
128142
The most common linear operators are (potentially structured) matrices,
@@ -170,7 +184,6 @@ torch.matmul(D, torch.tensor([4., 5., 6.])
170184
# Returns [4., 10., 18.]
171185
```
172186

173-
#### Why is This Useful?
174187
While `_matmul`, `_size`, and `_transpose_nonbatch` might seem like a limited set of functions,
175188
it turns out that most functions on the `torch` and `torch.linalg` namespaces can be efficiently implemented
176189
using only these three primitative functions.
@@ -181,8 +194,13 @@ This makes it possible to define very complex compositional structures that stil
181194

182195
Finally, `LinearOperator` objects can be composed with one another, yielding new `LinearOperator` objects and automatically keeping track of algebraic structure after each computation.
183196
As a result, users never need to reason about what efficient linear algebra routines to use (so long as the input elements defined by the user encode known input structure).
197+
<!-- docs_about_end -->
184198
See the [using LinearOperator objects](#using-linearoperator-objects) section for more details.
185199

200+
201+
<!-- docs_usecases_start -->
202+
203+
186204
## Use Cases
187205

188206
There are several use cases for the LinearOperator package.
@@ -236,6 +254,10 @@ torch.linalg.solve(A, torch.randn(20000)) # Sub O(N^3) routine!
236254
```
237255

238256

257+
<!-- docs_usecases_end -->
258+
<!-- docs_using_start -->
259+
260+
239261
## Using LinearOperator Objects
240262

241263
LinearOperator objects share (mostly) the same API as `torch.Tensor` objects.
@@ -330,6 +352,11 @@ This includes:
330352

331353
See the documentation for a [full list of supported composition and decoration operations](https://linear-operator.readthedocs.io/en/latest/composition_decoration_operators.html).
332354

355+
356+
<!-- docs_using_end -->
357+
<!-- docs_install_start -->
358+
359+
333360
## Installation
334361

335362
LinearOperator requires Python >= 3.8.
@@ -357,6 +384,10 @@ To install what is currently on the `main` branch (potentially buggy and unstabl
357384
pip install --upgrade git+https://github.com/cornellius-gp/linear_operator.git
358385
```
359386

387+
388+
<!-- docs_install_end -->
389+
390+
360391
### Development Installation
361392
If you are contributing a pull request, it is best to perform a manual installation:
362393

docs/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
myst-parser
12
setuptools_scm
23
sphinx
34
sphinx_rtd_theme

docs/source/about.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.. role:: hidden
2+
:class: hidden-section
3+
4+
.. include:: ../../README.md
5+
:start-after: <!-- docs_about_start -->
6+
:end-before: <!-- docs_about_end -->
7+
:parser: myst_parser.sphinx_

docs/source/conf.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
4545
# ones.
4646
extensions = [
47+
"myst_parser", # For adding sections of the README to the docs
4748
"sphinx.ext.intersphinx",
4849
"sphinx.ext.coverage",
4950
"sphinx.ext.mathjax",
@@ -53,6 +54,12 @@
5354
"sphinx_autodoc_typehints",
5455
]
5556

57+
myst_enable_extensions = [
58+
"amsmath", # Ensure markdown math from README gets compiled into rst math
59+
"dollarmath", # Ensure markdown math from README gets compiled into rst math
60+
"tasklist", # Check boxes
61+
]
62+
5663
# Add any paths that contain templates here, relative to this directory.
5764
templates_path = ["_templates"]
5865

docs/source/converting.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@
44
Converting Between LinearOperators and torch.Tensor
55
====================================================
66

7-
TODO
8-
97
.. autofunction:: linear_operator.to_linear_operator
108

119
.. autofunction:: linear_operator.to_dense
12-
13-
.. autoclass:: linear_operator.operators.DenseLinearOperator
14-
:members:

docs/source/index.rst

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,52 @@
55
66
:github_url: https://github.com/cornellius-gp/linear_operator
77

8-
LinearOperator Documentation
8+
LinearOperator
99
===========================================
1010

11+
.. include:: ../../README.md
12+
:start-after: <!-- docs_intro_start -->
13+
:end-before: <!-- docs_intro_end -->
14+
:parser: myst_parser.sphinx_
15+
16+
Why LinearOperator
17+
------------------
18+
19+
.. include:: ../../README.md
20+
:start-after: <!-- docs_index_start -->
21+
:end-before: <!-- docs_index_end -->
22+
:parser: myst_parser.sphinx_
23+
24+
Use Cases
25+
----------
26+
27+
.. include:: ../../README.md
28+
:start-after: ## Use Cases
29+
:end-before: ## Using LinearOperator Objects
30+
:parser: myst_parser.sphinx_
31+
32+
33+
.. toctree::
34+
:maxdepth: 1
35+
:caption: Getting Started
36+
37+
self
38+
install
39+
1140
.. toctree::
1241
:maxdepth: 1
1342
:caption: Basic Concepts
1443

15-
intro
44+
about
45+
using
1646
converting
17-
structure
1847
custom_linear_operators
1948

2049

2150
.. toctree::
2251
:maxdepth: 1
2352
:caption: Core API
2453

25-
namespace
26-
settings
2754

2855

2956
.. toctree::
@@ -33,12 +60,15 @@ LinearOperator Documentation
3360
linear_operator
3461
data_sparse_operators
3562
composition_decoration_operators
63+
structure
3664

3765

3866
.. toctree::
3967
:maxdepth: 1
4068
:caption: Advanced Package Reference
4169

70+
settings
71+
namespace
4272
utils
4373

4474

docs/source/install.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.. role:: hidden
2+
:class: hidden-section
3+
4+
.. include:: ../../README.md
5+
:start-after: <!-- docs_install_start -->
6+
:end-before: <!-- docs_install_end -->
7+
:parser: myst_parser.sphinx_

docs/source/intro.rst

Lines changed: 0 additions & 24 deletions
This file was deleted.

docs/source/namespace.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
.. currentmodule:: linear_operator
55

66

7+
Functions
8+
==============================
9+
710
LinearOperator objects are designed to work seamlessly with the torch API.
811
For example:
912

@@ -23,9 +26,6 @@ These functions are designed to work on :class:`~linear_operator.operators.Linea
2326
objects alike.
2427

2528

26-
linear_operator
27-
----------------
28-
2929
.. automodule:: linear_operator
3030

3131
.. autofunction:: add_diagonal

docs/source/settings.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.. role:: hidden
22
:class: hidden-section
33

4-
linear_operator.settings
4+
Settings
55
===================================
66

77
.. currentmodule:: linear_operator.settings

0 commit comments

Comments
 (0)