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

Advanced indexing #25

Merged
merged 1 commit into from
Jan 8, 2025
Merged

Advanced indexing #25

merged 1 commit into from
Jan 8, 2025

Conversation

seanmcl
Copy link
Collaborator

@seanmcl seanmcl commented Jan 7, 2025

We implement a common version of advanced indexing, where all arguments are (broadcastable to) int arrays.

Copy link
Collaborator

@govereau govereau left a comment

Choose a reason for hiding this comment

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

Looks good. I think it is safe (for now) to not support mixing, I think NKI doesn't handle those cases either.

else .error "index out of bounds"
else if ind < -dim then .error "index out of bounds"
else .ok (dim + ind).toNat
(shape.val.zip index).traverse (fun (dim, ind) => conv dim ind)
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 this is why you have batteries, for traverse. Why is this not doable with mapM?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, mapM is better. Changed throughout the codebase. I usually just reach for traverse since it works in more cases, but here all we have are monads so we are good either way.

(Still use Batteries.Data.List for toChunks in one place, but that's it. We could implement this ourselves if we want to ever drop the Batteries/Aesop dependency).

We implement a common version of advanced indexing, where
all arguments are (broadcastable to) int arrays.
@seanmcl seanmcl force-pushed the sm/11-advanced-indexing branch from 08860fd to 0faad65 Compare January 8, 2025 17:34
@seanmcl seanmcl merged commit 575bf43 into main Jan 8, 2025
1 check passed
@seanmcl seanmcl deleted the sm/11-advanced-indexing branch January 8, 2025 17:35
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