| 1675 | |
| 1676 | |
| 1677 | static PyObject * |
| 1678 | array_deepcopy(PyArrayObject *self, PyObject *args) |
| 1679 | { |
| 1680 | PyArrayObject *copied_array; |
| 1681 | PyObject *visit; |
| 1682 | NpyIter *iter = NULL; |
| 1683 | NpyIter_IterNextFunc *iternext; |
| 1684 | char *data; |
| 1685 | char **dataptr; |
| 1686 | npy_intp *strideptr, *innersizeptr; |
| 1687 | npy_intp stride, count; |
| 1688 | PyObject *copy, *deepcopy; |
| 1689 | int deepcopy_res; |
| 1690 | |
| 1691 | if (!PyArg_ParseTuple(args, "O:__deepcopy__", &visit)) { |
| 1692 | return NULL; |
| 1693 | } |
| 1694 | copied_array = (PyArrayObject*) PyArray_NewCopy(self, NPY_KEEPORDER); |
| 1695 | if (copied_array == NULL) { |
| 1696 | return NULL; |
| 1697 | } |
| 1698 | |
| 1699 | if (!PyDataType_REFCHK(PyArray_DESCR(self))) { |
| 1700 | return (PyObject *)copied_array; |
| 1701 | } |
| 1702 | |
| 1703 | /* If the array contains objects, need to deepcopy them as well */ |
| 1704 | copy = PyImport_ImportModule("copy"); |
| 1705 | if (copy == NULL) { |
| 1706 | Py_DECREF(copied_array); |
| 1707 | return NULL; |
| 1708 | } |
| 1709 | deepcopy = PyObject_GetAttrString(copy, "deepcopy"); |
| 1710 | Py_DECREF(copy); |
| 1711 | if (deepcopy == NULL) { |
| 1712 | goto error; |
| 1713 | } |
| 1714 | iter = NpyIter_New(copied_array, |
| 1715 | NPY_ITER_READWRITE | |
| 1716 | NPY_ITER_EXTERNAL_LOOP | |
| 1717 | NPY_ITER_REFS_OK | |
| 1718 | NPY_ITER_ZEROSIZE_OK, |
| 1719 | NPY_KEEPORDER, NPY_NO_CASTING, |
| 1720 | NULL); |
| 1721 | if (iter == NULL) { |
| 1722 | goto error; |
| 1723 | } |
| 1724 | if (NpyIter_GetIterSize(iter) != 0) { |
| 1725 | iternext = NpyIter_GetIterNext(iter, NULL); |
| 1726 | if (iternext == NULL) { |
| 1727 | goto error; |
| 1728 | } |
| 1729 | |
| 1730 | dataptr = NpyIter_GetDataPtrArray(iter); |
| 1731 | strideptr = NpyIter_GetInnerStrideArray(iter); |
| 1732 | innersizeptr = NpyIter_GetInnerLoopSizePtr(iter); |
| 1733 | |
| 1734 | do { |
nothing calls this directly
no test coverage detected