Skip to content

Commit

Permalink
Merge pull request #4179 from juliantaylor/backport-4170-1.7
Browse files Browse the repository at this point in the history
Backport #4170 to 1.7
  • Loading branch information
charris committed Jan 9, 2014
2 parents f3ee073 + e52c08c commit 4d94317
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
4 changes: 2 additions & 2 deletions doc/source/reference/c-api.config.rst
Expand Up @@ -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

Expand Down
11 changes: 6 additions & 5 deletions numpy/core/src/multiarray/buffer.c
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
}

Expand Down
16 changes: 10 additions & 6 deletions numpy/core/tests/test_multiarray.py
Expand Up @@ -2650,17 +2650,21 @@ def test_roundtrip(self):
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):
Expand Down Expand Up @@ -2746,9 +2750,9 @@ def test_export_record(self):

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)

Expand Down

0 comments on commit 4d94317

Please sign in to comment.