Hi,

I'd like to adjust the way numpy.core.umath ufunc docstrings are defined
to make them more easy to handle in the ongoing documentation marathon:

- Remove the signature magic in ufunc_get_doc
- Define ufunc docstrings in a separate module
  instead of in generate_umath.py, in the same format as in 
  add_newdocs.py

Suggested patch is attached; it passes numpy tests. Any thoughts on
whether it should go in?

I was also thinking about the problem with pydoc.help and ufuncs: would
making PyUFuncObject a subclass of PyFunctionObject be a reasonable fix?

        Pauli

diff -r 3f819a04782e numpy/core/code_generators/docstrings.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/numpy/core/code_generators/docstrings.py	Sat May 31 22:45:35 2008 +0300
@@ -0,0 +1,403 @@
+# Docstrings for ufuncs
+
+docdict = {}
+
+def get(name):
+    return docdict.get(name)
+
+def add_newdoc(place, name, doc):
+    docdict['.'.join((place, name))] = doc
+
+
+add_newdoc('numpy.core.umath', 'absolute',
+    """
+    y = absolute(x) takes |x| elementwise.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'add',
+    """
+    y = add(x1,x2) adds the arguments elementwise.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'arccos',
+    """
+    y = arccos(x) inverse cosine elementwise.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'arccosh',
+    """
+    y = arccosh(x) inverse hyperbolic cosine elementwise.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'arcsin',
+    """
+    y = arcsin(x) inverse sine elementwise.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'arcsinh',
+    """
+    y = arcsinh(x) inverse hyperbolic sine elementwise.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'arctan',
+    """
+    y = arctan(x) inverse tangent elementwise.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'arctan2',
+    """
+    y = arctan2(x1,x2) a safe and correct arctan(x1/x2)
+
+    """)
+
+add_newdoc('numpy.core.umath', 'arctanh',
+    """
+    y = arctanh(x) inverse hyperbolic tangent elementwise.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'bitwise_and',
+    """
+    y = bitwise_and(x1,x2) computes x1 & x2 elementwise.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'bitwise_or',
+    """
+    y = bitwise_or(x1,x2) computes x1 | x2 elementwise.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'bitwise_xor',
+    """
+    y = bitwise_xor(x1,x2) computes x1 ^ x2 elementwise.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'ceil',
+    """
+    y = ceil(x) elementwise smallest integer >= x.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'conjugate',
+    """
+    y = conjugate(x) takes the conjugate of x elementwise.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'cos',
+    """
+    y = cos(x) cosine elementwise.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'cosh',
+    """
+    y = cosh(x) hyperbolic cosine elementwise.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'degrees',
+    """
+    y = degrees(x) converts angle from radians to degrees
+
+    """)
+
+add_newdoc('numpy.core.umath', 'divide',
+    """
+    y = divide(x1,x2) divides the arguments elementwise.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'equal',
+    """
+    y = equal(x1,x2) returns elementwise x1 == x2 in a bool array
+
+    """)
+
+add_newdoc('numpy.core.umath', 'exp',
+    """
+    y = exp(x) e**x elementwise.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'expm1',
+    """
+    y = expm1(x) e**x-1 elementwise.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'fabs',
+    """
+    y = fabs(x) absolute values.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'floor',
+    """
+    y = floor(x) elementwise largest integer <= x
+
+    """)
+
+add_newdoc('numpy.core.umath', 'floor_divide',
+    """
+    y = floor_divide(x1,x2) floor divides the arguments elementwise.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'fmod',
+    """
+    y = fmod(x1,x2) computes (C-like) x1 % x2 elementwise.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'greater',
+    """
+    y = greater(x1,x2) returns elementwise x1 > x2 in a bool array.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'greater_equal',
+    """
+    y = greater_equal(x1,x2) returns elementwise x1 >= x2 in a bool array.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'hypot',
+    """
+    y = hypot(x1,x2) sqrt(x1**2 + x2**2) elementwise
+
+    """)
+
+add_newdoc('numpy.core.umath', 'invert',
+    """
+    y = invert(x) computes ~x (bit inversion) elementwise.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'isfinite',
+    """
+    y = isfinite(x) returns True where x is finite
+
+    """)
+
+add_newdoc('numpy.core.umath', 'isinf',
+    """
+    y = isinf(x) returns True where x is +inf or -inf
+
+    """)
+
+add_newdoc('numpy.core.umath', 'isnan',
+    """
+    y = isnan(x) returns True where x is Not-A-Number
+
+    """)
+
+add_newdoc('numpy.core.umath', 'left_shift',
+    """
+    y = left_shift(x1,x2) computes x1 << x2 (x1 shifted to left by x2 bits) elementwise.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'less',
+    """
+    y = less(x1,x2) returns elementwise x1 < x2 in a bool array.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'less_equal',
+    """
+    y = less_equal(x1,x2) returns elementwise x1 <= x2 in a bool array
+
+    """)
+
+add_newdoc('numpy.core.umath', 'log',
+    """
+    y = log(x) logarithm base e elementwise.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'log10',
+    """
+    y = log10(x) logarithm base 10 elementwise.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'log1p',
+    """
+    y = log1p(x) log(1+x) to base e elementwise.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'logical_and',
+    """
+    y = logical_and(x1,x2) returns x1 and x2 elementwise.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'logical_not',
+    """
+    y = logical_not(x) returns not x elementwise.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'logical_or',
+    """
+    y = logical_or(x1,x2) returns x1 or x2 elementwise.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'logical_xor',
+    """
+    y = logical_xor(x1,x2) returns x1 xor x2 elementwise.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'maximum',
+    """
+    y = maximum(x1,x2) returns maximum (if x1 > x2: x1;  else: x2) elementwise.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'minimum',
+    """
+    y = minimum(x1,x2) returns minimum (if x1 < x2: x1;  else: x2) elementwise
+
+    """)
+
+add_newdoc('numpy.core.umath', 'modf',
+    """
+    y1,y2 = modf(x) breaks x into fractional (y1) and integral (y2) parts.
+
+    Each output has the same sign as the input.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'multiply',
+    """
+    y = multiply(x1,x2) multiplies the arguments elementwise.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'negative',
+    """
+    y = negative(x) determines -x elementwise
+
+    """)
+
+add_newdoc('numpy.core.umath', 'not_equal',
+    """
+    y = not_equal(x1,x2) returns elementwise x1 |= x2
+
+    """)
+
+add_newdoc('numpy.core.umath', 'ones_like',
+    """
+    y = ones_like(x) returns an array of ones of the shape and typecode of x.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'power',
+    """
+    y = power(x1,x2) computes x1**x2 elementwise.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'radians',
+    """
+    y = radians(x) converts angle from degrees to radians
+
+    """)
+
+add_newdoc('numpy.core.umath', 'reciprocal',
+    """
+    y = reciprocal(x) compute 1/x
+
+    """)
+
+add_newdoc('numpy.core.umath', 'remainder',
+    """
+    y = remainder(x1,x2) computes x1-n*x2 where n is floor(x1 / x2)
+
+    """)
+
+add_newdoc('numpy.core.umath', 'right_shift',
+    """
+    y = right_shift(x1,x2) computes x1 >> x2 (x1 shifted to right by x2 bits) elementwise.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'rint',
+    """
+    y = rint(x) round x elementwise to the nearest integer, round halfway cases away from zero
+
+    """)
+
+add_newdoc('numpy.core.umath', 'sign',
+    """
+    y = sign(x) returns -1 if x < 0 and 0 if x==0 and 1 if x > 0
+
+    """)
+
+add_newdoc('numpy.core.umath', 'signbit',
+    """
+    y = signbit(x) returns True where signbit of x is set (x<0).
+
+    """)
+
+add_newdoc('numpy.core.umath', 'sin',
+    """
+    y = sin(x) sine elementwise.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'sinh',
+    """
+    y = sinh(x) hyperbolic sine elementwise.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'sqrt',
+    """
+    y = sqrt(x) square-root elementwise. For real x, the domain is restricted to x>=0.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'square',
+    """
+    y = square(x) compute x**2.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'subtract',
+    """
+    y = subtract(x1,x2) subtracts the arguments elementwise.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'tan',
+    """
+    y = tan(x) tangent elementwise.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'tanh',
+    """
+    y = tanh(x) hyperbolic tangent elementwise.
+
+    """)
+
+add_newdoc('numpy.core.umath', 'true_divide',
+    """
+    y = true_divide(x1,x2) true divides the arguments elementwise.
+
+    """)
+
diff -r 3f819a04782e numpy/core/code_generators/generate_umath.py
--- a/numpy/core/code_generators/generate_umath.py	Thu May 29 18:15:45 2008 +0300
+++ b/numpy/core/code_generators/generate_umath.py	Sat May 31 22:45:35 2008 +0300
@@ -1,4 +1,8 @@
-import re
+import re, textwrap
+import sys, os
+sys.path.insert(0, os.path.dirname(__file__))
+import docstrings
+sys.path.pop(0)
 
 Zero = "PyUFunc_Zero"
 One = "PyUFunc_One"
@@ -153,37 +157,37 @@
 defdict = {
 'add' :
     Ufunc(2, 1, Zero,
-          'adds the arguments elementwise.',
+          docstrings.get('numpy.core.umath.add'),
           TD(noobj),
           TD(O, f='PyNumber_Add'),
           ),
 'subtract' :
     Ufunc(2, 1, Zero,
-          'subtracts the arguments elementwise.',
+          docstrings.get('numpy.core.umath.subtract'),
           TD(noobj),
           TD(O, f='PyNumber_Subtract'),
           ),
 'multiply' :
     Ufunc(2, 1, One,
-          'multiplies the arguments elementwise.',
+          docstrings.get('numpy.core.umath.multiply'),
           TD(noobj),
           TD(O, f='PyNumber_Multiply'),
           ),
 'divide' :
     Ufunc(2, 1, One,
-          'divides the arguments elementwise.',
+          docstrings.get('numpy.core.umath.divide'),
           TD(intfltcmplx),
           TD(O, f='PyNumber_Divide'),
           ),
 'floor_divide' :
     Ufunc(2, 1, One,
-          'floor divides the arguments elementwise.',
+          docstrings.get('numpy.core.umath.floor_divide'),
           TD(intfltcmplx),
           TD(O, f='PyNumber_FloorDivide'),
           ),
 'true_divide' :
     Ufunc(2, 1, One,
-          'true divides the arguments elementwise.',
+          docstrings.get('numpy.core.umath.true_divide'),
           TD('bBhH', out='f'),
           TD('iIlLqQ', out='d'),
           TD(flts+cmplx),
@@ -191,346 +195,346 @@
           ),
 'conjugate' :
     Ufunc(1, 1, None,
-          'takes the conjugate of x elementwise.',
+          docstrings.get('numpy.core.umath.conjugate'),
           TD(nobool_or_obj),
           TD(M, f='conjugate'),
           ),
 'fmod' :
     Ufunc(2, 1, Zero,
-          'computes (C-like) x1 % x2 elementwise.',
+          docstrings.get('numpy.core.umath.fmod'),
           TD(ints),
           TD(flts, f='fmod'),
           TD(M, f='fmod'),
           ),
 'square' :
     Ufunc(1, 1, None,
-          'compute x**2.',
+          docstrings.get('numpy.core.umath.square'),
           TD(nobool_or_obj),
           TD(O, f='Py_square'),
           ),
 'reciprocal' :
     Ufunc(1, 1, None,
-          'compute 1/x',
+          docstrings.get('numpy.core.umath.reciprocal'),
           TD(nobool_or_obj),
           TD(O, f='Py_reciprocal'),
           ),
 'ones_like' :
     Ufunc(1, 1, None,
-          'returns an array of ones of the shape and typecode of x.',
+          docstrings.get('numpy.core.umath.ones_like'),
           TD(nobool_or_obj),
           TD(O, f='Py_get_one'),
           ),
 'power' :
     Ufunc(2, 1, One,
-          'computes x1**x2 elementwise.',
+          docstrings.get('numpy.core.umath.power'),
           TD(ints),
           TD(inexact, f='pow'),
           TD(O, f='PyNumber_Power'),
           ),
 'absolute' :
     Ufunc(1, 1, None,
-          'takes |x| elementwise.',
+          docstrings.get('numpy.core.umath.absolute'),
           TD(nocmplx),
           TD(cmplx, out=('f', 'd', 'g')),
           TD(O, f='PyNumber_Absolute'),
           ),
 'negative' :
     Ufunc(1, 1, None,
-          'determines -x elementwise',
+          docstrings.get('numpy.core.umath.negative'),
           TD(nocmplx),
           TD(cmplx, f='neg'),
           TD(O, f='PyNumber_Negative'),
           ),
 'sign' :
     Ufunc(1, 1, None,
-          'returns -1 if x < 0 and 0 if x==0 and 1 if x > 0',
+          docstrings.get('numpy.core.umath.sign'),
           TD(nobool),
           ),
 'greater' :
     Ufunc(2, 1, None,
-          'returns elementwise x1 > x2 in a bool array.',
+          docstrings.get('numpy.core.umath.greater'),
           TD(all, out='?'),
           ),
 'greater_equal' :
     Ufunc(2, 1, None,
-          'returns elementwise x1 >= x2 in a bool array.',
+          docstrings.get('numpy.core.umath.greater_equal'),
           TD(all, out='?'),
           ),
 'less' :
     Ufunc(2, 1, None,
-          'returns elementwise x1 < x2 in a bool array.',
+          docstrings.get('numpy.core.umath.less'),
           TD(all, out='?'),
           ),
 'less_equal' :
     Ufunc(2, 1, None,
-          'returns elementwise x1 <= x2 in a bool array',
+          docstrings.get('numpy.core.umath.less_equal'),
           TD(all, out='?'),
           ),
 'equal' :
     Ufunc(2, 1, None,
-          'returns elementwise x1 == x2 in a bool array',
+          docstrings.get('numpy.core.umath.equal'),
           TD(all, out='?'),
           ),
 'not_equal' :
     Ufunc(2, 1, None,
-          'returns elementwise x1 |= x2',
+          docstrings.get('numpy.core.umath.not_equal'),
           TD(all, out='?'),
           ),
 'logical_and' :
     Ufunc(2, 1, One,
-          'returns x1 and x2 elementwise.',
+          docstrings.get('numpy.core.umath.logical_and'),
           TD(noobj, out='?'),
           TD(M, f='logical_and'),
           ),
 'logical_not' :
     Ufunc(1, 1, None,
-          'returns not x elementwise.',
+          docstrings.get('numpy.core.umath.logical_not'),
           TD(noobj, out='?'),
           TD(M, f='logical_not'),
           ),
 'logical_or' :
     Ufunc(2, 1, Zero,
-          'returns x1 or x2 elementwise.',
+          docstrings.get('numpy.core.umath.logical_or'),
           TD(noobj, out='?'),
           TD(M, f='logical_or'),
           ),
 'logical_xor' :
     Ufunc(2, 1, None,
-          'returns x1 xor x2 elementwise.',
+          docstrings.get('numpy.core.umath.logical_xor'),
           TD(noobj, out='?'),
           TD(M, f='logical_xor'),
           ),
 'maximum' :
     Ufunc(2, 1, None,
-          'returns maximum (if x1 > x2: x1;  else: x2) elementwise.',
+          docstrings.get('numpy.core.umath.maximum'),
           TD(noobj),
           TD(O, f='_npy_ObjectMax')
           ),
 'minimum' :
     Ufunc(2, 1, None,
-          'returns minimum (if x1 < x2: x1;  else: x2) elementwise',
+          docstrings.get('numpy.core.umath.minimum'),
           TD(noobj),
           TD(O, f='_npy_ObjectMin')
           ),
 'bitwise_and' :
     Ufunc(2, 1, One,
-          'computes x1 & x2 elementwise.',
+          docstrings.get('numpy.core.umath.bitwise_and'),
           TD(bints),
           TD(O, f='PyNumber_And'),
           ),
 'bitwise_or' :
     Ufunc(2, 1, Zero,
-          'computes x1 | x2 elementwise.',
+          docstrings.get('numpy.core.umath.bitwise_or'),
           TD(bints),
           TD(O, f='PyNumber_Or'),
           ),
 'bitwise_xor' :
     Ufunc(2, 1, None,
-          'computes x1 ^ x2 elementwise.',
+          docstrings.get('numpy.core.umath.bitwise_xor'),
           TD(bints),
           TD(O, f='PyNumber_Xor'),
           ),
 'invert' :
     Ufunc(1, 1, None,
-          'computes ~x (bit inversion) elementwise.',
+          docstrings.get('numpy.core.umath.invert'),
           TD(bints),
           TD(O, f='PyNumber_Invert'),
           ),
 'left_shift' :
     Ufunc(2, 1, None,
-          'computes x1 << x2 (x1 shifted to left by x2 bits) elementwise.',
+          docstrings.get('numpy.core.umath.left_shift'),
           TD(ints),
           TD(O, f='PyNumber_Lshift'),
           ),
 'right_shift' :
     Ufunc(2, 1, None,
-          'computes x1 >> x2 (x1 shifted to right by x2 bits) elementwise.',
+          docstrings.get('numpy.core.umath.right_shift'),
           TD(ints),
           TD(O, f='PyNumber_Rshift'),
           ),
 'degrees' :
     Ufunc(1, 1, None,
-          'converts angle from radians to degrees',
+          docstrings.get('numpy.core.umath.degrees'),
           TD(fltsM, f='degrees'),
           ),
 'radians' :
     Ufunc(1, 1, None,
-          'converts angle from degrees to radians',
+          docstrings.get('numpy.core.umath.radians'),
           TD(fltsM, f='radians'),
           ),
 'arccos' :
     Ufunc(1, 1, None,
-          'inverse cosine elementwise.',
+          docstrings.get('numpy.core.umath.arccos'),
           TD(inexact, f='acos'),
           TD(M, f='arccos'),
           ),
 'arccosh' :
     Ufunc(1, 1, None,
-          'inverse hyperbolic cosine elementwise.',
+          docstrings.get('numpy.core.umath.arccosh'),
           TD(inexact, f='acosh'),
           TD(M, f='arccosh'),
           ),
 'arcsin' :
     Ufunc(1, 1, None,
-          'inverse sine elementwise.',
+          docstrings.get('numpy.core.umath.arcsin'),
           TD(inexact, f='asin'),
           TD(M, f='arcsin'),
           ),
 'arcsinh' :
     Ufunc(1, 1, None,
-          'inverse hyperbolic sine elementwise.',
+          docstrings.get('numpy.core.umath.arcsinh'),
           TD(inexact, f='asinh'),
           TD(M, f='arcsinh'),
           ),
 'arctan' :
     Ufunc(1, 1, None,
-          'inverse tangent elementwise.',
+          docstrings.get('numpy.core.umath.arctan'),
           TD(inexact, f='atan'),
           TD(M, f='arctan'),
           ),
 'arctanh' :
     Ufunc(1, 1, None,
-          'inverse hyperbolic tangent elementwise.',
+          docstrings.get('numpy.core.umath.arctanh'),
           TD(inexact, f='atanh'),
           TD(M, f='arctanh'),
           ),
 'cos' :
     Ufunc(1, 1, None,
-          'cosine elementwise.',
+          docstrings.get('numpy.core.umath.cos'),
           TD(inexact, f='cos'),
           TD(M, f='cos'),
           ),
 'sin' :
     Ufunc(1, 1, None,
-          'sine elementwise.',
+          docstrings.get('numpy.core.umath.sin'),
           TD(inexact, f='sin'),
           TD(M, f='sin'),
           ),
 'tan' :
     Ufunc(1, 1, None,
-          'tangent elementwise.',
+          docstrings.get('numpy.core.umath.tan'),
           TD(inexact, f='tan'),
           TD(M, f='tan'),
           ),
 'cosh' :
     Ufunc(1, 1, None,
-          'hyperbolic cosine elementwise.',
+          docstrings.get('numpy.core.umath.cosh'),
           TD(inexact, f='cosh'),
           TD(M, f='cosh'),
           ),
 'sinh' :
     Ufunc(1, 1, None,
-          'hyperbolic sine elementwise.',
+          docstrings.get('numpy.core.umath.sinh'),
           TD(inexact, f='sinh'),
           TD(M, f='sinh'),
           ),
 'tanh' :
     Ufunc(1, 1, None,
-          'hyperbolic tangent elementwise.',
+          docstrings.get('numpy.core.umath.tanh'),
           TD(inexact, f='tanh'),
           TD(M, f='tanh'),
           ),
 'exp' :
     Ufunc(1, 1, None,
-          'e**x elementwise.',
+          docstrings.get('numpy.core.umath.exp'),
           TD(inexact, f='exp'),
           TD(M, f='exp'),
           ),
 'expm1' :
     Ufunc(1, 1, None,
-          'e**x-1 elementwise.',
+          docstrings.get('numpy.core.umath.expm1'),
           TD(inexact, f='expm1'),
           TD(M, f='expm1'),
           ),
 'log' :
     Ufunc(1, 1, None,
-          'logarithm base e elementwise.',
+          docstrings.get('numpy.core.umath.log'),
           TD(inexact, f='log'),
           TD(M, f='log'),
           ),
 'log10' :
     Ufunc(1, 1, None,
-          'logarithm base 10 elementwise.',
+          docstrings.get('numpy.core.umath.log10'),
           TD(inexact, f='log10'),
           TD(M, f='log10'),
           ),
 'log1p' :
     Ufunc(1, 1, None,
-          'log(1+x) to base e elementwise.',
+          docstrings.get('numpy.core.umath.log1p'),
           TD(inexact, f='log1p'),
           TD(M, f='log1p'),
           ),
 'sqrt' :
     Ufunc(1, 1, None,
-          'square-root elementwise. For real x, the domain is restricted to x>=0.',
+          docstrings.get('numpy.core.umath.sqrt'),
           TD(inexact, f='sqrt'),
           TD(M, f='sqrt'),
           ),
 'ceil' :
     Ufunc(1, 1, None,
-          'elementwise smallest integer >= x.',
+          docstrings.get('numpy.core.umath.ceil'),
           TD(flts, f='ceil'),
           TD(M, f='ceil'),
           ),
 'fabs' :
     Ufunc(1, 1, None,
-          'absolute values.',
+          docstrings.get('numpy.core.umath.fabs'),
           TD(flts, f='fabs'),
           TD(M, f='fabs'),
        ),
 'floor' :
     Ufunc(1, 1, None,
-          'elementwise largest integer <= x',
+          docstrings.get('numpy.core.umath.floor'),
           TD(flts, f='floor'),
           TD(M, f='floor'),
           ),
 'rint' :
     Ufunc(1, 1, None,
-          'round x elementwise to the nearest integer, round halfway cases away from zero',
+          docstrings.get('numpy.core.umath.rint'),
           TD(inexact, f='rint'),
           TD(M, f='rint'),
           ),
 'arctan2' :
     Ufunc(2, 1, None,
-          'a safe and correct arctan(x1/x2)',
+          docstrings.get('numpy.core.umath.arctan2'),
           TD(flts, f='atan2'),
           TD(M, f='arctan2'),
           ),
 'remainder' :
     Ufunc(2, 1, None,
-          'computes x1-n*x2 where n is floor(x1 / x2)',
+          docstrings.get('numpy.core.umath.remainder'),
           TD(intflt),
           TD(O, f='PyNumber_Remainder'),
           ),
 'hypot' :
     Ufunc(2, 1, None,
-          'sqrt(x1**2 + x2**2) elementwise',
+          docstrings.get('numpy.core.umath.hypot'),
           TD(flts, f='hypot'),
           TD(M, f='hypot'),
           ),
 'isnan' :
     Ufunc(1, 1, None,
-          'returns True where x is Not-A-Number',
+          docstrings.get('numpy.core.umath.isnan'),
           TD(inexact, out='?'),
           ),
 'isinf' :
     Ufunc(1, 1, None,
-          'returns True where x is +inf or -inf',
+          docstrings.get('numpy.core.umath.isinf'),
           TD(inexact, out='?'),
           ),
 'isfinite' :
     Ufunc(1, 1, None,
-          'returns True where x is finite',
+          docstrings.get('numpy.core.umath.isfinite'),
           TD(inexact, out='?'),
           ),
 'signbit' :
     Ufunc(1, 1, None,
-          'returns True where signbit of x is set (x<0).',
+          docstrings.get('numpy.core.umath.signbit'),
           TD(flts, out='?'),
           ),
 'modf' :
     Ufunc(1, 2, None,
-          'breaks x into fractional (y1) and integral (y2) parts.\\n\\n    Each output has the same sign as the input.',
+          docstrings.get('numpy.core.umath.modf'),
           TD(flts),
           ),
 }
@@ -667,6 +671,8 @@
     for name in names:
         uf = funcdict[name]
         mlist = []
+        docstring = textwrap.dedent(uf.docstring).strip()
+        docstring = docstring.encode('string-escape').replace(r'"', r'\"')
         mlist.append(\
 r"""f = PyUFunc_FromFuncAndData(%s_functions, %s_data, %s_signatures, %d,
                                 %d, %d, %s, "%s",
@@ -674,7 +680,7 @@
                                                 len(uf.type_descriptions),
                                                 uf.nin, uf.nout,
                                                 uf.identity,
-                                                name, uf.docstring))
+                                                name, docstring))
         mlist.append(r"""PyDict_SetItemString(dictionary, "%s", f);""" % name)
         mlist.append(r"""Py_DECREF(f);""")
         code3list.append('\n'.join(mlist))
