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

Skip to content

MAINT: simplify complex math function handling in npymath #22161

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 2 commits into from
Oct 6, 2022

Conversation

mattip
Copy link
Member

@mattip mattip commented Aug 22, 2022

Continuation of #22090: now for complex functions

@mattip
Copy link
Member Author

mattip commented Aug 22, 2022

We have our own function declarations in numpy/core/feature_detection_math.h for MANDATORY functions, so adding complex functions to MANDATORY is going to require some refactoring.

@rgommers
Copy link
Member

this needs a rebase now that gh-22090 is merged

@seberg
Copy link
Member

seberg commented Sep 27, 2022

Tried to fix the issue with the mandatory functions by creating the header. That is slightly annoying, since MSVC does not have proper complex support, so the header has to define the complex type.

gh-5687 may mean we have to put the ctanh fallback back to blocklist it on windows (I am wondering if moving to C++ might be another solution). But so long we think the new header is OK, this is probably fine for now?

@rgommers
Copy link
Member

It's probably a pragmatic choice to add all those complex functions to a single file. It does couple them together though. I'll note that I implemented this as separate checks for Meson already: https://github.com/numpy/numpy/compare/main...rgommers:numpy:meson?expand=1#diff-1b8787c0de2167aaf65f45eadb93cec2810f91b92c42e422b1e8d07bc152a92fR65-R79

@@ -102,12 +102,14 @@ def set_sig(sig):
args = args.rpartition(")")[0]
funcname = prefix.rpartition(" ")[-1]
args = [arg.strip() for arg in args.split(",")]
FUNC_CALL_ARGS[funcname] = ", ".join("(%s) 0" % arg for arg in args)
# We use {0} because 0 alone cannot be cast to complex on MSVC in C:
FUNC_CALL_ARGS[funcname] = ", ".join("(%s){0}" % arg for arg in args)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets see if this works. I had to add the struct here because (_Dcomplex)0 is not a valid cast in MSVC complex.h...

@seberg
Copy link
Member

seberg commented Oct 4, 2022

@rgommers should we just roll with this? The deletion seems nice (whether we need to roll back or not eventually).

@rgommers
Copy link
Member

rgommers commented Oct 4, 2022

@seberg yes I am fine with this, more cleanups in npymath are great. @mattip is planning to look at your changes before merging I believe.

@mattip mattip merged commit 562c80a into numpy:main Oct 6, 2022
@mattip
Copy link
Member Author

mattip commented Oct 6, 2022

xref #20880

@mattip mattip deleted the simplify-npy_math2 branch December 27, 2022 16:52
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.

3 participants