You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Add tests for expression evaluation in Model
Introduces the test_evaluate function to verify correct evaluation of various expressions using Model.getVal, including arithmetic and trigonometric operations, and checks for TypeError on invalid input.
* Add unified expression evaluation with _evaluate methods
Introduced _evaluate methods to Term, Expr, and all GenExpr subclasses for consistent evaluation of expressions and variables. Refactored Solution and Model to use these methods, simplifying and unifying value retrieval for variables and expressions. Cleaned up class definitions and improved hashing and equality for Term and Variable.
* Optimize matrix expression evaluation in Solution
Replaced explicit loop with flat iterator for evaluating matrix expressions in Solution.getVal, improving performance and code clarity.
* Add test for matrix variable evaluation
Introduces a new test 'test_evaluate' to verify correct evaluation of matrix variable division and summation in the model.
* Remove matrix expression handling in Solution __getitem__
Eliminated special handling for MatrixExpr and MatrixGenExpr in Solution.__getitem__, simplifying the method to only evaluate single expressions. This change streamlines the code and removes unnecessary numpy array construction.
* Refactor Term class variable naming and usage
Renamed 'vars' to 'vartuple' and '_hash' to 'hashval' in the Term class for clarity. Updated all references and methods to use the new attribute names, improving code readability and consistency.
* Use double precision for expression evaluation
Changed internal evaluation methods in expression classes from float to double for improved numerical precision. Updated type declarations and imports accordingly.
* Add type annotations and improve Term class attributes
Added type annotations to the Term constructor and specified types for class attributes. This improves code clarity and type safety.
* Make _evaluate methods public and refactor Expr/Variable
Changed all _evaluate methods in expression classes from cdef to cpdef to make them accessible from Python. Moved the definition of terms and _evaluate to the Expr class in scip.pxd, and refactored Variable to inherit from Expr in scip.pxd, consolidating class member definitions. These changes improve the interface and maintainability of expression evaluation.
* Update CHANGELOG.md
* Remove hash method from Variable
* back to old behavior
* Fix MatrixExpr _evaluate to return ndarray type
Ensures that MatrixExpr._evaluate returns a numpy ndarray when appropriate. Adds a test to verify the return type of getVal for matrix variables.
* Remove unused _evaluate method from Solution stub
Deleted the _evaluate method from the Solution class in the scip.pyi stub file, as it is no longer needed. Also added TYPE_CHECKING to the typing imports.
* Add @disjoint_base decorator to Term and UnaryExpr
Applied the @disjoint_base decorator to the Term and UnaryExpr classes in scip.pyi to clarify their base class relationships. This may improve type checking or class hierarchy handling.
* Add noqa to suppress unused import warning
Appended '# noqa: F401' to the 'ClassVar' import to suppress linter warnings about unused imports in scip.pyi.
* cache `_evaluate` function for matrix
* Refactor _evaluate to use np.frompyfunc
Replaces the @np.vectorize-decorated _evaluate function with an np.frompyfunc-based implementation for evaluating expressions with solutions. This change may improve compatibility and performance when applying _evaluate to arrays.
* Simplify _evaluate return in MatrixExpr
Refactored the _evaluate method in MatrixExpr to always return the result as a NumPy ndarray, removing the conditional type check.
* Expand test_evaluate with additional variable and cases
Added a second variable 'y' to test_evaluate and included new assertions for expressions involving both variables. This improves coverage of expression evaluation, including addition and division of variables.
* Update expected value in test_evaluate assertion
Changed the expected result of m.getVal(x + y + 1) from 3 to 4 in test_evaluate to reflect updated logic or correct the test expectation.
* Optimize Expr._evaluate by iterating dict with PyDict_Next
Replaces the standard Python dict iteration in Expr._evaluate with a more efficient C-level iteration using PyDict_Next. This change improves performance by avoiding Python-level overhead when evaluating expressions.
* Optimize Term evaluation with early exit on zero
Improved the _evaluate method in Term to return early if the product becomes zero, enhancing performance. Added a test case to verify correct evaluation when a variable is zero.
* Fix loop variable usage in Term evaluation
Replaces iteration over self.vartuple with a range-based loop to correctly access variables by index, preventing potential errors in variable assignment during term evaluation.
* Refactor variable names in Term class evaluation
Renamed local variables 'scip' and 'sol' to 'scip_ptr' and 'sol_ptr' in the Term class to improve clarity and avoid shadowing the input parameter 'sol'.
* Refactor variable initialization in _evaluate methods
Updated variable initialization in Term._evaluate and Expr._evaluate for clarity and consistency. Changed res initialization to 1.0 and consolidated variable declarations to improve code readability.
* Add exception specification to _evaluate methods
Appended 'except *' to all cpdef double _evaluate methods in expression classes to ensure proper exception handling in Cython. This change improves error propagation and consistency across the codebase.
* Fix _evaluate method calls in expression classes
Corrects the _evaluate method implementations in VarExpr, PowExpr, and UnaryExpr to explicitly cast children[0] to GenExpr before calling _evaluate. This ensures proper method resolution and avoids potential attribute errors.
* Optimize SumExpr and ProdExpr evaluation loops
Refactored the _evaluate methods in SumExpr and ProdExpr to use indexed loops for better performance and type safety. Added early exit in ProdExpr when result becomes zero to improve efficiency.
* Fix evaluation of UnaryExpr in expression module
Corrects the _evaluate method in UnaryExpr to properly evaluate the child expression before applying the math operation. This ensures that the math function receives a numeric value instead of an expression object.
* Fix error message grammar
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Replace _evaluate with _vec_evaluate in matrix.pxi
Removed the unused _evaluate function and replaced its usage with _vec_evaluate in the MatrixExpr class. This change clarifies the evaluation logic and ensures consistency in function naming.
* Change hashval type to Py_ssize_t in Term class
Updated the Term class in expr.pxi to use Py_ssize_t for the hashval attribute instead of int, ensuring compatibility with Python's hash function return type and improving type safety.
* Handle 'abs' operator in UnaryExpr evaluation
Special-cases the 'abs' operator in UnaryExpr._evaluate to use math.fabs, ensuring correct evaluation for absolute value expressions.
* Update getSolVal return type to support NDArray
Modified the getSolVal method in the Model class to return either a float or a numpy NDArray of float64, reflecting support for vectorized solution values. Also imported NDArray from numpy.typing to enable this type annotation.
* Expand getVal to support GenExpr in Model
Updated the getVal method in the Model class to accept GenExpr in addition to Expr and MatrixExpr. This broadens the method's applicability to more expression types.
* Fix type cast in VarExpr _evaluate method
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Remove unused include of matrix.pxi
The include statement for matrix.pxi was removed from expr.pxi as it is no longer needed.
* Update tests/test_expr.py
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: João Dionísio <57299939+Joao-Dionisio@users.noreply.github.com>
0 commit comments