-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
By submitting this pull request, I confirm that my contribution is made under the terms of the [MIT license](https://github.com/dafny-lang/dafny/blob/master/LICENSE.txt).
- Loading branch information
1 parent
c86989e
commit 88f1dab
Showing
9 changed files
with
125 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: 'Build Python' | ||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
push: | ||
branches: | ||
- 'main' | ||
jobs: | ||
build-python: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- run: bash scripts/prep.sh | ||
- run: DAFNY=dafny/dafny TARGET_LANG=py bash scripts/build.sh | ||
- run: build/py/run.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: 'Run Python tests' | ||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
push: | ||
branches: | ||
- 'main' | ||
jobs: | ||
test-python: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- run: bash scripts/prep.sh | ||
- run: DAFNY=dafny/dafny TARGET_LANG=py bash scripts/test.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#1/bin/bash | ||
|
||
PYTHONPATH=.:build/py/DafnyVMC-py python3 docs/py/BuildTest.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import DafnyVMC | ||
|
||
def main(): | ||
arr1 = [0, 1, 2] | ||
arr2 = [float(0), float(1), float(2)] | ||
arr3 = ["aa", "bb", "cc"] | ||
arr4 = ['a', 'b', 'c'] | ||
arr5 = [True, False, False, True] | ||
num = 3 | ||
den = 5 | ||
|
||
# STANDARD RNG | ||
print("\nSTANDARD RNG TESTS\n") | ||
|
||
r = DafnyVMC.Random() | ||
|
||
print("Example of Uniform sampling") | ||
print(r.UniformSample(4)) | ||
|
||
print("Example of Bernoulli sampling") | ||
print(r.BernoulliSample(num,den)) | ||
|
||
print("Example of BernoulliExpNeg sampling") | ||
print(r.BernoulliExpNegSample(num,den)) | ||
|
||
print("Example of DiscreteGaussian sampling") | ||
print(r.DiscreteGaussianSample(num,den)) | ||
|
||
print("Example of DiscreteLaplace sampling") | ||
print(r.DiscreteLaplaceSample(num,den)) | ||
|
||
print("Example of Fisher-Yates: int") | ||
arr1 = r.Shuffle(arr1) | ||
print(arr1) | ||
|
||
print("Example of Fisher-Yates: float") | ||
arr2 = r.Shuffle(arr2) | ||
print(arr2) | ||
|
||
print("Example of Fisher-Yates: str") | ||
arr3 = r.Shuffle(arr3) | ||
print(arr3) | ||
|
||
print("Example of Fisher-Yates: char/str") | ||
arr4 = r.Shuffle(arr4) | ||
print(arr4) | ||
|
||
print("Example of Fisher-Yates: boolean") | ||
arr5 = r.Shuffle(arr5) | ||
print(arr5) | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Module: DafnyVMC | ||
|
||
import secrets | ||
import _dafny | ||
import DafnyVMCPart | ||
|
||
def ArrayFromList(l): | ||
arr = _dafny.Array(None, len(l)) | ||
for i, e in enumerate(l): | ||
arr[i] = e | ||
return arr | ||
|
||
class Random(DafnyVMCPart.Random): | ||
def Shuffle(self, xs): | ||
a = ArrayFromList(xs) | ||
DafnyVMCPart.Random.Shuffle(self, a) | ||
return list(a) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Module: DafnyVMCPartMaterial | ||
|
||
import secrets | ||
|
||
class Random: | ||
def UniformPowerOfTwoSample(n): | ||
return secrets.randbits(n.bit_length()-1) |