Skip to content

Commit 99e9157

Browse files
committed
Bind a serial eval_func (called do)
1 parent ac40f05 commit 99e9157

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

ompybind11/ompybind11.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ double calc_pi(int n) {
3838
};
3939

4040
PYBIND11_MODULE(ompybind11, m) {
41-
m.def("eval_func", &eval_func), py::arg("rank"), py::arg("function"),
41+
m.def("eval_func", &eval_func, py::arg("rank"), py::arg("function"),
4242
py::arg("x"))
43+
.def("do", [](std::function<double(double)> f, double x) { return f(x); },
44+
py::arg("function"), py::arg("x"))
4345
.def("calc_pi", &calc_pi);
4446
}

ompybind11/test.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@
22
import sys
33

44
sys.path.append(os.getenv('OMPYBIND11_MODULE_PATH'))
5-
import ompybind11 # isort:skip
5+
import ompybind11 # isort:skip
66

7+
done = ompybind11.do(function=(lambda x: x + 40.0), x=2.0)
8+
print('ompybind11.do(function=(lambda x: x + 40.0), x=2.0) returned {}'.format(done))
79

810
def f(x):
9-
return x*x
11+
return x * x
12+
1013

1114
x = 2.0
1215

1316
pi = ompybind11.calc_pi(100)
1417
print('pi is {}'.format(pi))
1518

16-
foo = ompybind11.eval_func(0, f, x)
19+
foo = ompybind11.eval_func(rank=0, function=f, x=x)
1720
print('Output of eval_func {}\n'.format(foo))
1821

19-
bar = ompybind11.eval_func(1, f, x)
22+
bar = ompybind11.eval_func(rank=1, function=f, x=x)
2023
print('Output of eval_func {}\n'.format(bar))

0 commit comments

Comments
 (0)