Skip to content

Add Python module support for multi-dimensional arrays #26940

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 44 commits into from
Apr 8, 2025

Conversation

jabraham17
Copy link
Member

@jabraham17 jabraham17 commented Mar 18, 2025

Adds Python module support for passing multi-dimensional Chapel arrays by reference and receiving multi-dimensional Python arrays. This is done by expanding our usage of the Python array buffer protocol, both as a producer (Chapel arrays by ref) and as a consumer (PyArray).

This PR contains a number of additional fixes for issues I found along the way, including some portability issues. I also updated some tests (bs4) to be cleaner and use nicer syntax.

  • start_test test/library/packages/Python with COMM=none
  • start_test test/library/packages/Python with COMM=gasnet
  • start_test test/library/packages/Python --memLeaks with COMM=none

Future Work (#27073):

  • Support native indexing/slicing of Chapel Array Shim objects for ND arrays
    • Currently uses need to do something like np.asarray first, and then index the numpy view of the Chapel array
  • Print the shape of a Chapel Array Shim Object as apart of its string repr.
  • Expose the shape of a Chapel Array Shim Object as a property of the class via PyGetSetDef.
  • Consider supporting writable buffers

[Reviewed by @lydia-duncan]

@jabraham17 jabraham17 changed the title Support Python module support for multi-dimensional arrays Add module support for multi-dimensional arrays Mar 20, 2025
@jabraham17 jabraham17 changed the title Add module support for multi-dimensional arrays Add Python module support for multi-dimensional arrays Mar 20, 2025
@jabraham17 jabraham17 force-pushed the py-ndarrays branch 3 times, most recently from 6de1cea to 67fe9c4 Compare March 28, 2025 00:11
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
@jabraham17 jabraham17 marked this pull request as ready for review April 5, 2025 01:36
Signed-off-by: Jade Abraham <[email protected]>
@jabraham17 jabraham17 requested a review from lydia-duncan April 7, 2025 15:07
Copy link
Member

@lydia-duncan lydia-duncan left a comment

Choose a reason for hiding this comment

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

Let's make the PR description a bit more extensive :)

Overall this seems like a great improvement and I'm excited to see the feature get merged. I've got some comments inline, some are minor, some are more important, and some are probably just questions for my own understanding.

Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>

remove wchar

Signed-off-by: Jade Abraham <[email protected]>

fix char handling

Signed-off-by: Jade Abraham <[email protected]>

add array types test case

Signed-off-by: Jade Abraham <[email protected]>
Copy link
Member

@lydia-duncan lydia-duncan left a comment

Choose a reason for hiding this comment

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

Sweet, I think this is good to go!

@jabraham17 jabraham17 merged commit 9203ea3 into chapel-lang:main Apr 8, 2025
10 checks passed
@jabraham17 jabraham17 deleted the py-ndarrays branch April 8, 2025 22:41
@bradcray
Copy link
Member

bradcray commented Apr 8, 2025

Hooray!

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

Successfully merging this pull request may close these issues.

3 participants