chore(frontend-python): use rounding in some flanky tests around floats

This commit is contained in:
Umut
2023-04-11 16:23:14 +02:00
committed by Quentin Bourgerie
parent 02e655748f
commit 307d6997e9
3 changed files with 15 additions and 14 deletions

View File

@@ -23,7 +23,7 @@ def test_artifacts_export(helpers):
@compiler({"x": "encrypted"})
def f(x):
a = ((np.sin(x) ** 2) + (np.cos(x) ** 2)).astype(np.int64)
a = ((np.sin(x) ** 2) + (np.cos(x) ** 2)).round().astype(np.int64)
b = np.where(x < 5, x * 10, x + 10)
return a + b

View File

@@ -155,7 +155,7 @@ return %1
@fhe.circuit({"x": "encrypted"}, helpers.configuration())
def circuit4(x: fhe.uint3):
return ((np.sin(x) ** 2) + (np.cos(x) ** 2)).astype(fhe.uint3)
return ((np.sin(x) ** 2) + (np.cos(x) ** 2)).round().astype(fhe.uint3)
helpers.check_str(
"""
@@ -168,16 +168,17 @@ Subgraphs:
%1 = subgraph(%0):
%0 = input # EncryptedScalar<uint3>
%1 = sin(%0) # EncryptedScalar<float64>
%2 = 2 # ClearScalar<uint2>
%3 = power(%1, %2) # EncryptedScalar<float64>
%4 = cos(%0) # EncryptedScalar<float64>
%5 = 2 # ClearScalar<uint2>
%6 = power(%4, %5) # EncryptedScalar<float64>
%7 = add(%3, %6) # EncryptedScalar<float64>
%8 = astype(%7) # EncryptedScalar<uint3>
return %8
%0 = input # EncryptedScalar<uint3>
%1 = sin(%0) # EncryptedScalar<float64>
%2 = 2 # ClearScalar<uint2>
%3 = power(%1, %2) # EncryptedScalar<float64>
%4 = cos(%0) # EncryptedScalar<float64>
%5 = 2 # ClearScalar<uint2>
%6 = power(%4, %5) # EncryptedScalar<float64>
%7 = add(%3, %6) # EncryptedScalar<float64>
%8 = around(%7, decimals=0) # EncryptedScalar<float64>
%9 = astype(%8) # EncryptedScalar<uint3>
return %9
""".strip(),
str(circuit4),

View File

@@ -451,11 +451,11 @@ def deterministic_unary_function(x):
id="(60 * np.sin(x)).astype(np.int64) + 60",
),
pytest.param(
lambda x: ((np.sin(x) ** 2) + (np.cos(x) ** 2)).astype(np.int64),
lambda x: ((np.sin(x) ** 2) + (np.cos(x) ** 2)).round().astype(np.int64),
{
"x": {"status": "encrypted", "range": [0, 127]},
},
id="((np.sin(x) ** 2) + (np.cos(x) ** 2)).astype(np.int64)",
id="((np.sin(x) ** 2) + (np.cos(x) ** 2)).round().astype(np.int64)",
),
pytest.param(
lambda x: np.maximum(x, [[10, 20], [30, 40], [50, 60]]),