]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/python/test/numpy/indexing.cpp
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)
7 #include <boost/python/numpy.hpp>
8 #include <boost/python/slice.hpp>
10 namespace p
= boost::python
;
11 namespace np
= boost::python::numpy
;
13 p::object
single(np::ndarray ndarr
, int i
) { return ndarr
[i
];}
14 p::object
slice(np::ndarray ndarr
, p::slice sl
) { return ndarr
[sl
];}
15 p::object
indexarray(np::ndarray ndarr
, np::ndarray d1
) { return ndarr
[d1
];}
16 p::object
indexarray_2d(np::ndarray ndarr
, np::ndarray d1
,np::ndarray d2
) { return ndarr
[p::make_tuple(d1
,d2
)];}
17 p::object
indexslice(np::ndarray ndarr
, np::ndarray d1
, p::slice sl
) { return ndarr
[p::make_tuple(d1
, sl
)];}
19 BOOST_PYTHON_MODULE(indexing_ext
)
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
);