summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2017-02-19 10:49:10 -0700
committerGitHub <noreply@github.com>2017-02-19 10:49:10 -0700
commit60ad1ec509ba719e21a69282e49b67de381465a7 (patch)
tree4f49660d05202276e141c540be2043637b3b8cc8
parentd5f2962f666f5b811673cfbd1a01912044085395 (diff)
parent05f3430ca595e316117d6808051750f4b8c7e233 (diff)
downloadnumpy-60ad1ec509ba719e21a69282e49b67de381465a7.tar.gz
Merge pull request #8638 from juliantaylor/packbits-fix
BUG: fix wrong odd determination in packbits
-rw-r--r--numpy/core/src/multiarray/compiled_base.c2
-rw-r--r--numpy/lib/tests/test_packbits.py9
2 files changed, 10 insertions, 1 deletions
diff --git a/numpy/core/src/multiarray/compiled_base.c b/numpy/core/src/multiarray/compiled_base.c
index 6c76dbd4b..7ff803f96 100644
--- a/numpy/core/src/multiarray/compiled_base.c
+++ b/numpy/core/src/multiarray/compiled_base.c
@@ -1509,7 +1509,7 @@ pack_inner(const char *inptr,
__m128i zero = _mm_setzero_si128();
/* don't handle non-full 8-byte remainder */
npy_intp vn_out = n_out - (remain ? 1 : 0);
- vn_out -= (vn_out & 2);
+ vn_out -= (vn_out & 1);
for (index = 0; index < vn_out; index += 2) {
unsigned int r;
/* swap as packbits is "big endian", note x86 can load unaligned */
diff --git a/numpy/lib/tests/test_packbits.py b/numpy/lib/tests/test_packbits.py
index 4bf505f56..965cbf67c 100644
--- a/numpy/lib/tests/test_packbits.py
+++ b/numpy/lib/tests/test_packbits.py
@@ -213,6 +213,15 @@ def test_packbits_large():
assert_raises(TypeError, np.packbits, np.array(a, dtype=float))
+def test_packbits_very_large():
+ # test some with a larger arrays gh-8637
+ # code is covered earlier but larger array makes crash on bug more likely
+ for s in range(950, 1050):
+ for dt in '?bBhHiIlLqQ':
+ x = np.ones((200, s), dtype=bool)
+ np.packbits(x, axis=1)
+
+
def test_unpackbits():
# Copied from the docstring.
a = np.array([[2], [7], [23]], dtype=np.uint8)