Speed up sol[UnaryExpr] via C-level math and refactor UnaryExpr#1224
Open
Zeroto521 wants to merge 8 commits into
Open
Speed up sol[UnaryExpr] via C-level math and refactor UnaryExpr#1224Zeroto521 wants to merge 8 commits into
sol[UnaryExpr] via C-level math and refactor UnaryExpr#1224Zeroto521 wants to merge 8 commits into
Conversation
…r unary expressions Remove Python math module and use libc.math for C-level functions (fabs, exp, log, sqrt, sin, cos). Refactor unary expression evaluation by introducing specific subclasses (AbsExpr, ExpExpr, LogExpr, SqrtExpr, SinExpr, CosExpr) with dedicated evaluate methods using C functions, replacing the generic UnaryExpr implementation.
Update UnaryExpr type stubs to include concrete expression subclasses for more precise type annotations. This change refines the return type of __abs__ and introduces new expression classes. - Change __abs__ return type from GenExpr to AbsExpr - Add AbsExpr, ExpExpr, LogExpr, SqrtExpr, SinExpr, and CosExpr classes - All new classes inherit from UnaryExpr
UnaryExpr
UnaryExprUnaryExpr
UnaryExprsol[UnaryExpr] via C-level math and refactor UnaryExpr
Member
|
By the way, @Zeroto521 , out of curiosity. Are you also using PySCIPOpt for your work, or are you just speeding things up for fun? |
Contributor
Author
|
80% of the OR problems I encounter use commercial solvers or our closure algorithms for large-scale, speed-critical cases, while the rest use open-source ones for small tasks and research. |
Zeroto521
commented
Jun 11, 2026
| def __abs__(self) -> UnaryExpr: | ||
| if self._op == "abs": | ||
| return <UnaryExpr>self.copy() | ||
| return UnaryExpr(Operator.fabs, self) |
Contributor
Author
There was a problem hiding this comment.
ExprLike.__abs__ can replace UnaryExpr(Operator.fabs, self)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This branch is 1.45x faster than master.