diff options
author | Sebastian Berg <sebastian@sipsolutions.net> | 2021-04-27 16:17:19 -0500 |
---|---|---|
committer | Sebastian Berg <sebastian@sipsolutions.net> | 2021-04-27 16:58:44 -0500 |
commit | 18ffb74487c0e121a369fd8b4e2824caa7a20b95 (patch) | |
tree | b9f9097533afa0de7098970f65af6f0857438b76 /numpy | |
parent | 6d871ca31abad2ce7065469ca8b530e4daa4996f (diff) | |
download | numpy-18ffb74487c0e121a369fd8b4e2824caa7a20b95.tar.gz |
TST: Add test for non-broadcastibility of the gufunc output
This ensures that it is correct to not initize the output array if
the outer iteration has size 0. The broadcast result would always
have size 0 in that case.
If the iterator rejects such a broadcast it cannot happen.
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/tests/test_multiarray.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index 073433bd1..f16b9d39a 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -6446,6 +6446,16 @@ class TestMatmul(MatmulCommon): c = c.astype(tgt.dtype) assert_array_equal(c, tgt) + def test_empty_out(self): + # Check that the output cannot be broadcast, so that it cannot be + # size zero when the outer dimensions (iterator size) has size zero. + arr = np.ones((0, 1, 1)) + out = np.ones((1, 1, 1)) + assert self.matmul(arr, arr).shape == (0, 1, 1) + + with pytest.raises(ValueError, match=r"non-broadcastable"): + self.matmul(arr, arr, out=out) + def test_out_contiguous(self): a = np.ones((5, 2), dtype=float) b = np.array([[1, 3], [5, 7]], dtype=float) |