https://github.com/iamhatesz/torchstruct
Combine PyTorch tensors into a single structure.
https://github.com/iamhatesz/torchstruct
pytorch structures tensors
Last synced: 7 months ago
JSON representation
Combine PyTorch tensors into a single structure.
- Host: GitHub
- URL: https://github.com/iamhatesz/torchstruct
- Owner: iamhatesz
- License: mit
- Created: 2019-11-07T18:03:15.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-02T14:54:34.000Z (almost 6 years ago)
- Last Synced: 2025-03-30T03:01:33.690Z (11 months ago)
- Topics: pytorch, structures, tensors
- Language: Python
- Homepage:
- Size: 28.3 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# torchstruct
Wrap your multiple `torch.Tensor`s into single `TensorStruct`
and use it like you are using `torch.Tensor`.
## Installation
```bash
pip install torchstruct
```
## Testing
```bash
PYTHONPATH=. pytest
```
## Examples
```python
import torch
from torchstruct import TensorStruct
# Initialization
ts = TensorStruct.zeros({
'obs': (2,),
'rew': (1,),
'done': (1,)
}, prefix_shape=(10,), dtype=torch.float32, device='cpu')
raw_data = {
'obs': torch.randn((10, 2)),
'rew': torch.randn((10, 1)),
'done': torch.randn((10, 1))
}
# Assigning
ts[:] = raw_data
# Indexing
ts[2:4]
ts['rew']
# Calling PyTorch methods
ts.unsqueeze(dim=0)
ts.sum(dim=0)
```