-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
abs() on structured array gives invalid values in numpy 1.19.0 #16660
Comments
This looks like a vectorization bug to me, possibly introduced in #13885. @r-devulap, thoughts? We've had bugs like this appear elsewhere, and the cause is usually that the vectorized code assumes the data is contiguous. You'd see the same effect comparing |
This was introduced in #15408. The vectorized code assumes that strides is a multiple of the element size, which breaks in this case of mixed data types. I will have a fix for it soon. |
Hmm, in general we use the uint-alignment here, but I guess that only really matters for complex. I am not sure it only breaks for mixed datatypes? I would think it breaks for complex specifically, because its alignment is considered to be the alignment of the underlying float type? (not quite sure though). |
@r-devulap, presumably this applies to all vectorized loops? |
@seberg I am pretty sure it does affect other datatypes too. Just surprised it was never reported. |
@eric-wieser I think so. |
@r-devulap the ufunc machinery should normally ensure aligned data by using buffering IIRC. Most loops are not written in a way that handle unaligned data in general. |
The SIMD code assumes that the spacing between strided elements is a multiple of the element data size, which doesn't seem to be the case in the above example where the float64 elements are spaced 9 bytes apart. |
Also, it doesn't look like the float64 elements are 8 byte aligned in the above example. |
@r-devulap yes, but within the ufunc machinery, they will be. Try
is True in both cases, because |
matmul uses a |
@seberg ok, that makes this little less scary of a bug :) While I work on fixing this for complex types, could you point me to the source code for the ufunc machinery? Lack of that knowledge has bitten me more than once now. |
@r-devulap Its a bit hidden. Here is the fast path: numpy/numpy/core/src/umath/ufunc_object.c Lines 1581 to 1584 in a5d021a
But, typically this goes through the iterator here (EDIT: Ops, that link is too far down, somewhere AdvancedNew is created though): numpy/numpy/core/src/umath/ufunc_object.c Line 1478 in a5d021a
Which guarantees buffering for unaligned inputs, e.g. here: numpy/numpy/core/src/multiarray/nditer_constr.c Line 2867 in a5d021a
(this is exposed as |
I suppose it might be reasonable to add an assert for SIMD code though. Since it is conceivable to relax that requirement if flagged to the iterator. On most typical hardware, unaligned reads are not big issue and probably much faster than buffering, AFAIK. |
the issue reported in numpy/numpy#16660 was fixed in numpy/numpy#16666 and released as part of numpy 1.19.1, so pycbc should now be able to use those newer versions, and just avoid 1.19.0
the issue reported in numpy/numpy#16660 was fixed in numpy/numpy#16666 and released as part of numpy 1.19.1, so pycbc should now be able to use those newer versions, and just avoid 1.19.0
the issue reported in numpy/numpy#16660 was fixed in numpy/numpy#16666 and released as part of numpy 1.19.1, so pycbc should now be able to use those newer versions, and just avoid 1.19.0
the issue reported in numpy/numpy#16660 was fixed in numpy/numpy#16666 and released as part of numpy 1.19.1, so pycbc should now be able to use those newer versions, and just avoid 1.19.0
Since the numpy 1.19.0 release, calculating ABS on a complex field of a structured dtype gives incorrect results.
The exact output looks as if there is an indexing problem.
I am able to reliably reproduce following bug on Travis-CI (but not other machines, such as my personal laptop and local compute cluster). It is unclear if this is hardware or environment specific in some way. I've created as simple an example
as I could. One possible hint is that it seems that Travis has AVX512 in its environment, whereas my test machines do not.
Reproducing code example:
Error message:
Output of the above test script when BROKEN (i.e. numpy 1.19.0)
Output the above test script when WORKING (i.e. numpy 1.18.5)
The 'broken' values looks suspiciously like an indexing error, as the second value output is what abs would be if using the wrong fields, and so on.
Numpy/Python version information:
Broken -> numpy == 1.19.0
Last Working -> numpy == 1.18.5
see https://travis-ci.org/github/ahnitz/test-numpy/builds/700834047
The text was updated successfully, but these errors were encountered: