Thanks to visit codestin.com
Credit goes to github.com

Skip to content

API: Remove seterrobj/geterrobj/extobj= and related C-API functions #23922

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

Merged
merged 11 commits into from
Jun 14, 2023

Conversation

seberg
Copy link
Member

@seberg seberg commented Jun 12, 2023

This has a couple of different commits and is unfortunately a bit large because of that. With the exception of the necessary linalg cleanup, they are rather intertwined though.

The commits should be cleanly reviewable one-by-one, though!

Not marking as draft, but the release note build may error until gh-23919 is merged.

Closes gh-23900. There were 2 👍 on the issue, so I assume/hope we have a consensus on these. Right now this is the most minimal useful version: Remove everything directly exposing extobj or the C-API side tuple of (ufunc_name, callable) which is a weird indirection.

EDIT: OK, removing "log" and "print" is not minimal.

@seberg seberg marked this pull request as ready for review June 12, 2023 14:52
return 0;
}

#undef HANDLEIT
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a straight copy paste, the only change is making them static.

@seberg seberg force-pushed the remove-errstate branch from cbee123 to 807bf89 Compare June 12, 2023 16:01
@seberg
Copy link
Member Author

seberg commented Jun 12, 2023

@mattip I saw some of those unpacking non 0-d arrays into scalars in the f2py tests here also. Maybe something unrelated to the meson PR changed?!

This run: https://github.com/numpy/numpy/pull/23922/checks?check_run_id=14193159921 (if it still is around)

I don't think it is, so here the details:

f2py/tests/test_return_real.py: 16 warnings
  /private/var/folders/76/zy5ktkns50v6gt5g8r0sf6sc0000gn/T/cibw-run-gkmigpag/cp310-macosx_arm64/venv-test/lib/python3.10/site-packages/numpy/f2py/tests/test_return_real.py:26: DeprecationWarning: Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.)
    assert abs(t(array([234], "h")) - 234.0) <= err

f2py/tests/test_return_real.py: 16 warnings
  /private/var/folders/76/zy5ktkns50v6gt5g8r0sf6sc0000gn/T/cibw-run-gkmigpag/cp310-macosx_arm64/venv-test/lib/python3.10/site-packages/numpy/f2py/tests/test_return_real.py:27: DeprecationWarning: Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.)
    assert abs(t(array([234], "i")) - 234.0) <= err

f2py/tests/test_return_real.py: 16 warnings
  /private/var/folders/76/zy5ktkns50v6gt5g8r0sf6sc0000gn/T/cibw-run-gkmigpag/cp310-macosx_arm64/venv-test/lib/python3.10/site-packages/numpy/f2py/tests/test_return_real.py:28: DeprecationWarning: Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.)
    assert abs(t(array([234], "l")) - 234.0) <= err

f2py/tests/test_return_real.py: 16 warnings
  /private/var/folders/76/zy5ktkns50v6gt5g8r0sf6sc0000gn/T/cibw-run-gkmigpag/cp310-macosx_arm64/venv-test/lib/python3.10/site-packages/numpy/f2py/tests/test_return_real.py:29: DeprecationWarning: Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.)
    assert abs(t(array([234], "B")) - 234.0) <= err

f2py/tests/test_return_real.py: 16 warnings
  /private/var/folders/76/zy5ktkns50v6gt5g8r0sf6sc0000gn/T/cibw-run-gkmigpag/cp310-macosx_arm64/venv-test/lib/python3.10/site-packages/numpy/f2py/tests/test_return_real.py:30: DeprecationWarning: Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.)
    assert abs(t(array([234], "f")) - 234.0) <= err

f2py/tests/test_return_real.py: 16 warnings
  /private/var/folders/76/zy5ktkns50v6gt5g8r0sf6sc0000gn/T/cibw-run-gkmigpag/cp310-macosx_arm64/venv-test/lib/python3.10/site-packages/numpy/f2py/tests/test_return_real.py:31: DeprecationWarning: Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.)
    assert abs(t(array([234], "d")) - 234.0) <= err

linalg/tests/test_linalg.py::TestDet::test_types[complex64]
linalg/tests/test_linalg.py::TestDet::test_types[complex128]
  /private/var/folders/76/zy5ktkns50v6gt5g8r0sf6sc0000gn/T/cibw-run-gkmigpag/cp310-macosx_arm64/venv-test/lib/python3.10/site-packages/numpy/linalg/linalg.py:2175: RuntimeWarning: divide by zero encountered in det
    r = _umath_linalg.det(a, signature=signature)

