Conversation
jcabrero
left a comment
There was a problem hiding this comment.
Great work. I had never seen an implementation of Benes Networks and yours seems very clear. Two small nits:
- We could have
array.shuffle()as a primitive inarray.py. Though it may not match Numpy, I think it prevents users from not finding the available routine. - I also think this deserves an example in itself, as it is the basis for many card-games or things users may want to implement.
| # Shuffling the arrays | ||
| shuffled_a = shuffle(a) | ||
| shuffled_b = shuffle(b) | ||
| shuffled_c = shuffle(c) |
There was a problem hiding this comment.
Missing closing: ```
Ok, I will add this. Thanks. |
What do you mean by an example? I have an example in the function docs but I assume you are referring to more than that. Are you proposing to add an example to the |
|
hey @manel1874! I think @jcabrero is asking you to create an example program using shuffling in our nada-by-example repo. Then I can add it to the docs! here's how: https://github.com/NillionNetwork/nada-by-example?tab=readme-ov-file#add-a-new-example |
|
Yes, you can copy the example in the docstring both into the |
| 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 |
There was a problem hiding this comment.
@manel1874 instead of checking that shuffled_method_a - shuffled_method_a == 0, can we loop over all the elements of the original array and the shuffle version and assert that not everything is equal? (i.e., at least two have been swapped). The equality to zero doesn't guarantee us anything -- the elements may not have been swapped at all, or even we may have completely different elements, both these would pass.
There was a problem hiding this comment.
Agree! Thanks. So, ideally we would test three properties:
- Randomness: we can use your idea here. We test it by showing that at least one element is in a different position. This gives us a bit more confidence than the current method but this test might fail, although with a very low probability: the same configuration can happen with the same probability as any other.
- The elements are preserved: agree!
This PR introduces support for array shuffling for arrays with size as a power of two.
Apart from this it also:
isortchanged some ordering of the imports in some files.Tests
One test added to tests/nada-tests. It tests arrays of
Rational,SecretRational,PublicIntegerandSecretIntegerTo run them use:nada test shuffle