Skip to content

Commit 2baa648

Browse files
author
Dzhelil Rufat
committed
Fixes to monte carlo example
1 parent 9e32b6e commit 2baa648

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

examples/benchmarks/monte_carlo_pi.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@
1111

1212
from random import random
1313
from time import time
14-
import numpy as np
1514
import arrayfire as af
1615
import sys
1716

17+
try:
18+
import numpy as np
19+
except:
20+
np = None
21+
1822
#alias range / xrange because xrange is faster than range in python2
1923
try:
2024
frange = xrange #Python2
@@ -32,8 +36,8 @@ def calc_pi_device(samples):
3236

3337
def calc_pi_numpy(samples):
3438
np.random.seed(1)
35-
x = np.random.rand(samples)
36-
y = np.random.rand(samples)
39+
x = np.random.rand(samples).astype(np.float32)
40+
y = np.random.rand(samples).astype(np.float32)
3741
return 4 * np.sum(in_circle(x, y)) / samples
3842

3943
def calc_pi_host(samples):
@@ -58,5 +62,6 @@ def bench(calc_pi, samples=1000000, iters=25):
5862
af.info()
5963

6064
bench(calc_pi_device)
61-
bench(calc_pi_numpy)
65+
if np:
66+
bench(calc_pi_numpy)
6267
bench(calc_pi_host)

0 commit comments

Comments
 (0)