Content-Length: 663262 | pFad | http://togithub.com/numpy/numpy/commit/c7e073c2bb88a94fc2de5f843dc836f33820305b

E4F BLD: fix math func feature checks, fix FreeBSD build, add CI job (#24… · numpy/numpy@c7e073c · GitHub
Skip to content

Commit c7e073c

Browse files
charrisrgommers
andauthored
BLD: fix math func feature checks, fix FreeBSD build, add CI job (#24876) (#24879)
* BLD: fix incorrect feature checks for mandatory math functions Should fix the build on FreeBSD and other OSes that are not C99-compliant. Closes gh-24873 * CI: add a FreeBSD job on Cirrus CI * BUG: define `_npy_scaled_cexpl` when ccoshl/csinhl are missing This was a regression in the 1.24.x branch, after a lot of churn in this file. In 1.22.x/1.23.x, the conditional is the same as in this fix. * TST: avoid failures for FPE errors/warnings in `abs` on BSDs Co-authored-by: Ralf Gommers <ralf.gommers@gmail.com>
1 parent d042bda commit c7e073c

File tree

7 files changed

+85
-19
lines changed

7 files changed

+85
-19
lines changed

numpy/core/meson.build

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -149,20 +149,32 @@ endif
149149
# Mandatory functions: if not found, fail the build
150150
# Some of these can still be blocklisted if the C99 implementation
151151
# is buggy, see numpy/core/src/common/npy_config.h
152-
mandatory_funcs = [
152+
mandatory_math_funcs = [
153153
'sin', 'cos', 'tan', 'sinh', 'cosh', 'tanh', 'fabs',
154154
'floor', 'ceil', 'sqrt', 'log10', 'log', 'exp', 'asin',
155155
'acos', 'atan', 'fmod', 'modf', 'frexp', 'ldexp',
156156
'expm1', 'log1p', 'acosh', 'asinh', 'atanh',
157-
'rint', 'trunc', 'exp2',
158-
'copysign', 'nextafter', 'strtoll', 'strtoull', 'cbrt',
157+
'rint', 'trunc', 'exp2', 'copysign', 'nextafter', 'cbrt',
159158
'log2', 'pow', 'hypot', 'atan2',
160-
'csin', 'csinh', 'ccos', 'ccosh', 'ctan', 'ctanh',
161-
'creal', 'cimag', 'conj'
162159
]
163-
foreach func: mandatory_funcs
164-
if not cc.has_function(func)
165-
error('Function `{func}` not found')
160+
foreach func: mandatory_math_funcs
161+
if not cc.has_function(func, prefix: '#include <math.h>', dependencies: m_dep)
162+
error(f'Function `@func@` not found')
163+
endif
164+
endforeach
165+
166+
mandatory_complex_math_funcs = [
167+
'csin', 'csinh', 'ccos', 'ccosh', 'ctan', 'ctanh', 'creal', 'cimag', 'conj'
168+
]
169+
foreach func: mandatory_complex_math_funcs
170+
if not cc.has_function(func, prefix: '#include <complex.h>', dependencies: m_dep)
171+
error(f'Function `@func@` not found')
172+
endif
173+
endforeach
174+
175+
foreach func: ['strtoll', 'strtoull']
176+
if not cc.has_function(func, prefix: '#include <stdlib.h>')
177+
error(f'Function `@func@` not found')
166178
endif
167179
endforeach
168180

@@ -177,13 +189,13 @@ c99_complex_funcs = [
177189
foreach func: c99_complex_funcs
178190
func_single = func + 'f'
179191
func_longdouble = func + 'l'
180-
if cc.has_function(func)
192+
if cc.has_function(func, prefix: '#include <complex.h>', dependencies: m_dep)
181193
cdata.set10('HAVE_' + func.to_upper(), true)
182194
endif
183-
if cc.has_function(func_single)
195+
if cc.has_function(func_single, prefix: '#include <complex.h>', dependencies: m_dep)
184196
cdata.set10('HAVE_' + func_single.to_upper(), true)
185197
endif
186-
if cc.has_function(func_longdouble)
198+
if cc.has_function(func_longdouble, prefix: '#include <complex.h>', dependencies: m_dep)
187199
cdata.set10('HAVE_' + func_longdouble.to_upper(), true)
188200
endif
189201
endforeach
@@ -192,7 +204,7 @@ endforeach
192204
# libnpymath as a C99 compat layer, these may still be relevant.
193205
c99_macros = ['isfinite', 'isinf', 'isnan', 'signbit']
194206
foreach macro: c99_macros
195-
if cc.has_function(macro)
207+
if cc.has_function(macro, prefix: '#include <math.h>', dependencies: m_dep)
196208
cdata.set10('NPY_HAVE_DECL_' + macro.to_upper(), true)
197209
if not cc.has_header_symbol('Python.h', macro, dependencies: py_dep)
198210
# Add in config.h as well, except if it will clash with Python's config.h content

numpy/core/src/npymath/npy_math_complex.c.src

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ npy_carg@c@(@ctype@ z)
158158
#define SCALED_CEXP_LOWERL 11357.216553474703895L
159159
#define SCALED_CEXP_UPPERL 22756.021937783004509L
160160

161-
#if !defined(HAVE_CEXP@C@)
161+
#if !defined(HAVE_CSINH@C@) || \
162+
!defined(HAVE_CCOSH@C@) || \
163+
!defined(HAVE_CEXP@C@)
162164

163165
static
164166
@ctype@

numpy/core/tests/test_multiarray.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9723,9 +9723,12 @@ def test_ragged_comparison_fails(op):
97239723
def test_npymath_complex(fun, npfun, x, y, test_dtype):
97249724
# Smoketest npymath functions
97259725
z = test_dtype(complex(x, y))
9726-
got = fun(z)
9727-
expected = npfun(z)
9728-
assert_allclose(got, expected)
9726+
with np.errstate(invalid='ignore'):
9727+
# Fallback implementations may emit a warning for +-inf (see gh-24876):
9728+
# RuntimeWarning: invalid value encountered in absolute
9729+
got = fun(z)
9730+
expected = npfun(z)
9731+
assert_allclose(got, expected)
97299732

97309733

97319734
def test_npymath_real():

numpy/core/tests/test_numeric.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,11 @@ def assert_op_raises_fpe(self, fpeerr, flop, sc1, sc2):
645645
@pytest.mark.skipif(IS_WASM, reason="no wasm fp exception support")
646646
@pytest.mark.parametrize("typecode", np.typecodes["AllFloat"])
647647
def test_floating_exceptions(self, typecode):
648+
if 'bsd' in sys.platform and typecode in 'gG':
649+
pytest.skip(reason="Fallback impl for (c)longdouble may not raise "
650+
"FPE errors as expected on BSD OSes, "
651+
"see gh-24876, gh-23379")
652+
648653
# Test basic arithmetic function errors
649654
with np.errstate(all='raise'):
650655
ftype = np.obj2sctype(typecode)

numpy/core/tests/test_umath.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,6 +1646,8 @@ def test_sinh(self):
16461646
np.array(1200.0, dtype='d'))
16471647

16481648
@pytest.mark.skipif(IS_WASM, reason="fp errors don't work in wasm")
1649+
@pytest.mark.skipif('bsd' in sys.platform,
1650+
reason="fallback implementation may not raise, see gh-2487")
16491651
def test_cosh(self):
16501652
in_ = [np.nan, -np.nan, np.inf, -np.inf]
16511653
out = [np.nan, np.nan, np.inf, np.inf]

numpy/core/tests/test_umath_complex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,8 +576,8 @@ def test_array(self, stride, astype):
576576
complex(0., 0.),
577577
complex(np.nan, np.nan),
578578
complex(np.nan, np.nan)], dtype=astype)
579-
assert_equal(np.abs(arr[::stride]), abs_true[::stride])
580579
with np.errstate(invalid='ignore'):
580+
assert_equal(np.abs(arr[::stride]), abs_true[::stride])
581581
assert_equal(np.square(arr[::stride]), sq_true[::stride])
582582

583583
class TestComplexAbsoluteAVX:

tools/ci/cirrus_arm.yml

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ macos_arm64_test_task:
9696
9797
RUNNER_OS="macOS"
9898
SDKROOT=/Applications/Xcode-14.0.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk
99-
99+
100100
# NOTE: OpenBLAS is not used in this job; if that's done in the future, ensure
101101
# PKG_CONFIG_PATH points to the directory containing the openblas.pc file
102102
# that's installed with the cibw_before_build.sh command.
@@ -110,8 +110,50 @@ macos_arm64_test_task:
110110
111111
pip install -r build_requirements.txt
112112
pip install pytest pytest-xdist hypothesis typing_extensions
113-
113+
114114
spin build -- -Dallow-noblas=true
115115
spin test -j auto
116116
117117
ccache -s
118+
119+
120+
freebsd_test_task:
121+
use_compute_credits: $CIRRUS_USER_COLLABORATOR == 'true'
122+
compute_engine_instance:
123+
image_project: freebsd-org-cloud-dev
124+
image: family/freebsd-13-2
125+
platform: freebsd
126+
cpu: 1
127+
memory: 4G
128+
129+
install_devtools_script: |
130+
pkg install -y git bash ninja ccache
131+
132+
<<: *MODIFIED_CLONE
133+
134+
ccache_cache:
135+
folder: .ccache
136+
populate_script:
137+
- mkdir -p .ccache
138+
fingerprint_key: ccache-freebsd
139+
140+
prepare_env_script: |
141+
# Create a venv (the `source` command needs bash, not the default sh shell)
142+
chsh -s /usr/local/bin/bash
143+
python -m venv .venv
144+
source .venv/bin/activate
145+
# Minimal build and test requirements
146+
python -m pip install -U pip
147+
python -m pip install meson-python Cython pytest hypothesis
148+
149+
build_script: |
150+
chsh -s /usr/local/bin/bash
151+
source .venv/bin/activate
152+
python -m pip install . --no-build-isolation -v -Csetup-args="-Dallow-noblas=true"
153+
154+
test_script: |
155+
chsh -s /usr/local/bin/bash
156+
source .venv/bin/activate
157+
cd tools
158+
python -m pytest --pyargs numpy -m "not slow"
159+
ccache -s

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://togithub.com/numpy/numpy/commit/c7e073c2bb88a94fc2de5f843dc836f33820305b

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy