def selection(method='python', it=10000000): import lognormal import lognormal_cy mu = np.array([1.0, 2.0, 3.0], dtype=DTYPE) sigma = np.array([2.0, 2.0, 2.0], dtype=DTYPE) x = 0.1 y = 3.0 k = np.array([0.1, 0.2, 0.3], dtype=DTYPE) args = [mu, sigma] python_res = lognormal.selectionfunc(x, k, *args) cython_res = lognormal_cy.selectionfunc(x, k, args) assert python_res == cython_res, 'Values not match' if method == 'python': total = 0 for i in range(it): tic = time.time() res = lognormal.selectionfunc(x, k, *args) toc = time.time() total += toc - tic aver_time = total / it * 1e6 print('breakage function takes %5.2f \u03BCs.' % aver_time) elif method == 'cython': total = 0 for i in range(it): tic = time.time() res = lognormal_cy.selectionfunc(x, k, args) toc = time.time() total += toc - tic aver_time = total / it * 1e6 print('breakage function takes %5.2f \u03BCs.' % aver_time)
def den_integrand(x, k, *args): return x**3 * selectionfunc(x, k, args)
def selection_integrand(x, k, *args): return (particle_number(x, k, *args) - 1) * selectionfunc(x, k, args)
def num_integrand(x, y, k, *args): return x**3 * selectionfunc(y, k, args) * breakagefunc(x, y, k, args)