Skip to content

dims.Data creates XTensorSharedVariables#8096

Merged
jessegrabowski merged 3 commits into
pymc-devs:mainfrom
ricardoV94:handle_xtensor_variables_more_naturally
Feb 21, 2026
Merged

dims.Data creates XTensorSharedVariables#8096
jessegrabowski merged 3 commits into
pymc-devs:mainfrom
ricardoV94:handle_xtensor_variables_more_naturally

Conversation

@ricardoV94
Copy link
Copy Markdown
Member

@ricardoV94 ricardoV94 commented Feb 8, 2026

Depends on pymc-devs/pytensor#1882

We were registering regular TensorSharedVariables in pymc.dims.Data, and then wrapping those in as_xtensor. The problem with that is that when you then try to act on m["x"] you were not acting on the same variable that pymc.dims.Data returned to you, instead you were acting on the input of as_xtensor...

This made it hard to adopt it in pymc-marketing

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.50%. Comparing base (c32715a) to head (0a6f365).
⚠️ Report is 115 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #8096   +/-   ##
=======================================
  Coverage   91.49%   91.50%           
=======================================
  Files         123      123           
  Lines       19832    19821   -11     
=======================================
- Hits        18146    18137    -9     
+ Misses       1686     1684    -2     
Files with missing lines Coverage Δ
pymc/dims/model.py 65.38% <100.00%> (-1.29%) ⬇️
pymc/model/core.py 93.30% <100.00%> (ø)
pymc/model/fgraph.py 97.91% <100.00%> (-0.04%) ⬇️
pymc/model/transform/optimization.py 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ricardoV94 ricardoV94 changed the title Handle xtensor variables more naturally Use variable agnostic view operation (so XTensorVariables are handled as well as TensorVariables) Feb 9, 2026
@ricardoV94 ricardoV94 changed the title Use variable agnostic view operation (so XTensorVariables are handled as well as TensorVariables) Use type agnostic view operation (so XTensorVariables are handled as well as TensorVariables) Feb 9, 2026
@ricardoV94 ricardoV94 force-pushed the handle_xtensor_variables_more_naturally branch from ba31b01 to abfdd9e Compare February 10, 2026 14:01
@ricardoV94 ricardoV94 changed the title Use type agnostic view operation (so XTensorVariables are handled as well as TensorVariables) Support XTensorSharedVariables Feb 10, 2026
@ricardoV94 ricardoV94 force-pushed the handle_xtensor_variables_more_naturally branch from abfdd9e to 04e2f24 Compare February 19, 2026 14:47
@ricardoV94 ricardoV94 changed the title Support XTensorSharedVariables pymc.dims.Data creates XTensorSharedVariables directly Feb 19, 2026
@ricardoV94 ricardoV94 changed the title pymc.dims.Data creates XTensorSharedVariables directly dims.Data creates XTensorSharedVariables directly Feb 19, 2026
@ricardoV94 ricardoV94 changed the title dims.Data creates XTensorSharedVariables directly dims.Data creates XTensorSharedVariables Feb 20, 2026
@ricardoV94 ricardoV94 marked this pull request as ready for review February 20, 2026 13:11
@read-the-docs-community
Copy link
Copy Markdown

read-the-docs-community Bot commented Feb 20, 2026

Documentation build overview

📚 pymc | 🛠️ Build #31498443 | 📁 Comparing 0a6f365 against latest (c32715a)


🔍 Preview build

Show files changed (9 files in total): 📝 9 modified | ➕ 0 added | ➖ 0 deleted
File Status
glossary.html 📝 modified
contributing/jupyter_style.html 📝 modified
api/generated/pymc.sample_posterior_predictive.html 📝 modified
learn/core_notebooks/dims_module.html 📝 modified
_modules/pymc/dims/model.html 📝 modified
_modules/pymc/model/core.html 📝 modified
_modules/pymc/model/fgraph.html 📝 modified
_modules/pytensor/tensor/extra_ops.html 📝 modified
_modules/pymc/model/transform/optimization.html 📝 modified

Copy link
Copy Markdown
Member

@jessegrabowski jessegrabowski left a comment

Choose a reason for hiding this comment

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

approved with some stupid questions and a nitpick about a comment, typical PR review smh

Comment thread pymc/model/core.py
"""
model = modelcontext(model)
var = var.copy(model.name_for(name))
var = view_op(var, name=model.name_for(name))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What's the difference? Maybe a better question - why were we copying in the first place?

Copy link
Copy Markdown
Member Author

@ricardoV94 ricardoV94 Feb 21, 2026

Choose a reason for hiding this comment

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

You need an op sometimes because you can't have x be both a free rv and a deterministic, but x and view(x) is fine. Copy was another way of achieving this but it's Elemwise or XElemwise Op depending on the type. View instead works with any input type (and achieves the same).

Even variables without a .copy method would work in the future.

The immediate motivation for changing though was to keep pretending xtensorvariables don't exist as much as possible in the rest of the codebase

Comment thread pymc/model/fgraph.py
Comment thread tests/dims/test_model.py
coords = {
"group": range(3),
"knots": range(N_knots),
"knot": range(N_knots),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

singular dims gang rise up!

@jessegrabowski jessegrabowski force-pushed the handle_xtensor_variables_more_naturally branch from 9b06508 to 0a6f365 Compare February 21, 2026 08:46
@jessegrabowski jessegrabowski merged commit 9d6f6c1 into pymc-devs:main Feb 21, 2026
74 of 76 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants