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

Function PyArray_ClipmodeConverter

numpy/core/src/multiarray/conversion_utils.c:747–780  ·  view source on GitHub ↗

NUMPY_API * Convert an object to NPY_RAISE / NPY_CLIP / NPY_WRAP */

Source from the content-addressed store, hash-verified

745 * Convert an object to NPY_RAISE / NPY_CLIP / NPY_WRAP
746 */
747NPY_NO_EXPORT int
748PyArray_ClipmodeConverter(PyObject *object, NPY_CLIPMODE *val)
749{
750 if (object == NULL || object == Py_None) {
751 *val = NPY_RAISE;
752 }
753
754 else if (PyBytes_Check(object) || PyUnicode_Check(object)) {
755 return string_converter_helper(
756 object, (void *)val, clipmode_parser, "clipmode",
757 "must be one of 'clip', 'raise', or 'wrap'");
758 }
759 else {
760 /* For users passing `np.RAISE`, `np.WRAP`, `np.CLIP` */
761 int number = PyArray_PyIntAsInt(object);
762 if (error_converting(number)) {
763 goto fail;
764 }
765 if (number <= (int) NPY_RAISE
766 && number >= (int) NPY_CLIP) {
767 *val = (NPY_CLIPMODE) number;
768 }
769 else {
770 PyErr_Format(PyExc_ValueError,
771 "integer clipmode must be np.RAISE, np.WRAP, or np.CLIP");
772 }
773 }
774 return NPY_SUCCEED;
775
776 fail:
777 PyErr_SetString(PyExc_TypeError,
778 "clipmode not understood");
779 return NPY_FAIL;
780}
781
782/*NUMPY_API
783 * Convert an object to an array of n NPY_CLIPMODE values.

Callers 1

Calls 2

string_converter_helperFunction · 0.85
PyArray_PyIntAsIntFunction · 0.85

Tested by

no test coverage detected