-
-
Notifications
You must be signed in to change notification settings - Fork 11k
[Windows Python 3.5 only] np.clip replace nans with lower bound #7601
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
Comments
Sorry, I can't test at the moment (no access to a Windows machine or VM) but would you mind testing with the current numpy wheel on pypi? I imagine it has the same error, because it's built with the same compiler, but it would be good to be sure. Do you get the same error for 32- and 64-bit? |
This is 64 bit, I haven't tested with 32-bit. I get the same behaviour with the numpy wheel from PyPI. |
I started looking at it a bit further and I see a very surprising behaviour. It seems like adding a I see this behaviour on my laptop and I reproduced it on AppVeyor:
|
I don't know this stuff well, but I would guess that the printf statement kills the compilers optimization to vectorized/SIMD instructions, which in turn changes the floating point error status setting stuff. If you compile with |
Loic - this is rather a serious bug - would you consider writing a failing
test case for it to put into the numpy test suite?
|
There is one in my branch: lesteve@2c257cf The AppVeyor failure can be seen here. Or did you mean something else? |
I managed to reproduce the problem in a stand-alone C program. #include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define SIZE 2
void clip(double* in, int size, double min, double max, double* out){
for (int i=0; i < size; i++){
if (in[i] < min){
out[i] = min;
}
else if (in[i] > max) {
out[i] = max;
}
else {
out[i] = in[i];
}
}
}
int main() {
double* in = malloc(sizeof(double) * SIZE);
double* out = malloc(sizeof(double) * SIZE);
double min = -1.;
double max = 1.;
in[0] = NAN;
in[1] = 10;
clip(in, SIZE, min, max, out);
for (int i=0; i < SIZE; i++){
printf("i: %d, value: %f\n", i, out[i]);
}
} As @seberg it has something to do with optimizations. Compiling it with
Compiling it with
Does anyone have any advice on where to report this bug? |
Does `/Ox` imply the equivalent of gcc `-ffast-math`? If yes, this is
not necessarily compiler bug --- rather, it means Numpy should not use
the `/Ox` flag but some more conservative optimization setting.
|
I just opened a ticket at connect.microsoft.com here. |
@eric-wieser does that stand alone program fail in your setup? |
It seems Microsoft Connect has been retired ... I could not find anything from googling and I could not find any archive online. From what I remember there was not much content in the Microsoft Connect ticket besides an acknowledgement that there was a bug and that the bug will be fixed in a further version of Visual Studio (I asked but the answer was not clear as to which version it was going to be exactly). |
Expected output is that nan are left untouched:
Actual output with Python 3.5 on a Windows VM (numpy 1.11 installed through conda):
It works as expected with Python 2.7 and 3.4 on the Windows VM. It works as expected with all Python versions on my Ubuntu box.
The text was updated successfully, but these errors were encountered: