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

Convert ndarray scalars to Span<T> using the buffer protocol #187

Merged
merged 55 commits into from
Sep 18, 2024

Conversation

tonybaloney
Copy link
Owner

@tonybaloney tonybaloney commented Sep 5, 2024

This implements the Python Buffer protocol as a type and exposes the data for most unmanaged types as either a scalar Span<> or 2D array Span2D.

There is also an optional ReadOnlySpan interface.

This is a significant feature for numpy so that users dont need to convert ndarrays back into lists and then CSnakes marshals them.

It also works for bytes (as ReadOnlySpan<byte>) and bytearray as (Span<byte>).

It also opens up a bidirectional interface for exchanging low-level data via the span.

@tonybaloney tonybaloney changed the title Test numpy support Convert ndarray scalars to Span<T> using the buffer protocol Sep 5, 2024
src/CSnakes.Runtime/CPython/Buffer.cs Outdated Show resolved Hide resolved
src/CSnakes.Runtime/CPython/Buffer.cs Outdated Show resolved Hide resolved
src/CSnakes.Runtime/CPython/Buffer.cs Outdated Show resolved Hide resolved
src/CSnakes.Runtime/Python/IPyBuffer.cs Outdated Show resolved Hide resolved
src/CSnakes.Runtime/Python/PyBuffer.cs Outdated Show resolved Hide resolved
src/CSnakes.Runtime/Python/PyBuffer.cs Outdated Show resolved Hide resolved
src/CSnakes.Runtime/Python/PyBuffer.cs Outdated Show resolved Hide resolved
src/CSnakes.Runtime/Python/PyBuffer.cs Outdated Show resolved Hide resolved
src/CSnakes.Runtime/Python/PyBuffer.cs Outdated Show resolved Hide resolved
src/CSnakes.Runtime/Python/PyBuffer.cs Outdated Show resolved Hide resolved
tonybaloney and others added 10 commits September 6, 2024 06:58
Co-authored-by: Aaron Robinson <arobins@microsoft.com>
Co-authored-by: Aaron Robinson <arobins@microsoft.com>
Co-authored-by: Aaron Robinson <arobins@microsoft.com>
Co-authored-by: Aaron Robinson <arobins@microsoft.com>
Co-authored-by: Aaron Robinson <arobins@microsoft.com>
Co-authored-by: Aaron Robinson <arobins@microsoft.com>
@tonybaloney
Copy link
Owner Author

Linux tests are failing because of #189

Rest of the implementation I'm happy with

src/CSnakes.Runtime/CPython/Buffer.cs Outdated Show resolved Hide resolved
src/CSnakes.Runtime/CPython/Buffer.cs Outdated Show resolved Hide resolved
src/CSnakes.Runtime/CPython/Buffer.cs Outdated Show resolved Hide resolved
docs/buffers.md Outdated Show resolved Hide resolved
docs/buffers.md Outdated Show resolved Hide resolved
docs/buffers.md Outdated Show resolved Hide resolved
docs/buffers.md Show resolved Hide resolved
docs/buffers.md Show resolved Hide resolved
src/CSnakes.Runtime/Python/PyBuffer.cs Outdated Show resolved Hide resolved
src/CSnakes.Runtime/Python/PyBuffer.cs Outdated Show resolved Hide resolved
src/Integration.Tests/Integration.Tests.csproj Outdated Show resolved Hide resolved
@tonybaloney tonybaloney merged commit 6b1a5e2 into main Sep 18, 2024
22 checks passed
@tonybaloney tonybaloney deleted the numpy_tests branch September 18, 2024 10:48
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.

Support PEP688 for buffers and in particular numpy array
4 participants