8000 DOC: Add ref docs for C generic types. by tylerjereddy · Pull Request #11689 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

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

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 1 commit into from
Mar 15, 2019

Conversation

tylerjereddy
Copy link
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.

Generic Typing and Deviations from C Standard Syntax
----------------------------------------------------

Many of the C source files in NumPy are not compliant with standard
Copy link
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.

enumerate the intended type substitutions.

The preprocessing of generically typed NumPy C source files is performed
by a set of Python modules (:file:`numpy/core/code_generators`). The type
Copy link
Contributor

Choose a reason for hiding this comment

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

8000

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
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
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
Copy link
Member
mattip commented Aug 8, 2018

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
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.

a substitution mechansim for the large number of data types described above.
For example, a loop in the NumPy C source code may have a :c:data:`@TYPE@`
variable which is preprocessed to a number of otherwise identical loops
with several types such as :c:data:`INT, LONG, UINT, ULONG`.
Copy link
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
Copy link
Member
charris commented Aug 17, 2018

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
Copy link
Member
charris commented Aug 17, 2018

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
Copy link
Contributor Author
tylerjereddy commented Oct 16, 2018

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
Copy link
Member
eric-wieser commented Oct 17, 2018

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
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
Copy link
Member
mattip commented Oct 23, 2018

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

* 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
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

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
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.

Copy link
Member
@eric-wieser eric-wieser left a comment

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
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
Copy link
Member
mattip commented Mar 10, 2019

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

@eric-wieser
Copy link
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
0