@classmethod
def _shape_from_broadcast_dict(cls, orig_shape, broadcast_dict):
    """Using a broadcast dictionary, compute the broadcast shape."""
    shape = list(orig_shape)
    for axis, length in broadcast_dict.items():
        if not 0 <= axis < len(shape):
            raise ValueError('Axis {} out of range [0, {})'.format(axis,
                len(shape)))
        if length < 0:
            raise ValueError('Axis length must be positive. Got {}.'.format
                (length))
        if shape[axis] != 1:
            raise ValueError(
                'Attempted to broadcast axis {} which is of length {}.'.
                format(axis, shape[axis]))
        shape[axis] = length
    return tuple(shape)
