[Numpy-svn] r4759 - in branches/maskedarray/numpy: . doc doc/html f2py/src lib

numpy-svn@scip... numpy-svn@scip...
Mon Jan 28 17:15:19 CST 2008


Author: stefan
Date: 2008-01-28 17:14:08 -0600 (Mon, 28 Jan 2008)
New Revision: 4759

Modified:
   branches/maskedarray/numpy/ctypeslib.py
   branches/maskedarray/numpy/doc/HOWTO_DOCUMENT.txt
   branches/maskedarray/numpy/doc/example.py
   branches/maskedarray/numpy/doc/html/example-module.html
   branches/maskedarray/numpy/doc/html/example-pysrc.html
   branches/maskedarray/numpy/doc/html/help.html
   branches/maskedarray/numpy/doc/html/identifier-index.html
   branches/maskedarray/numpy/doc/html/module-tree.html
   branches/maskedarray/numpy/f2py/src/fortranobject.c
   branches/maskedarray/numpy/lib/function_base.py
Log:
Merge maskedarray branch to r4758.


Modified: branches/maskedarray/numpy/ctypeslib.py
===================================================================
--- branches/maskedarray/numpy/ctypeslib.py	2008-01-28 22:45:54 UTC (rev 4758)
+++ branches/maskedarray/numpy/ctypeslib.py	2008-01-28 23:14:08 UTC (rev 4759)
@@ -1,8 +1,8 @@
 __all__ = ['load_library', 'ndpointer', 'test', 'ctypes_load_library',
-           'c_intp']
+           'c_intp', 'as_ctypes', 'as_array']
 
 import sys, os
-from numpy import integer, ndarray, dtype as _dtype, deprecate
+from numpy import integer, ndarray, dtype as _dtype, deprecate, array
 from numpy.core.multiarray import _flagdict, flagsobj
 
 try:
@@ -15,6 +15,8 @@
         raise ImportError, "ctypes is not available."
     ctypes_load_library = _dummy
     load_library = _dummy
+    as_ctypes = _dummy
+    as_array = _dummy
     from numpy import intp as c_intp
 else:
     import numpy.core._internal as nic
@@ -160,6 +162,118 @@
     _pointer_type_cache[dtype] = klass
     return klass
 
+if ctypes is not None:
+    ct = ctypes
+    ################################################################
+    # simple types
+
+    # maps the numpy typecodes like '<f8' to simple ctypes types like
+    # c_double. Filled in by prep_simple.
+    _typecodes = {}
+
+    def prep_simple(simple_type, typestr):
+        """Given a ctypes simple type, construct and attach an
+        __array_interface__ property to it if it does not yet have one.
+        """
+        try: simple_type.__array_interface__
+        except AttributeError: pass
+        else: return
+
+        _typecodes[typestr] = simple_type
+
+        def __array_interface__(self):
+            return {'descr': [('', typestr)],
+                    '__ref': self,
+                    'strides': None,
+                    'shape': (),
+                    'version': 3,
+                    'typestr': typestr,
+                    'data': (ct.addressof(self), False),
+                    }
+
+        simple_type.__array_interface__ = property(__array_interface__)
+
+    if sys.byteorder == "little":
+        TYPESTR = "<%c%d"
+    else:
+        TYPESTR = ">%c%d"
+
+    simple_types = [
+        ((ct.c_byte, ct.c_short, ct.c_int, ct.c_long, ct.c_longlong), "i"),
+        ((ct.c_ubyte, ct.c_ushort, ct.c_uint, ct.c_ulong, ct.c_ulonglong), "u"),
+        ((ct.c_float, ct.c_double), "f"),
+    ]
+
+    # Prep that numerical ctypes types:
+    for types, code in simple_types:
+        for tp in types:
+            prep_simple(tp, TYPESTR % (code, ct.sizeof(tp)))
+
+    ################################################################
+    # array types
+
+    _ARRAY_TYPE = type(ct.c_int * 1)
+
+    def prep_array(array_type):
+        """Given a ctypes array type, construct and attach an
+        __array_interface__ property to it if it does not yet have one.
+        """
+        try: array_type.__array_interface__
+        except AttributeError: pass
+        else: return
+
+        shape = []
+        ob = array_type
+        while type(ob) == _ARRAY_TYPE:
+            shape.append(ob._length_)
+            ob = ob._type_
+        shape = tuple(shape)
+        ai = ob().__array_interface__
+        descr = ai['descr']
+        typestr = ai['typestr']
+
+        def __array_interface__(self):
+            return {'descr': descr,
+                    '__ref': self,
+                    'strides': None,
+                    'shape': shape,
+                    'version': 3,
+                    'typestr': typestr,
+                    'data': (ct.addressof(self), False),
+                    }
+
+        array_type.__array_interface__ = property(__array_interface__)
+
+    ################################################################
+    # public functions
+
+    def as_array(obj):
+        """Create a numpy array from a ctypes array.  The numpy array
+        shares the memory with the ctypes object."""
+        tp = type(obj)
+        try: tp.__array_interface__
+        except AttributeError: prep_array(tp)
+        return array(obj, copy=False)
+
+    def as_ctypes(obj):
+        """Create and return a ctypes object from a numpy array.  Actually
+        anything that exposes the __array_interface__ is accepted."""
+        ai = obj.__array_interface__
+        if ai["strides"]:
+            raise TypeError("strided arrays not supported")
+        if ai["version"] != 3:
+            raise TypeError("only __array_interface__ version 3 supported")
+        addr, readonly = ai["data"]
+        if readonly:
+            raise TypeError("readonly arrays unsupported")
+        tp = _typecodes[ai["typestr"]]
+        for dim in ai["shape"][::-1]:
+            tp = tp * dim
+        result = tp.from_address(addr)
+        result.__keep = ai
+        return result
+
+
 def test(level=1, verbosity=1):
     from numpy.testing import NumpyTest
     return NumpyTest().test(level, verbosity)

Modified: branches/maskedarray/numpy/doc/HOWTO_DOCUMENT.txt
===================================================================
--- branches/maskedarray/numpy/doc/HOWTO_DOCUMENT.txt	2008-01-28 22:45:54 UTC (rev 4758)
+++ branches/maskedarray/numpy/doc/HOWTO_DOCUMENT.txt	2008-01-28 23:14:08 UTC (rev 4759)
@@ -4,6 +4,8 @@
 
 .. Contents::
 
+.. Attention:: This document is slightly out of date.  During the December 2007 sprint, Travis Oliphant made some changes to the NumPy/SciPy docstring standard.  The changes are relatively minor, but the standard no longer follows the epydoc/restructured text standards.  The changes brings our docstring standard more in line with the ETS standard; in addition, it also conserves horizontal real-estate and arguably looks better when printed as plain text.  Unfortunately, these changes mean that currently it isn't possible to render the docstrings as desired.  Travis has committed to writing something to render the docstrings.  At that point, we will update this document to correspond with the new standard.  For now, just refer to: `example.py <http://svn.scipy.org/svn/numpy/trunk/numpy/doc/example.py>`__
+
 Overview
 --------
 In general, we follow the standard Python style conventions as described here:
@@ -158,6 +160,11 @@
   cd epydoc/src
   sudo python setup.py install
 
+Since we use reST-formatted docstrings instead of the epytext markup, you will
+need to include the following line near the top of your module::
+
+    __docformat__ = "restructuredtext en"
+
 The appearance of some elements can be changed in the epydoc.css
 style sheet. 
 

Modified: branches/maskedarray/numpy/doc/example.py
===================================================================
--- branches/maskedarray/numpy/doc/example.py	2008-01-28 22:45:54 UTC (rev 4758)
+++ branches/maskedarray/numpy/doc/example.py	2008-01-28 23:14:08 UTC (rev 4759)
@@ -8,6 +8,9 @@
 a line by itself, preferably preceeded by a blank line.
 
 """
+# Make sure this line is here such that epydoc 3 can parse the docstrings for
+# auto-generated documentation.
+__docformat__ = "restructuredtext en"
 
 import os                      # standard library imports first
 

Modified: branches/maskedarray/numpy/doc/html/example-module.html
===================================================================
--- branches/maskedarray/numpy/doc/html/example-module.html	2008-01-28 22:45:54 UTC (rev 4758)
+++ branches/maskedarray/numpy/doc/html/example-module.html	2008-01-28 23:14:08 UTC (rev 4759)
@@ -56,12 +56,12 @@
 <!-- ==================== MODULE DESCRIPTION ==================== -->
 <h1 class="epydoc">Module example</h1><p class="nomargin-top"><span class="codelink"><a href="example-pysrc.html">source&nbsp;code</a></span></p>
 <p>This is the docstring for the example.py module.  Modules names should
-  have short, all-lowercase names.  The module name may have underscores if
-  this improves readability.</p>
-  <p>Every module should have a docstring at the very top of the file.  The
-  module's docstring may extend over multiple lines.  If your docstring 
-  does extend over multiple lines, the closing three quotation marks must 
-  be on a line by itself, preferably preceeded by a blank line.</p>
+have short, all-lowercase names.  The module name may have underscores if
+this improves readability.</p>
+<p>Every module should have a docstring at the very top of the file.  The
+module's docstring may extend over multiple lines.  If your docstring does
+extend over multiple lines, the closing three quotation marks must be on
+a line by itself, preferably preceeded by a blank line.</p>
 
 <!-- ==================== FUNCTIONS ==================== -->
 <a name="section-Functions"></a>
@@ -168,61 +168,61 @@
     </td>
   </tr></table>
   
-  <pre class="literalblock">
-One-line summary or signature.
-
-Several sentences providing an extended description. You can put
-text in mono-spaced type like so: ``var``.
-
-Parameters
-----------
-var1 : array_like
-    Array_like means all those objects -- lists, nested lists, etc. --
-    that can be converted to an array.
-var2 : integer
-    Write out the full type
-long_variable_name : {'hi', 'ho'}, optional
-    Choices in brackets, default first when optional.
-
-Returns
--------
-named : type
-    Explanation
-list
-    Explanation
-of
-    Explanation
-outputs
-    even more explaining
-
-Other Parameters
-----------------
-only_seldom_used_keywords : type
-    Explanation
-common_parametrs_listed_above : type
-    Explanation
-
-See Also
---------    
-otherfunc : relationship (optional)
-newfunc : relationship (optional)
-
-Notes
------
-Notes about the implementation algorithm (if needed).
-
-This can have multiple paragraphs as can all sections.
-
-Examples
---------
-
-examples in doctest format
-
-&gt;&gt;&gt; a=[1,2,3]
-&gt;&gt;&gt; [x + 3 for x in a]
-[4, 5, 6]
-
-</pre>
+  <p>One-line summary or signature.</p>
+<p>Several sentences providing an extended description. You can put
+text in mono-spaced type like so: <tt class="rst-docutils literal"><span class="pre">var</span></tt>.</p>
+<div class="rst-section" id="rst-parameters">
+<h1 class="heading">Parameters</h1>
+<dl class="rst-docutils">
+<dt>var1 <span class="classifier-delimiter">:</span> <span class="rst-classifier">array_like</span></dt>
+<dd>Array_like means all those objects -- lists, nested lists, etc. --
+that can be converted to an array.</dd>
+<dt>var2 <span class="classifier-delimiter">:</span> <span class="rst-classifier">integer</span></dt>
+<dd>Write out the full type</dd>
+<dt>long_variable_name <span class="classifier-delimiter">:</span> <span class="rst-classifier">{'hi', 'ho'}, optional</span></dt>
+<dd>Choices in brackets, default first when optional.</dd>
+</dl>
+</div>
+<div class="rst-section" id="rst-returns">
+<h1 class="heading">Returns</h1>
+<dl class="rst-docutils">
+<dt>named <span class="classifier-delimiter">:</span> <span class="rst-classifier">type</span></dt>
+<dd>Explanation</dd>
+<dt>list</dt>
+<dd>Explanation</dd>
+<dt>of</dt>
+<dd>Explanation</dd>
+<dt>outputs</dt>
+<dd>even more explaining</dd>
+</dl>
+</div>
+<div class="rst-section" id="rst-other-parameters">
+<h1 class="heading">Other Parameters</h1>
+<dl class="rst-docutils">
+<dt>only_seldom_used_keywords <span class="classifier-delimiter">:</span> <span class="rst-classifier">type</span></dt>
+<dd>Explanation</dd>
+<dt>common_parametrs_listed_above <span class="classifier-delimiter">:</span> <span class="rst-classifier">type</span></dt>
+<dd>Explanation</dd>
+</dl>
+</div>
+<div class="rst-section" id="rst-see-also">
+<h1 class="heading">See Also</h1>
+<p>otherfunc : relationship (optional)
+newfunc : relationship (optional)</p>
+</div>
+<div class="rst-section" id="rst-notes">
+<h1 class="heading">Notes</h1>
+<p>Notes about the implementation algorithm (if needed).</p>
+<p>This can have multiple paragraphs as can all sections.</p>
+</div>
+<div class="rst-section" id="rst-examples">
+<h1 class="heading">Examples</h1>
+<p>examples in doctest format</p>
+<pre class="py-doctest">
+<span class="py-prompt">&gt;&gt;&gt; </span>a=[1,2,3]
+<span class="py-prompt">&gt;&gt;&gt; </span>[x + 3 <span class="py-keyword">for</span> x <span class="py-keyword">in</span> a]
+<span class="py-output">[4, 5, 6]</span></pre>
+</div>
   <dl class="fields">
   </dl>
 </td></tr></table>
@@ -242,7 +242,7 @@
   </tr></table>
   
   <p>Do nothing.</p>
-  <p>I never saw a purple cow.</p>
+<p>I never saw a purple cow.</p>
   <dl class="fields">
   </dl>
 </td></tr></table>
@@ -262,7 +262,7 @@
   </tr></table>
   
   <p>Do nothing.</p>
-  <p>I never hope to see one.</p>
+<p>I never hope to see one.</p>
   <dl class="fields">
   </dl>
 </td></tr></table>
@@ -294,7 +294,7 @@
 <table border="0" cellpadding="0" cellspacing="0" width="100%%">
   <tr>
     <td align="left" class="footer">
-    Generated by Epydoc 3.0beta1 on Fri Dec 28 00:50:17 2007
+    Generated by Epydoc 3.0beta1 on Tue Jan 22 00:26:36 2008
     </td>
     <td align="right" class="footer">
       <a target="mainFrame" href="http://epydoc.sourceforge.net"

Modified: branches/maskedarray/numpy/doc/html/example-pysrc.html
===================================================================
--- branches/maskedarray/numpy/doc/html/example-pysrc.html	2008-01-28 22:45:54 UTC (rev 4758)
+++ branches/maskedarray/numpy/doc/html/example-pysrc.html	2008-01-28 23:14:08 UTC (rev 4759)
@@ -65,61 +65,61 @@
 <a name="L8"></a><tt class="py-lineno"> 8</tt>  <tt class="py-line"><tt class="py-docstring">a line by itself, preferably preceeded by a blank line.</tt> </tt>
 <a name="L9"></a><tt class="py-lineno"> 9</tt>  <tt class="py-line"><tt class="py-docstring"></tt> </tt>
 <a name="L10"></a><tt class="py-lineno">10</tt>  <tt class="py-line"><tt class="py-docstring">"""</tt> </tt>
