10000 BUG: Fixes for building on Cygwin. by DWesl · Pull Request #16246 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: Fixes for building on Cygwin. #16246

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 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
1a2292f
Don't add `gfortran` to the list of GNU77 compilers
DWesl May 29, 2020
20df822
Include only 'gfortran' in gnu fcompiler, not absolute version
DWesl Jun 6, 2020
52b9ed5
Merge branch 'master' into cygwin-fixes
DWesl Jul 9, 2020
6a16452
TST: Use usual names for the dtypes in xfail mark
DWesl Jul 9, 2020
92eaff3
BLD: Remind GCC that .seh_savexmm fails for xmm16-31.
DWesl Jun 17, 2020
d9c21bb
BLD: Fix code checking for old GCC on cygwin.
DWesl Jun 19, 2020
eca1e27
TST: Only mark fork()-using tests xfail on 32-bit cygwin.
DWesl Jun 19, 2020
6ffbcb2
BLD: Fix flags added to compiler line for old GCC on MS.
DWesl Jun 19, 2020
5adbca1
TST: parametrize test_npymath_complex.
DWesl Jul 9, 2020
51fbbb8
TST: Clarify the xfail messages for branch cuts.
DWesl Aug 29, 2020
f47f315
BLD: Remove probably-unnecessary include.
DWesl Aug 29, 2020
5cb8a0f
TST: Try to keep testing code from changing tempfile name.
DWesl Aug 23, 2020
ced41b5
BLD: Mark modfl as problematic on cygwin.
DWesl Aug 29, 2020
d706499
Undef HAVE_MODFL only on 64-bit cygwin
DWesl Sep 1, 2020
160fd73
Revert "BLD: Fix flags added to compiler line for old GCC on MS."
DWesl Oct 27, 2020
cc9e8df
Revert "BLD: Fix code checking for old GCC on cygwin."
DWesl Oct 27, 2020
e18c4b6
Revert "BLD: Remind GCC that .seh_savexmm fails for xmm16-31."
DWesl Oct 27, 2020
4abffbd
Merge branch 'master' into cygwin-fixes
charris Dec 31, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
8000
Diff view
1 change: 1 addition & 0 deletions numpy/core/include/numpy/npy_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#ifndef NPY_USE_NEW_CASTINGIMPL
#define NPY_USE_NEW_CASTINGIMPL 0
#endif

/*
* using static inline modifiers when defining npy_math functions
* allows the compiler to make optimizations when possible
Expand Down
54 changes: 54 additions & 0 deletions numpy/core/src/common/npy_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,60 @@
#endif
#endif /* defined(_MSC_VER) && defined(__INTEL_COMPILER) */

/* Disable functions that give undesired floating-point outputs on
Cygwin. */
#ifdef __CYGWIN__

#undef HAVE_CABS
#undef HAVE_CABSF
#undef HAVE_CABSL

/* These work for me in C++, even for the failing test case (2 ** 29),
but the tests fail. No idea if the functions I'm getting are used
or not. */
#undef HAVE_LOG2
#undef HAVE_LOG2F
#undef HAVE_LOG2L

/* Complex square root does not use sign of zero to find branch
cuts. */
#undef HAVE_CSQRT
#undef HAVE_CSQRTF
#undef HAVE_CSQRTL

/* C++ Real asinh works fine, complex asinh says asinh(1e-20+0j) =
0 */
#undef HAVE_CASINH
#undef HAVE_CASINHF
#undef HAVE_CASINHL

/* _check_branch_cut(np.arcsin, ...) fails */
#undef HAVE_CASIN
#undef HAVE_CASINF
#undef HAVE_CASINL

/* Branch cuts for arccosine also fail */
#undef HAVE_CACOS
#undef HAVE_CACOSF
#undef HAVE_CACOSL

/* Branch cuts for arctan fail as well */
#undef HAVE_CATAN
#undef HAVE_CATANF
#undef HAVE_CATANL

/* check_loss_of_precision fails in arctanh */
#undef HAVE_CATANH
#undef HAVE_CATANHF
#undef HAVE_CATANHL

/* modfl segfaults on 64-bit Cygwin 3.1.5-3.1.7 */
#ifdef __x86_64__
#undef HAVE_MODFL
#endif

#endif

