-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathexample.cpp
More file actions
36 lines (28 loc) · 809 Bytes
/
example.cpp
File metadata and controls
36 lines (28 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <pybind11/pybind11.h>
#include <pybind11/eigen.h>
#include <Eigen/LU>
#include <iostream>
// ----------------
// regular C++ code
// ----------------
Eigen::MatrixXd mul(const Eigen::MatrixXd &xs, double fac)
{
std::cout << "Double" << std::endl;
return fac*xs;
}
Eigen::MatrixXi mul(const Eigen::MatrixXi &xs, int fac)
{
std::cout << "Int" << std::endl;
return fac*xs;
}
// ----------------
// Python interface
// ----------------
namespace py = pybind11;
PYBIND11_MODULE(example,m)
{
m.doc() = "pybind11 example plugin";
// N.B. the order here is crucial, in the reversed order every "int" is converted to a "double"
m.def("mul", py::overload_cast<const Eigen::MatrixXi &,int >(&mul) );
m.def("mul", py::overload_cast<const Eigen::MatrixXd &,double>(&mul) );
}