Skip to content

Conversation

vmoens
Copy link
Collaborator

@vmoens vmoens commented Jul 7, 2022

Allows for TensorDict creation like this

>>> td = TensorDict({}, batch_size=[100])
>>> 
>>> for i in range(100):
>>>     td[i] = TensorDict({"a": torch.randn(10), "b": torch.zeros(1)}, [])
>>> 
>>> print(td)
TensorDict(
    fields={
        a: Tensor(torch.Size([100, 10]), dtype=torch.float32),
        b: Tensor(torch.Size([100, 1]), dtype=torch.float32)},
    batch_size=torch.Size([100]),
    device=cpu,
    is_shared=False)

The tensordict is populated with zero-valued key-value pairs when first initialized, hence creating an empty tensor that is to be populated.

cc @BoboBananas

@vmoens vmoens added bug Something isn't working enhancement New feature or request labels Jul 7, 2022
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 7, 2022
@vmoens vmoens merged commit 3122602 into main Jul 7, 2022
@vmoens vmoens deleted the implicit_td_creation branch July 7, 2022 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants