summaryrefslogtreecommitdiff
path: root/numpy/lib
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2022-09-22 14:04:13 -0500
committerGitHub <noreply@github.com>2022-09-22 14:04:13 -0500
commit88c1a4fefa0687193e3944416fea7c311caceb39 (patch)
tree49ca36298271dee17ac70dfe6b78e120699adc18 /numpy/lib
parentd23050a12984c3d881356f0aea166f579b755de9 (diff)
parent0815a8c8a31d0d16e3011db8f72cfdc750161c76 (diff)
downloadnumpy-88c1a4fefa0687193e3944416fea7c311caceb39.tar.gz
Merge pull request #22319 from sjtechdev/21257/add_kron_functional_tests
TST: add functional tests for kron
Diffstat (limited to 'numpy/lib')
-rw-r--r--numpy/lib/tests/test_shape_base.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_shape_base.py b/numpy/lib/tests/test_shape_base.py
index 07960627b..76058cf20 100644
--- a/numpy/lib/tests/test_shape_base.py
+++ b/numpy/lib/tests/test_shape_base.py
@@ -644,6 +644,35 @@ class TestSqueeze:
class TestKron:
+ def test_basic(self):
+ # Using 0-dimensional ndarray
+ a = np.array(1)
+ b = np.array([[1, 2], [3, 4]])
+ k = np.array([[1, 2], [3, 4]])
+ assert_array_equal(np.kron(a, b), k)
+ a = np.array([[1, 2], [3, 4]])
+ b = np.array(1)
+ assert_array_equal(np.kron(a, b), k)
+
+ # Using 1-dimensional ndarray
+ a = np.array([3])
+ b = np.array([[1, 2], [3, 4]])
+ k = np.array([[3, 6], [9, 12]])
+ assert_array_equal(np.kron(a, b), k)
+ a = np.array([[1, 2], [3, 4]])
+ b = np.array([3])
+ assert_array_equal(np.kron(a, b), k)
+
+ # Using 3-dimensional ndarray
+ a = np.array([[[1]], [[2]]])
+ b = np.array([[1, 2], [3, 4]])
+ k = np.array([[[1, 2], [3, 4]], [[2, 4], [6, 8]]])
+ assert_array_equal(np.kron(a, b), k)
+ a = np.array([[1, 2], [3, 4]])
+ b = np.array([[[1]], [[2]]])
+ k = np.array([[[1, 2], [3, 4]], [[2, 4], [6, 8]]])
+ assert_array_equal(np.kron(a, b), k)
+
def test_return_type(self):
class myarray(np.ndarray):
__array_priority__ = 1.0