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

Add HPy_(Get|Set|Del)Slice #470

Merged
merged 8 commits into from
Jan 29, 2024
Merged

Add HPy_(Get|Set|Del)Slice #470

merged 8 commits into from
Jan 29, 2024

Conversation

fangerer
Copy link
Contributor

Again, we needed this for Cython/HPy (in particular, for the fannkuch benchmark) because getting and setting slices required multiple upcalls like this:

// create a slice object
HPy start = HPyLong_FromLong(lstart);
HPy stop = HPyLong_FromLong(lsop);
HPy ctor_args[] = { start, stop };
HPy slice = HPy_Call(ctx, ctx->h_SliceType, ctor_args, 2, HPy_NULL);
HPy res = HPy_GetItem(ctx, seq, slice);
HPy_Close(ctx, slice);
HPy_Close(ctx, stop);
HPy_Close(ctx, start);

Now, this can be done with:

HPy res = HPy_GetSlice(ctx, seq, lstart, lstop);

The proposed APIs are probably worth some discussion. E.g. we may think about introducing a third argument to each denoting the slice's step. Right now, this will always be 1.

@fangerer fangerer added this to the ABI version 2 milestone Jan 26, 2024
Copy link
Contributor

@hodgestar hodgestar left a comment

Choose a reason for hiding this comment

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

I'm happy with the slice methods not supporting a step size here unless someone else sees a strong use case (e.g. striding numpy arrays).

If needed, we can always add our own HPy_GetSliceStride, etc later?

@fangerer fangerer merged commit 928c94d into master Jan 29, 2024
38 checks passed
@fangerer fangerer deleted the fa/slice branch January 29, 2024 08:32
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.

None yet

2 participants