dtype.hpp
Go to the documentation of this file.
00001 // Copyright Jim Bosch 2010-2012.
00002 // Distributed under the Boost Software License, Version 1.0.
00003 //    (See accompanying file LICENSE_1_0.txt or copy at
00004 //          http://www.boost.org/LICENSE_1_0.txt)
00005 #ifndef BOOST_NUMPY_DTYPE_HPP_INCLUDED
00006 #define BOOST_NUMPY_DTYPE_HPP_INCLUDED
00007 
00013 #include <boost/python.hpp>
00014 #include <boost/numpy/numpy_object_mgr_traits.hpp>
00015 
00016 #include <boost/mpl/for_each.hpp>
00017 #include <boost/type_traits/add_pointer.hpp>
00018 
00019 namespace boost { namespace numpy {
00020 
00026 class dtype : public python::object {
00027   static python::detail::new_reference convert(python::object::object_cref arg, bool align);
00028 public:
00029 
00031   template <typename T>
00032   explicit dtype(T arg, bool align=false) : python::object(convert(arg, align)) {}
00033 
00045   template <typename T> static dtype get_builtin();
00046 
00048   int get_itemsize() const;
00049 
00056   friend bool equivalent(dtype const & a, dtype const & b);
00057 
00064   static void register_scalar_converters();
00065 
00066   BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(dtype, python::object);
00067 
00068 };
00069 
00070 bool equivalent(dtype const & a, dtype const & b);
00071 
00072 namespace detail
00073 {
00074 
00075 template <int bits, bool isUnsigned> dtype get_int_dtype();
00076 
00077 template <int bits> dtype get_float_dtype();
00078 
00079 template <int bits> dtype get_complex_dtype();
00080 
00081 template <typename T, bool isInt=boost::is_integral<T>::value>
00082 struct builtin_dtype;
00083 
00084 template <typename T>
00085 struct builtin_dtype<T,true> {
00086   static dtype get() { return get_int_dtype< 8*sizeof(T), boost::is_unsigned<T>::value >(); }
00087 };
00088 
00089 template <>
00090 struct builtin_dtype<bool,true> {
00091   static dtype get();
00092 };
00093 
00094 template <typename T>
00095 struct builtin_dtype<T,false> {
00096   static dtype get() { return get_float_dtype< 8*sizeof(T) >(); }
00097 };
00098 
00099 template <typename T>
00100 struct builtin_dtype< std::complex<T>, false > {
00101   static dtype get() { return get_complex_dtype< 16*sizeof(T) >(); }  
00102 };
00103 
00104 } // namespace detail
00105 
00106 template <typename T>
00107 inline dtype dtype::get_builtin() { return detail::builtin_dtype<T>::get(); }
00108 
00109 }} // namespace boost::numpy
00110 
00111 namespace boost { namespace python { namespace converter {
00112 NUMPY_OBJECT_MANAGER_TRAITS(numpy::dtype);
00113 }}} // namespace boost::python::converter
00114 
00115 #endif // !BOOST_NUMPY_DTYPE_HPP_INCLUDED


boost_numpy
Author(s): Jim Bosch, Ankit Daftery
autogenerated on Fri Aug 28 2015 10:10:40