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

Slicing #19

Merged
merged 1 commit into from
Jan 4, 2025
Merged

Slicing #19

merged 1 commit into from
Jan 4, 2025

Conversation

seanmcl
Copy link
Collaborator

@seanmcl seanmcl commented Jan 2, 2025

Implements Python's slice operator, commonly used in NumPy indexing.

> Defaults for i:j:k
>
> Assume n is the number of elements in the dimension being sliced.
> Then, if i is not given it defaults to 0 for step > 0 and n - 1 for step < 0 .
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you are using step and k interchangeably

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, got my verbatim quote messed up. Fixed.

def build (start stop step : Option Int) : Err Slice :=
match H : step with
| .none =>
let stepNz : step ≠ some 0 := by aesop
Copy link
Collaborator

Choose a reason for hiding this comment

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

by aesop seems pretty heavy, is this just trivial?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well, close. Removed aesop here. Maybe we should come up with some conventions around automation should be.


def all : Slice :=
let stepNz : Option.none ≠ .some (0:Int) := by trivial
Slice.mk .none .none .none stepNz
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is just default

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ha, cool.

iter := iter'
match <- f n res with
| .yield k
| .done k => res := k
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same comment as other review. Does this properly support break and return in the for loops?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in the same way, added tests.

Base automatically changed from sm/04-broadcast to main January 3, 2025 23:32
Implements Python's slice operator, commonly used in
NumPy indexing.
@seanmcl seanmcl merged commit 1a5aa13 into main Jan 4, 2025
1 check passed
@seanmcl seanmcl deleted the sm/05-slice branch January 4, 2025 00:07
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.

2 participants