summaryrefslogtreecommitdiff
path: root/numpy/core/src
diff options
context:
space:
mode:
authorAitik Gupta <aitikgupta@gmail.com>2020-10-10 18:04:04 +0530
committermattip <matti.picus@gmail.com>2021-03-18 20:48:23 +0200
commitf53eaf7780cf2c92157cb8dc650447792476e2eb (patch)
tree4a48d221124c16d8bc21dc23e00f9850b957cbc4 /numpy/core/src
parent666866936c1c731f9de0c66d66a58f14c975c871 (diff)
downloadnumpy-f53eaf7780cf2c92157cb8dc650447792476e2eb.tar.gz
DEP: Deprecate inexact matches of mode, shift parameter parsing to C
Diffstat (limited to 'numpy/core/src')
-rw-r--r--numpy/core/src/multiarray/conversion_utils.c71
-rw-r--r--numpy/core/src/multiarray/conversion_utils.h3
-rw-r--r--numpy/core/src/multiarray/multiarraymodule.c4
3 files changed, 76 insertions, 2 deletions
diff --git a/numpy/core/src/multiarray/conversion_utils.c b/numpy/core/src/multiarray/conversion_utils.c
index dd18f71fd..bcb916791 100644
--- a/numpy/core/src/multiarray/conversion_utils.c
+++ b/numpy/core/src/multiarray/conversion_utils.c
@@ -715,6 +715,77 @@ PyArray_ConvertClipmodeSequence(PyObject *object, NPY_CLIPMODE *modes, int n)
return NPY_SUCCEED;
}
+static int correlatemode_parser(char const *str, Py_ssize_t length, void *data)
+{
+ NPY_CORRELATEMODE *val = (NPY_CORRELATEMODE *)data;
+ int is_exact = 0;
+
+ if (length < 1) {
+ return -1;
+ }
+ if (str[0] == 'V' || str[0] == 'v') {
+ *val = NPY_VALID;
+ is_exact = (length == 5 && strcmp(str, "valid") == 0);
+ }
+ else if (str[0] == 'S' || str[0] == 's') {
+ *val = NPY_SAME;
+ is_exact = (length == 4 && strcmp(str, "same") == 0);
+ }
+ else if (str[0] == 'F' || str[0] == 'f') {
+ *val = NPY_FULL;
+ is_exact = (length == 4 && strcmp(str, "full") == 0);
+ }
+ else {
+ return -1;
+ }
+
+ /* Filters out the case sensitive/non-exact
+ * match inputs and other inputs and outputs DeprecationWarning
+ */
+ if (!is_exact) {
+ if (DEPRECATE("inexact matches and case insensitive matches for "
+ "convolve/correlate mode are deprecated, please "
+ "use one of 'valid', 'same', or 'full' instead.") < 0) {
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+/*
+ * Convert an object to NPY_VALID / NPY_SAME / NPY_FULL
+ */
+NPY_NO_EXPORT int
+PyArray_CorrelatemodeConverter(PyObject *object, NPY_CORRELATEMODE *val)
+{
+ if (PyUnicode_Check(object)) {
+ return string_converter_helper(
+ object, (void *)val, correlatemode_parser, "mode",
+ "must be one of 'valid', 'same', or 'full'");
+ }
+
+ else {
+ /* For users passing integers */
+ int number = PyArray_PyIntAsInt(object);
+ if (error_converting(number)) {
+ PyErr_SetString(PyExc_TypeError,
+ "convolve/correlate mode not understood");
+ return NPY_FAIL;
+ }
+ if (number <= (int) NPY_FULL
+ && number >= (int) NPY_VALID) {
+ *val = (NPY_CORRELATEMODE) number;
+ return NPY_SUCCEED;
+ }
+ else {
+ PyErr_Format(PyExc_ValueError,
+ "integer convolve/correlate mode must be 0, 1, or 2");
+ return NPY_FAIL;
+ }
+ }
+}
+
static int casting_parser(char const *str, Py_ssize_t length, void *data)
{
NPY_CASTING *casting = (NPY_CASTING *)data;
diff --git a/numpy/core/src/multiarray/conversion_utils.h b/numpy/core/src/multiarray/conversion_utils.h
index bee0c6064..7d1871c43 100644
--- a/numpy/core/src/multiarray/conversion_utils.h
+++ b/numpy/core/src/multiarray/conversion_utils.h
@@ -43,6 +43,9 @@ NPY_NO_EXPORT PyObject *
PyArray_IntTupleFromIntp(int len, npy_intp const *vals);
NPY_NO_EXPORT int
+PyArray_CorrelatemodeConverter(PyObject *object, NPY_CORRELATEMODE *val);
+
+NPY_NO_EXPORT int
PyArray_SelectkindConverter(PyObject *obj, NPY_SELECTKIND *selectkind);
/*
diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c
index a0f7afeb5..12705dc19 100644
--- a/numpy/core/src/multiarray/multiarraymodule.c
+++ b/numpy/core/src/multiarray/multiarraymodule.c
@@ -2839,7 +2839,7 @@ array_correlate(PyObject *NPY_UNUSED(dummy),
if (npy_parse_arguments("correlate", args, len_args, kwnames,
"a", NULL, &a0,
"v", NULL, &shape,
- "|mode", &PyArray_PythonPyIntFromInt, &mode,
+ "|mode", &PyArray_CorrelatemodeConverter, &mode,
NULL, NULL, NULL) < 0) {
return NULL;
}
@@ -2857,7 +2857,7 @@ array_correlate2(PyObject *NPY_UNUSED(dummy),
if (npy_parse_arguments("correlate2", args, len_args, kwnames,
"a", NULL, &a0,
"v", NULL, &shape,
- "|mode", &PyArray_PythonPyIntFromInt, &mode,
+ "|mode", &PyArray_CorrelatemodeConverter, &mode,
NULL, NULL, NULL) < 0) {
return NULL;
}