NUMPY_API * Convert an object to an array of n NPY_CLIPMODE values. * This is intended to be used in functions where a different mode * could be applied to each axis, like in ravel_multi_index. */
| 785 | * could be applied to each axis, like in ravel_multi_index. |
| 786 | */ |
| 787 | NPY_NO_EXPORT int |
| 788 | PyArray_ConvertClipmodeSequence(PyObject *object, NPY_CLIPMODE *modes, int n) |
| 789 | { |
| 790 | int i; |
| 791 | /* Get the clip mode(s) */ |
| 792 | if (object && (PyTuple_Check(object) || PyList_Check(object))) { |
| 793 | if (PySequence_Size(object) != n) { |
| 794 | PyErr_Format(PyExc_ValueError, |
| 795 | "list of clipmodes has wrong length (%zd instead of %d)", |
| 796 | PySequence_Size(object), n); |
| 797 | return NPY_FAIL; |
| 798 | } |
| 799 | |
| 800 | for (i = 0; i < n; ++i) { |
| 801 | PyObject *item = PySequence_GetItem(object, i); |
| 802 | if(item == NULL) { |
| 803 | return NPY_FAIL; |
| 804 | } |
| 805 | |
| 806 | if(PyArray_ClipmodeConverter(item, &modes[i]) != NPY_SUCCEED) { |
| 807 | Py_DECREF(item); |
| 808 | return NPY_FAIL; |
| 809 | } |
| 810 | |
| 811 | Py_DECREF(item); |
| 812 | } |
| 813 | } |
| 814 | else if (PyArray_ClipmodeConverter(object, &modes[0]) == NPY_SUCCEED) { |
| 815 | for (i = 1; i < n; ++i) { |
| 816 | modes[i] = modes[0]; |
| 817 | } |
| 818 | } |
| 819 | else { |
| 820 | return NPY_FAIL; |
| 821 | } |
| 822 | return NPY_SUCCEED; |
| 823 | } |
| 824 | |
| 825 | static int correlatemode_parser(char const *str, Py_ssize_t length, void *data) |
| 826 | { |
no test coverage detected