Repository navigation
Add Idx value type for positions along an axis - #185
Open
marcelluethi wants to merge 1 commit into
Open
marcelluethi wants to merge 1 commit into
marcelluethi wants to merge 1 commit into
Conversation
So far, indices were represented as ordinary int32 values. This introduces an explicit value type Idx[L], which marks a value as a position along the axis L and records that axis in its type (at runtime it is still an int32). This adds type safety, as positions can only be used along their own axis, but more importantly it communicates the intent of argmax, argmin, argsort, Random.permutation and Categorical, which now return Idx. Breaking changes: - These results are no longer Int32; use asInt32 for arithmetic on them. - Axis[L].at with a vector of indices requires Tensor1[L2, Idx[L]]; convert plain integers with Idx.fromInt32(Axis[L]). The existing TypedIndex (the per-element index used by fromFunction) meant something else and is renamed to ElementIndex.
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.
So far, indices were represented as ordinary
Tensor[T, Int32]values . This PR introduces an explicit value typeIdx[L], which marks a value as a position along the axisLand records that axis in its type. At runtime it is still anInt32. This adds type safety, as positions can only be used along their own axis, but more importantly it communicates the intent ofargmax,argmin,argsort,Random.permutationandCategorical, much better.Breaking changes:
argmax, etc. are no longerInt32use asInt32 for arithmetic on them.Axis[L].atwith a vector of indices requiresTensor1[L2, Idx[L]]The existing TypedIndex (the per-element index used by fromFunction) meant something else and is renamed to ElementIndex to avoid confusion.