Skip to main content

No project description provided

Project description

torchstruct

Wrap your multiple torch.Tensors into single TensorStruct and use it like you are using torch.Tensor.

Installation

pip install torchstruct

Testing

PYTHONPATH=. pytest

Examples

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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for torchstruct, version 0.1.6
Filename, size File type Python version Upload date Hashes
Filename, size torchstruct-0.1.6-py3-none-any.whl (4.9 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size torchstruct-0.1.6.tar.gz (5.8 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page