/* powl gives zero division warning on OS X, see gh-8307 */
#if defined(HAVE_POWL) && defined(NPY_OS_DARWIN)
#undef HAVE_POWL
Expand Down
45 changes: 29 additions & 16 deletions numpy/core/tests/test_multiarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -8576,23 +8576,36 @@ class MyAlwaysEqualNew(MyAlwaysEqual):
assert_equal(array != my_always_equal, 'ne')


def test_npymath_complex():
@pytest.mark.parametrize(
["fun", "npfun", "x", "y", "dtype"],
[
pytest.param(
fun, npfun, x, y, dtype, marks=pytest.mark.xfail(
sys.platform == "cygwin" and
dtype in (np.clongdouble,) and
fun == _multiarray_tests.npy_cabs and
np.isinf([x, y]).any() and np.isnan([x, y]).any(),
reason='abs(inf+nanj) short-circuits to inf',
strict=True,
)
)
for (fun, npfun), x, y, dtype in itertools.product(
[
(_multiarray_tests.npy_cabs, np.absolute),
(_multiarray_tests.npy_carg, np.angle),
],
[1, np.inf, -np.inf, np.nan],
[1, np.inf, -np.inf, np.nan],
[np.complex64, np.complex128, np.clongdouble],
)
],
)
def test_npymath_complex(fun, npfun, x, y, dtype):
# Smoketest npymath functions
from numpy.core._multiarray_tests import (
npy_cabs, npy_carg)

funcs = {npy_cabs: np.absolute,
npy_carg: np.angle}
vals = (1, np.inf, -np.inf, np.nan)
types = (np.complex64, np.complex128, np.clongdouble)

for fun, npfun in funcs.items():
for x, y in itertools.product(vals, vals):
for t in types:
z = t(complex(x, y))
got = fun(z)
expected = npfun(z)
assert_allclose(got, expected)
z = dtype(complex(x, y))
got = fun(z)
expected = npfun(z)
assert_allclose(got, expected)


def test_npymath_real():
Expand Down
6 changes: 6 additions & 0 deletions numpy/core/tests/test_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,12 @@ def assert_op_raises_fpe(self, fpeerr, flop, sc1, sc2):
self.assert_raises_fpe(fpeerr, flop, sc1, sc2[()])
self.assert_raises_fpe(fpeerr, flop, sc1[()], sc2[()])

@pytest.mark.xfail(
sys.platform == "cygwin",
reason="complex256(2 ** (2 ** nexp_256)) is inf+infj without OverflowError",
raises=AssertionError,
strict=True,
)
def test_floating_exceptions(self):
# Test basic arithmetic function errors
with np.errstate(all='raise'):
Expand Down
87 changes: 61 additions & 26 deletions numpy/core/tests/test_scalarmath.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,32 +653,67 @@ def test_result(self):


class TestAbs:
def _test_abs_func(self, absfunc):
for tp in floating_types + complex_floating_types:
x = tp(-1.5)
assert_equal(absfunc(x), 1.5)
x = tp(0.0)
res = absfunc(x)
# assert_equal() checks zero signedness
assert_equal(res, 0.0)
x = tp(-0.0)
res = absfunc(x)
assert_equal(res, 0.0)

x = tp(np.finfo(tp).max)
assert_equal(absfunc(x), x.real)

x = tp(np.finfo(tp).tiny)
assert_equal(absfunc(x), x.real)

x = tp(np.finfo(tp).min)
assert_equal(absfunc(x), -x.real)

def test_builtin_abs(self):
self._test_abs_func(abs)

def test_numpy_abs(self):
self._test_abs_func(np.abs)
def _test_abs_func(self, absfunc, tp):
x = tp(-1.5)
assert_equal(absfunc(x), 1.5)
x = tp(0.0)
res = absfunc(x)
# assert_equal() checks zero signedness
assert_equal(res, 0.0)
x = tp(-0.0)
res = absfunc(x)
assert_equal(res, 0.0)

x = tp(np.finfo(tp).max)
assert_equal(absfunc(x), x.real)

x = tp(np.finfo(tp).tiny)
assert_equal(absfunc(x), x.real)

x = tp(np.finfo(tp).min)
assert_equal(absfunc(x), -x.real)

