PoC,WIP: Proof of concept for extending buffer protocol string#50
Open
PoC,WIP: Proof of concept for extending buffer protocol string#50
Conversation
This closes numpygh-28190 and fixes another issue in the initial code that triggered the regression. Note that we may still want to avoid this, since this does lead to constructing (view compatible) structured dtypes unnecessarily here. It would also compactify the dtype. For building unnecessary dtypes, the better solution may be to just introduce a "canonical" flag to the dtypes (now that we have the space).
This is a proof of concept, that allows roundtripping code such
as:
```
a = np.arange(100000).astype("T")
print(memoryview(a).format) # just to see it
via_memview_string = np.asarray(memoryview(a))
a = np.arange(1000).astype("m8[ms]") # or even struct "m8[...],i"
print(memoryview(a).format) # just to see it
via_memview_timedelta = np.asarray(memoryview(a))
```
I opted to simply store the `descr` pointer directly. This seems
just as well because the descr owns the side-car buffer.
One could still export it to non-Python (somewhat) since accessing
that side-car buffer _doesn't_ need Python API in the end (just
struct layout information).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a proof of concept, that allows roundtripping code such as:
As well as a PoC for basic Cython exposure as a typed memory-view (see below).
I opted to simply store the
descrpointer directly. This seems just as well because the descr owns the side-car buffer. One could still export it to non-Python (somewhat) since accessing that side-car buffer doesn't need Python API in the end (just struct layout information).For the times I opted to store two hex ints. From Python that is awkward, but our time enum is public anyway. (But we could also store
ns, etc. strings.)Note: This branch shows a minimal PoC extension to access NumPy string arrays via Cython (these are particularly difficulty, because one needs the allocator to access elements).
Because of this, it requires using this branch of Cython da-woods/cython#5