MCPcopy Create free account
hub / github.com/numpy/numpy / unpack_bits

Function unpack_bits

numpy/core/src/multiarray/compiled_base.c:1753–1973  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1751}
1752
1753static PyObject *
1754unpack_bits(PyObject *input, int axis, PyObject *count_obj, char order)
1755{
1756 static int unpack_init = 0;
1757 /*
1758 * lookuptable for bitorder big as it has been around longer
1759 * bitorder little is handled via byteswapping in the loop
1760 */
1761 static union {
1762 npy_uint8 bytes[8];
1763 npy_uint64 uint64;
1764 } unpack_lookup_big[256];
1765 PyArrayObject *inp;
1766 PyArrayObject *new = NULL;
1767 PyArrayObject *out = NULL;
1768 npy_intp outdims[NPY_MAXDIMS];
1769 int i;
1770 PyArrayIterObject *it, *ot;
1771 npy_intp count, in_n, in_tail, out_pad, in_stride, out_stride;
1772 NPY_BEGIN_THREADS_DEF;
1773
1774 inp = (PyArrayObject *)PyArray_FROM_O(input);
1775
1776 if (inp == NULL) {
1777 return NULL;
1778 }
1779 if (PyArray_TYPE(inp) != NPY_UBYTE) {
1780 PyErr_SetString(PyExc_TypeError,
1781 "Expected an input array of unsigned byte data type");
1782 Py_DECREF(inp);
1783 goto fail;
1784 }
1785
1786 new = (PyArrayObject *)PyArray_CheckAxis(inp, &axis, 0);
1787 Py_DECREF(inp);
1788 if (new == NULL) {
1789 return NULL;
1790 }
1791
1792 if (PyArray_NDIM(new) == 0) {
1793 /* Handle 0-d array by converting it to a 1-d array */
1794 PyArrayObject *temp;
1795 PyArray_Dims newdim = {NULL, 1};
1796 npy_intp shape = 1;
1797
1798 newdim.ptr = &shape;
1799 temp = (PyArrayObject *)PyArray_Newshape(new, &newdim, NPY_CORDER);
1800 Py_DECREF(new);
1801 if (temp == NULL) {
1802 return NULL;
1803 }
1804 new = temp;
1805 }
1806
1807 /* Setup output shape */
1808 for (i = 0; i < PyArray_NDIM(new); i++) {
1809 outdims[i] = PyArray_DIM(new, i);
1810 }

Callers 1

io_unpackFunction · 0.85

Calls 11

PyArray_TYPEFunction · 0.85
PyArray_CheckAxisFunction · 0.85
PyArray_NDIMFunction · 0.85
PyArray_NewshapeFunction · 0.85
PyArray_DIMFunction · 0.85
PyArray_PyIntAsIntpFunction · 0.85
PyArray_NewFromDescrFunction · 0.85
PyArray_IterAllButAxisFunction · 0.85
PyArray_STRIDEFunction · 0.85
PyArray_SizeFunction · 0.85
npy_bswap8Function · 0.85

Tested by

no test coverage detected