From f5842fb7ad4b144184bff53baaf68691f253cbbd Mon Sep 17 00:00:00 2001 From: Umut Date: Tue, 19 Jul 2022 13:22:05 +0200 Subject: [PATCH] test: iteration of tracers --- tests/execution/test_iter.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/execution/test_iter.py diff --git a/tests/execution/test_iter.py b/tests/execution/test_iter.py new file mode 100644 index 000000000..a3345a103 --- /dev/null +++ b/tests/execution/test_iter.py @@ -0,0 +1,30 @@ +""" +Tests of execution of iteration of tracer. +""" + +import numpy as np +import pytest + +import concrete.numpy as cnp + + +@pytest.mark.parametrize("shape", [(3,), (3, 2), (3, 2, 4)]) +def test_iter(shape, helpers): + """ + Test iteration of tracers. + """ + + def function(x): + result = cnp.zeros(x.shape[1:]) + for value in x: + result += value + return result + + configuration = helpers.configuration() + compiler = cnp.Compiler(function, {"x": "encrypted"}) + + inputset = [np.random.randint(0, 2**2, size=shape) for _ in range(100)] + circuit = compiler.compile(inputset, configuration) + + sample = np.random.randint(0, 2**2, size=shape) + helpers.check_execution(circuit, function, sample)