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

Function arraydescr_reduce

numpy/core/src/multiarray/descriptor.c:2603–2716  ·  view source on GitHub ↗

* return a tuple of (callable object, args, state). * * TODO: This method needs to change so that unpickling doesn't * use __setstate__. This is required for the dtype * to be an immutable object. */

Source from the content-addressed store, hash-verified

2601 * to be an immutable object.
2602 */
2603static PyObject *
2604arraydescr_reduce(PyArray_Descr *self, PyObject *NPY_UNUSED(args))
2605{
2606 /*
2607 * version number of this pickle type. Increment if we need to
2608 * change the format. Be sure to handle the old versions in
2609 * arraydescr_setstate.
2610 */
2611 const int version = 4;
2612 PyObject *ret, *mod, *obj;
2613 PyObject *state;
2614 char endian;
2615 int elsize, alignment;
2616
2617 ret = PyTuple_New(3);
2618 if (ret == NULL) {
2619 return NULL;
2620 }
2621 mod = PyImport_ImportModule("numpy.core._multiarray_umath");
2622 if (mod == NULL) {
2623 Py_DECREF(ret);
2624 return NULL;
2625 }
2626 obj = PyObject_GetAttrString(mod, "dtype");
2627 Py_DECREF(mod);
2628 if (obj == NULL) {
2629 Py_DECREF(ret);
2630 return NULL;
2631 }
2632 PyTuple_SET_ITEM(ret, 0, obj);
2633 if (PyTypeNum_ISUSERDEF(self->type_num)
2634 || ((self->type_num == NPY_VOID
2635 && self->typeobj != &PyVoidArrType_Type))) {
2636 obj = (PyObject *)self->typeobj;
2637 Py_INCREF(obj);
2638 }
2639 else {
2640 elsize = self->elsize;
2641 if (self->type_num == NPY_UNICODE) {
2642 elsize >>= 2;
2643 }
2644 obj = PyUnicode_FromFormat("%c%d",self->kind, elsize);
2645 }
2646 PyTuple_SET_ITEM(ret, 1, Py_BuildValue("(NOO)", obj, Py_False, Py_True));
2647
2648 /*
2649 * Now return the state which is at least byteorder,
2650 * subarray, and fields
2651 */
2652 endian = self->byteorder;
2653 if (endian == '=') {
2654 endian = '<';
2655 if (!PyArray_IsNativeByteOrder(endian)) {
2656 endian = '>';
2657 }
2658 }
2659 if (PyDataType_ISDATETIME(self)) {
2660 PyObject *newobj;

Callers

nothing calls this directly

Tested by

no test coverage detected