Skip to content

Commit 49d4aac

Browse files
committed
Fix lots of bugs in the numeric interface and tests.
Tests: * Coerce a result to bool to deal with Python's new Bool type * Better reporting of mismatches in expected and received results * Remove bogus nullary y.astype() call * Fix all uses of trace and diagonal so they don't cause errors * Use appropriate typecodes * Use doctest detailed API to run just the relevant tests * Factor out error handling from macro API: * Added get_module_name() function to get current numeric module * new_(x) now returns an array instead of object * Fixed the signatures of the factory() family of functions * Updated docs accordingly. [SVN r35528]
1 parent 545be29 commit 49d4aac

File tree

5 files changed

+289
-232
lines changed

5 files changed

+289
-232
lines changed

doc/v2/numeric.html

Lines changed: 159 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,105 @@
11
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2-
32
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
43
<!-- Software License, Version 1.0. (See accompanying -->
54
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
5+
66
<html>
7-
<head>
8-
<meta name="generator" content=
9-
"HTML Tidy for Windows (vers 1st August 2002), see www.w3.org">
10-
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
11-
<link rel="stylesheet" type="text/css" href="../boost.css">
12-
13-
<title>Boost.Python - &lt;boost/python/numeric.hpp&gt;</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"
22-
alt="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 &lt;boost/python/numeric.hpp&gt;</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>
54-
static 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"></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"></a>Classes</h2>
73-
74-
<h3><a name="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 <a
83-
href="ObjectWrapper.html#TypeWrapper-concept">TypeWrapper</a> concept
84-
definition. Since <code>array</code> is publicly derived from <code><a
85-
href="object.html#object-spec">object</a></code>, the public object
86-
interface applies to <code>array</code> instances as well.</p>
87-
88-
<p><a name="default_search"></a>The default behavior is to use
89-
<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, conversions to arguments of type
93-
<code>numeric::array</code> will cause overload resolution to reject the
94-
overload, and other attempted uses of <code>numeric::array</code> will <a
95-
href="definitions.html#raise">raise</a> an appropriate Python exception.
96-
The 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"></a>Class <code>array</code>
101-
synopsis</h4>
102-
<pre>
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 - &lt;boost/python/numeric.hpp&gt;</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 &lt;boost/python/numeric.hpp&gt;</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>
103103
namespace boost { namespace python { namespace numeric
104104
{
105105
class array : public object
@@ -110,7 +110,7 @@ <h4><a name="array-spec-synopsis"></a>Class <code>array</code>
110110
object astype(Type const&amp; type_);
111111

112112
template &lt;class Type&gt;
113-
object new_(Type const&amp; type_) const;
113+
array new_(Type const&amp; type_) const;
114114

115115
template &lt;class Sequence&gt;
116116
void resize(Sequence const&amp; x);
@@ -136,14 +136,14 @@ <h4><a name="array-spec-synopsis"></a>Class <code>array</code>
136136
void tofile(File const&amp; f) const;
137137

138138
object factory();
139-
template &lt;class Buffer&gt;
140-
object factory(Buffer const&amp;);
141-
template &lt;class Buffer, class Type&gt;
142-
object factory(Buffer const&amp;, Type const&amp;);
143-
template &lt;class Buffer, class Type, class Shape&gt;
144-
object factory(Buffer const&amp;, Type const&amp;, Shape const&amp;, bool copy = true, bool savespace = false);
145-
template &lt;class Buffer, class Type, class Shape&gt;
146-
object factory(Buffer const&amp;, Type const&amp;, Shape const&amp;, bool copy, bool savespace, char typecode);
139+
template &lt;class Sequence&gt;
140+
object factory(Sequence const&amp;);
141+
template &lt;class Sequence, class Typecode&gt;
142+
object factory(Sequence const&amp;, Typecode const&amp;, bool copy = true, bool savespace = false);
143+
template &lt;class Sequence, class Typecode, class Type&gt;
144+
object factory(Sequence const&amp;, Typecode const&amp;, bool copy, bool savespace, Type const&amp;);
145+
template &lt;class Sequence, class Typecode, class Type, class Shape&gt;
146+
object factory(Sequence const&amp;, Typecode const&amp;, bool copy, bool savespace, Type const&amp;, Shape const&amp;);
147147

148148
template &lt;class T1&gt;
149149
explicit array(T1 const&amp; x1);
@@ -155,6 +155,7 @@ <h4><a name="array-spec-synopsis"></a>Class <code>array</code>
155155

156156
static void set_module_and_type();
157157
static void set_module_and_type(char const* package_path = 0, char const* type_name = 0);
158+
static void get_module_name();
158159

159160
object argmax(long axis=-1);
160161

@@ -203,54 +204,60 @@ <h4><a name="array-spec-synopsis"></a>Class <code>array</code>
203204
}}}
204205
</pre>
205206

206-
<h4><a name="array-spec-observers"></a>Class <code>array</code> observer
207-
functions</h4>
208-
<pre>
207+
<h4><a name="array-spec-observers" id="array-spec-observers"></a>Class
208+
<code>array</code> observer functions</h4>
209+
<pre>
209210
object factory();
210-
template &lt;class Buffer&gt;
211-
object factory(Buffer const&amp;);
212-
template &lt;class Buffer, class Type&gt;
213-
object factory(Buffer const&amp;, Type const&amp;);
214-
template &lt;class Buffer, class Type, class Shape&gt;
215-
object factory(Buffer const&amp;, Type const&amp;, Shape const&amp;, bool copy = true, bool savespace = false);
216-
template &lt;class Buffer, class Type, class Shape&gt;
217-
object factory(Buffer const&amp;, Type const&amp;, Shape const&amp;, bool copy, bool savespace, char typecode);
218-
</pre>
219-
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
221-
C++ limitation that you can't define a member function with the same name
222-
as its enclosing class.
223-
<pre>
211+
template &lt;class Sequence&gt;
212+
object factory(Sequence const&amp;);
213+
template &lt;class Sequence, class Typecode&gt;
214+
object factory(Sequence const&amp;, Typecode const&amp;, bool copy = true, bool savespace = false);
215+
template &lt;class Sequence, class Typecode, class Type&gt;
216+
object factory(Sequence const&amp;, Typecode const&amp;, bool copy, bool savespace, Type const&amp;);
217+
template &lt;class Sequence, class Typecode, class Type, class Shape&gt;
218+
object factory(Sequence const&amp;, Typecode const&amp;, bool copy, bool savespace, Type const&amp;, Shape const&amp;);
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>
224224
template &lt;class Type&gt;
225-
object new_(Type const&amp;) const;
226-
</pre>
227-
This function maps to the underlying array type's <code>new()</code>
228-
function. It is not called "<code>new</code>" because that is a keyword
229-
in C++.
230-
231-
<h4><a name="array-spec-statics"></a>Class <code>array</code> static
232-
functions</h4>
233-
<pre>
225+
array new_(Type const&amp;) 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>
234233
static void set_module_and_type(char const* package_path, char const* type_name);
235234
static void set_module_and_type();
236235
</pre>
237236

238-
<dl class="function-semantics">
239-
<dt><b>Requires:</b> <code>package_path</code> and
240-
<code>type_name</code>, if supplied, is an <a href=
241-
"definitions.html#ntbs">ntbs</a>.</dt>
242-
243-
<dt><b>Effects:</b> The first form sets the package path of the module
244-
which supplies the type named by <code>type_name</code> to
245-
<code>package_path</code>. The second form restores the <a href=
246-
"#default_search">default search behavior</a>. The associated Python
247-
type will be searched for only the first time it is needed, and
248-
thereafter the first time it is needed after an invocation of
249-
<code>set_module_and_type</code>.</dt>
250-
</dl>
251-
252-
<h2><a name="examples"></a>Example</h2>
253-
<pre>
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>
254261
#include &lt;boost/python/numeric.hpp&gt;
255262
#include &lt;boost/python/tuple.hpp&gt;
256263

@@ -261,10 +268,9 @@ <h2><a name="examples"></a>Example</h2>
261268
}
262269
</pre>
263270

264-
<p>Revised 03 October, 2002</p>
271+
<p>Revised 07 October, 2006</p>
265272

266-
<p><i>&copy; Copyright <a href=
267-
"../../../../people/dave_abrahams.htm">Dave Abrahams</a> 2002.</i></p>
268-
</body>
273+
<p><i>&copy; Copyright <a href="../../../../people/dave_abrahams.htm">Dave
274+
Abrahams</a> 2002-2006.</i></p>
275+
</body>
269276
</html>
270-

0 commit comments

Comments
 (0)