-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_tests.ipy
51 lines (43 loc) · 1.87 KB
/
run_tests.ipy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
## require to run in ipython
import numpy as np
import testpython as tp
n = 60000
imin = 12; imax = 1500
all = np.random.randint(imin, imax, n).astype('i') #population
size = 5000
prob = all / float(all.sum())
nagents = 5000
nalts = 10
sample_size = (nagents, nalts)
#sample = probsample_noreplace(n, size, prob, return_index=True)
print "probsample_noreplace in python[current]:"
%timeit tp.probsample_noreplace(n, size, prob, return_index=True)
#import testcython as tc
R = np.random.uniform(size=size)
sample = np.zeros(size, dtype='i')
#ps.ProbSampleNoReplace(n, prob, R, size, sample)
#print "ProbSampleNoReplace in cython:"
#%timeit tc.ProbSampleReplaceVec(n, prob, size, sample)
if np.__version__ >= '2.0.0':
import numpy.random.mtrand as mtrand
print "ProbSample NoReplace in mtrand:"
%timeit mtrand.choice(n, size=size, replace=False, p=prob)
else:
print 'numpy version lower than 2.0.0; mtrand testing skipped'
COMMENTED = \
"""
results = np.zeros(shape=sample_size, dtype='i')
print "prob2dsample in python (iterate by row):"
%timeit -n2 -r3 tp.prob2dsample(all, nagents, nalts, prob, results)
results = np.zeros(shape=sample_size, dtype='i')
#tc.prob2dsample(all, nagents, nalts, prob, exclude_index=None, replace=0, results=results)
print "prob2dsample in cython (iterate by row):"
%timeit -n2 -r3 tc.prob2dsample(all, nagents, nalts, prob, exclude_index=None, replace=0, results=results)
from opus_core.sampling_toolbox import prob2dsample
#results = prob2dsample(all, sample_size, prob, return_index=True)
print "prob2dsample in python(iterate by col)[current]:"
%timeit -n2 -r3 prob2dsample(all, sample_size, prob, return_index=True)
#results = np.zeros(shape=sample_size, dtype='i')
#tc.prob2dsample2(all, nagents, nalts, prob, exclude_index=None, replace=0, results=results)
#%timeit -n2 -r3 tc.prob2dsample2(all, nagents, nalts, prob, exclude_index=None, replace=0, results=results)
"""