Skip to content

fix GLIsosurface overflow warning on numpy 2#3235

Merged
j9ac9k merged 2 commits intopyqtgraph:masterfrom
pijyoi:fix-numpy2-promotion
Feb 3, 2025
Merged

fix GLIsosurface overflow warning on numpy 2#3235
j9ac9k merged 2 commits intopyqtgraph:masterfrom
pijyoi:fix-numpy2-promotion

Conversation

@pijyoi
Copy link
Copy Markdown
Contributor

@pijyoi pijyoi commented Feb 2, 2025

pg.isosurface() relies on NumPy < 2.0 promotion behavior.
An overflow warning occurs on NumPy >= 2.0.
Fix by explicitly promoting to an int.

In [1]: import numpy as np
In [2]: val = np.arange(10, dtype=np.uint16)[0] - 1
In [3]: val, val.dtype
Out[3]: (-1, dtype('int32'))
In [4]: np.__version__
Out[4]: '1.26.4'
In [1]: import numpy as np
In [2]: val = np.arange(10, dtype=np.uint16)[0] - 1
<ipython-input-2-04d47eed1b3c>:1: RuntimeWarning: overflow encountered in scalar subtract
  val = np.arange(10, dtype=np.uint16)[0] - 1
In [3]: val, val.dtype
Out[3]: (np.uint16(65535), dtype('uint16'))
In [4]: np.__version__
Out[4]: '2.2.1'

shift[j] is of dtype uint16 and does have a value of 0 for certain
iterations. a subtraction of 1 can thus cause an overflow depending on
the numpy version.

in numpy < 2.0, shift[j] is automatically promoted to an int32 prior
to the subtraction and thus no overflow occurs.
(i.e. pyqtgraph was relying on this behavior)

in numpy >= 2.0, shift[j] remains as an uint16 and an overflow occurs.
GLMeshItem does not support correctly the combination of setFaceColors()
and smooth=True.
@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Feb 3, 2025

Thanks @pijyoi !

@j9ac9k j9ac9k merged commit eadadf6 into pyqtgraph:master Feb 3, 2025
29 checks passed
@pijyoi pijyoi deleted the fix-numpy2-promotion branch February 3, 2025 03:56
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