]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/python/doc/reference/numeric.qbk
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / python / doc / reference / numeric.qbk
1 [section boost/python/numeric.hpp]
2 [section Introduction]
3 Exposes a [link concepts.objectwrapper.typewrapper_concept_requirements TypeWrapper] for the Python [@http://www.python.org/dev/doc/devel/lib/typesmapping.html array] type.
4 [endsect]
5 [section Class `array`]
6 Provides access to the array types of [@http://www.pfdubois.com/numpy/ Numerical Python]\ 's [@http://www.pfdubois.com/numpy/#Numeric Numeric] and [@http://stsdas.stsci.edu/numarray/index.html NumArray] modules. With the exception of the functions documented below, the semantics of the constructors and member functions defined below can be fully understood by reading the [link concepts.objectwrapper.typewrapper_concept_requirements TypeWrapper] concept definition. Since array is publicly derived from object, the public object interface applies to array instances as well.
7
8 The default behavior is to use numarray.NDArray as the associated Python type if the numarray module is installed in the default location. Otherwise it falls back to use Numeric.ArrayType. If neither extension module is installed, overloads of wrapped C++ functions with numeric::array parameters will never be matched, and other attempted uses of numeric::array will raise an appropriate Python exception. The associated Python type can be set manually using the set_module_and_type(...) static function.
9 ``
10 namespace boost { namespace python { namespace numeric
11 {
12 class array : public object
13 {
14 public:
15 object astype();
16 template <class Type>
17 object astype(Type const& type_);
18
19 template <class Type>
20 array new_(Type const& type_) const;
21
22 template <class Sequence>
23 void resize(Sequence const& x);
24 void resize(long x1);
25 void resize(long x1, long x2);
26 ...
27 void resize(long x1, long x2,...long xn);
28
29 template <class Sequence>
30 void setshape(Sequence const& x);
31 void setshape(long x1);
32 void setshape(long x1, long x2);
33 ...
34 void setshape(long x1, long x2,...long xn);
35
36 template <class Indices, class Values>
37 void put(Indices const& indices, Values const& values);
38
39 template <class Sequence>
40 object take(Sequence const& sequence, long axis = 0);
41
42 template <class File>
43 void tofile(File const& f) const;
44
45 object factory();
46 template <class Sequence>
47 object factory(Sequence const&);
48 template <class Sequence, class Typecode>
49 object factory(Sequence const&, Typecode const&, bool copy = true, bool savespace = false);
50 template <class Sequence, class Typecode, class Type>
51 object factory(Sequence const&, Typecode const&, bool copy, bool savespace, Type const&);
52 template <class Sequence, class Typecode, class Type, class Shape>
53 object factory(Sequence const&, Typecode const&, bool copy, bool savespace, Type const&, Shape const&);
54
55 template <class T1>
56 explicit array(T1 const& x1);
57 template <class T1, class T2>
58 explicit array(T1 const& x1, T2 const& x2);
59 ...
60 template <class T1, class T2,...class Tn>
61 explicit array(T1 const& x1, T2 const& x2,...Tn const& xn);
62
63 static void set_module_and_type();
64 static void set_module_and_type(char const* package_path = 0, char const* type_name = 0);
65 static void get_module_name();
66
67 object argmax(long axis=-1);
68
69 object argmin(long axis=-1);
70
71 object argsort(long axis=-1);
72
73 void byteswap();
74
75 object copy() const;
76
77 object diagonal(long offset = 0, long axis1 = 0, long axis2 = 1) const;
78
79 void info() const;
80
81 bool is_c_array() const;
82 bool isbyteswapped() const;
83 void sort();
84 object trace(long offset = 0, long axis1 = 0, long axis2 = 1) const;
85 object type() const;
86 char typecode() const;
87
88 object getflat() const;
89 long getrank() const;
90 object getshape() const;
91 bool isaligned() const;
92 bool iscontiguous() const;
93 long itemsize() const;
94 long nelements() const;
95 object nonzero() const;
96
97 void ravel();
98 object repeat(object const& repeats, long axis=0);
99 void setflat(object const& flat);
100 void swapaxes(long axis1, long axis2);
101 str tostring() const;
102 void transpose(object const& axes = object());
103 object view() const;
104 };
105 }}}
106 ``
107 [endsect]
108 [section Class `array` observer functions]
109 ``
110 object factory();
111 template <class Sequence>
112 object factory(Sequence const&);
113 template <class Sequence, class Typecode>
114 object factory(Sequence const&, Typecode const&, bool copy = true, bool savespace = false);
115 template <class Sequence, class Typecode, class Type>
116 object factory(Sequence const&, Typecode const&, bool copy, bool savespace, Type const&);
117 template <class Sequence, class Typecode, class Type, class Shape>
118 object factory(Sequence const&, Typecode const&, bool copy, bool savespace, Type const&, Shape const&);
119 ``
120 These functions map to the underlying array type's array() function family. They are not called "array" because of the C++ limitation that you can't define a member function with the same name as its enclosing class.
121 ``
122 template <class Type>
123 array new_(Type const&) const;
124 ``
125 This function maps to the underlying array type's new() function. It is not called "new" because that is a keyword in C++.
126 [endsect]
127 [section Class `array` static functions]
128 ``
129 static void set_module_and_type(char const* package_path, char const* type_name);
130 static void set_module_and_type();
131 ``
132 [variablelist
133 [[Requires][package_path and type_name, if supplied, is an [link ntbs].]]
134 [[Effects][The first form sets the package path of the module that supplies the type named by type_name to package_path. The second form restores the default search behavior. The associated Python type will be searched for only the first time it is needed, and thereafter the first time it is needed after an invocation of set_module_and_type.]]
135 ]
136 ``static std::string get_module_name()``
137 [variablelist
138 [[Effects][Returns the name of the module containing the class that will be held by new `numeric::array` instances.]]
139 ]
140 [endsect]
141 [section Example]
142 ``
143 #include <boost/python/numeric.hpp>
144 #include <boost/python/tuple.hpp>
145
146 // sets the first element in a 2d numeric array
147 void set_first_element(numeric::array& y, double value)
148 {
149 y[make_tuple(0,0)] = value;
150 }
151 ``
152 [endsect]
153 [endsect]