Math (Special)
make_sin()¶
Create scaled sin for encrypted fixed-point angles.
This cell verifies the make_sin function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import make_sin
import math
fn = make_sin(min_input=-2, max_input=3, angle_unit='degrees')
def test_make_sin_enc(value):
import numpy as np
res = fn(value)
return fhe.array(res) if isinstance(res, list) else res
compiler = fhe.Compiler(test_make_sin_enc, {'value': 'encrypted'})
inputset = [(3,), (-2,), (0,), (2,)]
circuit = compiler.compile(inputset)
_successes = 0
for inp in inputset:
try:
expected = fn(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "make_sin: all inputs were skipped — test is broken"
print(f"make_sin tests passed! ({_successes}/{len(inputset)})")
compile_sin()¶
Compile scaled sin for encrypted fixed-point angles.
This cell verifies the compile_sin function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import compile_sin
import math
from concrete_fhe_toolkit.math.special import make_sin
circuit = compile_sin(min_input=-2, max_input=3, angle_unit='degrees')
inputset = [(3,), (-2,), (0,), (2,)]
_successes = 0
for inp in inputset:
try:
expected = make_sin(min_input=-2, max_input=3, angle_unit='degrees')(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "compile_sin: all inputs were skipped — test is broken"
print(f"compile_sin tests passed! ({_successes}/{len(inputset)})")
make_cos()¶
Create scaled cos for encrypted fixed-point angles.
This cell verifies the make_cos function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import make_cos
import math
fn = make_cos(min_input=-2, max_input=3, angle_unit='degrees')
def test_make_cos_enc(value):
import numpy as np
res = fn(value)
return fhe.array(res) if isinstance(res, list) else res
compiler = fhe.Compiler(test_make_cos_enc, {'value': 'encrypted'})
inputset = [(3,), (-2,), (0,), (2,)]
circuit = compiler.compile(inputset)
_successes = 0
for inp in inputset:
try:
expected = fn(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "make_cos: all inputs were skipped — test is broken"
print(f"make_cos tests passed! ({_successes}/{len(inputset)})")
compile_cos()¶
Compile scaled cos for encrypted fixed-point angles.
This cell verifies the compile_cos function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import compile_cos
import math
from concrete_fhe_toolkit.math.special import make_cos
circuit = compile_cos(min_input=-2, max_input=3, angle_unit='degrees')
inputset = [(3,), (-2,), (0,), (2,)]
_successes = 0
for inp in inputset:
try:
expected = make_cos(min_input=-2, max_input=3, angle_unit='degrees')(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "compile_cos: all inputs were skipped — test is broken"
print(f"compile_cos tests passed! ({_successes}/{len(inputset)})")
make_tan()¶
Create scaled tan for encrypted fixed-point angles.
This cell verifies the make_tan function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import make_tan
import math
fn = make_tan(min_input=-2, max_input=3, angle_unit='degrees')
def test_make_tan_enc(value):
import numpy as np
res = fn(value)
return fhe.array(res) if isinstance(res, list) else res
compiler = fhe.Compiler(test_make_tan_enc, {'value': 'encrypted'})
inputset = [(3,), (-2,), (0,), (2,)]
circuit = compiler.compile(inputset)
_successes = 0
for inp in inputset:
try:
expected = fn(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "make_tan: all inputs were skipped — test is broken"
print(f"make_tan tests passed! ({_successes}/{len(inputset)})")
compile_tan()¶
Compile scaled tan for encrypted fixed-point angles.
This cell verifies the compile_tan function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import compile_tan
import math
from concrete_fhe_toolkit.math.special import make_tan
circuit = compile_tan(min_input=-2, max_input=3, angle_unit='degrees')
inputset = [(3,), (-2,), (0,), (2,)]
_successes = 0
for inp in inputset:
try:
expected = make_tan(min_input=-2, max_input=3, angle_unit='degrees')(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "compile_tan: all inputs were skipped — test is broken"
print(f"compile_tan tests passed! ({_successes}/{len(inputset)})")
make_exp()¶
Create scaled exp for encrypted fixed-point inputs.
This cell verifies the make_exp function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import make_exp
import math
fn = make_exp(min_input=0, max_input=3)
def test_make_exp_enc(value):
import numpy as np
res = fn(value)
return fhe.array(res) if isinstance(res, list) else res
compiler = fhe.Compiler(test_make_exp_enc, {'value': 'encrypted'})
inputset = [(1,), (2,), (3,)]
circuit = compiler.compile(inputset)
_successes = 0
for inp in inputset:
try:
expected = fn(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "make_exp: all inputs were skipped — test is broken"
print(f"make_exp tests passed! ({_successes}/{len(inputset)})")
compile_exp()¶
Compile scaled exp for encrypted fixed-point inputs.
This cell verifies the compile_exp function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import compile_exp
import math
from concrete_fhe_toolkit.math.special import make_exp
circuit = compile_exp(min_input=0, max_input=3)
inputset = [(1,), (2,), (3,)]
_successes = 0
for inp in inputset:
try:
expected = make_exp(min_input=0, max_input=3)(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "compile_exp: all inputs were skipped — test is broken"
print(f"compile_exp tests passed! ({_successes}/{len(inputset)})")
make_expm1()¶
Create scaled expm1 for encrypted fixed-point inputs.
This cell verifies the make_expm1 function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import make_expm1
import math
fn = make_expm1(min_input=0, max_input=3)
def test_make_expm1_enc(value):
import numpy as np
res = fn(value)
return fhe.array(res) if isinstance(res, list) else res
compiler = fhe.Compiler(test_make_expm1_enc, {'value': 'encrypted'})
inputset = [(1,), (2,), (3,)]
circuit = compiler.compile(inputset)
_successes = 0
for inp in inputset:
try:
expected = fn(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "make_expm1: all inputs were skipped — test is broken"
print(f"make_expm1 tests passed! ({_successes}/{len(inputset)})")
compile_expm1()¶
Compile scaled expm1 for encrypted fixed-point inputs.
This cell verifies the compile_expm1 function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import compile_expm1
import math
from concrete_fhe_toolkit.math.special import make_expm1
circuit = compile_expm1(min_input=0, max_input=3)
inputset = [(1,), (2,), (3,)]
_successes = 0
for inp in inputset:
try:
expected = make_expm1(min_input=0, max_input=3)(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "compile_expm1: all inputs were skipped — test is broken"
print(f"compile_expm1 tests passed! ({_successes}/{len(inputset)})")
make_log()¶
Create scaled log (natural by default, or any base); invalid_result handles x <= 0.
This cell verifies the make_log function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import make_log
import math
fn = make_log(min_input=0, max_input=3, invalid_result=7, base=2)
def test_make_log_enc(value):
import numpy as np
res = fn(value)
return fhe.array(res) if isinstance(res, list) else res
compiler = fhe.Compiler(test_make_log_enc, {'value': 'encrypted'})
inputset = [(1,), (2,), (3,)]
circuit = compiler.compile(inputset)
_successes = 0
for inp in inputset:
try:
expected = fn(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "make_log: all inputs were skipped — test is broken"
print(f"make_log tests passed! ({_successes}/{len(inputset)})")
compile_log()¶
Compile scaled log (natural by default, or any base); invalid_result handles x <= 0.
This cell verifies the compile_log function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import compile_log
import math
from concrete_fhe_toolkit.math.special import make_log
circuit = compile_log(min_input=0, max_input=3, invalid_result=7, base=2)
inputset = [(1,), (2,), (3,)]
_successes = 0
for inp in inputset:
try:
expected = make_log(min_input=0, max_input=3, invalid_result=7, base=2)(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "compile_log: all inputs were skipped — test is broken"
print(f"compile_log tests passed! ({_successes}/{len(inputset)})")
make_log2()¶
Create scaled log2; invalid_result handles x <= 0 if needed.
This cell verifies the make_log2 function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import make_log2
import math
fn = make_log2(min_input=0, max_input=3, invalid_result=7)
def test_make_log2_enc(value):
import numpy as np
res = fn(value)
return fhe.array(res) if isinstance(res, list) else res
compiler = fhe.Compiler(test_make_log2_enc, {'value': 'encrypted'})
inputset = [(1,), (2,), (3,)]
circuit = compiler.compile(inputset)
_successes = 0
for inp in inputset:
try:
expected = fn(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "make_log2: all inputs were skipped — test is broken"
print(f"make_log2 tests passed! ({_successes}/{len(inputset)})")
compile_log2()¶
Compile scaled log2; invalid_result handles x <= 0 if needed.
This cell verifies the compile_log2 function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import compile_log2
import math
from concrete_fhe_toolkit.math.special import make_log2
circuit = compile_log2(min_input=0, max_input=3, invalid_result=7)
inputset = [(1,), (2,), (3,)]
_successes = 0
for inp in inputset:
try:
expected = make_log2(min_input=0, max_input=3, invalid_result=7)(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "compile_log2: all inputs were skipped — test is broken"
print(f"compile_log2 tests passed! ({_successes}/{len(inputset)})")
make_log10()¶
Create scaled log10; invalid_result handles x <= 0 if needed.
This cell verifies the make_log10 function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import make_log10
import math
fn = make_log10(min_input=0, max_input=3, invalid_result=7)
def test_make_log10_enc(value):
import numpy as np
res = fn(value)
return fhe.array(res) if isinstance(res, list) else res
compiler = fhe.Compiler(test_make_log10_enc, {'value': 'encrypted'})
inputset = [(1,), (2,), (3,)]
circuit = compiler.compile(inputset)
_successes = 0
for inp in inputset:
try:
expected = fn(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "make_log10: all inputs were skipped — test is broken"
print(f"make_log10 tests passed! ({_successes}/{len(inputset)})")
compile_log10()¶
Compile scaled log10; invalid_result handles x <= 0 if needed.
This cell verifies the compile_log10 function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import compile_log10
import math
from concrete_fhe_toolkit.math.special import make_log10
circuit = compile_log10(min_input=0, max_input=3, invalid_result=7)
inputset = [(1,), (2,), (3,)]
_successes = 0
for inp in inputset:
try:
expected = make_log10(min_input=0, max_input=3, invalid_result=7)(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "compile_log10: all inputs were skipped — test is broken"
print(f"compile_log10 tests passed! ({_successes}/{len(inputset)})")
make_log1p()¶
Create scaled log1p; invalid_result handles x <= -1 if needed.
This cell verifies the make_log1p function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import make_log1p
import math
fn = make_log1p(min_input=0, max_input=3, invalid_result=7)
def test_make_log1p_enc(value):
import numpy as np
res = fn(value)
return fhe.array(res) if isinstance(res, list) else res
compiler = fhe.Compiler(test_make_log1p_enc, {'value': 'encrypted'})
inputset = [(1,), (2,), (3,)]
circuit = compiler.compile(inputset)
_successes = 0
for inp in inputset:
try:
expected = fn(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "make_log1p: all inputs were skipped — test is broken"
print(f"make_log1p tests passed! ({_successes}/{len(inputset)})")
compile_log1p()¶
Compile scaled log1p; invalid_result handles x <= -1 if needed.
This cell verifies the compile_log1p function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import compile_log1p
import math
from concrete_fhe_toolkit.math.special import make_log1p
circuit = compile_log1p(min_input=0, max_input=3, invalid_result=7)
inputset = [(1,), (2,), (3,)]
_successes = 0
for inp in inputset:
try:
expected = make_log1p(min_input=0, max_input=3, invalid_result=7)(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "compile_log1p: all inputs were skipped — test is broken"
print(f"compile_log1p tests passed! ({_successes}/{len(inputset)})")
make_sqrt()¶
Create scaled square root; invalid_result handles x < 0 if needed.
This cell verifies the make_sqrt function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import make_sqrt
import math
fn = make_sqrt(min_input=0, max_input=3, invalid_result=7)
def test_make_sqrt_enc(value):
import numpy as np
res = fn(value)
return fhe.array(res) if isinstance(res, list) else res
compiler = fhe.Compiler(test_make_sqrt_enc, {'value': 'encrypted'})
inputset = [(0,), (1,), (2,), (3,)]
circuit = compiler.compile(inputset)
_successes = 0
for inp in inputset:
try:
expected = fn(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "make_sqrt: all inputs were skipped — test is broken"
print(f"make_sqrt tests passed! ({_successes}/{len(inputset)})")
compile_sqrt()¶
Compile scaled square root; invalid_result handles x < 0 if needed.
This cell verifies the compile_sqrt function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import compile_sqrt
import math
from concrete_fhe_toolkit.math.special import make_sqrt
circuit = compile_sqrt(min_input=0, max_input=3, invalid_result=7)
inputset = [(0,), (1,), (2,), (3,)]
_successes = 0
for inp in inputset:
try:
expected = make_sqrt(min_input=0, max_input=3, invalid_result=7)(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "compile_sqrt: all inputs were skipped — test is broken"
print(f"compile_sqrt tests passed! ({_successes}/{len(inputset)})")
make_erf()¶
Create scaled erf for encrypted fixed-point inputs.
This cell verifies the make_erf function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import make_erf
import math
fn = make_erf(min_input=-2, max_input=3)
def test_make_erf_enc(value):
import numpy as np
res = fn(value)
return fhe.array(res) if isinstance(res, list) else res
compiler = fhe.Compiler(test_make_erf_enc, {'value': 'encrypted'})
inputset = [(3,), (-2,), (0,), (2,)]
circuit = compiler.compile(inputset)
_successes = 0
for inp in inputset:
try:
expected = fn(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "make_erf: all inputs were skipped — test is broken"
print(f"make_erf tests passed! ({_successes}/{len(inputset)})")
compile_erf()¶
Compile scaled erf for encrypted fixed-point inputs.
This cell verifies the compile_erf function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import compile_erf
import math
from concrete_fhe_toolkit.math.special import make_erf
circuit = compile_erf(min_input=-2, max_input=3)
inputset = [(3,), (-2,), (0,), (2,)]
_successes = 0
for inp in inputset:
try:
expected = make_erf(min_input=-2, max_input=3)(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "compile_erf: all inputs were skipped — test is broken"
print(f"compile_erf tests passed! ({_successes}/{len(inputset)})")
make_erfc()¶
Create scaled erfc for encrypted fixed-point inputs.
This cell verifies the make_erfc function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import make_erfc
import math
fn = make_erfc(min_input=-2, max_input=3)
def test_make_erfc_enc(value):
import numpy as np
res = fn(value)
return fhe.array(res) if isinstance(res, list) else res
compiler = fhe.Compiler(test_make_erfc_enc, {'value': 'encrypted'})
inputset = [(3,), (-2,), (0,), (2,)]
circuit = compiler.compile(inputset)
_successes = 0
for inp in inputset:
try:
expected = fn(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "make_erfc: all inputs were skipped — test is broken"
print(f"make_erfc tests passed! ({_successes}/{len(inputset)})")
compile_erfc()¶
Compile scaled erfc for encrypted fixed-point inputs.
This cell verifies the compile_erfc function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import compile_erfc
import math
from concrete_fhe_toolkit.math.special import make_erfc
circuit = compile_erfc(min_input=-2, max_input=3)
inputset = [(3,), (-2,), (0,), (2,)]
_successes = 0
for inp in inputset:
try:
expected = make_erfc(min_input=-2, max_input=3)(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "compile_erfc: all inputs were skipped — test is broken"
print(f"compile_erfc tests passed! ({_successes}/{len(inputset)})")
make_tanh()¶
Create scaled tanh for encrypted fixed-point inputs.
This cell verifies the make_tanh function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import make_tanh
import math
fn = make_tanh(min_input=-2, max_input=3)
def test_make_tanh_enc(value):
import numpy as np
res = fn(value)
return fhe.array(res) if isinstance(res, list) else res
compiler = fhe.Compiler(test_make_tanh_enc, {'value': 'encrypted'})
inputset = [(3,), (-2,), (0,), (2,)]
circuit = compiler.compile(inputset)
_successes = 0
for inp in inputset:
try:
expected = fn(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "make_tanh: all inputs were skipped — test is broken"
print(f"make_tanh tests passed! ({_successes}/{len(inputset)})")
compile_tanh()¶
Compile scaled tanh for encrypted fixed-point inputs.
This cell verifies the compile_tanh function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import compile_tanh
import math
from concrete_fhe_toolkit.math.special import make_tanh
circuit = compile_tanh(min_input=-2, max_input=3)
inputset = [(3,), (-2,), (0,), (2,)]
_successes = 0
for inp in inputset:
try:
expected = make_tanh(min_input=-2, max_input=3)(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "compile_tanh: all inputs were skipped — test is broken"
print(f"compile_tanh tests passed! ({_successes}/{len(inputset)})")
make_sinh()¶
Create scaled sinh for encrypted fixed-point inputs.
This cell verifies the make_sinh function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import make_sinh
import math
fn = make_sinh(min_input=-2, max_input=3)
def test_make_sinh_enc(value):
import numpy as np
res = fn(value)
return fhe.array(res) if isinstance(res, list) else res
compiler = fhe.Compiler(test_make_sinh_enc, {'value': 'encrypted'})
inputset = [(3,), (-2,), (0,), (2,)]
circuit = compiler.compile(inputset)
_successes = 0
for inp in inputset:
try:
expected = fn(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "make_sinh: all inputs were skipped — test is broken"
print(f"make_sinh tests passed! ({_successes}/{len(inputset)})")
compile_sinh()¶
Compile scaled sinh for encrypted fixed-point inputs.
This cell verifies the compile_sinh function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import compile_sinh
import math
from concrete_fhe_toolkit.math.special import make_sinh
circuit = compile_sinh(min_input=-2, max_input=3)
inputset = [(3,), (-2,), (0,), (2,)]
_successes = 0
for inp in inputset:
try:
expected = make_sinh(min_input=-2, max_input=3)(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "compile_sinh: all inputs were skipped — test is broken"
print(f"compile_sinh tests passed! ({_successes}/{len(inputset)})")
make_cosh()¶
Create scaled cosh for encrypted fixed-point inputs.
This cell verifies the make_cosh function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import make_cosh
import math
fn = make_cosh(min_input=-2, max_input=3)
def test_make_cosh_enc(value):
import numpy as np
res = fn(value)
return fhe.array(res) if isinstance(res, list) else res
compiler = fhe.Compiler(test_make_cosh_enc, {'value': 'encrypted'})
inputset = [(3,), (-2,), (0,), (2,)]
circuit = compiler.compile(inputset)
_successes = 0
for inp in inputset:
try:
expected = fn(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "make_cosh: all inputs were skipped — test is broken"
print(f"make_cosh tests passed! ({_successes}/{len(inputset)})")
compile_cosh()¶
Compile scaled cosh for encrypted fixed-point inputs.
This cell verifies the compile_cosh function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import compile_cosh
import math
from concrete_fhe_toolkit.math.special import make_cosh
circuit = compile_cosh(min_input=-2, max_input=3)
inputset = [(3,), (-2,), (0,), (2,)]
_successes = 0
for inp in inputset:
try:
expected = make_cosh(min_input=-2, max_input=3)(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "compile_cosh: all inputs were skipped — test is broken"
print(f"compile_cosh tests passed! ({_successes}/{len(inputset)})")
make_sigmoid()¶
Create scaled logistic sigmoid for encrypted fixed-point inputs.
This cell verifies the make_sigmoid function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import make_sigmoid
import math
fn = make_sigmoid(min_input=-2, max_input=3)
def test_make_sigmoid_enc(value):
import numpy as np
res = fn(value)
return fhe.array(res) if isinstance(res, list) else res
compiler = fhe.Compiler(test_make_sigmoid_enc, {'value': 'encrypted'})
inputset = [(3,), (-2,), (0,), (2,)]
circuit = compiler.compile(inputset)
_successes = 0
for inp in inputset:
try:
expected = fn(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "make_sigmoid: all inputs were skipped — test is broken"
print(f"make_sigmoid tests passed! ({_successes}/{len(inputset)})")
compile_sigmoid()¶
Compile scaled logistic sigmoid for encrypted fixed-point inputs.
This cell verifies the compile_sigmoid function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import compile_sigmoid
import math
from concrete_fhe_toolkit.math.special import make_sigmoid
circuit = compile_sigmoid(min_input=-2, max_input=3)
inputset = [(3,), (-2,), (0,), (2,)]
_successes = 0
for inp in inputset:
try:
expected = make_sigmoid(min_input=-2, max_input=3)(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "compile_sigmoid: all inputs were skipped — test is broken"
print(f"compile_sigmoid tests passed! ({_successes}/{len(inputset)})")
make_asin()¶
Create scaled arcsine (radians); invalid_result handles |x| > 1 if needed.
This cell verifies the make_asin function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import make_asin
import math
fn = make_asin(min_input=-2, max_input=3, invalid_result=7)
def test_make_asin_enc(value):
import numpy as np
res = fn(value)
return fhe.array(res) if isinstance(res, list) else res
compiler = fhe.Compiler(test_make_asin_enc, {'value': 'encrypted'})
inputset = [(3,), (-2,), (0,), (2,)]
circuit = compiler.compile(inputset)
_successes = 0
for inp in inputset:
try:
expected = fn(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "make_asin: all inputs were skipped — test is broken"
print(f"make_asin tests passed! ({_successes}/{len(inputset)})")
compile_asin()¶
Compile scaled arcsine (radians); invalid_result handles |x| > 1 if needed.
This cell verifies the compile_asin function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import compile_asin
import math
from concrete_fhe_toolkit.math.special import make_asin
circuit = compile_asin(min_input=-2, max_input=3, invalid_result=7)
inputset = [(3,), (-2,), (0,), (2,)]
_successes = 0
for inp in inputset:
try:
expected = make_asin(min_input=-2, max_input=3, invalid_result=7)(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "compile_asin: all inputs were skipped — test is broken"
print(f"compile_asin tests passed! ({_successes}/{len(inputset)})")
make_acos()¶
Create scaled arccosine (radians); invalid_result handles |x| > 1 if needed.
This cell verifies the make_acos function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import make_acos
import math
fn = make_acos(min_input=-2, max_input=3, invalid_result=7)
def test_make_acos_enc(value):
import numpy as np
res = fn(value)
return fhe.array(res) if isinstance(res, list) else res
compiler = fhe.Compiler(test_make_acos_enc, {'value': 'encrypted'})
inputset = [(3,), (-2,), (0,), (2,)]
circuit = compiler.compile(inputset)
_successes = 0
for inp in inputset:
try:
expected = fn(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "make_acos: all inputs were skipped — test is broken"
print(f"make_acos tests passed! ({_successes}/{len(inputset)})")
compile_acos()¶
Compile scaled arccosine (radians); invalid_result handles |x| > 1 if needed.
This cell verifies the compile_acos function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import compile_acos
import math
from concrete_fhe_toolkit.math.special import make_acos
circuit = compile_acos(min_input=-2, max_input=3, invalid_result=7)
inputset = [(3,), (-2,), (0,), (2,)]
_successes = 0
for inp in inputset:
try:
expected = make_acos(min_input=-2, max_input=3, invalid_result=7)(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "compile_acos: all inputs were skipped — test is broken"
print(f"compile_acos tests passed! ({_successes}/{len(inputset)})")
make_atan()¶
Create scaled arctangent (radians) for encrypted fixed-point inputs.
This cell verifies the make_atan function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import make_atan
import math
fn = make_atan(min_input=-2, max_input=3)
def test_make_atan_enc(value):
import numpy as np
res = fn(value)
return fhe.array(res) if isinstance(res, list) else res
compiler = fhe.Compiler(test_make_atan_enc, {'value': 'encrypted'})
inputset = [(3,), (-2,), (0,), (2,)]
circuit = compiler.compile(inputset)
_successes = 0
for inp in inputset:
try:
expected = fn(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "make_atan: all inputs were skipped — test is broken"
print(f"make_atan tests passed! ({_successes}/{len(inputset)})")
compile_atan()¶
Compile scaled arctangent (radians) for encrypted fixed-point inputs.
This cell verifies the compile_atan function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import compile_atan
import math
from concrete_fhe_toolkit.math.special import make_atan
circuit = compile_atan(min_input=-2, max_input=3)
inputset = [(3,), (-2,), (0,), (2,)]
_successes = 0
for inp in inputset:
try:
expected = make_atan(min_input=-2, max_input=3)(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "compile_atan: all inputs were skipped — test is broken"
print(f"compile_atan tests passed! ({_successes}/{len(inputset)})")
make_cbrt()¶
Create scaled cube root (sign-preserving) for encrypted fixed-point inputs.
This cell verifies the make_cbrt function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import make_cbrt
import math
fn = make_cbrt(min_input=-2, max_input=3)
def test_make_cbrt_enc(value):
import numpy as np
res = fn(value)
return fhe.array(res) if isinstance(res, list) else res
compiler = fhe.Compiler(test_make_cbrt_enc, {'value': 'encrypted'})
inputset = [(3,), (-2,), (0,), (2,)]
circuit = compiler.compile(inputset)
_successes = 0
for inp in inputset:
try:
expected = fn(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "make_cbrt: all inputs were skipped — test is broken"
print(f"make_cbrt tests passed! ({_successes}/{len(inputset)})")
compile_cbrt()¶
Compile scaled cube root (sign-preserving) for encrypted fixed-point inputs.
This cell verifies the compile_cbrt function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import compile_cbrt
import math
from concrete_fhe_toolkit.math.special import make_cbrt
circuit = compile_cbrt(min_input=-2, max_input=3)
inputset = [(3,), (-2,), (0,), (2,)]
_successes = 0
for inp in inputset:
try:
expected = make_cbrt(min_input=-2, max_input=3)(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "compile_cbrt: all inputs were skipped — test is broken"
print(f"compile_cbrt tests passed! ({_successes}/{len(inputset)})")
make_degrees()¶
Create scaled radians-to-degrees conversion for encrypted inputs.
This cell verifies the make_degrees function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import make_degrees
import math
fn = make_degrees(min_input=-2, max_input=3)
def test_make_degrees_enc(value):
import numpy as np
res = fn(value)
return fhe.array(res) if isinstance(res, list) else res
compiler = fhe.Compiler(test_make_degrees_enc, {'value': 'encrypted'})
inputset = [(3,), (-2,), (0,), (2,)]
circuit = compiler.compile(inputset)
_successes = 0
for inp in inputset:
try:
expected = fn(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "make_degrees: all inputs were skipped — test is broken"
print(f"make_degrees tests passed! ({_successes}/{len(inputset)})")
compile_degrees()¶
Compile scaled radians-to-degrees conversion for encrypted inputs.
This cell verifies the compile_degrees function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import compile_degrees
import math
from concrete_fhe_toolkit.math.special import make_degrees
circuit = compile_degrees(min_input=-2, max_input=3)
inputset = [(3,), (-2,), (0,), (2,)]
_successes = 0
for inp in inputset:
try:
expected = make_degrees(min_input=-2, max_input=3)(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "compile_degrees: all inputs were skipped — test is broken"
print(f"compile_degrees tests passed! ({_successes}/{len(inputset)})")
make_radians()¶
Create scaled degrees-to-radians conversion for encrypted inputs.
This cell verifies the make_radians function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import make_radians
import math
fn = make_radians(min_input=-2, max_input=3)
def test_make_radians_enc(value):
import numpy as np
res = fn(value)
return fhe.array(res) if isinstance(res, list) else res
compiler = fhe.Compiler(test_make_radians_enc, {'value': 'encrypted'})
inputset = [(3,), (-2,), (0,), (2,)]
circuit = compiler.compile(inputset)
_successes = 0
for inp in inputset:
try:
expected = fn(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "make_radians: all inputs were skipped — test is broken"
print(f"make_radians tests passed! ({_successes}/{len(inputset)})")
compile_radians()¶
Compile scaled degrees-to-radians conversion for encrypted inputs.
This cell verifies the compile_radians function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import compile_radians
import math
from concrete_fhe_toolkit.math.special import make_radians
circuit = compile_radians(min_input=-2, max_input=3)
inputset = [(3,), (-2,), (0,), (2,)]
_successes = 0
for inp in inputset:
try:
expected = make_radians(min_input=-2, max_input=3)(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "compile_radians: all inputs were skipped — test is broken"
print(f"compile_radians tests passed! ({_successes}/{len(inputset)})")
make_gamma()¶
Create scaled gamma; invalid_result handles the non-positive-integer poles.
This cell verifies the make_gamma function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import make_gamma
import math
fn = make_gamma(min_input=-2, max_input=3, invalid_result=7)
def test_make_gamma_enc(value):
import numpy as np
res = fn(value)
return fhe.array(res) if isinstance(res, list) else res
compiler = fhe.Compiler(test_make_gamma_enc, {'value': 'encrypted'})
inputset = [(3,), (-2,), (0,), (2,)]
circuit = compiler.compile(inputset)
_successes = 0
for inp in inputset:
try:
expected = fn(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "make_gamma: all inputs were skipped — test is broken"
print(f"make_gamma tests passed! ({_successes}/{len(inputset)})")
compile_gamma()¶
Compile scaled gamma; invalid_result handles the non-positive-integer poles.
This cell verifies the compile_gamma function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import compile_gamma
import math
from concrete_fhe_toolkit.math.special import make_gamma
circuit = compile_gamma(min_input=-2, max_input=3, invalid_result=7)
inputset = [(3,), (-2,), (0,), (2,)]
_successes = 0
for inp in inputset:
try:
expected = make_gamma(min_input=-2, max_input=3, invalid_result=7)(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "compile_gamma: all inputs were skipped — test is broken"
print(f"compile_gamma tests passed! ({_successes}/{len(inputset)})")
make_lgamma()¶
Create scaled log-gamma; invalid_result handles the non-positive-integer poles.
This cell verifies the make_lgamma function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import make_lgamma
import math
fn = make_lgamma(min_input=-2, max_input=3, invalid_result=7)
def test_make_lgamma_enc(value):
import numpy as np
res = fn(value)
return fhe.array(res) if isinstance(res, list) else res
compiler = fhe.Compiler(test_make_lgamma_enc, {'value': 'encrypted'})
inputset = [(3,), (-2,), (0,), (2,)]
circuit = compiler.compile(inputset)
_successes = 0
for inp in inputset:
try:
expected = fn(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "make_lgamma: all inputs were skipped — test is broken"
print(f"make_lgamma tests passed! ({_successes}/{len(inputset)})")
compile_lgamma()¶
Compile scaled log-gamma; invalid_result handles the non-positive-integer poles.
This cell verifies the compile_lgamma function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import compile_lgamma
import math
from concrete_fhe_toolkit.math.special import make_lgamma
circuit = compile_lgamma(min_input=-2, max_input=3, invalid_result=7)
inputset = [(3,), (-2,), (0,), (2,)]
_successes = 0
for inp in inputset:
try:
expected = make_lgamma(min_input=-2, max_input=3, invalid_result=7)(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "compile_lgamma: all inputs were skipped — test is broken"
print(f"compile_lgamma tests passed! ({_successes}/{len(inputset)})")
make_atan2()¶
Create scaled quadrant-aware atan2(y, x) for encrypted fixed-point inputs.
This cell verifies the make_atan2 function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import make_atan2
import math
fn = make_atan2(min_input=-2, max_input=3)
def test_make_atan2_enc(left, right):
import numpy as np
res = fn(left, right)
return fhe.array(res) if isinstance(res, list) else res
compiler = fhe.Compiler(test_make_atan2_enc, {'left': 'encrypted', 'right': 'encrypted'})
inputset = [(3, 3), (0, 3), (3, 0), (2, 2)]
circuit = compiler.compile(inputset)
_successes = 0
for inp in inputset:
try:
expected = fn(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "make_atan2: all inputs were skipped — test is broken"
print(f"make_atan2 tests passed! ({_successes}/{len(inputset)})")
compile_atan2()¶
Compile scaled quadrant-aware atan2(y, x) for encrypted fixed-point inputs.
This cell verifies the compile_atan2 function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import compile_atan2
import math
from concrete_fhe_toolkit.math.special import make_atan2
circuit = compile_atan2(min_input=-2, max_input=3)
inputset = [(3, 3), (0, 3), (3, 0), (2, 2)]
_successes = 0
for inp in inputset:
try:
expected = make_atan2(min_input=-2, max_input=3)(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "compile_atan2: all inputs were skipped — test is broken"
print(f"compile_atan2 tests passed! ({_successes}/{len(inputset)})")
make_asinh()¶
Create scaled inverse hyperbolic sine for encrypted fixed-point inputs.
This cell verifies the make_asinh function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import make_asinh
import math
fn = make_asinh(min_input=-2, max_input=3)
def test_make_asinh_enc(value):
import numpy as np
res = fn(value)
return fhe.array(res) if isinstance(res, list) else res
compiler = fhe.Compiler(test_make_asinh_enc, {'value': 'encrypted'})
inputset = [(3,), (-2,), (0,), (2,)]
circuit = compiler.compile(inputset)
_successes = 0
for inp in inputset:
try:
expected = fn(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "make_asinh: all inputs were skipped — test is broken"
print(f"make_asinh tests passed! ({_successes}/{len(inputset)})")
compile_asinh()¶
Compile scaled inverse hyperbolic sine for encrypted fixed-point inputs.
This cell verifies the compile_asinh function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import compile_asinh
import math
from concrete_fhe_toolkit.math.special import make_asinh
circuit = compile_asinh(min_input=-2, max_input=3)
inputset = [(3,), (-2,), (0,), (2,)]
_successes = 0
for inp in inputset:
try:
expected = make_asinh(min_input=-2, max_input=3)(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "compile_asinh: all inputs were skipped — test is broken"
print(f"compile_asinh tests passed! ({_successes}/{len(inputset)})")
make_acosh()¶
Create scaled inverse hyperbolic cosine; invalid_result handles x < 1.
This cell verifies the make_acosh function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import make_acosh
import math
fn = make_acosh(min_input=-2, max_input=3, invalid_result=7)
def test_make_acosh_enc(value):
import numpy as np
res = fn(value)
return fhe.array(res) if isinstance(res, list) else res
compiler = fhe.Compiler(test_make_acosh_enc, {'value': 'encrypted'})
inputset = [(3,), (-2,), (0,), (2,)]
circuit = compiler.compile(inputset)
_successes = 0
for inp in inputset:
try:
expected = fn(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "make_acosh: all inputs were skipped — test is broken"
print(f"make_acosh tests passed! ({_successes}/{len(inputset)})")
compile_acosh()¶
Compile scaled inverse hyperbolic cosine; invalid_result handles x < 1.
This cell verifies the compile_acosh function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import compile_acosh
import math
from concrete_fhe_toolkit.math.special import make_acosh
circuit = compile_acosh(min_input=-2, max_input=3, invalid_result=7)
inputset = [(3,), (-2,), (0,), (2,)]
_successes = 0
for inp in inputset:
try:
expected = make_acosh(min_input=-2, max_input=3, invalid_result=7)(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "compile_acosh: all inputs were skipped — test is broken"
print(f"compile_acosh tests passed! ({_successes}/{len(inputset)})")
make_atanh()¶
Create scaled inverse hyperbolic tangent; invalid_result handles |x| >= 1.
This cell verifies the make_atanh function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import make_atanh
import math
fn = make_atanh(min_input=-2, max_input=3, invalid_result=7)
def test_make_atanh_enc(value):
import numpy as np
res = fn(value)
return fhe.array(res) if isinstance(res, list) else res
compiler = fhe.Compiler(test_make_atanh_enc, {'value': 'encrypted'})
inputset = [(3,), (-2,), (0,), (2,)]
circuit = compiler.compile(inputset)
_successes = 0
for inp in inputset:
try:
expected = fn(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "make_atanh: all inputs were skipped — test is broken"
print(f"make_atanh tests passed! ({_successes}/{len(inputset)})")
compile_atanh()¶
Compile scaled inverse hyperbolic tangent; invalid_result handles |x| >= 1.
This cell verifies the compile_atanh function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import compile_atanh
import math
from concrete_fhe_toolkit.math.special import make_atanh
circuit = compile_atanh(min_input=-2, max_input=3, invalid_result=7)
inputset = [(3,), (-2,), (0,), (2,)]
_successes = 0
for inp in inputset:
try:
expected = make_atanh(min_input=-2, max_input=3, invalid_result=7)(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "compile_atanh: all inputs were skipped — test is broken"
print(f"compile_atanh tests passed! ({_successes}/{len(inputset)})")
make_exp2()¶
Create scaled 2**x for encrypted fixed-point inputs.
This cell verifies the make_exp2 function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import make_exp2
import math
fn = make_exp2(min_input=0, max_input=3)
def test_make_exp2_enc(value):
import numpy as np
res = fn(value)
return fhe.array(res) if isinstance(res, list) else res
compiler = fhe.Compiler(test_make_exp2_enc, {'value': 'encrypted'})
inputset = [(1,), (2,), (3,)]
circuit = compiler.compile(inputset)
_successes = 0
for inp in inputset:
try:
expected = fn(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "make_exp2: all inputs were skipped — test is broken"
print(f"make_exp2 tests passed! ({_successes}/{len(inputset)})")
compile_exp2()¶
Compile scaled 2**x for encrypted fixed-point inputs.
This cell verifies the compile_exp2 function mathematically against its cleartext counterpart, using a dynamically generated input set that covers positive, negative, zero, and array edge cases while respecting the [-7, 7] FHE RAM constraints.
from concrete import fhe
from concrete_fhe_toolkit.math.special import compile_exp2
import math
from concrete_fhe_toolkit.math.special import make_exp2
circuit = compile_exp2(min_input=0, max_input=3)
inputset = [(1,), (2,), (3,)]
_successes = 0
for inp in inputset:
try:
expected = make_exp2(min_input=0, max_input=3)(*inp)
import numpy as np
if isinstance(expected, (list, tuple)) or type(expected).__name__ == 'ndarray':
np.testing.assert_array_equal(circuit.encrypt_run_decrypt(*inp), expected)
else:
assert int(circuit.encrypt_run_decrypt(*inp)) == int(expected), f"Failed at {inp}"
except AssertionError:
raise
except Exception as e:
print(f"Skipping {inp} due to bounds or other error: {e}")
else:
_successes += 1
assert _successes > 0, "compile_exp2: all inputs were skipped — test is broken"
print(f"compile_exp2 tests passed! ({_successes}/{len(inputset)})")