Skip to content

Commit 673131e

Browse files
committed
random.utilities: Run guvectorize only when necessary
1 parent 8755243 commit 673131e

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

quantecon/random/utilities.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,14 @@ def probvec(m, k, random_state=None, parallel=True):
5656

5757
# Parse Parallel Option #
5858
if parallel:
59+
_probvec_parallel = guvectorize(
60+
['(f8[:], f8[:])'], '(n), (k)', nopython=True, target='parallel'
61+
)(_probvec)
5962
_probvec_parallel(r, x)
6063
else:
64+
_probvec_cpu = guvectorize(
65+
['(f8[:], f8[:])'], '(n), (k)', nopython=True, target='cpu'
66+
)(_probvec)
6167
_probvec_cpu(r, x)
6268

6369
return x
@@ -88,13 +94,6 @@ def _probvec(r, out):
8894
out[i] = r[i] - r[i-1]
8995
out[n] = 1 - r[n-1]
9096

91-
_probvec_parallel = guvectorize(
92-
['(f8[:], f8[:])'], '(n), (k)', nopython=True, target='parallel'
93-
)(_probvec)
94-
_probvec_cpu = guvectorize(
95-
['(f8[:], f8[:])'], '(n), (k)', nopython=True, target='cpu'
96-
)(_probvec)
97-
9897

9998
@jit
10099
def sample_without_replacement(n, k, num_trials=None, random_state=None):

0 commit comments

Comments
 (0)