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

How create Array from exists Memory without copy? #425

Open
ZHUI opened this issue Apr 8, 2024 · 1 comment
Open

How create Array from exists Memory without copy? #425

ZHUI opened this issue Apr 8, 2024 · 1 comment
Labels

Comments

@ZHUI
Copy link

ZHUI commented Apr 8, 2024

I find https://docs.rs/numpy/latest/numpy/array/struct.PyArray.html#method.from_slice

by it copy the memory.

@adamreichold
Copy link
Member

Conversions which take ownership of Rust data and transfer it over to Python use the IntoPyArray trait.

It basically supports Vec<T>, Box<[T]> and Array<T, D> where T is any of the supported element types.

If this ties in with PyO3/pyo3#4058, I could image adding support for Mmap reinterpreted as [T] to turn this into a one-dimensional NumPy array without copying which you can then reshape into the final form without copying via the usual NumPy API.

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

No branches or pull requests

2 participants