Repository navigation
Closed
Labels
3.7 (EOL)end of lifeend of lifeextension-modulesC modules in the Modules dirC modules in the Modules dirtype-featureA feature request or enhancementA feature request or enhancement
Description
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 = None
closed_at = <Date 2017-03-12.12:23:40.722>
created_at = <Date 2016-01-15.11:42:15.479>
labels = ['extension-modules', 'type-feature', '3.7']
title = 'Use C99 functions in math if available'
updated_at = <Date 2017-09-15.16:57:46.090>
user = 'https://github.com/serhiy-storchaka'bugs.python.org fields:
activity = <Date 2017-09-15.16:57:46.090>
actor = 'paulromano'
assignee = 'none'
closed = True
closed_date = <Date 2017-03-12.12:23:40.722>
closer = 'serhiy.storchaka'
components = ['Extension Modules']
creation = <Date 2016-01-15.11:42:15.479>
creator = 'serhiy.storchaka'
dependencies = []
files = ['41623']
hgrepos = []
issue_num = 26121
keywords = ['patch']
message_count = 15.0
messages = ['258288', '258293', '258505', '258508', '289099', '289457', '289478', '289486', '289487', '289491', '289494', '289499', '290199', '290201', '290225']
nosy_count = 4.0
nosy_names = ['mark.dickinson', 'christian.heimes', 'zach.ware', 'serhiy.storchaka']
pr_nums = ['515', '632', '637', '703', '3603']
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue26121'
versions = ['Python 3.7']Metadata
Metadata
Assignees
Labels
3.7 (EOL)end of lifeend of lifeextension-modulesC modules in the Modules dirC modules in the Modules dirtype-featureA feature request or enhancementA feature request or enhancement
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