Skip to content

various fixes for NumPy 2.0#2894

Merged
j9ac9k merged 1 commit intopyqtgraph:masterfrom
pijyoi:numpy20-compat
Dec 9, 2023
Merged

various fixes for NumPy 2.0#2894
j9ac9k merged 1 commit intopyqtgraph:masterfrom
pijyoi:numpy20-compat

Conversation

@pijyoi
Copy link
Copy Markdown
Contributor

@pijyoi pijyoi commented Dec 2, 2023

This PR fixes the test suite to pass with NumPy 2.0, which may be releasing soon (numpy/numpy#24300).

1) use lowercase names of nan, inf
2) avoid accessing np.core which is considered private
3) ensure clip limits fit within data dtype
4) rename row_stack to vstack
@pijyoi
Copy link
Copy Markdown
Contributor Author

pijyoi commented Dec 8, 2023

Just a short script to verify that pyqtgraph's clip_array workaround is no longer needed since numpy >= 1.25.0

import time
import numpy as np

print(np.__version__)

rng = np.random.default_rng(0)
shape = 10000
data = rng.random(size=shape, dtype=np.float32)
niters = 10000

for alpha in [0.1, 0.25]:
    for name, func in [('np', np.clip), ('pg', np.core.umath.clip)]:
        vmin, vmax = alpha, 1 - alpha
        output = np.zeros_like(data)
        t0 = time.perf_counter()
        for _ in range(niters):
            res = func(data, vmin, vmax, out=output)
        t1 = time.perf_counter()
        print(name, data.dtype, alpha, t1 - t0)
1.24.4
np float32 0.1 0.3700788999994984
pg float32 0.1 0.204399000009289
np float32 0.25 0.36337140000250656
pg float32 0.25 0.20933669999067206

1.25.0
np float32 0.1 0.2218218999914825
pg float32 0.1 0.19125470001017675
np float32 0.25 0.21257340000011027
pg float32 0.25 0.19529110001167282

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Dec 9, 2023

I'm surprised more changes weren't needed for NumPy 2.0, guess goes to show you how mature their API is. Thanks for the PR @pijyoi

@j9ac9k j9ac9k merged commit 133b7d5 into pyqtgraph:master Dec 9, 2023
@pijyoi pijyoi deleted the numpy20-compat branch December 9, 2023 06:39
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