Skip to content

Commit c570454

Browse files
committed
refactor: use DimSymbolicRandomVariable for hybrid path, deduplicate signature inference, fix compound dists
- Replace compiled-function + graph-walking hybrid path with DimSymbolicRandomVariable(SymbolicRandomVariable) + OpFromGraph - Deduplicate _infer_dims_signature / _infer_final_signature - Add XElemwise support to expand_dist_dims for compound dists - Drop _forward_dim_lengths, enforce strict XTensorVariable output - Add tests: compound non-XRV output, hybrid support_point
1 parent 79dcc0c commit c570454

4 files changed

Lines changed: 246 additions & 162 deletions

File tree

pymc/dims/distributions/core.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from pytensor.xtensor.basic import XTensorFromTensor, xtensor_from_tensor
2929
from pytensor.xtensor.shape import Transpose
3030
from pytensor.xtensor.type import XTensorVariable
31-
from pytensor.xtensor.vectorization import XRV
31+
from pytensor.xtensor.vectorization import XRV, XElemwise
3232

3333
from pymc import SymbolicRandomVariable, modelcontext
3434
from pymc.dims.distributions.transforms import DimTransform, log_odds_transform, log_transform
@@ -191,7 +191,6 @@ class DimDistribution:
191191

192192
xrv_op: Callable
193193
default_transform: DimTransform | None = None
194-
_forward_dim_lengths: bool = False
195194

196195
@staticmethod
197196
def _as_xtensor(x):
@@ -326,8 +325,6 @@ def dist(
326325
}
327326
if kwargs.get("rng") is None:
328327
kwargs["rng"] = pt.random.shared_rng(seed=None)
329-
if cls._forward_dim_lengths and dim_lengths is not None:
330-
kwargs["dim_lengths"] = dim_lengths
331328
_, rv = cls.xrv_op(
332329
*dist_params,
333330
extra_dims=extra_dims,
@@ -377,6 +374,14 @@ def expand_dist_dims(dist: XTensorVariable, extra_dims: dict[str, Any]) -> XTens
377374
# We don't propagate the old RNG, because we don't want the new and old dists to be correlated
378375
new_rng = pt.random.shared_rng(seed=None)
379376
return new_dist_op(new_rng, *extra_dims.values(), *params_and_dim_lengths)
377+
case XElemwise():
378+
expanded_inputs = [
379+
expand_dist_dims(inp, extra_dims=extra_dims)
380+
if isinstance(inp, XTensorVariable)
381+
else inp
382+
for inp in dist.owner.inputs
383+
]
384+
return dist.owner.op.make_node(*expanded_inputs).outputs[0]
380385
case Transpose():
381386
return expand_dist_dims(dist.owner.inputs[0], extra_dims=extra_dims).transpose(
382387
..., *dist.dims

0 commit comments

Comments
 (0)