Skip to content

Commit

Permalink
Test IdentityKronecker
Browse files Browse the repository at this point in the history
  • Loading branch information
schmidtjonathan committed Aug 12, 2021
1 parent 4d8b477 commit d543e01
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/probnum/linops/_kronecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from probnum.typing import DTypeArgType, NotImplementedType

from . import _linear_operator, _utils
from ._scaling import Scaling


class Symmetrize(_linear_operator.LinearOperator):
Expand Down
15 changes: 15 additions & 0 deletions tests/test_linops/test_arithmetics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d543e01

Please sign in to comment.