Skip to content

Commit

Permalink
fix(frontend-python): always increase the clear bit width by one to a…
Browse files Browse the repository at this point in the history
…void sign extension issues
  • Loading branch information
umut-sahin committed Mar 26, 2024
1 parent 4068046 commit 29e131a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@ def apply_many(self, graphs: Dict[str, Graph]):
)

if node.output.is_clear:
new_bit_width = original_bit_width
if not node.output.dtype.is_signed:
new_bit_width += 1
new_bit_width = original_bit_width + 1

node.properties["original_bit_width"] = original_bit_width
node.output.dtype.bit_width = new_bit_width
Expand Down
24 changes: 24 additions & 0 deletions frontends/concrete-python/tests/execution/test_others.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,22 @@ def copy_modify(x):
return np.concatenate((x, y))


def issue650(x):
"""
Function of a reported bug in which bit widths assigned to clear values were wrong.
"""
tmp0 = x
tmp1 = [[1], [-1], [-1], [-1], [-1], [-1], [-2], [-1], [0], [0]]
tmp2 = np.matmul(tmp0, tmp1)
tmp3 = np.sum(tmp0, axis=1, keepdims=True)
tmp4 = -1
tmp5 = np.multiply(tmp4, tmp3)
tmp6 = np.subtract(tmp2, tmp5)
tmp7 = [[11]]
tmp8 = np.add(tmp6, tmp7)
return tmp8


@pytest.mark.parametrize(
"function,parameters,configuration_overrides",
[
Expand Down Expand Up @@ -932,6 +948,14 @@ def copy_modify(x):
"{optimize_tlu_based_on_measured_bounds: True}"
),
),
pytest.param(
issue650,
{
"x": {"range": [-2, 1], "status": "encrypted", "shape": (1, 10)},
},
{},
id="issue-650",
),
],
)
def test_others(function, parameters, configuration_overrides, helpers):
Expand Down

0 comments on commit 29e131a

Please sign in to comment.