Skip to content

Instantly share code, notes, and snippets.

@nschloe
Created September 8, 2016 17:05
Show Gist options
  • Save nschloe/2905bbd136605aa91eeb5d22cbe6ec05 to your computer and use it in GitHub Desktop.
Save nschloe/2905bbd136605aa91eeb5d22cbe6ec05 to your computer and use it in GitHub Desktop.
#ifndef MYFOO_HPP
#define MYFOO_HPP
#include <vector>
double sum(const std::vector<double> & a) {
double sum = 0.0;
for (const auto & elem: a) {
sum += elem;
}
return sum;
}
#endif // MYFOO_HPP
%module myfoo
%{
#define SWIG_FILE_WITH_INIT
#include "myfoo.hpp"
%}
%include <std_vector.i>
namespace std {
%template(Line) vector<double>;
}
%include "myfoo.hpp"
from distutils.core import setup, Extension
setup(
name='myfoo',
ext_modules=[
Extension(
'_myfoo',
['myfoo.i'],
swig_opts=['-keyword', '-c++'],
extra_compile_args=['-std=c++11']
)
],
py_modules=['myfoo'],
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment