DOC: Add concrete Meson build example for NumPy C ufunc extension#30008
DOC: Add concrete Meson build example for NumPy C ufunc extension#30008rgommers merged 2 commits intonumpy:mainfrom
Conversation
|
@mhvk please review these changes when you get chance, and let me know if this needs improvement. I have created a new file and don't know if this is best approach . |
mattip
left a comment
There was a problem hiding this comment.
I think the added examples are missing. The other code examples are all in f2py/code, maybe put them under a ufunc subdirectory?
|
@mattip I've updated with changes. |
mhvk
left a comment
There was a problem hiding this comment.
@Aniketsy - this looks fine but it is in the wrong place! I think this should be part of https://numpy.org/doc/stable/user/c-info.ufunc-tutorial.html -- and ideally where it introduces how to compile it using setuptools, you give an alternative with meson. A big advantage is that then you can just adjust the sample for the ufunc c code that is already introduced there.
What would be brilliant is to use the same kind of switchable display as on https://numpy.org/doc/stable/building/index.html#building-from-source, where one has blocks different OS, and for different ways to create virtual environments, etc. Here, one could have one for setuptools and one for meson. Note, however, that I have not looked at the source code to see if it would be very tricky!
|
@mhvk i have updated, the changes as per suggestion, please let me know if it needs improvement. |
|
Also probably worth suggesting writing a |
|
The numpy-user-dtypes repo has a number of meson/meson-python examples that use the numpy C API you can take inspiration from: https://github.com/numpy/numpy-user-dtypes |
|
@ngoldbaum Thanks! I've updated as per suggestions, please let me know if this need improvement. |
|
@rgommers Thanks! I've updated with changes as per suggestion, please let me know if this need improvement. |
rgommers
left a comment
There was a problem hiding this comment.
This is getting closer. If you look at the rendered page (see here for the latest version), the page doesn't flow very well though; it contains duplicate setup.py entries now above the .. note:: blocks. Those can be deleted. The extra docstring content is mostly obsolete, except for the numpy-specific paragraphs like this one:
setup.py file for single_type_logit.c
Note that since this is a numpy extension
we add an include_dirs=[get_include()] so that the
extension is built with numpy's C/C++ header files.
Can you move those parts into the setup.py example in the tabs, and delete the rest (e.g., everything related to running python setup.py xxx is obsolete)?
There is only last issue with libraries=["npymath"]. I think we need to leave that as is but open a follow-up issue to change the example and remove those docs. We should stop encouraging anyone to use libnpymath, since we want to get rid of that. To do so, the example has to be changed to not use half-precision dtypes (it's a known issue that float16 et al routines aren't available through the regular C API).
|
|
||
| For modern Python packaging, it is recommended to use a `pyproject.toml` and select | ||
| either `meson-python` or `scikit-build-core` as your build backend. Both are well-designed, | ||
| well-maintained, and make your extension pip-installable and compatible with current Python packaging standards. |
There was a problem hiding this comment.
This note doesn't need to be repeated three times, can you just leave the first one and delete the other ones?
|
@rgommers I've update as per suggestion, please let me know if this needs further improvements. Thanks! |
|
We're getting close! There's a rendering issue, see the double indent here:
|
rgommers
left a comment
There was a problem hiding this comment.
A few more small comments. Once those are resolved and the rendered version looks good, I'll do some local testing.
|
@rgommers done with changes, please let me know if this needs further improvements. Thanks! |
|
@rgommers I’d love to work on this issue if you allow. Please let me know if I can go ahead with this! |
|
After 3 rounds of review there was still a lot of straightforward things to fix, like duplication of content and added examples that invalidated the existing text above it. So I pushed the needed changes for those directly. The
@mhvk @ngoldbaum thoughts on that approach? |
mhvk
left a comment
There was a problem hiding this comment.
Just had a quick look. Overall, looks very nice, just a few small comments on the existing changes.
On the later question of float16, I think for these examples it is also fine to not go on to an example that includes float16, but just skip to describing what that is tricky. In the end, these examples are meant to be for people writing their first ufunc, it does not have to be too elaborate.
| project('spam', 'c') | ||
|
|
||
| py = import('python').find_installation() | ||
| np_dep = dependency('numpy') |
There was a problem hiding this comment.
This particular example actually doesn't use the numpy dependency, so this is not necessary.
| extension_module = py.extension_module( | ||
| 'spam', | ||
| ['spammodule.c'], | ||
| dependencies: [np_dep], |
| .. code-block:: python | ||
|
|
||
| from setuptools import setup, Extension | ||
| import numpy as np |
Agreed, that sounds like a good way to go. @Aniketsy if you're up for giving that a go, removing all |
781cc6e to
f859953
Compare
…ip azp] [skip cirrus]
f859953 to
d39130b
Compare
|
@Aniketsy - I had a look and tried everything. Some things still failed, in part because the @rgommers - I think this is now ready... p.s. I am not sure the docs build can be viewed anywhere, but I checked it locally, and it looks good. |
The link |
|
Great! And the result of a nice three-way collaboration, thanks both! |
…mpy#30008) Co-authored-by: Marten Henric van Kerkwijk <mhvk@astro.utoronto.ca> Co-authored-by: Ralf Gommers <ralf.gommers@gmail.com>
…mpy#30008) Co-authored-by: Marten Henric van Kerkwijk <mhvk@astro.utoronto.ca> Co-authored-by: Ralf Gommers <ralf.gommers@gmail.com>


#28614
This PR adds a new documentation page, ufunc_meson_example.rst
Please let me know if my approach or fix needs any improvements . I’m open to feedback and happy to make changes based on suggestions.
Thankyou !