Tensor Broadcasting
- xtensors.broadcast(X: XTensor, Y: XTensor, dimcast: Dimcaster, dimmerge: DimMerger, coordmerge: CoordMerger, shapecheck: bool = True) Tuple[np.ndarray, np.ndarray, Dims, Coords]
Given two named tensors, return two numpy ND arrays of the same rank that can be broadcast together, along with the dimension names and coordinates after broadcasting.
- Parameters:
X,Y –
xtensors.XTensorobjects to be broadcast togetherdimcast – An object implementing the
xtensors.Dimcasterprotocoldimmerge – An object implmenting the
xtensors.DimMergerprotocolcoordmerge – An object implementing the
xtensors.CoordMergerprotocol
- xtensors.unilateral_broadcaster(X: XTensor, Y: XTensor) Tuple[np.ndarray, np.ndarray, Dims, Coords]
This broadcaster takes the second tensor and permutes its dimensions to match the first one. The algorithm for finding the permutation is defined by unilateral_dimcast()
- xtensors.vanilla_broadcaster(X: XTensor, Y: XTensor) Tuple[np.ndarray, np.ndarray, Dims, Coords]
Vanilla broadcaster: the same as what’s used in torch’s named tensors. Dimension names (or None) have to match at the same axis position.
- xtensors.cast(broadcaster: Broadcaster, X: XTensor) Callable[[XTensor], XTensor]
- xtensors.cast(broadcaster: Broadcaster, X: XTensor, Y: XTensor) XTensor
Broadcast the second tensor with
broadcaster(X, Y). IfYisNoneor not provided, a casting function is returned instead.