1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
---|
2 | <!-- Copyright David Abrahams 2006. Distributed under the Boost --> |
---|
3 | <!-- Software License, Version 1.0. (See accompanying --> |
---|
4 | <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) --> |
---|
5 | |
---|
6 | <html> |
---|
7 | <head> |
---|
8 | <meta name="generator" content= |
---|
9 | "HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org"> |
---|
10 | <meta http-equiv="Content-Type" content="text/html; charset=us-ascii"> |
---|
11 | <link rel="stylesheet" type="text/css" href="../boost.css"> |
---|
12 | |
---|
13 | <title>Boost.Python - <boost/python/numeric.hpp></title> |
---|
14 | </head> |
---|
15 | |
---|
16 | <body> |
---|
17 | <table border="0" cellpadding="7" cellspacing="0" width="100%" summary= |
---|
18 | "header"> |
---|
19 | <tr> |
---|
20 | <td valign="top" width="300"> |
---|
21 | <h3><a href="../../../../index.htm"><img height="86" width="277" alt= |
---|
22 | "C++ Boost" src="../../../../boost.png" border="0"></a></h3> |
---|
23 | </td> |
---|
24 | |
---|
25 | <td valign="top"> |
---|
26 | <h1 align="center"><a href="../index.html">Boost.Python</a></h1> |
---|
27 | |
---|
28 | <h2 align="center">Header <boost/python/numeric.hpp></h2> |
---|
29 | </td> |
---|
30 | </tr> |
---|
31 | </table> |
---|
32 | <hr> |
---|
33 | |
---|
34 | <h2>Contents</h2> |
---|
35 | |
---|
36 | <dl class="page-index"> |
---|
37 | <dt><a href="#introduction">Introduction</a></dt> |
---|
38 | |
---|
39 | <dt><a href="#classes">Classes</a></dt> |
---|
40 | |
---|
41 | <dd> |
---|
42 | <dl class="page-index"> |
---|
43 | <dt><a href="#array-spec">Class <code>array</code></a></dt> |
---|
44 | |
---|
45 | <dd> |
---|
46 | <dl class="page-index"> |
---|
47 | <dt><a href="#array-spec-synopsis">Class <code>array</code> |
---|
48 | synopsis</a></dt> |
---|
49 | |
---|
50 | <dt><a href="#array-spec-observers">Class <code>array</code> |
---|
51 | observer functions</a></dt> |
---|
52 | |
---|
53 | <dt><a href="#array-spec-statics">Class <code>array</code> static |
---|
54 | functions</a></dt> |
---|
55 | </dl> |
---|
56 | </dd> |
---|
57 | </dl> |
---|
58 | </dd> |
---|
59 | |
---|
60 | <dt><a href="#examples">Example(s)</a></dt> |
---|
61 | </dl> |
---|
62 | <hr> |
---|
63 | |
---|
64 | <h2><a name="introduction" id="introduction"></a>Introduction</h2> |
---|
65 | |
---|
66 | <p>Exposes a <a href= |
---|
67 | "ObjectWrapper.html#TypeWrapper-concept">TypeWrapper</a> for the Python |
---|
68 | <a href= |
---|
69 | "http://www.python.org/dev/doc/devel/lib/typesmapping.html">array</a> |
---|
70 | type.</p> |
---|
71 | |
---|
72 | <h2><a name="classes" id="classes"></a>Classes</h2> |
---|
73 | |
---|
74 | <h3><a name="array-spec" id="array-spec"></a>Class <code>array</code></h3> |
---|
75 | |
---|
76 | <p>Provides access to the array types of <a href= |
---|
77 | "http://www.pfdubois.com/numpy/">Numerical Python</a>'s <a href= |
---|
78 | "http://www.pfdubois.com/numpy/#Numeric">Numeric</a> and <a href= |
---|
79 | "http://stsdas.stsci.edu/numarray/index.html">NumArray</a> modules. With |
---|
80 | the exception of the functions documented <a href= |
---|
81 | "#array-spec-observers">below</a>, the semantics of the constructors and |
---|
82 | member functions defined below can be fully understood by reading the |
---|
83 | <a href="ObjectWrapper.html#TypeWrapper-concept">TypeWrapper</a> concept |
---|
84 | definition. Since <code>array</code> is publicly derived from |
---|
85 | <code><a href="object.html#object-spec">object</a></code>, the public |
---|
86 | object interface applies to <code>array</code> instances as well.</p> |
---|
87 | |
---|
88 | <p><a name="default_search" id="default_search"></a>The default behavior is |
---|
89 | to use <code>numarray.NDArray</code> as the associated Python type if the |
---|
90 | <code>numarray</code> module is installed in the default location. |
---|
91 | Otherwise it falls back to use <code>Numeric.ArrayType</code>. If neither |
---|
92 | extension module is installed, overloads of wrapped C++ functions with |
---|
93 | <code>numeric::array</code> parameters will never be matched, and other |
---|
94 | attempted uses of <code>numeric::array</code> will <a href= |
---|
95 | "definitions.html#raise">raise</a> an appropriate Python exception. The |
---|
96 | associated Python type can be set manually using the <code><a href= |
---|
97 | "#array-spec-statics">set_module_and_type</a>(...)</code> static |
---|
98 | function.</p> |
---|
99 | |
---|
100 | <h4><a name="array-spec-synopsis" id="array-spec-synopsis"></a>Class |
---|
101 | <code>array</code> synopsis</h4> |
---|
102 | <pre> |
---|
103 | namespace boost { namespace python { namespace numeric |
---|
104 | { |
---|
105 | class array : public object |
---|
106 | { |
---|
107 | public: |
---|
108 | object astype(); |
---|
109 | template <class Type> |
---|
110 | object astype(Type const& type_); |
---|
111 | |
---|
112 | template <class Type> |
---|
113 | array new_(Type const& type_) const; |
---|
114 | |
---|
115 | template <class Sequence> |
---|
116 | void resize(Sequence const& x); |
---|
117 | void resize(long x1); |
---|
118 | void resize(long x1, long x2); |
---|
119 | ... |
---|
120 | void resize(long x1, long x2,...long x<i>n</i>); |
---|
121 | |
---|
122 | template <class Sequence> |
---|
123 | void setshape(Sequence const& x); |
---|
124 | void setshape(long x1); |
---|
125 | void setshape(long x1, long x2); |
---|
126 | ... |
---|
127 | void setshape(long x1, long x2,...long x<i>n</i>); |
---|
128 | |
---|
129 | template <class Indices, class Values> |
---|
130 | void put(Indices const& indices, Values const& values); |
---|
131 | |
---|
132 | template <class Sequence> |
---|
133 | object take(Sequence const& sequence, long axis = 0); |
---|
134 | |
---|
135 | template <class File> |
---|
136 | void tofile(File const& f) const; |
---|
137 | |
---|
138 | object factory(); |
---|
139 | template <class Sequence> |
---|
140 | object factory(Sequence const&); |
---|
141 | template <class Sequence, class Typecode> |
---|
142 | object factory(Sequence const&, Typecode const&, bool copy = true, bool savespace = false); |
---|
143 | template <class Sequence, class Typecode, class Type> |
---|
144 | object factory(Sequence const&, Typecode const&, bool copy, bool savespace, Type const&); |
---|
145 | template <class Sequence, class Typecode, class Type, class Shape> |
---|
146 | object factory(Sequence const&, Typecode const&, bool copy, bool savespace, Type const&, Shape const&); |
---|
147 | |
---|
148 | template <class T1> |
---|
149 | explicit array(T1 const& x1); |
---|
150 | template <class T1, class T2> |
---|
151 | explicit array(T1 const& x1, T2 const& x2); |
---|
152 | ... |
---|
153 | template <class T1, class T2,...class T<i>n</i>> |
---|
154 | explicit array(T1 const& x1, T2 const& x2,...T<i>n</i> const& xn); |
---|
155 | |
---|
156 | static void set_module_and_type(); |
---|
157 | static void set_module_and_type(char const* package_path = 0, char const* type_name = 0); |
---|
158 | static void get_module_name(); |
---|
159 | |
---|
160 | object argmax(long axis=-1); |
---|
161 | |
---|
162 | object argmin(long axis=-1); |
---|
163 | |
---|
164 | object argsort(long axis=-1); |
---|
165 | |
---|
166 | void byteswap(); |
---|
167 | |
---|
168 | object copy() const; |
---|
169 | |
---|
170 | object diagonal(long offset = 0, long axis1 = 0, long axis2 = 1) const; |
---|
171 | |
---|
172 | void info() const; |
---|
173 | |
---|
174 | bool is_c_array() const; |
---|
175 | bool isbyteswapped() const; |
---|
176 | void sort(); |
---|
177 | object trace(long offset = 0, long axis1 = 0, long axis2 = 1) const; |
---|
178 | object type() const; |
---|
179 | char typecode() const; |
---|
180 | |
---|
181 | object getflat() const; |
---|
182 | long getrank() const; |
---|
183 | object getshape() const; |
---|
184 | bool isaligned() const; |
---|
185 | bool iscontiguous() const; |
---|
186 | long itemsize() const; |
---|
187 | long nelements() const; |
---|
188 | object nonzero() const; |
---|
189 | |
---|
190 | void ravel(); |
---|
191 | |
---|
192 | object repeat(object const& repeats, long axis=0); |
---|
193 | |
---|
194 | void setflat(object const& flat); |
---|
195 | |
---|
196 | void swapaxes(long axis1, long axis2); |
---|
197 | |
---|
198 | str tostring() const; |
---|
199 | |
---|
200 | void transpose(object const& axes = object()); |
---|
201 | |
---|
202 | object view() const; |
---|
203 | }; |
---|
204 | }}} |
---|
205 | </pre> |
---|
206 | |
---|
207 | <h4><a name="array-spec-observers" id="array-spec-observers"></a>Class |
---|
208 | <code>array</code> observer functions</h4> |
---|
209 | <pre> |
---|
210 | object factory(); |
---|
211 | template <class Sequence> |
---|
212 | object factory(Sequence const&); |
---|
213 | template <class Sequence, class Typecode> |
---|
214 | object factory(Sequence const&, Typecode const&, bool copy = true, bool savespace = false); |
---|
215 | template <class Sequence, class Typecode, class Type> |
---|
216 | object factory(Sequence const&, Typecode const&, bool copy, bool savespace, Type const&); |
---|
217 | template <class Sequence, class Typecode, class Type, class Shape> |
---|
218 | object factory(Sequence const&, Typecode const&, bool copy, bool savespace, Type const&, Shape const&); |
---|
219 | </pre>These functions map to the underlying array type's <code>array()</code> |
---|
220 | function family. They are not called "<code>array</code>" because of the C++ |
---|
221 | limitation that you can't define a member function with the same name as its |
---|
222 | enclosing class. |
---|
223 | <pre> |
---|
224 | template <class Type> |
---|
225 | array new_(Type const&) const; |
---|
226 | </pre>This function maps to the underlying array type's <code>new()</code> |
---|
227 | function. It is not called "<code>new</code>" because that is a keyword in |
---|
228 | C++. |
---|
229 | |
---|
230 | <h4><a name="array-spec-statics" id="array-spec-statics"></a>Class |
---|
231 | <code>array</code> static functions</h4> |
---|
232 | <pre> |
---|
233 | static void set_module_and_type(char const* package_path, char const* type_name); |
---|
234 | static void set_module_and_type(); |
---|
235 | </pre> |
---|
236 | |
---|
237 | <dl class="function-semantics"> |
---|
238 | <dt><b>Requires:</b> <code>package_path</code> and |
---|
239 | <code>type_name</code>, if supplied, is an <a href= |
---|
240 | "definitions.html#ntbs">ntbs</a>.</dt> |
---|
241 | |
---|
242 | <dt><b>Effects:</b> The first form sets the package path of the module |
---|
243 | that supplies the type named by <code>type_name</code> to |
---|
244 | <code>package_path</code>. The second form restores the <a href= |
---|
245 | "#default_search">default search behavior</a>. The associated Python type |
---|
246 | will be searched for only the first time it is needed, and thereafter the |
---|
247 | first time it is needed after an invocation of |
---|
248 | <code>set_module_and_type</code>.</dt> |
---|
249 | </dl> |
---|
250 | <pre> |
---|
251 | static std::string get_module_name() |
---|
252 | </pre> |
---|
253 | |
---|
254 | <dl class="function-semantics"> |
---|
255 | <dt><b>Effects:</b> Returns the name of the module containing the class |
---|
256 | that will be held by new <code>numeric::array</code> instances.</dt> |
---|
257 | </dl> |
---|
258 | |
---|
259 | <h2><a name="examples" id="examples"></a>Example</h2> |
---|
260 | <pre> |
---|
261 | #include <boost/python/numeric.hpp> |
---|
262 | #include <boost/python/tuple.hpp> |
---|
263 | |
---|
264 | // sets the first element in a 2d numeric array |
---|
265 | void set_first_element(numeric::array& y, double value) |
---|
266 | { |
---|
267 | y[make_tuple(0,0)] = value; |
---|
268 | } |
---|
269 | </pre> |
---|
270 | |
---|
271 | <p>Revised 07 October, 2006</p> |
---|
272 | |
---|
273 | <p><i>© Copyright <a href="../../../../people/dave_abrahams.htm">Dave |
---|
274 | Abrahams</a> 2002-2006.</i></p> |
---|
275 | </body> |
---|
276 | </html> |
---|