On Aug 22, 2009, at 7:40 PM, Adam Ginsburg wrote: > I reinstalled cython from source (instead of easy_install-ing it) and > my code compiled successfully. Sorry about the previous e-mail.
Great--I saw your previous email and started to get worried. I thought easy_install was a source install (we didn't ship any binaries until recently, and then just windows installers). > Unfortunately, my code runs slower with cython than without, but at > least now I know I can compile. In case anyone wants to offer > assistance, the code I'm trying to optimize is: > http://code.google.com/p/agpy/source/browse/trunk/plfit.py > http://code.google.com/p/agpy/source/browse/trunk/cplfit.pyx My first piece of advice is to run cython -a over your code. This will produce an html file which is most helpful in diagnosing where you're wasting time. Just in a quick glance at your code I noticed: - You're calling Python's log, sqrt, max, abs, sum. This would negate any gains you may hope to see. - You're calling len a lot, either store it as a int somewhere, or use .shape[0]. - Unless n is huge, arange(n)/float(n) is probably way to expensive. If the above don't help, try unrolling this. I bet there's a lot more performance that one could ring out of your code, but the above should take you far. > Thanks, > Adam > > On Sat, Aug 22, 2009 at 8:28 PM, Adam > Ginsburg<[email protected]> wrote: >> Hi folks, >> I'm trying to turn some numpy code into cython. In pure python >> it's very slow, and I don't believe the task can be vectorized >> easily, >> so I've turned to you. >> >> The code imported fine before I tried adding the cython >> modifications to it, but it ran slower than before. Now, it fails >> with this error: >> >> $ python-64 setup.py build >> running build >> running build_ext >> building 'cplfit' extension >> creating build >> creating build/temp.macosx-10.3-universal-2.6 >> gcc -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes >> /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ >> site-packages/numpy/core/include/ >> -I/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ >> site-packages/numpy/core/include >> -I. -I/Library/Frameworks/Python.framework/Versions/2.6/include/ >> python2.6 >> -c cplfit.c -o build/temp.macosx-10.3-universal-2.6/cplfit.o >> cplfit.c:854: warning: '__pyx_k_3' defined but not used >> cplfit.c:855: warning: '__pyx_k_4' defined but not used >> cplfit.c:875: warning: '__pyx_k_24' defined but not used >> cplfit.c:881: warning: '__pyx_k_26' defined but not used >> cplfit.c:882: warning: '__pyx_k_27' defined but not used >> i686-apple-darwin9-gcc-4.0.1: >> /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ >> site-packages/numpy/core/include/: >> linker input file unused because linking not done >> creating build/lib.macosx-10.3-universal-2.6 >> gcc -arch i386 -arch ppc -arch ppc64 -arch x86_64 -isysroot >> /Developer/SDKs/MacOSX10.5.sdk -bundle -undefined dynamic_lookup >> /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ >> site-packages/numpy/core/include/ >> build/temp.macosx-10.3-universal-2.6/cplfit.o -o >> build/lib.macosx-10.3-universal-2.6/cplfit.so >> ld: in /Developer/SDKs/MacOSX10.5.sdk/Library/Frameworks/ >> Python.framework/ldVersions/:2.6 >> /inlib //Developer/ldSDKs:python2.6 in/MacOSX10.5.sdk >> ///siteLibrary-/Developer/packagesFrameworks/SDKsnumpy// >> Python.frameworkcore///MacOSX10.5.sdkVersions/include//,Library >> /can2.6Frameworks'//tlibPython.framework //mappython2.6Versions >> //filesite2.6-/,packageslib //errnonumpypython2.6/ldsite=-/core/:22 >> include for architecturepackages/numpy/ ppc64 >> ,in // coreDevelopercan//'includeSDKs/tMacOSX10.5.sdk/ Library/map, >> /file, Frameworks canerrno't/= map collect2: 22 filefor >> architectureld >> returned 1 exit status >> ,Python.frameworki386 / >> errnoVersions/=2.6/22lib /forpython2.6 architecture /x86_64 >> site-packages/numpy/core/include/, can't map file, errno=22 for >> architecture ppccollect2: >> ld returned 1 exit status >> collect2: ld returned 1 exit status >> collect2: ld returned 1 exit status >> lipo: can't open input file: >> /var/folders/ni/ni+DtdqFGMeSMH13AvkNkU+++TI/-Tmp-//ccl3U2RI.out (No >> such file or directory) >> error: command 'gcc' failed with exit status 1 >> >> My setup.py: >> from distutils.core import setup >> from distutils.extension import Extension >> from Cython.Distutils import build_ext >> import numpy >> >> setup( >> ext_modules = [ >> Extension("cplfit", ["cplfit.pyx"], >> include_dirs = [numpy.get_include(),'.']) >> ], >> cmdclass = {'build_ext': build_ext}, >> ) >> >> >> Am I passing the wrong flags / setting the wrong variables? Or is >> there some fundamental incompatibility with the 64 bit setup I have? >> >> I can distribute the python & cython code if that helps. >> >> Thanks, >> Adam >> > _______________________________________________ > Cython-dev mailing list > [email protected] > http://codespeak.net/mailman/listinfo/cython-dev _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
