Commit 46cc2008 authored by Stefan Behnel's avatar Stefan Behnel Committed by GitHub

Merge pull request #2676 from telamonian/fix_npy_bool_cast_false

Fix support for functions with ndarray parameters of type npy_bool
parents 7ebbc39f 43de4852
......@@ -36,3 +36,8 @@ TAGS
MANIFEST
.tox
# Jetbrains IDE project files
/.idea
/*.iml
......@@ -298,6 +298,7 @@ static void __Pyx_BufFmt_RaiseUnexpectedChar(char ch) {
static const char* __Pyx_BufFmt_DescribeTypeChar(char ch, int is_complex) {
switch (ch) {
case '?': return "'bool'";
case 'c': return "'char'";
case 'b': return "'signed char'";
case 'B': return "'unsigned char'";
......@@ -342,7 +343,7 @@ static size_t __Pyx_BufFmt_TypeCharToStandardSize(char ch, int is_complex) {
static size_t __Pyx_BufFmt_TypeCharToNativeSize(char ch, int is_complex) {
switch (ch) {
case 'c': case 'b': case 'B': case 's': case 'p': return 1;
case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1;
case 'h': case 'H': return sizeof(short);
case 'i': case 'I': return sizeof(int);
case 'l': case 'L': return sizeof(long);
......@@ -431,7 +432,7 @@ static char __Pyx_BufFmt_TypeCharToGroup(char ch, int is_complex) {
case 'b': case 'h': case 'i':
case 'l': case 'q': case 's': case 'p':
return 'I';
case 'B': case 'H': case 'I': case 'L': case 'Q':
case '?': case 'B': case 'H': case 'I': case 'L': case 'Q':
return 'U';
case 'f': case 'd': case 'g':
return (is_complex ? 'C' : 'R');
......@@ -752,7 +753,7 @@ static const char* __Pyx_BufFmt_CheckString(__Pyx_BufFmt_Context* ctx, const cha
return NULL;
}
CYTHON_FALLTHROUGH;
case 'c': case 'b': case 'B': case 'h': case 'H': case 'i': case 'I':
case '?': case 'c': case 'b': case 'B': case 'h': case 'H': case 'i': case 'I':
case 'l': case 'L': case 'q': case 'Q':
case 'f': case 'd': case 'g':
case 'O': case 'p':
......
......@@ -133,6 +133,7 @@ try:
...
ValueError: ndarray is not C...contiguous
>>> test_dtype('?', inc1_bool)
>>> test_dtype('b', inc1_byte)
>>> test_dtype('B', inc1_ubyte)
>>> test_dtype('h', inc1_short)
......@@ -339,6 +340,7 @@ def test_f_contig(np.ndarray[int, ndim=2, mode='fortran'] arr):
print u" ".join([unicode(arr[i, j]) for j in range(arr.shape[1])])
# Exhaustive dtype tests -- increments element [1] by 1 (or 1+1j) for all dtypes
def inc1_bool(np.ndarray[unsigned char] arr): arr[1] += 1
def inc1_byte(np.ndarray[char] arr): arr[1] += 1
def inc1_ubyte(np.ndarray[unsigned char] arr): arr[1] += 1
def inc1_short(np.ndarray[short] arr): arr[1] += 1
......@@ -401,6 +403,13 @@ def test_dtype(dtype, inc1):
a = np.array([0, 10+10j], dtype=dtype)
inc1(a)
if a[1] != (11 + 11j): print u"failed!", a[1]
elif dtype == '?':
# bool ndarrays coerce all values to 0 or 1
a = np.array([0, 0], dtype=dtype)
inc1(a)
if a[1] != 1: print u"failed!"
inc1(a)
if a[1] != 1: print u"failed!"
else:
a = np.array([0, 10], dtype=dtype)
inc1(a)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment