+
Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions torchrl/data/tensor_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4665,7 +4665,11 @@ def separates(self, *keys: NestedKey, default: Any = None) -> Composite:
out[key] = result
return out

def set(self, name, spec):
def set(self, name: str, spec: TensorSpec) -> Composite:
"""Sets a spec in the Composite spec."""
if not isinstance(name, str):
self[name] = spec
return self
if self.locked:
raise RuntimeError("Cannot modify a locked Composite.")
if spec is not None and self.device is not None and spec.device != self.device:
Expand Down Expand Up @@ -4698,6 +4702,7 @@ def set(self, name, spec):
f"Composite.shape={self.shape}."
)
self._specs[name] = spec
return self

def __init__(
self, *args, shape: torch.Size = None, device: torch.device = None, **kwargs
Expand Down Expand Up @@ -5733,9 +5738,10 @@ def ndim(self):
def ndimension(self):
return len(self.shape)

def set(self, name, spec):
def set(self, name: str, spec: TensorSpec) -> StackedComposite:
for sub_spec, sub_item in zip(self._specs, spec.unbind(self.dim)):
sub_spec[name] = sub_item
return self

@property
def shape(self):
Expand Down
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载