|
| 1 | +// |
| 2 | +// demo_module.cpp |
| 3 | +// python-multi-array |
| 4 | +// |
| 5 | +// Copyright (C) 2017 Rue Yokaze |
| 6 | +// Distributed under the MIT License. |
| 7 | +// |
| 8 | +#include <boost/multi_array.hpp> |
| 9 | +#include <boost/python.hpp> |
| 10 | + |
| 11 | +using boost::multi_array; |
| 12 | +using std::shared_ptr; |
| 13 | + |
| 14 | +float average(const shared_ptr<multi_array<float, 1>>& vec) |
| 15 | +{ |
| 16 | + float total = 0.f; |
| 17 | + size_t size = vec->shape()[0]; |
| 18 | + for (size_t i = 0; i < size; ++i) |
| 19 | + { |
| 20 | + total += (*vec)[i]; |
| 21 | + } |
| 22 | + return total / size; |
| 23 | +} |
| 24 | + |
| 25 | +BOOST_PYTHON_MODULE(demo_module) |
| 26 | +{ |
| 27 | + using boost::python::def; |
| 28 | + def("average", average); |
| 29 | +} |
0 commit comments