Skip to content
Merged
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
41 changes: 36 additions & 5 deletions tests/creation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,43 @@
import torch
from grassmann_tensor import GrassmannTensor

Initialization = tuple[tuple[bool, ...], tuple[tuple[int, int], ...], torch.Tensor]

def test_creation() -> None:
x = GrassmannTensor((False, False), ((2, 2), (1, 3)), torch.randn([4, 4]))

@pytest.mark.parametrize("x", [
((False, False), ((2, 2), (1, 3)), torch.randn([4, 4])),
((True, False), ((2, 2), (3, 1)), torch.randn([4, 4])),
((False, True, False), ((1, 1), (2, 2), (1, 1)), torch.randn([2, 4, 2])),
])
def test_creation_success(x: Initialization) -> None:
GrassmannTensor(*x)


@pytest.mark.parametrize("x", [
((False,), ((2, 2), (1, 3)), torch.randn([4, 4])),
((True, False, True), ((2, 2), (3, 1)), torch.randn([4, 4])),
((False, True), ((1, 1), (2, 2), (1, 1)), torch.randn([2, 4, 2])),
])
def test_creation_invalid_arrow(x: Initialization) -> None:
with pytest.raises(AssertionError):
x = GrassmannTensor((False, False, False), ((2, 2), (1, 3)), torch.randn([4, 4]))
GrassmannTensor(*x)


@pytest.mark.parametrize("x", [
((False, False), ((2, 2),), torch.randn([4, 4])),
((True, False), ((2, 2), (1, 1), (3, 1)), torch.randn([4, 4])),
((False, True, False), ((1, 1), (1, 1)), torch.randn([2, 4, 2])),
])
def test_creation_invalid_edges(x: Initialization) -> None:
with pytest.raises(AssertionError):
x = GrassmannTensor((False, False), ((2, 2), (1, 3), (3, 1)), torch.randn([4, 4]))
GrassmannTensor(*x)


@pytest.mark.parametrize("x", [
((False, False), ((2, 2), (1, 3)), torch.randn([4, 2])),
((True, False), ((2, 2), (3, 1)), torch.randn([2, 4])),
((False, True, False), ((1, 1), (2, 2), (1, 1)), torch.randn([4, 4, 2])),
])
def test_creation_invalid_shape(x: Initialization) -> None:
with pytest.raises(AssertionError):
x = GrassmannTensor((False, False), ((2, 2), (1, 1)), torch.randn([4, 4]))
GrassmannTensor(*x)