-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Fix the _array_ methods to avoid deprecation warnings #26442
Conversation
def __array__(self, dtype=object, copy=None): if copy is not None and not copy: raise TypeError("Cannot implement copy=False when converting Matrix to ndarray")
Currently copy=False is commented out due to a bug in numpy. see: numpy/numpy#25941 (comment)
✅ Hi, I am the SymPy bot. I'm here to help you write a release notes entry. Please read the guide on how to write release notes.
Click here to see the pull request description that was parsed.
|
np_array = array([[1,2], [3,4]]) | ||
assert array_equal(array(A), np_array) | ||
assert array_equal(array(A, copy=True), np_array) | ||
#raises(TypeError, lambda: array(A, copy=False)) TODO: Uncomment this whenever copy variable properly passes to __array__ |
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.
This works as intended if numpy 2.0.0rc1 is installed.
We should add a version check
int(importlib.metadata.version('numpy').split('.')[0]) >= 2
also, fixed a little bug in test_matexpr which was causing the test to fail on master.
Benchmark results from GitHub Actions Lower numbers are good, higher numbers are bad. A ratio less than 1 Significantly changed benchmark results (PR vs master) Significantly changed benchmark results (master vs previous release) | Change | Before [40e55587] | After [d91b8ad6] <1.12.1rc1> | Ratio | Benchmark (Parameter) |
|----------|----------------------|--------------------------------|---------|----------------------------------------------------------------------|
| - | 68.8±0.9ms | 44.5±0.5ms | 0.65 | integrate.TimeIntegrationRisch02.time_doit(10) |
| - | 66.9±0.7ms | 44.1±0.5ms | 0.66 | integrate.TimeIntegrationRisch02.time_doit_risch(10) |
| + | 18.5±0.07μs | 30.1±0.1μs | 1.63 | integrate.TimeIntegrationRisch03.time_doit(1) |
| - | 5.45±0.02ms | 2.87±0.01ms | 0.53 | logic.LogicSuite.time_load_file |
| - | 72.8±0.8ms | 28.8±0.3ms | 0.4 | polys.TimeGCD_GaussInt.time_op(1, 'dense') |
| - | 25.5±0.2ms | 16.9±0.05ms | 0.66 | polys.TimeGCD_GaussInt.time_op(1, 'expr') |
| - | 73.2±0.5ms | 29.0±0.04ms | 0.4 | polys.TimeGCD_GaussInt.time_op(1, 'sparse') |
| - | 254±0.8ms | 127±0.1ms | 0.5 | polys.TimeGCD_GaussInt.time_op(2, 'dense') |
| - | 258±3ms | 126±0.6ms | 0.49 | polys.TimeGCD_GaussInt.time_op(2, 'sparse') |
| - | 667±4ms | 376±2ms | 0.56 | polys.TimeGCD_GaussInt.time_op(3, 'dense') |
| - | 662±4ms | 375±2ms | 0.57 | polys.TimeGCD_GaussInt.time_op(3, 'sparse') |
| - | 498±2μs | 289±2μs | 0.58 | polys.TimeGCD_LinearDenseQuadraticGCD.time_op(1, 'dense') |
| - | 1.77±0ms | 1.06±0.02ms | 0.6 | polys.TimeGCD_LinearDenseQuadraticGCD.time_op(2, 'dense') |
| - | 5.74±0.07ms | 3.16±0.02ms | 0.55 | polys.TimeGCD_LinearDenseQuadraticGCD.time_op(3, 'dense') |
| - | 446±2μs | 236±1μs | 0.53 | polys.TimeGCD_QuadraticNonMonicGCD.time_op(1, 'dense') |
| - | 1.47±0.01ms | 687±4μs | 0.47 | polys.TimeGCD_QuadraticNonMonicGCD.time_op(2, 'dense') |
| - | 4.90±0.04ms | 1.68±0.01ms | 0.34 | polys.TimeGCD_QuadraticNonMonicGCD.time_op(3, 'dense') |
| - | 376±1μs | 206±0.5μs | 0.55 | polys.TimeGCD_SparseGCDHighDegree.time_op(1, 'dense') |
| - | 2.40±0.01ms | 1.23±0.01ms | 0.51 | polys.TimeGCD_SparseGCDHighDegree.time_op(3, 'dense') |
| - | 10.00±0.05ms | 4.36±0.03ms | 0.44 | polys.TimeGCD_SparseGCDHighDegree.time_op(5, 'dense') |
| - | 354±0.7μs | 170±1μs | 0.48 | polys.TimeGCD_SparseNonMonicQuadratic.time_op(1, 'dense') |
| - | 2.45±0.03ms | 898±8μs | 0.37 | polys.TimeGCD_SparseNonMonicQuadratic.time_op(3, 'dense') |
| - | 9.64±0.1ms | 2.66±0.02ms | 0.28 | polys.TimeGCD_SparseNonMonicQuadratic.time_op(5, 'dense') |
| - | 1.03±0.01ms | 441±2μs | 0.43 | polys.TimePREM_LinearDenseQuadraticGCD.time_op(3, 'dense') |
| - | 1.76±0.01ms | 514±1μs | 0.29 | polys.TimePREM_LinearDenseQuadraticGCD.time_op(3, 'sparse') |
| - | 5.87±0.06ms | 1.82±0.02ms | 0.31 | polys.TimePREM_LinearDenseQuadraticGCD.time_op(5, 'dense') |
| - | 8.31±0.05ms | 1.54±0.01ms | 0.19 | polys.TimePREM_LinearDenseQuadraticGCD.time_op(5, 'sparse') |
| - | 285±0.8μs | 66.2±0.4μs | 0.23 | polys.TimePREM_QuadraticNonMonicGCD.time_op(1, 'sparse') |
| - | 3.46±0.02ms | 399±3μs | 0.12 | polys.TimePREM_QuadraticNonMonicGCD.time_op(3, 'dense') |
| - | 4.02±0.01ms | 291±2μs | 0.07 | polys.TimePREM_QuadraticNonMonicGCD.time_op(3, 'sparse') |
| - | 6.99±0.1ms | 1.29±0.01ms | 0.18 | polys.TimePREM_QuadraticNonMonicGCD.time_op(5, 'dense') |
| - | 8.68±0.09ms | 862±6μs | 0.1 | polys.TimePREM_QuadraticNonMonicGCD.time_op(5, 'sparse') |
| - | 5.04±0.02ms | 3.08±0.03ms | 0.61 | polys.TimeSUBRESULTANTS_LinearDenseQuadraticGCD.time_op(2, 'sparse') |
| - | 12.0±0.03ms | 6.82±0.03ms | 0.57 | polys.TimeSUBRESULTANTS_LinearDenseQuadraticGCD.time_op(3, 'dense') |
| - | 22.2±0.07ms | 9.10±0.02ms | 0.41 | polys.TimeSUBRESULTANTS_LinearDenseQuadraticGCD.time_op(3, 'sparse') |
| - | 5.25±0.02ms | 878±3μs | 0.17 | polys.TimeSUBRESULTANTS_QuadraticNonMonicGCD.time_op(1, 'sparse') |
| - | 12.6±0.04ms | 7.14±0.02ms | 0.57 | polys.TimeSUBRESULTANTS_QuadraticNonMonicGCD.time_op(2, 'sparse') |
| - | 101±0.6ms | 26.3±0.09ms | 0.26 | polys.TimeSUBRESULTANTS_QuadraticNonMonicGCD.time_op(3, 'dense') |
| - | 166±0.6ms | 54.3±0.7ms | 0.33 | polys.TimeSUBRESULTANTS_QuadraticNonMonicGCD.time_op(3, 'sparse') |
| - | 358±2μs | 219±2μs | 0.61 | polys.TimeSUBRESULTANTS_SparseGCDHighDegree.time_op(1, 'sparse') |
| - | 4.24±0.03ms | 849±6μs | 0.2 | polys.TimeSUBRESULTANTS_SparseGCDHighDegree.time_op(3, 'dense') |
| - | 5.24±0.05ms | 388±1μs | 0.07 | polys.TimeSUBRESULTANTS_SparseGCDHighDegree.time_op(3, 'sparse') |
| - | 19.8±0.06ms | 2.84±0.01ms | 0.14 | polys.TimeSUBRESULTANTS_SparseGCDHighDegree.time_op(5, 'dense') |
| - | 22.8±0.1ms | 643±4μs | 0.03 | polys.TimeSUBRESULTANTS_SparseGCDHighDegree.time_op(5, 'sparse') |
| - | 479±3μs | 138±1μs | 0.29 | polys.TimeSUBRESULTANTS_SparseNonMonicQuadratic.time_op(1, 'sparse') |
| - | 4.85±0.03ms | 622±8μs | 0.13 | polys.TimeSUBRESULTANTS_SparseNonMonicQuadratic.time_op(3, 'dense') |
| - | 5.30±0.04ms | 141±2μs | 0.03 | polys.TimeSUBRESULTANTS_SparseNonMonicQuadratic.time_op(3, 'sparse') |
| - | 12.9±0.05ms | 1.31±0ms | 0.1 | polys.TimeSUBRESULTANTS_SparseNonMonicQuadratic.time_op(5, 'dense') |
| - | 14.0±0.2ms | 144±2μs | 0.01 | polys.TimeSUBRESULTANTS_SparseNonMonicQuadratic.time_op(5, 'sparse') |
| - | 135±0.6μs | 73.7±0.4μs | 0.55 | solve.TimeMatrixOperations.time_rref(3, 0) |
| - | 249±0.7μs | 86.4±0.2μs | 0.35 | solve.TimeMatrixOperations.time_rref(4, 0) |
| - | 24.8±0.2ms | 10.3±0.06ms | 0.42 | solve.TimeSolveLinSys189x49.time_solve_lin_sys |
| - | 28.7±0.2ms | 15.4±0.2ms | 0.54 | solve.TimeSparseSystem.time_linsolve_Aaug(20) |
| - | 55.0±0.4ms | 25.4±0.1ms | 0.46 | solve.TimeSparseSystem.time_linsolve_Aaug(30) |
| - | 28.4±0.2ms | 15.3±0.2ms | 0.54 | solve.TimeSparseSystem.time_linsolve_Ab(20) |
| - | 54.5±0.3ms | 24.6±0.07ms | 0.45 | solve.TimeSparseSystem.time_linsolve_Ab(30) |
Full benchmark results can be found as artifacts in GitHub Actions |
Looks good. Thanks |
References to other Issues or PRs
Brief description of what is fixed or changed
Fixes #26302
I finished the work started in PR #26303 by adding test cases for the array methods.
Note: currently the tests with copy=False are commented out because there is an issue
with numpy passing the copy argument into the array function. As a result, array
will not raise an error as it should, so this test must be commented out for now.
see this comment for confirmation:
numpy/numpy#25941 (comment).
Other comments
Release Notes
NO ENTRY