-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Update ufunc override to work properly with ufunc methods. #4626
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
Conversation
This fixes the bug mentioned here. |
@@ -4939,6 +4949,20 @@ ufunc_at(PyUFuncObject *ufunc, PyObject *args) | |||
char * err_msg = NULL; | |||
NPY_BEGIN_THREADS_DEF; | |||
|
|||
/* override vars */ | |||
int errval; |
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.
Need to declare before NPY_BEGIN_THREADS_DEF;
, which has an empty statement before;
and makes this declaration after a code statement. This is an error on windows also.
Bunch of warnings like this
Might be related to the almost universal test failures. When you are ready, could you clean up the commit history and messages? Messages like |
All compiled and ran, but all had failures. |
method_name = PyUString_FromString(method); | ||
if (method_name == NULL) { | ||
/* ufunc.reduce */ | ||
else if (strncmp(method, "reduce", 6) == 0) { |
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 also catches "reduceat"
maybe an enum is more appropriate
@juliantaylor good catch, I'll do that when I get a chance. @charris I'll rebase with the appropriate |
Any clue about the segfault? |
else { | ||
/* keepdims */ | ||
PyDict_SetItemString(*normal_kwds, "keepdims", obj); | ||
} |
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.
Do I need to Py_DECREF(obj)
here (and other places)? I'm not sure if PyDict_SetItemString
has its own reference to obj
now.
Don't know that much debugging foo, but did you try running the test in valgrind (best selectively just that file with runtests maybe, it is slow)? |
@@ -4939,6 +4954,15 @@ ufunc_at(PyUFuncObject *ufunc, PyObject *args) | |||
char * err_msg = NULL; | |||
NPY_BEGIN_THREADS_DEF; | |||
|
|||
/* `nin`, the last arg, is unused. So we put 0. */ | |||
errval = PyUFunc_CheckOverride(ufunc, "at", args, kwds, &override, 0); |
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.
kwds is uninitialized here, probably the cause of the segfault
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.
Yep, that was it. Thanks!
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.
now theres a memory leak, why not simply pass in NULL?
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.
Done, thanks.
@charris Rebased with proper commit messages. |
@pv Does this LGTY. |
assert_equal(res[4], (1, a)) | ||
assert_equal(res[5], {}) | ||
|
||
res = np.multiply.reduce(a, 'axis0', 'dtype0', 'out0', 'keep0') |
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.
No tests with kwargs --- these check just that the positional args work ok.
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.
Working on it. I implemented at
with the last arg as a kwarg which is incorrect.
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.
What state is master in if this doesn't get merged? Would leaving this out
of 1.9 mean that we release 1.9 with a broken numpy_ufunc API and get
stuck in some compatibility trap?
On Fri, May 9, 2014 at 8:34 PM, Blake Griffith notifications@github.comwrote:
In numpy/core/tests/test_umath.py:
- assert_equal(res, "reduce")
res = np.multiply.accumulate(a, 1)
- assert_equal(res, "accumulate")
res = np.multiply.reduceat(a, 1)
assert_equal(res, "reduceat")
res = np.multiply.**call**(1, a)
assert_equal(res[0], a)
assert_equal(res[1], np.multiply)
assert_equal(res[2], '**call**')
assert_equal(res[3], 1)
assert_equal(res[4], (1, a))
assert_equal(res[5], {})
res = np.multiply.reduce(a, 'axis0', 'dtype0', 'out0', 'keep0')
Working on it. I implemented at with the last arg as a kwarg which is
inco 8000 rrect.—
Reply to this email directly or view it on GitHubhttps://github.com//pull/4626/files#r12492498
.
Nathaniel J. Smith
Postdoctoral researcher - Informatics - University of Edinburgh
http://vorpus.org
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.
In master: if ufuncs are given extra optional arguments as positional arguments --- apart from the input and out= one --- they are stuffed to out
kwarg instead of separate kwargs in master.
While this is buggy in itself, it is in practice perhaps not a common situation. (As the ufunc extra args are obscure stuff, people tend to call them as kwargs.)
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.
@pv kwargs tests added.
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.
are the non reduce kwargs tested? extobj, where, casting etc?
I'm going to branch 1.9.x today, and wait a few days for 1.9.0. This can be backported if it is ready in time. |
the non-reduce kwargs cannot be passed positionally, so its probably fine |
merging, thanks |
Update ufunc override to work properly with ufunc methods.
This allows the ufunc override machinery to work properly with all the ufunc methods.
There is one failing test here which I am looking into. It passes for some python versions and not others.
The ufunc methods required some API design decisions and I'd like to hear what people think. The original ufunc override spec called for the arguments to be parsed into
inputs
andkwargs
. But what is an input and what is a kwarg?The methods I'm wondering about are
ufunc.outer(A, B)
andufunc.at(a, indices[, b])
.For
outer
I guess bothA
andB
should be ininputs
? Forat
shouldb
also be ininputs
.Also please check my reference counting, I'm not confident about it.