Skip to content

ENH: Optional dtype for fftfreq/rfftfreq #9126

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

Open
jakirkham opened this issue May 17, 2017 · 5 comments
Open

ENH: Optional dtype for fftfreq/rfftfreq #9126

jakirkham opened this issue May 17, 2017 · 5 comments

Comments

@jakirkham
Copy link
Contributor

Would be nice to be able to specify a dtype for fftfreq/rfftfreq other than float64 (e.g. float32), to which it appears to default.

@mhvk
Copy link
Contributor

mhvk commented May 17, 2017

Yes, would be nice. Even better to support float32 and complex64 in the regular fft calls... Previously, it has been stated one should use scipy for this, but since that stores the transforms in a logical but very inconvenient format (not proper complex numbers), there is a case to be made to extend numpy. In principle, it is just a matter of compiling the same C source twice, with different definitions of DOUBLE -- which affects Treal in https://github.com/numpy/numpy/blob/master/numpy/fft/fftpack.c#L14

@jakirkham
Copy link
Contributor Author

I'm not sure that it is even that complicated. Should be a simple matter of changing this line and this line to not force float.

@eric-wieser
Copy link
Member

Using np.reciprocal there would work, right?

@shitian-ni
Copy link
Contributor

@eric-wieser
Sorry, I don't understand, what is the relationship between np.reciprocal and the dtype issue here?
And can I make a PR to match the output type with the type of d?

@mhvk
Copy link
Contributor

mhvk commented May 21, 2017

I think this is a little tricker than just changing the line, since there are two times the likely float value gets multiplied with an int, first in val = 1.0 / (n * d), and then again at the very end, results * val. Instead, it is probably best to set the dtype in the creation of results, and then do calculations inplace.

In addition to (or instead of?) the dtype argument, should one add an out argument? To make it most similar to ufuncs, the signature might then become fftfreq(n, d=1.0, out=None, dtype=None) (that said, arange -- which this really is an elaborate version of -- does not have an out argument, but does have dtype).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants