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

Should we have factory functions to create arrays? #18163

Open
ronawho opened this issue Aug 5, 2021 · 5 comments
Open

Should we have factory functions to create arrays? #18163

ronawho opened this issue Aug 5, 2021 · 5 comments

Comments

@ronawho
Copy link
Contributor

ronawho commented Aug 5, 2021

We have factory functions that can create bytes from a pointer:

  • createBytesWithBorrowedBuffer
  • createBytesWithOwnedBuffer
  • createBytesWithNewBuffer

We also have similar ones for strings. I think we should add something like this for arrays. We have makeArrayFromPtr from the 'external' array support, which can be used but that's not user-facing or stable. Here I'm thinking of something user-facing and more consistent with the bytes/string versions where we create an array from either a pointer or bytes. Note that for arrays we'll also want to provide a way to specify the domain, so the interface won't be exactly the same. Maybe something like:

proc createArrayWith*Buffer(buffer: bytes, dom:domain={0..<buffer.size}) {}
proc createArrayWith*Buffer(buffer: c_ptr(?t), dom: domain) {}

For some context/motivation, we started using makeArrayFromPtr in Arkouda Bears-R-Us/arkouda#880 and that made me want a stable version of it. Another user was also trying to create an array from an existing pointer in https://chapel.discourse.group/t/building-a-distributed-chapel-array-with-multiple-pointers/5501.


See also #14291, which discusses coming up with consistent names for factory functions (we had some conversations recently about whether createBytesWith*Buffer is the naming we want to stick with longer term, and that thread has more information on where we ended up a few years ago.)

@mppf
Copy link
Member

mppf commented Aug 5, 2021

Just noting that we do have some kind of factory function for creating Block arrays.

@ronawho
Copy link
Contributor Author

ronawho commented Aug 5, 2021

Here I'm really talking about creating arrays from pointers/bytes, so the title is probably a little misleading

@bradcray
Copy link
Member

bradcray commented Apr 4, 2023

Giving this a bump and some labels because @milthorpe expressed interest in it this week (and probably before this week as well).

@mppf

This comment was marked as resolved.

@milthorpe
Copy link
Contributor

While it's not a resolution to this issue, I've made a pull request that adds an overload for makeArrayFromPtr to construct (rectangular, dense, zero-based) multi-dimensional arrays from an external pointer, which supports my use case for GPU unified memory.

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

No branches or pull requests

4 participants