Skip to content

Commit

Permalink
TEST: add test for non-contiguous input to ufuncs
Browse files Browse the repository at this point in the history
  • Loading branch information
mattip authored and r-devulap committed May 16, 2019
1 parent 5bf9ab9 commit 56201bb
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions numpy/core/tests/test_ufunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1964,3 +1964,28 @@ def test_ufunc_types(ufunc):
assert r.dtype == np.dtype(t)
else:
assert res.dtype == np.dtype(out)

@pytest.mark.parametrize('ufunc', [getattr(np, x) for x in dir(np)
if isinstance(getattr(np, x), np.ufunc)])
def test_ufunc_noncontiguous(ufunc):
'''
Check that contiguous and non-contiguous calls to ufuncs
have the same results for values in range(9)
'''
for typ in ufunc.types:
# types is a list of strings like ii->i
if any(set('O?mM') & set(typ)):
# bool, object, datetime are too irregular for this simple test
continue
inp, out = typ.split('->')
args_c = [np.empty(6, t) for t in inp]
args_n = [np.empty(18, t)[::3] for t in inp]
for a in args_c:
a.flat = range(6)
for a in args_n:
a.flat = range(6)
with warnings.catch_warnings(record=True):
warnings.filterwarnings("always")
res_c = ufunc(*args_c)
res_n = ufunc(*args_n)
assert_equal(res_c, res_n)

0 comments on commit 56201bb

Please sign in to comment.