Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #81847 > unrolled thread
| Started by | Michael Kreim <michael@perfect-kreim.de> |
|---|---|
| First post | 2014-12-03 09:29 +0100 |
| Last post | 2014-12-04 09:49 +0100 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
Python, C++ interaction Michael Kreim <michael@perfect-kreim.de> - 2014-12-03 09:29 +0100
Re: Python, C++ interaction Christian Gollwitzer <auriocus@gmx.de> - 2014-12-04 09:49 +0100
| From | Michael Kreim <michael@perfect-kreim.de> |
|---|---|
| Date | 2014-12-03 09:29 +0100 |
| Subject | Python, C++ interaction |
| Message-ID | <mailman.16522.1417595824.18130.python-list@python.org> |
Hi, we are working on a small scientific program that helps us in developing and testing of new numerical methods for a certain type of biochemical problems. I spare you the math ;-) We code our new methods in Python and compare them with the existing methods. Unfortunately, these existing methods are quite slow and need a lot of runtime. Therefor we implemented them in C++. Now, we like to combine these two approaches. So we can develop a new method in Python and compare it easily with the results from the C++ functions. I did some googleing on extending Python by C++ code but I did not find something that satisfies me. I gave SWIG a try, but several webpages disadvised me of using it. Also my small experiments did not work. Now, I read about ctypes. But as far as I understood it, I have to write a C wrapper for my C++ code and then a Python wrapper for my C code. That seems a little complicated. My C++ code is structured as a class that contains several variables and functions. Then everything is compiled as a shared library. I can write things like: MyClass.initialvalue = 5; MyClass.timestep = 0.1; ... MyClass.solve(); I would like to keep this structure in python, but if I understand ctypes correctly I would loose the class approach. So after the long writeup I come to my questions: What are you using to wrap C++ classes for Python? Can you recommend swig? Should I give it another try? Did I misunderstood ctypes? Also later on in our code development we would like to pass python lambda functions to C++. So far I understood that this seems not to be possible. Do you have any ideas or hints on this topics? Thank you very much. Cheers, Michael
[toc] | [next] | [standalone]
| From | Christian Gollwitzer <auriocus@gmx.de> |
|---|---|
| Date | 2014-12-04 09:49 +0100 |
| Message-ID | <m5p753$j77$1@dont-email.me> |
| In reply to | #81847 |
Am 03.12.14 09:29, schrieb Michael Kreim: > I did some googleing on extending Python by C++ code but I did not find > something that satisfies me. I gave SWIG a try, but several webpages > disadvised me of using it. Also my small experiments did not work. I don't know why SWIG is discouraged; in my experience, it is a very easy way to generate the wrapping code around C++ classes, and also flexible in many directions. It can be easily extended for new datatypes (there is a numpy interface module, for instance), and also generates code for other scripting languages as well. What specifically did you try, and what failed? Concerning the callbacks, I don't know about these, but hopefully you are aware that you can easily loose the C++ speed advantage by using Python lambdas, since those have to go through the Python interpreter. Christian
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web