Build external C functions that take numpy arrays as parameters and return numpy arrays
![](https://secure.gravatar.com/avatar/11bc81e43c7f85543e5245030195455d.jpg?s=120&d=mm&r=g)
Hi Everyone, I am going to write some external C functions that takes in numpy arrays as parameters and return numpy arrays. I have the following questions: 1. What should I do in my C code? 2. Can I use any C compiler to build my library that takes numpy arrays? I am using Windows XP and Visual Studio 2005. 3. How can I generate the python binding? Thanks, cg
![](https://secure.gravatar.com/avatar/60e03bd1fd9f2dbc750e0899b9e7e71d.jpg?s=120&d=mm&r=g)
Hi, The simplest way of doing this is with ctypes : http://scipy.org/Cookbook/Ctypes Matthieu 2007/7/24, computer_guy <zyzhu2000@gmail.com>:
Hi Everyone,
I am going to write some external C functions that takes in numpy arrays as parameters and return numpy arrays. I have the following questions:
1. What should I do in my C code? 2. Can I use any C compiler to build my library that takes numpy arrays? I am using Windows XP and Visual Studio 2005. 3. How can I generate the python binding?
Thanks, cg
_______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
![](https://secure.gravatar.com/avatar/6194b135cba546afa82516de1537de49.jpg?s=120&d=mm&r=g)
Note also that there was essentially the very same question on this list just a few days ago. At the time, there were many answers and quite a discussion... Hope you can find the list archive at scipy.org. -Sebastian On 7/29/07, Matthieu Brucher <matthieu.brucher@gmail.com> wrote:
Hi,
The simplest way of doing this is with ctypes : http://scipy.org/Cookbook/Ctypes
Matthieu
2007/7/24, computer_guy < zyzhu2000@gmail.com>:
Hi Everyone,
I am going to write some external C functions that takes in numpy arrays as parameters and return numpy arrays. I have the following questions:
1. What should I do in my C code? 2. Can I use any C compiler to build my library that takes numpy arrays? I am using Windows XP and Visual Studio 2005. 3. How can I generate the python binding?
Thanks, cg
_______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
![](https://secure.gravatar.com/avatar/764323a14e554c97ab74177e0bce51d4.jpg?s=120&d=mm&r=g)
Sebastian Haase wrote:
Note also that there was essentially the very same question on this list just a few days ago. At the time, there were many answers and quite a discussion...
The OP is the same in both. We just got a burst of emails (including the one that starts this thread) that had been delayed for some reason. So it's no surprise, and no one's fault, that there's some duplication here. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
![](https://secure.gravatar.com/avatar/6194b135cba546afa82516de1537de49.jpg?s=120&d=mm&r=g)
On 7/29/07, Robert Kern <robert.kern@gmail.com> wrote:
Sebastian Haase wrote:
Note also that there was essentially the very same question on this list just a few days ago. At the time, there were many answers and quite a discussion...
The OP is the same in both. We just got a burst of emails (including the one that starts this thread) that had been delayed for some reason. So it's no surprise, and no one's fault, that there's some duplication here.
Oooh - I see - there is the date: July 24 ... [ another email just came in is from 7/18 ...] That's quite interesting. I have never seen such a delay before .... Was some computer sitting on them being turnted off for 10 days ? ;-) -Sebastian.
![](https://secure.gravatar.com/avatar/11bc81e43c7f85543e5245030195455d.jpg?s=120&d=mm&r=g)
Hi Sebastian,
Oooh - I see - there is the date: July 24 ... [ another email just came in is from 7/18 ...] That's quite interesting. I have never seen such a delay before .... Was some computer sitting on them being turnted off for 10 days ? ;-)
-Sebastian.
Not knowing that the mailing list and the google group "Numpy Discussion" are one and the same, originally I posted this question through Google Groups. Until now it never showed up in the group. I thought it was lost and made another post to the mailing list. In fact with the help of people on this mailing list and some trial and error, I have already built an extended moudle that does exactly that. Thanks for your help. Geoffrey
![](https://secure.gravatar.com/avatar/4b748d7edc52453d8470f5307b52db07.jpg?s=120&d=mm&r=g)
I wrote a basic article on C extensions using NumPy arrays on the SciPy.org site. See: Cookbook/C_Extensions/NumPy at http://www.scipy.org/Cookbook/C_Extensions/NumPy_arrays?highlight=%28%28----... It's very basic, but should get you started. Note that once you get the patterns down for NumPy then other extensions are mostly the same pattern over and over. -- Lou Pecora -------------------------------------------------
2007/7/24, computer_guy < zyzhu2000@gmail.com>:
Hi Everyone,
I am going to write some external C functions that takes in numpy arrays as parameters and return numpy arrays. I have the following questions:
1. What should I do in my C code? 2. Can I use any C compiler to build my library that takes numpy arrays? I am using Windows XP and Visual Studio
3. How can I generate the python binding?
Thanks, cg
-- Lou Pecora, my views are my own. --------------- Great spirits have always encountered violent opposition from mediocre minds. -Albert Einstein ____________________________________________________________________________________ Got a little couch potato? Check out fun summer activities for kids. http://search.yahoo.com/search?fr=oni_on_mail&p=summer+activities+for+kids&cs=bz
![](https://secure.gravatar.com/avatar/11bc81e43c7f85543e5245030195455d.jpg?s=120&d=mm&r=g)
On 7/29/07, Lou Pecora <lou_boog2000@yahoo.com> wrote:
I wrote a basic article on C extensions using NumPy arrays on the SciPy.org site. See: Cookbook/C_Extensions/NumPy at
http://www.scipy.org/Cookbook/C_Extensions/NumPy_arrays?highlight=%28%28----...
It's very basic, but should get you started. Note that once you get the patterns down for NumPy then other extensions are mostly the same pattern over and over.
-- Lou Pecora
That was the 'template' I was using.
participants (6)
-
computer_guy
-
Geoffrey Zhu
-
Lou Pecora
-
Matthieu Brucher
-
Robert Kern
-
Sebastian Haase