krischer / mtspec

Python library for multitaper spectral estimations
http://krischer.github.io/mtspec/
GNU General Public License v3.0
69 stars 44 forks source link

move to mwlib 4.2 ? #10

Closed ThomasLecocq closed 8 years ago

ThomasLecocq commented 9 years ago

Ok, this would mean a move to fftw3, but that shouldn't be too hard to move... Even on Windows (I successfully installed fftw3 + compiled python libs using it)...

krischer commented 9 years ago

If somebody starts this: This is a good opportunity to also transition to f2py. The f2py branch already does that but can probably not be merged in the master anymore...

efiring commented 9 years ago

I looked at this quite some time ago (I took a stab at using f2py to wrap libmtspec), so I'm sorry I can't give details, but only raise a caution. FFTW is fast only when used with skill and care. It gains its speed by customizing code for a particular array size. The gain is realized with repeated calls using the same array size, saving the customization so that the customization calculation isn't redone each time. In 4.2, it is not being used this way. I concluded that the result is actually slower by about a factor of 2 than with the older and much simpler fft library. (I could be wrong; but I would advise a close look and some testing.)

A second caution is that f2py development seems to have completely stalled, and support for F90 and later Fortran features is incomplete. It might be perfectly adequate, though.

krischer commented 9 years ago

Thanks for the comment and your tests! I am surprised to hear FFTW performs worse than the simple FFT implementation in mtspec but I guess that is just a slight usage error. Can one use FFTW without making a plan first?

Nonetheless I guess this means we don't move to the latest mtspec version but leave the current one as is which is also pretty nice.

I kind of reached the same conclusion in regards to f2py as you did. There is even an old f2py branch on this repository...

I think the cleanest way to wrap Fortran in Python these days is to write small wrappers on the Fortran side using the iso_c_bindings module and then call these from Python with CFFI (https://cffi.readthedocs.org/en/latest/).

The way it is currently done in mtspec probably does not work across compilers due to the name mangling and maybe even other reasons.

efiring commented 9 years ago

I'm by no means an expert in FFTW--quite the contrary--but as I see it, it depends on the existence of a plan. So you can run it without making a plan beforehand, and it will make one, but the total runtime will not be especially quick. If you use one of the available methods for saving the plan, so that it is available for subsequent calculations with an array of the same size, then those calculations will be fast. There are perhaps 3 planning methods you can specify; the more times you are going to use a given plan, the more benefit there is in selecting a slower plan generation method. The slowest makes sense only when there will be a large number of identical calculations. Fortran wrapping: one recent recommendation on the numpy list, by Sturla Molden, I think, was to use iso_c_bindings with cython to generate C wrappers. How that compares with using CFFI, I don't know. I like and use cython, but have never tried CFFI.

krischer commented 8 years ago

I recently worked a bit on mtspec and I don't think I'll transition to 4.2 with FFTW - the dependency is just too much hassle and mtspec currently works well enough IMHO.