torchgear.tensor¶
- exception torchgear.tensor.ShapeError[source]¶
Bases:
RuntimeErrorRaised when the shape of a tensor is invalid for some functions.
- torchgear.tensor.as1d(x: Tensor, ndim: int = 1, dim: int = -1) Tensor[source]¶
Transforms
xinto andim-D tensor but arranges its all elements into dimensiondim.>>> x = torch.arange(4) >>> as1d(x) tensor([0, 1, 2, 3])
- Parameters:
x (Tensor) – A tensor with any shape.
ndim (int) – Number of dimensions of resulted tensor.
dim – The dimension to place elements in.
- Returns:
The transformed tensor.
- Return type:
Tensor
- torchgear.tensor.broadcastable(*tensors: Tensor) bool[source]¶
- torchgear.tensor.broadcastable(*shapes: Sequence[int]) bool
Check whether some tensors or some tensor shapes are broadcastable.
- Parameters:
tensors_or_shapes – Some tensors or some tensor shapes.
- Returns:
Whether they are broadcastable.
- Return type: