jactorch.functional.shape#
Tensor shape utilities.
Functions
|
Add a dimension at dim with size size. |
|
Add dimension for the input tensor so that |
|
Broadcast a specific dim for size times. |
|
Add AND expand dimension for the input tensor so that |
|
Concatenate shapes into a tuple. |
|
Flatten the tensor. |
|
Flatten the tensor while keep the first (batch) dimension. |
|
Do a view with optional contiguous copy. |
|
Move a specific dimension to a designated dimension. |
|
Repeat a specific dimension for count times. |
|
Repeat each element along a specific dimension for repeats times. |
Functions
- add_dim(tensor, dim, size)[source]#
Add a dimension at dim with size size.
Example
>>> add_dim(torch.tensor([1, 2, 3]), 0, 2) tensor([[1, 2, 3], [1, 2, 3]])
- add_dim_as_except(tensor, target, *excepts)[source]#
Add dimension for the input tensor so that
It has the same number of dimensions as target.
The original axes of the tensor are ordered in excepts.
Basically, it will “match” the shape of the target tensor, and align the axes in the input tensor with
excepts
in the target tensor.Note
The list excepts must be in ascending order.
See also
broadcast_as_except()
, which adds AND expands dimension.Example
>>> add_dim_as_except(torch.rand(3, 4), torch.rand(2, 3, 4, 5), 1, 1).size() torch.Size([1, 3, 4, 1])
- broadcast(tensor, dim, size)[source]#
Broadcast a specific dim for size times. Originally the dim size must be 1.
Example
>>> broadcast(torch.tensor([1, 2, 3]), 0, 2) tensor([[1, 2, 3], [1, 2, 3]])
- broadcast_as_except(tensor, target, *excepts)[source]#
Add AND expand dimension for the input tensor so that
It has the same number of dimensions as target.
The original axes of the tensor are ordered in excepts.
The original axes of the tensor are expanded to the size of the corresponding axes in target.
After this function, the input tensor will have the same shape as the target tensor.
Note
The list excepts must be in ascending order.
See also
add_dim_as_except()
, which only adds dimension (without expanding).Example
>>> broadcast_as_except(torch.rand(3, 4), torch.rand(2, 3, 4, 5), 1, 1).size() torch.Size([2, 3, 4, 5])
- concat_shape(*shapes)[source]#
Concatenate shapes into a tuple. The values can be either torch.Size, tuple, list, or int.
- force_view(tensor, *shapes)[source]#
Do a view with optional contiguous copy. DEPRECATED. Use tensor.reshape instead.
- repeat(tensor, dim, count)[source]#
Repeat a specific dimension for count times.
Example
>>> repeat(torch.tensor([1, 2, 3]), 0, 2) tensor([1, 2, 3, 1, 2, 3])
See also
repeat_times()
, which repeats each element along the dimension.