Skip to content

Conversation

@Zeroto521
Copy link
Contributor

closes #1159
A lower numpy version, like 1.16, doesn't support the @np.vectorize decorator.

Replaces usage of _core_dot_2d with a new vectorized _core_dot_nd for mixed-type matrix multiplication in _core_dot. Defines _core_dot_nd as a vectorized wrapper around _core_dot_2d, improving code clarity and consistency.
Copilot AI review requested due to automatic review settings January 21, 2026 03:12
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a compatibility issue with NumPy 1.16 where the @np.vectorize decorator syntax was not supported. The fix refactors the code to use np.vectorize as a function call instead of a decorator, and reverts the minimum NumPy version requirement from 1.19.0 back to 1.16.0.

Changes:

  • Refactored _core_dot_2d to use np.vectorize as a function assignment instead of as a decorator
  • Reverted minimum NumPy version from 1.19.0 to 1.16.0 in pyproject.toml
  • Removed the changelog entry about the NumPy version increase

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/pyscipopt/matrix.pxi Refactored _core_dot_2d from decorator-style to function-call-style np.vectorize, changed function signature to cdef, and updated a parameter documentation
pyproject.toml Reverted minimum NumPy version requirement from 1.19.0 to 1.16.0
CHANGELOG.md Removed the entry about NumPy version increase that was previously added

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Zeroto521 Zeroto521 changed the title BUG: Compat BUG: Fix numpy 1.16 doesn't support @np.vectorize decorator syntax Jan 21, 2026
@Zeroto521 Zeroto521 changed the title BUG: Fix numpy 1.16 doesn't support @np.vectorize decorator syntax BUG: numpy 1.16 doesn't support @np.vectorize decorator syntax Jan 21, 2026
@Zeroto521 Zeroto521 changed the title BUG: numpy 1.16 doesn't support @np.vectorize decorator syntax BUG: numpy 1.16 doesn't support @np.vectorize decorator syntax Jan 21, 2026
Refactored _core_dot_2d to be a Python-accessible function with an explicit return type annotation. This improves clarity and allows the function to be used from Python code.
@Zeroto521
Copy link
Contributor Author

Since PR CI only has one environment, I'm not sure it's okay to master the branch.
So I'll build a local env to test this later.

@Joao-Dionisio
Copy link
Member

Thank you @Zeroto521 , please let me know if it passes in your local env.

Relocated the _vec_evaluate assignment to precede the _ensure_array function for improved code organization and clarity.
NumPy 1.x doesn't support bool
@Zeroto521
Copy link
Contributor Author

Zeroto521 commented Jan 21, 2026

Thank you @Zeroto521 , please let me know if it passes in your local env.

This PR is fine. Local tests are passed.
But there is another problem with numpy. #1164 (comment)

Copy link
Member

@Joao-Dionisio Joao-Dionisio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fingers crossed!

@Joao-Dionisio Joao-Dionisio merged commit 1e90ab6 into scipopt:master Jan 22, 2026
3 checks passed
@Joao-Dionisio
Copy link
Member

Joao-Dionisio commented Jan 22, 2026

Nope, now it breaks something else: https://github.com/scipopt/PySCIPOpt/actions/runs/21245818764/job/61134718269

@Zeroto521 Zeroto521 deleted the pr/1159/patch branch January 22, 2026 11:04
@Zeroto521
Copy link
Contributor Author

It's still a version compatibility problem. Only fails on window 3.8
Let's see which numpy feature cases this.

[gw2] linux -- Python 3.8.18 /opt/hostedtoolcache/Python/3.8.18/x64/bin/python

    def test_ranged_matrix_cons_with_expr():
        m = Model()
        x = m.addMatrixVar(3)
        var = m.addVar(vtype="B", ub=0)
    
        # test MatrixExprCons vs Variable
        with pytest.raises(TypeError):
            m.addMatrixCons((x <= 1) >= var)
    
        # test "==" operator
        with pytest.raises(NotImplementedError):
>           m.addMatrixCons((x <= 1) == 1)

tests/test_matrix_variable.py:594: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

>   raise TypeError("given constraint is not MatrixExprCons nor ExprCons but %s" % cons.__class__.__name__)
E   TypeError: given constraint is not MatrixExprCons nor ExprCons but bool

src/pyscipopt/scip.pxi:6223: TypeError

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants