10000 DOC: deprecate size-2 inputs for np.cross · numpy/numpy@ea42abc · GitHub
[go: up one dir, main page]

Skip to content

Commit ea42abc

Browse files
mtsokolngoldbaum
andcommitted
DOC: deprecate size-2 inputs for np.cross
Co-authored-by: Nathan Goldbaum <nathan.goldbaum@gmail.com>
1 parent 382eedf commit ea42abc

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Arrays of 2-dimensional vectors for ``np.cross`` have been deprecated.
2+
Use arrays of 3-dimensional vectors instead.

numpy/_core/numeric.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,6 +1597,13 @@ def cross(a, b, axisa=-1, axisb=-1, axisc=-1, axis=None):
15971597
"(dimension must be 2 or 3)")
15981598
if a.shape[-1] not in (2, 3) or b.shape[-1] not in (2, 3):
15991599
raise ValueError(msg)
1600+
if a.shape[-1] == 2 or b.shape[-1] == 2:
1601+
# Deprecated in NumPy 2.0, 2023-09-26
1602+
warnings.warn(
1603+
"Arrays of 2-dimensional vectors are deprecated. Use arrays of "
1604+
"3-dimensional vectors instead. (deprecated in NumPy 2.0)",
1605+
DeprecationWarning, stacklevel=2
1606+
)
16001607

16011608
# Create the output array
16021609
shape = broadcast(a[..., 0], b[..., 0]).shape

numpy/_core/tests/test_numeric.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3573,6 +3573,9 @@ def test_array_likes(self):
35733573

35743574

35753575
class TestCross:
3576+
@pytest.mark.filterwarnings(
3577+
"ignore:.*2-dimensional vectors.*:DeprecationWarning"
3578+
)
35763579
def test_2x2(self):
35773580
u = [1, 2]
35783581
v = [3, 4]
@@ -3582,6 +3585,9 @@ def test_2x2(self):
35823585
cp = np.cross(v, u)
35833586
assert_equal(cp, -z)
35843587

3588+
@pytest.mark.filterwarnings(
3589+
"ignore:.*2-dimensional vectors.*:DeprecationWarning"
3590+
)
35853591
def test_2x3(self):
35863592
u = [1, 2]
35873593
v = [3, 4, 5]
@@ -3600,6 +3606,9 @@ def test_3x3(self):
36003606
cp = np.cross(v, u)
36013607
assert_equal(cp, -z)
36023608

3609+
@pytest.mark.filterwarnings(
3610+
"ignore:.*2-dimensional vectors.*:DeprecationWarning"
3611+
)
36033612
def test_broadcasting(self):
36043613
# Ticket #2624 (Trac #2032)
36053614
u = np.tile([1, 2], (11, 1))
@@ -3630,6 +3639,9 @@ def test_broadcasting(self):
36303639
assert_equal(np.cross(v.T, u), -z)
36313640
assert_equal(np.cross(u, u), 0)
36323641

3642+
@pytest.mark.filterwarnings(
3643+
"ignore:.*2-dimensional vectors.*:DeprecationWarning"
3644+
)
36333645
def test_broadcasting_shapes(self):
36343646
u = np.ones((2, 1, 3))
36353647
v = np.ones((5, 3))

0 commit comments

Comments
 (0)
0