NUMPY_API * Clip */
| 850 | * Clip |
| 851 | */ |
| 852 | NPY_NO_EXPORT PyObject * |
| 853 | PyArray_Clip(PyArrayObject *self, PyObject *min, PyObject *max, PyArrayObject *out) |
| 854 | { |
| 855 | PyArray_FastClipFunc *func; |
| 856 | int outgood = 0, ingood = 0; |
| 857 | PyArrayObject *maxa = NULL; |
| 858 | PyArrayObject *mina = NULL; |
| 859 | PyArrayObject *newout = NULL, *newin = NULL; |
| 860 | PyArray_Descr *indescr = NULL, *newdescr = NULL; |
| 861 | char *max_data, *min_data; |
| 862 | PyObject *zero; |
| 863 | |
| 864 | /* Treat None the same as NULL */ |
| 865 | if (min == Py_None) { |
| 866 | min = NULL; |
| 867 | } |
| 868 | if (max == Py_None) { |
| 869 | max = NULL; |
| 870 | } |
| 871 | |
| 872 | if ((max == NULL) && (min == NULL)) { |
| 873 | PyErr_SetString(PyExc_ValueError, |
| 874 | "array_clip: must set either max or min"); |
| 875 | return NULL; |
| 876 | } |
| 877 | |
| 878 | func = PyArray_DESCR(self)->f->fastclip; |
| 879 | if (func == NULL) { |
| 880 | if (min == NULL) { |
| 881 | return PyObject_CallFunctionObjArgs(n_ops.minimum, self, max, out, NULL); |
| 882 | } |
| 883 | else if (max == NULL) { |
| 884 | return PyObject_CallFunctionObjArgs(n_ops.maximum, self, min, out, NULL); |
| 885 | } |
| 886 | else { |
| 887 | return PyObject_CallFunctionObjArgs(n_ops.clip, self, min, max, out, NULL); |
| 888 | } |
| 889 | } |
| 890 | |
| 891 | /* |
| 892 | * NumPy 1.17.0, 2019-02-24 |
| 893 | * NumPy 1.19.0, 2020-01-15 |
| 894 | * |
| 895 | * Setting `->f->fastclip to anything but NULL has been deprecated in 1.19 |
| 896 | * the code path below was previously deprecated since 1.17. |
| 897 | * (the deprecation moved to registration time instead of execution time) |
| 898 | * everything below can be removed once this deprecation completes |
| 899 | */ |
| 900 | |
| 901 | if (func == NULL |
| 902 | || (min != NULL && !PyArray_CheckAnyScalar(min)) |
| 903 | || (max != NULL && !PyArray_CheckAnyScalar(max)) |
| 904 | || PyArray_ISBYTESWAPPED(self) |
| 905 | || (out && PyArray_ISBYTESWAPPED(out))) { |
| 906 | return _slow_array_clip(self, min, max, out); |
| 907 | } |
| 908 | /* Use the fast scalar clip function */ |
| 909 |
nothing calls this directly
no test coverage detected