From dcd7a7ac6d190530f1057cca8068871794182135 Mon Sep 17 00:00:00 2001 From: Umut Date: Mon, 18 Apr 2022 10:41:46 +0300 Subject: [PATCH] docs: improve explicit compiler api example in readme --- README.md | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 808daf58d..42102ebf6 100644 --- a/README.md +++ b/README.md @@ -66,19 +66,23 @@ if you have a function object that you cannot decorate, you can use the explicit ```python import concrete.numpy as cnp -def add(x, y): - return x + y +def adder(constant): + def add(x): + return x + constant + return add -compiler = cnp.Compiler(add, {"x": "encrypted", "y": "encrypted"}) -inputset = [(2, 3), (0, 0), (1, 6), (7, 7), (7, 1), (3, 2), (6, 1), (1, 7), (4, 5), (5, 4)] +add_42 = adder(42) + +compiler = cnp.Compiler(add_42, {"x": "encrypted"}) +inputset = range(10) print(f"Compiling...") circuit = compiler.compile(inputset) -examples = [(3, 4), (1, 2), (7, 7), (0, 0)] +examples = [4, 2, 5, 9, 0] for example in examples: - result = circuit.encrypt_run_decrypt(*example) - print(f"Evaluation of {' + '.join(map(str, example))} homomorphically = {result}") + result = circuit.encrypt_run_decrypt(example) + print(f"Evaluation of {example} + 42 homomorphically = {result}") ``` # For developers