8000 BUG: Adds asanyarray to start of linalg.cross (#26667) · numpy/numpy@b52814f · GitHub
[go: up one dir, main page]

Skip to content

Commit b52814f

Browse files
authored
BUG: Adds asanyarray to start of linalg.cross (#26667)
Currently linalg.cross fails when given two 3D lists. This adds `asanyarray` at the start of the code, mimicing the other Array API compatible additions. This was discussed in PR #26640, with a bug fix requested.
1 parent d80bce0 commit b52814f

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

numpy/linalg/_linalg.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3171,6 +3171,9 @@ def cross(x1, x2, /, *, axis=-1):
31713171
numpy.cross
31723172
31733173
"""
3174+
x1 = asanyarray(x1)
3175+
x2 = asanyarray(x2)
3176+
31743177
if x1.shape[axis] != 3 or x2.shape[axis] != 3:
31753178
raise ValueError(
31763179
"Both input arrays must be (arrays of) 3-dimensional vectors, "

numpy/linalg/tests/test_linalg.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2307,6 +2307,14 @@ def test_cross():
23072307

23082308
assert_equal(actual, expected)
23092309

2310+
# We test that lists are converted to arrays.
2311+
u = [1, 2, 3]
2312+
v = [4, 5, 6]
2313+
actual = np.linalg.cross(u, v)
2314+
expected = array([-3, 6, -3])
2315+
2316+
assert_equal(actual, expected)
2317+
23102318
with assert_raises_regex(
23112319
ValueError,
23122320
r"input arrays must be \(arrays of\) 3-dimensional vectors"

0 commit comments

Comments
 (0)
0