Commit ec0568f
* Support more ufuncs
Handle numpy.ndarray arguments in ExprLike.__call__ by converting numeric ndarrays to MatrixGenExpr via a new _to_matrix helper and applying the ufunc. Non-numeric dtypes return NotImplemented. Also map common ufuncs (add, subtract, multiply, divide/true_divide, power, negative, comparisons, equal, absolute) to corresponding Expr/operator semantics to enable elementwise and operator-based behavior.
* Use MatrixExpr for Expr/ndarray in _to_matrix
Annotate _to_matrix arg as object and change its behavior to return MatrixExpr for numpy ndarray inputs and for values that are Expr instances; otherwise return MatrixGenExpr. This ensures Expr-backed arrays get a MatrixExpr view while keeping generic inputs as MatrixGenExpr.
* Rename test_unary to test_unary_ufunc
Rename the test function in tests/test_expr.py from test_unary to test_unary_ufunc to make its purpose clearer — it specifically targets unary ufunc behavior. No functional changes to the test logic.
* Add tests for binary numpy ufuncs
Add test_binary_ufunc to tests/test_expr.py. The new tests exercise np.add, np.subtract, np.multiply, np.divide, np.negative and np.power against Expr objects and numpy arrays, including scalar/array operands and swapped operand orders, asserting expected string representations to catch regressions in binary ufunc handling.
* Document ndarray conversion before ufunc
Add a clarifying comment in src/pyscipopt/expr.pxi explaining that when a numeric numpy ndarray is present among arguments, all arguments are converted to MatrixExpr or MatrixGenExpr before applying the ufunc. This improves code readability for future maintainers and documents the intended behavior in the ExprLike ufunc handling.
* Move np.negative test into unary ufunc tests
Relocate the np.negative assertion from the binary ufunc test block into the unary_ufunc test to group unary function checks together and eliminate the duplicate assertion. No functional changes—just test reorganization for clarity.
* Update CHANGELOG.md
* Update CHANGELOG.md
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Rename _to_matrix to _ensure_matrix
Rename helper function _to_matrix to _ensure_matrix and update its call site in ExprLike ufunc handling. The change preserves behavior (numpy arrays are viewed as MatrixExpr/MatrixGenExpr and other Expr instances map to MatrixExpr/MatrixGenExpr) while clarifying the function's intention.
* Add tests for comparison ufuncs in expressions
Extend tests/test_expr.py to cover np.less_equal, np.equal and np.greater_equal in test_binary_ufunc. Adds assertions verifying the string representation of ExprCons for both operand orders to ensure comparison ufuncs produce the expected expression forms.
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: João Dionísio <57299939+Joao-Dionisio@users.noreply.github.com>
1 parent 89f092f commit ec0568f
3 files changed
Lines changed: 86 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
246 | 246 | | |
247 | 247 | | |
248 | 248 | | |
249 | | - | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
250 | 275 | | |
251 | 276 | | |
252 | 277 | | |
| |||
1031 | 1056 | | |
1032 | 1057 | | |
1033 | 1058 | | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
1034 | 1065 | | |
1035 | 1066 | | |
1036 | 1067 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
222 | 222 | | |
223 | 223 | | |
224 | 224 | | |
225 | | - | |
| 225 | + | |
226 | 226 | | |
227 | 227 | | |
228 | 228 | | |
| |||
276 | 276 | | |
277 | 277 | | |
278 | 278 | | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
279 | 330 | | |
280 | 331 | | |
281 | 332 | | |
| |||
0 commit comments