diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f4159d1d6..84e34f7d0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/tensordict/memmap.py b/tensordict/memmap.py index 1ec43595b..3b33c45ed 100644 --- a/tensordict/memmap.py +++ b/tensordict/memmap.py @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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__ diff --git a/tensordict/memmap_deprec.py b/tensordict/memmap_deprec.py index 23bbd1f2b..f44d4037f 100644 --- a/tensordict/memmap_deprec.py +++ b/tensordict/memmap_deprec.py @@ -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