Re: wrapping C functions in python

Discussion in 'Python' started by Paul Anton Letnes, Apr 10, 2008.

  1. Brian and Diez:

    First of all, thanks for the advice.

    Brian:

    I have installed NumPy and SciPy, but I can't seem to find a wavelet
    transform there.

    The main point of this was more to learn C wrapping than to actually
    get a calculation done. I will probably be starting a PhD soon, doing
    really heavy computations. If I want to manipulate data (input /
    results), python is very nice, especially with gnuplot-py. However,
    heavy calculations should probably be done in C(++), especially as
    some code for this already exists.

    I will look into SWIG.


    Diez:

    I will look into it. Do you know a good tutorial for this? I found the
    "standard" tutorial on C extensions, http://www.python.org/doc/ext/intro.html
    , but as I mentioned, it seems to be a bit complicated to wrap heavy
    data structures like arrays.



    Cheers
    PA.
     
    Paul Anton Letnes, Apr 10, 2008
    #1
    1. Advertising

  2. Paul Anton Letnes schrieb:
    > Brian and Diez:
    >
    > First of all, thanks for the advice.
    >
    > Brian:
    >
    > I have installed NumPy and SciPy, but I can't seem to find a wavelet
    > transform there.
    >
    > The main point of this was more to learn C wrapping than to actually get
    > a calculation done. I will probably be starting a PhD soon, doing really
    > heavy computations. If I want to manipulate data (input / results),
    > python is very nice, especially with gnuplot-py. However, heavy
    > calculations should probably be done in C(++), especially as some code
    > for this already exists.
    >
    > I will look into SWIG.
    >
    >
    > Diez:
    >
    > I will look into it. Do you know a good tutorial for this? I found the
    > "standard" tutorial on C extensions,
    > http://www.python.org/doc/ext/intro.html , but as I mentioned, it seems
    > to be a bit complicated to wrap heavy data structures like arrays.


    ctypes is documented as part of the python 2.5 standard lib
    documentation. And google helps as always.

    diez
     
    Diez B. Roggisch, Apr 10, 2008
    #2
    1. Advertising

  3. On Apr 10, 9:57 am, Paul Anton Letnes <>
    wrote:
    [...]
    > , but as I mentioned, it seems to be a bit complicated to wrap heavy
    > data structures like arrays.


    Hello,

    I suggest that you might take a look at how other people solved the
    same problems. The great example is path.c inside PIL [1].
    `PyPath_Flatten` function creates C array from Python data,
    `path_to_list` converts C array into Python list and `path_map`
    applies a Python function to C array.

    Also take a look at Python buffer interface [2] - use array module on
    Python side instead of lists and you'll have almost instant C arrays
    from Python data and vice versa.

    1: http://effbot.org/downloads/Imaging-1.1.6.tar.gz
    2: http://docs.python.org/api/buffer-structs.html

    Regards,

    --
    Ivan
     
    Ivan Illarionov, Apr 10, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Antoon Pardon

    Wrapping functions in modules or packages.

    Antoon Pardon, Jan 24, 2005, in forum: Python
    Replies:
    0
    Views:
    268
    Antoon Pardon
    Jan 24, 2005
  2. Glenn Pierce

    Wrapping c functions

    Glenn Pierce, May 1, 2005, in forum: Python
    Replies:
    2
    Views:
    474
    David M. Cooke
    May 1, 2005
  3. TPJ
    Replies:
    1
    Views:
    301
    Diez B. Roggisch
    Nov 9, 2005
  4. Replies:
    3
    Views:
    262
    Carl Banks
    Dec 17, 2006
  5. Anonymous

    Wrapping C functions in C++

    Anonymous, Sep 28, 2006, in forum: C++
    Replies:
    4
    Views:
    386
    mlimber
    Sep 28, 2006
Loading...

Share This Page