Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6874ae4
Consolidate operator overloads into ExprLike
Zeroto521 Apr 6, 2026
d8f2cce
Consolidate ExprLike operator methods
Zeroto521 Apr 6, 2026
d140fb7
Move __rtruediv__ to ExprLike base class
Zeroto521 Apr 6, 2026
6998944
Update changelog: move magic methods to ExprLike
Zeroto521 Apr 6, 2026
9d2d251
Update CHANGELOG.md
Zeroto521 Apr 6, 2026
043b032
Mark reflected dunder methods positional-only
Zeroto521 Apr 7, 2026
11d1801
Consolidate arithmetic dunders into ExprLike
Zeroto521 Apr 7, 2026
b814b40
Update CHANGELOG.md
Zeroto521 Apr 7, 2026
27ff00f
Merge branch 'ExprLike' of github.com:Zeroto521/PySCIPOpt into ExprLike
Zeroto521 Apr 7, 2026
c7f6715
style: format scip.pyi with ruff
Zeroto521 Apr 7, 2026
483528a
Merge branch 'scipopt:master' into ExprLike
Zeroto521 Apr 24, 2026
d88206c
Merge branch 'master' into ExprLike
Zeroto521 May 20, 2026
7dbf944
Refine operator type hints in scip.pyi
Zeroto521 May 20, 2026
8e8bf59
Update CHANGELOG.md
Zeroto521 May 20, 2026
64e6947
Merge branch 'master' into ExprLike
Joao-Dionisio May 20, 2026
6ca96c9
Make ExprLike.__neg__ positional-only
Zeroto521 May 23, 2026
823b94c
Refine ExprLike operator return types
Zeroto521 May 23, 2026
f21d708
Merge branch 'ExprLike' of github.com:Zeroto521/PySCIPOpt into ExprLike
Zeroto521 May 23, 2026
ec64ba2
Annotate __rtruediv__ return type as GenExpr
Zeroto521 May 23, 2026
9fdca93
Annotate __neg__ return type
Zeroto521 May 23, 2026
61cea57
Unify __rtruediv__ typing in stubs
Zeroto521 May 23, 2026
dcd64b9
Merge branch 'master' into ExprLike
Zeroto521 May 23, 2026
aa6ae86
Mark __neg__ as positional-only in scip.pyi
Zeroto521 May 23, 2026
fb3a4bd
Merge branch 'master' into ExprLike
Joao-Dionisio Jun 5, 2026
c3ca2fe
Resolve CHANGELOG merge conflict
Joao-Dionisio Jun 5, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
### Changed
- Speed up `constant * Expr` via C-level API
- Speed up `Term.__eq__` via the C-level API
- Move magic methods (`__radd__`, `__sub__`, `__rsub__`, `__rmul__`, `__richcmp__`, `__neg__`, and `__rtruediv__`) to `ExprLike` base class
Comment thread
Zeroto521 marked this conversation as resolved.
Outdated
### Removed
- Removed outdated warning about Make build system incompatibility
- Removed `Term.ptrtuple` to optimize `Term` memory usage
Expand Down
69 changes: 21 additions & 48 deletions src/pyscipopt/expr.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,27 @@ cdef class ExprLike:

return NotImplemented

def __radd__(self, other):
return self + other

def __sub__(self, other):
return self + (-other)
Comment thread
Zeroto521 marked this conversation as resolved.
Outdated

def __rsub__(self, other):
return (-self) + other

def __rmul__(self, other):
return self * other

def __rtruediv__(self, other):
return buildGenExprObj(other) / self

def __richcmp__(self, other, int op):
return _expr_richcmp(self, other, op)

def __neg__(self):
return self * -1.0

def __abs__(self) -> GenExpr:
return UnaryExpr(Operator.fabs, buildGenExprObj(self))

Expand Down Expand Up @@ -383,10 +404,6 @@ cdef class Expr(ExprLike):
selfexpr = buildGenExprObj(self)
return selfexpr.__truediv__(other)

def __rtruediv__(self, other):
''' other / self '''
return buildGenExprObj(other) / self

def __pow__(self, other, modulo):
if float(other).is_integer() and other >= 0:
exp = int(other)
Expand All @@ -411,25 +428,6 @@ cdef class Expr(ExprLike):
else:
raise TypeError(f"Unsupported base type {type(other)} for exponentiation.")

def __neg__(self):
return Expr({v:-c for v,c in self.terms.items()})
Comment thread
Joao-Dionisio marked this conversation as resolved.

def __sub__(self, other):
return self + (-other)

def __radd__(self, other):
return self.__add__(other)

def __rmul__(self, other):
return self.__mul__(other)

def __rsub__(self, other):
return -1.0 * self + other

def __richcmp__(self, other, op):
'''turn it into a constraint'''
return _expr_richcmp(self, other, op)

def normalize(self):
'''remove terms with coefficient of 0'''
self.terms = {t:c for (t,c) in self.terms.items() if c != 0.0}
Expand Down Expand Up @@ -488,7 +486,6 @@ cdef class ExprCons:
if not self._rhs is None:
self._rhs -= c


def __richcmp__(self, other, op):
'''turn it into a constraint'''
if op == 1: # <=
Expand Down Expand Up @@ -715,30 +712,6 @@ cdef class GenExpr(ExprLike):
raise ZeroDivisionError("cannot divide by 0")
return self * divisor**(-1)

def __rtruediv__(self, other):
''' other / self '''
otherexpr = buildGenExprObj(other)
return otherexpr.__truediv__(self)

def __neg__(self):
return -1.0 * self
Comment thread
Joao-Dionisio marked this conversation as resolved.

def __sub__(self, other):
return self + (-other)

def __radd__(self, other):
return self.__add__(other)

def __rmul__(self, other):
return self.__mul__(other)

def __rsub__(self, other):
return -1.0 * self + other

def __richcmp__(self, other, op):
'''turn it into a constraint'''
return _expr_richcmp(self, other, op)

def degree(self):
'''Note: none of these expressions should be polynomial'''
return float('inf')
Expand Down
Loading