linalg/tests/test_linalg.py::TestDet::test_types[complex64]
linalg/tests/test_linalg.py::TestDet::test_types[complex128]
  /private/var/folders/76/zy5ktkns50v6gt5g8r0sf6sc0000gn/T/cibw-run-gkmigpag/cp310-macosx_arm64/venv-test/lib/python3.10/site-packages/numpy/linalg/linalg.py:2175: RuntimeWarning: invalid value encountered in det
    r = _umath_linalg.det(a, signature=signature)

linalg/tests/test_linalg.py::TestDet::test_types[complex64]
linalg/tests/test_linalg.py::TestDet::test_types[complex128]
  /private/var/folders/76/zy5ktkns50v6gt5g8r0sf6sc0000gn/T/cibw-run-gkmigpag/cp310-macosx_arm64/venv-test/lib/python3.10/site-packages/numpy/linalg/linalg.py:2115: RuntimeWarning: divide by zero encountered in slogdet
    sign, logdet = _umath_linalg.slogdet(a, signature=signature)

linalg/tests/test_linalg.py::TestDet::test_types[complex64]
linalg/tests/test_linalg.py::TestDet::test_types[complex128]
  /private/var/folders/76/zy5ktkns50v6gt5g8r0sf6sc0000gn/T/cibw-run-gkmigpag/cp310-macosx_arm64/venv-test/lib/python3.10/site-packages/numpy/linalg/linalg.py:2115: RuntimeWarning: invalid value encountered in slogdet
    sign, logdet = _umath_linalg.slogdet(a, signature=signature)

-- Docs: https://docs.pytest.org/en/stable/warnings.html
=========================== short test summary info ============================
FAILED typing/tests/test_typing.py::test_code_runs[ufunc_config] - KeyError: ...
1 failed, 35041 passed, 212 skipped, 38 xfailed, 9 xpassed, 349 warnings in 441.04s (0:07:21)
 a=
 a=

                                                                     ✕ 456.90s
Error: Command ['/bin/sh', '-c', 'bash /private/var/folders/76/zy5ktkns50v6gt5g8r0sf6sc0000gn/T/cirrus-ci-build/tools/wheels/cibw_test_command.sh /private/var/folders/76/zy5ktkns50v6gt5g8r0sf6sc0000gn/T/cirrus-ci-build'] failed with code 1. None

@seberg seberg force-pushed the remove-errstate branch 2 times, most recently from cc6b782 to c3e2e57 Compare June 12, 2023 23:23
seberg added 9 commits June 13, 2023 09:21
…perr`

We could introduce a new to combine these (mainly the GetPyValues and
handlefperr) and we could do so in a way that is backwards compatible:
Combine both functions into one small helper.

There is no known user, but if someone comes up even restoring them
should be possible.

These functions are threaded through our code to deal with error handling
but create an unnecessary `errobj` that may have made some sense when
you wish to raise errors from a worker/inner-loop.
However, we never do that, and there shouldn't a be reason for downstream
to do that either:  The current split in functions just makes it hard
to improve the `errstate` handling (because this API will not remain useful
internally).
This may slow things down very slightly, but we should be able to
recover this easily and the `extobj=` API is a bit strange.
These are left for now as a private implementation detail.
We will want to undo parts because eventually we probably want to fetch
the "global" relatively early on once and potentially thread it through
in many places.

But, that refactor probably needs to touch so much, that this should
make it easier anyway.
We will remove some things without deprecations, this is a category
for that.
@seberg seberg force-pushed the remove-errstate branch from c3e2e57 to e8796b3 Compare June 13, 2023 07:29
@seberg
Copy link
Member Author

seberg commented Jun 13, 2023

I have dropped removal of 'log' and 'print' mode. It shouldn't matter much for introducing a ContextVar (I wouldn't mind removing at least print, but no need to do it here).

Technically, the C-API could be retained. But I still think it will make the refactor unnecessarily annoying as it will require duplicate code for only that purpose and there is no known user.

@seberg seberg force-pushed the remove-errstate branch from e8796b3 to 7cba4d8 Compare June 13, 2023 07:41
@mattip mattip merged commit 59e8c62 into numpy:main Jun 14, 2023
@mattip
Copy link
Member

mattip commented Jun 14, 2023

Thanks @seberg. Nice cleanup.

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

Successfully merging this pull request may close these issues.

API: Slash down errstate related API to make it sustainable
3 participants