Conversation
Adding a f2py-wrapper for the logarithmic FFT by A. J. S. Hamilton; original code available at: http://casa.colorado.edu/~ajsh/FFTLog.
|
Link to scipy-dev message: https://mail.python.org/pipermail/scipy-dev/2017-April/021939.html |
Don't worry about this for now, easier to do right before or after merging.
The continuous integration will complain about this. I'll have a look at what to add where. |
|
There's a couple of doctest failures, and a non-ascii character. Have a look at the bottom of https://travis-ci.org/scipy/scipy/jobs/222840699 for details |
scipy/fftpack/logarithmic.py
Outdated
| del atexit | ||
|
|
||
|
|
||
| def fftlog(x, dlogr, mu='sine', q=0.0, kr=1.0, rk=1.0): |
There was a problem hiding this comment.
Are all these parameters really necessary, and if so can they be given more descriptive names? Especially kr and rk seem like parameters that are taken over from the Fortran code but are unintuitive for users.
scipy/fftpack/logarithmic.py
Outdated
| (the default) then ``n = x.shape[axis]``. If ``n < x.shape[axis]``, | ||
| `x` is truncated, if ``n > x.shape[axis]``, `x` is zero-padded. | ||
|
|
||
| axis : int, optional |
There was a problem hiding this comment.
this parameter as well as overwrite_x is not in the signature of this function
scipy/fftpack/logarithmic.py
Outdated
| Returns | ||
| ------- | ||
| y : real ndarray | ||
| Transformed array Ã(k): a(j) is Ã(k_j) at k_j = k_c exp[(j-jc) dlnr]. |
There was a problem hiding this comment.
These weird A's are non-ascii and should be removed.
scipy/fftpack/logarithmic.py
Outdated
| Examples | ||
| -------- | ||
| >>> from scipy.fftpack import fftlog, fftlogargs | ||
| >>> # Get fftlog-arguments |
There was a problem hiding this comment.
Instead of comments you should use normal text (i.e. remove >>> # ) with blank lines above and below.
There was a problem hiding this comment.
that goes for all comments in here
| >>> print('Input :', fw) | ||
| >>> print('Analytical :', ft) | ||
| >>> print('fftlog :', fftl) | ||
| Input : [ 1.48956664 1.32757767 1.18320484 1.05453243] |
There was a problem hiding this comment.
the output should be straight under each print statement
scipy/fftpack/logarithmic.py
Outdated
| return y | ||
|
|
||
|
|
||
| def fftlogargs(n, dlogr=0.01, logrc=0.0, mu='sine', q=0, kr=1, kropt=0): |
There was a problem hiding this comment.
Related to my API question for fftlog: why is this function needed at all? Can you instead use this internally in fftlog?
| >>> print('outpts :', outpts[1]) | ||
| >>> print('kr :', outpts[2]) | ||
| >>> print('rk :', outpts[3]) | ||
| intpts : [ 0.96605088 0.98855309 1.01157945 1.03514217] |
There was a problem hiding this comment.
same as for fftlog, put print outputs straight under each print statement
- Replace non-ascii characters - Name input parameters more intuitively - Correct examples for doctest
|
Thanks for reviewing it Ralf. Few things:
Required changes in order to include
to only calculated the required input points for given Do you prefer to keep it as it is or shall I make the changes to include |
|
Turns out that the ü in my surname was the ascii-problem... |
|
Glad to see it added to the 1.1.0 milestone. I assume it still needs work, but I am happy to iterate over it. |
Not sure right now. We're short on reviewer power unfortunately, and fftpack isn't the most active submodule. I'm adding PRs with enhancements that seem ready to the milestone for the next release so we make sure to go over those and try to get them merged. |
|
I apologize for bumping this again. Looks like we're getting some more momentum on FFTs with the Pocketfft work in NumPy, however no reviewer in time for 1.2.0 |
|
Bumping again -- I'm not the right person to review FFT Fortran code at this time, but hopefully we will regain momentum as Ralf suggests. |
|
I'm sorry ... I've inadvertently sabotaged this PR by pushing for the switch to I don't have a feeling how hard it would be to implement FFTLog on top of the new C++ module, but I volunteer to assist, if I can. |
|
Thanks @mreineck for picking this up. It all depends. Mainly,
In the meantime since I made this PR I created a pure Python-Version of it, which could be implemented instead. It can be found here: https://github.com/prisae/pyfftlog I never benchmarked FFTLog versus pyfftlog. But there are no loops, and most work is carried out within |
|
I don't think I'll have enough time to work on this in the near future. |
|
I would like to revive the effort to get FFTLog into scipy, as it seems that people are reimplementing this constantly. Instead of using the original Fortran FFTLog implementation, why not use a Python implementation that calls whatever FFT routine in scipy is fastest. Here is an example of the main routine using |
|
If someone picks it up that would be great @ntessore. For what its worth, my implementations can now be installed via pip and via conda: or for the pure Python version, or or for the Python-wrapped Fortran version. |
|
The FFTLog algorithm contains possibilities for a Hankel transform and a Fourier transform. As far as I can see, the gist you posted contains only the Hankel transform, right? The name "FFTLog" is a bit misleading, unfortunately. |
|
The gist I posted only contains the main routine as an example of how simple the implementation would be. Every other routine in the original FFTLog is then essentially a one-liner to provide a more convenient interface for special cases. Note that I also only show the forward transform, since the backward transform should be its own function, in the spirit of |
|
I would certainly love to have it in SciPy. |
|
Thanks, @ntessore, for the demo! This certainly looks like a good way of having the functionality in scipy. |
|
(Just FWIW: in my experience the Fortran-wrapped version is usually faster by a margin, so it would be nice to have that one. However, I'd be happy to have a pure Python version over not having anything at all.) |
|
I don't remember exactly, but my recollection is that the Fortran code for FFTlog was fairly closely linked to FFTPACK, which is no longer available in Scipy. So if there should be a compiled version of FFTLog, it would require substantial rewriting. At least for the moment I'd lean towards a Python implementation, since it really appears to be very easy to do. If a compiled implementation follows at a later time, not much effort would be lost. |
|
Yes, I think that was one of the reason why this PR stalled in the end @mreineck - given your insights a pure Python version sounds more feasible indeed. |
|
Using your Either way, it looks like there it not much in the Python code that is inherently slow. The FFT implementation will make the difference. And for very large input lengths, I expect the numpy array operations to perform well compared to the Fortran loops. |
|
Any idea why the |
Hmm, maybe that depends on the transform length. Which length did you use for this run? |
Apologies, that was the profiler being flaky due to insufficient time resolution for an input size of And pure Python is only about 1/3 as fast as Fotran. For Now pure Python is 2/3 as fast as Fortran. So I guess tweaking the |
|
Interesting, thanks! It almost seems like |
|
I suspect that it could do with a lot less precision here than in the general purpose case. If speed is really that important, perhaps it would make sense to port the Lastly, I wanted to point out that the Fortran implementation is really not any more complicated than the Python example. Almost all of the complexity comes from setting up the FFT, and in particular dealing with the last element of the array, which the Python version just hands over to |
|
The complexity (or let's say the maintenance burden) will come mostly from the interface, I think. If I look at the amount of glue code that comes between the pure C++ FFT implementation in But I should stress that this is only my personal opinion - I'm only involved in |
|
+1 for a pure-Python solution. I say let's get something that works properly with a good/suitable interface first. That is enough work to start. After that, we can have follow-up PRs to make it more efficient where there are pain points. For example the line |
|
Please let me know how I can help. I can provide a pure Python implementation of the classical FFTLog functionality which has the following interface:
|
|
That looks reasonable to me -- @mreineck @peterbell10 I guess these should live in |
Feels like the most natural place, yes. Thanks a lot, @ntessore, for taking care of this! |
|
Sounds OK to me. I think the best is if you simply provide the functionality and then we can iterate over it. Feel free to use this PR and replace all the files, or start a new one. We can then link to this one and close this. Either way is fine. I am happy to review with what you come up. |
|
Given how much of this PR has to do with wrapping to Fortran, I would probably just keep parts of the I'll close this but you should be able to pull commits from @prisae's branch if need be |
|
Ok thanks. I will pull in prisae/include-fftlog and move stuff around, that should credit @prisae as well. The I will open a new PR. Give a thumbs up to this and I will ping you in the new PR. |
|
Yes feel free to do that. In the end I will probably merge your PR with squash+merge and let the "Co-authored by" take care of dual code credit. The alternative is to |
|
Thanks @ntessore , looking forward to it! |
Adding a f2py-wrapper for the logarithmic FFT by A. J. S. Hamilton;
original code available at: http://casa.colorado.edu/~ajsh/FFTLog.
This is an initial pull request to add Hamilton's FFTLog to the fftpack of SciPy, as discussed on the mailing list starting with https://mail.scipy.org/pipermail/scipy-dev/2016-October/021552.html.
Some important points:
fftpack/src/fftlog/cdgamma.f: It has to be replaced with
scipy.special.loggamma(I am lacking the necessary knowledge to do this) => all callscdgamma(x, 1)infftlog.fcan be replaced withloggamma(x). See discussion here and in the whole thread in general: https://mail.scipy.org/pipermail/scipy-dev/2016-October/021584.html.fftpack/FFTLog-Example.ipyn: Not part of it, they are just examples of its usage.
I tried to follow the Contributing to SciPy (HACKING.rst.txt) guide as much as possible. In terms of the provided checklist in HACKING.rst.txt, I did all but:
I welcome any feedback!
Dieter