Skip to content

Commit 945fb17

Browse files
add documentation for math.rst
1 parent 0960323 commit 945fb17

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

docs/source/api/dims/math.rst

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,44 @@
11
***************************************
2-
Mathematical operations with dimensions
2+
Mathematical operations
33
***************************************
44

55
This module wraps all the mathematical operations defined in :ref:`pytensor.xtensor.math <pytensor:libdoc_xtensor_math>`.
66

77
It includes a ``linalg`` submodule that wraps all the operations defined in :ref:`pytensor.xtensor.linalg <pytensor:libdoc_xtensor_linalg>`.
88

9-
Operations defined at the module level in :ref:`pytensor.xtensor <pytensor:libdoc_xtensor_module_function>` are available at the ``pymc.dims`` module level.
9+
Operations defined at the module level in :ref:`pytensor.xtensor <pytensor:libdoc_xtensor_module_function>` are available at the :mod:`pymc.dims` module level.
10+
11+
Method-based API on XTensorVariable
12+
===================================
13+
14+
Many operations are also available as methods on :class:`~pytensor.xtensor.type.XTensorVariable` instances, providing a more intuitive interface when working with named dimensions:
15+
16+
**Key methods include:**
17+
18+
- :meth:`~pytensor.xtensor.type.XTensorVariable.isel` - Select data by dimension names
19+
- :meth:`~pytensor.xtensor.type.XTensorVariable.dot` - Perform dot products
20+
- :meth:`~pytensor.xtensor.type.XTensorVariable.sum`, :meth:`~pytensor.xtensor.type.XTensorVariable.mean`, :meth:`~pytensor.xtensor.type.XTensorVariable.prod` - Aggregation operations
21+
- :meth:`~pytensor.xtensor.type.XTensorVariable.transpose` - Reorder dimensions by name
22+
- :meth:`~pytensor.xtensor.type.XTensorVariable.expand_dims`, :meth:`~pytensor.xtensor.type.XTensorVariable.squeeze` - Dimension manipulation
23+
24+
Example
25+
-------
26+
27+
.. code-block:: python
28+
29+
import numpy as np
30+
import pymc as pm
31+
32+
coords = {"time": np.arange(10), "feature": ["a", "b", "c"]}
33+
with pm.Model(coords=coords):
34+
x = pm.Normal("x", mu=0, sigma=1, dims=("time", "feature"))
35+
36+
# Method-based selection and operations
37+
x_subset = x.isel(time=slice(0, 5)) # First 5 timesteps
38+
x_mean = x_subset.mean(dim="feature") # Average across features
39+
40+
# Dot product using method syntax
41+
y = pm.Normal("y", mu=0, sigma=1, dims="feature")
42+
dot_result = x.dot(y, dim="feature") # Shape: (time,)
43+
44+
For a complete list of available methods, see the :class:`~pytensor.xtensor.type.XTensorVariable` API documentation.

0 commit comments

Comments
 (0)