TensorDictBase.logsumexp#
- TensorDictBase.logsumexp(dim=None, keepdim=False, *, out=None)#
Returns the log of the summed exponentials of every leaf along batch dimensions.
The computation is numerically stable, as with
torch.logsumexp(). Unlikesum(), it never reduces the feature dimensions: withoutdim, it reduces every batch dimension.- Parameters:
- Keyword Arguments:
out (TensorDictBase, optional) – the tensordict to write the result into, which is returned. Defaults to
None, which returns a new tensordict.- Raises:
ValueError – if
dimis not a batch dimension.
Examples
>>> import torch >>> from tensordict import TensorDict >>> td = TensorDict(a=torch.zeros(2, 3), batch_size=[2]) >>> td.logsumexp()["a"] # log(exp(0) + exp(0)) tensor([0.6931, 0.6931, 0.6931])
Every tensordict class and every tensorclass has this method. For the other methods, see Methods by task.