summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Taylor <jtaylor.debian@googlemail.com>2014-01-04 01:13:03 +0100
committerJulian Taylor <jtaylor.debian@googlemail.com>2014-01-04 12:54:51 +0100
commit28eb575c0c73a2061942b72b80ff6c43a67a431a (patch)
treeb051cad101e377101e15f157ebec2a4bf48e99f5
parent57330377d914e163389d66cf644915f851f37242 (diff)
downloadnumpy-28eb575c0c73a2061942b72b80ff6c43a67a431a.tar.gz
BUG: fix native-only long long check
Caused all long longs to be required native only in memoryviews. NPY_SIZEOF_LONG_LONG never existed, replace documentation with existing NPY_SIZEOF_LONGLONG and code with a sizeof(npy_longlong).
-rw-r--r--doc/source/reference/c-api.config.rst4
-rw-r--r--numpy/core/src/multiarray/buffer.c10
-rw-r--r--numpy/core/tests/test_multiarray.py16
3 files changed, 17 insertions, 13 deletions
diff --git a/doc/source/reference/c-api.config.rst b/doc/source/reference/c-api.config.rst
index 0073b37a4..972a78596 100644
--- a/doc/source/reference/c-api.config.rst
+++ b/doc/source/reference/c-api.config.rst
@@ -34,10 +34,10 @@ information is available to the pre-processor.
sizeof(long)
-.. cvar:: NPY_SIZEOF_LONG_LONG
+.. cvar:: NPY_SIZEOF_LONGLONG
sizeof(longlong) where longlong is defined appropriately on the
- platform (A macro defines **NPY_SIZEOF_LONGLONG** as well.)
+ platform.
.. cvar:: NPY_SIZEOF_PY_LONG_LONG
diff --git a/numpy/core/src/multiarray/buffer.c b/numpy/core/src/multiarray/buffer.c
index b25613fd0..e32bc76eb 100644
--- a/numpy/core/src/multiarray/buffer.c
+++ b/numpy/core/src/multiarray/buffer.c
@@ -297,11 +297,11 @@ _buffer_format_string(PyArray_Descr *descr, _tmp_string_t *str,
int is_standard_size = 1;
int is_native_only_type = (descr->type_num == NPY_LONGDOUBLE ||
descr->type_num == NPY_CLONGDOUBLE);
-#if NPY_SIZEOF_LONG_LONG != 8
- is_native_only_type = is_native_only_type || (
- descr->type_num == NPY_LONGLONG ||
- descr->type_num == NPY_ULONGLONG);
-#endif
+ if (sizeof(npy_longlong) != 8) {
+ is_native_only_type = is_native_only_type || (
+ descr->type_num == NPY_LONGLONG ||
+ descr->type_num == NPY_ULONGLONG);
+ }
*offset += descr->elsize;
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index 68bdaf97a..fa698f1ac 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -3528,17 +3528,21 @@ class TestNewBufferProtocol(object):
x = np.array([1, 2, 3], dtype='<i4')
self._check_roundtrip(x)
+ # check long long can be represented as non-native
+ x = np.array([1, 2, 3], dtype='>q')
+ self._check_roundtrip(x)
+
# Native-only data types can be passed through the buffer interface
# only in native byte order
if sys.byteorder == 'little':
- x = np.array([1, 2, 3], dtype='>q')
+ x = np.array([1, 2, 3], dtype='>g')
assert_raises(ValueError, self._check_roundtrip, x)
- x = np.array([1, 2, 3], dtype='<q')
+ x = np.array([1, 2, 3], dtype='<g')
self._check_roundtrip(x)
else:
- x = np.array([1, 2, 3], dtype='>q')
+ x = np.array([1, 2, 3], dtype='>g')
self._check_roundtrip(x)
- x = np.array([1, 2, 3], dtype='<q')
+ x = np.array([1, 2, 3], dtype='<g')
assert_raises(ValueError, self._check_roundtrip, x)
def test_roundtrip_half(self):
@@ -3651,9 +3655,9 @@ class TestNewBufferProtocol(object):
sz = sum([dtype(b).itemsize for a, b in dt])
if dtype('l').itemsize == 4:
- assert_equal(y.format, 'T{b:a:=h:b:i:c:l:d:^q:dx:B:e:@H:f:=I:g:L:h:^Q:hx:=f:i:d:j:^g:k:=Zf:ix:Zd:jx:^Zg:kx:4s:l:=4w:m:3x:n:?:o:@e:p:}')
+ assert_equal(y.format, 'T{b:a:=h:b:i:c:l:d:q:dx:B:e:@H:f:=I:g:L:h:Q:hx:f:i:d:j:^g:k:=Zf:ix:Zd:jx:^Zg:kx:4s:l:=4w:m:3x:n:?:o:@e:p:}')
else:
- assert_equal(y.format, 'T{b:a:=h:b:i:c:q:d:^q:dx:B:e:@H:f:=I:g:Q:h:^Q:hx:=f:i:d:j:^g:k:=Zf:ix:Zd:jx:^Zg:kx:4s:l:=4w:m:3x:n:?:o:@e:p:}')
+ assert_equal(y.format, 'T{b:a:=h:b:i:c:q:d:q:dx:B:e:@H:f:=I:g:Q:h:Q:hx:f:i:d:j:^g:k:=Zf:ix:Zd:jx:^Zg:kx:4s:l:=4w:m:3x:n:?:o:@e:p:}')
# Cannot test if NPY_RELAXED_STRIDES_CHECKING changes the strides
if not (np.ones(1).strides[0] == np.iinfo(np.intp).max):
assert_equal(y.strides, (sz,))