Skip to content

Commit 6068c50

Browse files
committed
Add extra error messages regarding unused terms in IBLanguage.qwm
- Adds extra error messages to catch zero rows in qwm, which cause errors - Adds extra testing to ensure the edge case is caught
1 parent 695b99d commit 6068c50

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

src/eff_conv/ib/language.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ def __init__(
5151
raise ValueError(
5252
"All columns of conditional probability matrix must sum to 1"
5353
)
54+
if (np.sum(qwm, axis=1) <= 0).any():
55+
raise ValueError(
56+
"All rows of conditional probability matrix must sum to a value greater than 0"
57+
)
5458
if (qwm < 0).any():
5559
raise ValueError(
5660
"No negative numbers are allowed in the probability matrix"

src/tests/test_ib.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,5 @@ def test_ib_language_check(self):
186186
lang_negative_probability = IBLanguage(
187187
self.simple_struct, np.array([[-1, 1], [2, 0]])
188188
)
189+
with pytest.raises(ValueError):
190+
lang_zero_row = IBLanguage(self.simple_struct, np.array([[1, 1], [0, 0]]))

0 commit comments

Comments
 (0)