| 1646 | } |
| 1647 | |
| 1648 | static PyObject * |
| 1649 | pack_bits(PyObject *input, int axis, char order) |
| 1650 | { |
| 1651 | PyArrayObject *inp; |
| 1652 | PyArrayObject *new = NULL; |
| 1653 | PyArrayObject *out = NULL; |
| 1654 | npy_intp outdims[NPY_MAXDIMS]; |
| 1655 | int i; |
| 1656 | PyArrayIterObject *it, *ot; |
| 1657 | NPY_BEGIN_THREADS_DEF; |
| 1658 | |
| 1659 | inp = (PyArrayObject *)PyArray_FROM_O(input); |
| 1660 | |
| 1661 | if (inp == NULL) { |
| 1662 | return NULL; |
| 1663 | } |
| 1664 | if (!PyArray_ISBOOL(inp) && !PyArray_ISINTEGER(inp)) { |
| 1665 | PyErr_SetString(PyExc_TypeError, |
| 1666 | "Expected an input array of integer or boolean data type"); |
| 1667 | Py_DECREF(inp); |
| 1668 | goto fail; |
| 1669 | } |
| 1670 | |
| 1671 | new = (PyArrayObject *)PyArray_CheckAxis(inp, &axis, 0); |
| 1672 | Py_DECREF(inp); |
| 1673 | if (new == NULL) { |
| 1674 | return NULL; |
| 1675 | } |
| 1676 | |
| 1677 | if (PyArray_NDIM(new) == 0) { |
| 1678 | char *optr, *iptr; |
| 1679 | |
| 1680 | out = (PyArrayObject *)PyArray_NewFromDescr( |
| 1681 | Py_TYPE(new), PyArray_DescrFromType(NPY_UBYTE), |
| 1682 | 0, NULL, NULL, NULL, |
| 1683 | 0, NULL); |
| 1684 | if (out == NULL) { |
| 1685 | goto fail; |
| 1686 | } |
| 1687 | optr = PyArray_DATA(out); |
| 1688 | iptr = PyArray_DATA(new); |
| 1689 | *optr = 0; |
| 1690 | for (i = 0; i < PyArray_ITEMSIZE(new); i++) { |
| 1691 | if (*iptr != 0) { |
| 1692 | *optr = 1; |
| 1693 | break; |
| 1694 | } |
| 1695 | iptr++; |
| 1696 | } |
| 1697 | goto finish; |
| 1698 | } |
| 1699 | |
| 1700 | |
| 1701 | /* Setup output shape */ |
| 1702 | for (i = 0; i < PyArray_NDIM(new); i++) { |
| 1703 | outdims[i] = PyArray_DIM(new, i); |
| 1704 | } |
| 1705 |
no test coverage detected