pypto.gcd#
产品支持情况#
产品 |
是否支持 |
|---|---|
Ascend 950PR/Ascend 950DT |
√ |
Atlas A3 训练系列产品/Atlas A3 推理系列产品 |
√ |
Atlas A2 训练系列产品/Atlas A2 推理系列产品 |
√ |
功能说明#
求input与other对应元素的最大公约数。
函数原型#
gcd(input: Tensor, other: Union[Tensor, int]) -> Tensor:
参数说明#
参数名 |
输入/输出 |
说明 |
|---|---|---|
input |
输入 |
源操作数。 |
other |
输入 |
源操作数。 |
返回值说明#
返回输出Tensor,Tensor的数据类型和input、other相同,Shape为input和other广播后大小。
约束说明#
input 和 other 类型应该相同。
other 为数字的时候,不支持隐式转化。
other 不支持nan、inf等特殊值
调用示例#
TileShape设置示例#
说明:调用该operation接口前,应通过set_vec_tile_shapes设置TileShape, TileShape尾轴须32B对齐。
TileShape维度应和输出一致。
示例1:非广播场景,输入intput shape为[m, n],other为[m, n],输出为[m, n],TileShape设置为[m1, n1], 则m1, n1分别用于切分m, n轴。
pypto.set_vec_tile_shapes(4, 16)
示例2:广播场景,输入intput shape为[m, n],other为[m, 1],输出为[m, n],TileShape设置为[m1, n1], 则m1, n1分别用于切分m, n轴。
pypto.set_vec_tile_shapes(4, 16)
接口调用示例#
x = pypto.tensor([2, 3], pypto.DT_INT32)
y = pypto.tensor([2, 3], pypto.DT_INT32)
z = pypto.gcd(x, y)
# Using a scalar
c = pypto.gcd(x, 2)
结果示例如下:
输入数据x: : [[9 9 9],
[6 6 6]]
输入数据y: [[1 2 3],
[1 2 3]]
输出数据z: [[1 1 3],
[1 2 3]]
输出数据c: [[1 1 1],
[2 2 2]]