Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: array comparison #65

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions nada_numpy/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
public_rational, rational, secret_rational, sign)
from nada_numpy.utils import copy_metadata


class NadaArray: # pylint:disable=too-many-public-methods
"""
Represents an array-like object with additional functionality.
Expand Down Expand Up @@ -424,9 +423,8 @@ def __comparison_operator(
if isinstance(value, np.ndarray):
if len(self.inner) != len(value):
raise ValueError("Arrays must have the same length")
return NadaArray(
np.array([operator(x, y) for x, y in zip(self.inner, value)])
)
vectorized_operator = np.vectorize(operator)
return NadaArray(vectorized_operator(self.inner, value))

raise ValueError(f"Unsupported type: {type(value)}")

Expand Down
6 changes: 3 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "nada-numpy"
version = "0.4.1"
version = "0.4.2"
description = "Nada-Numpy is a Python library designed for algebraic operations on NumPy-like array objects on top of Nada DSL and Nillion Network."
authors = ["José Cabrero-Holgueras <[email protected]>"]
readme = "README.md"
Expand Down
4 changes: 2 additions & 2 deletions tests/nada-tests/src/array_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
def nada_main():
parties = na.parties(2)

a = na.array([3], parties[0], "A", SecretInteger)
b = na.array([3], parties[1], "B", SecretInteger)
a = na.array([1, 3], parties[0], "A", SecretInteger)
b = na.array([1, 3], parties[1], "B", SecretInteger)
c = Integer(1)

d = a == b
Expand Down
84 changes: 42 additions & 42 deletions tests/nada-tests/tests/array_comparison.yaml
Original file line number Diff line number Diff line change
@@ -1,99 +1,99 @@
---
program: array_comparison
inputs:
A_0:
A_0_0:
SecretInteger: "1"
A_1:
A_0_1:
SecretInteger: "100"
A_2:
A_0_2:
SecretInteger: "0"
B_0:
B_0_0:
SecretInteger: "8"
B_1:
B_0_1:
SecretInteger: "101"
B_2:
B_0_2:
SecretInteger: "0"
expected_outputs:
my_output_1_0:
my_output_1_0_0:
SecretBoolean: false
my_output_1_1:
my_output_1_0_1:
SecretBoolean: false
my_output_1_2:
my_output_1_0_2:
SecretBoolean: true

my_output_2_0:
my_output_2_0_0:
SecretBoolean: true
my_output_2_1:
my_output_2_0_1:
SecretBoolean: false
my_output_2_2:
my_output_2_0_2:
SecretBoolean: false

my_output_3_0:
my_output_3_0_0:
SecretBoolean: true
my_output_3_1:
my_output_3_0_1:
SecretBoolean: true
my_output_3_2:
my_output_3_0_2:
SecretBoolean: false

my_output_4_0:
my_output_4_0_0:
SecretBoolean: false
my_output_4_1:
my_output_4_0_1:
SecretBoolean: true
my_output_4_2:
my_output_4_0_2:
SecretBoolean: true

my_output_5_0:
my_output_5_0_0:
SecretBoolean: true
my_output_5_1:
my_output_5_0_1:
SecretBoolean: true
my_output_5_2:
my_output_5_0_2:
SecretBoolean: false

my_output_6_0:
my_output_6_0_0:
SecretBoolean: false
my_output_6_1:
my_output_6_0_1:
SecretBoolean: false
my_output_6_2:
my_output_6_0_2:
SecretBoolean: true

my_output_7_0:
my_output_7_0_0:
SecretBoolean: true
my_output_7_1:
my_output_7_0_1:
SecretBoolean: true
my_output_7_2:
my_output_7_0_2:
SecretBoolean: true

my_output_8_0:
my_output_8_0_0:
SecretBoolean: true
my_output_8_1:
my_output_8_0_1:
SecretBoolean: false
my_output_8_2:
my_output_8_0_2:
SecretBoolean: true

my_output_9_0:
my_output_9_0_0:
SecretBoolean: false
my_output_9_1:
my_output_9_0_1:
SecretBoolean: false
my_output_9_2:
my_output_9_0_2:
SecretBoolean: false

my_output_10_0:
my_output_10_0_0:
SecretBoolean: false
my_output_10_1:
my_output_10_0_1:
SecretBoolean: true
my_output_10_2:
my_output_10_0_2:
SecretBoolean: false

my_output_11_0:
my_output_11_0_0:
SecretBoolean: false
my_output_11_1:
my_output_11_0_1:
SecretBoolean: false
my_output_11_2:
my_output_11_0_2:
SecretBoolean: true

my_output_12_0:
my_output_12_0_0:
SecretBoolean: true
my_output_12_1:
my_output_12_0_1:
SecretBoolean: true
my_output_12_2:
my_output_12_0_2:
SecretBoolean: false
Loading