def breakage(method='python', it=100000): 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.breakagefunc(x, y, k, *args) cython_res = lognormal_cy.breakagefunc(x, y, 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.breakagefunc(x, y, 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.breakagefunc(x, y, k, args) toc = time.time() total += toc - tic aver_time = total / it * 1e6 print('breakage function takes %5.2f \u03BCs.' % aver_time)
def particle_number(x, k, *args): res = quad(lambda a: breakagefunc(a, x, k, args), 0, x)[0] return res
def num_integrand(x, y, k, *args): return x**3 * selectionfunc(y, k, args) * breakagefunc(x, y, k, args)