-<a name="L11"></a><tt class="py-lineno">11</tt>  <tt class="py-line"> </tt>
-<a name="L12"></a><tt class="py-lineno">12</tt>  <tt class="py-line"><tt class="py-keyword">import</tt> <tt class="py-name">os</tt>                      <tt class="py-comment"># standard library imports first</tt> </tt>
-<a name="L13"></a><tt class="py-lineno">13</tt>  <tt class="py-line"> </tt>
-<a name="L14"></a><tt class="py-lineno">14</tt>  <tt class="py-line"><tt class="py-keyword">import</tt> <tt class="py-name">numpy</tt> <tt class="py-keyword">as</tt> <tt class="py-name">np</tt>             <tt class="py-comment"># related third party imports next</tt> </tt>
-<a name="L15"></a><tt class="py-lineno">15</tt>  <tt class="py-line"><tt class="py-keyword">import</tt> <tt class="py-name">scipy</tt> <tt class="py-keyword">as</tt> <tt class="py-name">sp</tt>             <tt class="py-comment"># imports should be at the top of the module</tt> </tt>
-<a name="L16"></a><tt class="py-lineno">16</tt>  <tt class="py-line"><tt class="py-keyword">import</tt> <tt class="py-name">matplotlib</tt> <tt class="py-keyword">as</tt> <tt class="py-name">mpl</tt>       <tt class="py-comment"># imports should usually be on separate lines</tt> </tt>
-<a name="L17"></a><tt class="py-lineno">17</tt>  <tt class="py-line"> </tt>
-<a name="foo"></a><div id="foo-def"><a name="L18"></a><tt class="py-lineno">18</tt> <a class="py-toggle" href="#" id="foo-toggle" onclick="return toggle('foo');">-</a><tt class="py-line"><tt class="py-keyword">def</tt> <a class="py-def-name" href="example-module.html#foo">foo</a><tt class="py-op">(</tt><tt class="py-param">var1</tt><tt class="py-op">,</tt> <tt class="py-param">var2</tt><tt class="py-op">,</tt> <tt class="py-param">long_var_name</tt><tt class="py-op">=</tt><tt class="py-string">'hi'</tt><tt class="py-op">)</tt> <tt class="py-op">:</tt> </tt>
-</div><div id="foo-collapsed" style="display:none;" pad="++" indent="++++"></div><div id="foo-expanded"><a name="L19"></a><tt class="py-lineno">19</tt>  <tt class="py-line">    <tt class="py-docstring">"""One-line summary or signature.</tt> </tt>
-<a name="L20"></a><tt class="py-lineno">20</tt>  <tt class="py-line"><tt class="py-docstring"></tt> </tt>
-<a name="L21"></a><tt class="py-lineno">21</tt>  <tt class="py-line"><tt class="py-docstring">    Several sentences providing an extended description. You can put</tt> </tt>
-<a name="L22"></a><tt class="py-lineno">22</tt>  <tt class="py-line"><tt class="py-docstring">    text in mono-spaced type like so: ``var``.</tt> </tt>
-<a name="L23"></a><tt class="py-lineno">23</tt>  <tt class="py-line"><tt class="py-docstring"></tt> </tt>
-<a name="L24"></a><tt class="py-lineno">24</tt>  <tt class="py-line"><tt class="py-docstring">    Parameters</tt> </tt>
-<a name="L25"></a><tt class="py-lineno">25</tt>  <tt class="py-line"><tt class="py-docstring">    ----------</tt> </tt>
-<a name="L26"></a><tt class="py-lineno">26</tt>  <tt class="py-line"><tt class="py-docstring">    var1 : array_like</tt> </tt>
-<a name="L27"></a><tt class="py-lineno">27</tt>  <tt class="py-line"><tt class="py-docstring">        Array_like means all those objects -- lists, nested lists, etc. --</tt> </tt>
-<a name="L28"></a><tt class="py-lineno">28</tt>  <tt class="py-line"><tt class="py-docstring">        that can be converted to an array.</tt> </tt>
-<a name="L29"></a><tt class="py-lineno">29</tt>  <tt class="py-line"><tt class="py-docstring">    var2 : integer</tt> </tt>
-<a name="L30"></a><tt class="py-lineno">30</tt>  <tt class="py-line"><tt class="py-docstring">        Write out the full type</tt> </tt>
-<a name="L31"></a><tt class="py-lineno">31</tt>  <tt class="py-line"><tt class="py-docstring">    long_variable_name : {'hi', 'ho'}, optional</tt> </tt>
-<a name="L32"></a><tt class="py-lineno">32</tt>  <tt class="py-line"><tt class="py-docstring">        Choices in brackets, default first when optional.</tt> </tt>
-<a name="L33"></a><tt class="py-lineno">33</tt>  <tt class="py-line"><tt class="py-docstring"></tt> </tt>
-<a name="L34"></a><tt class="py-lineno">34</tt>  <tt class="py-line"><tt class="py-docstring">    Returns</tt> </tt>
-<a name="L35"></a><tt class="py-lineno">35</tt>  <tt class="py-line"><tt class="py-docstring">    -------</tt> </tt>
-<a name="L36"></a><tt class="py-lineno">36</tt>  <tt class="py-line"><tt class="py-docstring">    named : type</tt> </tt>
-<a name="L37"></a><tt class="py-lineno">37</tt>  <tt class="py-line"><tt class="py-docstring">        Explanation</tt> </tt>
-<a name="L38"></a><tt class="py-lineno">38</tt>  <tt class="py-line"><tt class="py-docstring">    list</tt> </tt>
-<a name="L39"></a><tt class="py-lineno">39</tt>  <tt class="py-line"><tt class="py-docstring">        Explanation</tt> </tt>
-<a name="L40"></a><tt class="py-lineno">40</tt>  <tt class="py-line"><tt class="py-docstring">    of</tt> </tt>
-<a name="L41"></a><tt class="py-lineno">41</tt>  <tt class="py-line"><tt class="py-docstring">        Explanation</tt> </tt>
-<a name="L42"></a><tt class="py-lineno">42</tt>  <tt class="py-line"><tt class="py-docstring">    outputs</tt> </tt>
-<a name="L43"></a><tt class="py-lineno">43</tt>  <tt class="py-line"><tt class="py-docstring">        even more explaining</tt> </tt>
-<a name="L44"></a><tt class="py-lineno">44</tt>  <tt class="py-line"><tt class="py-docstring"></tt> </tt>
-<a name="L45"></a><tt class="py-lineno">45</tt>  <tt class="py-line"><tt class="py-docstring">    Other Parameters</tt> </tt>
-<a name="L46"></a><tt class="py-lineno">46</tt>  <tt class="py-line"><tt class="py-docstring">    ----------------</tt> </tt>
-<a name="L47"></a><tt class="py-lineno">47</tt>  <tt class="py-line"><tt class="py-docstring">    only_seldom_used_keywords : type</tt> </tt>
-<a name="L48"></a><tt class="py-lineno">48</tt>  <tt class="py-line"><tt class="py-docstring">        Explanation</tt> </tt>
-<a name="L49"></a><tt class="py-lineno">49</tt>  <tt class="py-line"><tt class="py-docstring">    common_parametrs_listed_above : type</tt> </tt>
-<a name="L50"></a><tt class="py-lineno">50</tt>  <tt class="py-line"><tt class="py-docstring">        Explanation</tt> </tt>
-<a name="L51"></a><tt class="py-lineno">51</tt>  <tt class="py-line"><tt class="py-docstring"></tt> </tt>
-<a name="L52"></a><tt class="py-lineno">52</tt>  <tt class="py-line"><tt class="py-docstring">    See Also</tt> </tt>
-<a name="L53"></a><tt class="py-lineno">53</tt>  <tt class="py-line"><tt class="py-docstring">    --------    </tt> </tt>
-<a name="L54"></a><tt class="py-lineno">54</tt>  <tt class="py-line"><tt class="py-docstring">    otherfunc : relationship (optional)</tt> </tt>
-<a name="L55"></a><tt class="py-lineno">55</tt>  <tt class="py-line"><tt class="py-docstring">    newfunc : relationship (optional)</tt> </tt>
-<a name="L56"></a><tt class="py-lineno">56</tt>  <tt class="py-line"><tt class="py-docstring"></tt> </tt>
-<a name="L57"></a><tt class="py-lineno">57</tt>  <tt class="py-line"><tt class="py-docstring">    Notes</tt> </tt>
-<a name="L58"></a><tt class="py-lineno">58</tt>  <tt class="py-line"><tt class="py-docstring">    -----</tt> </tt>
-<a name="L59"></a><tt class="py-lineno">59</tt>  <tt class="py-line"><tt class="py-docstring">    Notes about the implementation algorithm (if needed).</tt> </tt>
-<a name="L60"></a><tt class="py-lineno">60</tt>  <tt class="py-line"><tt class="py-docstring"></tt> </tt>
-<a name="L61"></a><tt class="py-lineno">61</tt>  <tt class="py-line"><tt class="py-docstring">    This can have multiple paragraphs as can all sections.</tt> </tt>
-<a name="L62"></a><tt class="py-lineno">62</tt>  <tt class="py-line"><tt class="py-docstring"></tt> </tt>
-<a name="L63"></a><tt class="py-lineno">63</tt>  <tt class="py-line"><tt class="py-docstring">    Examples</tt> </tt>
-<a name="L64"></a><tt class="py-lineno">64</tt>  <tt class="py-line"><tt class="py-docstring">    --------</tt> </tt>
-<a name="L65"></a><tt class="py-lineno">65</tt>  <tt class="py-line"><tt class="py-docstring"></tt> </tt>
+<a name="L11"></a><tt class="py-lineno">11</tt>  <tt class="py-line"><tt class="py-name">__docformat__</tt> <tt class="py-op">=</tt> <tt class="py-string">"restructuredtext en"</tt> </tt>
+<a name="L12"></a><tt class="py-lineno">12</tt>  <tt class="py-line"> </tt>
+<a name="L13"></a><tt class="py-lineno">13</tt>  <tt class="py-line"><tt class="py-keyword">import</tt> <tt class="py-name">os</tt>                      <tt class="py-comment"># standard library imports first</tt> </tt>
+<a name="L14"></a><tt class="py-lineno">14</tt>  <tt class="py-line"> </tt>
+<a name="L15"></a><tt class="py-lineno">15</tt>  <tt class="py-line"><tt class="py-keyword">import</tt> <tt class="py-name">numpy</tt> <tt class="py-keyword">as</tt> <tt class="py-name">np</tt>             <tt class="py-comment"># related third party imports next</tt> </tt>
+<a name="L16"></a><tt class="py-lineno">16</tt>  <tt class="py-line"><tt class="py-keyword">import</tt> <tt class="py-name">scipy</tt> <tt class="py-keyword">as</tt> <tt class="py-name">sp</tt>             <tt class="py-comment"># imports should be at the top of the module</tt> </tt>
+<a name="L17"></a><tt class="py-lineno">17</tt>  <tt class="py-line"><tt class="py-keyword">import</tt> <tt class="py-name">matplotlib</tt> <tt class="py-keyword">as</tt> <tt class="py-name">mpl</tt>       <tt class="py-comment"># imports should usually be on separate lines</tt> </tt>
+<a name="L18"></a><tt class="py-lineno">18</tt>  <tt class="py-line"> </tt>
+<a name="foo"></a><div id="foo-def"><a name="L19"></a><tt class="py-lineno">19</tt> <a class="py-toggle" href="#" id="foo-toggle" onclick="return toggle('foo');">-</a><tt class="py-line"><tt class="py-keyword">def</tt> <a class="py-def-name" href="example-module.html#foo">foo</a><tt class="py-op">(</tt><tt class="py-param">var1</tt><tt class="py-op">,</tt> <tt class="py-param">var2</tt><tt class="py-op">,</tt> <tt class="py-param">long_var_name</tt><tt class="py-op">=</tt><tt class="py-string">'hi'</tt><tt class="py-op">)</tt> <tt class="py-op">:</tt> </tt>
+</div><div id="foo-collapsed" style="display:none;" pad="++" indent="++++"></div><div id="foo-expanded"><a name="L20"></a><tt class="py-lineno">20</tt>  <tt class="py-line">    <tt class="py-docstring">"""One-line summary or signature.</tt> </tt>
+<a name="L21"></a><tt class="py-lineno">21</tt>  <tt class="py-line"><tt class="py-docstring"></tt> </tt>
+<a name="L22"></a><tt class="py-lineno">22</tt>  <tt class="py-line"><tt class="py-docstring">    Several sentences providing an extended description. You can put</tt> </tt>
+<a name="L23"></a><tt class="py-lineno">23</tt>  <tt class="py-line"><tt class="py-docstring">    text in mono-spaced type like so: ``var``.</tt> </tt>
+<a name="L24"></a><tt class="py-lineno">24</tt>  <tt class="py-line"><tt class="py-docstring"></tt> </tt>
+<a name="L25"></a><tt class="py-lineno">25</tt>  <tt class="py-line"><tt class="py-docstring">    Parameters</tt> </tt>
+<a name="L26"></a><tt class="py-lineno">26</tt>  <tt class="py-line"><tt class="py-docstring">    ----------</tt> </tt>
+<a name="L27"></a><tt class="py-lineno">27</tt>  <tt class="py-line"><tt class="py-docstring">    var1 : array_like</tt> </tt>
+<a name="L28"></a><tt class="py-lineno">28</tt>  <tt class="py-line"><tt class="py-docstring">        Array_like means all those objects -- lists, nested lists, etc. --</tt> </tt>
+<a name="L29"></a><tt class="py-lineno">29</tt>  <tt class="py-line"><tt class="py-docstring">        that can be converted to an array.</tt> </tt>
+<a name="L30"></a><tt class="py-lineno">30</tt>  <tt class="py-line"><tt class="py-docstring">    var2 : integer</tt> </tt>
+<a name="L31"></a><tt class="py-lineno">31</tt>  <tt class="py-line"><tt class="py-docstring">        Write out the full type</tt> </tt>
+<a name="L32"></a><tt class="py-lineno">32</tt>  <tt class="py-line"><tt class="py-docstring">    long_variable_name : {'hi', 'ho'}, optional</tt> </tt>
+<a name="L33"></a><tt class="py-lineno">33</tt>  <tt class="py-line"><tt class="py-docstring">        Choices in brackets, default first when optional.</tt> </tt>
+<a name="L34"></a><tt class="py-lineno">34</tt>  <tt class="py-line"><tt class="py-docstring"></tt> </tt>
+<a name="L35"></a><tt class="py-lineno">35</tt>  <tt class="py-line"><tt class="py-docstring">    Returns</tt> </tt>
+<a name="L36"></a><tt class="py-lineno">36</tt>  <tt class="py-line"><tt class="py-docstring">    -------</tt> </tt>
+<a name="L37"></a><tt class="py-lineno">37</tt>  <tt class="py-line"><tt class="py-docstring">    named : type</tt> </tt>
+<a name="L38"></a><tt class="py-lineno">38</tt>  <tt class="py-line"><tt class="py-docstring">        Explanation</tt> </tt>
+<a name="L39"></a><tt class="py-lineno">39</tt>  <tt class="py-line"><tt class="py-docstring">    list</tt> </tt>
+<a name="L40"></a><tt class="py-lineno">40</tt>  <tt class="py-line"><tt class="py-docstring">        Explanation</tt> </tt>
+<a name="L41"></a><tt class="py-lineno">41</tt>  <tt class="py-line"><tt class="py-docstring">    of</tt> </tt>
+<a name="L42"></a><tt class="py-lineno">42</tt>  <tt class="py-line"><tt class="py-docstring">        Explanation</tt> </tt>
+<a name="L43"></a><tt class="py-lineno">43</tt>  <tt class="py-line"><tt class="py-docstring">    outputs</tt> </tt>
+<a name="L44"></a><tt class="py-lineno">44</tt>  <tt class="py-line"><tt class="py-docstring">        even more explaining</tt> </tt>
+<a name="L45"></a><tt class="py-lineno">45</tt>  <tt class="py-line"><tt class="py-docstring"></tt> </tt>
+<a name="L46"></a><tt class="py-lineno">46</tt>  <tt class="py-line"><tt class="py-docstring">    Other Parameters</tt> </tt>
+<a name="L47"></a><tt class="py-lineno">47</tt>  <tt class="py-line"><tt class="py-docstring">    ----------------</tt> </tt>
+<a name="L48"></a><tt class="py-lineno">48</tt>  <tt class="py-line"><tt class="py-docstring">    only_seldom_used_keywords : type</tt> </tt>
+<a name="L49"></a><tt class="py-lineno">49</tt>  <tt class="py-line"><tt class="py-docstring">        Explanation</tt> </tt>
+<a name="L50"></a><tt class="py-lineno">50</tt>  <tt class="py-line"><tt class="py-docstring">    common_parametrs_listed_above : type</tt> </tt>
+<a name="L51"></a><tt class="py-lineno">51</tt>  <tt class="py-line"><tt class="py-docstring">        Explanation</tt> </tt>
+<a name="L52"></a><tt class="py-lineno">52</tt>  <tt class="py-line"><tt class="py-docstring"></tt> </tt>
+<a name="L53"></a><tt class="py-lineno">53</tt>  <tt class="py-line"><tt class="py-docstring">    See Also</tt> </tt>
+<a name="L54"></a><tt class="py-lineno">54</tt>  <tt class="py-line"><tt class="py-docstring">    --------    </tt> </tt>
+<a name="L55"></a><tt class="py-lineno">55</tt>  <tt class="py-line"><tt class="py-docstring">    otherfunc : relationship (optional)</tt> </tt>
+<a name="L56"></a><tt class="py-lineno">56</tt>  <tt class="py-line"><tt class="py-docstring">    newfunc : relationship (optional)</tt> </tt>
+<a name="L57"></a><tt class="py-lineno">57</tt>  <tt class="py-line"><tt class="py-docstring"></tt> </tt>
+<a name="L58"></a><tt class="py-lineno">58</tt>  <tt class="py-line"><tt class="py-docstring">    Notes</tt> </tt>
+<a name="L59"></a><tt class="py-lineno">59</tt>  <tt class="py-line"><tt class="py-docstring">    -----</tt> </tt>
+<a name="L60"></a><tt class="py-lineno">60</tt>  <tt class="py-line"><tt class="py-docstring">    Notes about the implementation algorithm (if needed).</tt> </tt>
+<a name="L61"></a><tt class="py-lineno">61</tt>  <tt class="py-line"><tt class="py-docstring"></tt> </tt>
+<a name="L62"></a><tt class="py-lineno">62</tt>  <tt class="py-line"><tt class="py-docstring">    This can have multiple paragraphs as can all sections.</tt> </tt>
+<a name="L63"></a><tt class="py-lineno">63</tt>  <tt class="py-line"><tt class="py-docstring"></tt> </tt>
+<a name="L64"></a><tt class="py-lineno">64</tt>  <tt class="py-line"><tt class="py-docstring">    Examples</tt> </tt>
+<a name="L65"></a><tt class="py-lineno">65</tt>  <tt class="py-line"><tt class="py-docstring">    --------</tt> </tt>
 <a name="L66"></a><tt class="py-lineno">66</tt>  <tt class="py-line"><tt class="py-docstring">    examples in doctest format</tt> </tt>
 <a name="L67"></a><tt class="py-lineno">67</tt>  <tt class="py-line"><tt class="py-docstring"></tt> </tt>
 <a name="L68"></a><tt class="py-lineno">68</tt>  <tt class="py-line"><tt class="py-docstring">    &gt;&gt;&gt; a=[1,2,3]</tt> </tt>
