diff options
author | Ganesh Kathiresan <ganesh3597@gmail.com> | 2022-03-22 21:13:22 +0530 |
---|---|---|
committer | Ganesh Kathiresan <ganesh3597@gmail.com> | 2022-03-22 21:16:30 +0530 |
commit | 57da1fa154cb48c8f219e9306fa03fd37efe510e (patch) | |
tree | 54aa8b9dd82402e8430688ffff40b782f628864b /numpy/lib/tests | |
parent | acb65168868814ce6d36059ca021dabc1839dc6d (diff) | |
download | numpy-57da1fa154cb48c8f219e9306fa03fd37efe510e.tar.gz |
TST: Added testcases for `np.kron`
* Smoke tests to ensure `np.kron` works.
* Shape tests to check if `np.kron` computes the right shape for
different edge cases of input arrays
Diffstat (limited to 'numpy/lib/tests')
-rw-r--r-- | numpy/lib/tests/test_shape_base.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_shape_base.py b/numpy/lib/tests/test_shape_base.py index a148e53da..d75a1006c 100644 --- a/numpy/lib/tests/test_shape_base.py +++ b/numpy/lib/tests/test_shape_base.py @@ -655,6 +655,32 @@ 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): |