8000 Merge pull request #7678 from lesteve/fix-python35-windows-clip-with-… · numpy/numpy@a075c36 · GitHub
[go: up one dir, main page]

8000
Skip to content

Commit a075c36

Browse files
committed
Merge pull request #7678 from lesteve/fix-python35-windows-clip-with-nan-bug
BUG: Fix np.clip bug NaN handling for Visual Studio 2015
2 parents eb1cb8b + 4df1d32 commit a075c36

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

numpy/core/src/multiarray/arraytypes.c.src

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3763,6 +3763,12 @@ static void
37633763
}
37643764
}
37653765
else {
3766+
// Visual Studio 2015 loop vectorizer handles NaN in an unexpected manner, see:
3767+
// https://github.com/numpy/numpy/issues/7601
3768+
// https://connect.microsoft.com/VisualStudio/feedback/details/2723801/unexpected-nan-handling-in-vectorized-loop
3769+
#if (_MSC_VER == 1900)
3770+
#pragma loop( no_vector )
3771+
#endif
37663772
for (i = 0; i < ni; i++) {
37673773
if (@lt@(in[i], min_val)) {
37683774
out[i] = min_val;

numpy/core/tests/test_multiarray.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3452,6 +3452,12 @@ def test_max_or_min(self):
34523452
x = val.clip(max=4)
34533453
assert_(np.all(x <= 4))
34543454

3455+
def test_nan(self):
3456+
input_arr = np.array([-2., np.nan, 0.5, 3., 0.25, np.nan])
3457+
result = input_arr.clip(-1, 1)
3458+
expected = np.array([-1., np.nan, 0.5, 1., 0.25, np.nan])
3459+
assert_array_equal(result, expected)
3460+
34553461

34563462
class TestCompress(TestCase):
34573463
def test_axis(self):

0 commit comments

Comments
 (0)
0