Skip to content

Fix mean, var and std for XTensorVariables #1533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ricardoV94
Copy link
Member

@ricardoV94 ricardoV94 commented Jul 11, 2025

Also add docstrings to most methods and properties so they show up in the docs.

Removes broadcast as a method, since it is not one in xarray


📚 Documentation preview 📚: https://pytensor--1533.org.readthedocs.build/en/1533/

@ricardoV94 ricardoV94 added bug Something isn't working docs xtensor labels Jul 11, 2025
@ricardoV94 ricardoV94 requested a review from OriolAbril July 11, 2025 16:58
@ricardoV94 ricardoV94 force-pushed the broadcast_not_a_method branch from d89351c to 33e831a Compare July 11, 2025 16:59
Raises
------
Value:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Value:
ValueError

@@ -516,6 +578,48 @@ def set(self, value):
return px.indexing.index_assignment(x, value, *idxs)

def inc(self, value):
"""Return a copy of the variable indexed by self with the indexed values incremented by value.
The original variable is not modified.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation got messed up somehow

Raises
------
Value:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Value:
ValueError

Comment on lines +871 to +876
import pytensor.xtensor as ptx
x = ptx.as_xtensor([[1, 2], [3, 4]], dims=("a", "b"))
stacked_cumsum = x.stack({"c": ["a", "b"]}).cumsum("c")
unstacked_cumsum = stacked_x.unstack({"c": x.sizes})
unstacked_cumsum.eval()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be indented

Examples
--------
.. test-code::
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.. test-code::
.. testcode::

None of these blocks are being shown in the rendered version: https://pytensor--1533.org.readthedocs.build/en/1533/library/xtensor/type.html#pytensor.xtensor.type.XTensorVariable.inc

I think it is because the directive name is without hyphen: https://www.sphinx-doc.org/en/master/usage/extensions/doctest.html#directive-testcode

@@ -720,7 +830,7 @@ def transpose(
*dim: str | EllipsisType,
missing_dims: Literal["raise", "warn", "ignore"] = "raise",
):
"""Transpose dimensions of the tensor.
"""Transpose the dimensions of the variable.
Parameters
----------
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the description of missing dims, if you want the bullet point list to be rendered as a list instead of as inline text (see current render https://pytensor--1533.org.readthedocs.build/en/1533/library/xtensor/type.html#pytensor.xtensor.type.XTensorVariable.transpose) there should be an empty line between previous line and start of list:

How to handle dimensions that don't exist in the tensor:

- "raise": Raise an error if any dimensions don't exist

Comment on lines 720 to 721
- int: the new size
- sequence: coordinates (length determines size)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- int: the new size
- sequence: coordinates (length determines size)
- int: the new size
- sequence: coordinates (length determines size)

no extra indentation and empty line between previous line and list should render as list instead of current quoted list render

@ricardoV94
Copy link
Member Author

Sorry for the noise, should have checked :l

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working docs xtensor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants