Skip to content

Commit

Permalink
feat: add shuffling example
Browse files Browse the repository at this point in the history
  • Loading branch information
oceans404 committed Sep 5, 2024
1 parent c6cd32b commit 34d8bb2
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
53 changes: 53 additions & 0 deletions docs/nada-by-example/shuffle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Shuffle

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import TestProgram from '@site/src/components/TestProgram/index';


## Simple Shuffle

This example uses the [nada-numpy](/nada-numpy-introduction) shuffle implementation to shuffle an array of four secret integers and return the shuffled values. This process preserves the original elements but places them in a different order.

<Tabs>

<TabItem value="program" label="Nada program" default>
```python reference showGithubLink
https://github.com/NillionNetwork/nada-by-example/blob/main/src/shuffle_simple.py
```
</TabItem>

<TabItem value="test" label="Test">
```yaml reference showGithubLink
https://github.com/NillionNetwork/nada-by-example/blob/main/tests/shuffle_simple_test.yaml
```
</TabItem>
<TabItem value="nada_test" label="nada-test">
```python reference showGithubLink
https://github.com/NillionNetwork/nada-by-example/blob/main/tests/shuffle_simple_test.py
```
</TabItem>
</Tabs>

<TestProgram programName="shuffle_simple" testFileName="shuffle_simple_test"/>

## More Shuffle Examples

This example demonstrates how the [nada-numpy](/nada-numpy-introduction) shuffling operation supports multiple data types, including Rational, SecretRational, PublicInteger, and SecretInteger. Shuffling can be applied using two approaches: the `shuffle()` function or the built-in `.shuffle()` method on arrays.

<Tabs>

<TabItem value="program" label="Nada program" default>
```python reference showGithubLink
https://github.com/NillionNetwork/nada-by-example/blob/main/src/shuffle.py
```
</TabItem>

<TabItem value="test" label="Test">
```yaml reference showGithubLink
https://github.com/NillionNetwork/nada-by-example/blob/main/tests/shuffle_test.yaml
```
</TabItem>
</Tabs>

<TestProgram programName="shuffle" testFileName="shuffle_test"/>
1 change: 1 addition & 0 deletions sidebar-nada-by-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ module.exports = [
'nada-by-example/reduce',
'nada-by-example/random-number',
'nada-by-example/linear-scan',
'nada-by-example/shuffle',
'nada-by-example/square-root',
'nada-by-example/cube-root',
'nada-by-example/arg-max',
Expand Down

0 comments on commit 34d8bb2

Please sign in to comment.