Skip to content
This repository was archived by the owner on Nov 17, 2025. It is now read-only.

Commit 1a1d422

Browse files
committed
Dynamically generate RVTransform list in docs
1 parent b39b744 commit 1a1d422

File tree

2 files changed

+41
-25
lines changed

2 files changed

+41
-25
lines changed

docs/source/api/transforms.rst

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -56,37 +56,14 @@ associated variables and their values:
5656

5757
.. autoclass:: aeppl.transforms.TransformValuesRewrite
5858

59+
5960
---------------------
6061
Invertible transforms
6162
---------------------
6263

6364
AePPL currently supports transforms using the following (invertible) Aesara operators. This means that AePPL can compute the log-probability of a random variable that is the result of one of the following transformations applied to another random variable:
6465

65-
- `aesara.tensor.add`
66-
- `aesara.tensor.sub`
67-
- `aesara.tensor.mul`
68-
- `aesara.tensor.true_div`
69-
- `aesara.tensor.exponential`
70-
- `aesara.tensor.exp`
71-
- `aesara.tensor.log`
72-
73-
One can also apply the following transforms directly:
74-
75-
.. autoclass:: aeppl.transforms.LocTransform
76-
.. autoclass:: aeppl.transforms.ScaleTransform
77-
.. autoclass:: aeppl.transforms.LogTransform
78-
.. autoclass:: aeppl.transforms.ExpTransform
79-
.. autoclass:: aeppl.transforms.ReciprocalTransform
80-
.. autoclass:: aeppl.transforms.IntervalTransform
81-
.. autoclass:: aeppl.transforms.LogOddsTransform
82-
.. autoclass:: aeppl.transforms.SimplexTransform
83-
.. autoclass:: aeppl.transforms.CircularTransform
84-
85-
These transformations can be chained using:
86-
87-
88-
.. autoclass:: aeppl.transforms.ChainedTransform
89-
66+
.. print-invertible-transforms::
9067

9168
---------
9269
Censoring

docs/source/conf.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import sphinx.addnodes
44
import sphinx.directives
55
from docutils import nodes
6+
from docutils.frontend import OptionParser
7+
from docutils.utils import new_document
8+
from sphinx.parsers import RSTParser
69
from sphinx.util.docutils import SphinxDirective
710

811
import aeppl
@@ -110,5 +113,41 @@ def run(self):
110113
return [res]
111114

112115

116+
class InvertibleTransformationsDirective(SphinxDirective):
117+
def run(self):
118+
import inspect
119+
import sys
120+
121+
import aeppl.transforms as transforms
122+
123+
invertible_transforms = (
124+
mname
125+
for mname, mtype in inspect.getmembers(sys.modules["aeppl.transforms"])
126+
if inspect.isclass(mtype)
127+
and issubclass(mtype, transforms.RVTransform)
128+
and not mtype == transforms.RVTransform
129+
)
130+
131+
rst = ".. autosummary::\n"
132+
rst += " :toctree: _generated\n\n"
133+
for transform_name in invertible_transforms:
134+
rst += f" aeppl.transforms.{transform_name}\n"
135+
136+
return self.parse_rst(rst)
137+
138+
def parse_rst(self, text: str):
139+
parser = RSTParser()
140+
parser.set_application(self.env.app)
141+
142+
settings = OptionParser(
143+
defaults=self.env.settings,
144+
components=(RSTParser,),
145+
read_config_files=True,
146+
).get_default_values()
147+
document = new_document("<rst-doc>", settings=settings)
148+
parser.parse(text, document)
149+
return [document.children[1]]
150+
113151
def setup(app):
114152
app.add_directive("print-supported-dists", SupportedDistributionsDirective)
153+
app.add_directive("print-invertible-transforms", InvertibleTransformationsDirective)

0 commit comments

Comments
 (0)