Template Broadcasting
- xtensors.template_broadcaster(dims: Sequence[str | int], channels: Sequence[Literal['x', 'y'] | None]) Broadcaster
Return a template broadcaster with the specified dimensions and channels
- class xtensors.AxisSelector
Abstract base class for objects that implement
select_axis- __init__() None
- abstract select_axis(X: XTensor, channel: str | None = None) int | None
Select an axis from the tensor X
- Parameters:
X – tensor
channel – (optional) a string specifying the channel. If
self.channelis set, axis selection will only be performed when thechannelparameter matchesself.channel, or elseNoneis returned.
- class xtensors.DimNameSelector(dimname: str, required: bool = False, channel: str | None = None)
Bases:
AxisSelectorSelect an axis based on its name
- __init__(dimname: str, required: bool = False, channel: str | None = None) None
- Parameters:
dimname – target axis name
required – if
True, aKeyErrorwill be raised if no axis nameddimnameis found when selecting an axis from a tensor.channel – Selecting channel.
- select_axis(X: XTensor, channel: str | None = None) int | None
Select an axis from the tensor X
- Parameters:
X – tensor
channel – (optional) a string specifying the channel. If
self.channelis set, axis selection will only be performed when thechannelparameter matchesself.channel, or elseNoneis returned.
- class xtensors.IndexSelector(axis: int, channel: str | None = None)
Bases:
AxisSelectorSelect an axis based on the index
- __init__(axis: int, channel: str | None = None) None
- Parameters:
axis – The axis index, negative indices are supported
channel – Selecting channel.
- select_axis(X: XTensor, channel: str | None = None) int | None
Select an axis from the tensor X
- Parameters:
X – tensor
channel – (optional) a string specifying the channel. If
self.channelis set, axis selection will only be performed when thechannelparameter matchesself.channel, or elseNoneis returned.
- class xtensors.Template(*selectors: AxisSelector)
A tensor broadcasting template that can be reused to broadcast multiple tensors.
A template is basically a list of
AxisSelectorinstances, each specifying how an axis (integer) should be selected.- __init__(*selectors: AxisSelector) None
- Parameters:
selectors – A list of
AxisSelector
- check_well_defined()
Check if the
AxisSelectors are configured in a self-consistent manner.In particular, this method checks if there are
DimNameSelectors with duplicate names orAxisSelectors with duplicate indices.- Raises:
ValueErrorif the check fails
- cast_and_update(X: XTensor, channel: str | None = None) XTensor
Cast the input tensor according to the template and update self’s internal state (i.e. dimension names and coordinates).
- clear()
Reset the internal states.
- property dims: Dims
The dimension names gathered from casting tensors.
- property coords: Coords
The coordinates names gathered from casting tensors.