summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2014-01-08 19:49:19 -0800
committerCharles Harris <charlesr.harris@gmail.com>2014-01-08 19:49:19 -0800
commit4d94317be03617f8cc6a038e42ea07cfd13123ec (patch)
treebe6c33292ebfcae9517e37d77d57c12a439e0a41
parentf3ee0735c1c372dfb9e0efcaa6846bd05e53b836 (diff)
parente52c08c7bbe6e9009520fbbe4fb33c6022e93389 (diff)
downloadnumpy-maintenance/1.7.x.tar.gz
Merge pull request #4179 from juliantaylor/backport-4170-1.7maintenance/1.7.x
Backport #4170 to 1.7
-rw-r--r--doc/source/reference/c-api.config.rst4
-rw-r--r--numpy/core/src/multiarray/buffer.c11
-rw-r--r--numpy/core/tests/test_multiarray.py16
3 files changed, 18 insertions, 13 deletions
diff --git a/doc/source/reference/c-api.config.rst b/doc/source/reference/c-api.config.rst
index 0989c53d7..9978434fc 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 530edbb1a..35156e72a 100644
--- a/numpy/core/src/multiarray/buffer.c
+++ b/numpy/core/src/multiarray/buffer.c
@@ -299,11 +299,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;
@@ -339,6 +339,7 @@ _buffer_format_string(PyArray_Descr *descr, _tmp_string_t *str,
"cannot expose native-only dtype '%c' in "
"non-native byte order '%c' via buffer interface",
descr->type, descr->byteorder);
+ return -1;
}
}
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index 6697b8131..5fb53fbb1 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -2650,17 +2650,21 @@ if sys.version_info >= (2, 6):
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):
@@ -2746,9 +2750,9 @@ if sys.version_info >= (2, 6):
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:}')
assert_equal(y.strides, (sz,))
assert_equal(y.itemsize, sz)