Skip to content

Commit

Permalink
amend
Browse files Browse the repository at this point in the history
  • Loading branch information
vmoens committed Oct 19, 2023
1 parent 319e1bd commit af7f289
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tensordict/memmap_refact.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,30 @@ def from_handler(cls, handler, dtype, shape, index):
out.parent_shape = shape
return out

def __setstate__(self, state):
if 'filename' in state:
self.__dict__.update(type(self).from_filename(**state).__dict__)
else:
self.__dict__.update(type(self).from_handler(**state).__dict__)

def __getstate__(self):
if getattr(self, "_handler", None) is not None:
return {
'handler': self._handler,
'dtype': self.dtype,
'shape': self.parent_shape,
'index': self.index,
}
elif getattr(self, "_filename", None) is not None:
return {
'filename': self._filename,
'dtype': self.dtype,
'shape': self.parent_shape,
'index': self.index,
}
else:
raise RuntimeError("Could not find handler or filename.")

def __reduce__(self):
if getattr(self, "_handler", None) is not None:
return type(self).from_handler, (
Expand Down

0 comments on commit af7f289

Please sign in to comment.