評價此頁

torch.addcdiv#

torch.addcdiv(input, tensor1, tensor2, *, value=1, out=None) Tensor#

執行 tensor1 除以 tensor2 的逐元素除法,將結果乘以標量 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),適用於所有資料型別。

outi=inputi+value×tensor1itensor2i\text{out}_i = \text{input}_i + \text{value} \times \frac{\text{tensor1}_i}{\text{tensor2}_i}

inputtensor1tensor2 的形狀必須是 可廣播的

對於 FloatTensorDoubleTensor 型別的輸入,value 必須是實數,否則為整數。

引數
  • input (Tensor) – 要新增的張量

  • tensor1 (Tensor) – 被除數張量

  • tensor2 (Tensor) – 除數張量

關鍵字引數
  • value (Number, optional) – tensor1/tensor2\text{tensor1} / \text{tensor2} 的乘數

  • out (Tensor, optional) – 輸出張量。

示例

>>> 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]])