SlideShare ist ein Scribd-Unternehmen logo
1 von 32
Downloaden Sie, um offline zu lesen
Python Extending/Integrating A Real World Example Tips Summary

  Python where we can,
   C++ where we must




                                                                   Source: http://xkcd.com/353/
Guy K. Kloss — Thinking Hybrid – Python/C++ Integration                                           1/25
Python Extending/Integrating A Real World Example Tips Summary




                             Thinking Hybrid –
                          Python/C++ Integration
                 (Python where we can, C++ where we must∗ )


                                            Guy K. Kloss


                      New Zealand Python User Group Meeting
                            Auckland, 30 January 2008

                  ∗   Quote: Alex Martelli, Senior Google Developer
Guy K. Kloss — Thinking Hybrid – Python/C++ Integration               2/25
Python Extending/Integrating A Real World Example Tips Summary

  Outline



     1 Python

     2 Extending/Integrating

     3 A Real World Example

     4 Tips




Guy K. Kloss — Thinking Hybrid – Python/C++ Integration            3/25
Python Extending/Integrating A Real World Example Tips Summary

  Outline



     1 Python

     2 Extending/Integrating

     3 A Real World Example

     4 Tips




Guy K. Kloss — Thinking Hybrid – Python/C++ Integration            4/25
Python Extending/Integrating A Real World Example Tips Summary

  Why Python?

     We all know why . . .
     Some reasons that are important for us:
         Dynamic
         High-level data types
         Embeddable/Mixable
                     Extend Python with components
                     written in C++, Java, C
                     Embed Python into your application
                     and call it from C/C++
                     Platform independent
             50 % less code, 300 % more productive
             Automatic memory management
             All those utilities, modules, . . .
             Many, many more reasons . . .
Guy K. Kloss — Thinking Hybrid – Python/C++ Integration            5/25
Python Extending/Integrating A Real World Example Tips Summary

  Why Python?




     Source: http://xkcd.com/371/




Guy K. Kloss — Thinking Hybrid – Python/C++ Integration            6/25
Python Extending/Integrating A Real World Example Tips Summary

  Outline



     1 Python

     2 Extending/Integrating

     3 A Real World Example

     4 Tips




Guy K. Kloss — Thinking Hybrid – Python/C++ Integration            7/25
Python Extending/Integrating A Real World Example Tips Summary

  What if I could . . .



     Use this code more effectively . . . ?




     [NaSt2D demonstration (native executable)]




Guy K. Kloss — Thinking Hybrid – Python/C++ Integration            8/25
Python Extending/Integrating A Real World Example Tips Summary

  Extending/Integration

     The Contestants:
             The “classic way” . . .
             Extending and Embedding the Python Interpreter
             The “new way” . . .
             Python ctypes
             SWIG
             Boost.Python
             Others:
                     SIP
                     Pythonizer
                     SILOON
                     (Pyrex)
             Extensions also for Java, C#, Fortran, . . . available
Guy K. Kloss — Thinking Hybrid – Python/C++ Integration               9/25
Python Extending/Integrating A Real World Example Tips Summary

  Extending/Integration

     The Contestants:
             The “classic way” . . .
             Extending and Embedding the Python Interpreter
             The “new way” . . .
             Python ctypes
             SWIG
             Boost.Python
             Others:
                     SIP
                     Pythonizer
                     SILOON
                     (Pyrex)
             Extensions also for Java, C#, Fortran, . . . available
Guy K. Kloss — Thinking Hybrid – Python/C++ Integration               9/25
Python Extending/Integrating A Real World Example Tips Summary

  Extending/Integration

     The Contestants:
             The “classic way” . . .
             Extending and Embedding the Python Interpreter
             The “new way” . . .
             Python ctypes
             SWIG
             Boost.Python
             Others:
                     SIP
                     Pythonizer
                     SILOON
                     (Pyrex)
             Extensions also for Java, C#, Fortran, . . . available
Guy K. Kloss — Thinking Hybrid – Python/C++ Integration               9/25
Python Extending/Integrating A Real World Example Tips Summary

  Extending/Integration

     The Contestants:
             The “classic way” . . .
             Extending and Embedding the Python Interpreter
             The “new way” . . .
             Python ctypes
             SWIG
             Boost.Python
             Others:
                     SIP
                     Pythonizer
                     SILOON
                     (Pyrex)
             Extensions also for Java, C#, Fortran, . . . available
Guy K. Kloss — Thinking Hybrid – Python/C++ Integration               9/25
Python Extending/Integrating A Real World Example Tips Summary

  Extending/Integration

     The Contestants:
             The “classic way” . . .
             Extending and Embedding the Python Interpreter
             The “new way” . . .
             Python ctypes
             SWIG
             Boost.Python
             Others:
                     SIP
                     Pythonizer
                     SILOON
                     (Pyrex)
             Extensions also for Java, C#, Fortran, . . . available
Guy K. Kloss — Thinking Hybrid – Python/C++ Integration               9/25
Python Extending/Integrating A Real World Example Tips Summary

  Boost.Python


     Thinking Hybrid with Boost.Python
             Bottom up and . . .
             Top down possible
             Develop quickly
             Resolve bottle necks
             Donald Knuth’s:
             “Premature optimisation is the root of all evil.”
             or: Don’t Optimise Now!




Guy K. Kloss — Thinking Hybrid – Python/C++ Integration            10/25
Python Extending/Integrating A Real World Example Tips Summary

  Boost.Python


     Thinking Hybrid with Boost.Python
             Bottom up and . . .
             Top down possible
             Develop quickly
             Resolve bottle necks
             Donald Knuth’s:
             “Premature optimisation is the root of all evil.”
             or: Don’t Optimise Now!




Guy K. Kloss — Thinking Hybrid – Python/C++ Integration            10/25
Python Extending/Integrating A Real World Example Tips Summary

  Boost.Python


     Thinking Hybrid with Boost.Python
             Bottom up and . . .
             Top down possible
             Develop quickly
             Resolve bottle necks
             Donald Knuth’s:
             “Premature optimisation is the root of all evil.”
             or: Don’t Optimise Now!




