-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
BUG: np.cross() warns about arrays of vectors when used with two simple 2-d vectors #26620
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
Comments
Ref #24818, does anyone know what the argument/reasoning for this was?
|
OK, since I missed it there. The issue is the first thing and the reasoning is in #13718 which suggested a |
We had a bit of a discussing, we should definitely tell people to use this (I think it is right):
And maybe even document it in the text. The original issue had |
This PR stems from the community meeting on Jun 5, 2024. This implements a new function cross2d that accepts (a stack of) 2-element vectors, in the same manner that cross currently does. Both np.cross2d and np.linalg.cross2d are added. The np.linalg.cross2d is API compatible. This PR closes numpy#13718 and closes numpy#26620. Units tests for cross2d are included. A new test_ValueError is added for cross. Updated doc links for both funtions. Added examples for cross2d. Cleaned up whitespace on both functions.
This PR stems from the community meeting on Jun 5, 2024. This implements a new function cross2d that accepts (a stack of) 2-element vectors, in the same manner that cross currently does. Both np.cross2d and np.linalg.cross2d are added. The function np.linalg.cross2d is Array API compatible. This PR closes numpy#13718 and closes numpy#26620. Units tests for cross2d are included. A new test_ValueError is added for cross. Updated doc links for both funtions and linked to .rst. Added examples for cross2d. Cleaned up whitespace on both functions. Adjusted examples in cross to show how to avoid deprecation warning. Adds an example to compare cross2d with (floating point) det. Includes a release note.
It looks like Let's verify the one-liner above as a workaround (it seems right), and add that to the docstring as a compat note, and backport it to the 2.0.x branch. That should be easy and safe to do in the next few days. |
This addresses a part of numpygh-26620. The one-liner was verified and is likely to be used in a future `np.linalg.cross2d` function implementation, in numpygh-26640. [skip actions] [skip azp] [skip cirrus]
Once gh-26692 is backported to the 2.0.x branch, the milestone on this can be removed. |
This addresses a part of numpygh-26620. The one-liner was verified and is likely to be used in a future `np.linalg.cross2d` function implementation, in numpygh-26640. [skip actions] [skip azp] [skip cirrus]
This addresses a part of numpygh-26620. The one-liner was verified and is likely to be used in a future `np.linalg.cross2d` function implementation, in numpygh-26640. [skip actions] [skip azp] [skip cirrus]
Having the same issue. Why wouldn't cross() be abstract enough to handle 2d and 3d without the user having to differentiate |
lol. So, DeprecationWarning: Arrays of 2-dimensional vectors are deprecated.
Use arrays of 3-dimensional vectors instead. (deprecated in NumPy 2.0) That's a hard UX fail. Simply hand-waving that away as "fine for certain definitions of fine" because users failed to test against NumPy pre-releases like tl;drIn short, the existing
DeprecationWarning: np.cross() no longer supports 2-dimensional vectors.
Replace all np.cross() calls over 2-dimensional vectors with one-liners:
cross2d = arr1[..., 0] * arr2[..., 1] - arr1[..., 1] * arr2[..., 0] I shake my head, fam. I shake it hard. 😮💨 |
* Address numpy 2.0 warning: numpy/numpy#26620 * Address issue with codecov uploading: codecov/codecov-action#1274
This addresses a part of numpygh-26620. The one-liner was verified and is likely to be used in a future `np.linalg.cross2d` function implementation, in numpygh-26640. [skip actions] [skip azp] [skip cirrus]
Pity that |
This has also affected me. Converting all my 2D vectors to 3D vectors with an empty row just to cross multiply feels like a pretty clunky work around, I'd strongly prefer not to do that if it's in the cards. |
Uh oh!
There was an error while loading. Please reload this page.
Describe the issue:
np.cross()
warns about arrays of vectors when used with simply two 2-d vectors (this use case is even in the "Examples" section ofnp.cross()
docstring). I believe, that check whether a warning should be shown is missing a check for number of dimensions of the input.numpy/numpy/_core/numeric.py
Lines 1645 to 1653 in 42e9aa2
I feel like there should be a change, either
'2-dimensional vectors are deprecated. Use 3-dimensional vectors instead.'
without the'Arrays of..'
parts, or..if a.ndim > 1 or b.ndim > 1
Tbh, I'm a bit confused what that warning is implying as recommended usage anyway. Is the user supposed to add an all-zero third dimension for 2-d vectors and then calculate cross product in 3-d and then extract the valid part from it? That seems kinda odd-looking, I guess if that really is the case it looks like this prompts to look at #13718 again potentially?
So instead of..
user should do something like..?
Reproduce the code example:
Error message:
DeprecationWarning: Arrays of 2-dimensional vectors are deprecated. Use arrays of 3-dimensional vectors instead. (deprecated in NumPy 2.0)
Python and NumPy Versions:
2.0.0rc2
3.10.14 | packaged by conda-forge | (main, Mar 20 2024, 12:45:18) [GCC 12.3.0]
Runtime Environment:
Context for the issue:
In our testsuite, we also have a test runner with
pytest -W error
to make sure our code is not causing deprecation warnings in order to keep our code base work with upcoming releases of dependencies. And that's where this deprecation warning came up.The text was updated successfully, but these errors were encountered: