Skip to content

Commit 3c88ce7

Browse files
committed
Add docstring to _wrap_ufunc
Add an explanatory docstring to the _wrap_ufunc helper describing how it handles scalars and collections: converting numeric inputs to Constant expressions, applying the ufunc element-wise via np.frompyfunc for arrays/lists/tuples, and returning a MatrixGenExpr for ndarrays or a list/tuple of GenExprs otherwise. Documentation-only change; no functional behavior modified.
1 parent 43746e2 commit 3c88ce7

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

src/pyscipopt/expr.pxi

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,22 @@ cdef inline object _to_const(object x):
875875
cdef object _vec_to_const = np.frompyfunc(_to_const, 1, 1)
876876

877877
cdef inline object _wrap_ufunc(object x, object ufunc):
878+
"""
879+
Apply a universal function (ufunc) to an expression or a collection of expressions.
880+
881+
Parameters
882+
----------
883+
x : Expr, GenExpr, number, np.ndarray, list, or tuple
884+
- If x is a scalar expression or number, apply the ufunc directly to it. And if
885+
it's a number, convert it to a Constant expression first.
886+
- If x is a vector (np.ndarray, list, or tuple), apply the ufunc element-wise
887+
using np.frompyfunc to convert each element to a Constant if it's a number,
888+
and then apply the ufunc. The result is returned as a MatrixGenExpr if x was
889+
an np.ndarray, otherwise as a list or tuple of GenExprs.
890+
891+
ufunc : np.ufunc
892+
The universal function to be applied to x.
893+
"""
878894
if isinstance(x, (np.ndarray, list, tuple)):
879895
res = ufunc(_vec_to_const(x))
880896
return res.view(MatrixGenExpr) if isinstance(res, np.ndarray) else res

0 commit comments

Comments
 (0)