summaryrefslogtreecommitdiff
path: root/numpy/core/_internal.py
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2017-04-29 21:40:21 +0100
committerEric Wieser <wieser.eric@gmail.com>2017-05-08 01:26:29 +0100
commit476ce747b407a18f5c4dea618953b0ea9419fd2b (patch)
treee888f908688143293ca674acb20f86f044c1d87c /numpy/core/_internal.py
parent11f3ebf86a16452d0af40b41925b201485ae7f9c (diff)
downloadnumpy-476ce747b407a18f5c4dea618953b0ea9419fd2b.tar.gz
DOC: Show full argument lists for ufuncs
Diffstat (limited to 'numpy/core/_internal.py')
-rw-r--r--numpy/core/_internal.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/numpy/core/_internal.py b/numpy/core/_internal.py
index d8d9168ac..bd5a5f22b 100644
--- a/numpy/core/_internal.py
+++ b/numpy/core/_internal.py
@@ -670,3 +670,48 @@ def array_ufunc_errmsg_formatter(ufunc, method, *inputs, **kwargs):
return ('operand type(s) do not implement __array_ufunc__'
'({!r}, {!r}, {}): {}'
.format(ufunc, method, args_string, types_string))
+
+def _ufunc_doc_signature_formatter(ufunc):
+ """
+ Builds a signature string which resembles PEP 457
+
+ This is used to construct the first line of the docstring
+ """
+
+ # input arguments are simple
+ if ufunc.nin == 1:
+ in_args = 'x'
+ else:
+ in_args = ', '.join('x{}'.format(i+1) for i in range(ufunc.nin))
+
+ # output arguments are both keyword or positional
+ if ufunc.nout == 0:
+ out_args = ', /, out=()'
+ elif ufunc.nout == 1:
+ out_args = ', /, out=None'
+ else:
+ out_args = '[, {positional}], / [, out={default}]'.format(
+ positional=', '.join(
+ 'out{}'.format(i+1) for i in range(ufunc.nout)),
+ default=repr((None,)*ufunc.nout)
+ )
+
+ # keyword only args depend on whether this is a gufunc
+ kwargs = (
+ ", casting='same_kind'"
+ ", order='K'"
+ ", dtype=None"
+ ", subok=True"
+ "[, signature"
+ ", extobj]"
+ )
+ if ufunc.signature is None:
+ kwargs = ", where=True" + kwargs
+
+ # join all the parts together
+ return '{name}({in_args}{out_args}, *{kwargs})'.format(
+ name=ufunc.__name__,
+ in_args=in_args,
+ out_args=out_args,
+ kwargs=kwargs
+ )