Skip to content

Add variable names to size from dims #5669

Closed as not planned
Closed as not planned
@ricardoV94

Description

@ricardoV94

Would make dprint more readable

import aesara
import pymc as pm

with pm.Model(coords=dict(cities=range(5))) as m:
  x = pm.Normal("x", dims=("cities"))

aesara.dprint(x)
normal_rv{0, (0, 0), floatX, False}.1 [id A] 'x'   
 |RandomStateSharedVariable(<RandomState(MT19937) at 0x7FF40F93C540>) [id B]
 |SpecifyShape [id C] ''   
 | |MakeVector{dtype='int64'} [id D] ''   
 | | |<TensorType(int64, ())> [id E]  <- Cryptic variable!
 | |TensorConstant{(1,) of 1} [id F]
 |TensorConstant{11} [id G]
 |TensorConstant{0} [id H]
 |TensorConstant{1.0} [id I]

Instead we could give it a name (doing it manually here for illustration):

with pm.Model(coords=dict(cities=range(5))) as m:
  size = aesara.shared(len(m.coords), name="cities_dim")
  x = pm.Normal("x", size=(size,))

aesara.dprint(x)
normal_rv{0, (0, 0), floatX, False}.1 [id A] 'x'   
 |RandomStateSharedVariable(<RandomState(MT19937) at 0x7FF408D8E140>) [id B]
 |SpecifyShape [id C] ''   
 | |MakeVector{dtype='int64'} [id D] ''   
 | | |cities_dim [id E]  <- Readable variable name
 | |TensorConstant{(1,) of 1} [id F]
 |TensorConstant{11} [id G]
 |TensorConstant{0} [id H]
 |TensorConstant{1.0} [id I]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions