GeezerVison is showing github.com — BLD: fix math func feature checks, fix FreeBSD build, add CI job (#24… · numpy/numpy@040ed2d
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 |
|---|
@@ -148,20 +148,32 @@ endforeach | 148 | 148 | # Mandatory functions: if not found, fail the build | 149 | 149 | # Some of these can still be blocklisted if the C99 implementation | 150 | 150 | # is buggy, see numpy/core/src/common/npy_config.h | 151 | | -mandatory_funcs = [ | | 151 | +mandatory_math_funcs = [ | 152 | 152 | 'sin', 'cos', 'tan', 'sinh', 'cosh', 'tanh', 'fabs', | 153 | 153 | 'floor', 'ceil', 'sqrt', 'log10', 'log', 'exp', 'asin', | 154 | 154 | 'acos', 'atan', 'fmod', 'modf', 'frexp', 'ldexp', | 155 | 155 | 'expm1', 'log1p', 'acosh', 'asinh', 'atanh', | 156 | | - 'rint', 'trunc', 'exp2', | 157 | | - 'copysign', 'nextafter', 'strtoll', 'strtoull', 'cbrt', | | 156 | + 'rint', 'trunc', 'exp2', 'copysign', 'nextafter', 'cbrt', | 158 | 157 | 'log2', 'pow', 'hypot', 'atan2', | 159 | | - 'csin', 'csinh', 'ccos', 'ccosh', 'ctan', 'ctanh', | 160 | | - 'creal', 'cimag', 'conj' | 161 | 158 | ] | 162 | | -foreach func: mandatory_funcs | 163 | | - if not cc.has_function(func) | 164 | | - error('Function `{func}` not found') | | 159 | +foreach func: mandatory_math_funcs | | 160 | + if not cc.has_function(func, prefix: '#include <math.h>', dependencies: m_dep) | | 161 | + error(f'Function `@func@` not found') | | 162 | + endif | | 163 | +endforeach | | 164 | + | | 165 | +mandatory_complex_math_funcs = [ | | 166 | + 'csin', 'csinh', 'ccos', 'ccosh', 'ctan', 'ctanh', 'creal', 'cimag', 'conj' | | 167 | +] | | 168 | +foreach func: mandatory_complex_math_funcs | | 169 | + if not cc.has_function(func, prefix: '#include <complex.h>', dependencies: m_dep) | | 170 | + error(f'Function `@func@` not found') | | 171 | + endif | | 172 | +endforeach | | 173 | + | | 174 | +foreach func: ['strtoll', 'strtoull'] | | 175 | + if not cc.has_function(func, prefix: '#include <stdlib.h>') | | 176 | + error(f'Function `@func@` not found') | 165 | 177 | endif | 166 | 178 | endforeach | 167 | 179 |
| @@ -175,13 +187,13 @@ c99_complex_funcs = [ | 175 | 187 | foreach func: c99_complex_funcs | 176 | 188 | func_single = func + 'f' | 177 | 189 | func_longdouble = func + 'l' | 178 | | - if cc.has_function(func) | | 190 | + if cc.has_function(func, prefix: '#include <complex.h>', dependencies: m_dep) | 179 | 191 | cdata.set10('HAVE_' + func.to_upper(), true) | 180 | 192 | endif | 181 | | - if cc.has_function(func_single) | | 193 | + if cc.has_function(func_single, prefix: '#include <complex.h>', dependencies: m_dep) | 182 | 194 | cdata.set10('HAVE_' + func_single.to_upper(), true) | 183 | 195 | endif | 184 | | - if cc.has_function(func_longdouble) | | 196 | + if cc.has_function(func_longdouble, prefix: '#include <complex.h>', dependencies: m_dep) | 185 | 197 | cdata.set10('HAVE_' + func_longdouble.to_upper(), true) | 186 | 198 | endif | 187 | 199 | endforeach | @@ -190,7 +202,7 @@ endforeach | 190 | 202 | # libnpymath as a C99 compat layer, these may still be relevant. | 191 | 203 | c99_macros = ['isfinite', 'isinf', 'isnan', 'signbit'] | 192 | 204 | foreach macro: c99_macros | 193 | | - if cc.has_function(macro) | | 205 | + if cc.has_function(macro, prefix: '#include <math.h>', dependencies: m_dep) | 194 | 206 | cdata.set10('NPY_HAVE_DECL_' + macro.to_upper(), true) | 195 | 207 | if not cc.has_header_symbol('Python.h', macro, dependencies: py_dep) | 196 | 208 | # 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 |
|---|
@@ -163,7 +163,9 @@ npy_carg@c@(@ctype@ z) | 163 | 163 | #define SCALED_CEXP_LOWERL 11357.216553474703895L | 164 | 164 | #define SCALED_CEXP_UPPERL 22756.021937783004509L | 165 | 165 |
| 166 | | -#if !defined(HAVE_CEXP@C@) | | 166 | +#if !defined(HAVE_CSINH@C@) || \ | | 167 | + !defined(HAVE_CCOSH@C@) || \ | | 168 | + !defined(HAVE_CEXP@C@) | 167 | 169 |
| 168 | 170 | static | 169 | 171 | @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 |
|---|
@@ -9706,9 +9706,12 @@ def test_ragged_comparison_fails(op): | 9706 | 9706 | def test_npymath_complex(fun, npfun, x, y, test_dtype): | 9707 | 9707 | # Smoketest npymath functions | 9708 | 9708 | z = test_dtype(complex(x, y)) | 9709 | | - got = fun(z) | 9710 | | - expected = npfun(z) | 9711 | | - assert_allclose(got, expected) | | 9709 | + with np.errstate(invalid='ignore'): | | 9710 | + # Fallback implementations may emit a warning for +-inf (see gh-24876): | | 9711 | + # RuntimeWarning: invalid value encountered in absolute | | 9712 | + got = fun(z) | | 9713 | + expected = npfun(z) | | 9714 | + assert_allclose(got, expected) | 9712 | 9715 |
| 9713 | 9716 |
| 9714 | 9717 | 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 |
|---|
@@ -916,6 +916,11 @@ def assert_op_raises_fpe(self, fpeerr, flop, sc1, sc2): | 916 | 916 | @pytest.mark.skipif(IS_WASM, reason="no wasm fp exception support") | 917 | 917 | @pytest.mark.parametrize("typecode", np.typecodes["AllFloat"]) | 918 | 918 | def test_floating_exceptions(self, typecode): | | 919 | + if 'bsd' in sys.platform and typecode in 'gG': | | 920 | + pytest.skip(reason="Fallback impl for (c)longdouble may not raise " | | 921 | + "FPE errors as expected on BSD OSes, " | | 922 | + "see gh-24876, gh-23379") | | 923 | + | 919 | 924 | # Test basic arithmetic function errors | 920 | 925 | with np.errstate(all='raise'): | 921 | 926 | ftype = 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 |
|---|
@@ -1645,6 +1645,8 @@ def test_sinh(self): | 1645 | 1645 | np.array(1200.0, dtype='d')) | 1646 | 1646 |
| 1647 | 1647 | @pytest.mark.skipif(IS_WASM, reason="fp errors don't work in wasm") | | 1648 | + @pytest.mark.skipif('bsd' in sys.platform, | | 1649 | + reason="fallback implementation may not raise, see gh-2487") | 1648 | 1650 | def test_cosh(self): | 1649 | 1651 | in_ = [np.nan, -np.nan, np.inf, -np.inf] | 1650 | 1652 | 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 |
|