summaryrefslogtreecommitdiff
path: root/numpy/core
diff options
context:
space:
mode:
authorPauli Virtanen <pav@iki.fi>2017-02-04 20:12:34 +0100
committerPauli Virtanen <pav@iki.fi>2017-02-04 20:14:40 +0100
commit7886906af7cccdde892db7be8f8ae53fd5266d95 (patch)
treed939fce313cde139fa4f9ad720f8eb7a46270802 /numpy/core
parenta611932bbcb132f82472a1f222a31e120fb6dc86 (diff)
downloadnumpy-7886906af7cccdde892db7be8f8ae53fd5266d95.tar.gz
TST: core: use aligned memory for dot() out= arrays
On SPARC, longdouble alignment is bigger than that provided by default allocation. So use a custom allocation method in the test using dot(out=).
Diffstat (limited to 'numpy/core')
-rw-r--r--numpy/core/tests/test_multiarray.py33
1 files changed, 32 insertions, 1 deletions
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index 3bbe99b8f..8229f1e1a 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -8,6 +8,7 @@ import warnings
import operator
import io
import itertools
+import functools
import ctypes
import os
import gc
@@ -46,6 +47,32 @@ else:
EMPTY = None
+def _aligned_zeros(shape, dtype=float, order="C", align=None):
+ """Allocate a new ndarray with aligned memory."""
+ dtype = np.dtype(dtype)
+ if dtype == np.dtype(object):
+ # Can't do this, fall back to standard allocation (which
+ # should always be sufficiently aligned)
+ if align is not None:
+ raise ValueError("object array alignment not supported")
+ return np.zeros(shape, dtype=dtype, order=order)
+ if align is None:
+ align = dtype.alignment
+ if not hasattr(shape, '__len__'):
+ shape = (shape,)
+ size = functools.reduce(operator.mul, shape) * dtype.itemsize
+ buf = np.empty(size + align + 1, np.uint8)
+ offset = buf.__array_interface__['data'][0] % align
+ if offset != 0:
+ offset = align - offset
+ # Note: slices producing 0-size arrays do not necessarily change
+ # data pointer --- so we use and allocate size+1
+ buf = buf[offset:offset+size+1][:-1]
+ data = np.ndarray(shape, dtype, buf, order=order)
+ data.fill(0)
+ return data
+
+
class TestFlags(TestCase):
def setUp(self):
self.a = np.arange(10)
@@ -2335,7 +2362,11 @@ class TestMethods(TestCase):
if code not in 'USVM']
for dtype in dtypes:
a = np.random.rand(3, 3).astype(dtype)
- b = np.random.rand(3, 3).astype(dtype)
+
+ # Valid dot() output arrays must be aligned
+ b = _aligned_zeros((3, 3), dtype=dtype)
+ b[...] = np.random.rand(3, 3)
+
y = np.dot(a, b)
x = np.dot(a, b, out=b)
assert_equal(x, y, err_msg=repr(dtype))