• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright Jim Bosch & Ankit Daftery 2010-2012.
2 // Copyright Stefan Seefeld 2016.
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 
7 #include <boost/python/numpy.hpp>
8 #include <boost/python/slice.hpp>
9 
10 namespace p = boost::python;
11 namespace np = boost::python::numpy;
12 
single(np::ndarray ndarr,int i)13 p::object single(np::ndarray ndarr, int i) { return ndarr[i];}
slice(np::ndarray ndarr,p::slice sl)14 p::object slice(np::ndarray ndarr, p::slice sl) { return ndarr[sl];}
indexarray(np::ndarray ndarr,np::ndarray d1)15 p::object indexarray(np::ndarray ndarr, np::ndarray d1) { return ndarr[d1];}
indexarray_2d(np::ndarray ndarr,np::ndarray d1,np::ndarray d2)16 p::object indexarray_2d(np::ndarray ndarr, np::ndarray d1,np::ndarray d2) { return ndarr[p::make_tuple(d1,d2)];}
indexslice(np::ndarray ndarr,np::ndarray d1,p::slice sl)17 p::object indexslice(np::ndarray ndarr, np::ndarray d1, p::slice sl) { return ndarr[p::make_tuple(d1, sl)];}
18 
BOOST_PYTHON_MODULE(indexing_ext)19 BOOST_PYTHON_MODULE(indexing_ext)
20 {
21   np::initialize();
22   p::def("single", single);
23   p::def("slice", slice);
24   p::def("indexarray", indexarray);
25   p::def("indexarray", indexarray_2d);
26   p::def("indexslice", indexslice);
27 
28 }
29