bnpy.cpp
Go to the documentation of this file.
1 /* Simple test using the boost::numpy interface: return an array and a matrix. */
2 
3 #include "eigenpy/fwd.hpp"
4 #include "boost/numpy.hpp"
5 
6 namespace bp = boost::python;
7 namespace bn = boost::numpy;
8 
9 /* Return an dim-1 array with 5 elements. */
10 bn::ndarray array() {
11  std::vector<double> v(5);
12  v[0] = 56;
13  Py_intptr_t shape[1] = { v.size() };
14  bn::ndarray result = bn::zeros(1, shape, bn::dtype::get_builtin<double>());
15  std::copy(v.begin(), v.end(), reinterpret_cast<double*>(result.get_data()));
16  return result;
17 }
18 
19 /* Return a dim-1 matrix with five elements. */
20 boost::python::object matrix() {
21  std::vector<double> v(5);
22  v[0] = 56;
23  Py_intptr_t shape[1] = { v.size() };
24  bn::matrix t(bn::zeros(1, shape, bn::dtype::get_builtin<double>()));
25  std::copy(v.begin(), v.end(), reinterpret_cast<double*>(t.get_data()));
26 
27  return t;
28 }
29 
31  bn::initialize();
32  bp::def("array", array);
33  bp::def("matrix", matrix);
34 }
boost::python::object matrix()
Definition: bnpy.cpp:20
bn::ndarray array()
Definition: bnpy.cpp:10
BOOST_PYTHON_MODULE(libbnpy)
Definition: bnpy.cpp:30


eigenpy
Author(s): Justin Carpentier, Nicolas Mansard
autogenerated on Sat Apr 17 2021 02:37:59