You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2017-03-12.12:23:40.722>created_at=<Date2016-01-15.11:42:15.479>labels= ['extension-modules', 'type-feature', '3.7']
title='Use C99 functions in math if available'updated_at=<Date2017-09-15.16:57:46.090>user='https://github.com/serhiy-storchaka'
Currently the math module uses own implementation of some mathematical functions that are in C99 standard, but not in C89 standard: tgamma, lgamma, erf, erfc. Proposed patch makes it to use functions from standard C library if they are available. They are faster and presumably more accurate.
Here are microbenchmark results (time in microseconds):
Is there some way that this can be submitted to the buildbots *before* applying to the 3.6 branch, so that we can get a sense of how widespread (if at all) libm problems are?
So the GitHub branch fails on my OS X 10.10 machine: there are a number of test failures for gamma and lgamma (but none for erf and erfc).
Some of the gamma and lgamma test failures are accuracy issues; some are more likely to do with errno handling: OS X probably isn't setting errno appropriate on domain or range errors, so any implementation using the libm lgamma/tgamma would need to add code for error handling.
Given this, I'd prefer to leave lgamma and gamma as-is, using their current implementations, at least on OS X; I don't regard the accuracy loss in using the libm functions to be within acceptable limits.
There may still be a case for using the libm versions of erf and erfc.
Please can we revert to using the existing implementations of lgamma and gamma on all platforms? It's clear that there are many issues with OS-provided implementations.
New changeset 4125e5c by Serhiy Storchaka in branch 'master': bpo-26121: Revert to using the own implementations of lgamma and gamma on all platforms. (#637) 4125e5c
New changeset 4dadcd4 by Serhiy Storchaka in branch 'master': bpo-26121: Use C library implementation for math functions erf() and erfc() on Windows. (#632) 4dadcd4
New changeset 97553fd by Mark Dickinson (Serhiy Storchaka) in branch 'master': bpo-26121: Use C library implementation for math functions: (#515) 97553fd
Activity
serhiy-storchaka commentedon Jan 15, 2016
Currently the math module uses own implementation of some mathematical functions that are in C99 standard, but not in C89 standard: tgamma, lgamma, erf, erfc. Proposed patch makes it to use functions from standard C library if they are available. They are faster and presumably more accurate.
Here are microbenchmark results (time in microseconds):
erf unpatched: 0.506 0.655 0.509 0.548 0.239
erf patched: 0.129 0.252 0.357 0.253 0.253
erfc unpatched: 0.508 0.646 0.532 0.522 0.251
erfc patched: 0.129 0.239 0.373 0.371 0.307
gamma unpatched: 0.369 0.279 0.273 0.274 0.457
gamma patched: 0.24 0.23 0.412 0.741 0.682
lgamma unpatched: 0.351 0.338 0.478 0.627 0.52
lgamma patched: 0.217 0.155 0.37 0.372 0.247
If some libm implementations are pretty bad, they can be disabled by undefining corresponding HAVE_XXX macros.
tiran commentedon Jan 15, 2016
Faster: maybe. More accurate ... Mark can tell you some funny stories. :)
mdickinson commentedon Jan 18, 2016
LGTM. What platform are the benchmarks on?
Is there some way that this can be submitted to the buildbots *before* applying to the 3.6 branch, so that we can get a sense of how widespread (if at all) libm problems are?
serhiy-storchaka commentedon Jan 18, 2016
The benchmarks were ran on 32-bit Linux with AMD processor.
I'll try to run custom build on buildbots.
serhiy-storchaka commentedon Mar 6, 2017
I don't know how to run custom build on buildbots with new workflow.
mdickinson commentedon Mar 11, 2017
So the GitHub branch fails on my OS X 10.10 machine: there are a number of test failures for gamma and lgamma (but none for erf and erfc).
Some of the gamma and lgamma test failures are accuracy issues; some are more likely to do with errno handling: OS X probably isn't setting errno appropriate on domain or range errors, so any implementation using the libm lgamma/tgamma would need to add code for error handling.
Given this, I'd prefer to leave lgamma and gamma as-is, using their current implementations, at least on OS X; I don't regard the accuracy loss in using the libm functions to be within acceptable limits.
There may still be a case for using the libm versions of erf and erfc.
serhiy-storchaka commentedon Mar 12, 2017
Tests are failed only on s390x RHEL 3.x.
http://buildbot.python.org/all/builders/s390x%20RHEL%203.x/builds/446/steps/test/logs/stdio
======================================================================
FAIL: test_mtestfile (test.test_math.MathTests)
----------------------------------------------------------------------
serhiy-storchaka commentedon Mar 12, 2017
PR 632 switch on using libc implementation on Windows. Will see how AppVeyor tests passed.
serhiy-storchaka commentedon Mar 12, 2017
There are accuracy issues with tgamma() and lgamma() on Windows. But less than on OS X.
======================================================================
FAIL: test_mtestfile (test.test_math.MathTests)
----------------------------------------------------------------------
Does this mean that we should not use libc implementations of tgamma() and lgamma() on Windows?
mdickinson commentedon Mar 12, 2017
Please can we revert to using the existing implementations of lgamma and gamma on all platforms? It's clear that there are many issues with OS-provided implementations.
serhiy-storchaka commentedon Mar 12, 2017
PR 637 revert to using the own implementations of lgamma and gamma on all platforms.
serhiy-storchaka commentedon Mar 12, 2017
Done.
serhiy-storchaka commentedon Mar 24, 2017
New changeset 4125e5c by Serhiy Storchaka in branch 'master':
bpo-26121: Revert to using the own implementations of lgamma and gamma on all platforms. (#637)
4125e5c
serhiy-storchaka commentedon Mar 24, 2017
New changeset 4dadcd4 by Serhiy Storchaka in branch 'master':
bpo-26121: Use C library implementation for math functions erf() and erfc() on Windows. (#632)
4dadcd4
mdickinson commentedon Mar 24, 2017
New changeset 97553fd by Mark Dickinson (Serhiy Storchaka) in branch 'master':
bpo-26121: Use C library implementation for math functions: (#515)
97553fd