Skip to content

numpy 2.0: workaround regression in rescaleData#2974

Merged
j9ac9k merged 1 commit intopyqtgraph:masterfrom
pijyoi:npy2-float-promotion
Apr 17, 2024
Merged

numpy 2.0: workaround regression in rescaleData#2974
j9ac9k merged 1 commit intopyqtgraph:masterfrom
pijyoi:npy2-float-promotion

Conversation

@pijyoi
Copy link
Copy Markdown
Contributor

@pijyoi pijyoi commented Mar 31, 2024

Testing against NumPy 2.0rc1, a performance regression was noticed in functions.rescaleData.

The cause was traced to:
https://numpy.org/devdocs/numpy_2_0_migration_guide.html#changes-to-numpy-data-type-promotion

It does seem rather counter-intuitive that the new behavior should affect in-place operations:
e.g.

data -= offset
data *= scalar

i.e. the resultant dtype can't change, so the performance regression might imply that a temporary higher precision ndarray was created? This would defeat the purpose of doing in-place operations.

The fix in this PR is only applied to the numpy codepath, and not to the cupy and numba codepaths.
The numba codepath (functions_numba.rescaleData) already marks the offset and scale arguments as type f8.

@pijyoi pijyoi force-pushed the npy2-float-promotion branch from b466c70 to e74f521 Compare April 13, 2024 03:43
@j9ac9k j9ac9k merged commit 45bf45c into pyqtgraph:master Apr 17, 2024
@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Apr 17, 2024

Thanks for keeping the library up to date w/ issues with upcoming releases of our dependencies!

@pijyoi pijyoi deleted the npy2-float-promotion branch April 17, 2024 02:02
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