python

SWIG vs ctypes

When I started work on pylibsvm, I had to wrap the libsvm library (C and C++ code with a pure-C interface) to call certain libsvm functions from Python and to interoperate with NumPy. After wasting a week on trying to wrap it with SWIG and raw Python/C (yikes!) and not being near done, I compiled the library as a standalone DLL and was up and running with ctypes in a matter of hours.

The power of ctypes lies in the fact that it allows you to write your wrapping code in Python. As an added bonus, you can build your C code as a library that doesn't depend on Python, which means that you can build a debug DLL on Windows without having to use a debug build of Python (remembering to take into account all the cross-runtime memory allocation issues, etc.).

I had to do a few tricks to get NumPy and ctypes to play nicely together and there are still a few issues I need to sort out here, but this doesn't come close to the kind of stuff you need to do when wrapping with SWIG.

You probably can't use ctypes to wrap everything that you can wrap with SWIG or Boost.Python (huge C++ libraries come to mind), but if I have the option, I'd go with ctypes any day. It might be possible to build a light C wrapper around your C++ code, which is basically what happens in libsvm.

If you want to play with ctypes, yum install python-ctypes on Fedora Core 4 and 5 should do the trick. A Windows installer is available from the ctypes site. To sweeten the deal even further, ctypes will be included in Python 2.5.

fullung – Sat, 2006 – 05 – 27 23:17

Status Report

I spent Friday working on a super-duper top secret ultra-spiffy project related to NumPy with Stefan van der Walt (hopefully we'll have something very cool to show for it in a week or two). On the pylibsvm front, I've been doing some more research into SVM regression. I've added some details on the libsvm internals and heap fragmentation issues to the overview page.

fullung – Sat, 2006 – 05 – 27 22:57

[Subversion Python bindings] First patch

Walter Mundt, checking in. I'm the student working on the Python bindings for Subversion.

I decided to put off my first post until I at least had some results. Now I do -- the first patch to come out of my SoC is on the Subversion mailing list. It's pretty bare bones, but it does do the job. Now Python can set a couple of callbacks it was previously unable to.

Next up, if the project takes the current patch, is to start the real work: wrapping the SWIG-generated Python interface into something a little (okay maybe a lot) more friendly to pure Python programmers. I'm looking forward

WalterMundt – Sat, 2006 – 05 – 27 21:11

PropDict in JavaScript

Metadata in XMMS2 is returned to users in a custom data type we call a PropDict.
XMMS2's MediaLib supports writing data arbitarily to the Media Library, but for any
data written to the medialib one must set a source. So to make this source data
avaliable XMMS2 has the PropDict. A PropDict in Python is something like:


{('source', 'key'):'value'}

This is perfectly valid for a Python datatype, but can not be serialized to JSON.
Since most of the magic for TurboX2 is done in JavaScript we can't make use
of a standard PropDict serialized to JSON, so we reformat it. The reformatting

alexbl – Fri, 2006 – 05 – 26 00:07

Hello, World

My name is Albert Strasheim and I'll be working on adding Support Vector Machines to SciPy this summer (actually, winter here in South Africa).

I'm pretty new to the field of SVMs, but I've been using them for speaker verification for about 6 months. I recently took part in the NIST Speaker Recognition Evaluation during which I started development of the code that will be added to SciPy.

fullung – Thu, 2006 – 05 – 25 21:26
Syndicate content