mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-08 19:44:57 -05:00
feat: improve graph formatting with float bounds
This commit is contained in:
@@ -228,7 +228,9 @@ class Client:
|
||||
output < (np.prod(crt_decomposition) // 2),
|
||||
output,
|
||||
-np.prod(crt_decomposition) + output,
|
||||
).astype(np.int64)
|
||||
).astype(
|
||||
np.int64
|
||||
) # type: ignore
|
||||
|
||||
sanitized_outputs.append(sanititzed_output)
|
||||
|
||||
@@ -242,7 +244,9 @@ class Client:
|
||||
output = output.astype(np.longlong) # to prevent overflows in numpy
|
||||
sanititzed_output = np.where(
|
||||
output < (2 ** (n - 1)), output, output - (2**n)
|
||||
).astype(np.int64)
|
||||
).astype(
|
||||
np.int64
|
||||
) # type: ignore
|
||||
sanitized_outputs.append(sanititzed_output)
|
||||
else:
|
||||
sanitized_outputs.append(
|
||||
|
||||
@@ -189,7 +189,7 @@ def round_bit_pattern(
|
||||
if isinstance(lsbs_to_remove, AutoRounder):
|
||||
if local._is_adjusting:
|
||||
if not lsbs_to_remove.is_adjusted:
|
||||
raise Adjusting(lsbs_to_remove, int(np.min(x)), int(np.max(x)))
|
||||
raise Adjusting(lsbs_to_remove, int(np.min(x)), int(np.max(x))) # type: ignore
|
||||
|
||||
elif not lsbs_to_remove.is_adjusted:
|
||||
message = (
|
||||
|
||||
@@ -282,13 +282,26 @@ class Graph:
|
||||
if node.operation == Operation.Generic and "subgraph" in node.properties["kwargs"]:
|
||||
subgraphs[line] = node.properties["kwargs"]["subgraph"]
|
||||
|
||||
# get formatted bounds
|
||||
bounds = ""
|
||||
if node.bounds is not None:
|
||||
bounds += "∈ ["
|
||||
|
||||
lower, upper = node.bounds
|
||||
assert type(lower) == type(upper) # pylint: disable=unidiomatic-typecheck
|
||||
|
||||
if isinstance(lower, (float, np.float32, np.float64)):
|
||||
bounds += f"{round(lower, 6)}, {round(upper, 6)}"
|
||||
else:
|
||||
bounds += f"{int(lower)}, {int(upper)}"
|
||||
|
||||
bounds += "]"
|
||||
|
||||
# remember metadata of the node
|
||||
line_metadata.append(
|
||||
{
|
||||
"type": f"# {node.output}",
|
||||
"bounds": (
|
||||
f"∈ [{node.bounds[0]}, {node.bounds[1]}]" if node.bounds is not None else ""
|
||||
),
|
||||
"bounds": bounds,
|
||||
"tag": (f"@ {node.tag}" if node.tag != "" else ""),
|
||||
"location": node.location,
|
||||
},
|
||||
|
||||
@@ -86,8 +86,8 @@ return %2
|
||||
Function you are trying to compile cannot be converted to MLIR
|
||||
|
||||
%0 = x # EncryptedScalar<uint7> ∈ [0, 99]
|
||||
%1 = sin(%0) # EncryptedScalar<float64> ∈ [-0.9999902065507035, 0.9999118601072672]
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ only integer operations are supported
|
||||
%1 = sin(%0) # EncryptedScalar<float64> ∈ [-0.99999, 0.999912]
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ only integer operations are supported
|
||||
return %1
|
||||
|
||||
""", # noqa: E501
|
||||
|
||||
Reference in New Issue
Block a user