Table Lookups
In this tutorial, we will review how to perform direct table lookups in Concrete.
Direct table lookup
Concrete provides a LookupTable class to create your own tables and apply them in your circuits.
With scalars.
You can create the lookup table using a list of integers and apply it using indexing:
from concrete import fhe
table = fhe.LookupTable([2, -1, 3, 0])
@fhe.compiler({"x": "encrypted"})
def f(x):
return table[x]
inputset = range(4)
circuit = f.compile(inputset)
assert circuit.encrypt_run_decrypt(0) == table[0] == 2
assert circuit.encrypt_run_decrypt(1) == table[1] == -1
assert circuit.encrypt_run_decrypt(2) == table[2] == 3
assert circuit.encrypt_run_decrypt(3) == table[3] == 0With tensors.
When you apply a table lookup to a tensor, the scalar table lookup is applied to each element of the tensor:
With negative values.
LookupTable mimics array indexing in Python, which means if the lookup variable is negative, the table is looked up from the back:
Direct multi-table lookup
If you want to apply a different lookup table to each element of a tensor, you can have a LookupTable of LookupTables:
In this example, we applied a squared table to the first column and a cubed table to the second column.
Fused table lookup
Concrete tries to fuse some operations into table lookups automatically so that lookup tables don't need to be created manually:
The function is first traced into:

Concrete then fuses appropriate nodes:

Last updated
Was this helpful?