Skip to content

DOC: Add ref docs for C generic types. - #11689

Merged
eric-wieser merged 1 commit into
numpy:masterfrom
tylerjereddy:docs_C_at_symbol
Mar 15, 2019
Merged

eric-wieser merged 1 commit into
numpy:masterfrom
tylerjereddy:docs_C_at_symbol

Conversation

@tylerjereddy

Copy link
Copy Markdown
Contributor

I tried drafting a bit of reference documentation about the @TYPE@ style generic typing used in NumPy C source since even an experienced C programmer may not have seen that before (it is not standard compliant). I don't think we spell this out anywhere in docs based on a brief discussion with Matti.

Also, because I may learn something about NumPy source from the criticism of this documentation.

Comment thread doc/source/reference/c-api.dtype.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.

would be good to make clear that this is about .c.src files. The current sentence suggest that we have .c files that aren't C89/99 compliant.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The macros you're trying to document aren't expanded by anything in the numpy/core/code_generators directory. The code you're looking for is part of numpy-distutils in numpy/distutils/conv_template.py.

I think the "C standard compliant" wording here is a little negative about this. Numpy uses a custom code generator that it also ships. This isn't really all that crazy of a thing to do. Its not like doing this with C macros or just accepting that massive code duplication are either good choices.

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.

Interesting, and I see there are more "rules" than I thought in numpy/distutils/conv_template.py. I'll try to rephrase to make it a bit less framed around C standard compliance deviations, though this should likely be mentioned at least somewhere for clarity.

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.

Instead of "are not compliant with standard C syntax" consider something like "are written in a custom templating language that is used to generate C code"

@mattip

mattip commented Aug 8, 2018

Copy link
Copy Markdown
Member

The documentation might find a better home in doc/source/dev/gitwash, which is rendered as Working with NumPy source code. I admit that whole section could use some refactoring, the git parts can just be references to other, perhaps better, generic documentation, and we should expand the parts that are NumPy specific, like this one

@tylerjereddy

Copy link
Copy Markdown
Contributor Author

Revised & expanded a bit based on initial feedback; I suppose this means that any project using numpy-distutils could theoretically use the type substitution macros.

If people feel that this piece of doc is more suitably placed elsewhere as Matti suggests perhaps they can chime in--I've not visited the page he suggests before so perhaps not entirely convinced on that git workflow page being the right home.

Comment thread doc/source/reference/c-api.dtype.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.

Those are not really type variables, they are intended as part of function names. Then actual types are strings like npy_byte. It is probably better to describe the operation as string substitution.

@charris

charris commented Aug 17, 2018

Copy link
Copy Markdown
Member

It would be good to add an example, and maybe link to the module documentation in numpy/distutils/conv_template. Curiously, I can find that module documentation online, but it doesn't seem to be included in the NumPy documentation anywhere. We should maybe add it.

@charris

charris commented Aug 17, 2018

Copy link
Copy Markdown
Member

Maybe in the distutils section doc/source/reference/distutils.rst. I wonder if we should actually move some of those distutils files into the tools directory.

@tylerjereddy

tylerjereddy commented Oct 16, 2018 •

Copy link
Copy Markdown
Contributor Author

I've substantially revised this DOC PR in the following ways, based on feedback above and now having some experience with our template language:

  • added an example
  • emphasize string substitution as what is actually happening
  • add a link to conv_template module where there are some gory details

Other notes / thoughts here:

  • I just stumbled across the placeholder Template files section in the distutils reference docs--I think a reviewer of my PR here could make a compelling argument that that is where this information should reside--currently there's an XXX placeholder there; at least that's evidence that these docs are needed somewhere accessible
  • It may eventually be worthwhile to write a custom pygments lexer for our template files so that we get nice docs with syntax highlighting for inner loop template code blocks--could probably be templated off C lexer with just another color or two for the delimiters and @ things [same could be said for syntax highlights for common editors, but anyway many of us probably just tell the editor it is a C file in config]
    • for now: WARNING: Could not lex literal_block as "C". Highlighting skipped.

@eric-wieser

eric-wieser commented Oct 17, 2018 •

Copy link
Copy Markdown
Member

I think a reviewer of my PR here could make a compelling argument

I'm too lazy to do that, but I think you're right - especially if this is something that we're distributing as part of distutils, and not just using internally.

@tylerjereddy

Copy link
Copy Markdown
Contributor Author

Ok, I revised again to migrate the changes to disutils docs and adjust wording accordingly.

However, this raises other issues:

  • how does one even navigate to the distutils docs from the reference guide?
  • the code block and general formatting are just not functional in the rst view on github as a reviewer may notice--my changes were designed to be compiled with the rest of the docs & not simply viewed on github; so, now I'm -0.5 on migrating to the distutils docs as I've just done -- this will have to be reformatted if that's where it is staying.

@mattip

mattip commented Oct 23, 2018

Copy link
Copy Markdown
Member

how does one even navigate to the distutils docs from the reference guide?

In #12250 I linked the guide into the rendered on-line documents

Comment thread doc/DISTUTILS.rst.txt
* TIMEDELTA#
* #totype = npy_byte, npy_ubyte, npy_short, npy_ushort, npy_int, npy_uint,
* npy_long, npy_ulong, npy_longlong, npy_ulonglong,
* npy_datetime, npy_timedelta#

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.

It would be good to note that:

  • These sequences are combined essentially via zip, and iterated together rather than as a cartesian product
  • There is a *N syntax for repeated elements

Comment thread doc/DISTUTILS.rst.txt
XXX: Describe how files with extensions ``.f.src``, ``.pyf.src``,
``.c.src``, etc. are pre-processed by the ``build_src`` command.
NumPy Distutils preprocesses C source files (extension: :file:`.c.src`) written
in a custom templating language to generate C code. The :c:data:`@` symbol is

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.

Only C files? It looks like it might support other files too.

@eric-wieser eric-wieser left a comment •

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 think there's more to say here, but this looks like a great start, and I see no reason not to merge it as is, leaving further improvement to the future.

@eric-wieser

Copy link
Copy Markdown
Member

Looking again, it seems there's a lot of overlap here with https://github.com/numpy/numpy/blob/master/doc/source/reference/distutils.rst#conversion-of-src-files.

Can you try to merge these? Perhaps doc/DISTUTILS.rst.txt should just link to doc/source/reference/distutils.rst?

@mattip

mattip commented Mar 10, 2019

Copy link
Copy Markdown
Member

@eric-wieser this PR has an approval but then a request for refactoring. Is it still approved?

@eric-wieser

Copy link
Copy Markdown
Member

Let's just put this in - I've opened a new issue about merging these docs

@eric-wieser
eric-wieser merged commit 47d9d09 into numpy:master Mar 15, 2019
@tylerjereddy
tylerjereddy deleted the docs_C_at_symbol branch March 15, 2019 16:36
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.

6 participants