Guy K. Kloss — Thinking Hybrid – Python/C++ Integration            10/25
Python Extending/Integrating A Real World Example Tips Summary

  Hello World
     char const* greet(unsigned x) {
         static char const* const msgs[] = {quot;helloquot;, quot;Boost.Pythonquot;,
     quot;world!quot;};
         if (x > 2) {
              throw std::range error(quot;greet: Index out of range.quot;);
         }
         return msgs[x];
     }

     #include <boost/python.hpp>
     using namespace boost::python;
     BOOST PYTHON MODULE(hello)
     {
          .def(quot;greetquot;, greet, quot;return one of 3 parts of a greetingquot;);
     }

     And here it is in action:
     >>> import hello
     >>> for x in range (3):
     ...       print hello . greet ( x )
     ...
     hello
     Boost . Python
     world !
Guy K. Kloss — Thinking Hybrid – Python/C++ Integration                  11/25
Python Extending/Integrating A Real World Example Tips Summary

  Boost.Python




             One of a few libraries that make it easy
             to integrate C++ and Python code
             How does it pull off this trick?
             Template meta–programming
             (i. e. Don’t ask!)




Guy K. Kloss — Thinking Hybrid – Python/C++ Integration            12/25
Python Extending/Integrating A Real World Example Tips Summary

  Boost.Python




             One of a few libraries that make it easy
             to integrate C++ and Python code
             How does it pull off this trick?
             Template meta–programming
             (i. e. Don’t ask!)




Guy K. Kloss — Thinking Hybrid – Python/C++ Integration            12/25
Python Extending/Integrating A Real World Example Tips Summary

  See it Happen



     I’m making it work for you now . . .




     [“MyClass” demonstration (MyClass.cpp, MyClass.h, mymodule.cpp)]




Guy K. Kloss — Thinking Hybrid – Python/C++ Integration                 13/25
Python Extending/Integrating A Real World Example Tips Summary

  Outline



     1 Python

     2 Extending/Integrating

     3 A Real World Example

     4 Tips




Guy K. Kloss — Thinking Hybrid – Python/C++ Integration            14/25
Python Extending/Integrating A Real World Example Tips Summary

  A Real World Example
  Re-visiting NaSt2D




     Wrapping NaSt2D
             Control the code




Guy K. Kloss — Thinking Hybrid – Python/C++ Integration            15/25
Python Extending/Integrating A Real World Example Tips Summary

  NaSt2D in Python


     This is what I’m going to show you:
             Code to be wrapped
             Generated wrapper code
             Generator script
             SCons (build system)
             How it works with Python
     [Wrapped NaSt2D demonstration (Wrapper.h, nast2dmodule.cpp,
     generate bindings.py, SConstruct, demo0.py)]




Guy K. Kloss — Thinking Hybrid – Python/C++ Integration            16/25
Python Extending/Integrating A Real World Example Tips Summary

  Extend Wrapper Class




     Inheriting from C++ classes
             Interfacing numerical values
             Change functionality
             Follow the Computation




Guy K. Kloss — Thinking Hybrid – Python/C++ Integration            17/25
Python Extending/Integrating A Real World Example Tips Summary

  Overriding in Python



     This is what I’m going to show you:
             Overriding a native method in Python
             Native method needs to be “virtual”
             Live data plotting with GNUplot
     [NaSt2D with plotting demonstration (demo1.py, demo2.py)]




Guy K. Kloss — Thinking Hybrid – Python/C++ Integration            18/25
Python Extending/Integrating A Real World Example Tips Summary

  Do more Computations




     Parameter Study
             Change input file
             Compute several cases
             Plot results automatically




Guy K. Kloss — Thinking Hybrid – Python/C++ Integration            19/25
Python Extending/Integrating A Real World Example Tips Summary

  Automating in Python



     This is what I’m going to show you:
             Using a template input file
             Batch–calculating several runs
             Plotting results with GNUplot
     [NaSt2D with parameter variation demonstration (demo3.py, demo4.py)]




Guy K. Kloss — Thinking Hybrid – Python/C++ Integration                     20/25
Python Extending/Integrating A Real World Example Tips Summary

  Outline



     1 Python

     2 Extending/Integrating

     3 A Real World Example

     4 Tips




Guy K. Kloss — Thinking Hybrid – Python/C++ Integration            21/25
Python Extending/Integrating A Real World Example Tips Summary

  Tips


             To override C++ methods: make them virtual
             C/C++ pit fall
                     Call by reference/value
                     Solution: calling policies
             Map to “other/sane” languages
                     Java: Jython
                     C#: IronPython
                     Fortran: PyFort, Py2F
                     (Native to other: SWIG)




Guy K. Kloss — Thinking Hybrid – Python/C++ Integration            22/25
Python Extending/Integrating A Real World Example Tips Summary

  Summary



             Why is Python good for you?
             How can performance bottle necks be resolved?
             Advantages of “Thinking Hybrid”
             Python–native wrapping using Boost.Python
             Automated wrapper generation
             SCons build system




Guy K. Kloss — Thinking Hybrid – Python/C++ Integration            23/25
Python Extending/Integrating A Real World Example Tips Summary

  Python and the “Need for Speed”




     Cuong Do – Software Architect YouTube.com
                 “Python is fast enough for our site
           and allows us to produce maintainable features
                           in record times,
                   with a minimum of developers.”




Guy K. Kloss — Thinking Hybrid – Python/C++ Integration            24/25
Python Extending/Integrating A Real World Example Tips Summary




     Questions?


     G.Kloss@massey.ac.nz
     Slides and code available here:
     http://www.kloss-familie.de/moin/TalksPresentations
Guy K. Kloss — Thinking Hybrid – Python/C++ Integration            25/25

Weitere ähnliche Inhalte

Ähnlich wie Thinking Hybrid - Python/C++ Integration

PyCon2022 - Building Python Extensions
PyCon2022 - Building Python ExtensionsPyCon2022 - Building Python Extensions
PyCon2022 - Building Python ExtensionsHenry Schreiner
 
Writing a Python C extension
Writing a Python C extensionWriting a Python C extension
Writing a Python C extensionSqreen
 
Python for Application Integration and Development
Python for Application Integration and DevelopmentPython for Application Integration and Development
Python for Application Integration and DevelopmentTsungWei Hu
 
