Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.

C++ Boost

(NumPy)


dtype

A dtype is an object describing the type of the elements of an ndarray

<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

synopsis

namespace boost
{
namespace python
{
namespace numpy
{

class dtype : public object
{
  static python::detail::new_reference convert(object::object_cref arg, bool align);
public:

  // Convert an arbitrary Python object to a data-type descriptor object.
  template <typename T>
  explicit dtype(T arg, bool align=false);

  // Get the built-in numpy dtype associated with the given scalar template type.
  template <typename T> static dtype get_builtin();

  // Return the size of the data type in bytes.
  int get_itemsize() const;
};

}
}
}

constructors

template <typename T>
explicit dtype(T arg, bool align=false)
Requirements:

T must be either :

  • a built-in C++ typename convertible to object
  • a valid python object or convertible to object
Effects:

Constructs an object from the supplied python object / convertible to object / builtin C++ data type

Throws:

Nothing

template <typename T> static dtype get_builtin();
Requirements:The typename supplied, T must be a builtin C++ type also supported by numpy
Returns:Numpy dtype corresponding to builtin C++ type

accessors

int get_itemsize() const;
Returns:the size of the data type in bytes.

Example(s)

namespace p = boost::python;
namespace np = boost::python::numpy;

np::dtype dtype = np::dtype::get_builtin<double>();
p::tuple for_custom_dtype = p::make_tuple("ha",dtype);
np::dtype custom_dtype = np::dtype(list_for_dtype);