diff options
author | Jarrod Millman <millman@berkeley.edu> | 2008-02-08 09:48:31 +0000 |
---|---|---|
committer | Jarrod Millman <millman@berkeley.edu> | 2008-02-08 09:48:31 +0000 |
commit | fb3f711f1a1eafb2895a84a80f88814d7fb9a465 (patch) | |
tree | aab6281c88fd6bed7c74df03562c197d934edd83 | |
parent | 2f3f1a8ef977fd04fc40d12ffd05903eb88c8635 (diff) | |
parent | 964727a2c475a7e48e262efc52b51345f51f2522 (diff) | |
download | numpy-fb3f711f1a1eafb2895a84a80f88814d7fb9a465.tar.gz |
Merge revisions 4721:4771 from the trunk
-rw-r--r-- | numpy/add_newdocs.py | 1 | ||||
-rw-r--r-- | numpy/core/src/arraytypes.inc.src | 2 | ||||
-rw-r--r-- | numpy/core/src/multiarraymodule.c | 22 | ||||
-rw-r--r-- | numpy/core/tests/test_regression.py | 9 | ||||
-rw-r--r-- | numpy/ctypeslib.py | 118 | ||||
-rw-r--r-- | numpy/doc/HOWTO_DOCUMENT.txt | 7 | ||||
-rw-r--r-- | numpy/doc/example.py | 3 | ||||
-rw-r--r-- | numpy/doc/html/example-module.html | 128 | ||||
-rw-r--r-- | numpy/doc/html/example-pysrc.html | 112 | ||||
-rw-r--r-- | numpy/doc/html/help.html | 2 | ||||
-rw-r--r-- | numpy/doc/html/identifier-index.html | 2 | ||||
-rw-r--r-- | numpy/doc/html/module-tree.html | 2 | ||||
-rwxr-xr-x | numpy/f2py/crackfortran.py | 10 | ||||
-rw-r--r-- | numpy/f2py/src/fortranobject.c | 23 | ||||
-rw-r--r-- | numpy/lib/function_base.py | 1 |
15 files changed, 296 insertions, 146 deletions
diff --git a/numpy/add_newdocs.py b/numpy/add_newdocs.py index 91c6a6e80..d727df234 100644 --- a/numpy/add_newdocs.py +++ b/numpy/add_newdocs.py @@ -216,6 +216,7 @@ add_newdoc('numpy.core.multiarray','fromstring', size is determined by the size of string. If sep is not empty then the string is interpreted in ASCII mode and converted to the desired number type using sep as the separator between elements (extra whitespace is ignored). + ASCII integer conversions are base-10; octal and hex are not supported. """) diff --git a/numpy/core/src/arraytypes.inc.src b/numpy/core/src/arraytypes.inc.src index cecf54bed..dbee57c33 100644 --- a/numpy/core/src/arraytypes.inc.src +++ b/numpy/core/src/arraytypes.inc.src @@ -935,7 +935,7 @@ static int { @btype@ result; - result = PyOS_strto@func@(str, endptr, 0); + result = PyOS_strto@func@(str, endptr, 10); *ip = (@type@) result; return 0; } diff --git a/numpy/core/src/multiarraymodule.c b/numpy/core/src/multiarraymodule.c index bcfed19d1..40b287715 100644 --- a/numpy/core/src/multiarraymodule.c +++ b/numpy/core/src/multiarraymodule.c @@ -3065,23 +3065,25 @@ PyArray_SearchSorted(PyArrayObject *op1, PyObject *op2, NPY_SEARCHSIDE side) PyArrayObject *ap1=NULL; PyArrayObject *ap2=NULL; PyArrayObject *ret=NULL; - int typenum = 0; + PyArray_Descr *dtype; NPY_BEGIN_THREADS_DEF - typenum = PyArray_ObjectType((PyObject *)op1, 0); - typenum = PyArray_ObjectType(op2, typenum); - + dtype = PyArray_DescrFromObject((PyObject *)op2, op1->descr); + /* need ap1 as contiguous array and of right type */ - ap1 = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)op1, - typenum, - 1, 1); - if (ap1 == NULL) + Py_INCREF(dtype); + ap1 = (PyArrayObject *)PyArray_FromAny((PyObject *)op1, dtype, + 1, 1, NPY_DEFAULT, NULL); + + if (ap1 == NULL) { + Py_DECREF(dtype); return NULL; + } /* need ap2 as contiguous array and of right type */ - ap2 = (PyArrayObject *)PyArray_ContiguousFromAny(op2, typenum, - 0, 0); + ap2 = (PyArrayObject *)PyArray_FromAny(op2, dtype, 0, 0, NPY_DEFAULT, NULL); + if (ap2 == NULL) goto fail; diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py index b9575bdf4..26cbfece1 100644 --- a/numpy/core/tests/test_regression.py +++ b/numpy/core/tests/test_regression.py @@ -771,5 +771,14 @@ class TestRegression(NumpyTestCase): def check_binary_repr_0_width(self, level=rlevel): assert_equal(np.binary_repr(0,width=3),'000') + def check_fromstring(self, level=rlevel): + assert_equal(np.fromstring("12:09:09", dtype=int, sep=":"), + [12,9,9]) + + def check_searchsorted_variable_length(self, level=rlevel): + x = np.array(['a','aa','b']) + y = np.array(['d','e']) + assert_equal(x.searchsorted(y), [3,3]) + if __name__ == "__main__": NumpyTest().run() diff --git a/numpy/ctypeslib.py b/numpy/ctypeslib.py index 82f6a91df..a6031607d 100644 --- a/numpy/ctypeslib.py +++ b/numpy/ctypeslib.py @@ -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 @@ if ctypes is None: 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 @@ def ndpointer(dtype=None, ndim=None, shape=None, flags=None): _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) diff --git a/numpy/doc/HOWTO_DOCUMENT.txt b/numpy/doc/HOWTO_DOCUMENT.txt index bb147068d..de5d0ce37 100644 --- a/numpy/doc/HOWTO_DOCUMENT.txt +++ b/numpy/doc/HOWTO_DOCUMENT.txt @@ -4,6 +4,8 @@ A Guide to NumPy/SciPy Documentation .. 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 @@ Currently, we recommend that you build epydoc from the trunk:: 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. diff --git a/numpy/doc/example.py b/numpy/doc/example.py index 0ae83d2bb..32a7e6602 100644 --- a/numpy/doc/example.py +++ b/numpy/doc/example.py @@ -8,6 +8,9 @@ extend over multiple lines, the closing three quotation marks must be on 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 diff --git a/numpy/doc/html/example-module.html b/numpy/doc/html/example-module.html index 7a9fdfd5a..f08370632 100644 --- a/numpy/doc/html/example-module.html +++ b/numpy/doc/html/example-module.html @@ -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 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 - ->>> a=[1,2,3] ->>> [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">>>> </span>a=[1,2,3] +<span class="py-prompt">>>> </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 @@ examples in doctest format </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 @@ examples in doctest format </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 @@ examples in doctest format <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" diff --git a/numpy/doc/html/example-pysrc.html b/numpy/doc/html/example-pysrc.html index ded35ac87..f771330e2 100644 --- a/numpy/doc/html/example-pysrc.html +++ b/numpy/doc/html/example-pysrc.html @@ -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"> >>> a=[1,2,3]</tt> </tt> @@ -182,7 +182,7 @@ expandto(location.href); <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" diff --git a/numpy/doc/html/help.html b/numpy/doc/html/help.html index 2329f20a7..b92302aeb 100644 --- a/numpy/doc/html/help.html +++ b/numpy/doc/html/help.html @@ -246,7 +246,7 @@ page was last updated. </p> <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" diff --git a/numpy/doc/html/identifier-index.html b/numpy/doc/html/identifier-index.html index 9a4fce613..c29b8c5c9 100644 --- a/numpy/doc/html/identifier-index.html +++ b/numpy/doc/html/identifier-index.html @@ -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" diff --git a/numpy/doc/html/module-tree.html b/numpy/doc/html/module-tree.html index 3a3dbc287..ad64d11b2 100644 --- a/numpy/doc/html/module-tree.html +++ b/numpy/doc/html/module-tree.html @@ -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" diff --git a/numpy/f2py/crackfortran.py b/numpy/f2py/crackfortran.py index 0e7dbd44c..48d1eaac5 100755 --- a/numpy/f2py/crackfortran.py +++ b/numpy/f2py/crackfortran.py @@ -791,7 +791,7 @@ def analyzeline(m,case,line): grouplist[groupcounter]=[] if needinterface: if verbose>1: - outmess('analyzeline: Creating additional interface block.\n',0) + outmess('analyzeline: Creating additional interface block (groupcounter=%s).\n' % (groupcounter),0) groupname[groupcounter]='interface' groupcache[groupcounter]['block']='interface' groupcache[groupcounter]['name']='unknown_interface' @@ -892,6 +892,7 @@ def analyzeline(m,case,line): pl = ch[0] outmess('analyzeline: cannot handle multiple attributes without type specification. Ignoring %r.\n' % (','.join(ch[1:]))) last_name = None + for e in [x.strip() for x in markoutercomma(ll).split('@,@')]: m1=namepattern.match(e) if not m1: @@ -910,11 +911,14 @@ def analyzeline(m,case,line): ap=m.group('this')+pl if _intentcallbackpattern.match(ap): if k not in groupcache[groupcounter]['args']: - if groupcounter>1 and \ - '__user__' in groupcache[groupcounter-2]['name']: + if groupcounter>1: outmess('analyzeline: appending intent(callback) %s'\ ' to %s arguments\n' % (k,groupcache[groupcounter]['name'])) + if '__user__' not in groupcache[groupcounter-2]['name']: + outmess('analyzeline: missing __user__ module (could be nothing)\n') groupcache[groupcounter]['args'].append(k) + else: + errmess('analyzeline: intent(callback) %s is ignored' % (k)) else: errmess('analyzeline: intent(callback) %s is already'\ ' in argument list' % (k)) diff --git a/numpy/f2py/src/fortranobject.c b/numpy/f2py/src/fortranobject.c index ff1eb6252..f6679665e 100644 --- a/numpy/f2py/src/fortranobject.c +++ b/numpy/f2py/src/fortranobject.c @@ -694,18 +694,20 @@ int check_and_fix_dimensions(const PyArrayObject* arr,const int rank,npy_intp *d 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 @@ int check_and_fix_dimensions(const PyArrayObject* arr,const int rank,npy_intp *d 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,6 +746,12 @@ int check_and_fix_dimensions(const PyArrayObject* arr,const int rank,npy_intp *d } 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; @@ -782,7 +791,7 @@ int check_and_fix_dimensions(const PyArrayObject* arr,const int rank,npy_intp *d } 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]); diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 711c609e8..ea6b5d8fb 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -151,6 +151,7 @@ def histogram(a, bins=10, range=None, normed=False): 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.' |