Skip to content

Implement dims.DiracDelta - #8350

Merged
ricardoV94 merged 3 commits into
pymc-devs:mainfrom
anevolbap:feat/dims-diracdelta
Jul 9, 2026
Merged

Implement dims.DiracDelta#8350
ricardoV94 merged 3 commits into
pymc-devs:mainfrom
anevolbap:feat/dims-diracdelta

Conversation

@anevolbap

Copy link
Copy Markdown
Contributor

Related to #7874

Needed for the pymc-marketing Bass model migration to pymc.dims (pymc-labs/pymc-marketing#2598). DiracDelta is the only distribution that migration uses that pymc.dims was missing.

Also adds Poisson and NegativeBinomial to the dims distributions API page.

anevolbap added 2 commits July 7, 2026 08:31
DiracDeltaRV has no rng, so it can't be wrapped by the XRV machinery like
the other scalar dims distributions. Build the regular RV and wrap it in an
xtensor, relying on MeasurableXTensorFromTensor for the logp.
@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.73%. Comparing base (b1a6bb6) to head (7b45619).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
pymc/dims/distributions/scalar.py 96.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #8350      +/-   ##
==========================================
- Coverage   91.76%   91.73%   -0.03%     
==========================================
  Files         128      128              
  Lines       20661    20697      +36     
==========================================
+ Hits        18960    18987      +27     
- Misses       1701     1710       +9     
Files with missing lines Coverage Δ
pymc/dims/distributions/scalar.py 96.75% <96.00%> (-0.10%) ⬇️

... and 15 files with indirect coverage changes

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

return super().dist([c], **kwargs)

@classmethod
def xrv_op(self, c, core_dims=None, extra_dims=None, rng=None, return_next_rng=False, **kwargs):

@anevolbap anevolbap Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

DiracDeltaRV has no rng, so this can't use as_xrv; here I wrap the tensor RV with xtensor_from_tensor and pass the rng through unchanged (same shape as the old Censored hack). Once DimSymbolicRandomVariable from #8346 lands, this should become a DimDiracDeltaRV(DimSymbolicRandomVariable) for consistency. Keep the interim wrapper until then?

@ricardoV94 ricardoV94 left a comment

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.

Looks good, just a nit to keep the tests light, we already have assert_equivalent_random_graph that should give us the guarantees we need that forward sampling will work

Comment thread tests/dims/distributions/test_scalar.py Outdated
assert_equivalent_random_graph already guarantees forward sampling matches
pm.DiracDelta, so the explicit sample_prior_predictive test is not needed.
@ricardoV94
ricardoV94 marked this pull request as ready for review July 9, 2026 17:05
@ricardoV94
ricardoV94 merged commit c870b5c into pymc-devs:main Jul 9, 2026
42 checks passed
@ricardoV94

Copy link
Copy Markdown
Member

Thanks @anevolbap

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