mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-09 03:55:04 -05:00
docs: start updating docs to reflect the rewrite
This commit is contained in:
@@ -115,17 +115,17 @@ return %1
|
||||
Manual exports are mostly used for visualization. Nonetheless, they can be very useful for demonstrations. Here is how to do it:
|
||||
|
||||
```python
|
||||
import concrete.numpy as hnp
|
||||
import concrete.numpy as cnp
|
||||
import numpy as np
|
||||
import pathlib
|
||||
|
||||
artifacts = cnp.CompilationArtifacts("/tmp/custom/export/path")
|
||||
|
||||
@cnp.compiler({"x": "encrypted"}, artifacts=artifacts)
|
||||
def f(x):
|
||||
return 127 - (50 * (np.sin(x) + 1)).astype(np.uint32)
|
||||
|
||||
artifacts = hnp.CompilationArtifacts(pathlib.Path("/tmp/custom/export/path"))
|
||||
|
||||
compiler = hnp.NPFHECompiler(f, {"x": "encrypted"}, compilation_artifacts=artifacts)
|
||||
compiler.compile_on_inputset(range(2 ** 3))
|
||||
f.compile(range(2 ** 3))
|
||||
|
||||
artifacts.export()
|
||||
```
|
||||
|
||||
@@ -9,16 +9,15 @@ Here are some examples of constant indexing:
|
||||
### Extracting a single element
|
||||
|
||||
```python
|
||||
import concrete.numpy as hnp
|
||||
import concrete.numpy as cnp
|
||||
import numpy as np
|
||||
|
||||
@cnp.compiler({"x": "encrypted"})
|
||||
def f(x):
|
||||
return x[1]
|
||||
|
||||
inputset = [np.random.randint(0, 2 ** 3, size=(3,), dtype=np.uint8) for _ in range(10)]
|
||||
|
||||
compiler = hnp.NPFHECompiler(f, {"x": "encrypted"})
|
||||
circuit = compiler.compile_on_inputset(inputset)
|
||||
circuit = f.compile(inputset)
|
||||
|
||||
test_input = np.array([4, 2, 6], dtype=np.uint8)
|
||||
expected_output = 2
|
||||
@@ -29,16 +28,15 @@ assert np.array_equal(circuit.encrypt_run_decrypt(test_input), expected_output)
|
||||
You can use negative indexing.
|
||||
|
||||
```python
|
||||
import concrete.numpy as hnp
|
||||
import concrete.numpy as cnp
|
||||
import numpy as np
|
||||
|
||||
@cnp.compiler({"x": "encrypted"})
|
||||
def f(x):
|
||||
return x[-1]
|
||||
|
||||
inputset = [np.random.randint(0, 2 ** 3, size=(3,), dtype=np.uint8) for _ in range(10)]
|
||||
|
||||
compiler = hnp.NPFHECompiler(f, {"x": "encrypted"})
|
||||
circuit = compiler.compile_on_inputset(inputset)
|
||||
circuit = f.compile(inputset)
|
||||
|
||||
test_input = np.array([4, 2, 6], dtype=np.uint8)
|
||||
expected_output = 6
|
||||
@@ -49,16 +47,15 @@ assert np.array_equal(circuit.encrypt_run_decrypt(test_input), expected_output)
|
||||
You can use multidimensional indexing as well.
|
||||
|
||||
```python
|
||||
import concrete.numpy as hnp
|
||||
import concrete.numpy as cnp
|
||||
import numpy as np
|
||||
|
||||
@cnp.compiler({"x": "encrypted"})
|
||||
def f(x):
|
||||
return x[-1, 1]
|
||||
|
||||
inputset = [np.random.randint(0, 2 ** 3, size=(3, 2), dtype=np.uint8) for _ in range(10)]
|
||||
|
||||
compiler = hnp.NPFHECompiler(f, {"x": "encrypted"})
|
||||
circuit = compiler.compile_on_inputset(inputset)
|
||||
circuit = f.compile(inputset)
|
||||
|
||||
test_input = np.array([[4, 2], [1, 5], [7, 6]], dtype=np.uint8)
|
||||
expected_output = 6
|
||||
@@ -69,16 +66,15 @@ assert np.array_equal(circuit.encrypt_run_decrypt(test_input), expected_output)
|
||||
### Extracting a slice
|
||||
|
||||
```python
|
||||
import concrete.numpy as hnp
|
||||
import concrete.numpy as cnp
|
||||
import numpy as np
|
||||
|
||||
@cnp.compiler({"x": "encrypted"})
|
||||
def f(x):
|
||||
return x[1:4]
|
||||
|
||||
inputset = [np.random.randint(0, 2 ** 3, size=(5,), dtype=np.uint8) for _ in range(10)]
|
||||
|
||||
compiler = hnp.NPFHECompiler(f, {"x": "encrypted"})
|
||||
circuit = compiler.compile_on_inputset(inputset)
|
||||
circuit = f.compile(inputset)
|
||||
|
||||
test_input = np.array([4, 2, 6, 1, 7], dtype=np.uint8)
|
||||
expected_output = np.array([2, 6, 1], dtype=np.uint8)
|
||||
|
||||
@@ -7,9 +7,9 @@ In this tutorial, we are going to go over the ways to perform direct table looku
|
||||
**Concrete Numpy** provides a special class to allow direct table lookups. Here is how to use it:
|
||||
|
||||
```python
|
||||
import concrete.numpy as hnp
|
||||
import concrete.numpy as cnp
|
||||
|
||||
table = hnp.LookupTable([2, 1, 3, 0])
|
||||
table = cnp.LookupTable([2, 1, 3, 0])
|
||||
|
||||
def f(x):
|
||||
return table[x]
|
||||
@@ -47,12 +47,12 @@ Sometimes you may want to apply a different lookup table to each value in a tens
|
||||
|
||||
<!--pytest-codeblocks:skip-->
|
||||
```python
|
||||
import concrete.numpy as hnp
|
||||
import concrete.numpy as cnp
|
||||
|
||||
squared = hnp.LookupTable([i ** 2 for i in range(4)])
|
||||
cubed = hnp.LookupTable([i ** 3 for i in range(4)])
|
||||
squared = cnp.LookupTable([i ** 2 for i in range(4)])
|
||||
cubed = cnp.LookupTable([i ** 3 for i in range(4)])
|
||||
|
||||
table = hnp.MultiLookupTable([
|
||||
table = cnp.MultiLookupTable([
|
||||
[squared, cubed],
|
||||
[squared, cubed],
|
||||
[squared, cubed],
|
||||
@@ -118,7 +118,7 @@ Internally, it uses the following lookup table
|
||||
|
||||
<!--pytest-codeblocks:skip-->
|
||||
```python
|
||||
table = hnp.LookupTable([50, 92, 95, 57, 12, 2, 36, 82])
|
||||
table = cnp.LookupTable([50, 92, 95, 57, 12, 2, 36, 82])
|
||||
```
|
||||
|
||||
which is calculated by:
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import concrete.numpy as hnp\n",
|
||||
"import concrete.numpy as cnp\n",
|
||||
"import inspect\n",
|
||||
"import numpy as np"
|
||||
]
|
||||
@@ -535,8 +535,8 @@
|
||||
],
|
||||
"source": [
|
||||
"for operation in supported_operations:\n",
|
||||
" compiler = hnp.NPFHECompiler(operation, {\"x\": \"encrypted\"})\n",
|
||||
" circuit = compiler.compile_on_inputset(inputset)\n",
|
||||
" compiler = cnp.Compiler(operation, {\"x\": \"encrypted\"})\n",
|
||||
" circuit = compiler.compile(inputset)\n",
|
||||
" \n",
|
||||
" # We setup an example tensor that will be encrypted and passed on to the current operation\n",
|
||||
" sample = np.random.randint(3, 11, size=(3, 2), dtype=np.uint8)\n",
|
||||
|
||||
@@ -3,17 +3,16 @@
|
||||
## An example
|
||||
|
||||
```python
|
||||
import concrete.numpy as cnp
|
||||
import numpy as np
|
||||
import concrete.numpy as hnp
|
||||
|
||||
# Function using floating points values converted back to integers at the end
|
||||
@cnp.compiler({"x": "encrypted"})
|
||||
def f(x):
|
||||
return np.fabs(50 * (2 * np.sin(x) * np.cos(x))).astype(np.uint32)
|
||||
# astype is to go back to the integer world
|
||||
|
||||
# Compiling with x encrypted
|
||||
compiler = hnp.NPFHECompiler(f, {"x": "encrypted"})
|
||||
circuit = compiler.compile_on_inputset(range(64))
|
||||
circuit = f.compile(range(64))
|
||||
|
||||
print(circuit.encrypt_run_decrypt(3) == f(3))
|
||||
print(circuit.encrypt_run_decrypt(0) == f(0))
|
||||
|
||||
Reference in New Issue
Block a user