"""PyPTO"""
from typing import List, Optional, Tuple
from .. import pypto_impl
from .._op_wrapper import op_wrapper
from ..tensor import Tensor
@op_wrapper
def concat(tensors: List[Tensor], dim: int = 0) -> Tensor:
"""
Concatenate multiple tensors according to the specified dimension.
Parameters
---------
tensors: Tensors
tensor to be spliced.
dim : int
specified dimensions.
out: Tensor
The concatenated tensor
Examples
---------
x = pypto.tensor([2, 2], pypto.data_type.DT_FP32) # 2x2 tensor with all 1s
y = pypto.tensor([2, 2], pypto.data_type.DT_FP32) # 2x2 tensor with all 0s
dim = 0
out = pypto.concat([x, y], dim)
Input x : [[1.0 1.0],
[1.0 1.0]]
y : [[0.0 0.0],
[0.0 0.0]]
Output out:[[1.0 1.0],
[1.0 1.0],
[0.0 0.0],
[0.0 0.0]]
"""
return pypto_impl.Cat(tensors, dim)
@op_wrapper
def interleave(input: Tensor, other: Tensor) -> Tuple[Tensor, Tensor]:
"""
Interleave two tensors into two output tensors.
Parameters
---------
input: Tensor
The first input tensor.
other: Tensor
The second input tensor. It must have the same shape as input.
Returns
-------
tuple
A tuple of two tensors.
"""
return pypto_impl.Interleave(input, other)
@op_wrapper
def deinterleave(input: Tensor, other: Optional[Tensor] = None) -> Tuple[Tensor, Tensor]:
"""
Deinterleave one or two input tensors into two output tensors.
Parameters
---------
input: Tensor
The input tensor. In single-input mode, its last dimension is twice the output last dimension.
other: Tensor, optional
The second input tensor. If provided, it must have the same shape as input and the outputs.
Returns
-------
tuple
A tuple of two tensors.
"""
if other is None:
return pypto_impl.DeInterleave(input)
return pypto_impl.DeInterleave(input, other)