Sunday, September 27, 2009

FFTW issues in Matlab on Mac

For the project I'm currently working on (dVA on sphere), I'm using the Yawtb toolbox, with the S2Kit interface (see previous post) . This interface is faster when it uses FFTW3.
I followed the build instructions for S2Kit, using Macports's FFTW. S2Kit built and tested ok from command line. Testing the integration in Yawtb, I encountered a linker error:

>> yademo s2fst
% Sample(s) of code for S2FST
>> [phi,theta] = sphgrid(46,46); %%
>> mat = exp(-tan(theta/2).^2) .* ( phi == phi(1,10)); %%
>> fmat = s2fst(mat); %%
??? Invalid MEX-file '/IM2sandbox/yawtb/interfaces/s2kit/s2fst.mexmaci':
dlopen(/IM2sandbox/yawtb/interfaces/s2kit/s2fst.mexmaci, 1): Library not loaded: /opt/local/lib/libfftw3.3.dylib
Referenced from: /IM2sandbox/yawtb/interfaces/s2kit/s2fst.mexmaci
Reason: Incompatible library version: s2fst.mexmaci requires version 6.0.0 or later, but libfftw3.dylib provides version

Error in ==> yademo at 77

Some googling after (see comments here), I learned that this comes from a version mismatch between Matlab's FFTW and the newer Macports version.

Contrary to Geoffrey, I decided to update the lib in Matlab (quite similarly to the suggestion here). Note: a backup is recommended. In my case, the fix implied copying libfftw3.dylib and libfftw3.dylib from /opt/local/lib to /Applications/ .

And now, the yademo s2fst example works great :-)
Note that I did not check whether this fix breaks other FFTW related code. YMMV.

Spherical wavelets toolbox - run on windows

I recently began to work on a project concerning dynamic visual attention (VA) on the sphere, and the current code base uses Yawtb and SpharmonicKit.
Since the camera used in the project has only MS Windows drivers, I wanted to run the algorithms in the same OS. A quick google search turned only to posts with similar questions (see questions on Chris Rodgers software blog).
So, I took the plunge and tried to compile on my WinXP SP3 box, with MS Visual Studio 2005. I used premake to create the target projects, based on a quick look at the Makefiles. Note that I replaced the SpharmonicKit27 interface with the more recent S2Kit, which uses fftw for faster Fourier transforms.
Apparently, MS compilers have gained in compliance to ANSI standards over the years. The only issues I had were:
  • undefined M_PI for both Yawtb and S2Kit
fixed with '#define _USE_MATH_DEFINES' in files including math.h
  • srand48() and drand48() could not be found (for S2Kit test files)
here, the fix is less obvious. For now I just used rand() and (double) rand() / (double) RAND_MAX , but this is probably far from optimal (please don't flame for not using your favorite RNG ;-).

A copy of the modified S2Kit is available at
while the modified Yawtb is at:

Beware, those quick patches run on my XP machine, but have not been thoroughly tested. Your mileage may vary.