10000 WIP/MAINT: core: Restore float128 power on Mac OSX. by WarrenWeckesser · Pull Request #15074 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

WIP/MAINT: core: Restore float128 power on Mac OSX. #15074

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

Closed
wants to merge 1 commit into from

Conversation

WarrenWeckesser
Copy link
Member
@WarrenWeckesser WarrenWeckesser commented Dec 8, 2019

The use of the math library powl was blacklisted on Mac OSX
(gh-8318) because powl(0, y) would trigger a divide-by-zero
warning even when y > 0 (issue gh-8307).

This change creates npy_powl on OSX that avoids the spurious
warning by not calling powl when x = 0 and y > 0.

The change in npy_math_internal.h.src moves the handling
of pow out of a template repeat-loop, so powl and powf
are handled individually. This allows the creation of
npy_powl to be specialized when NPY_OS_DARWIN is defined.

Closes gh-8608.

@WarrenWeckesser WarrenWeckesser force-pushed the osxpowl branch 5 times, most recently from 7451d8a to 4df3918 Compare December 9, 2019 06:15
@WarrenWeckesser WarrenWeckesser changed the title WIP/MAINT: core: Restore float128 power on Mac OSX. MAINT: core: Restore float128 power on Mac OSX. Dec 9, 2019
# Check that we are using more than double precision.
v = np.float128(2) ** 16383
assert_allclose(v, np.float128('5.9486574767861588254e+4931'))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we expect the second test to fail on any platform with 'float128'? I.e., why not skipif(not hasattr(np, 'float128'),

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is possible that there are (or will be) other platforms that have also implemented power for float128 by falling back to the double precision version. Currently, this test will fail if it is run on the ppc64le platform on Travis-CI. So for now, the test is restricted to Mac OSX/Darwin.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as we are fixing, could we fix it for ppy64le as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started working on this because I have a Mac, so it seemed like it would be straightforward to fix. The feclearexcept(FE_ALL_EXCEPT) hack shows that, even on the platform for which the problem was originally reported, it is not as easy as it seemed it should be. Without having a ppc64le computer to work on directly, testing and debugging means lots of guess work, and repeatedly running tests via our CI suite. That's pretty inefficient, and probably not a good use of time and computer resources.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without having a ppc64le computer to work on directly,

You should be eligible for the gcc compile farm machines, which do include ppc64le machines that are suitable for iterative work, see here: https://cfarm.tetaneutral.net/users/new/

I've been using them & they are pretty great machines.

// This shouldn't be necessary, but without it, unit tests on some
// of the Mac OSX CI platforms raise a divide-by-zero warning with
// a call such as `np.array([0, 1, 2], dtype=np.float128) ** 4`.
feclearexcept(FE_ALL_EXCEPT);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this entirely without effect for future calcalations in C / Numpy?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, and that is a problem, because the internal ufunc code only checks the flags at the end of an inner loop. For example, this should generate RuntimeWarning: invalid value encountered in power, but it does not:

In [24]: np.array([-1, 0], dtype=np.float128) ** 2.5
Out[24]: array([nan,  0.], dtype=float128)

With float64, the warning is generated:

In [25]: np.array([-1.0, 0.0]) ** 2.5
/Users/warren/mc37numpy/bin/ipython:1: RuntimeWarning: invalid value encountered in power
  #!/Users/warren/mc37numpy/bin/python
Out[25]: array([nan,  0.])

The call of feclearexcept(FE_ALL_EXCEPT) is a hack to get the tests on azure to pass. The tests pass on my computer (Mac OSX 10.12.6) without that call, and I was surprised that they didn't pass on the azure Mac OSX test suite. Somehow, even with the custom version of npy_power, calling np.power with float128 data containing 0 and with positive exponents on the azure OSX platform results in a divide-by-zero warning.

P.S. I added "WIP" back to the PR title.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The macos azure image seems to be this one which is documented as using xcode 11.1 as default but also has other versions. Maybe the bug has been fixed in the version you are using?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Matti. My version is old: Xcode 9.2. (I'm running OSX 10.12.6 on a 2013 Macbook Pro. When I upgraded the OS earlier this year, I tried using a newer version of OSX but ran into problems. 10.12.6 has been working fine.)

@WarrenWeckesser WarrenWeckesser changed the title MAINT: core: Restore float128 power on Mac OSX. WIP/MAINT: core: Restore float128 power on Mac OSX. Dec 9, 2019
@WarrenWeckesser WarrenWeckesser marked this pull request as draft April 22, 2020 01:54
The use of the math library powl was blacklisted on Mac OSX
(numpygh-8318) because powl(0, y) would trigger a divide-by-zero
warning even when y > 0 (issue numpygh-8307).

This change creates npy_powl on OSX that avoids the spurious
warning by not calling powl when x = 0 and y > 0.

The change in npy_math_internal.h.src moves the handling
of pow out of a template repeat-loop, so powl and powf
are handled individually.  This allows the creation of
npy_powl to be specialized when NPY_OS_DARWIN is defined.

Closes numpygh-8608.
Base automatically changed from master to main March 4, 2021 02:04
@WarrenWeckesser
Copy link
Member Author
WarrenWeckesser commented Oct 13, 2021

It would be nice to fix the blacklisting of powl on Mac OS

/* powl gives zero division warning on OS X, see gh-8307 */
#if defined(HAVE_POWL) && defined(NPY_OS_DARWIN)
#undef HAVE_POWL
#endif

but I will not likely get back to this PR any time soon, so I'm closing it.

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

Successfully merging this pull request may close these issues.

Change in longdouble calculations in numpy >= 1.12 on OSX
4 participants
0