feat: implement transpose

This commit is contained in:
Umut
2022-04-04 14:13:03 +02:00
parent 79685ed7dc
commit ba33d42762
8 changed files with 126 additions and 3 deletions

View File

@@ -0,0 +1,48 @@
"""
Tests of execution of transpose operation.
"""
import numpy as np
import pytest
import concrete.numpy as cnp
@pytest.mark.parametrize(
"function,parameters",
[
pytest.param(
lambda x: np.transpose(x),
{
"x": {"shape": (3, 2), "range": [0, 10], "status": "encrypted"},
},
),
pytest.param(
lambda x: x.transpose(),
{
"x": {"shape": (3, 2), "range": [0, 10], "status": "encrypted"},
},
),
pytest.param(
lambda x: x.T,
{
"x": {"shape": (3, 2), "range": [0, 10], "status": "encrypted"},
},
),
],
)
def test_transpose(function, parameters, helpers):
"""
Test transpose.
"""
parameter_encryption_statuses = helpers.generate_encryption_statuses(parameters)
configuration = helpers.configuration()
compiler = cnp.Compiler(function, parameter_encryption_statuses, configuration)
inputset = helpers.generate_inputset(parameters)
circuit = compiler.compile(inputset)
sample = helpers.generate_sample(parameters)
helpers.check_execution(circuit, function, sample)

View File

@@ -309,6 +309,22 @@ Function you are trying to compile cannot be converted to MLIR:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ only up to 8-bit integers are supported
return %2
""", # noqa: E501
),
pytest.param(
lambda x: np.transpose(x),
{"x": "clear"},
[np.random.randint(0, 2, size=(3, 2)) for _ in range(100)],
RuntimeError,
"""
Function you are trying to compile cannot be converted to MLIR
%0 = x # ClearTensor<uint1, shape=(3, 2)>
%1 = transpose(%0) # ClearTensor<uint1, shape=(2, 3)>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ only encrypted transpose is supported
return %1
""", # noqa: E501
),
],

View File

@@ -25,6 +25,18 @@ from concrete.numpy.values import EncryptedTensor
RuntimeError,
"Function 'np.sum' is not supported with kwarg 'initial'",
),
pytest.param(
lambda x: np.transpose(x, (1, 0, 2)),
{"x": EncryptedTensor(UnsignedInteger(7), shape=(1, 2, 3))},
RuntimeError,
"Function 'np.transpose' is not supported with kwarg 'axes'",
),
pytest.param(
lambda x: x.transpose((1, 0, 2)),
{"x": EncryptedTensor(UnsignedInteger(7), shape=(1, 2, 3))},
RuntimeError,
"Function 'np.transpose' is not supported with kwarg 'axes'",
),
pytest.param(
lambda x: np.multiply.outer(x, [1, 2, 3]),
{"x": EncryptedTensor(UnsignedInteger(7), shape=(4,))},