@pytest.mark.parametrize(
"dtype",
[
pytest.param(
dtype,
marks=(
pytest.mark.xfail(
sys.platform == 'cygwin',
reason='abs(np.complex256.max) overflows',
raises=AssertionError,
strict=True,
)
if sys.platform == 'cygwin' and dtype == np.complex256 else ()
)
)
for dtype in floating_types + complex_floating_types
],
)
def test_builtin_abs(self, dtype):
self._test_abs_func(abs, dtype)

@pytest.mark.parametrize(
"dtype",
[
pytest.param(
dtype,
marks=(
pytest.mark.xfail(
sys.platform == 'cygwin',
reason='abs(np.complex256.max) overflows',
raises=RuntimeWarning,
strict=True,
)
if sys.platform == 'cygwin' and dtype == np.complex256 else ()
)
)
for dtype in floating_types + complex_floating_types
],
)
def test_numpy_abs(self, dtype):
self._test_abs_func(np.abs, dtype)


class TestBitShifts:
Expand Down
10 changes: 10 additions & 0 deletions numpy/core/tests/test_umath.py
Original file line number Diff line number Diff line change
Expand Up @@ -3011,6 +3011,11 @@ def test_precisions_consistent(self):
assert_almost_equal(fcf, fcd, decimal=6, err_msg='fch-fcd %s' % f)
assert_almost_equal(fcl, fcd, decimal=15, err_msg='fch-fcl %s' % f)

@pytest.mark.xfail(
sys.platform == 'cygwin',
reason='Cygwin does not use the sign of zero for branch cuts along an axis',
strict=True,
)
def test_branch_cuts(self):
# check branch cuts and continuity on them
_check_branch_cut(np.log, -0.5, 1j, 1, -1, True)
Expand All @@ -3036,6 +3041,11 @@ def test_branch_cuts(self):
_check_branch_cut(np.arccosh, [0-2j, 2j, 2], [1, 1, 1j], 1, 1)
_check_branch_cut(np.arctanh, [0-2j, 2j, 0], [1, 1, 1j], 1, 1)

@pytest.mark.xfail(
sys.platform == 'cygwin',
reason='Cygwin does not use sign of zero for branch cuts along an axis',
strict=True,
)
def test_branch_cuts_complex64(self):
# check branch cuts and continuity on them
_check_branch_cut(np.log, -0.5, 1j, 1, -1, True, np.complex64)
Expand Down
2 changes: 1 addition & 1 deletion numpy/distutils/fcompiler/gnu.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def get_flags_arch(self):
return []

def runtime_library_dir_option(self, dir):
if sys.platform == 'win32':
if sys.platform == 'win32' or sys.platform == 'cygwin':
# Linux/Solaris/Unix support RPATH, Windows does not
raise NotImplementedError

Expand Down
2 changes: 1 addition & 1 deletion numpy/distutils/tests/test_system_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def test_overrides(self):

# Also, the values will be taken from a section named '[DEFAULT]'
with open(cfg, 'r') as fid:
dflt = fid.read().replace('mkl', 'DEFAULT')
dflt = fid.read().replace('[mkl]', '[DEFAULT]', 1)
with open(cfg, 'w') as fid:
fid.write(dflt)
info = mkl_info()
Expand Down
7 changes: 7 additions & 0 deletions numpy/f2py/tests/test_compile_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import numpy.f2py

from numpy.testing import assert_equal
from numpy.testing._private.utils import IS_32BIT_CYGWIN
from . import util


Expand All @@ -26,6 +27,8 @@ def setup_module():
"extra_args", [['--noopt', '--debug'], '--noopt --debug', '']
)
@pytest.mark.leaks_references(reason="Imported module seems never deleted.")
@pytest.mark.xfail(IS_32BIT_CYGWIN, reason="Random fork failures",
raises=BlockingIOError)
def test_f2py_init_compile(extra_args):
# flush through the f2py __init__ compile() function code path as a
# crude test for input handling following migration from
Expand Down Expand Up @@ -83,6 +86,8 @@ def test_f2py_init_compile(extra_args):
del sys.modules[modname]


