pangolin.interface.Interface.broadcast#
- Interface.broadcast(fun: Callable[[], RV]) Callable[[], RV][source]#
- Interface.broadcast(fun: Callable[[RV], RV]) Callable[[RVLike], RV]
- Interface.broadcast(fun: Callable[[RV, RV], RV]) Callable[[RVLike, RVLike], RV]
- Interface.broadcast(fun: Callable[[RV, RV, RV], RV]) Callable[[RVLike, RVLike, RVLike], RV]
- Interface.broadcast(fun: Callable[[RV, RV, RV, RV], RV]) Callable[[RVLike, RVLike, RVLike, RVLike], RV]
- Interface.broadcast(fun: Callable[[RV, RV, RV, RV, RV], RV]) Callable[[RVLike, RVLike, RVLike, RVLike, RVLike], RV]
- Interface.broadcast(fun: Callable[[RV, RV, RV, RV, RV, RV], RV]) Callable[[RVLike, RVLike, RVLike, RVLike, RVLike, RVLike], RV]
- Interface.broadcast(fun: Callable[[...], RV]) Callable[[...], RV]
A combinator that broadcasts a scalar graph-building function.
The returned function coerces supplied arguments to RVs and applies
funto scalar arguments according to this interface’s broadcasting policy. The policy is looked up when the returned function is called, so temporaryoverloadsettings apply.- Parameters:
fun (Callable[[...], RV]) – Function accepting scalar RV arguments and returning one scalar RV. Its internal calculations may use vectors and matrices; only its inputs and output must be scalar.
- Returns:
broadcast_fun – Function accepting RVLike arguments and returning an RV with their broadcast shape. Supplied positional and keyword arguments follow the same broadcasting rules.
- Raises:
TypeError – If
fundoes not return an RV.ValueError – If input shapes cannot be broadcast under the current policy or
funreturns a nonscalar RV.
- Return type:
Callable[[…], RV]
Notes
Existing RV inputs retain their interfaces; coerced constants use this interface. The result retains the interface chosen by
fun.Only explicitly supplied arguments are coerced and broadcast. Omitted defaults and captured values are used normally by
funand do not determine the broadcast shape. Static overloads describe positional calls with up to six arguments. Other signatures retain the RV return type but leave arguments unchecked. Runtime coercion applies to every supplied argument, including keyword arguments.Examples
Broadcast a function that accepts only scalar RVs:
>>> from pangolin import interface as pi, ir >>> def squared_difference(x, y): ... assert isinstance(x, ir.RV) and x.shape == () ... assert isinstance(y, ir.RV) and y.shape == () ... return (x - y) * (x - y) >>> broadcast_squared_difference = pi.broadcast(squared_difference) >>> broadcast_squared_difference([1.0, 2.0, 3.0], 1.0).shape (3,)