Skip to content

Commit 7b8185d

Browse files
committed
add unit tests to excercise error branches of rapply/__rmatmul__
1 parent a307b84 commit 7b8185d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tests/test_BlkDiagMatrix.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ def testBlkDiagMatrixApply(self):
145145
e[:, i] = self.blk_a.apply(coeffm[:, i])
146146
self.allallfunc(e, d)
147147

148+
# We can use syntactic sugar @ for apply as well
149+
f = self.blk_a @ coeffm
150+
self.allallfunc(f, d)
151+
148152
# Test the rapply is also functional
149153
coeffm = coeffm.T # matmul dimensions
150154
res = coeffm @ self.blk_a.dense()
@@ -155,6 +159,17 @@ def testBlkDiagMatrixApply(self):
155159
d = coeffm @ self.blk_a
156160
self.allallfunc(res, d)
157161

162+
# And test some incorrrect invocations:
163+
# inplace not supported for matmul of mixed classes.
164+
with pytest.raises(RuntimeError, match=r".*method not supported.*"):
165+
self.blk_a @= coeffm
166+
167+
# Test left operand of an __rmatmul__ must be an ndarray
168+
with pytest.raises(
169+
RuntimeError, match=r".*only defined for np.ndarray @ BlkDiagMatrix.*"
170+
):
171+
_ = list(coeffm) @ self.blk_a
172+
158173
def testBlkDiagMatrixMatMult(self):
159174
result = [np.matmul(*tup) for tup in zip(self.blk_a, self.blk_b)]
160175

0 commit comments

Comments
 (0)