Skip to content

Commit 4053f21

Browse files
committed
Correct the super using
1 parent 7fc03e9 commit 4053f21

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

src/pyscipopt/matrix.pxi

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,6 @@ def _is_number(e):
1717
return False
1818

1919

20-
def _matrixexpr_richcmp(self, other, op):
21-
if not (_is_number(other) or isinstance(other, (Expr, MatrixExpr, np.ndarray))):
22-
raise TypeError(f"Unsupported type {type(other)}")
23-
24-
if op == 1: # <=
25-
return super(self).__le__(other).view(MatrixExprCons)
26-
elif op == 5: # >=
27-
return super(self).__ge__(other).view(MatrixExprCons)
28-
elif op == 2: # ==
29-
return super(self).__eq__(other).view(MatrixExprCons)
30-
else:
31-
raise NotImplementedError("Can only support constraints with '<=', '>=', or '=='.")
32-
33-
3420
class MatrixExpr(np.ndarray):
3521
def sum(self, **kwargs):
3622
"""
@@ -41,13 +27,22 @@ class MatrixExpr(np.ndarray):
4127
return res if res.size > 1 else res.item()
4228

4329
def __le__(self, other: Union[float, int, Expr, np.ndarray, 'MatrixExpr']) -> MatrixExprCons:
44-
return _matrixexpr_richcmp(self, other, 1)
30+
if not _is_number(other) or not isinstance(other, (Expr, MatrixExpr, np.ndarray)):
31+
raise TypeError(f"Unsupported type {type(other)}")
32+
33+
return super().__le__(other).view(MatrixExprCons)
4534

4635
def __ge__(self, other: Union[float, int, Expr, np.ndarray, 'MatrixExpr']) -> MatrixExprCons:
47-
return _matrixexpr_richcmp(self, other, 5)
36+
if not _is_number(other) or not isinstance(other, (Expr, MatrixExpr, np.ndarray)):
37+
raise TypeError(f"Unsupported type {type(other)}")
38+
39+
return super().__ge__(other).view(MatrixExprCons)
4840

4941
def __eq__(self, other: Union[float, int, Expr, np.ndarray, 'MatrixExpr']) -> MatrixExprCons:
50-
return _matrixexpr_richcmp(self, other, 2)
42+
if not _is_number(other) or not isinstance(other, (Expr, MatrixExpr, np.ndarray)):
43+
raise TypeError(f"Unsupported type {type(other)}")
44+
45+
return super().__eq__(other).view(MatrixExprCons)
5146

5247
def __add__(self, other):
5348
return super().__add__(other).view(MatrixExpr)
@@ -85,10 +80,16 @@ class MatrixGenExpr(MatrixExpr):
8580
class MatrixExprCons(np.ndarray):
8681

8782
def __le__(self, other: Union[float, int, np.ndarray]) -> MatrixExprCons:
88-
return _matrixexpr_richcmp(self, other, 1)
83+
if not _is_number(other) or not isinstance(other, (Expr, MatrixExpr, np.ndarray)):
84+
raise TypeError(f"Unsupported type {type(other)}")
85+
86+
return super().__le__(other).view(MatrixExprCons)
8987

9088
def __ge__(self, other: Union[float, int, np.ndarray]) -> MatrixExprCons:
91-
return _matrixexpr_richcmp(self, other, 5)
89+
if not _is_number(other) or not isinstance(other, (Expr, MatrixExpr, np.ndarray)):
90+
raise TypeError(f"Unsupported type {type(other)}")
91+
92+
return super().__ge__(other).view(MatrixExprCons)
9293

9394
def __eq__(self, other):
9495
raise NotImplementedError("Cannot compare MatrixExprCons with '=='.")

0 commit comments

Comments
 (0)