Skip to content
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

To do: in-place API #163

Open
cjdoris opened this issue Apr 22, 2022 · 6 comments
Open

To do: in-place API #163

cjdoris opened this issue Apr 22, 2022 · 6 comments
Labels
enhancement New feature or request

Comments

@cjdoris
Copy link
Collaborator

cjdoris commented Apr 22, 2022

Make in-place versions of all the API functions, like:

pyimport!(ans, "sys")
pyadd!(ans, x, y)
pygetattr!(ans, x, "foo")

These replace the pointer in ans::Py with the result of the computation, instead of allocating a new Py each time. This will allow writing super-fast non-allocating code where needed.

You'd use these by pre-allocating places to store the results with pynew, which can optionally by freed with pydel!.

@cjdoris cjdoris added the enhancement New feature or request label Apr 22, 2022
@cjdoris
Copy link
Collaborator Author

cjdoris commented Apr 22, 2022

The Python in-place operators would be like:

pyiadd!(ans, x)   # like ans += x

@cjdoris
Copy link
Collaborator Author

cjdoris commented Apr 22, 2022

These should generally return ans, to make chaining more convenient.

@cjdoris
Copy link
Collaborator Author

cjdoris commented Apr 22, 2022

A function

pyhasnext!(ans, iterator)

would be useful to return true if there is a next item, and if so set ans to its value.

@cjdoris
Copy link
Collaborator Author

cjdoris commented Apr 22, 2022

Even for complicated functions (such as pycall!) we can put all the temporary state we need into ans (e.g. by setting it to a tuple of all the things we need). We'd need to generalise the first argument ans to be anything with getptr and setptr! methods, and have a non-allocating PyTupleRef type which stores a pointer to a tuple and an index.

@github-actions
Copy link
Contributor

This issue has been marked as stale because it has been open for 30 days with no activity. If the issue is still relevant then please leave a comment, or else it will be closed in 7 days.

@github-actions github-actions bot added the stale Issues about to be auto-closed label Sep 10, 2023
@github-actions
Copy link
Contributor

This issue has been closed because it has been stale for 7 days. If it is still relevant, please re-open it.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 18, 2023
@cjdoris cjdoris reopened this Sep 22, 2023
@cjdoris cjdoris removed the stale Issues about to be auto-closed label Sep 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant