10000 API: deprecate size-2 inputs for `np.cross` [Array API] by mtsokol · Pull Request #24818 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

API: deprecate size-2 inputs for np.cross [Array API] #24818

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 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/release/upcoming_changes/24818.deprecation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Arrays of 2-dimensional vectors for ``np.cross`` have been deprecated.
Use arrays of 3-dimensional vectors instead.
7 changes: 7 additions & 0 deletions numpy/_core/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -1597,6 +1597,13 @@ def cross(a, b, axisa=-1, axisb=-1, axisc=-1, axis=None):
"(dimension must be 2 or 3)")
if a.shape[-1] not in (2, 3) or b.shape[-1] not in (2, 3):
raise ValueError(msg)
if a.shape[-1] == 2 or b.shape[-1] == 2:
# Deprecated in NumPy 2.0, 2023-09-26
warnings.warn(
"Arrays of 2-dimensional vectors are deprecated. Use arrays of "
"3-dimensional vectors instead. (deprecated in NumPy 2.0)",
DeprecationWarning, stacklevel=2
)

# Create the output array
shape = broadcast(a[..., 0], b[..., 0]).shape
Expand Down
12 changes: 12 additions & 0 deletions numpy/_core/tests/test_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -3573,6 +3573,9 @@ def test_array_likes(self):


class TestCross:
@pytest.mark.filterwarnings(
"ignore:.*2-dimensional vectors.*:DeprecationWarning"
)
def test_2x2(self):
u = [1, 2]
v = [3, 4]
Expand All @@ -3582,6 +3585,9 @@ def test_2x2(self):
cp = np.cross(v, u)
assert_equal(cp, -z)

@pytest.mark.filterwarnings(
"ignore:.*2-dimensional vectors.*:DeprecationWarning"
)
def test_2x3(self):
u = [1, 2]
v = [3, 4, 5]
Expand All @@ -3600,6 +3606,9 @@ def test_3x3(self):
cp = np.cross(v, u)
assert_equal(cp, -z)

@pytest.mark.filterwarnings(
"ignore:.*2-dimensional vectors.*:DeprecationWarning"
)
def test_broadcasting(self):
# Ticket #2624 (Trac #2032)
u = np.tile([1, 2], (11, 1))
Expand Down Expand Up @@ -3630,6 +3639,9 @@ def test_broadcasting(self):
assert_equal(np.cross(v.T, u), -z)
assert_equal(np.cross(u, u), 0)

@pytest.mark.filterwarnings(
"ignore:.*2-dimensional vectors.*:DeprecationWarning"
)
def test_broadcasting_shapes(self):
u = np.ones((2, 1, 3))
v = np.ones((5, 3))
Expand Down
0