Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shape to BatchedTensor #237

Merged
merged 1 commit into from
May 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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