Files
concrete/compiler/tests/python/test_hlfhe_dialect.py
youben11 47ef595a2a chore: use namespace concrete for the py package
Compiler tools such as CompilerEngine would now be imported from
concrete.compiler
Dialects would now be imported from concrete.lang.dialects
And anything related to concretelang can be imported directly from
concrete.lang
2021-12-29 15:13:34 +01:00

32 lines
1.1 KiB
Python

import pytest
from mlir.ir import Context, RankedTensorType, Location
from concrete.lang import register_dialects
from concrete.lang.dialects import hlfhe
@pytest.mark.parametrize("width", list(range(1, 8)))
def test_eint(width):
ctx = Context()
register_dialects(ctx)
eint = hlfhe.EncryptedIntegerType.get(ctx, width)
assert eint.__str__() == f"!HLFHE.eint<{width}>"
@pytest.mark.parametrize("shape", [(1,), (2,), (1, 1), (1, 2), (2, 1), (3, 3, 3)])
def test_eint_tensor(shape):
with Context() as ctx, Location.unknown(context=ctx):
register_dialects(ctx)
eint = hlfhe.EncryptedIntegerType.get(ctx, 3)
tensor = RankedTensorType.get(shape, eint)
assert (
tensor.__str__() == f"tensor<{'x'.join(map(str, shape))}x!HLFHE.eint<{3}>>"
)
@pytest.mark.parametrize("width", [0, 8, 10, 12])
def test_invalid_eint(width):
ctx = Context()
register_dialects(ctx)
with pytest.raises(ValueError, match=r"can't create eint with the given width"):
eint = hlfhe.EncryptedIntegerType.get(ctx, width)