Skip to content

support string dims in as_xtensor #1793

Description

@williambdean

Using pymc.dims, using as_tensor is suggested with pymc.dims. However, dims work different with as_xtensor than pmd.<DistributionName>.

import pymc as pm
import pymc.dims as pmd
from pytensor.xtensor import as_xtensor

observed = [5, 7]

coords = {"repo": ["pymc", "pymc-marketing"]}
with pm.Model(coords=coords) as model:
    lam = pmd.HalfNormal("lam", dims="repo")
    pmd.Exponential(
        "obs",
        lam=lam,
        observed=observed,
        dims="repo",
    )
ValueError: Variable [5, 7] must have dims associated with it.
To avoid subtle bugs, PyMC does not make any assumptions about the dims of parameters.
Use `as_xtensor` with the `dims` keyword argument to specify the dims explicitly.

However, a likely use of as_xtensor doesn't act the way pymc supports dims

observed = as_xtensor([5, 7], dims="repo")

coords = {"repo": ["pymc", "pymc-marketing"]}
with pm.Model(coords=coords) as model:
    lam = pmd.HalfNormal("lam", dims="repo")
    pmd.Exponential(
        "obs",
        lam=lam,
        observed=observed,
        dims="repo",
    )

ValueError: Shape (2,) must have the same length as dims ('r', 'e', 'p', 'o')

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions