feat(frontend-python): add support for np.copy

This commit is contained in:
Umut
2023-06-15 13:31:43 +02:00
parent e360e938c9
commit 3456978c24
3 changed files with 22 additions and 0 deletions

View File

@@ -307,6 +307,10 @@ class Converter:
ctx.error({node: "3-dimensional convolutions are not supported at the moment"})
assert False, "unreachable" # pragma: no cover
def copy(self, ctx: Context, node: Node, preds: List[Conversion]) -> Conversion:
assert len(preds) == 1
return preds[0]
def dot(self, ctx: Context, node: Node, preds: List[Conversion]) -> Conversion:
assert len(preds) == 2
return ctx.dot(ctx.typeof(node), preds[0], preds[1])

View File

@@ -226,6 +226,7 @@ class Tracer:
np.ceil,
np.clip,
np.concatenate,
np.copy,
np.copysign,
np.cos,
np.cosh,

View File

@@ -202,6 +202,16 @@ def deterministic_unary_function(x):
return np.vectorize(per_element)(x)
def copy_modify(x):
"""
A function that used `np.copy` and then modifies the copied object.
"""
y = np.copy(x)
y[1] = np.sum(x)
return np.concatenate((x, y))
@pytest.mark.parametrize(
"function,parameters",
[
@@ -691,6 +701,13 @@ def deterministic_unary_function(x):
},
id="fhe.LookupTable([10, 5])[x > 5]",
),
pytest.param(
copy_modify,
{
"x": {"status": "encrypted", "range": [0, 10], "shape": (3,)},
},
id="copy_modify",
),
],
)
def test_others(function, parameters, helpers):