Coder Social home page Coder Social logo

jianglimed / cpp-py-example Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wyli/cpp-py-example

0.0 1.0 0.0 393 KB

Example project that shows hybrid programming with C++ and Python (incl. NumPy and SciPy).

License: BSD 3-Clause "New" or "Revised" License

Python 18.47% CMake 13.39% C++ 68.13%

cpp-py-example's Introduction

GitPitch

Summary

Example project that shows hybrid programming with C++ and Python. It also shows how to wrap C++ datatypes as NumPy arrays, so as to enable use of SciPy routines.

Requirements

  • Cmake version 3.2 or newer
  • C++11 compatible compiler
  • Boost.Python version 1.63
  • Python 3
  • NumPy and SciPy
  • Tested on an Ubuntu 16.04 LTS.

See towards the end of this file for instructions how to install these.

Usage

Building the libraries

  1. git clone [email protected]:dzhoshkun/cpp-py-example.git
  2. cd cpp-py-example/ex && export PYTHONPATH="$(pwd):$PYTHONPATH" && cd ../..
  3. mkdir cpp-py-example-build && cd cpp-py-example-build
  4. cmake ../cpp-py-example/src
  5. make -j
  6. export PYTHONPATH="$(pwd):$PYTHONPATH"

Running the examples

Most of the *.py files in the ex sub-folder contain main functions. Some of these use the image file located in the res sub-folder. So please change to this folder before running any example. You can then run any example by calling the file directly, e.g. ../ex/gil.py.

Running the benchmarks

The mgrad.py file in the ex folder is intended for benchmarking. You can benchmark the pure Python function in this file using e.g.:

python3 -m timeit "from mgrad import grad; import numpy as np; arr = np.zeros((128, 128, 3), dtype='uint8'); grad(arr)"

To benchmark its C++ implementation, replace mgrad with pymycpp, i.e:

python3 -m timeit "from pymycpp import grad; import numpy as np; arr = np.zeros((128, 128, 3), dtype='uint8'); grad(arr)"

Installing the requirements

Cmake

  • Ubuntu: apt install cmake
  • Mac OS X: brew install cmake (i.e. using Homebrew)

Boost.Python 1.63

  • Ubuntu
    1. Install Python 3 development libs (see below).
    2. wget https://sourceforge.net/projects/boost/files/boost/1.63.0/boost_1_63_0.tar.bz2
    3. tar xvfj boost_1_63_0.tar.bz2
    4. cd boost_1_63_0
    5. ./bootstrap.sh --with-python=$(which python3)
    6. ./b2 -j 7
    7. ./b2 -j 7 install
  • Mac OS X
    1. Install Python 3 and SciPy (see below)
    2. brew install boost-python --with-python3
    3. You might need to set your BOOST_ROOT, e.g. export BOOST_ROOT=/usr/local/Cellar/boost/1.63.0/include

Python 3

  • Ubuntu: apt install python3-dev
  • Mac OS X: brew install python3

NumPy and SciPy

  • Ubuntu
    1. apt install python3-numpy
    2. apt install python3-scipy
  • Mac OS X: brew install scipy --with-python3

cpp-py-example's People

Contributors

dzhoshkun avatar wyli avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.