diff options
| author | Omar <Omarh90@gmail.com> | 2022-07-04 12:09:54 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-04 21:09:54 +0200 |
| commit | cf39a723ef4cac328225fd0e3a9b83edac41c2c1 (patch) | |
| tree | dc495119abe9ce5bb6ceffbef0a7834e0740ff19 /numpy | |
| parent | 353fea031dacf2c31399cc938f545cfcfdc9c57c (diff) | |
| download | numpy-cf39a723ef4cac328225fd0e3a9b83edac41c2c1.tar.gz | |
BUG: cross product: add dtype conversions of inputs (#20659)
Closes #19138
Diffstat (limited to 'numpy')
| -rw-r--r-- | numpy/core/numeric.py | 4 | ||||
| -rw-r--r-- | numpy/core/tests/test_numeric.py | 8 |
2 files changed, 12 insertions, 0 deletions
diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py index d6e1d4eec..cfcd237aa 100644 --- a/numpy/core/numeric.py +++ b/numpy/core/numeric.py @@ -1622,6 +1622,10 @@ def cross(a, b, axisa=-1, axisb=-1, axisc=-1, axis=None): dtype = promote_types(a.dtype, b.dtype) cp = empty(shape, dtype) + # recast arrays as dtype + a = a.astype(dtype) + b = b.astype(dtype) + # create local aliases for readability a0 = a[..., 0] a1 = a[..., 1] diff --git a/numpy/core/tests/test_numeric.py b/numpy/core/tests/test_numeric.py index 5b15e29b4..21bf91a35 100644 --- a/numpy/core/tests/test_numeric.py +++ b/numpy/core/tests/test_numeric.py @@ -3383,6 +3383,14 @@ class TestCross: for axisc in range(-2, 2): assert_equal(np.cross(u, u, axisc=axisc).shape, (3, 4)) + def test_uint8_int32_mixed_dtypes(self): + # regression test for gh-19138 + u = np.array([[195, 8, 9]], np.uint8) + v = np.array([250, 166, 68], np.int32) + z = np.array([[950, 11010, -30370]], dtype=np.int32) + assert_equal(np.cross(v, u), z) + assert_equal(np.cross(u, v), -z) + def test_outer_out_param(): arr1 = np.ones((5,)) |
