diff options
author | Matti Picus <matti.picus@gmail.com> | 2022-03-27 11:35:41 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-27 11:35:41 +0300 |
commit | beb5dedf78b96183906ec9e979ef83bb040b7b78 (patch) | |
tree | d0b26143f68605dc7c4582c4e6ae299dc00834e5 /numpy/lib/tests | |
parent | b516cc24ec81fbc093f080c126dba9f360ceca52 (diff) | |
parent | 97d1229a06053e1be1d411b4891e914e99c801a3 (diff) | |
download | numpy-beb5dedf78b96183906ec9e979ef83bb040b7b78.tar.gz |
Merge pull request #21232 from ganesh-k13/bug_21051_kron
BUG: Fixes `ValueError` in `np.kron`
Diffstat (limited to 'numpy/lib/tests')
-rw-r--r-- | numpy/lib/tests/test_shape_base.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_shape_base.py b/numpy/lib/tests/test_shape_base.py index a148e53da..564cdfeea 100644 --- a/numpy/lib/tests/test_shape_base.py +++ b/numpy/lib/tests/test_shape_base.py @@ -655,6 +655,33 @@ class TestKron: assert_equal(type(kron(a, ma)), np.ndarray) assert_equal(type(kron(ma, a)), myarray) + def test_kron_smoke(self): + a = np.ones([3, 3]) + b = np.ones([3, 3]) + k = np.ones([9, 9]) + + assert np.array_equal(np.kron(a, b), k), "Smoke test for kron failed" + + @pytest.mark.parametrize( + "shape_a,shape_b", [ + ((1, 1), (1, 1)), + ((1, 2, 3), (4, 5, 6)), + ((2, 2), (2, 2, 2)), + ((1, 0), (1, 1)), + ((2, 0, 2), (2, 2)), + ((2, 0, 0, 2), (2, 0, 2)), + ]) + def test_kron_shape(self, shape_a, shape_b): + a = np.ones(shape_a) + b = np.ones(shape_b) + normalised_shape_a = (1,) * max(0, len(shape_b)-len(shape_a)) + shape_a + normalised_shape_b = (1,) * max(0, len(shape_a)-len(shape_b)) + shape_b + expected_shape = np.multiply(normalised_shape_a, normalised_shape_b) + + k = np.kron(a, b) + assert np.array_equal( + k.shape, expected_shape), "Unexpected shape from kron" + class TestTile: def test_basic(self): |