scalars.hpp 1.6 KB

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