orlando-codecamp-meet-copilot-24-Feb-2024_pub.pptx
orlando-codecamp-meet-copilot-24-Feb-2024_pub.pptxorlando-codecamp-meet-copilot-24-Feb-2024_pub.pptx
orlando-codecamp-meet-copilot-24-Feb-2024_pub.pptxBill Wilder
 
Pycon Australia 2015: Docker + Python
Pycon Australia 2015: Docker + PythonPycon Australia 2015: Docker + Python
Pycon Australia 2015: Docker + PythonTim Butler
 
osakapy 2014.10 LT (CI for Python Project)
osakapy 2014.10 LT (CI for Python Project)osakapy 2014.10 LT (CI for Python Project)
osakapy 2014.10 LT (CI for Python Project)Hattori Hideo
 
Micropython for the iot
Micropython for the iotMicropython for the iot
Micropython for the iotJacques Supcik
 
Pythonic doesn't mean slow!
Pythonic doesn't mean slow!Pythonic doesn't mean slow!
Pythonic doesn't mean slow!Ronan Lamy
 
Python_final_print_batch_II_vision_academy.pdf
Python_final_print_batch_II_vision_academy.pdfPython_final_print_batch_II_vision_academy.pdf
Python_final_print_batch_II_vision_academy.pdfbhagyashri686896
 
Python_final_print_batch_II_vision_academy (1).pdf
Python_final_print_batch_II_vision_academy (1).pdfPython_final_print_batch_II_vision_academy (1).pdf
Python_final_print_batch_II_vision_academy (1).pdfrupaliakhute
 
Python_final_print_batch_II_vision_academy.pdf
Python_final_print_batch_II_vision_academy.pdfPython_final_print_batch_II_vision_academy.pdf
Python_final_print_batch_II_vision_academy.pdfsannykhopade
 
Python_vision_academy notes
Python_vision_academy notes Python_vision_academy notes
Python_vision_academy notes rajaniraut
 
Kyrylo Cherneha "C++ & Python Interaction in Automotive Industry"
Kyrylo Cherneha "C++ & Python Interaction in Automotive Industry"Kyrylo Cherneha "C++ & Python Interaction in Automotive Industry"
Kyrylo Cherneha "C++ & Python Interaction in Automotive Industry"LogeekNightUkraine
 
Building Data Pipelines in Python
Building Data Pipelines in PythonBuilding Data Pipelines in Python
Building Data Pipelines in PythonC4Media
 
Why "Hello World" is a Massive Operation - From Python code to Stack Virtual ...
Why "Hello World" is a Massive Operation - From Python code to Stack Virtual ...Why "Hello World" is a Massive Operation - From Python code to Stack Virtual ...
Why "Hello World" is a Massive Operation - From Python code to Stack Virtual ...Richard Rowland
 

Ähnlich wie Thinking Hybrid - Python/C++ Integration (20)

PyCon2022 - Building Python Extensions
PyCon2022 - Building Python ExtensionsPyCon2022 - Building Python Extensions
PyCon2022 - Building Python Extensions
 
05 python.pdf
05 python.pdf05 python.pdf
05 python.pdf
 
Writing a Python C extension
Writing a Python C extensionWriting a Python C extension
Writing a Python C extension
 
Doing the Impossible
Doing the ImpossibleDoing the Impossible
Doing the Impossible
 
Python for Application Integration and Development
Python for Application Integration and DevelopmentPython for Application Integration and Development
Python for Application Integration and Development
 
orlando-codecamp-meet-copilot-24-Feb-2024_pub.pptx
orlando-codecamp-meet-copilot-24-Feb-2024_pub.pptxorlando-codecamp-meet-copilot-24-Feb-2024_pub.pptx
orlando-codecamp-meet-copilot-24-Feb-2024_pub.pptx
 
Pycon Australia 2015: Docker + Python
Pycon Australia 2015: Docker + PythonPycon Australia 2015: Docker + Python
Pycon Australia 2015: Docker + Python
 
PyPy London Demo Evening 2013
PyPy London Demo Evening 2013PyPy London Demo Evening 2013
PyPy London Demo Evening 2013
 
osakapy 2014.10 LT (CI for Python Project)
osakapy 2014.10 LT (CI for Python Project)osakapy 2014.10 LT (CI for Python Project)
osakapy 2014.10 LT (CI for Python Project)
 
Micropython for the iot
Micropython for the iotMicropython for the iot
Micropython for the iot
 
Pythonic doesn't mean slow!
Pythonic doesn't mean slow!Pythonic doesn't mean slow!
Pythonic doesn't mean slow!
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Python_final_print_batch_II_vision_academy.pdf
Python_final_print_batch_II_vision_academy.pdfPython_final_print_batch_II_vision_academy.pdf
Python_final_print_batch_II_vision_academy.pdf
 
Python_final_print_batch_II_vision_academy (1).pdf
Python_final_print_batch_II_vision_academy (1).pdfPython_final_print_batch_II_vision_academy (1).pdf
Python_final_print_batch_II_vision_academy (1).pdf
 
Python_final_print_batch_II_vision_academy.pdf
Python_final_print_batch_II_vision_academy.pdfPython_final_print_batch_II_vision_academy.pdf
Python_final_print_batch_II_vision_academy.pdf
 
Python_vision_academy notes
Python_vision_academy notes Python_vision_academy notes
Python_vision_academy notes
 
Kyrylo Cherneha "C++ & Python Interaction in Automotive Industry"
Kyrylo Cherneha "C++ & Python Interaction in Automotive Industry"Kyrylo Cherneha "C++ & Python Interaction in Automotive Industry"
Kyrylo Cherneha "C++ & Python Interaction in Automotive Industry"
 
Building Data Pipelines in Python
Building Data Pipelines in PythonBuilding Data Pipelines in Python
Building Data Pipelines in Python
 
Cython compiler
Cython compilerCython compiler
Cython compiler
 
Why "Hello World" is a Massive Operation - From Python code to Stack Virtual ...
Why "Hello World" is a Massive Operation - From Python code to Stack Virtual ...Why "Hello World" is a Massive Operation - From Python code to Stack Virtual ...
Why "Hello World" is a Massive Operation - From Python code to Stack Virtual ...
 

Mehr von Guy K. Kloss

Kauri ID - A Self-Sovereign, Blockchain-based Identity System
Kauri ID - A Self-Sovereign, Blockchain-based Identity SystemKauri ID - A Self-Sovereign, Blockchain-based Identity System
Kauri ID - A Self-Sovereign, Blockchain-based Identity SystemGuy K. Kloss
 
Qrious about Insights -- Big Data in the Real World
Qrious about Insights -- Big Data in the Real WorldQrious about Insights -- Big Data in the Real World
Qrious about Insights -- Big Data in the Real WorldGuy K. Kloss
 
WTF is Blockchain???
WTF is Blockchain???WTF is Blockchain???
WTF is Blockchain???Guy K. Kloss
 
Building a (Really) Secure Cloud Product
Building a (Really) Secure Cloud ProductBuilding a (Really) Secure Cloud Product
Building a (Really) Secure Cloud ProductGuy K. Kloss
 
Representational State Transfer (REST) and HATEOAS
Representational State Transfer (REST) and HATEOASRepresentational State Transfer (REST) and HATEOAS
Representational State Transfer (REST) and HATEOASGuy K. Kloss
 
Introduction to LaTeX (For Word users)
 Introduction to LaTeX (For Word users) Introduction to LaTeX (For Word users)
Introduction to LaTeX (For Word users)Guy K. Kloss
 
MataNui - Building a Grid Data Infrastructure that "doesn't suck!"
MataNui - Building a Grid Data Infrastructure that "doesn't suck!"MataNui - Building a Grid Data Infrastructure that "doesn't suck!"
MataNui - Building a Grid Data Infrastructure that "doesn't suck!"Guy K. Kloss
 
Operations Research and Optimization in Python using PuLP
Operations Research and Optimization in Python using PuLPOperations Research and Optimization in Python using PuLP
Operations Research and Optimization in Python using PuLPGuy K. Kloss
 
Python Data Plotting and Visualisation Extravaganza
Python Data Plotting and Visualisation ExtravaganzaPython Data Plotting and Visualisation Extravaganza
Python Data Plotting and Visualisation ExtravaganzaGuy K. Kloss
 
Lecture "Open Source and Open Content"
Lecture "Open Source and Open Content"Lecture "Open Source and Open Content"
Lecture "Open Source and Open Content"Guy K. Kloss
 
Version Control with Subversion
Version Control with SubversionVersion Control with Subversion
Version Control with SubversionGuy K. Kloss
 
Beating the (sh** out of the) GIL - Multithreading vs. Multiprocessing
Beating the (sh** out of the) GIL - Multithreading vs. MultiprocessingBeating the (sh** out of the) GIL - Multithreading vs. Multiprocessing
Beating the (sh** out of the) GIL - Multithreading vs. MultiprocessingGuy K. Kloss
 
Gaining Colour Stability in Live Image Capturing
Gaining Colour Stability in Live Image CapturingGaining Colour Stability in Live Image Capturing
Gaining Colour Stability in Live Image CapturingGuy K. Kloss
 
LaTeX Introduction for Word Users
LaTeX Introduction for Word UsersLaTeX Introduction for Word Users
LaTeX Introduction for Word UsersGuy K. Kloss
 

Mehr von Guy K. Kloss (14)

Kauri ID - A Self-Sovereign, Blockchain-based Identity System
Kauri ID - A Self-Sovereign, Blockchain-based Identity SystemKauri ID - A Self-Sovereign, Blockchain-based Identity System
Kauri ID - A Self-Sovereign, Blockchain-based Identity System
 
Qrious about Insights -- Big Data in the Real World
Qrious about Insights -- Big Data in the Real WorldQrious about Insights -- Big Data in the Real World
Qrious about Insights -- Big Data in the Real World
 
WTF is Blockchain???
WTF is Blockchain???WTF is Blockchain???
WTF is Blockchain???
 
Building a (Really) Secure Cloud Product
Building a (Really) Secure Cloud ProductBuilding a (Really) Secure Cloud Product
Building a (Really) Secure Cloud Product
 
Representational State Transfer (REST) and HATEOAS
Representational State Transfer (REST) and HATEOASRepresentational State Transfer (REST) and HATEOAS
Representational State Transfer (REST) and HATEOAS
 
Introduction to LaTeX (For Word users)
 Introduction to LaTeX (For Word users) Introduction to LaTeX (For Word users)
Introduction to LaTeX (For Word users)
 
MataNui - Building a Grid Data Infrastructure that "doesn't suck!"
MataNui - Building a Grid Data Infrastructure that "doesn't suck!"MataNui - Building a Grid Data Infrastructure that "doesn't suck!"
MataNui - Building a Grid Data Infrastructure that "doesn't suck!"
 
Operations Research and Optimization in Python using PuLP
Operations Research and Optimization in Python using PuLPOperations Research and Optimization in Python using PuLP
Operations Research and Optimization in Python using PuLP
 
Python Data Plotting and Visualisation Extravaganza
Python Data Plotting and Visualisation ExtravaganzaPython Data Plotting and Visualisation Extravaganza
Python Data Plotting and Visualisation Extravaganza
 
Lecture "Open Source and Open Content"
Lecture "Open Source and Open Content"Lecture "Open Source and Open Content"
Lecture "Open Source and Open Content"
 
Version Control with Subversion
Version Control with SubversionVersion Control with Subversion
Version Control with Subversion
 
Beating the (sh** out of the) GIL - Multithreading vs. Multiprocessing
Beating the (sh** out of the) GIL - Multithreading vs. MultiprocessingBeating the (sh** out of the) GIL - Multithreading vs. Multiprocessing
Beating the (sh** out of the) GIL - Multithreading vs. Multiprocessing
 
Gaining Colour Stability in Live Image Capturing
Gaining Colour Stability in Live Image CapturingGaining Colour Stability in Live Image Capturing
Gaining Colour Stability in Live Image Capturing
 
LaTeX Introduction for Word Users
LaTeX Introduction for Word UsersLaTeX Introduction for Word Users
LaTeX Introduction for Word Users
 

Kürzlich hochgeladen

CBD Belapur Expensive Housewife Call Girls Number-📞📞9833754194 No 1 Vipp HIgh...
CBD Belapur Expensive Housewife Call Girls Number-📞📞9833754194 No 1 Vipp HIgh...CBD Belapur Expensive Housewife Call Girls Number-📞📞9833754194 No 1 Vipp HIgh...
CBD Belapur Expensive Housewife Call Girls Number-📞📞9833754194 No 1 Vipp HIgh...priyasharma62062
 
Call Girls Koregaon Park Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Koregaon Park Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Koregaon Park Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Koregaon Park Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Kharghar Blowjob Housewife Call Girls NUmber-9833754194-CBD Belapur Internati...
Kharghar Blowjob Housewife Call Girls NUmber-9833754194-CBD Belapur Internati...Kharghar Blowjob Housewife Call Girls NUmber-9833754194-CBD Belapur Internati...
Kharghar Blowjob Housewife Call Girls NUmber-9833754194-CBD Belapur Internati...priyasharma62062
 
Mira Road Awesome 100% Independent Call Girls NUmber-9833754194-Dahisar Inter...
Mira Road Awesome 100% Independent Call Girls NUmber-9833754194-Dahisar Inter...Mira Road Awesome 100% Independent Call Girls NUmber-9833754194-Dahisar Inter...
Mira Road Awesome 100% Independent Call Girls NUmber-9833754194-Dahisar Inter...priyasharma62062
 
Vasai-Virar Fantastic Call Girls-9833754194-Call Girls MUmbai
Vasai-Virar Fantastic Call Girls-9833754194-Call Girls MUmbaiVasai-Virar Fantastic Call Girls-9833754194-Call Girls MUmbai
Vasai-Virar Fantastic Call Girls-9833754194-Call Girls MUmbaipriyasharma62062
 
Business Principles, Tools, and Techniques in Participating in Various Types...
Business Principles, Tools, and Techniques  in Participating in Various Types...Business Principles, Tools, and Techniques  in Participating in Various Types...
Business Principles, Tools, and Techniques in Participating in Various Types...jeffreytingson
 
Call Girls Banaswadi Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Banaswadi Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Banaswadi Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Banaswadi Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...amitlee9823
 
Cybersecurity Threats in Financial Services Protection.pptx
Cybersecurity Threats in  Financial Services Protection.pptxCybersecurity Threats in  Financial Services Protection.pptx
Cybersecurity Threats in Financial Services Protection.pptxLumiverse Solutions Pvt Ltd
 
VIP Call Girl Service Andheri West ⚡ 9920725232 What It Takes To Be The Best ...
VIP Call Girl Service Andheri West ⚡ 9920725232 What It Takes To Be The Best ...VIP Call Girl Service Andheri West ⚡ 9920725232 What It Takes To Be The Best ...
VIP Call Girl Service Andheri West ⚡ 9920725232 What It Takes To Be The Best ...dipikadinghjn ( Why You Choose Us? ) Escorts
 
( Jasmin ) Top VIP Escorts Service Dindigul 💧 7737669865 💧 by Dindigul Call G...
( Jasmin ) Top VIP Escorts Service Dindigul 💧 7737669865 💧 by Dindigul Call G...( Jasmin ) Top VIP Escorts Service Dindigul 💧 7737669865 💧 by Dindigul Call G...
( Jasmin ) Top VIP Escorts Service Dindigul 💧 7737669865 💧 by Dindigul Call G...dipikadinghjn ( Why You Choose Us? ) Escorts
 
Navi Mumbai Cooperetive Housewife Call Girls-9833754194-Natural Panvel Enjoye...
Navi Mumbai Cooperetive Housewife Call Girls-9833754194-Natural Panvel Enjoye...Navi Mumbai Cooperetive Housewife Call Girls-9833754194-Natural Panvel Enjoye...
Navi Mumbai Cooperetive Housewife Call Girls-9833754194-Natural Panvel Enjoye...priyasharma62062
 
Q1 2024 Conference Call Presentation vF.pdf
Q1 2024 Conference Call Presentation vF.pdfQ1 2024 Conference Call Presentation vF.pdf
Q1 2024 Conference Call Presentation vF.pdfAdnet Communications
 
7 tips trading Deriv Accumulator Options
7 tips trading Deriv Accumulator Options7 tips trading Deriv Accumulator Options
7 tips trading Deriv Accumulator OptionsVince Stanzione
 
VIP Independent Call Girls in Mumbai 🌹 9920725232 ( Call Me ) Mumbai Escorts ...
VIP Independent Call Girls in Mumbai 🌹 9920725232 ( Call Me ) Mumbai Escorts ...VIP Independent Call Girls in Mumbai 🌹 9920725232 ( Call Me ) Mumbai Escorts ...
VIP Independent Call Girls in Mumbai 🌹 9920725232 ( Call Me ) Mumbai Escorts ...dipikadinghjn ( Why You Choose Us? ) Escorts
 
VIP Independent Call Girls in Bandra West 🌹 9920725232 ( Call Me ) Mumbai Esc...
VIP Independent Call Girls in Bandra West 🌹 9920725232 ( Call Me ) Mumbai Esc...VIP Independent Call Girls in Bandra West 🌹 9920725232 ( Call Me ) Mumbai Esc...
VIP Independent Call Girls in Bandra West 🌹 9920725232 ( Call Me ) Mumbai Esc...dipikadinghjn ( Why You Choose Us? ) Escorts
 
VIP Call Girl in Mira Road 💧 9920725232 ( Call Me ) Get A New Crush Everyday ...
VIP Call Girl in Mira Road 💧 9920725232 ( Call Me ) Get A New Crush Everyday ...VIP Call Girl in Mira Road 💧 9920725232 ( Call Me ) Get A New Crush Everyday ...
VIP Call Girl in Mira Road 💧 9920725232 ( Call Me ) Get A New Crush Everyday ...dipikadinghjn ( Why You Choose Us? ) Escorts
 
VIP Independent Call Girls in Mira Bhayandar 🌹 9920725232 ( Call Me ) Mumbai ...
VIP Independent Call Girls in Mira Bhayandar 🌹 9920725232 ( Call Me ) Mumbai ...VIP Independent Call Girls in Mira Bhayandar 🌹 9920725232 ( Call Me ) Mumbai ...
VIP Independent Call Girls in Mira Bhayandar 🌹 9920725232 ( Call Me ) Mumbai ...dipikadinghjn ( Why You Choose Us? ) Escorts
 
20240419-SMC-submission-Annual-Superannuation-Performance-Test-–-design-optio...
20240419-SMC-submission-Annual-Superannuation-Performance-Test-–-design-optio...20240419-SMC-submission-Annual-Superannuation-Performance-Test-–-design-optio...
20240419-SMC-submission-Annual-Superannuation-Performance-Test-–-design-optio...Henry Tapper
 

Kürzlich hochgeladen (20)

CBD Belapur Expensive Housewife Call Girls Number-📞📞9833754194 No 1 Vipp HIgh...
CBD Belapur Expensive Housewife Call Girls Number-📞📞9833754194 No 1 Vipp HIgh...CBD Belapur Expensive Housewife Call Girls Number-📞📞9833754194 No 1 Vipp HIgh...
CBD Belapur Expensive Housewife Call Girls Number-📞📞9833754194 No 1 Vipp HIgh...
 
Call Girls Koregaon Park Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Koregaon Park Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Koregaon Park Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Koregaon Park Call Me 7737669865 Budget Friendly No Advance Booking
 
(INDIRA) Call Girl Mumbai Call Now 8250077686 Mumbai Escorts 24x7
(INDIRA) Call Girl Mumbai Call Now 8250077686 Mumbai Escorts 24x7(INDIRA) Call Girl Mumbai Call Now 8250077686 Mumbai Escorts 24x7
(INDIRA) Call Girl Mumbai Call Now 8250077686 Mumbai Escorts 24x7
 
Kharghar Blowjob Housewife Call Girls NUmber-9833754194-CBD Belapur Internati...
Kharghar Blowjob Housewife Call Girls NUmber-9833754194-CBD Belapur Internati...Kharghar Blowjob Housewife Call Girls NUmber-9833754194-CBD Belapur Internati...
Kharghar Blowjob Housewife Call Girls NUmber-9833754194-CBD Belapur Internati...
 
Mira Road Awesome 100% Independent Call Girls NUmber-9833754194-Dahisar Inter...
Mira Road Awesome 100% Independent Call Girls NUmber-9833754194-Dahisar Inter...Mira Road Awesome 100% Independent Call Girls NUmber-9833754194-Dahisar Inter...
Mira Road Awesome 100% Independent Call Girls NUmber-9833754194-Dahisar Inter...
 
Vasai-Virar Fantastic Call Girls-9833754194-Call Girls MUmbai
Vasai-Virar Fantastic Call Girls-9833754194-Call Girls MUmbaiVasai-Virar Fantastic Call Girls-9833754194-Call Girls MUmbai
Vasai-Virar Fantastic Call Girls-9833754194-Call Girls MUmbai
 
Business Principles, Tools, and Techniques in Participating in Various Types...
Business Principles, Tools, and Techniques  in Participating in Various Types...Business Principles, Tools, and Techniques  in Participating in Various Types...
Business Principles, Tools, and Techniques in Participating in Various Types...
 
Call Girls Banaswadi Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Banaswadi Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Banaswadi Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Banaswadi Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
 
Cybersecurity Threats in Financial Services Protection.pptx
Cybersecurity Threats in  Financial Services Protection.pptxCybersecurity Threats in  Financial Services Protection.pptx
Cybersecurity Threats in Financial Services Protection.pptx
 
VIP Call Girl Service Andheri West ⚡ 9920725232 What It Takes To Be The Best ...
VIP Call Girl Service Andheri West ⚡ 9920725232 What It Takes To Be The Best ...VIP Call Girl Service Andheri West ⚡ 9920725232 What It Takes To Be The Best ...
VIP Call Girl Service Andheri West ⚡ 9920725232 What It Takes To Be The Best ...
 
( Jasmin ) Top VIP Escorts Service Dindigul 💧 7737669865 💧 by Dindigul Call G...
( Jasmin ) Top VIP Escorts Service Dindigul 💧 7737669865 💧 by Dindigul Call G...( Jasmin ) Top VIP Escorts Service Dindigul 💧 7737669865 💧 by Dindigul Call G...
( Jasmin ) Top VIP Escorts Service Dindigul 💧 7737669865 💧 by Dindigul Call G...
 
Navi Mumbai Cooperetive Housewife Call Girls-9833754194-Natural Panvel Enjoye...
Navi Mumbai Cooperetive Housewife Call Girls-9833754194-Natural Panvel Enjoye...Navi Mumbai Cooperetive Housewife Call Girls-9833754194-Natural Panvel Enjoye...
Navi Mumbai Cooperetive Housewife Call Girls-9833754194-Natural Panvel Enjoye...
 
Q1 2024 Conference Call Presentation vF.pdf
Q1 2024 Conference Call Presentation vF.pdfQ1 2024 Conference Call Presentation vF.pdf
Q1 2024 Conference Call Presentation vF.pdf
 
7 tips trading Deriv Accumulator Options
7 tips trading Deriv Accumulator Options7 tips trading Deriv Accumulator Options
7 tips trading Deriv Accumulator Options
 
From Luxury Escort Service Kamathipura : 9352852248 Make on-demand Arrangemen...
From Luxury Escort Service Kamathipura : 9352852248 Make on-demand Arrangemen...From Luxury Escort Service Kamathipura : 9352852248 Make on-demand Arrangemen...
From Luxury Escort Service Kamathipura : 9352852248 Make on-demand Arrangemen...
 
VIP Independent Call Girls in Mumbai 🌹 9920725232 ( Call Me ) Mumbai Escorts ...
VIP Independent Call Girls in Mumbai 🌹 9920725232 ( Call Me ) Mumbai Escorts ...VIP Independent Call Girls in Mumbai 🌹 9920725232 ( Call Me ) Mumbai Escorts ...
VIP Independent Call Girls in Mumbai 🌹 9920725232 ( Call Me ) Mumbai Escorts ...
 
VIP Independent Call Girls in Bandra West 🌹 9920725232 ( Call Me ) Mumbai Esc...
VIP Independent Call Girls in Bandra West 🌹 9920725232 ( Call Me ) Mumbai Esc...VIP Independent Call Girls in Bandra West 🌹 9920725232 ( Call Me ) Mumbai Esc...
VIP Independent Call Girls in Bandra West 🌹 9920725232 ( Call Me ) Mumbai Esc...
 
VIP Call Girl in Mira Road 💧 9920725232 ( Call Me ) Get A New Crush Everyday ...
VIP Call Girl in Mira Road 💧 9920725232 ( Call Me ) Get A New Crush Everyday ...VIP Call Girl in Mira Road 💧 9920725232 ( Call Me ) Get A New Crush Everyday ...
VIP Call Girl in Mira Road 💧 9920725232 ( Call Me ) Get A New Crush Everyday ...
 
VIP Independent Call Girls in Mira Bhayandar 🌹 9920725232 ( Call Me ) Mumbai ...
VIP Independent Call Girls in Mira Bhayandar 🌹 9920725232 ( Call Me ) Mumbai ...VIP Independent Call Girls in Mira Bhayandar 🌹 9920725232 ( Call Me ) Mumbai ...
VIP Independent Call Girls in Mira Bhayandar 🌹 9920725232 ( Call Me ) Mumbai ...
 
20240419-SMC-submission-Annual-Superannuation-Performance-Test-–-design-optio...
20240419-SMC-submission-Annual-Superannuation-Performance-Test-–-design-optio...20240419-SMC-submission-Annual-Superannuation-Performance-Test-–-design-optio...
20240419-SMC-submission-Annual-Superannuation-Performance-Test-–-design-optio...
 