diff -r 3f819a04782e numpy/core/src/ufuncobject.c
--- a/numpy/core/src/ufuncobject.c	Thu May 29 18:15:45 2008 +0300
+++ b/numpy/core/src/ufuncobject.c	Sat May 31 22:45:35 2008 +0300
@@ -3962,27 +3962,6 @@
 
 
 
-/* construct the string
-   y1,y2,...,yn
-*/
-static PyObject *
-_makeargs(int num, char *ltr)
-{
-    PyObject *str;
-    int i;
-    switch (num) {
-    case 0:
-        return PyString_FromString("");
-    case 1:
-        return PyString_FromString(ltr);
-    }
-    str = PyString_FromFormat("%s1,%s2", ltr, ltr);
-    for(i = 3; i <= num; ++i) {
-        PyString_ConcatAndDel(&str, PyString_FromFormat(",%s%d", ltr, i));
-    }
-    return str;
-}
-
 static char
 _typecharfromnum(int num) {
     PyArray_Descr *descr;
@@ -3997,24 +3976,7 @@
 static PyObject *
 ufunc_get_doc(PyUFuncObject *self)
 {
-    /* Put docstring first or FindMethod finds it...*/
-    /* could so some introspection on name and nin + nout */
-    /* to automate the first part of it */
-    /* the doc string shouldn't need the calling convention */
-    /* construct
-       y1,y2,,... = name(x1,x2,...) __doc__
-    */
-    PyObject *outargs, *inargs, *doc;
-    outargs = _makeargs(self->nout, "y");
-    inargs = _makeargs(self->nin, "x");
-    doc = PyString_FromFormat("%s = %s(%s) %s",
-                              PyString_AS_STRING(outargs),
-                              self->name,
-                              PyString_AS_STRING(inargs),
-                              self->doc);
-    Py_DECREF(outargs);
-    Py_DECREF(inargs);
-    return doc;
+    return PyString_FromString(self->doc);
 }
 
 static PyObject *

Attachment: signature.asc
Description: Digitaalisesti allekirjoitettu viestin osa

_______________________________________________
Numpy-discussion mailing list
[email protected]
http://projects.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to