diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 92fcf5a4..dc3414cb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -40,6 +40,17 @@ repos: hooks: - id: python-check-blanket-noqa - id: python-use-type-annotations + - repo: https://github.com/psf/black + rev: 23.3.0 + hooks: + - id: black + language_version: python3.10 + - repo: https://github.com/adamchainz/blacken-docs + rev: "1.13.0" + hooks: + - id: blacken-docs + additional_dependencies: + - black>=23.3 - repo: https://github.com/charliermarsh/ruff-pre-commit rev: v0.0.270 hooks: diff --git a/poetry.lock b/poetry.lock index b488532a..e490ad19 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1091,4 +1091,4 @@ all = ["polars"] [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "b263fee7e129a0ec0597becc2f34ca0ecd7820d4fb9c04b438292fa2253787f9" +content-hash = "799925190004c1d5bd0aa5b3e7e7ca27cc9b1867f7d00091da398c5b0db714b3" diff --git a/pyproject.toml b/pyproject.toml index b1e3e028..0ab96cf7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,7 +48,7 @@ docformatter = { extras = ["tomli"], version = "^1.7" } pre-commit = "^3.3" pylint = "^2.17" pytest = "^7.3" -pytest-cov = "^4.0" +pytest-cov = "^4.1" pytest-timeout = "^2.1" ruff = "^0.0,>=0.0.270" diff --git a/src/redcat/base.py b/src/redcat/base.py index 2449c804..a99ac2d2 100644 --- a/src/redcat/base.py +++ b/src/redcat/base.py @@ -41,7 +41,7 @@ def clone(self) -> TBatch: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -77,7 +77,7 @@ def allclose( Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -100,7 +100,7 @@ def equal(self, other: Any) -> bool: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -127,7 +127,7 @@ def permute_along_batch(self, permutation: Sequence[int] | Tensor) -> TBatch: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -152,7 +152,7 @@ def permute_along_batch_(self, permutation: Sequence[int] | Tensor) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -179,7 +179,7 @@ def shuffle_along_batch(self, generator: torch.Generator | None = None) -> TBatc Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -203,7 +203,7 @@ def shuffle_along_batch_(self, generator: torch.Generator | None = None) -> None Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -241,7 +241,7 @@ def append(self, other: BaseBatch) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -271,7 +271,7 @@ def chunk_along_batch(self, chunks: int) -> tuple[TBatch, ...]: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -304,14 +304,12 @@ def extend(self, other: Iterable[BaseBatch]) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor >>> batch = BatchedTensor(torch.ones(2, 3)) - >>> batch.extend( - ... [BatchedTensor(torch.zeros(1, 3)), BatchedTensor(torch.full((1, 3), 2.0))] - ... ) + >>> batch.extend([BatchedTensor(torch.zeros(1, 3)), BatchedTensor(torch.full((1, 3), 2.0))]) >>> batch.data tensor([[1., 1., 1.], [1., 1., 1.], @@ -334,7 +332,7 @@ def index_select_along_batch(self, index: Tensor | Sequence[int]) -> BaseBatch: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -363,7 +361,7 @@ def select_along_batch(self, index: int) -> T: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -389,7 +387,7 @@ def slice_along_batch(self, start: int = 0, stop: int | None = None, step: int = Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -421,7 +419,7 @@ def split_along_batch(self, split_size_or_sections: int | Sequence[int]) -> tupl Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -450,7 +448,7 @@ def get_num_minibatches(self, batch_size: int, drop_last: bool = False) -> int: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -490,7 +488,7 @@ def to_minibatches( Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor diff --git a/src/redcat/batchdict.py b/src/redcat/batchdict.py index 6a99c23c..a7479a2b 100644 --- a/src/redcat/batchdict.py +++ b/src/redcat/batchdict.py @@ -139,7 +139,7 @@ def permute_along_seq(self, permutation: Sequence[int] | Tensor) -> TBatchDict: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchDict, BatchList, BatchedTensorSeq @@ -181,7 +181,7 @@ def permute_along_seq_(self, permutation: Sequence[int] | Tensor) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchDict, BatchList, BatchedTensorSeq @@ -222,7 +222,7 @@ def shuffle_along_seq(self, generator: torch.Generator | None = None) -> TBatchD Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchDict, BatchList, BatchedTensorSeq @@ -264,7 +264,7 @@ def shuffle_along_seq_(self, generator: torch.Generator | None = None) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchDict, BatchList, BatchedTensorSeq @@ -324,7 +324,7 @@ def cat_along_seq(self, batches: BatchDict | Sequence[BatchDict]) -> TBatchDict: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchDict, BatchList, BatchedTensorSeq @@ -335,9 +335,7 @@ def cat_along_seq(self, batches: BatchDict | Sequence[BatchDict]) -> TBatchDict: ... } ... ) >>> b.cat_along_seq( - ... BatchDict( - ... {"key1": BatchedTensorSeq(torch.tensor([[10, 11, 12], [20, 21, 22]]))} - ... ) + ... BatchDict({"key1": BatchedTensorSeq(torch.tensor([[10, 11, 12], [20, 21, 22]]))}) ... ) BatchDict( (key1) tensor([[ 0, 1, 2, 3, 4, 10, 11, 12], @@ -366,7 +364,7 @@ def cat_along_seq_(self, batches: BatchDict | Sequence[BatchDict]) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchDict, BatchList, BatchedTensorSeq @@ -377,9 +375,7 @@ def cat_along_seq_(self, batches: BatchDict | Sequence[BatchDict]) -> None: ... } ... ) >>> b.cat_along_seq_( - ... BatchDict( - ... {"key1": BatchedTensorSeq(torch.tensor([[10, 11, 12], [20, 21, 22]]))} - ... ) + ... BatchDict({"key1": BatchedTensorSeq(torch.tensor([[10, 11, 12], [20, 21, 22]]))}) ... ) >>> b BatchDict( diff --git a/src/redcat/batchlist.py b/src/redcat/batchlist.py index d95c0d49..b9fc6ce7 100644 --- a/src/redcat/batchlist.py +++ b/src/redcat/batchlist.py @@ -160,7 +160,7 @@ def apply(self, fn: Callable[[T], T]) -> TBatchList: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchList @@ -183,7 +183,7 @@ def apply_(self, fn: Callable[[T], T]) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchList diff --git a/src/redcat/datapipes/iter/batching.py b/src/redcat/datapipes/iter/batching.py index 1912e6e2..4a23951f 100644 --- a/src/redcat/datapipes/iter/batching.py +++ b/src/redcat/datapipes/iter/batching.py @@ -35,7 +35,7 @@ class MiniBatcherIterDataPipe(IterDataPipe[BaseBatch[T]]): Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from torch.utils.data.datapipes.iter import IterableWrapper diff --git a/src/redcat/datapipes/iter/joining.py b/src/redcat/datapipes/iter/joining.py index 190924f6..295574a5 100644 --- a/src/redcat/datapipes/iter/joining.py +++ b/src/redcat/datapipes/iter/joining.py @@ -31,7 +31,7 @@ class BatchExtenderIterDataPipe(IterDataPipe[BaseBatch[T]]): Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from torch.utils.data.datapipes.iter import IterableWrapper diff --git a/src/redcat/datapipes/iter/shuffling.py b/src/redcat/datapipes/iter/shuffling.py index ff6c6982..487a64fb 100644 --- a/src/redcat/datapipes/iter/shuffling.py +++ b/src/redcat/datapipes/iter/shuffling.py @@ -26,7 +26,7 @@ class BatchShufflerIterDataPipe(IterDataPipe[BaseBatch[T]]): Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from torch.utils.data.datapipes.iter import IterableWrapper diff --git a/src/redcat/tensor.py b/src/redcat/tensor.py index f9ecf6ab..f2724ebb 100644 --- a/src/redcat/tensor.py +++ b/src/redcat/tensor.py @@ -95,7 +95,7 @@ def dim(self) -> int: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -112,7 +112,7 @@ def ndimension(self) -> int: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -129,7 +129,7 @@ def numel(self) -> int: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -158,7 +158,7 @@ def contiguous( Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -183,7 +183,7 @@ def is_contiguous(self, memory_format: torch.memory_format = torch.contiguous_fo Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -205,12 +205,12 @@ def to(self, *args, **kwargs) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor >>> batch = BatchedTensor(torch.ones(2, 3)) - >>> batch_cuda = batch.to(device=torch.device('cuda:0')) + >>> batch_cuda = batch.to(device=torch.device("cuda:0")) >>> batch_bool = batch.to(dtype=torch.bool) >>> batch_bool tensor([[True, True, True], @@ -234,7 +234,7 @@ def clone(self, *args, **kwargs) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -261,7 +261,7 @@ def empty_like(self, *args, **kwargs) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -287,7 +287,7 @@ def full_like(self, *args, **kwargs) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -324,7 +324,7 @@ def new_full( Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -370,7 +370,7 @@ def new_ones( Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -416,7 +416,7 @@ def new_zeros( Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -454,7 +454,7 @@ def ones_like(self, *args, **kwargs) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -481,7 +481,7 @@ def zeros_like(self, *args, **kwargs) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -534,7 +534,7 @@ def eq(self, other: BatchedTensor | Tensor | bool | int | float) -> TBatchedTens Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -572,7 +572,7 @@ def ge(self, other: BatchedTensor | Tensor | bool | int | float) -> TBatchedTens Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -602,7 +602,7 @@ def gt(self, other: BatchedTensor | Tensor | bool | int | float) -> TBatchedTens Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -631,12 +631,12 @@ def isinf(self) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor >>> batch = BatchedTensor( - ... torch.tensor([[1.0, 0.0, float('inf')], [-1.0, -2.0, float('-inf')]]) + ... torch.tensor([[1.0, 0.0, float("inf")], [-1.0, -2.0, float("-inf")]]) ... ) >>> batch.isinf() tensor([[False, False, True], @@ -655,12 +655,12 @@ def isneginf(self) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor >>> batch = BatchedTensor( - ... torch.tensor([[1.0, 0.0, float('inf')], [-1.0, -2.0, float('-inf')]]) + ... torch.tensor([[1.0, 0.0, float("inf")], [-1.0, -2.0, float("-inf")]]) ... ) >>> batch.isneginf() tensor([[False, False, False], @@ -679,12 +679,12 @@ def isposinf(self) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor >>> batch = BatchedTensor( - ... torch.tensor([[1.0, 0.0, float('inf')], [-1.0, -2.0, float('-inf')]]) + ... torch.tensor([[1.0, 0.0, float("inf")], [-1.0, -2.0, float("-inf")]]) ... ) >>> batch.isposinf() tensor([[False, False, True], @@ -702,12 +702,12 @@ def isnan(self) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor >>> batch = BatchedTensor( - ... torch.tensor([[1.0, 0.0, float('nan')], [float('nan'), -2.0, -1.0]]) + ... torch.tensor([[1.0, 0.0, float("nan")], [float("nan"), -2.0, -1.0]]) ... ) >>> batch.isnan() tensor([[False, False, True], @@ -727,7 +727,7 @@ def le(self, other: BatchedTensor | Tensor | bool | int | float) -> TBatchedTens Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -757,7 +757,7 @@ def lt(self, other: BatchedTensor | Tensor | bool | int | float) -> TBatchedTens Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -792,7 +792,7 @@ def bool(self) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -810,7 +810,7 @@ def double(self) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -828,7 +828,7 @@ def float(self) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -846,7 +846,7 @@ def int(self) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -864,7 +864,7 @@ def long(self) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -932,7 +932,7 @@ def add( Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -966,7 +966,7 @@ def add_( Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -1005,7 +1005,7 @@ def div( Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -1042,7 +1042,7 @@ def div_( Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -1073,7 +1073,7 @@ def fmod( Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -1099,7 +1099,7 @@ def fmod_(self, divisor: BatchedTensor | Tensor | int | float) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -1127,7 +1127,7 @@ def mul(self, other: BatchedTensor | Tensor | int | float) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -1157,7 +1157,7 @@ def mul_(self, other: BatchedTensor | Tensor | int | float) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -1179,7 +1179,7 @@ def neg(self) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -1216,7 +1216,7 @@ def sub( Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -1249,7 +1249,7 @@ def sub_( Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -1280,7 +1280,7 @@ def cumsum(self, dim: int, **kwargs) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -1300,7 +1300,7 @@ def cumsum_(self, dim: int, **kwargs) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -1325,7 +1325,7 @@ def cumsum_along_batch(self, **kwargs) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -1341,7 +1341,7 @@ def cumsum_along_batch_(self) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -1368,7 +1368,7 @@ def logcumsumexp(self, dim: int) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -1388,7 +1388,7 @@ def logcumsumexp_(self, dim: int) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -1412,7 +1412,7 @@ def logcumsumexp_along_batch(self) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -1432,7 +1432,7 @@ def logcumsumexp_along_batch_(self) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -1469,7 +1469,7 @@ def permute_along_dim(self, permutation: Sequence[int] | Tensor, dim: int) -> TB Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -1499,7 +1499,7 @@ def permute_along_dim_(self, permutation: Sequence[int] | Tensor, dim: int) -> N Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -1532,7 +1532,7 @@ def shuffle_along_dim( Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -1561,7 +1561,7 @@ def shuffle_along_dim_(self, dim: int, generator: torch.Generator | None = None) Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -1603,7 +1603,7 @@ def sort( Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -1642,7 +1642,7 @@ def sort_along_batch( Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -1668,7 +1668,7 @@ def abs(self) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -1686,7 +1686,7 @@ def abs_(self) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -1720,7 +1720,7 @@ def clamp( Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -1759,7 +1759,7 @@ def clamp_( Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -1790,7 +1790,7 @@ def exp(self) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -1808,7 +1808,7 @@ def exp_(self) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -1829,7 +1829,7 @@ def log(self) -> BatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -1849,7 +1849,7 @@ def log_(self) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -1872,11 +1872,13 @@ def log1p(self) -> BatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor - >>> batch = BatchedTensor(torch.tensor([[0.0, 1.0, 2.0, 3.0, 4.0], [5.0, 6.0, 7.0, 8.0, 9.0]])) + >>> batch = BatchedTensor( + ... torch.tensor([[0.0, 1.0, 2.0, 3.0, 4.0], [5.0, 6.0, 7.0, 8.0, 9.0]]) + ... ) >>> batch.log1p() tensor([[0.0000, 0.6931, 1.0986, 1.3863, 1.6094], [1.7918, 1.9459, 2.0794, 2.1972, 2.3026]], batch_dim=0) @@ -1890,7 +1892,7 @@ def log1p_(self) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -1917,7 +1919,7 @@ def maximum(self, other: BatchedTensor | Tensor) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -1941,7 +1943,7 @@ def minimum(self, other: BatchedTensor | Tensor) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -1967,7 +1969,7 @@ def pow(self, exponent: int | float | BatchedTensor) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -1991,7 +1993,7 @@ def pow_(self, exponent: int | float | BatchedTensor) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -2013,7 +2015,7 @@ def rsqrt(self) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -2030,7 +2032,7 @@ def rsqrt_(self) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -2051,7 +2053,7 @@ def sqrt(self) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -2069,7 +2071,7 @@ def sqrt_(self) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -2098,7 +2100,7 @@ def max(self, *args, **kwargs) -> Tensor | torch.return_types.max: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -2129,19 +2131,17 @@ def max_along_batch(self, keepdim: bool = False) -> torch.return_types.max: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor - >>> BatchedTensor( - ... torch.tensor([[0, 5], [1, 6], [2, 7], [3, 8], [4, 9]]) - ... ).max_along_batch() + >>> BatchedTensor(torch.tensor([[0, 5], [1, 6], [2, 7], [3, 8], [4, 9]])).max_along_batch() torch.return_types.max( values=tensor([4, 9]), indices=tensor([4, 4])) - >>> BatchedTensor( - ... torch.tensor([[0, 5], [1, 6], [2, 7], [3, 8], [4, 9]]) - ... ).max_along_batch(keepdim=True) + >>> BatchedTensor(torch.tensor([[0, 5], [1, 6], [2, 7], [3, 8], [4, 9]])).max_along_batch( + ... keepdim=True + ... ) torch.return_types.max( values=tensor([[4], [9]]), indices=tensor([[4], [4]])) @@ -2160,7 +2160,7 @@ def mean(self, *args, **kwargs) -> Tensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -2187,7 +2187,7 @@ def mean_along_batch(self, keepdim: bool = False) -> Tensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -2214,7 +2214,7 @@ def median(self, *args, **kwargs) -> Tensor | torch.return_types.median: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -2247,7 +2247,7 @@ def median_along_batch(self, keepdim: bool = False) -> torch.return_types.median Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -2273,7 +2273,7 @@ def min(self, *args, **kwargs) -> Tensor | torch.return_types.min: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -2304,19 +2304,17 @@ def min_along_batch(self, keepdim: bool = False) -> torch.return_types.min: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor - >>> BatchedTensor( - ... torch.tensor([[0, 5], [1, 6], [2, 7], [3, 8], [4, 9]]) - ... ).min_along_batch() + >>> BatchedTensor(torch.tensor([[0, 5], [1, 6], [2, 7], [3, 8], [4, 9]])).min_along_batch() torch.return_types.min( values=tensor([0, 5]), indices=tensor([0, 0])) - >>> BatchedTensor( - ... torch.tensor([[0, 5], [1, 6], [2, 7], [3, 8], [4, 9]]) - ... ).min_along_batch(keepdim=True) + >>> BatchedTensor(torch.tensor([[0, 5], [1, 6], [2, 7], [3, 8], [4, 9]])).min_along_batch( + ... keepdim=True + ... ) torch.return_types.min( values=tensor([[0], [5]]), indices=tensor([[0], [0]])) @@ -2335,21 +2333,19 @@ def nanmean(self, *args, **kwargs) -> Tensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor - >>> BatchedTensor( - ... torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, float("nan")]]) - ... ).nanmean() + >>> BatchedTensor(torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, float("nan")]])).nanmean() tensor(4.0) - >>> BatchedTensor( - ... torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, float("nan")]]) - ... ).nanmean(dim=1) + >>> BatchedTensor(torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, float("nan")]])).nanmean( + ... dim=1 + ... ) tensor([2.0, 6.5]) - >>> BatchedTensor( - ... torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, float("nan")]]) - ... ).nanmean(dim=1, keepdim=True) + >>> BatchedTensor(torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, float("nan")]])).nanmean( + ... dim=1, keepdim=True + ... ) tensor([[2.0], [6.5]]) """ return torch.nanmean(self, *args, **kwargs) @@ -2368,16 +2364,16 @@ def nanmean_along_batch(self, keepdim: bool = False) -> Tensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor >>> BatchedTensor( - ... torch.tensor([[0., 5.], [1., 6.], [2., 7.], [3., 8.], [4., float("nan")]]) + ... torch.tensor([[0.0, 5.0], [1.0, 6.0], [2.0, 7.0], [3.0, 8.0], [4.0, float("nan")]]) ... ).nanmean_along_batch() tensor([2.0, 6.5]) >>> BatchedTensor( - ... torch.tensor([[0., 5.], [1., 6.], [2., 7.], [3., 8.], [4., float("nan")]]) + ... torch.tensor([[0.0, 5.0], [1.0, 6.0], [2.0, 7.0], [3.0, 8.0], [4.0, float("nan")]]) ... ).nanmean_along_batch(keepdim=True) tensor([[2.0, 6.5]]) """ @@ -2399,23 +2395,21 @@ def nanmedian(self, *args, **kwargs) -> Tensor | torch.return_types.nanmedian: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor - >>> BatchedTensor( - ... torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, float("nan")]]) - ... ).nanmedian() + >>> BatchedTensor(torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, float("nan")]])).nanmedian() tensor(4.0) - >>> BatchedTensor( - ... torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, float("nan")]]) - ... ).nanmedian(dim=1) + >>> BatchedTensor(torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, float("nan")]])).nanmedian( + ... dim=1 + ... ) torch.return_types.nanmedian( values=tensor([2., 6.]), indices=tensor([2, 1])) - >>> BatchedTensor( - ... torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, float("nan")]]) - ... ).nanmedian(dim=1, keepdim=True) + >>> BatchedTensor(torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, float("nan")]])).nanmedian( + ... dim=1, keepdim=True + ... ) torch.return_types.nanmedian( values=tensor([[2.], [6.]]), indices=tensor([[2], [1]])) @@ -2438,12 +2432,12 @@ def nanmedian_along_batch(self, keepdim: bool = False) -> torch.return_types.nan Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor >>> BatchedTensor( - ... torch.tensor([[0., 5.], [1., 6.], [2., 7.], [3., 8.], [4., float("nan")]]) + ... torch.tensor([[0.0, 5.0], [1.0, 6.0], [2.0, 7.0], [3.0, 8.0], [4.0, float("nan")]]) ... ).nanmedian_along_batch() torch.return_types.nanmedian( values=tensor([2., 6.]), @@ -2463,21 +2457,17 @@ def nansum(self, *args, **kwargs) -> Tensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor - >>> BatchedTensor( - ... torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, float("nan")]]) - ... ).nansum() + >>> BatchedTensor(torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, float("nan")]])).nansum() tensor(36.) - >>> BatchedTensor( - ... torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, float("nan")]]) - ... ).nansum(dim=1) + >>> BatchedTensor(torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, float("nan")]])).nansum(dim=1) tensor([10., 26.]) - >>> BatchedTensor( - ... torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, float("nan")]]) - ... ).nansum(dim=1, keepdim=True) + >>> BatchedTensor(torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, float("nan")]])).nansum( + ... dim=1, keepdim=True + ... ) tensor([[10.], [26.]]) """ return torch.nansum(self, *args, **kwargs) @@ -2496,12 +2486,12 @@ def nansum_along_batch(self, keepdim: bool = False) -> Tensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor >>> BatchedTensor( - ... torch.tensor([[0., 5.], [1., 6.], [2., 7.], [3., 8.], [4., float("nan")]]) + ... torch.tensor([[0.0, 5.0], [1.0, 6.0], [2.0, 7.0], [3.0, 8.0], [4.0, float("nan")]]) ... ).nansum_along_batch() tensor([20., 26.]) """ @@ -2519,21 +2509,17 @@ def prod(self, *args, **kwargs) -> Tensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor - >>> BatchedTensor( - ... torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 1]]) - ... ).prod() + >>> BatchedTensor(torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 1]])).prod() tensor(362880) - >>> BatchedTensor( - ... torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 1]]) - ... ).prod(dim=1) + >>> BatchedTensor(torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 1]])).prod(dim=1) tensor([ 120, 3024]) - >>> BatchedTensor( - ... torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 1]]) - ... ).prod(dim=1, keepdim=True) + >>> BatchedTensor(torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 1]])).prod( + ... dim=1, keepdim=True + ... ) tensor([[ 120], [3024]]) """ return torch.prod(self, *args, **kwargs) @@ -2552,17 +2538,15 @@ def prod_along_batch(self, keepdim: bool = False) -> Tensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor - >>> BatchedTensor( - ... torch.tensor([[1, 6], [2, 7], [3, 8], [4, 9], [5, 1]]) - ... ).prod_along_batch() + >>> BatchedTensor(torch.tensor([[1, 6], [2, 7], [3, 8], [4, 9], [5, 1]])).prod_along_batch() tensor([ 120, 3024]) - >>> BatchedTensor( - ... torch.tensor([[1, 6], [2, 7], [3, 8], [4, 9], [5, 1]]) - ... ).prod_along_batch(keepdim=True) + >>> BatchedTensor(torch.tensor([[1, 6], [2, 7], [3, 8], [4, 9], [5, 1]])).prod_along_batch( + ... keepdim=True + ... ) tensor([[ 120, 3024]]) """ return self.prod(dim=self._batch_dim, keepdim=keepdim) @@ -2579,7 +2563,7 @@ def sum(self, *args, **kwargs) -> Tensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -2606,7 +2590,7 @@ def sum_along_batch(self, keepdim: bool = False) -> Tensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -2628,7 +2612,7 @@ def acos(self) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -2646,7 +2630,7 @@ def acos_(self) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -2668,7 +2652,7 @@ def acosh(self) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -2689,7 +2673,7 @@ def acosh_(self) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -2710,7 +2694,7 @@ def asin(self) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -2728,7 +2712,7 @@ def asin_(self) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -2750,7 +2734,7 @@ def asinh(self) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -2769,7 +2753,7 @@ def asinh_(self) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -2790,7 +2774,7 @@ def atan(self) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -2808,7 +2792,7 @@ def atan_(self) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -2829,7 +2813,7 @@ def atanh(self) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -2847,7 +2831,7 @@ def atanh_(self) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -2868,7 +2852,7 @@ def cos(self) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> import math @@ -2889,7 +2873,7 @@ def cos_(self) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> import math @@ -2913,7 +2897,7 @@ def cosh(self) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -2931,7 +2915,7 @@ def cosh_(self) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -2952,7 +2936,7 @@ def sin(self) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> import math @@ -2973,7 +2957,7 @@ def sin_(self) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> import math @@ -2997,7 +2981,7 @@ def sinh(self) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -3015,7 +2999,7 @@ def sinh_(self) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -3036,17 +3020,14 @@ def tan(self) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> import math >>> from redcat import BatchedTensor >>> batch = BatchedTensor( ... torch.tensor( - ... [ - ... [0.0, 0.25 * math.pi, math.pi], - ... [2 * math.pi, 1.75 * math.pi, -0.25 * math.pi] - ... ] + ... [[0.0, 0.25 * math.pi, math.pi], [2 * math.pi, 1.75 * math.pi, -0.25 * math.pi]] ... ) ... ) >>> batch.tan() @@ -3062,17 +3043,14 @@ def tan_(self) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> import math >>> from redcat import BatchedTensor >>> batch = BatchedTensor( ... torch.tensor( - ... [ - ... [0.0, 0.25 * math.pi, math.pi], - ... [2 * math.pi, 1.75 * math.pi, -0.25 * math.pi] - ... ] + ... [[0.0, 0.25 * math.pi, math.pi], [2 * math.pi, 1.75 * math.pi, -0.25 * math.pi]] ... ) ... ) >>> batch.tan_() @@ -3091,7 +3069,7 @@ def tanh(self) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -3109,7 +3087,7 @@ def tanh_(self) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -3142,7 +3120,7 @@ def logical_and(self, other: BatchedTensor | Tensor) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -3171,7 +3149,7 @@ def logical_and_(self, other: BatchedTensor | Tensor) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -3201,7 +3179,7 @@ def logical_not(self) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -3222,7 +3200,7 @@ def logical_not_(self) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -3252,7 +3230,7 @@ def logical_or(self, other: BatchedTensor | Tensor) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -3280,7 +3258,7 @@ def logical_or_(self, other: BatchedTensor | Tensor) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -3314,7 +3292,7 @@ def logical_xor(self, other: BatchedTensor | Tensor) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -3342,7 +3320,7 @@ def logical_xor_(self, other: BatchedTensor | Tensor) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -3399,7 +3377,7 @@ def cat( Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -3429,14 +3407,12 @@ def cat_( Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor >>> batch = BatchedTensor(torch.tensor([[0, 1, 2], [4, 5, 6]])) - >>> batch.cat_( - ... BatchedTensor(torch.tensor([[10, 11, 12], [13, 14, 15]])) - ... ) + >>> batch.cat_(BatchedTensor(torch.tensor([[10, 11, 12], [13, 14, 15]]))) >>> batch tensor([[ 0, 1, 2], [ 4, 5, 6], @@ -3461,7 +3437,7 @@ def cat_along_batch( Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -3500,14 +3476,12 @@ def cat_along_batch_( Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor >>> batch = BatchedTensor(torch.tensor([[0, 1, 2], [4, 5, 6]])) - >>> batch.cat_along_batch_( - ... BatchedTensor(torch.tensor([[10, 11, 12], [13, 14, 15]])) - ... ) + >>> batch.cat_along_batch_(BatchedTensor(torch.tensor([[10, 11, 12], [13, 14, 15]]))) >>> batch tensor([[ 0, 1, 2], [ 4, 5, 6], @@ -3545,7 +3519,7 @@ def chunk(self, chunks: int, dim: int = 0) -> tuple[TBatchedTensor, ...]: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -3577,7 +3551,7 @@ def index_select(self, dim: int, index: Tensor | Sequence[int]) -> TBatchedTenso Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -3615,7 +3589,7 @@ def masked_fill( Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -3657,7 +3631,7 @@ def select(self, dim: int, index: int) -> Tensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -3699,7 +3673,7 @@ def slice_along_dim( Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -3741,7 +3715,7 @@ def split( Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -3772,7 +3746,7 @@ def take_along_batch( Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -3802,7 +3776,7 @@ def take_along_dim( Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -3834,7 +3808,7 @@ def unsqueeze(self, dim: int) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -3871,7 +3845,7 @@ def view(self, *shape: tuple[int, ...]) -> Tensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -3903,7 +3877,7 @@ def view_as(self, other: BatchedTensor | Tensor) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -3947,7 +3921,7 @@ def apply(self, fn: Callable[[Tensor], Tensor]) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor @@ -3975,7 +3949,7 @@ def apply_(self, fn: Callable[[Tensor], Tensor]) -> TBatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensor diff --git a/src/redcat/tensorseq.py b/src/redcat/tensorseq.py index 5b751cf0..88cd1efc 100644 --- a/src/redcat/tensorseq.py +++ b/src/redcat/tensorseq.py @@ -124,7 +124,7 @@ def new_full( Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensorSeq @@ -179,7 +179,7 @@ def new_ones( Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensorSeq @@ -234,7 +234,7 @@ def new_zeros( Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensorSeq @@ -275,7 +275,7 @@ def from_seq_batch(cls, data: Any, **kwargs) -> BatchedTensorSeq: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensorSeq @@ -360,7 +360,7 @@ def cumsum_along_seq(self, **kwargs) -> BatchedTensorSeq: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensorSeq @@ -377,7 +377,7 @@ def cumsum_along_seq_(self) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensorSeq @@ -401,7 +401,7 @@ def logcumsumexp_along_seq(self) -> BatchedTensorSeq: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensorSeq @@ -418,7 +418,7 @@ def logcumsumexp_along_seq_(self) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensorSeq @@ -444,7 +444,7 @@ def permute_along_seq(self, permutation: Sequence[int] | Tensor) -> BatchedTenso Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensorSeq @@ -466,7 +466,7 @@ def permute_along_seq_(self, permutation: Sequence[int] | Tensor) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensorSeq @@ -491,7 +491,7 @@ def shuffle_along_seq(self, generator: torch.Generator | None = None) -> Batched Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensorSeq @@ -511,7 +511,7 @@ def shuffle_along_seq_(self, generator: torch.Generator | None = None) -> None: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensorSeq @@ -547,7 +547,7 @@ def sort_along_seq( Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensorSeq @@ -602,7 +602,7 @@ def max_along_seq(self, keepdim: bool = False) -> torch.return_types.max: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensorSeq @@ -632,7 +632,7 @@ def mean_along_seq(self, keepdim: bool = False) -> BatchedTensor | BatchedTensor Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensorSeq @@ -659,7 +659,7 @@ def median_along_seq(self, keepdim: bool = False) -> torch.return_types.median: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensorSeq @@ -684,7 +684,7 @@ def min_along_seq(self, keepdim: bool = False) -> torch.return_types.min: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensorSeq @@ -713,7 +713,7 @@ def nanmean_along_seq(self, keepdim: bool = False) -> Tensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensorSeq @@ -744,7 +744,7 @@ def nanmedian_along_seq(self, keepdim: bool = False) -> torch.return_types.nanme Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensorSeq @@ -771,7 +771,7 @@ def nansum_along_seq(self, keepdim: bool = False) -> Tensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensorSeq @@ -796,15 +796,15 @@ def prod_along_seq(self, keepdim: bool = False) -> Tensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensorSeq >>> BatchedTensorSeq(torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 1]])).prod_along_seq() tensor([ 120, 3024]) - >>> BatchedTensorSeq( - ... torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 1]]) - ... ).prod_along_seq(keepdim=True) + >>> BatchedTensorSeq(torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 1]])).prod_along_seq( + ... keepdim=True + ... ) tensor([[ 120], [3024]]) """ return self.prod(dim=self._seq_dim, keepdim=keepdim) @@ -824,7 +824,7 @@ def sum_along_seq(self, keepdim: bool = False) -> Tensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensorSeq @@ -852,7 +852,7 @@ def align_as(self, other: BatchedTensorSeq) -> BatchedTensorSeq: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensorSeq @@ -900,7 +900,7 @@ def align_to_batch_seq(self) -> BatchedTensorSeq: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensorSeq @@ -923,7 +923,7 @@ def align_to_seq_batch(self) -> BatchedTensorSeq: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensorSeq @@ -957,7 +957,7 @@ def cat_along_seq( Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensorSeq @@ -967,7 +967,9 @@ def cat_along_seq( tensor([[ 0, 1, 2, 10, 11], [ 4, 5, 6, 12, 13]], batch_dim=0, seq_dim=1) >>> BatchedTensorSeq( - ... torch.tensor([[0, 4], [1, 5], [2, 6]]), batch_dim=1, seq_dim=0, + ... torch.tensor([[0, 4], [1, 5], [2, 6]]), + ... batch_dim=1, + ... seq_dim=0, ... ).cat_along_seq( ... [ ... BatchedTensorSeq(torch.tensor([[10, 12], [11, 13]]), batch_dim=1, seq_dim=0), @@ -998,19 +1000,19 @@ def cat_along_seq_( Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensorSeq >>> batch = BatchedTensorSeq(torch.tensor([[0, 1, 2], [4, 5, 6]])) - >>> batch.cat_along_seq_( - ... BatchedTensorSeq(torch.tensor([[10, 11], [12, 13]])) - ... ) + >>> batch.cat_along_seq_(BatchedTensorSeq(torch.tensor([[10, 11], [12, 13]]))) >>> batch tensor([[ 0, 1, 2, 10, 11], [ 4, 5, 6, 12, 13]], batch_dim=0, seq_dim=1) >>> batch = BatchedTensorSeq( - ... torch.tensor([[0, 4], [1, 5], [2, 6]]), batch_dim=1, seq_dim=0, + ... torch.tensor([[0, 4], [1, 5], [2, 6]]), + ... batch_dim=1, + ... seq_dim=0, ... ) >>> batch.cat_along_seq( ... [ @@ -1041,7 +1043,7 @@ def chunk_along_seq(self, chunks: int) -> tuple[BatchedTensorSeq, ...]: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensorSeq @@ -1066,7 +1068,7 @@ def index_select_along_seq(self, index: Tensor | Sequence[int]) -> BatchedTensor Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensorSeq @@ -1101,7 +1103,7 @@ def repeat_along_seq(self, repeats: int) -> BatchedTensorSeq: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensorSeq @@ -1126,7 +1128,7 @@ def select_along_seq(self, index: int) -> BatchedTensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensorSeq @@ -1157,7 +1159,7 @@ def slice_along_seq( Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensorSeq @@ -1192,7 +1194,7 @@ def take_along_seq(self, indices: BaseBatch | Tensor | Sequence) -> BatchedTenso Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat import BatchedTensorSeq @@ -1437,7 +1439,7 @@ def from_sequences( Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> import redcat diff --git a/src/redcat/utils/format.py b/src/redcat/utils/format.py index 55771eaa..b388f36c 100644 --- a/src/redcat/utils/format.py +++ b/src/redcat/utils/format.py @@ -23,10 +23,10 @@ def str_mapping(mapping: Mapping, sorted_keys: bool = False, num_spaces: int = 2 Example usage: - .. code-block:: python + .. code-block:: pycon >>> from redcat.utils.format import str_mapping - >>> str_mapping({'key1': 'abc', 'key2': 'something\nelse'}) + >>> str_mapping({"key1": "abc", "key2": "something\nelse"}) (key1) abc (key2) something else diff --git a/src/redcat/utils/tensor.py b/src/redcat/utils/tensor.py index 44628887..e3ce5a34 100644 --- a/src/redcat/utils/tensor.py +++ b/src/redcat/utils/tensor.py @@ -39,7 +39,7 @@ def align_to_batch_first(tensor: Tensor, batch_dim: int) -> Tensor: Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat.utils.tensor import align_to_batch_first @@ -134,7 +134,7 @@ def compute_batch_seq_permutation( Example usage: - .. code-block:: python + .. code-block:: pycon >>> from redcat.utils.tensor import compute_batch_seq_permutation >>> compute_batch_seq_permutation(5, 0, 1, 1, 0) @@ -176,7 +176,7 @@ def get_available_devices() -> tuple[str, ...]: Example usage: - .. code-block:: python + .. code-block:: pycon >>> from redcat.utils.tensor import get_available_devices >>> get_available_devices() @@ -208,7 +208,7 @@ def get_torch_generator( Example usage: - .. code-block:: python + .. code-block:: pycon >>> import torch >>> from redcat.utils.tensor import get_torch_generator @@ -245,7 +245,7 @@ def permute_along_dim(tensor: Tensor, permutation: Tensor, dim: int = 0) -> Tens Example usage: - .. code-block:: python + .. code-block:: pycon >>> from redcat.utils.tensor import permute_along_dim >>> permute_along_dim(tensor=torch.arange(4), permutation=torch.tensor([0, 2, 1, 3])) @@ -309,7 +309,7 @@ def swap2( Example usage: - .. code-block:: python + .. code-block:: pycon >>> from redcat.utils.tensor import swap2 >>> seq = [1, 2, 3, 4, 5]