Skip to content

Commit

Permalink
Fix test failing due to Numpy 2.0 promotion rules
Browse files Browse the repository at this point in the history
From Numpy 2.0 adding a numpy.float32 and a Python numeric type returns
a numy.float32 when it previously returned a numpy.float64. This changes
the behavior when using the Python builtin sum function on a
numpy.float32 array as the internal computations now will be performed
as numpy.float32 additions when it used to be numpy.float64.

Changing these lines to calling .sum() on the arrays behaves the same
way as before (doing the internal calculations as float64 and
downcasting the result to a float32).
  • Loading branch information
sveinung-r committed Jul 30, 2024
1 parent eafe847 commit 2fd32b2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions python/test/segyio_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,10 +540,10 @@ def read_line(f, metrics, iline_idx, xline_idx):
buf = numpy.zeros((len(iline_idx), samples), dtype=numpy.single)

f.getline(xline_trace0, len(iline_idx), xline_stride, offsets, buf)
assert sum(sum(buf)) == approx(800.061169624, abs=1e-6)
assert buf.sum() == approx(800.061169624, abs=1e-6)

f.getline(iline_trace0, len(xline_idx), iline_stride, offsets, buf)
assert sum(sum(buf)) == approx(305.061146736, abs=1e-6)
assert buf.sum() == approx(305.061146736, abs=1e-6)

f.close()

Expand Down

0 comments on commit 2fd32b2

Please sign in to comment.