Thinking Hybrid - Python/C++ Integration

  • 1. Python Extending/Integrating A Real World Example Tips Summary Python where we can, C++ where we must Source: http://xkcd.com/353/ Guy K. Kloss — Thinking Hybrid – Python/C++ Integration 1/25
  • 2. Python Extending/Integrating A Real World Example Tips Summary Thinking Hybrid – Python/C++ Integration (Python where we can, C++ where we must∗ ) Guy K. Kloss New Zealand Python User Group Meeting Auckland, 30 January 2008 ∗ Quote: Alex Martelli, Senior Google Developer Guy K. Kloss — Thinking Hybrid – Python/C++ Integration 2/25
  • 3. Python Extending/Integrating A Real World Example Tips Summary Outline 1 Python 2 Extending/Integrating 3 A Real World Example 4 Tips Guy K. Kloss — Thinking Hybrid – Python/C++ Integration 3/25
  • 4. Python Extending/Integrating A Real World Example Tips Summary Outline 1 Python 2 Extending/Integrating 3 A Real World Example 4 Tips Guy K. Kloss — Thinking Hybrid – Python/C++ Integration 4/25
  • 5. Python Extending/Integrating A Real World Example Tips Summary Why Python? We all know why . . . Some reasons that are important for us: Dynamic High-level data types Embeddable/Mixable Extend Python with components written in C++, Java, C Embed Python into your application and call it from C/C++ Platform independent 50 % less code, 300 % more productive Automatic memory management All those utilities, modules, . . . Many, many more reasons . . . Guy K. Kloss — Thinking Hybrid – Python/C++ Integration 5/25
  • 6. Python Extending/Integrating A Real World Example Tips Summary Why Python? Source: http://xkcd.com/371/ Guy K. Kloss — Thinking Hybrid – Python/C++ Integration 6/25
  • 7. Python Extending/Integrating A Real World Example Tips Summary Outline 1 Python 2 Extending/Integrating 3 A Real World Example 4 Tips Guy K. Kloss — Thinking Hybrid – Python/C++ Integration 7/25
  • 8. Python Extending/Integrating A Real World Example Tips Summary What if I could . . . Use this code more effectively . . . ? [NaSt2D demonstration (native executable)] Guy K. Kloss — Thinking Hybrid – Python/C++ Integration 8/25
  • 9. Python Extending/Integrating A Real World Example Tips Summary Extending/Integration The Contestants: The “classic way” . . . Extending and Embedding the Python Interpreter The “new way” . . . Python ctypes SWIG Boost.Python Others: SIP Pythonizer SILOON (Pyrex) Extensions also for Java, C#, Fortran, . . . available Guy K. Kloss — Thinking Hybrid – Python/C++ Integration 9/25
  • 10. Python Extending/Integrating A Real World Example Tips Summary Extending/Integration The Contestants: The “classic way” . . . Extending and Embedding the Python Interpreter The “new way” . . . Python ctypes SWIG Boost.Python Others: SIP Pythonizer SILOON (Pyrex) Extensions also for Java, C#, Fortran, . . . available Guy K. Kloss — Thinking Hybrid – Python/C++ Integration 9/25
  • 11. Python Extending/Integrating A Real World Example Tips Summary Extending/Integration The Contestants: The “classic way” . . . Extending and Embedding the Python Interpreter The “new way” . . . Python ctypes SWIG Boost.Python Others: SIP Pythonizer SILOON (Pyrex) Extensions also for Java, C#, Fortran, . . . available Guy K. Kloss — Thinking Hybrid – Python/C++ Integration 9/25
  • 12. Python Extending/Integrating A Real World Example Tips Summary Extending/Integration The Contestants: The “classic way” . . . Extending and Embedding the Python Interpreter The “new way” . . . Python ctypes SWIG Boost.Python Others: SIP Pythonizer SILOON (Pyrex) Extensions also for Java, C#, Fortran, . . . available Guy K. Kloss — Thinking Hybrid – Python/C++ Integration 9/25
  • 13. Python Extending/Integrating A Real World Example Tips Summary Extending/Integration The Contestants: The “classic way” . . . Extending and Embedding the Python Interpreter The “new way” . . . Python ctypes SWIG Boost.Python Others: SIP Pythonizer SILOON (Pyrex) Extensions also for Java, C#, Fortran, . . . available Guy K. Kloss — Thinking Hybrid – Python/C++ Integration 9/25
  • 14. Python Extending/Integrating A Real World Example Tips Summary Boost.Python Thinking Hybrid with Boost.Python Bottom up and . . . Top down possible Develop quickly Resolve bottle necks Donald Knuth’s: “Premature optimisation is the root of all evil.” or: Don’t Optimise Now! Guy K. Kloss — Thinking Hybrid – Python/C++ Integration 10/25
  • 15. Python Extending/Integrating A Real World Example Tips Summary Boost.Python Thinking Hybrid with Boost.Python Bottom up and . . . Top down possible Develop quickly Resolve bottle necks Donald Knuth’s: “Premature optimisation is the root of all evil.” or: Don’t Optimise Now! Guy K. Kloss — Thinking Hybrid – Python/C++ Integration 10/25
  • 16. Python Extending/Integrating A Real World Example Tips Summary Boost.Python Thinking Hybrid with Boost.Python Bottom up and . . . Top down possible Develop quickly Resolve bottle necks Donald Knuth’s: “Premature optimisation is the root of all evil.” or: Don’t Optimise Now! Guy K. Kloss — Thinking Hybrid – Python/C++ Integration 10/25
  • 17. Python Extending/Integrating A Real World Example Tips Summary Hello World char const* greet(unsigned x) { static char const* const msgs[] = {quot;helloquot;, quot;Boost.Pythonquot;, quot;world!quot;}; if (x > 2) { throw std::range error(quot;greet: Index out of range.quot;); } return msgs[x]; } #include <boost/python.hpp> using namespace boost::python; BOOST PYTHON MODULE(hello) { .def(quot;greetquot;, greet, quot;return one of 3 parts of a greetingquot;); } And here it is in action: >>> import hello >>> for x in range (3): ... print hello . greet ( x ) ... hello Boost . Python world ! Guy K. Kloss — Thinking Hybrid – Python/C++ Integration 11/25
  • 18. Python Extending/Integrating A Real World Example Tips Summary Boost.Python One of a few libraries that make it easy to integrate C++ and Python code How does it pull off this trick? Template meta–programming (i. e. Don’t ask!) Guy K. Kloss — Thinking Hybrid – Python/C++ Integration 12/25
  • 19. Python Extending/Integrating A Real World Example Tips Summary Boost.Python One of a few libraries that make it easy to integrate C++ and Python code How does it pull off this trick? Template meta–programming (i. e. Don’t ask!) Guy K. Kloss — Thinking Hybrid – Python/C++ Integration 12/25
  • 20. Python Extending/Integrating A Real World Example Tips Summary See it Happen I’m making it work for you now . . . [“MyClass” demonstration (MyClass.cpp, MyClass.h, mymodule.cpp)] Guy K. Kloss — Thinking Hybrid – Python/C++ Integration 13/25
  • 21. Python Extending/Integrating A Real World Example Tips Summary Outline 1 Python 2 Extending/Integrating 3 A Real World Example 4 Tips Guy K. Kloss — Thinking Hybrid – Python/C++ Integration 14/25
  • 22. Python Extending/Integrating A Real World Example Tips Summary A Real World Example Re-visiting NaSt2D Wrapping NaSt2D Control the code Guy K. Kloss — Thinking Hybrid – Python/C++ Integration 15/25
  • 23. Python Extending/Integrating A Real World Example Tips Summary NaSt2D in Python This is what I’m going to show you: Code to be wrapped Generated wrapper code Generator script SCons (build system) How it works with Python [Wrapped NaSt2D demonstration (Wrapper.h, nast2dmodule.cpp, generate bindings.py, SConstruct, demo0.py)] Guy K. Kloss — Thinking Hybrid – Python/C++ Integration 16/25
  • 24. Python Extending/Integrating A Real World Example Tips Summary Extend Wrapper Class Inheriting from C++ classes Interfacing numerical values Change functionality Follow the Computation Guy K. Kloss — Thinking Hybrid – Python/C++ Integration 17/25
  • 25. Python Extending/Integrating A Real World Example Tips Summary Overriding in Python This is what I’m going to show you: Overriding a native method in Python Native method needs to be “virtual” Live data plotting with GNUplot [NaSt2D with plotting demonstration (demo1.py, demo2.py)] Guy K. Kloss — Thinking Hybrid – Python/C++ Integration 18/25
  • 26. Python Extending/Integrating A Real World Example Tips Summary Do more Computations Parameter Study Change input file Compute several cases Plot results automatically Guy K. Kloss — Thinking Hybrid – Python/C++ Integration 19/25
  • 27. Python Extending/Integrating A Real World Example Tips Summary Automating in Python This is what I’m going to show you: Using a template input file Batch–calculating several runs Plotting results with GNUplot [NaSt2D with parameter variation demonstration (demo3.py, demo4.py)] Guy K. Kloss — Thinking Hybrid – Python/C++ Integration 20/25
  • 28. Python Extending/Integrating A Real World Example Tips Summary Outline 1 Python 2 Extending/Integrating 3 A Real World Example 4 Tips Guy K. Kloss — Thinking Hybrid – Python/C++ Integration 21/25
  • 29. Python Extending/Integrating A Real World Example Tips Summary Tips To override C++ methods: make them virtual C/C++ pit fall Call by reference/value Solution: calling policies Map to “other/sane” languages Java: Jython C#: IronPython Fortran: PyFort, Py2F (Native to other: SWIG) Guy K. Kloss — Thinking Hybrid – Python/C++ Integration 22/25
  • 30. Python Extending/Integrating A Real World Example Tips Summary Summary Why is Python good for you? How can performance bottle necks be resolved? Advantages of “Thinking Hybrid” Python–native wrapping using Boost.Python Automated wrapper generation SCons build system Guy K. Kloss — Thinking Hybrid – Python/C++ Integration 23/25
  • 31. Python Extending/Integrating A Real World Example Tips Summary Python and the “Need for Speed” Cuong Do – Software Architect YouTube.com “Python is fast enough for our site and allows us to produce maintainable features in record times, with a minimum of developers.” Guy K. Kloss — Thinking Hybrid – Python/C++ Integration 24/25
  • 32. Python Extending/Integrating A Real World Example Tips Summary Questions? G.Kloss@massey.ac.nz Slides and code available here: http://www.kloss-familie.de/moin/TalksPresentations Guy K. Kloss — Thinking Hybrid – Python/C++ Integration 25/25