Skip to content

Commit

Permalink
feat: adding shuffle example
Browse files Browse the repository at this point in the history
  • Loading branch information
manel1874 committed Sep 4, 2024
1 parent 3818629 commit 58e9436
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 0 deletions.
5 changes: 5 additions & 0 deletions nada-project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,8 @@ prime_size = 128
path = "src/not.py"
name = "not"
prime_size = 128

[[programs]]
path = "src/shuffle.py"
name = "shuffle"
prime_size = 128
54 changes: 54 additions & 0 deletions src/shuffle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""Main Nada program"""

from nada_dsl import PublicInteger, SecretInteger

import nada_numpy as na
from nada_numpy import shuffle


def nada_main():

# Note:
# The current shuffle operation only supports vectors with
# a power-of-two size, e.g., 2, 4, 8, 16, 32, ...

parties = na.parties(2)
a = na.array([8], parties[0], "A", na.Rational)
b = na.array([8], parties[0], "B", na.SecretRational)
c = na.array([8], parties[0], "C", PublicInteger)
d = na.array([8], parties[0], "D", SecretInteger)

# As a function

shuffled_a = shuffle(a)
shuffled_b = shuffle(b)
shuffled_c = shuffle(c)
shuffled_d = shuffle(d)

result_a = shuffled_a - shuffled_a
result_b = shuffled_b - shuffled_b
result_c = shuffled_c - shuffled_c
result_d = shuffled_d - shuffled_d

# As a method

shuffled_method_a = a.shuffle()
shuffled_method_b = b.shuffle()
shuffled_method_c = c.shuffle()
shuffled_method_d = d.shuffle()

result_method_a = shuffled_method_a - shuffled_method_a
result_method_b = shuffled_method_b - shuffled_method_b
result_method_c = shuffled_method_c - shuffled_method_c
result_method_d = shuffled_method_d - shuffled_method_d

return (
na.output(result_a, parties[1], "my_output_a")
+ na.output(result_b, parties[1], "my_output_b")
+ na.output(result_c, parties[1], "my_output_c")
+ na.output(result_d, parties[1], "my_output_d")
+ na.output(result_method_a, parties[1], "my_output_method_a")
+ na.output(result_method_b, parties[1], "my_output_method_b")
+ na.output(result_method_c, parties[1], "my_output_method_c")
+ na.output(result_method_d, parties[1], "my_output_method_d")
)
100 changes: 100 additions & 0 deletions tests/shuffle_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
---
program: shuffle
inputs:
A_7: 7
B_3: 3
A_1: 1
A_0: 0
B_4: 4
B_7: 7
C_4: 4
C_1: 1
C_6: 6
C_2: 2
C_0: 0
C_3: 3
C_5: 5
A_3: 3
A_2: 2
C_7: 7
B_0: 0
B_2: 2
B_1: 1
B_6: 6
A_5: 5
A_6: 6
A_4: 4
B_5: 5
D_0: 0
D_1: 1
D_2: 2
D_3: 3
D_4: 4
D_5: 5
D_6: 6
D_7: 7
expected_outputs:
my_output_a_0: 0
my_output_b_2: 0
my_output_c_3: 0
my_output_c_6: 0
my_output_a_2: 0
my_output_a_6: 0
my_output_a_1: 0
my_output_b_7: 0
my_output_a_7: 0
my_output_b_3: 0
my_output_c_0: 0
my_output_c_1: 0
my_output_b_0: 0
my_output_b_4: 0
my_output_c_2: 0
my_output_c_4: 0
my_output_c_7: 0
my_output_c_5: 0
my_output_b_6: 0
my_output_b_5: 0
my_output_a_4: 0
my_output_a_3: 0
my_output_b_1: 0
my_output_a_5: 0
my_output_d_0: 0
my_output_d_1: 0
my_output_d_2: 0
my_output_d_3: 0
my_output_d_4: 0
my_output_d_5: 0
my_output_d_6: 0
my_output_d_7: 0
my_output_method_a_0: 0
my_output_method_a_1: 0
my_output_method_a_2: 0
my_output_method_a_3: 0
my_output_method_a_4: 0
my_output_method_a_5: 0
my_output_method_a_6: 0
my_output_method_a_7: 0
my_output_method_b_0: 0
my_output_method_b_1: 0
my_output_method_b_2: 0
my_output_method_b_3: 0
my_output_method_b_4: 0
my_output_method_b_5: 0
my_output_method_b_6: 0
my_output_method_b_7: 0
my_output_method_c_0: 0
my_output_method_c_1: 0
my_output_method_c_2: 0
my_output_method_c_3: 0
my_output_method_c_4: 0
my_output_method_c_5: 0
my_output_method_c_6: 0
my_output_method_c_7: 0
my_output_method_d_0: 0
my_output_method_d_1: 0
my_output_method_d_2: 0
my_output_method_d_3: 0
my_output_method_d_4: 0
my_output_method_d_5: 0
my_output_method_d_6: 0
my_output_method_d_7: 0

0 comments on commit 58e9436

Please sign in to comment.