TensorDictBase.addcdiv#
- TensorDictBase.addcdiv(other1: TensorDictBase | Tensor, other2: TensorDictBase | Tensor, value: float | None = 1) Self#
Returns a new tensordict with
value * other1 / other2added to every leaf.\[\text{out}_i = \text{input}_i + \text{value} \times \frac{\text{other1}_i}{\text{other2}_i}\]- Parameters:
other1 (TensorDictBase or Tensor) – the numerator. A tensordict is paired with the tensordict key by key and must have all its keys. A tensor is aligned with the batch dimensions of each leaf and expanded over its feature dimensions.
other2 (TensorDictBase or Tensor) – the denominator, paired like
other1. One ofother1andother2can be a tensordict and the other a tensor.value (Number, optional) – the multiplier for \(\text{other1} / \text{other2}\). Defaults to
1.
Examples
>>> import torch >>> from tensordict import TensorDict >>> td = TensorDict(x=torch.ones(2), batch_size=[2]) >>> td.addcdiv(torch.tensor([1.0, 2.0]), torch.tensor([2.0, 2.0]), value=2)["x"] tensor([2., 3.])
Every tensordict class and every tensorclass has this method. For the other methods, see Methods by task.