@pytest.mark.xfail(IS_32BIT_CYGWIN, reason="Random fork failures",
raises=BlockingIOError)
def test_f2py_init_compile_failure():
# verify an appropriate integer status value returned by
# f2py.compile() when invalid Fortran is provided
Expand Down Expand Up @@ -111,6 +116,8 @@ def test_f2py_init_compile_bad_cmd():
@pytest.mark.parametrize('fsource',
['program test_f2py\nend program test_f2py',
b'program test_f2py\nend program test_f2py',])
@pytest.mark.xfail(IS_32BIT_CYGWIN, reason="Random fork failures",
raises=BlockingIOError)
def test_compile_from_strings(tmpdir, fsource):
# Make sure we can compile str and bytes gh-12796
cwd = os.getcwd()
Expand Down
7 changes: 7 additions & 0 deletions numpy/f2py/tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from numpy.compat import asbytes, asstr
from numpy.testing import temppath
from numpy.testing._private.utils import IS_32BIT_CYGWIN
from importlib import import_module

#
Expand Down Expand Up @@ -317,6 +318,12 @@ class F2PyTest:
module = None
module_name = None

# Pytest seems to ignore this, but I'm not sure where else to put
# it, besides trying to make a metaclass that decorates every
# method of a subclass of F2PyTest
@pytest.mark.xfail(IS_32BIT_CYGWIN,
reason='Fork() randomly fails on cygwin',
raises=BlockingIOError)
def setup(self):
if sys.platform == 'win32':
pytest.skip('Fails with MinGW64 Gfortran (Issue #9673)')
Expand Down
3 changes: 3 additions & 0 deletions numpy/linalg/tests/test_linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1837,6 +1837,9 @@ def test_xerbla_override():


@pytest.mark.slow
@pytest.mark.xfail(sys.platform == 'cygwin',
reason='Fork() fails randomly on cygwin',
raises=BlockingIOError)
def test_sdot_bug_8577():
# Regression test that loading certain other libraries does not
# result to wrong results in float32 linear algebra.
Expand Down
2 changes: 1 addition & 1 deletion numpy/random/src/distributions/random_hypergeometric.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <stdint.h>
#include "numpy/random/distributions.h"
#include "logfactorial.h"
#include <stdint.h>

/*
* Generate a sample from the hypergeometric distribution.
Expand Down
4 changes: 4 additions & 0 deletions numpy/random/tests/test_extending.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys
import warnings
import numpy as np
from numpy.testing._private.utils import IS_32BIT_CYGWIN

try:
import cffi
Expand Down Expand Up @@ -42,6 +43,9 @@

@pytest.mark.skipif(cython is None, reason="requires cython")
@pytest.mark.slow
@pytest.mark.xfail(IS_32BIT_CYGWIN,
reason="Random fork() failures",
raises=BlockingIOError)
def test_cython(tmp_path):
srcdir = os.path.join(os.path.dirname(__file__), '..')
shutil.copytree(srcdir, tmp_path / 'random')
Expand Down
3 changes: 2 additions & 1 deletion numpy/testing/_private/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
'SkipTest', 'KnownFailureException', 'temppath', 'tempdir', 'IS_PYPY',
'HAS_REFCOUNT', 'suppress_warnings', 'assert_array_compare',
'_assert_valid_refcount', '_gen_alignment_data', 'assert_no_gc_cycles',
'break_cycles', 'HAS_LAPACK64'
'break_cycles', 'HAS_LAPACK64', 'IS_32BIT_CYGWIN'
]


Expand All @@ -48,6 +48,7 @@ class KnownFailureException(Exception):
verbose = 0

IS_PYPY = platform.python_implementation() == 'PyPy'
IS_32BIT_CYGWIN = (sys.platform == 'cygwin' and (sys.maxsize >> 30) == 1)
HAS_REFCOUNT = getattr(sys, 'getrefcount', None) is not None
HAS_LAPACK64 = numpy.linalg.lapack_lite._ilp64

Expand Down
3 changes: 3 additions & 0 deletions numpy/tests/test_public_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import numpy as np
import numpy
from numpy.testing._private.utils import IS_32BIT_CYGWIN
import pytest

try:
Expand Down Expand Up @@ -77,6 +78,8 @@ def test_numpy_namespace():


@pytest.mark.parametrize('name', ['testing', 'Tester'])
@pytest.mark.xfail(IS_32BIT_CYGWIN, reason="Random fork failures",
raises=BlockingIOError)
def test_import_lazy_import(name):
"""Make sure we can actually use the modules we lazy load.

Expand Down
Loading
0