Skip to content

DOC/ENH: Tutorial for adding C functions #20733

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

Open
madphysicist opened this issue Jan 5, 2022 · 4 comments
Open

DOC/ENH: Tutorial for adding C functions #20733

madphysicist opened this issue Jan 5, 2022 · 4 comments

Comments

@madphysicist
Copy link
Contributor

Proposed new feature or change:

There is a good tutorial for writing ufuncs in C here: https://numpy.org/doc/stable/user/c-info.ufunc-tutorial.html. It would be wonderful if there was something similar for regular functions. I wouldn't have to bug devs so much if it existed.

Some specific questions that I'd like to have authoritative answers for:

  • How to harness the code generation machinery to generate multiple loops.
  • How to dispatch to those loops correctly.
  • How to unpack arguments from the python code in preparation for the dispatcher.
  • All the different layers of python and C wrappers and where they go in the numpy codebase.
  • Where to put docstrings.

Actual usecase #1: I wrote a ufunc based on the tutorial: https://github.com/madphysicist/is_integer_ufunc. Now I want to add some arguments, but since ufuncs can't accept arbitrary arguments, I have to turn my ufunc into an ordinary function, but with multiple loops.

Actual usecase #2: I'd like to write up an O(n) version of weighted partitioning/quantiles. This will look something similar to sort, which is a regular function.

@melissawm
Copy link
Member

Thanks for the suggestion - I think this is a good idea and will bring it to the next Documentation Team meeting. You are also welcome to join in case it interests you. Meetings happen every two weeks, and the next one will take place on Monday January 17 (I usually announce those on the mailing list).

@madphysicist
Copy link
Contributor Author

@melissawm I was unable to attend the meeting. Is there anything relevant that I missed?

@melissawm
Copy link
Member

No, @madphysicist just general agreement that this would be nice. If anyone feels like taking this up, we'd be happy to review :)

@madphysicist
Copy link
Contributor Author

@melissawm. I'd be happy to get something started as I practice doing it myself, along the lines of the ufunc tutorial. There will be much missing and incorrect, but hopefully easy to fix. My only concern is that I don't really know where to start. Right now I'm piecing together what I can from sort and other examples. Do you know of any external resources that could help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants