@@ -34,14 +34,16 @@ def __call__(
3434 for c1 in constraints:
3535 columns = []
3636 for c2 in constraints:
37- try:
38- entry = getattr(self, f"_{type(c1.op).__name__}_{type(c2.op).__name__}")(c1, kernel, c2)
39- except AttributeError:
40- try:
41- entry = getattr(self, f"_{type(c2.op).__name__}_{type(c1.op).__name__}")(c2, kernel, c1).T
42- except AttributeError:
43- raise NotImplementedError(
44- f"No rule found to combine operators of types {type(c1.op).__name__} and {type(c2.op).__name__} with kernel.")
37+ combiner12 = getattr(self, f"_{type(c1.op).__name__}_{type(c2.op).__name__}", None)
38+ combiner21 = getattr(self, f"_{type(c2.op).__name__}_{type(c1.op).__name__}", None)
39+ if combiner12:
40+ entry = combiner12(c1, kernel, c2)
41+ elif combiner21:
42+ entry = combiner21(c2, kernel, c1).T
43+ else:
44+ raise NotImplementedError(
45+ f"No rule found to combine operators of types \
46+ {type(c1.op).__name__} and {type(c2.op).__name__} with kernel.")
4547 columns.append(entry)
4648 rows.append(np.concatenate(columns, axis=1))
4749 return np.concatenate(rows)
@@ -96,9 +98,10 @@ def __call__(
9698 ) -> np.ndarray:
9799 entries = []
98100 for c in constraints:
99- try:
100- entry = getattr(self, f"_{type(c.op).__name__}")(c, kernel, w)
101- except AttributeError:
101+ combiner = getattr(self, f"_{type(c.op).__name__}")
102+ if combiner:
103+ entry = combiner(c, kernel, w)
104+ else:
102105 raise NotImplementedError(
103106 f"No rule found to combine operator of type {type(c.op).__name__} with kernel.")
104107 entries.append(entry)
0 commit comments