Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 1 commit into from
Feb 11, 2019

Conversation

eric-wieser
Copy link
Member

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.

Spin off from #7876, where I was about to add PyUFunc_SimpleTernaryOperationTypeResolver and thought better of it.

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 */
Copy link
Member Author

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

Copy link
Member

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.

Copy link
Member

@seberg seberg left a 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 */
Copy link
Member

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>
Copy link
Member

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.

@seberg seberg self-assigned this Feb 7, 2019
@seberg
Copy link
Member

seberg commented Feb 11, 2019

OK, putting this in, thanks Eric!

@seberg seberg merged commit 1c4ab89 into numpy:master Feb 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants