[python-arrayfire] 08/58: Contribute numpy example.
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Wed Sep 28 13:57:03 UTC 2016
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch master
in repository python-arrayfire.
commit 9e32b6e2df491ad0bc5ea467bfa452b927dac2a4
Author: Dzhelil Rufat <drufat at caltech.edu>
Date: Mon May 2 11:51:36 2016 -0700
Contribute numpy example.
---
examples/benchmarks/monte_carlo_pi.py | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/examples/benchmarks/monte_carlo_pi.py b/examples/benchmarks/monte_carlo_pi.py
index fc35b3d..93e3931 100755
--- a/examples/benchmarks/monte_carlo_pi.py
+++ b/examples/benchmarks/monte_carlo_pi.py
@@ -11,7 +11,7 @@
from random import random
from time import time
-from arrayfire import (array, randu)
+import numpy as np
import arrayfire as af
import sys
@@ -21,16 +21,21 @@ try:
except NameError:
frange = range #Python3
-
-def calc_pi_device(samples):
- x = randu(samples)
- y = randu(samples)
- return 4 * af.sum((x * x + y * y) < 1) / samples
-
# Having the function outside is faster than the lambda inside
def in_circle(x, y):
return (x*x + y*y) < 1
+def calc_pi_device(samples):
+ x = af.randu(samples)
+ y = af.randu(samples)
+ return 4 * af.sum(in_circle(x, y)) / samples
+
+def calc_pi_numpy(samples):
+ np.random.seed(1)
+ x = np.random.rand(samples)
+ y = np.random.rand(samples)
+ return 4 * np.sum(in_circle(x, y)) / samples
+
def calc_pi_host(samples):
count = sum(1 for k in frange(samples) if in_circle(random(), random()))
return 4 * float(count) / samples
@@ -53,4 +58,5 @@ if __name__ == "__main__":
af.info()
bench(calc_pi_device)
+ bench(calc_pi_numpy)
bench(calc_pi_host)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/python-arrayfire.git
More information about the debian-science-commits
mailing list