blob: 03227116cc1df712258de91777951e6976b8b950 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
dtype
=====
.. contents :: Table of Contents
A `dtype`_ is an object describing the type of the elements of an ndarray
.. _dtype: http://docs.scipy.org/doc/numpy/reference/arrays.dtypes.html#data-type-objects-dtype
``<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);
|