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

Conversation

mhvk
Copy link
Contributor
@mhvk mhvk commented May 28, 2018

Cherry-picked part of #11132, which is nice & independent of the enhancement proposed there.

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.
Int8 of length `(nin + nout) * ntypes` It encodes the :ref:`dtype.num`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Int8 is only true on some platforms, where char is signed.

Might be better to refer to PyArray_Descr.type_num here, since that's the C-side name. Could refer to both.

(built-in only) that the corresponding function in the `func` array
accepts. For a ufunc with two `ntypes`, one `nin` and one `nout` where
the first function accepts and returns `int32` and the second accepts
and returns `int64`, `types` would be `\05\05\07\07` since `int32.num`
Copy link
Member
@eric-wieser eric-wieser May 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double backticks for code snippets.

Would be clearer here to say types would be ``(char[]) {5, 5, 7, 7}`` , I think - no need to reference a string literal

accepts. For a ufunc with two `ntypes`, one `nin` and one `nout` where
the first function accepts and returns `int32` and the second accepts
and returns `int64`, `types` would be `\05\05\07\07` since `int32.num`
is 5 and `int64.num` is 7.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potentially misleading - this is np.dtype(np.int64).num, not np.int64.num

@mhvk
Copy link
Contributor Author
mhvk commented May 28, 2018

All good points; adjusted.

contains the data-types (built-in only) that the corresponding
function in the *func* array can deal with.

Char of length ``(nin + nout) * ntypes`` It encodes the
Copy link
Member
@eric-wieser eric-wieser May 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Char array would be clearer. capitalizing Char looks weird too.

Could take advantage of C 2d arrays here, and write this as ``char[ntypes][nin+nout]`` array

Copy link
Contributor < 10000 span data-view-component="true" class="Label ml-1">Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like it in principle, but as this is not done anywhere in the code, it may lead to confusion...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose I'll have to make a patch at some point to make it so we do do that in the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would definitely make the definitions a lot clearer!

function in the ``func`` array accepts. For a ufunc with two
``ntypes``, one ``nin`` and one ``nout`` where the first function
accepts and returns ``int32`` and the second accepts and returns
``int64``, ``types`` would be ``(char[]) {5, 5, 7, 7}`` since
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the 2d notation above, this becomes (char[2][2]) {{5, 5}, {7, 7}};. To break symmetry between the 2s, I'd be inclined to use a binary op as an example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'll use a comparison as an example instead.

@mhvk mhvk force-pushed the gufunc-docs-improvement branch from f73b118 to 8ca8b0a Compare May 28, 2018 18:22
10000
instance, for a comparison ufunc with three ``ntypes``, two
``nin`` and one ``nout``, where the first function accepts
``int32`` and the the second ``int64``, with both returning
booleans (``unsigned char``), ``types`` would be ``(char[])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(``unsigned char``) is just wrong here. NPY_BOOL is its own type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I got this from

grep npy_bool numpy/core/include/numpy/*.h
.
.
.
numpy/core/include/numpy/npy_common.h:typedef unsigned char npy_bool;

Copy link
Member
@eric-wieser eric-wieser May 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NPY_BOOL is the enum value, which is distinct from NPY_UCHAR - even if the same underlying C type is used to represent them, at the numpy level they are different.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the description is a bit hinging on different things. One passes to the function definition those NPY_ names, but inside the routine one would use npy_bool, npy_int32,64, etc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just change your description to use npy_int32 and npy_bool - then you don't need to explain what those typedefs mean. If you single-backtick them, they might link to their definitions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and that also shows recommended practice, so better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the npy_* are indeed linkable, though I cannot seem to build the docs - get a very helpful error message...

ValueError: The section Notes appears twice in the docstring of None in None.

Bit beyond this PR...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mhvk Hmm, last time I saw that error it was because masked array was modifying docstrings. I think that was fixed.

@mhvk mhvk force-pushed the gufunc-docs-improvement branch from 8ca8b0a to d7f4eef Compare May 29, 2018 13:55
@eric-wieser eric-wieser merged commit 6246cf1 into numpy:master May 29, 2018
@mhvk mhvk deleted the gufunc-docs-improvement branch May 29, 2018 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0