@@ -182,7 +182,7 @@
 <table border="0" cellpadding="0" cellspacing="0" width="100%%">
   <tr>
     <td align="left" class="footer">
-    Generated by Epydoc 3.0beta1 on Fri Dec 28 00:50:17 2007
+    Generated by Epydoc 3.0beta1 on Tue Jan 22 00:26:36 2008
     </td>
     <td align="right" class="footer">
       <a target="mainFrame" href="http://epydoc.sourceforge.net"

Modified: branches/maskedarray/numpy/doc/html/help.html
===================================================================
--- branches/maskedarray/numpy/doc/html/help.html	2008-01-28 22:45:54 UTC (rev 4758)
+++ branches/maskedarray/numpy/doc/html/help.html	2008-01-28 23:14:08 UTC (rev 4759)
@@ -246,7 +246,7 @@
 <table border="0" cellpadding="0" cellspacing="0" width="100%%">
   <tr>
     <td align="left" class="footer">
-    Generated by Epydoc 3.0beta1 on Fri Dec 28 00:50:17 2007
+    Generated by Epydoc 3.0beta1 on Tue Jan 22 00:26:36 2008
     </td>
     <td align="right" class="footer">
       <a target="mainFrame" href="http://epydoc.sourceforge.net"

Modified: branches/maskedarray/numpy/doc/html/identifier-index.html
===================================================================
--- branches/maskedarray/numpy/doc/html/identifier-index.html	2008-01-28 22:45:54 UTC (rev 4758)
+++ branches/maskedarray/numpy/doc/html/identifier-index.html	2008-01-28 23:14:08 UTC (rev 4759)
@@ -158,7 +158,7 @@
 <table border="0" cellpadding="0" cellspacing="0" width="100%%">
   <tr>
     <td align="left" class="footer">
