8000 DOC: improvement of the documentation for gufunc. by mhvk · Pull Request #11177 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

DOC: improvement of the documentation for gufunc. #11177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions doc/source/reference/c-api.generalized-ufuncs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ Dimension Index
enumerates the dimension names according to the order of the first
occurrence of each name in the signature.

.. _details-of-signature:

Details of Signature
--------------------
Expand All @@ -126,9 +127,9 @@ The formal syntax of signatures is as follows::
<Output arguments> ::= <Argument list>
<Argument list> ::= nil | <Argument> | <Argument> "," <Argument list>
<Argument> ::= "(" <Core dimension list> ")"
<Core dimension list> ::= nil | <Dimension name> |
<Dimension name> "," <Core dimension list>
<Dimension name> ::= valid Python variable name
<Core dimension list> ::= nil | <Core dimension name> |
<Core dimension name> "," <Core dimension list>
<Core dimension name> ::= valid Python variable name


Notes:
Expand Down
26 changes: 19 additions & 7 deletions doc/source/reference/c-api.ufunc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,23 @@ Functions
the corresponding 1-d loop function in the func array.

:param types:
Must be of length (*nin* + *nout*) \* *ntypes*, and it
contains the data-types (built-in only) that the corresponding
function in the *func* array can deal with.
Length ``(nin + nout) * ntypes`` array of ``char`` encoding the
:ref:`PyArray_Descr.type_num` (built-in only) that the corresponding
function in the ``func`` array accepts. For instance, for a comparison
ufunc with three ``ntypes``, two ``nin`` and one ``nout``, where the
first function accepts :ref:`npy_int32` and the the second
:ref:`npy_int64`, with both returning :ref:`npy_bool`, ``types`` would
be ``(char[]) {5, 5, 0, 7, 7, 0}`` since ``NPY_INT32`` is 5,
``NPY_INT64`` is 7, and ``NPY_BOOL`` is 0 (on the python side, these
are exposed via :ref:`dtype.num`, i.e., for the example here,
``dtype(np.int32).num``, ``dtype(np.int64).num``, and
``dtype(np.bool_).num``, resp.).

:ref:`casting-rules` will be used at runtime to find the first
``func`` callable by the input/output provided.

:param ntypes:
How many different data-type "signatures" the ufunc has implemented.
How many different data-type-specific functions the ufunc has implemented.

:param nin:
The number of inputs to this operation.
Expand Down Expand Up @@ -129,10 +140,11 @@ Functions
int nin, int nout, int identity, char* name, char* doc, int unused, char *signature)

This function is very similar to PyUFunc_FromFuncAndData above, but has
an extra *signature* argument, to define generalized universal functions.
an extra *signature* argument, to define a
:ref:`generalized universal functions <c-api.generalized-ufuncs>`.
Similarly to how ufuncs are built around an element-by-element operation,
gufuncs are around subarray-by-subarray operations, the signature defining
the subarrays to operate on.
gufuncs are around subarray-by-subarray operations, the
:ref:`signature <details-of-signature>` defining the subarrays to operate on.

:param signature:
The signature for the new gufunc. Setting it to NULL is equivalent
Expand Down
4 changes: 2 additions & 2 deletions doc/source/reference/ufuncs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,8 @@ advanced usage and will not typically be used.
provided by the **types** attribute of the ufunc object. For backwards
compatibility this argument can also be provided as *sig*, although
the long form is preferred. Note that this should not be confused with
the generalized ufunc signature that is stored in the **signature**
attribute of the of the ufunc object.
the generalized ufunc :ref:`signature <details-of-signature>` that is
stored in the **signature** attribute of the of the ufunc object.

*extobj*

Expand Down
1 change: 1 addition & 0 deletions doc/source/user/c-info.ufunc-tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,7 @@ PyUFunc_FromFuncAndData Specification
What follows is the full specification of PyUFunc_FromFuncAndData, which
automatically generates a ufunc from a C function with the correct signature.

.. seealso:: :c:func:`PyUFunc_FromFuncAndDataAndSignature`

.. c:function:: PyObject *PyUFunc_FromFuncAndData( \
PyUFuncGenericFunction* func, void** data, char* types, int ntypes, \
Expand Down
2 changes: 1 addition & 1 deletion numpy/core/include/numpy/ufuncobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ typedef struct _tagPyUFuncObject {
int *core_dim_ixs;
/*
* positions of 1st core dimensions of each
* argument in core_dim_ixs
* argument in core_dim_ixs, equivalent to cumsum(core_num_dims)
*/
int *core_offsets;
/* signature string for printing purpose */
Expand Down
0