pypto.interleave#
产品支持情况#
Ascend 950PR/Ascend 950DT:支持
Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持
Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持
功能说明#
将两个输入 Tensor(input 和 other)按最后一个维度逐元素交织,并将交织后的数据流按中点拆分为两个输出 Tensor。
对每一行最后一维元素,先构造交织流:
interleaved[2 * k] = input[k]
interleaved[2 * k + 1] = other[k]
然后将交织流的前半部分写入第一个输出 Tensor,后半部分写入第二个输出 Tensor。pypto.interleave 是 pypto.deinterleave 的逆操作。
函数原型#
interleave(input: Tensor, other: Tensor) -> Tuple[Tensor, Tensor]
参数说明#
参数名 |
输入/输出 |
说明 |
|---|---|---|
input |
输入 |
第一个源操作数。支持的类型为 Tensor。 |
other |
输入 |
第二个源操作数。支持的类型为 Tensor。 |
返回值说明#
返回一个二元组 (out0, out1)。
out0保存交织流的前半部分。out1保存交织流的后半部分。out0和out1的 Shape、数据类型与input一致。
约束说明#
input和other的数据类型、维度数、Shape 必须一致。支持的数据类型为:
DT_INT8、DT_UINT8、DT_INT16、DT_UINT16、DT_INT32、DT_UINT32、DT_FP16、DT_FP32、DT_BF16。当前支持 1 到 4 维 Tensor。
最后一个维度的 Shape 必须为偶数。
当 TileShape 有效配置时,TileShape 维度应与输入 Tensor 维度一致,且最后一维必须与输入 Tensor 的 Shape 最后一维相等;其他维可按切分需求设置。
Tensor类型输入不支持
TileOpFormat.TILEOP_NZ格式。
调用示例#
TileShape 设置示例#
输入 input 和 other 的 Shape 为 [m, n],输出 out0 和 out1 的 Shape 均为 [m, n],TileShape 设置为 [m1, n1],则 m1、n1 分别用于切分 m、n 轴。
pypto.set_vec_tile_shapes(4, 16)
接口调用示例#
input = pypto.tensor([2, 4], pypto.DT_FP32)
other = pypto.tensor([2, 4], pypto.DT_FP32)
out0, out1 = pypto.interleave(input, other)
结果示例如下:
输入数据 input: [[0.0, 1.0, 2.0, 3.0],
[4.0, 5.0, 6.0, 7.0]]
输入数据 other: [[10.0, 11.0, 12.0, 13.0],
[14.0, 15.0, 16.0, 17.0]]
输出数据 out0: [[0.0, 10.0, 1.0, 11.0],
[4.0, 14.0, 5.0, 15.0]]
输出数据 out1: [[2.0, 12.0, 3.0, 13.0],
[6.0, 16.0, 7.0, 17.0]]
相关接口#
pypto.deinterleave:将交织流反交织回偶数位置和奇数位置的元素流。