Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

answered 2011-03-04 12:04:47 -0500

DSM gravatar image

Assuming you mean convert this function to Cython, I'm not sure whether it will help.

First, I get

sage: time z = myfisher_mp(1286, 9548, 133437, 148905)
CPU times: user 1.56 s, sys: 0.00 s, total: 1.56 s
Wall time: 1.60 s
sage: z
4.191535038879969055586166e-1316

Is that right? Almost all of the computations in the loops over i in the function don't matter to the final value because they're too small.

Second, you only get real benefits from Cython when the work can be pushed into C. If that values are so small, though, C floats won't work, as they'll underflow. And it's not that most of the time is being spent in the Python loops, which are linear anyway-- the vast majority of the time is being spent in the gamma function itself, which is already pretty fast.

sage: load "fisherfast.sage"
Time: CPU 1.61 s, Wall: 1.62 s
time in gamma: 1.50308275223
sage: timeit('z=mpmath.gamma(100000)')
625 loops, best of 3: 50.9 µs per loop

Do you have a link to the definition of this function? I'm sure we can find a way to compute it more efficiently, especially given how many terms are currently noncontributing.

Assuming you mean convert this function to Cython, I'm not sure whether it will help.

First, I get

sage: time z = myfisher_mp(1286, 9548, 133437, 148905)
CPU times: user 1.56 s, sys: 0.00 s, total: 1.56 s
Wall time: 1.60 s
sage: z
4.191535038879969055586166e-1316

Is that right? Almost all of the computations in the loops over i in the function don't matter to the final value because they're too small.

Second, you only get real benefits from Cython when the work can be pushed into C. If that the values are so small, though, C floats won't work, as they'll underflow. And it's not that most of the time is being spent in the Python loops, which are linear anyway-- anyway: the vast majority of the time is being spent in the gamma function itself, which is already pretty fast.

sage: load "fisherfast.sage"
Time: CPU 1.61 s, Wall: 1.62 s
time in gamma: 1.50308275223
sage: timeit('z=mpmath.gamma(100000)')
625 loops, best of 3: 50.9 µs per loop

Do you have a link to the definition of this function? I'm sure we can find a way to compute it more efficiently, especially given how many terms are currently noncontributing.

Assuming you mean convert this function to Cython, Cython [ah, you do, it's only the title that's wrong-- edited], I'm not sure whether it will help.

First, I get

sage: time z = myfisher_mp(1286, 9548, 133437, 148905)
CPU times: user 1.56 s, sys: 0.00 s, total: 1.56 s
Wall time: 1.60 s
sage: z
4.191535038879969055586166e-1316

Is that right? Almost all of the computations in the loops over i in the function don't matter to the final value because they're too small.

Second, you only get real benefits from Cython when the work can be pushed into C. If the values are so small, though, C floats won't work, as they'll underflow. And it's not that most of the time is being spent in the Python loops, which are linear anyway: the vast majority of the time is being spent in the gamma function itself, which is already pretty fast.

sage: load "fisherfast.sage"
Time: CPU 1.61 s, Wall: 1.62 s
time in gamma: 1.50308275223
sage: timeit('z=mpmath.gamma(100000)')
625 loops, best of 3: 50.9 µs per loop

Do you have a link to the definition of this function? I'm sure we can find a way to compute it more efficiently, especially given how many terms are currently noncontributing.

Assuming you mean convert this function to Cython [ah, you do, it's only the title that's wrong-- edited], I'm not sure whether it will help.

First, I get

sage: time z = myfisher_mp(1286, 9548, 133437, 148905)
CPU times: user 1.56 s, sys: 0.00 s, total: 1.56 s
Wall time: 1.60 s
sage: z
4.191535038879969055586166e-1316

Is that right? Almost all of the computations in the loops over i in the function don't matter to the final value because they're too small.

Second, you only get real benefits from Cython when the work can be pushed into C. If the values are so small, though, C floats won't work, as they'll underflow. And it's not that most of the time is being spent in the Python loops, which are linear anyway: the vast majority of the time is being spent in the gamma function itself, which is already pretty fast.

sage: load "fisherfast.sage"
Time: CPU 1.61 s, Wall: 1.62 s
time in gamma: 1.50308275223
timeit('z=mpmath.gamma(100)')
625 loops, best of 3: 5.67 µs per loop
sage: timeit('z=mpmath.gamma(100000)')
625 loops, best of 3: 50.9 µs per loop

Do you have a link to the definition of this function? I'm sure we can find a way to compute it more efficiently, especially given how many terms are currently noncontributing.