Calling a C function from Python

I’m working on piping together numpy and a gpu accelerated FFT on the raspberry pi.

I’ve never done anything like this.  This is very useful.

The official docs are less useful. Maybe once you already know what’s going on.

This is the basic code needed to make a squaring function callable from python. It’s in a file square.c. You need that initsquare function which is called when you import. You need to list your available functions in that SquareMethods thing. And you need to extract and rebuild python style formats using the built in macros.

put this in

Next, I gotta figure out how to get arrays

These actually are pretty useful


Here is some basic garbage mostly copied from those advanced scipy notes above. I cut out out the iterator stuff. That is probably the way you’d usually want to do things. However, ultimately, I’ll be able to handoff the input and output array pointer to gpu_fft. I think it is in the right format.

The way I’m currently structuring things I’m probably not going to hold your hand. Unless I withhold access to the raw C file from an intermediate python library module?

But not today. Maybe tomorrow.


Leave a Reply

Your email address will not be published. Required fields are marked *