GeezerVison is showing github.com — BLD: fix math func feature checks, fix FreeBSD build, add CI job (#24… · charris/numpy@075a94f
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: numpy/core/meson.build +24-12Lines changed: 24 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -149,20 +149,32 @@ endif | 149 | 149 | # Mandatory functions: if not found, fail the build | 150 | 150 | # Some of these can still be blocklisted if the C99 implementation | 151 | 151 | # is buggy, see numpy/core/src/common/npy_config.h | 152 | | -mandatory_funcs = [ | | 152 | +mandatory_math_funcs = [ | 153 | 153 | 'sin', 'cos', 'tan', 'sinh', 'cosh', 'tanh', 'fabs', | 154 | 154 | 'floor', 'ceil', 'sqrt', 'log10', 'log', 'exp', 'asin', | 155 | 155 | 'acos', 'atan', 'fmod', 'modf', 'frexp', 'ldexp', | 156 | 156 | 'expm1', 'log1p', 'acosh', 'asinh', 'atanh', | 157 | | - 'rint', 'trunc', 'exp2', | 158 | | - 'copysign', 'nextafter', 'strtoll', 'strtoull', 'cbrt', | | 157 | + 'rint', 'trunc', 'exp2', 'copysign', 'nextafter', 'cbrt', | 159 | 158 | 'log2', 'pow', 'hypot', 'atan2', | 160 | | - 'csin', 'csinh', 'ccos', 'ccosh', 'ctan', 'ctanh', | 161 | | - 'creal', 'cimag', 'conj' | 162 | 159 | ] | 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') | 166 | 178 | endif | 167 | 179 | endforeach | 168 | 180 |
| @@ -177,13 +189,13 @@ c99_complex_funcs = [ | 177 | 189 | foreach func: c99_complex_funcs | 178 | 190 | func_single = func + 'f' | 179 | 191 | func_longdouble = func + 'l' | 180 | | - if cc.has_function(func) | | 192 | + if cc.has_function(func, prefix: '#include <complex.h>', dependencies: m_dep) | 181 | 193 | cdata.set10('HAVE_' + func.to_upper(), true) | 182 | 194 | endif | 183 | | - if cc.has_function(func_single) | | 195 | + if cc.has_function(func_single, prefix: '#include <complex.h>', dependencies: m_dep) | 184 | 196 | cdata.set10('HAVE_' + func_single.to_upper(), true) | 185 | 197 | endif | 186 | | - if cc.has_function(func_longdouble) | | 198 | + if cc.has_function(func_longdouble, prefix: '#include <complex.h>', dependencies: m_dep) | 187 | 199 | cdata.set10('HAVE_' + func_longdouble.to_upper(), true) | 188 | 200 | endif | 189 | 201 | endforeach | @@ -192,7 +204,7 @@ endforeach | 192 | 204 | # libnpymath as a C99 compat layer, these may still be relevant. | 193 | 205 | c99_macros = ['isfinite', 'isinf', 'isnan', 'signbit'] | 194 | 206 | foreach macro: c99_macros | 195 | | - if cc.has_function(macro) | | 207 | + if cc.has_function(macro, prefix: '#include <math.h>', dependencies: m_dep) | 196 | 208 | cdata.set10('NPY_HAVE_DECL_' + macro.to_upper(), true) | 197 | 209 | if not cc.has_header_symbol('Python.h', macro, dependencies: py_dep) | 198 | 210 | # Add in config.h as well, except if it will clash with Python's config.h content | |
Collapse file Copy file name to clipboardExpand all lines: numpy/core/src/npymath/npy_math_complex.c.src +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -158,7 +158,9 @@ npy_carg@c@(@ctype@ z) | 158 | 158 | #define SCALED_CEXP_LOWERL 11357.216553474703895L | 159 | 159 | #define SCALED_CEXP_UPPERL 22756.021937783004509L | 160 | 160 |
| 161 | | -#if !defined(HAVE_CEXP@C@) | | 161 | +#if !defined(HAVE_CSINH@C@) || \ | | 162 | + !defined(HAVE_CCOSH@C@) || \ | | 163 | + !defined(HAVE_CEXP@C@) | 162 | 164 |
| 163 | 165 | static | 164 | 166 | @ctype@ | |
Collapse file Copy file name to clipboardExpand all lines: numpy/core/tests/test_multiarray.py +6-3Lines changed: 6 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -9723,9 +9723,12 @@ def test_ragged_comparison_fails(op): | 9723 | 9723 | def test_npymath_complex(fun, npfun, x, y, test_dtype): | 9724 | 9724 | # Smoketest npymath functions | 9725 | 9725 | 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) | 9729 | 9732 |
| 9730 | 9733 |
| 9731 | 9734 | def test_npymath_real(): | |
Collapse file Copy file name to clipboardExpand all lines: numpy/core/tests/test_numeric.py +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -645,6 +645,11 @@ def assert_op_raises_fpe(self, fpeerr, flop, sc1, sc2): | 645 | 645 | @pytest.mark.skipif(IS_WASM, reason="no wasm fp exception support") | 646 | 646 | @pytest.mark.parametrize("typecode", np.typecodes["AllFloat"]) | 647 | 647 | 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 | + | 648 | 653 | # Test basic arithmetic function errors | 649 | 654 | with np.errstate(all='raise'): | 650 | 655 | ftype = np.obj2sctype(typecode) | |
Collapse file Copy file name to clipboardExpand all lines: numpy/core/tests/test_umath.py +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1646,6 +1646,8 @@ def test_sinh(self): | 1646 | 1646 | np.array(1200.0, dtype='d')) | 1647 | 1647 |
| 1648 | 1648 | @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") | 1649 | 1651 | def test_cosh(self): | 1650 | 1652 | in_ = [np.nan, -np.nan, np.inf, -np.inf] | 1651 | 1653 | out = [np.nan, np.nan, np.inf, np.inf] | |
Collapse file Copy file name to clipboardExpand all lines: numpy/core/tests/test_umath_complex.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -576,8 +576,8 @@ def test_array(self, stride, astype): | 576 | 576 | complex(0., 0.), | 577 | 577 | complex(np.nan, np.nan), | 578 | 578 | complex(np.nan, np.nan)], dtype=astype) | 579 | | - assert_equal(np.abs(arr[::stride]), abs_true[::stride]) | 580 | 579 | with np.errstate(invalid='ignore'): | | 580 | + assert_equal(np.abs(arr[::stride]), abs_true[::stride]) | 581 | 581 | assert_equal(np.square(arr[::stride]), sq_true[::stride]) | 582 | 582 |
| 583 | 583 | class TestComplexAbsoluteAVX: | |
Collapse file Copy file name to clipboardExpand all lines: tools/ci/cirrus_arm.yml +44-2Lines changed: 44 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -96,7 +96,7 @@ macos_arm64_test_task: | 96 | 96 |
| 97 | 97 | RUNNER_OS="macOS" | 98 | 98 | SDKROOT=/Applications/Xcode-14.0.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk | 99 | | - | | 99 | +
| 100 | 100 | # NOTE: OpenBLAS is not used in this job; if that's done in the future, ensure | 101 | 101 | # PKG_CONFIG_PATH points to the directory containing the openblas.pc file | 102 | 102 | # that's installed with the cibw_before_build.sh command. | @@ -110,8 +110,50 @@ macos_arm64_test_task: | 110 | 110 |
| 111 | 111 | pip install -r build_requirements.txt | 112 | 112 | pip install pytest pytest-xdist hypothesis typing_extensions | 113 | | - | | 113 | +
| 114 | 114 | spin build -- -Dallow-noblas=true | 115 | 115 | spin test -j auto | 116 | 116 |
| 117 | 117 | 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 |
|