Skip to content

DOC: improvement of the documentation for gufunc. - #11177

Merged
eric-wieser merged 3 commits into
numpy:masterfrom
mhvk:gufunc-docs-improvement
May 29, 2018
Merged

eric-wieser merged 3 commits into
numpy:masterfrom
mhvk:gufunc-docs-improvement

Conversation

@mhvk

@mhvk mhvk commented May 28, 2018

Copy link
Copy Markdown
Contributor

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

Comment thread doc/source/reference/c-api.ufunc.rst Outdated
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
Copy Markdown
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.

Comment thread doc/source/reference/c-api.ufunc.rst Outdated
(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`

@eric-wieser eric-wieser May 28, 2018 •

Copy link
Copy Markdown
Member

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

Comment thread doc/source/reference/c-api.ufunc.rst Outdated
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
Copy Markdown
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

mhvk commented May 28, 2018

Copy link
Copy Markdown
Contributor Author

All good points; adjusted.

Comment thread doc/source/reference/c-api.ufunc.rst Outdated

@eric-wieser eric-wieser May 28, 2018 •

Copy link
Copy Markdown
Member

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
Copy Markdown
Contributor 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
Copy Markdown
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
Copy Markdown
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!

Comment thread doc/source/reference/c-api.ufunc.rst Outdated

Copy link
Copy Markdown
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
Copy Markdown
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
Comment thread doc/source/reference/c-api.ufunc.rst Outdated

Copy link
Copy Markdown
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
Copy Markdown
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;

@eric-wieser eric-wieser May 28, 2018 •

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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