1 // Copyright Jim Bosch 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 #ifndef boost_python_numpy_scalars_hpp_ 8 #define boost_python_numpy_scalars_hpp_ 9 10 /** 11 * @brief Object managers for array scalars (currently only numpy.void is implemented). 12 */ 13 14 #include <boost/python.hpp> 15 #include <boost/python/numpy/numpy_object_mgr_traits.hpp> 16 #include <boost/python/numpy/dtype.hpp> 17 18 namespace boost { namespace python { namespace numpy { 19 20 /** 21 * @brief A boost.python "object manager" (subclass of object) for numpy.void. 22 * 23 * @todo This could have a lot more functionality. 24 */ 25 class BOOST_NUMPY_DECL void_ : public object 26 { 27 static python::detail::new_reference convert(object_cref arg, bool align); 28 public: 29 30 /** 31 * @brief Construct a new array scalar with the given size and void dtype. 32 * 33 * Data is initialized to zero. One can create a standalone scalar object 34 * with a certain dtype "dt" with: 35 * @code 36 * void_ scalar = void_(dt.get_itemsize()).view(dt); 37 * @endcode 38 */ 39 explicit void_(Py_ssize_t size); 40 41 BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(void_, object); 42 43 /// @brief Return a view of the scalar with the given dtype. 44 void_ view(dtype const & dt) const; 45 46 /// @brief Copy the scalar (deep for all non-object fields). 47 void_ copy() const; 48 49 }; 50 51 } // namespace boost::python::numpy 52 53 namespace converter 54 { 55 NUMPY_OBJECT_MANAGER_TRAITS(numpy::void_); 56 }}} // namespace boost::python::converter 57 58 #endif 59