[python-arrayfire] 09/58: Fixes to monte carlo 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 2baa648e69c47db2c762dddacb375b6d3cb71399
Author: Dzhelil Rufat <drufat at caltech.edu>
Date: Mon May 2 12:21:43 2016 -0700
Fixes to monte carlo example
---
examples/benchmarks/monte_carlo_pi.py | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/examples/benchmarks/monte_carlo_pi.py b/examples/benchmarks/monte_carlo_pi.py
index 93e3931..f3198d4 100755
--- a/examples/benchmarks/monte_carlo_pi.py
+++ b/examples/benchmarks/monte_carlo_pi.py
@@ -11,10 +11,14 @@
from random import random
from time import time
-import numpy as np
import arrayfire as af
import sys
+try:
+ import numpy as np
+except:
+ np = None
+
#alias range / xrange because xrange is faster than range in python2
try:
frange = xrange #Python2
@@ -32,8 +36,8 @@ def calc_pi_device(samples):
def calc_pi_numpy(samples):
np.random.seed(1)
- x = np.random.rand(samples)
- y = np.random.rand(samples)
+ x = np.random.rand(samples).astype(np.float32)
+ y = np.random.rand(samples).astype(np.float32)
return 4 * np.sum(in_circle(x, y)) / samples
def calc_pi_host(samples):
@@ -58,5 +62,6 @@ if __name__ == "__main__":
af.info()
bench(calc_pi_device)
- bench(calc_pi_numpy)
+ if np:
+ 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