torch.addcdiv¶
- torch.addcdiv(input, tensor1, tensor2, *, value=1, out=None) → Tensor
对
tensor1
进行逐元素除法,将结果乘以标量value
并加到input
上。警告
整数除法在 addcdiv 中不再受支持,在未来的版本中,addcdiv 将对 tensor1 和 tensor2 执行真正的除法。历史版本的 addcdiv 行为可以通过以下方式实现:(input + value * torch.trunc(tensor1 / tensor2)).to(input.dtype),对于整数输入,以及(input + value * tensor1 / tensor2),对于浮点数输入。未来的 addcdiv 行为就是后者的实现:(input + value * tensor1 / tensor2),适用于所有数据类型。
input
,tensor1
和tensor2
的形状必须可广播。对于 FloatTensor 或 DoubleTensor 类型的输入,
value
必须是一个实数,否则为整数。- 参数:
输入(张量)- 要相加的张量
tensor1(张量)- 分子张量
tensor2(张量)- 分母张量
- 关键字参数:
value(数字,可选)- 的乘数
输出(张量,可选)- 输出张量。
示例:
>>> t = torch.randn(1, 3) >>> t1 = torch.randn(3, 1) >>> t2 = torch.randn(1, 3) >>> torch.addcdiv(t, t1, t2, value=0.1) tensor([[-0.2312, -3.6496, 0.1312], [-1.0428, 3.4292, -0.1030], [-0.5369, -0.9829, 0.0430]])