* Python C-Api level item assignment (implementation for PySequence_SetItem) * * Negative indices are not accepted because PySequence_SetItem converts * them to positive indices before calling this. */
| 1719 | * them to positive indices before calling this. |
| 1720 | */ |
| 1721 | NPY_NO_EXPORT int |
| 1722 | array_assign_item(PyArrayObject *self, Py_ssize_t i, PyObject *op) |
| 1723 | { |
| 1724 | npy_index_info indices[2]; |
| 1725 | |
| 1726 | if (op == NULL) { |
| 1727 | PyErr_SetString(PyExc_ValueError, |
| 1728 | "cannot delete array elements"); |
| 1729 | return -1; |
| 1730 | } |
| 1731 | if (PyArray_FailUnlessWriteable(self, "assignment destination") < 0) { |
| 1732 | return -1; |
| 1733 | } |
| 1734 | if (PyArray_NDIM(self) == 0) { |
| 1735 | PyErr_SetString(PyExc_IndexError, |
| 1736 | "too many indices for array"); |
| 1737 | return -1; |
| 1738 | } |
| 1739 | |
| 1740 | if (i < 0) { |
| 1741 | /* This is an error, but undo PySequence_SetItem fix for message */ |
| 1742 | i -= PyArray_DIM(self, 0); |
| 1743 | } |
| 1744 | |
| 1745 | indices[0].value = i; |
| 1746 | indices[0].type = HAS_INTEGER; |
| 1747 | if (PyArray_NDIM(self) == 1) { |
| 1748 | char *item; |
| 1749 | if (get_item_pointer(self, &item, indices, 1) < 0) { |
| 1750 | return -1; |
| 1751 | } |
| 1752 | if (PyArray_Pack(PyArray_DESCR(self), item, op) < 0) { |
| 1753 | return -1; |
| 1754 | } |
| 1755 | } |
| 1756 | else { |
| 1757 | PyArrayObject *view; |
| 1758 | |
| 1759 | indices[1].value = PyArray_NDIM(self) - 1; |
| 1760 | indices[1].type = HAS_ELLIPSIS; |
| 1761 | if (get_view_from_index(self, &view, indices, 2, 0) < 0) { |
| 1762 | return -1; |
| 1763 | } |
| 1764 | if (PyArray_CopyObject(view, op) < 0) { |
| 1765 | Py_DECREF(view); |
| 1766 | return -1; |
| 1767 | } |
| 1768 | Py_DECREF(view); |
| 1769 | } |
| 1770 | return 0; |
| 1771 | } |
| 1772 | |
| 1773 | |
| 1774 | /* |
nothing calls this directly
no test coverage detected