Skip to content

Commit

Permalink
amend
Browse files Browse the repository at this point in the history
  • Loading branch information
vmoens committed Oct 18, 2023
1 parent 1e45b4a commit c8132be
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions tensordict/memmap_refact.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ def from_tensor(
out.copy_(tensor)
return out

@property
def filename(self):
filename = self._filename
if filename is None:
raise RuntimeError("The MemoryMappedTensor has no file associated.")
return filename

@classmethod
def empty_like(cls, tensor, *, filename=None):
return cls.from_tensor(torch.zeros((), dtype=tensor.dtype, device=tensor.device).expand_as(tensor), filename=filename)
Expand Down
2 changes: 1 addition & 1 deletion test/test_tensordict.py
Original file line number Diff line number Diff line change
Expand Up @@ -3038,7 +3038,7 @@ def test_repr_memmap(self, device, dtype):
is_shared_tensor = False
expected = f"""TensorDict(
fields={{
a: MemmapTensor(shape=torch.Size([4, 3, 2, 1, 5]), device={tensor_device}, dtype={dtype}, is_shared={is_shared_tensor})}},
a: MemoryMappedTensor(shape=torch.Size([4, 3, 2, 1, 5]), device={tensor_device}, dtype={dtype}, is_shared={is_shared_tensor})}},
batch_size=torch.Size([4, 3, 2, 1]),
device={str(device)},
is_shared={is_shared})"""
Expand Down

0 comments on commit c8132be

Please sign in to comment.