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
BUG: MatrixExpr can't be compared with Expr (#1069)
* Replace Variable with Expr in MatrixExpr
Updated type hints and isinstance checks in MatrixExpr comparison methods to use Expr instead of Variable. This change improves compatibility with broader expression types in matrix operations.
* add test case
* Replace Variable with Expr in MatrixExprCons
Updated type hints and isinstance checks in MatrixExprCons.__le__ and __ge__ methods to use Expr instead of Variable. This change improves consistency with the expected types for matrix expression constraints.
* add test case
* Update CHANGELOG.md
* Add test for ranged matrix constraint
Introduces test_ranged_matrix_cons to verify correct behavior when adding a ranged matrix constraint to the model. Ensures that the matrix variable x is set to ones as expected.
* Refactor matrix comparison operators using helper
Introduced a shared _matrixexpr_richcmp helper to handle rich comparison logic for MatrixExpr and MatrixExprCons, reducing code duplication and improving maintainability. Updated __le__, __ge__, and __eq__ methods to use this helper, and removed redundant code.
* Replace TypeError with NotImplementedError in __eq__
The __eq__ method of MatrixExprCons now raises NotImplementedError with a descriptive message instead of TypeError, clarifying that '==' comparison is not supported.
* Add tests for matrix constraint operators
Added tests for '<=', '>=', and '==' operators in matrix constraints. Verified correct exception is raised for unsupported '==' operator.
* Update CHANGELOG.md
* BUG: fix circular imports
Relocated the _is_number utility from expr.pxi to matrix.pxi for better modularity. Updated _matrixexpr_richcmp to use a local _richcmp helper for comparison operations.
* Fix matrix comparison shape handling
Replaces usage of undefined 'shape' variable with 'self.shape' when creating the result array in _matrixexpr_richcmp, ensuring correct array dimensions.
* Fix redundant .all() calls in matrix variable tests
Removed unnecessary double .all() calls in assertions for matrix variable tests, simplifying the checks for equality with np.ones(3).
* Fix matrix variable test assertions to use getVal
Updated assertions in test_matrix_variable.py to use m.getVal(x) and m.getVal(y) instead of direct variable comparison. This ensures the tests check the evaluated values from the model rather than the symbolic variables.
* let MatrixExprCons support <= and >= operator
* Refactor matrix comparison tests to optimize assertions and remove redundant checks
* let MatrixExprCons support <= and >= operator
* find what type it is
* align with `__add__`
* test "==" first
* Revert "let MatrixExprCons support <= and >= operator"
This reverts commit f69ce7e.
* Revert "let MatrixExprCons support <= and >= operator"
This reverts commit b6dcf42.
* find what type it is
* test expr
* Change the order
* Remove ExprCons
Can't add with ExprCons
* Ranged ExprCons requires number
* Update CHANGELOG.md
* Lint codes with 4 spaces
* keep `_is_number` in expr.pxi
* Update CHANGELOG.md
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Add quotes for annotations
* Simplify loop via `numpy.ndarray.flat`
Replaced explicit loops with list comprehensions for element-wise comparison, improving readability and potentially performance in matrix expression comparisons.
* Add shape check for ndarray comparison in _matrixexpr_richcmp
Raises a ValueError if the shapes of self and the other ndarray do not match during comparison, preventing invalid element-wise operations.
* TST: test MatrixExprCons vs Variable
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
0 commit comments