Skip to content

Commit

Permalink
add tests for different failure modes
Browse files Browse the repository at this point in the history
  • Loading branch information
arogozhnikov committed Jan 11, 2025
1 parent 051f67a commit 6bac534
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion einops/tests/test_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy
import pytest

from einops import rearrange, reduce
from einops import rearrange, reduce, EinopsError
from einops.tests import collect_test_backends, is_backend_tested, FLOAT_REDUCTIONS as REDUCTIONS

__author__ = "Alex Rogozhnikov"
Expand Down Expand Up @@ -433,3 +433,37 @@ def test_einmix_decomposition():
assert mixin7.einsum_pattern == "a...bc,cdb->a...db"
assert mixin7.saved_weight_shape == [3, 4, 2]
assert mixin7.saved_bias_shape == [1, 4, 2] # (a) d b, ellipsis does not participate


def test_einmix_restrictions():
"""
Testing different cases
"""
from einops.layers._einmix import _EinmixDebugger

with pytest.raises(EinopsError):
_EinmixDebugger(
"a b c d e -> e d c b a",
weight_shape="d a b",
d=2, a=3, # missing b
) # fmt: off

with pytest.raises(EinopsError):
_EinmixDebugger(
"a b c d e -> e d c b a",
weight_shape="w a b",
d=2, a=3, b=1 # missing d
) # fmt: off

with pytest.raises(EinopsError):
_EinmixDebugger(
"(...) a -> ... a",
weight_shape="a", a=1, # ellipsis on the left
) # fmt: off

with pytest.raises(EinopsError):
_EinmixDebugger(
"(...) a -> a ...",
weight_shape="a", a=1, # ellipsis on the right side after bias axis
bias_shape='a',
) # fmt: off

0 comments on commit 6bac534

Please sign in to comment.