From 40a7efe511b955c792d52a06eb2ef352e6f71765 Mon Sep 17 00:00:00 2001 From: 40% Date: Fri, 23 Jan 2026 13:24:47 +0800 Subject: [PATCH 1/2] Set __array_priority__ for MatrixExpr and MatrixExprCons Added __array_priority__ attributes to MatrixExpr and MatrixExprCons classes to ensure correct precedence in NumPy operations involving these custom ndarray subclasses. --- src/pyscipopt/matrix.pxi | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/pyscipopt/matrix.pxi b/src/pyscipopt/matrix.pxi index 84fb09b77..f88af8b89 100644 --- a/src/pyscipopt/matrix.pxi +++ b/src/pyscipopt/matrix.pxi @@ -17,6 +17,8 @@ cnp.import_array() class MatrixExpr(np.ndarray): + __array_priority__ = 100 + def __array_ufunc__( self, ufunc: np.ufunc, @@ -84,6 +86,8 @@ class MatrixGenExpr(MatrixExpr): class MatrixExprCons(np.ndarray): + __array_priority__ = 101 + def __array_ufunc__(self, ufunc, method, *args, **kwargs): if method == "__call__": args = tuple(_ensure_array(arg) for arg in args) From d00fb20bf3047001a4d3bf3b07c3345098bbb25b Mon Sep 17 00:00:00 2001 From: 40% Date: Fri, 23 Jan 2026 13:41:42 +0800 Subject: [PATCH 2/2] Update changelog for MatrixExpr __array_priority__ addition Added a changelog entry noting that `__array_priority__` is now set for MatrixExpr and MatrixExprCons. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc7dd4b59..9a0a3828c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ - Speed up np.ndarray(..., dtype=np.float64) @ MatrixExpr - Minimum numpy version increased from 1.16.0 to 1.19.0 - MatrixExpr and MatrixExprCons use `__array_ufunc__` protocol to control all numpy.ufunc inputs and outputs +- Set `__array_priority__` for MatrixExpr and MatrixExprCons ### Removed ## 6.0.0 - 2025.xx.yy