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

Typed PyBuffer #952

Merged
merged 2 commits into from
Jun 5, 2020
Merged

Typed PyBuffer #952

merged 2 commits into from
Jun 5, 2020

Conversation

kngwyu
Copy link
Member

@kngwyu kngwyu commented Jun 4, 2020

PyBuffer is now typed as PyBuffer<T>.
Since it can only have a single type, it is reasonable to make it typed.

In addition, I implemented FromPyObject for PyBuffer<T>.
The intention is enabling the use of PyBuffer as an argument of pyfunction, like:

#[pyfunction]
fn buffer_inplace_add(py: Python, x: PyBuffer<i32>, y: PyBuffer<i32>) { ... }

, which means that we can still use fast(=buffer to vec) conversion for function arguments even after #927 is merged.

@emmatyping
Copy link
Contributor

This looks really handy! I was just asking on Gitter if

numpy PyObject -> PyArray -> extract an ArrayView -> to_owned_array to a OwnedArray -> into_raw_vec to Vec

Was the best route, this seems much more straightforward.

Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Looks great to me, very nice!

CHANGELOG.md Outdated Show resolved Hide resolved
@@ -146,29 +147,51 @@ fn is_matching_endian(c: u8) -> bool {
}

/// Trait implemented for possible element types of `PyBuffer`.
pub unsafe trait Element {
pub unsafe trait Element: Copy {
Copy link
Member

Choose a reason for hiding this comment

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

👍

tests/test_pyfunction.rs Outdated Show resolved Hide resolved
@kngwyu kngwyu merged commit d674b5f into PyO3:master Jun 5, 2020
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