-
-
Notifications
You must be signed in to change notification settings - Fork 11k
MAINT: Merge together the unary and binary type resolvers #12928
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 merges `PyUFunc_SimpleUnaryOperationTypeResolver` and `PyUFunc_SimpleBinaryOperationTypeResolver` These are almost identical, save for using `ResultType` vs simply forcing a byte order. This comes at the cost of a handful of branches, which should be insignifcant compared to the rest of the ufunc overhead.
return PyUFunc_DefaultTypeResolver(ufunc, casting, operands, | ||
type_tup, out_dtypes); | ||
} | ||
|
||
if (type_tup == NULL) { | ||
/* Input types are the result type */ | ||
out_dtypes[0] = PyArray_ResultType(2, operands, 0, NULL); | ||
/* PyArray_ResultType forgets to force a byte order when n == 1 */ |
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 has the worrying consequence that np.result_type(dt)
and np.positive(np.empty((), dt)).dtype
give different results - but not something this patch affects
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.
Ah, I guess the strange thing seems to me that np.result_type
for a single item is no-op, while it is not for binary ones. Could consider changing that for result type, but not directly important here.
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.
Nice, looks good to me, will merge in a bit if nobody beats me to it.
return PyUFunc_DefaultTypeResolver(ufunc, casting, operands, | ||
type_tup, out_dtypes); | ||
} | ||
|
||
if (type_tup == NULL) { | ||
/* Input types are the result type */ | ||
out_dtypes[0] = PyArray_ResultType(2, operands, 0, NULL); | ||
/* PyArray_ResultType forgets to force a byte order when n == 1 */ |
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.
Ah, I guess the strange thing seems to me that np.result_type
for a single item is no-op, while it is not for binary ones. Could consider changing that for result type, but not directly important here.
@@ -12,6 +12,8 @@ | |||
#define _MULTIARRAYMODULE | |||
#define NPY_NO_DEPRECATED_API NPY_API_VERSION | |||
|
|||
#include <stdbool.h> |
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.
Guess we can use that more now with C99.
OK, putting this in, thanks Eric! |
This merges
PyUFunc_SimpleUnaryOperationTypeResolver
andPyUFunc_SimpleBinaryOperationTypeResolver
These are almost identical, save for using
ResultType
vs simply forcing a byte order.This comes at the cost of a handful of branches, which should be insignifcant compared to the rest of the ufunc overhead.
Spin off from #7876, where I was about to add
PyUFunc_SimpleTernaryOperationTypeResolver
and thought better of it.