From d543e015bf6ba45db2030fe25ac81aa848e333f5 Mon Sep 17 00:00:00 2001 From: Jonathan Schmidt Date: Thu, 12 Aug 2021 14:50:58 +0200 Subject: [PATCH] Test IdentityKronecker --- src/probnum/linops/_kronecker.py | 1 - tests/test_linops/test_arithmetics.py | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/probnum/linops/_kronecker.py b/src/probnum/linops/_kronecker.py index 99d30f162a..b14e8775a1 100644 --- a/src/probnum/linops/_kronecker.py +++ b/src/probnum/linops/_kronecker.py @@ -6,7 +6,6 @@ from probnum.typing import DTypeArgType, NotImplementedType from . import _linear_operator, _utils -from ._scaling import Scaling class Symmetrize(_linear_operator.LinearOperator): diff --git a/tests/test_linops/test_arithmetics.py b/tests/test_linops/test_arithmetics.py index bf8e8b2d18..f6d0b2541e 100644 --- a/tests/test_linops/test_arithmetics.py +++ b/tests/test_linops/test_arithmetics.py @@ -239,6 +239,21 @@ def test_kronecker_matmul(): assert not isinstance(res, Kronecker) +def test_idkronecker_matmul(): + # Checks the case in which the shapes of the Kronecker-structured matrices + # are valid in itself but the respective Kronecker factors (k1.A @ k2.A and/or + # k1.B @ k2.B) have invalid shapes for matmul. + k1 = IdentityKronecker(4, np.random.rand(2, 3)) # (8, 12) + k2 = IdentityKronecker(2, np.random.rand(6, 2)) # (12, 4) + + # Even though the shapes fit, and IdentityKronecker @ IdentityKronecker = IdentityKronecker .... + assert k1.shape[1] == k2.shape[0] + + # The result does not have a IdentityKronecker structure + res = k1 @ k2 + assert not isinstance(res, IdentityKronecker) + + def test_selection_embedding(): sel = get_linop(Selection) emb = get_linop(Embedding)