[Numpy-svn] r5768 - in trunk/numpy/core: src tests

numpy-svn@scip... numpy-svn@scip...
Thu Sep 4 13:04:43 CDT 2008


Author: ptvirtan
Date: 2008-09-04 13:04:35 -0500 (Thu, 04 Sep 2008)
New Revision: 5768

Modified:
   trunk/numpy/core/src/ufuncobject.c
   trunk/numpy/core/tests/test_umath.py
Log:
Ufunc docstrings: show the 'out' arguments in a more standard way

Modified: trunk/numpy/core/src/ufuncobject.c
===================================================================
--- trunk/numpy/core/src/ufuncobject.c	2008-09-04 16:29:09 UTC (rev 5767)
+++ trunk/numpy/core/src/ufuncobject.c	2008-09-04 18:04:35 UTC (rev 5768)
@@ -4046,19 +4046,20 @@
    y1,y2,...,yn
 */
 static PyObject *
-_makeargs(int num, char *ltr)
+_makeargs(int num, char *ltr, int null_if_none)
 {
     PyObject *str;
     int i;
     switch (num) {
     case 0:
+        if (null_if_none) return NULL;
         return PyString_FromString("");
     case 1:
         return PyString_FromString(ltr);
     }
-    str = PyString_FromFormat("%s1,%s2", ltr, ltr);
+    str = PyString_FromFormat("%s1, %s2", ltr, ltr);
     for(i = 3; i <= num; ++i) {
-        PyString_ConcatAndDel(&str, PyString_FromFormat(",%s%d", ltr, i));
+        PyString_ConcatAndDel(&str, PyString_FromFormat(", %s%d", ltr, i));
     }
     return str;
 }
@@ -4082,17 +4083,26 @@
     /* to automate the first part of it */
     /* the doc string shouldn't need the calling convention */
     /* construct
-       y1,y2,,... = name(x1,x2,...) __doc__
+       name(x1, x2, ...,[ out1, out2, ...])
+       
+       __doc__
     */
     PyObject *outargs, *inargs, *doc;
-    outargs = _makeargs(self->nout, "y");
-    inargs = _makeargs(self->nin, "x");
-    doc = PyString_FromFormat("%s = %s(%s)\n\n%s",
-                              PyString_AS_STRING(outargs),
-                              self->name,
-                              PyString_AS_STRING(inargs),
-                              self->doc);
-    Py_DECREF(outargs);
+    outargs = _makeargs(self->nout, "out", 1);
+    inargs = _makeargs(self->nin, "x", 0);
+    if (outargs == NULL) {
+        doc = PyString_FromFormat("%s(%s)\n\n%s",
+                                  self->name,
+                                  PyString_AS_STRING(inargs),
+                                  self->doc);
+    } else {
+        doc = PyString_FromFormat("%s(%s[, %s])\n\n%s",
+                                  self->name,
+                                  PyString_AS_STRING(inargs),
+                                  PyString_AS_STRING(outargs),
+                                  self->doc);
+        Py_DECREF(outargs);
+    }
     Py_DECREF(inargs);
     return doc;
 }

Modified: trunk/numpy/core/tests/test_umath.py
===================================================================
--- trunk/numpy/core/tests/test_umath.py	2008-09-04 16:29:09 UTC (rev 5767)
+++ trunk/numpy/core/tests/test_umath.py	2008-09-04 18:04:35 UTC (rev 5768)
@@ -271,7 +271,7 @@
     def test_attributes(self):
         add = ncu.add
         assert_equal(add.__name__, 'add')
-        assert add.__doc__.startswith('y = add(x1,x2)\n\n')
+        assert add.__doc__.startswith('add(x1, x2[, out])\n\n')
         self.failUnless(add.ntypes >= 18) # don't fail if types added
         self.failUnless('ii->i' in add.types)
         assert_equal(add.nin, 2)



More information about the Numpy-svn mailing list