pepijndevos / futhark-pycffi

Python library using the Futhark C backend via CFFI
MIT License
23 stars 7 forks source link

Expose store/restore functions in API #32

Open athas opened 1 year ago

athas commented 1 year ago

Not completely sure what that should look like.

FluxusMagna commented 1 year ago

If no one else is working on this, I will make an attempt as I kind of need it. I'm not very used to working with python, but I think I could create a modified copy of the existing make_wrapper to make it work.

To make it a bit simpler, I think limiting the use of store to the case where futhark allocates the memory (passing NULL) is reasonable, as the user would otherwise be forced to use pointers directly. I suppose this could later be expanded by someone more familiar with python to accept an optional pointer argument.

Restore has fewer options, so it should be fairly straightforward.

Python appears to have more than one way of representing binary data, bytes and bytearray, and from what I've seen the primary difference is that bytes is immutable, whereas bytearray is mutable. Are there any reasons to prefer mutability in this case? I tend to prefer immutable data, but it is in principle less flexible. Perhaps the code can be made to accept both since they share methods(my statically typed brain finds this type of polymorphism pretty unintuitive)?

athas commented 1 year ago

Immutable bytes sound good to me.

I agree that it is best to let Futhark handle the allocation, but note that Python is still responsible for deallocation.