docs: add what happens on out of bounds during table lookups, show lookup table with negative values

This commit is contained in:
Umut
2022-05-02 09:37:42 +02:00
parent 14b67702a8
commit b63150220e

View File

@@ -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
<!--pytest-codeblocks:skip-->
```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