New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DEP: Shift correlate mode parsing to C and deprecate inexact matches #17492
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution, although this isn't quite right.
I'd actually be very tempted to move this parameter parsing to C, so that it can be handled in exactly the same way as the other arguments like this. Would you be ok to try that instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed - the deprecation should not change the behavior, but warn the user that the behavior will change when the deprecation expires.
A few comments on the tests as well since I had looked at them.
f177eef
to
7708fe1
Compare
Close/reopen to restart builds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change still results in modified behavior. For example, on master np.convolve(*args, mode="silly")
will result in mode 1
being used, whereas in the PR, the same call will result in 2
. The deprecation should only warn the user of a pending behavior change, not silently change the behavior.
I would recommend getting rid of the default_mode
addition and see if you can come up with a minimal change for raising the warning.
I raised this question here: #17492 (comment) |
7708fe1
to
b3f86f9
Compare
I think my comment above might have gotten lost:
|
I actually missed it amid suggestions. I wouldn't mind, could you point me to a right path to start digging in? |
Sure, here's some pointers: The code that parses the numpy/numpy/core/src/multiarray/multiarraymodule.c Lines 2897 to 2909 in 565fe77
My suggestion would be to change that to something like:
where numpy/numpy/core/src/multiarray/conversion_utils.c Lines 598 to 673 in 565fe77
|
b3f86f9
to
4dbc544
Compare
Hey @eric-wieser I could use some help here. It took me a while but I was able to shift parameter parsing completely to C, it worked well locally until I did something wrong during the last few changes - build is failing (KeyError of the function name). I'm thinking I should add a Global C Pointer key value in numpy_api? I've incorporated your suggestion, and haven't changed the behaviour. (You can still review the changes, the build error should be solvable) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably don't need to make this part of the public C API - which should also fix your build error
9cf6fb9
to
e811a8f
Compare
The build works locally, should be fine for review now. 👍🏼 |
e811a8f
to
0cc1285
Compare
04cb219
to
6e417cb
Compare
valid_mode = np.correlate(d, k, mode='v') | ||
assert_array_equal(valid_mode, default_mode) | ||
# integer mode | ||
assert_array_equal(np.correlate(d, k, mode=0), valid_mode) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a test of an invalid integer too?
Also, it may make sense to add a test here too:
numpy/numpy/core/src/multiarray/_multiarray_tests.c.src
Lines 2088 to 2101 in aeb2374
static PyObject * | |
run_clipmode_converter(PyObject* NPY_UNUSED(self), PyObject *args) | |
{ | |
NPY_CLIPMODE mode; | |
if (!PyArg_ParseTuple(args, "O&", PyArray_ClipmodeConverter, &mode)) { | |
return NULL; | |
} | |
switch (mode) { | |
case NPY_CLIP: return PyUnicode_FromString("NPY_CLIP"); | |
case NPY_WRAP: return PyUnicode_FromString("NPY_WRAP"); | |
case NPY_RAISE: return PyUnicode_FromString("NPY_RAISE"); | |
} | |
return PyLong_FromLong(mode); | |
} |
numpy/numpy/core/src/multiarray/_multiarray_tests.c.src
Lines 2308 to 2310 in aeb2374
{"run_casting_converter", | |
run_casting_converter, | |
METH_VARARGS, NULL}, |
numpy/numpy/core/tests/test_conversion_utils.py
Lines 163 to 174 in aeb2374
class TestCastingConverter(StringConverterTestCase): | |
""" Tests of PyArray_CastingConverter """ | |
conv = mt.run_casting_converter | |
case_insensitive = False | |
exact_match = True | |
def test_valid(self): | |
self._check("no", "NPY_NO_CASTING") | |
self._check("equiv", "NPY_EQUIV_CASTING") | |
self._check("safe", "NPY_SAFE_CASTING") | |
self._check("same_kind", "NPY_SAME_KIND_CASTING") | |
self._check("unsafe", "NPY_UNSAFE_CASTING") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created the tests, but I can't seem to find a way to make PyArray_CorrelatemodeConverter
function visible like PyArray_ClipmodeConverter
in this file:
numpy/numpy/core/src/multiarray/_multiarray_tests.c.src
Lines 2088 to 2101 in aeb2374
static PyObject * | |
run_clipmode_converter(PyObject* NPY_UNUSED(self), PyObject *args) | |
{ | |
NPY_CLIPMODE mode; | |
if (!PyArg_ParseTuple(args, "O&", PyArray_ClipmodeConverter, &mode)) { | |
return NULL; | |
} | |
switch (mode) { | |
case NPY_CLIP: return PyUnicode_FromString("NPY_CLIP"); | |
case NPY_WRAP: return PyUnicode_FromString("NPY_WRAP"); | |
case NPY_RAISE: return PyUnicode_FromString("NPY_RAISE"); | |
} | |
return PyLong_FromLong(mode); | |
} |
If I directly #include "conversion_utils.h"
it throws a bunch of errors while building, which is understandable.
I think PyArray_ClipmodeConverter
is visible to this file as it is a global C API.
Or is there something I'm missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
PyArray_ClipmodeConverter
is visible to this file as it is a global C API.
Hmm, that's possible.
If I directly #include "conversion_utils.h" it throws a bunch of errors while building, which is understandable.
Can you give an example of those errors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's the full traceback, it seems like a compiler issue?
In file included from numpy/core/include/numpy/ndarrayobject.h:21:0,
from numpy/core/include/numpy/arrayobject.h:4,
from numpy/core/src/multiarray/_multiarray_tests.c.src:5:
numpy/core/include/numpy/__multiarray_api.h:1090:12: error: expected identifier or ‘(’ before ‘int’
(*(int (*)(PyObject *, PyArray_Dims *)) \
^
numpy/core/src/multiarray/conversion_utils.h:7:1: note: in expansion of macro ‘PyArray_IntpConverter’
PyArray_IntpConverter(PyObject *obj, PyArray_Dims *seq);
^~~~~~~~~~~~~~~~~~~~~
numpy/core/include/numpy/__multiarray_api.h:1445:10: error: expected ‘)’ before ‘PyArray_API’
PyArray_API[298])
^
numpy/core/src/multiarray/conversion_utils.h:49:1: note: in expansion of macro ‘PyArray_SelectkindConverter’
PyArray_SelectkindConverter(PyObject *obj, NPY_SELECTKIND *selectkind);
^~~~~~~~~~~~~~~~~~~~~~~~~~~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, looks like your diagnosis is correct; multiarray_tests
requires things to be in the public API. I think it's ok to leave things as is for now, thanks for investigating
6e417cb
to
5fe981e
Compare
All builds pass successfully, think we can merge it now? |
/cc @eric-wieser @rossbar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ought to have a release note too - sorry for forgetting about this for so long!
That's completely fine :) |
@eric-wieser Do you want me to squash the commits? |
@eric-wieser could you take one last look? |
@aitikgupta this PR was approved but seems to have gotten lost. Now there are merge conflicts. Could you merge with main or rebase it to clear the path for merging it? @eric-wieser any need for more review? |
I don't think this needs any more review; just the merge conflicts resolving after the argument parsing change |
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
80def6f
to
89de3d9
Compare
rebased to clear merge conflicts |
@mattip did the heavy lifting before I could jump in :D |
Thanks @aitikgupta, sorry it took so long to get this merged. |
Fixes #17476
Also, see #16056