@@ -17,20 +17,6 @@ def _is_number(e):
17
17
return False
18
18
19
19
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
-
34
20
class MatrixExpr (np.ndarray ):
35
21
def sum (self , **kwargs ):
36
22
"""
@@ -41,13 +27,22 @@ class MatrixExpr(np.ndarray):
41
27
return res if res.size > 1 else res.item()
42
28
43
29
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)
45
34
46
35
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)
48
40
49
41
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)
51
46
52
47
def __add__ (self , other ):
53
48
return super ().__add__(other).view(MatrixExpr)
@@ -85,10 +80,16 @@ class MatrixGenExpr(MatrixExpr):
85
80
class MatrixExprCons (np.ndarray ):
86
81
87
82
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)
89
87
90
88
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)
92
93
93
94
def __eq__ (self , other ):
94
95
raise NotImplementedError (" Cannot compare MatrixExprCons with '=='." )
0 commit comments