Skip to content

Add as_ffi_ptr to NDArray - #460

Merged
FrancescAlted merged 1 commit into
Blosc:mainfrom
barakugav:ffi-ptr
Aug 26, 2025
Merged

FrancescAlted merged 1 commit into
Blosc:mainfrom
barakugav:ffi-ptr

Conversation

@barakugav

@barakugav barakugav commented Aug 24, 2025 •

Copy link
Copy Markdown
Contributor

The function return a Capsule with the raw b2nd_array_t* pointer, and it is useful for passing the array to C functions

@FrancescAlted

Copy link
Copy Markdown
Member

Ok. Can you explain why exactly you want to add this functionality?

@barakugav

barakugav commented Aug 26, 2025 •

Copy link
Copy Markdown
Contributor Author

Ok. Can you explain why exactly you want to add this functionality?

I write a library that save data to disk, and some of it is ndarrays. The library is written in Rust and has a Rust API, and I use blosc2 through Rust bindings crate to compress the ndarray data.
In addition, there is a python bindings package that calls the Rust code, and expose a similar API in Python. I want to be able to pass blosc2.NDArray objects through the FFI boundary to Rust, convert it to the Rust bindings object and write it, and also read an array in Rust and pass it back to Python, and I want to do it all without copying.
In both Rust and Python the libraries hold a pointer to b2nd_array_t, so my solution is to expose it

@FrancescAlted FrancescAlted left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

Comment thread src/blosc2/__init__.py
@FrancescAlted
FrancescAlted merged commit 0ba130d into Blosc:main Aug 26, 2025
8 of 9 checks passed
@barakugav
barakugav deleted the ffi-ptr branch August 26, 2025 11:02
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.

2 participants