-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
MAINT: Make the NPY_CPU_DISPATCH_CALL
macros expressions not statements
#17201
Conversation
…ents This means they can return values, and need semicolons
e84686c
to
5dbc66e
Compare
@eric-wieser, flexibility and unify one behavior among all dispatching macros are the two reasons that forced me to use normal if-condition over the ternary condition. can I know your reasons? |
The main motivation here is that expressions are great, and making the result of the call an expression means I can use it like any other function call. Note that I haven't touched the generated headers - those were flexible enough that I could just change the |
NPY_CPU_DISPATCH_CALL(highest_func = _umath_tests_dispatch_func, ()); | ||
NPY_CPU_DISPATCH_CALL(highest_var = _umath_tests_dispatch_var); |
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.
Note that these could now be rewritten
NPY_CPU_DISPATCH_CALL(highest_func = _umath_tests_dispatch_func, ()); | |
NPY_CPU_DISPATCH_CALL(highest_var = _umath_tests_dispatch_var); | |
highest_func = NPY_CPU_DISPATCH_CALL(_umath_tests_dispatch_func)(); | |
highest_var = NPY_CPU_DISPATCH_CALL(_umath_tests_dispatch_var); |
Since this is a test, I decided to leave them as they are for now.
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.
You can just change one of them so we can test both behaviors.
I will always vote for flexibility/hackability especially when you don't know "how deep the rabbit hole goes".
We can speed up the multiple calls of NPY_CPU_HAVE by inlining numpy/numpy/core/src/common/npy_cpu_features.h Lines 111 to 115 in 60f9c61
|
/** | ||
* Macro NPY_CPU_DISPATCH_CALL_XB(LEFT, ...) | ||
* | ||
* Same as `NPY_CPU_DISPATCH_DECLARE` but exclude the baseline declration even | ||
* if it was provided within the configration statments. | ||
* Same as `NPY_CPU_DISPATCH_DECLARE` but exclude the baseline declaration even |
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.
* Same as `NPY_CPU_DISPATCH_DECLARE` but exclude the baseline declaration even | |
* Same as `NPY_CPU_DISPATCH_CALL` but exclude the baseline call even |
I think this patch increases readability at the expense of a bit of unity, I'm confused the first time I saw |
NPY__CPU_DISPATCH_CALL(NPY_CPU_HAVE, NPY_CPU_DISPATCH_CALL_CB_, __VA_ARGS__) \ | ||
NPY__CPU_DISPATCH_BASELINE_CALL(NPY_CPU_DISPATCH_CALL_BASE_CB_, __VA_ARGS__) | ||
// Preprocessor callbacks | ||
#define NPY_CPU_DISPATCH_CALL_CB_(TESTED_FEATURES, TARGET_NAME, LEFT, ...) \ | ||
else if (TESTED_FEATURES) { NPY_CAT(NPY_CAT(LEFT, _), TARGET_NAME) __VA_ARGS__; } | ||
(TESTED_FEATURES) ? (NPY_CAT(NPY_CAT(LEFT, _), TARGET_NAME) __VA_ARGS__) : |
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.
the if statement is easier to read, why use the conditional expression?
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.
Because the conditional expression makes this have a return value
Thanks @eric-wieser |
This means they can return values, and need semicolons.
Not tested locally, but the constructs were tested in godbolt.
ping @seiko2plus