-    Generated by Epydoc 3.0beta1 on Fri Dec 28 00:50:17 2007
+    Generated by Epydoc 3.0beta1 on Tue Jan 22 00:26:36 2008
     </td>
     <td align="right" class="footer">
       <a target="mainFrame" href="http://epydoc.sourceforge.net"

Modified: branches/maskedarray/numpy/doc/html/module-tree.html
===================================================================
--- branches/maskedarray/numpy/doc/html/module-tree.html	2008-01-28 22:45:54 UTC (rev 4758)
+++ branches/maskedarray/numpy/doc/html/module-tree.html	2008-01-28 23:14:08 UTC (rev 4759)
@@ -79,7 +79,7 @@
 <table border="0" cellpadding="0" cellspacing="0" width="100%%">
   <tr>
     <td align="left" class="footer">
-    Generated by Epydoc 3.0beta1 on Fri Dec 28 00:50:17 2007
+    Generated by Epydoc 3.0beta1 on Tue Jan 22 00:26:36 2008
     </td>
     <td align="right" class="footer">
       <a target="mainFrame" href="http://epydoc.sourceforge.net"

Modified: branches/maskedarray/numpy/f2py/src/fortranobject.c
===================================================================
--- branches/maskedarray/numpy/f2py/src/fortranobject.c	2008-01-28 22:45:54 UTC (rev 4758)
+++ branches/maskedarray/numpy/f2py/src/fortranobject.c	2008-01-28 23:14:08 UTC (rev 4759)
@@ -694,18 +694,20 @@
         npy_intp new_size = 1;
         int free_axe = -1;
         int i;
