]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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/cstdint.hpp> | |
9 | ||
10 | namespace p = boost::python; | |
11 | namespace np = boost::python::numpy; | |
12 | ||
13 | template <typename T> | |
14 | np::dtype accept(T) { | |
15 | return np::dtype::get_builtin<T>(); | |
16 | } | |
17 | ||
18 | BOOST_PYTHON_MODULE(dtype_ext) | |
19 | { | |
20 | np::initialize(); | |
21 | // wrap dtype equivalence test, since it isn't available in Python API. | |
22 | p::def("equivalent", np::equivalent); | |
23 | // integers, by number of bits | |
24 | p::def("accept_int8", accept<boost::int8_t>); | |
25 | p::def("accept_uint8", accept<boost::uint8_t>); | |
26 | p::def("accept_int16", accept<boost::int16_t>); | |
27 | p::def("accept_uint16", accept<boost::uint16_t>); | |
28 | p::def("accept_int32", accept<boost::int32_t>); | |
29 | p::def("accept_uint32", accept<boost::uint32_t>); | |
30 | p::def("accept_int64", accept<boost::int64_t>); | |
31 | p::def("accept_uint64", accept<boost::uint64_t>); | |
32 | // integers, by C name according to NumPy | |
33 | p::def("accept_bool_", accept<bool>); | |
34 | p::def("accept_byte", accept<signed char>); | |
35 | p::def("accept_ubyte", accept<unsigned char>); | |
36 | p::def("accept_short", accept<short>); | |
37 | p::def("accept_ushort", accept<unsigned short>); | |
38 | p::def("accept_intc", accept<int>); | |
39 | p::def("accept_uintc", accept<unsigned int>); | |
40 | // floats and complex | |
41 | p::def("accept_float32", accept<float>); | |
42 | p::def("accept_complex64", accept< std::complex<float> >); | |
43 | p::def("accept_float64", accept<double>); | |
44 | p::def("accept_complex128", accept< std::complex<double> >); | |
45 | if (sizeof(long double) > sizeof(double)) { | |
46 | p::def("accept_longdouble", accept<long double>); | |
47 | p::def("accept_clongdouble", accept< std::complex<long double> >); | |
48 | } | |
49 | } |