From 8f6a3f4eb60ec3ca7cb91b942e2a2bda29e7e209 Mon Sep 17 00:00:00 2001 From: Sefik Ilkin Serengil Date: Sat, 5 Oct 2024 22:53:20 +0100 Subject: [PATCH 1/2] warning message addedfor addition of different signs in tensors --- lightphe/models/Tensor.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lightphe/models/Tensor.py b/lightphe/models/Tensor.py index 0a1ba7b..2664881 100644 --- a/lightphe/models/Tensor.py +++ b/lightphe/models/Tensor.py @@ -1,6 +1,9 @@ from typing import Union, List from lightphe.models.Homomorphic import Homomorphic from lightphe.commons import phe_utils +from lightphe.commons.logger import Logger + +logger = Logger(module="lightphe/models/Tensor.py") # pylint: disable=too-few-public-methods, no-else-return @@ -174,6 +177,12 @@ def __add__(self, other: "EncryptedTensor") -> "EncryptedTensor": else: # if one is positive and one is negative, then i cannot know # the result is positive or negative. trust mod calculations. + if alpha_tensor.sign != beta_tensor.sign: + logger.warn( + f"{i}-th items of the vectors have different signs, and result's sign " + "cannot be determined in PHE. Result will be shown for positive for this anyway." + ) + current_tensor = Fraction( dividend=current_dividend, abs_dividend=current_dividend, From 0a939c19611ae1de13b2cec8c39076e580c2ec3b Mon Sep 17 00:00:00 2001 From: Sefik Ilkin Serengil Date: Sat, 5 Oct 2024 22:59:17 +0100 Subject: [PATCH 2/2] linting --- lightphe/models/Tensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lightphe/models/Tensor.py b/lightphe/models/Tensor.py index 2664881..7f48f2c 100644 --- a/lightphe/models/Tensor.py +++ b/lightphe/models/Tensor.py @@ -182,7 +182,7 @@ def __add__(self, other: "EncryptedTensor") -> "EncryptedTensor": f"{i}-th items of the vectors have different signs, and result's sign " "cannot be determined in PHE. Result will be shown for positive for this anyway." ) - + current_tensor = Fraction( dividend=current_dividend, abs_dividend=current_dividend,