dtype.rst 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. dtype
  2. =====
  3. .. contents :: Table of Contents
  4. A `dtype`_ is an object describing the type of the elements of an ndarray
  5. .. _dtype: http://docs.scipy.org/doc/numpy/reference/arrays.dtypes.html#data-type-objects-dtype
  6. ``<boost/python/numpy/dtype.hpp>`` contains the method calls necessary to generate a python object equivalent to a numpy.dtype from builtin C++ objects, as well as to create custom dtypes from user defined types
  7. synopsis
  8. --------
  9. ::
  10. namespace boost
  11. {
  12. namespace python
  13. {
  14. namespace numpy
  15. {
  16. class dtype : public object
  17. {
  18. static python::detail::new_reference convert(object::object_cref arg, bool align);
  19. public:
  20. // Convert an arbitrary Python object to a data-type descriptor object.
  21. template <typename T>
  22. explicit dtype(T arg, bool align=false);
  23. // Get the built-in numpy dtype associated with the given scalar template type.
  24. template <typename T> static dtype get_builtin();
  25. // Return the size of the data type in bytes.
  26. int get_itemsize() const;
  27. };
  28. }
  29. }
  30. }
  31. constructors
  32. ------------
  33. ::
  34. template <typename T>
  35. explicit dtype(T arg, bool align=false)
  36. :Requirements: ``T`` must be either :
  37. * a built-in C++ typename convertible to object
  38. * a valid python object or convertible to object
  39. :Effects: Constructs an object from the supplied python object / convertible
  40. to object / builtin C++ data type
  41. :Throws: Nothing
  42. ::
  43. template <typename T> static dtype get_builtin();
  44. :Requirements: The typename supplied, ``T`` must be a builtin C++ type also supported by numpy
  45. :Returns: Numpy dtype corresponding to builtin C++ type
  46. accessors
  47. ---------
  48. ::
  49. int get_itemsize() const;
  50. :Returns: the size of the data type in bytes.
  51. Example(s)
  52. ----------
  53. ::
  54. namespace p = boost::python;
  55. namespace np = boost::python::numpy;
  56. np::dtype dtype = np::dtype::get_builtin<double>();
  57. p::tuple for_custom_dtype = p::make_tuple("ha",dtype);
  58. np::dtype custom_dtype = np::dtype(list_for_dtype);