pytensor icon indicating copy to clipboard operation
pytensor copied to clipboard

`RandomVariable` treats `size=()` as `size=None`

Open ricardoV94 opened this issue 1 year ago • 0 comments

Description

This is different than numpy

import numpy as np
import pytensor.tensor as pt

pt.random.normal([0], size=None).eval()  # array([-0.57354733])
pt.random.normal([0], size=()).eval()  # array([-2.39088062])

np.random.normal([0], size=None)  # array([0.10438181])
np.random.normal([0], size=()).eval()  # ValueError: Output size () is not compatible with broadcast dimensions of inputs (1,).

And also JAX (and probably Numba?)

import jax

jax.random.lognormal(jax.random.PRNGKey(0), sigma=jax.numpy.ones((1,)), shape=())
# parameter shapes must be broadcast-compatible with shape argument, 
# and the result of broadcasting the shapes must equal the shape argument, 
# but got result (1,) for shape argument ().

ricardoV94 avatar Jan 02 '24 12:01 ricardoV94