summaryrefslogtreecommitdiff
path: root/numpy/lib/tests/test_utils.py
diff options
context:
space:
mode:
authorTyler Reddy <tyler.je.reddy@gmail.com>2018-10-15 13:40:03 -0700
committerTyler Reddy <tyler.je.reddy@gmail.com>2018-10-15 13:40:03 -0700
commit946781fbf04b9781f263da894cc2dfc9465e65ce (patch)
treed43d0fe8e2a2b3df0953673b672969d0b7c88fd0 /numpy/lib/tests/test_utils.py
parent86ebcffb482afb67c2f6ec4f396d9017ea610bf1 (diff)
downloadnumpy-946781fbf04b9781f263da894cc2dfc9465e65ce.tar.gz
TST: test byte_bounds contiguity handling
* add unit tests to probe previously-uncovered code paths in byte_bounds() that handle both positive and negative strides in non-contiguous arrays (or, at least, arrays with unusual ordering)
Diffstat (limited to 'numpy/lib/tests/test_utils.py')
-rw-r--r--numpy/lib/tests/test_utils.py32
1 files changed, 28 insertions, 4 deletions
diff --git a/numpy/lib/tests/test_utils.py b/numpy/lib/tests/test_utils.py
index c27c3cbf5..2723f3440 100644
--- a/numpy/lib/tests/test_utils.py
+++ b/numpy/lib/tests/test_utils.py
@@ -56,10 +56,34 @@ def test_safe_eval_nameconstant():
utils.safe_eval('None')
-def test_byte_bounds():
- a = arange(12).reshape(3, 4)
- low, high = utils.byte_bounds(a)
- assert_equal(high - low, a.size * a.itemsize)
+class TestByteBounds(object):
+
+ def test_byte_bounds(self):
+ # pointer difference matches size * itemsize
+ # due to contiguity
+ a = arange(12).reshape(3, 4)
+ low, high = utils.byte_bounds(a)
+ assert_equal(high - low, a.size * a.itemsize)
+
+ def test_unusual_order_positive_stride(self):
+ a = arange(12).reshape(3, 4)
+ b = a.T
+ low, high = utils.byte_bounds(b)
+ assert_equal(high - low, b.size * b.itemsize)
+
+ def test_unusual_order_negative_stride(self):
+ a = arange(12).reshape(3, 4)
+ b = a.T[::-1]
+ low, high = utils.byte_bounds(b)
+ assert_equal(high - low, b.size * b.itemsize)
+
+ def test_strided(self):
+ a = arange(12)
+ b = a[::2]
+ low, high = utils.byte_bounds(b)
+ # the largest pointer address is lost (even numbers only in the
+ # stride), and compensate addresses for striding by 2
+ assert_equal(high - low, b.size * 2 * b.itemsize - b.itemsize)
def test_assert_raises_regex_context_manager():