Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why slower than gsl on the same precision? And Which results are right? #354

Open
yixin-09 opened this issue Apr 27, 2017 · 3 comments
Open

Comments

@yixin-09
Copy link

yixin-09 commented Apr 27, 2017

I simplely test the clausen function of mpmath and gsl. The code is below:

> mp.prec = 53
time_begin = time.time()
print "mpmath results:"
print clsin(2,3.1415926535897327)
print "time1:"
print (time.time() - time_begin)
time_begin = time.time()
print "gsl results:"
print gsl_sf_clausen(3.1415926535897327)
print "time2"
print (time.time() - time_begin)

The results are below:

> mpmath results:
4.19482951966115e-14
time1:
0.00391387939453
gsl results:
4.18544219761e-14
time2
2.69412994385e-05

From the results I found on the same precision, the results are very different(mpmath:4.19... but gsl:4.18...), I want to know which one is more accurarcy?
Any the mpmath more than 100 times slower than gsl_sf_clausen, why?

Thank you

@KCErb
Copy link

KCErb commented Jan 3, 2018

Not an expert on Clausen functions, but for the record Mathematica gives an answer closer to mpmath: http://www.wolframalpha.com/input/?i=Clausen+Function(2,+3.1415926535897327)

@sven-mayer
Copy link

Any idea why the function is so slow? Any fix for this problem?

@skirpichev
Copy link
Collaborator

@sven-mayer, not sure how you run above benchmarks (perhaps, with pygsl). With ctypes I got 1000x difference:

$ python -m timeit -u usec -s 'from ctypes import CDLL, c_double;l=CDLL("libgsl.so");l.gsl_sf_clausen.restype = c_double' 'l.gsl_sf_clausen(c_double(3.1415926535897327))'
100000 loops, best of 5: 2.91 usec per loop
$ python -m timeit -u usec -s 'import mpmath;c=mpmath.fp.clsin' 'c(2,3.1415926535897327)'
200 loops, best of 5: 1.03e+03 usec per loop
$ python -m timeit -u usec -s 'import mpmath;c=mpmath.clsin' 'c(2,3.1415926535897327)'
50 loops, best of 5: 8.39e+03 usec per loop

Any idea why the function is so slow?

After all, this is a pure-python function... And the algorithm used in the gsl seems to be inaccurate for this value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants