fix(frontend-python): assigning signed values to unsigned tensors

This commit is contained in:
Umut
2023-12-04 12:41:22 +03:00
parent 687502d4e2
commit 07d6293ca8
3 changed files with 22 additions and 4 deletions

View File

@@ -1559,6 +1559,7 @@ class Context:
np.broadcast_to(np.zeros(y.shape), required_y_shape)
y = self.broadcast_to(y, required_y_shape)
x = self.to_signedness(x, of=resulting_type)
y = self.to_signedness(y, of=resulting_type)
return self.operation(

View File

@@ -5,6 +5,7 @@ Configuration of `pytest`.
import json
import os
import random
from copy import deepcopy
from pathlib import Path
from typing import Any, Callable, Dict, List, Tuple, Union
@@ -295,8 +296,8 @@ class Helpers:
if not only_simulation:
for i in range(retries):
expected = sanitize(function(*sample))
actual = sanitize(circuit.encrypt_run_decrypt(*sample))
expected = sanitize(function(*deepcopy(sample)))
actual = sanitize(circuit.encrypt_run_decrypt(*deepcopy(sample)))
if all(np.array_equal(e, a) for e, a in zip(expected, actual)):
break
@@ -317,8 +318,8 @@ class Helpers:
circuit.enable_fhe_simulation()
for i in range(retries):
expected = sanitize(function(*sample))
actual = sanitize(circuit.simulate(*sample))
expected = sanitize(function(*deepcopy(sample)))
actual = sanitize(circuit.simulate(*deepcopy(sample)))
if all(np.array_equal(e, a) for e, a in zip(expected, actual)):
break

View File

@@ -443,6 +443,21 @@ def assignment_case_28():
return shape, assign
def assignment_case_29():
"""
Assignment test case.
"""
shape = (5,)
value = -20
def assign(x):
x[0] = value
return x
return shape, assign
@pytest.mark.parametrize(
"shape,function",
[
@@ -475,6 +490,7 @@ def assignment_case_28():
pytest.param(*assignment_case_26()),
pytest.param(*assignment_case_27()),
pytest.param(*assignment_case_28()),
pytest.param(*assignment_case_29()),
],
)
def test_static_assignment(shape, function, helpers):