-
Notifications
You must be signed in to change notification settings - Fork 276
DEP: remove _is_number(Expr) from expr.pyi file
#1168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
float(Expr) can't return True
There was a problem hiding this 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 removes dead code from the Expr class by eliminating checks for _is_number(self) which always return False since Expr instances cannot be converted to float.
Changes:
- Removed unreachable code branches in
__add__,__mul__, and__rtruediv__methods that checked ifselfis a number - Simplified
__rtruediv__implementation by removing the always-false conditional check
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
This pr is ready. |
|
|
|
Same failures. Can you please try with and without your changes locally and report back, please? |
Replaces manual timing with the timeit module for more accurate performance measurement in matrix operation tests. Updates assertions to require the optimized implementation to be at least 25% faster, and reduces test parameterization to n=100 for consistency.
5d66cba to
1d0e6f5
Compare
Replaces random matrix generation with a stacked matrix of zeros and ones in test_matrix_dot_performance to provide more controlled test data.
|
GitHub and local test as below for 532dee4 from time import time
import numpy as np
from pyscipopt import Model
n = 50
model = Model()
x = model.addMatrixVar((n, n))
a = np.random.rand(n, n)
conda env# packages in environment at D:\Users\Zero\AppData\Local\miniforge3\envs\cy310:
#
# Name Version Build Channel
bzip2 1.0.8 h0ad9c76_8 conda-forge
ca-certificates 2025.11.12 h4c7d964_0 conda-forge
certifi 2025.11.12 pypi_0 pypi
charset-normalizer 3.4.4 pypi_0 pypi
colorama 0.4.6 pyhd8ed1ab_1 conda-forge
cython 3.2.3 py310h23e71ea_0 conda-forge
exceptiongroup 1.3.1 pyhd8ed1ab_0 conda-forge
execnet 2.1.2 pyhd8ed1ab_0 conda-forge
idna 3.11 pypi_0 pypi
iniconfig 2.3.0 pyhd8ed1ab_0 conda-forge
libblas 3.9.0 35_h5709861_mkl conda-forge
libcblas 3.9.0 35_h2a3cdd5_mkl conda-forge
libexpat 2.7.3 hac47afa_0 conda-forge
libffi 3.5.2 h52bdfb6_0 conda-forge
libhwloc 2.11.2 default_hc8275d1_1000 conda-forge
libiconv 1.18 hc1393d2_2 conda-forge
liblapack 3.9.0 35_hf9ab0e9_mkl conda-forge
liblzma 5.8.1 h2466b09_2 conda-forge
libpython 0.2 pypi_0 pypi
libpython-static 3.10.19 hac47afa_2_cpython conda-forge
libsqlite 3.51.1 hf5d6505_1 conda-forge
libxml2 2.13.9 h741aa76_0 conda-forge
libzlib 1.3.1 h2466b09_2 conda-forge
llvm-openmp 21.1.8 h4fa8253_0 conda-forge
m2w64-binutils 2.25.1 5 conda-forge
m2w64-bzip2 1.0.6 6 conda-forge
m2w64-crt-git 5.0.0.4636.2595836 2 conda-forge
m2w64-gcc 5.3.0 6 conda-forge
m2w64-gcc-ada 5.3.0 6 conda-forge
m2w64-gcc-fortran 5.3.0 6 conda-forge
m2w64-gcc-libgfortran 5.3.0 6 conda-forge
m2w64-gcc-libs 5.3.0 7 conda-forge
m2w64-gcc-libs-core 5.3.0 7 conda-forge
m2w64-gcc-objc 5.3.0 6 conda-forge
m2w64-gmp 6.1.0 2 conda-forge
m2w64-headers-git 5.0.0.4636.c0ad18a 2 conda-forge
m2w64-isl 0.16.1 2 conda-forge
m2w64-libiconv 1.14 6 conda-forge
m2w64-libmangle-git 5.0.0.4509.2e5a9a2 2 conda-forge
m2w64-libwinpthread-git 5.0.0.4634.697f757 2 conda-forge
m2w64-make 4.1.2351.a80a8b8 2 conda-forge
m2w64-mpc 1.0.3 3 conda-forge
m2w64-mpfr 3.1.4 4 conda-forge
m2w64-pkg-config 0.29.1 2 conda-forge
m2w64-toolchain 5.3.0 7 conda-forge
m2w64-tools-git 5.0.0.4592.90b8472 2 conda-forge
m2w64-windows-default-manifest 6.4 3 conda-forge
m2w64-winpthreads-git 5.0.0.4634.697f757 2 conda-forge
m2w64-zlib 1.2.8 10 conda-forge
mkl 2024.2.2 h57928b3_16 conda-forge
msys2-conda-epoch 20160418 1 conda-forge
numpy 2.2.6 py310h4987827_0 conda-forge
openssl 3.6.0 h725018a_0 conda-forge
packaging 25.0 pyh29332c3_1 conda-forge
pip 25.3 pyh8b19718_0 conda-forge
pluggy 1.6.0 pyhf9edf01_1 conda-forge
pthreads-win32 2.9.1 h2466b09_4 conda-forge
pygments 2.19.2 pyhd8ed1ab_0 conda-forge
pytest 9.0.2 pyhcf101f3_0 conda-forge
pytest-xdist 3.8.0 pyhd8ed1ab_0 conda-forge
python 3.10.19 hc20f281_2_cpython conda-forge
python_abi 3.10 8_cp310 conda-forge
requests 2.32.5 pypi_0 pypi
setuptools 80.9.0 pyhff2d567_0 conda-forge
tbb 2021.13.0 h62715c5_1 conda-forge
tk 8.6.13 h2c6b04d_3 conda-forge
tomli 2.3.0 pyhcf101f3_0 conda-forge
typing_extensions 4.15.0 pyhcf101f3_0 conda-forge
tzdata 2025c h8577fbf_0 conda-forge
ucrt 10.0.26100.0 h57928b3_0 conda-forge
urllib3 2.6.2 pypi_0 pypi
vc 14.3 h2b53caa_33 conda-forge
vc14_runtime 14.44.35208 h818238b_33 conda-forge
vcomp14 14.44.35208 h818238b_33 conda-forge
wheel 0.45.1 pyhd8ed1ab_1 conda-forge |
| assert np_res.shape == scip_res.shape | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("n", [50, 100]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A small data size will fail sometimes
| start = time() | ||
| a @ x.view(np.ndarray) | ||
| orig = time() - start | ||
| a = np.vstack((np.zeros((n // 2, n)), np.ones((n // 2, n)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a fixed constant matrix (a half-zeroes and a half-ones) instead of a random matrix.
| a @ x | ||
| matrix = time() - start | ||
| number = 5 | ||
| matrix = timeit(lambda: a @ x, number=number) / number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use timeit avoid pytest using cache
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I have to say, performance test cases sometimes can't pass.
All of this (use timeit, isGE, and *1.25) is decreasing the possibility.
I tested 20 times for pytest -n auto tests/test_matrix_variable.py, and 1 time failed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, there is some performance variability, but the goal of using matrices and a significant portion of your PRs is to increase performance over not using them. Agreed that it makes sense to reduce randomness in the performance tests.
_is_number(Expr)always return False. BecauseExprdoesn't have__float__method and it isn't a number type.