+        npy_intp d;
         /* Fill dims where -1 or 0; check dimensions; calc new_size; */
         for(i=0;i<arr->nd;++i) {
+            d = arr->dimensions[i];
             if (dims[i] >= 0) {
-                if (dims[i]!=arr->dimensions[i]) {
+                if (d>1 && dims[i]!=d) {
                     fprintf(stderr,"%d-th dimension must be fixed to %" NPY_INTP_FMT
                             " but got %" NPY_INTP_FMT "\n",
-                            i,dims[i], arr->dimensions[i]);
+                            i,dims[i], d);
                     return 1;
                 }
                 if (!dims[i]) dims[i] = 1;
             } else {
-                dims[i] = arr->dimensions[i] ? arr->dimensions[i] : 1;
+                dims[i] = d ? d : 1;
             }
             new_size *= dims[i];
         }
@@ -724,16 +726,17 @@
             new_size *= dims[free_axe];
         }
         if (new_size != arr_size) {
-            fprintf(stderr,"confused: new_size=%" NPY_INTP_FMT
-                    ", arr_size=%" NPY_INTP_FMT " (maybe too many free"
+            fprintf(stderr,"unexpected array size: new_size=%" NPY_INTP_FMT
+                    ", got array with arr_size=%" NPY_INTP_FMT " (maybe too many free"
                     " indices)\n", new_size,arr_size);
             return 1;
         }
     } else if (rank==arr->nd) {
+        npy_intp new_size = 1;
         int i;
         npy_intp d;
         for (i=0; i<rank; ++i) {
-            d = arr->dimensions[i];
+	    d = arr->dimensions[i];
             if (dims[i]>=0) {
                 if (d > 1 && d!=dims[i]) {
                     fprintf(stderr,"%d-th dimension must be fixed to %" NPY_INTP_FMT
@@ -743,7 +746,13 @@
                 }
                 if (!dims[i]) dims[i] = 1;
             } else dims[i] = d;
+            new_size *= dims[i];
         }
+        if (new_size != arr_size) {
+            fprintf(stderr,"unexpected array size: new_size=%" NPY_INTP_FMT
+                    ", got array with arr_size=%" NPY_INTP_FMT "\n", new_size,arr_size);
+            return 1;
+        }
     } else { /* [[1,2]] -> [[1],[2]] */
         int i,j;
         npy_intp d;
@@ -782,7 +791,7 @@
         }
         for (i=0,size=1;i<rank;++i) size *= dims[i];
         if (size != arr_size) {
-            fprintf(stderr,"confused: size=%" NPY_INTP_FMT ", arr_size=%" NPY_INTP_FMT
+            fprintf(stderr,"unexpected array size: size=%" NPY_INTP_FMT ", arr_size=%" NPY_INTP_FMT
                     ", rank=%d, effrank=%d, arr.nd=%d, dims=[",
                     size,arr_size,rank,effrank,arr->nd);
             for (i=0;i<rank;++i) fprintf(stderr," %" NPY_INTP_FMT,dims[i]);

Modified: branches/maskedarray/numpy/lib/function_base.py
===================================================================
--- branches/maskedarray/numpy/lib/function_base.py	2008-01-28 22:45:54 UTC (rev 4758)
+++ branches/maskedarray/numpy/lib/function_base.py	2008-01-28 23:14:08 UTC (rev 4759)
@@ -151,6 +151,7 @@
             mx += 0.5
         bins = linspace(mn, mx, bins, endpoint=False)
     else:
+        bins = asarray(bins)
         if(any(bins[1:]-bins[:-1] < 0)):
             raise AttributeError, 'bins must increase monotonically.'
 



More information about the Numpy-svn mailing list