Skip to content

Commit

Permalink
amend
Browse files Browse the repository at this point in the history
  • Loading branch information
vmoens committed Nov 14, 2023
1 parent d7668fa commit 0528111
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ repos:
additional_dependencies:
- flake8-bugbear==22.10.27
- flake8-comprehensions==3.10.1

- torchfix==0.0.2

- repo: https://github.com/PyCQA/pydocstyle
rev: 6.1.1
Expand Down
15 changes: 15 additions & 0 deletions tensordict/memmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ def filename(self):

@classmethod
def empty_like(cls, input, *, filename=None):
# noqa: D417
"""Creates a tensor with no content but the same shape and dtype as the input tensor.
Args:
Expand All @@ -193,6 +194,7 @@ def empty_like(cls, input, *, filename=None):

@classmethod
def full_like(cls, input, fill_value, *, filename=None):
# noqa: D417
"""Creates a tensor with a single content indicated by the `fill_value` argument, but the same shape and dtype as the input tensor.
Args:
Expand All @@ -212,6 +214,7 @@ def full_like(cls, input, fill_value, *, filename=None):

@classmethod
def zeros_like(cls, input, *, filename=None):
# noqa: D417
"""Creates a tensor with a 0-filled content, but the same shape and dtype as the input tensor.
Args:
Expand All @@ -228,6 +231,7 @@ def zeros_like(cls, input, *, filename=None):

@classmethod
def ones_like(cls, input, *, filename=None):
# noqa: D417
"""Creates a tensor with a 1-filled content, but the same shape and dtype as the input tensor.
Args:
Expand All @@ -244,6 +248,7 @@ def ones_like(cls, input, *, filename=None):

@classmethod
def ones(cls, *shape, dtype=None, device=None, filename=None):
# noqa: D417
"""Creates a tensor with a 1-filled content, specific shape, dtype and filename.
Args:
Expand Down Expand Up @@ -274,6 +279,7 @@ def ones(cls, *shape, dtype=None, device=None, filename=None):

@classmethod
def zeros(cls, *shape, dtype=None, device=None, filename=None):
# noqa: D417
"""Creates a tensor with a 0-filled content, specific shape, dtype and filename.
Args:
Expand Down Expand Up @@ -305,6 +311,7 @@ def zeros(cls, *shape, dtype=None, device=None, filename=None):

@classmethod
def empty(cls, *shape, dtype=None, device=None, filename=None):
# noqa: D417
"""Creates a tensor with empty content, specific shape, dtype and filename.
Args:
Expand Down Expand Up @@ -333,6 +340,7 @@ def empty(cls, *shape, dtype=None, device=None, filename=None):

@classmethod
def full(cls, *shape, fill_value, dtype=None, device=None, filename=None):
# noqa: D417
"""Creates a tensor with a single content specified by `fill_value`, specific shape, dtype and filename.
Args:
Expand Down Expand Up @@ -361,6 +369,7 @@ def full(cls, *shape, fill_value, dtype=None, device=None, filename=None):

@classmethod
def from_filename(cls, filename, dtype, shape, index=None):
# noqa: D417
"""Loads a MemoryMappedTensor from a given filename.
Args:
Expand All @@ -386,6 +395,7 @@ def from_filename(cls, filename, dtype, shape, index=None):

@classmethod
def from_handler(cls, handler, dtype, shape, index):
# noqa: D417
"""Loads a MemoryMappedTensor from a given handler.
Args:
Expand All @@ -408,6 +418,11 @@ def from_handler(cls, handler, dtype, shape, index):
out.parent_shape = shape
return out

@property
def _tensor(self):
# for bc-compatibility with MemmapTensor, to be deprecated in v0.4
return self

def __setstate__(self, state):
if "filename" in state:
self.__dict__ = type(self).from_filename(**state).__dict__
Expand Down
3 changes: 2 additions & 1 deletion tensordict/memmap_deprec.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

"""This is a deprecated class and will be removed in v0.4.
Consider using tensordict.MemoryMappedTensor instead."""
Consider using tensordict.MemoryMappedTensor instead.
"""

from __future__ import annotations

Expand Down

0 comments on commit 0528111

Please sign in to comment.