pymc icon indicating copy to clipboard operation
pymc copied to clipboard

Add variable names to size from dims

Open ricardoV94 opened this issue 3 years ago • 2 comments

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]

ricardoV94 avatar Mar 30 '22 05:03 ricardoV94

@flo-schu This may be a good beginner issue to work on! Let us know what you think

canyon289 avatar Jun 24 '22 03:06 canyon289

@flo-schu This may be a good beginner issue to work on! Let us know what you think

Thanks @canyon289. This seems doable. I'll look into it.

flo-schu avatar Jun 24 '22 07:06 flo-schu