Skip to content

Commit

Permalink
Add shape to BatchedTensor (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
durandtibo committed May 14, 2023
1 parent 07533eb commit 12f78dd
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "redcat"
version = "0.0.1a193"
version = "0.0.1a194"
description = "A library to manipulate batches of examples"
readme = "README.md"
authors = ["Thibaut Durand <durand.tibo+gh@gmail.com>"]
Expand Down
5 changes: 5 additions & 0 deletions src/redcat/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ def device(self) -> torch.device:
r"""``torch.device``: The device where the batch data/tensor is."""
return self._data.device

@property
def shape(self) -> torch.Size:
r"""``torch.Size``: The shape of the tensor."""
return self._data.shape

def dim(self) -> int:
r"""Gets the number of dimensions.
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/test_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ def test_batched_tensor_device(device: str) -> None:
assert BatchedTensor(torch.ones(2, 3, device=device)).device == device


def test_batched_tensor_shape() -> None:
assert BatchedTensor(torch.ones(2, 3)).shape == torch.Size([2, 3])


def test_batched_tensor_dim() -> None:
assert BatchedTensor(torch.ones(2, 3)).dim() == 2

Expand Down
4 changes: 4 additions & 0 deletions tests/unit/test_tensorseq.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ def test_batched_tensor_seq_device(device: str) -> None:
assert BatchedTensorSeq(torch.ones(2, 3, device=device)).device == device


def test_batched_tensor_seq_shape() -> None:
assert BatchedTensorSeq(torch.ones(2, 3)).shape == torch.Size([2, 3])


def test_batched_tensor_seq_dim() -> None:
assert BatchedTensorSeq(torch.ones(2, 3)).dim() == 2

Expand Down

0 comments on commit 12f78dd

Please sign in to comment.