8000 Merge pull request #4872 from juliantaylor/backports-1.9 · numpy/numpy@029662b · GitHub
[go: up one dir, main page]

Skip to content

Commit 029662b

Browse files
committed
Merge pull request #4872 from juliantaylor/backports-1.9
Backports stuff from master to 1.9
2 parents b6903d7 + 2a87c3e commit 029662b

File tree

6 files changed

+54
-7
lines changed

6 files changed

+54
-7
lines changed

doc/source/reference/routines.polynomials.classes.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ constant are 0, but both can be specified.::
211211
In the first case the lower bound of the integration is set to -1 and the
212212
integration constant is 0. In the second the constant of integration is set
213213
to 1 as well. Differentiation is simpler since the only option is the
214-
number times the polynomial is differentiated::
214+
number of times the polynomial is differentiated::
215215

216216
>>> p = P([1, 2, 3])
217217
>>> p.deriv(1)
@@ -270,7 +270,7 @@ polynomials up to degree 5 are plotted below.
270270
>>> import matplotlib.pyplot as plt
271271
>>> from numpy.polynomial import Chebyshev as T
272272
>>> x = np.linspace(-1, 1, 100)
273-
>>> for i in range(6): ax = plt.plot(x, T.basis(i)(x), lw=2, label="T_%d"%i)
273+
>>> for i in range(6): ax = plt.plot(x, T.basis(i)(x), lw=2, label="$T_%d$"%i)
274274
...
275275
>>> plt.legend(loc="upper left")
276276
<matplotlib.legend.Legend object at 0x3b3ee10>
@@ -284,7 +284,7 @@ The same plots over the range -2 <= `x` <= 2 look very different:
284284
>>> import matplotlib.pyplot as plt
285285
>>> from numpy.polynomial import Chebyshev as T
286286
>>> x = np.linspace(-2, 2, 100)
287-
>>> for i in range(6): ax = plt.plot(x, T.basis(i)(x), lw=2, label="T_%d"%i)
287+
>>> for i in range(6): ax = plt.plot(x, T.basis(i)(x), lw=2, label="$T_%d$"%i)
288288
...
289289
>>> plt.legend(loc="lower right")
290290
<matplotlib.legend.Legend object at 0x3b3ee10>

numpy/core/src/umath/simd.inc.src

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
((abs(args[1] - args[0]) >= (vsize)) || ((abs(args[1] - args[0]) == 0))))
3838

3939
#define IS_BLOCKABLE_REDUCE(esize, vsize) \
40-
(steps[1] == (esize) && abs(args[1] - args[0]) >= (vsize))
40+
(steps[1] == (esize) && abs(args[1] - args[0]) >= (vsize) && \
41+
npy_is_aligned(args[1], (esize)) && \
42+
npy_is_aligned(args[0], (esize)))
4143

4244
#define IS_BLOCKABLE_BINARY(esize, vsize) \
4345
(steps[0] == steps[1] && steps[1] == steps[2] && steps[2] == (esize) && \

numpy/core/tests/test_scalarmath.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ def test_blocked(self):
8383
np.add(1, inp2, out=out)
8484
assert_almost_equal(out, exp1, err_msg=msg)
8585

86+
def test_lower_align(self):
87+
# check data that is not aligned to element size
88+
# i.e doubles are aligned to 4 bytes on i386
89+
d = np.zeros(23 * 8, dtype=np.int8)[4:-4].view(np.float64)
90+
o = np.zeros(23 * 8, dtype=np.int8)[4:-4].view(np.float64)
91+
assert_almost_equal(d + d, d * 2)
92+
np.add(d, d, out=o)
93+
np.add(np.ones_like(d), d, out=o)
94+
np.add(d, np.ones_like(d), out=o)
95+
np.add(np.ones_like(d), d)
96+
np.add(d, np.ones_like(d))
97+
8698

8799
class TestPower(TestCase):
88100
def test_small_types(self):

numpy/core/tests/test_umath.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,13 @@ def test_minmax_blocked(self):
753753
inp[i] = -1e10
754754
assert_equal(inp.min(), -1e10, err_msg=msg)
755755

756+
def test_lower_align(self):
757+
# check data that is not aligned to element size
758+
# i.e doubles are aligned to 4 bytes on i386
759+
d = np.zeros(23 * 8, dtype=np.int8)[4:-4].view(np.float64)
760+
assert_equal(d.max(), d[0])
761+
assert_equal(d.min(), d[0])
762+
756763

757764
class TestAbsoluteNegative(TestCase):
758765
def test_abs_neg_blocked(self):
@@ -785,6 +792,17 @@ def test_abs_neg_blocked(self):
785792
np.negative(inp, out=out)
786793
assert_array_equal(out, -1*inp, err_msg=msg)
787794

795+
def test_lower_align(self):
796+
# check data that is not aligned to element size
797+
# i.e doubles are aligned to 4 bytes on i386
798+
d = np.zeros(23 * 8, dtype=np.int8)[4:-4].view(np.float64)
799+
assert_equal(np.abs(d), d)
800+
assert_equal(np.negative(d), -d)
801+
np.negative(d, out=d)
802+
np.negative(np.ones_like(d), out=d)
803+
np.abs(d, out=d)
804+
np.abs(np.ones_like(d), out=d)
805+
788806

789807
class TestSpecialMethods(TestCase):
790808
def test_wrap(self):

numpy/lib/tests/test_twodim_base.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,18 @@ def test_tril_triu_ndim3():
311311
yield assert_equal, a_triu_observed.dtype, a.dtype
312312
yield assert_equal, a_tril_observed.dtype, a.dtype
313313

314+
def test_tril_triu_with_inf():
315+
# Issue 4859
316+
arr = np.array([[1, 1, np.inf],
317+
[1, 1, 1],
318+
[np.inf, 1, 1]])
319+
out_tril = np.array([[1, 0, 0],
320+
[1, 1, 0],
321+
[np.inf, 1, 1]])
322+
out_triu = out_tril.T
323+
assert_array_equal(np.triu(arr), out_triu)
324+
assert_array_equal(np.tril(arr), out_tril)
325+
314326

315327
def test_mask_indices():
316328
# simple test without offset

numpy/lib/twodim_base.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,6 @@ def tri(N, M=None, k=0, dtype=float):
387387
dtype : dtype, optional
388388
Data type of the returned array. The default is float.
389389
390-
391390
Returns
392391
-------
393392
tri : ndarray of shape (N, M)
@@ -452,7 +451,9 @@ def tril(m, k=0):
452451
453452
"""
454453
m = asanyarray(m)
455-
return multiply(tri(*m.shape[-2:], k=k, dtype=bool), m, dtype=m.dtype)
454+
mask = tri(*m.shape[-2:], k=k, dtype=bool)
455+
456+
return where(mask, m, 0)
456457

457458

458459
def triu(m, k=0):
@@ -478,7 +479,9 @@ def triu(m, k=0):
478479
479480
"""
480481
m = asanyarray(m)
481-
return multiply(~tri(*m.shape[-2:], k=k-1, dtype=bool), m, dtype=m.dtype)
482+
mask = tri(*m.shape[-2:], k=k-1, dtype=bool)
483+
484+
return where(mask, 0, m)
482485

483486

484487
# Originally borrowed from John Hunter and matplotlib

0 commit comments

Comments
 (0)
0