From b63150220e1a883749da62641637b0f8aabbc856 Mon Sep 17 00:00:00 2001 From: Umut Date: Mon, 2 May 2022 09:37:42 +0200 Subject: [PATCH] docs: add what happens on out of bounds during table lookups, show lookup table with negative values --- docs/user/tutorial/table_lookup.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/user/tutorial/table_lookup.md b/docs/user/tutorial/table_lookup.md index 3ca354428..c40a8c6e7 100644 --- a/docs/user/tutorial/table_lookup.md +++ b/docs/user/tutorial/table_lookup.md @@ -9,7 +9,7 @@ In this tutorial, we are going to go over the ways to perform direct table looku ```python import concrete.numpy as cnp -table = cnp.LookupTable([2, 1, 3, 0]) +table = cnp.LookupTable([2, -1, 3, 0]) def f(x): return table[x] @@ -24,7 +24,7 @@ results in ```python circuit.encrypt_run_decrypt(0) == 2 -circuit.encrypt_run_decrypt(1) == 1 +circuit.encrypt_run_decrypt(1) == -1 circuit.encrypt_run_decrypt(2) == 3 circuit.encrypt_run_decrypt(3) == 0 ``` @@ -68,7 +68,13 @@ circuit.encrypt_run_decrypt(3) == 1 circuit.encrypt_run_decrypt(4) == 2 ``` -Lastly, a `LookupTable` can have any number of elements, let's call it **N**, as long as the lookup variable is in range [-**N**, **N**). Note that, number of elements in the lookup table doesn't affect the performance in any way. +Lastly, a `LookupTable` can have any number of elements, let's call it **N**, as long as the lookup variable is in range [-**N**, **N**). If you go out of bounds of this range, you will get the following error: + +``` +IndexError: index 10 is out of bounds for axis 0 with size 6 +``` + +Note that, number of elements in the lookup table doesn't affect the performance in any way. ## Direct multi table lookup