This submodule contains various functions that apply numpy’s broadcasting rules to shape tuples, and also to samples drawn from probability distributions.

The main challenge when broadcasting samples drawn from a generative model, is that each random variate has a core shape. When we draw many i.i.d samples from a given RV, for example if we ask for size_tuple i.i.d draws, the result usually is a size_tuple + RV_core_shape. In the generative model’s hierarchy, the downstream RVs that are conditionally dependent on our above sampled values, will get an array with a shape that is inconsistent with the core shape they expect to see for their parameters. This is a problem sometimes because it prevents regular broadcasting in complex hierarchical models, and thus make prior and posterior predictive sampling difficult.

This module introduces functions that are made aware of the requested size_tuple of i.i.d samples, and does the broadcasting on the core shapes, transparently ignoring or moving the i.i.d size_tuple prepended axes around.


Convert ints, arrays, and Nones to tuples

shapes_broadcasting(*args[, raise_exception])

Return the shape resulting from broadcasting multiple shapes.

broadcast_dist_samples_shape(shapes[, size])

Apply shape broadcasting to shape tuples but assuming that the shapes correspond to draws from random variables, with the size tuple possibly prepended to it.

get_broadcastable_dist_samples(samples[, ...])

Get a view of the samples drawn from distributions which adds new axes in between the size prepend and the distribution's shape.

broadcast_distribution_samples(samples[, size])

Broadcast samples drawn from distributions taking into account the size (i.e.

broadcast_dist_samples_to(to_shape, samples)

Broadcast samples drawn from distributions to a given shape, taking into account the size (i.e.


Check whether an rv size is None (ie., at.Constant([]))

change_dist_size(dist, new_size[, expand])

Change or expand the size of a Distribution.