Change Dim type alias to class AxisExtent - #50
Merged
Conversation
Introduce convenience syntax for - creating axis extent -> - creating axis Slices ~> - renaming as
Collaborator
|
Minor adjustments:
I like the distinction between I am not sure about the I suggest general non-infix named functions (on Axis) t.slice((Axis[C].at(0), Axis[D].at(0)))
t.slice(Axis[B].at(0 until part1.shape(Axis[B])))and only The |
Contributor
Author
|
Thanks for the review. I agree with your suggestion and especially like the slicing with |
Collaborator
|
I implemented suggested changes: .extent(...), .at(...), as(...), ->. No longer ~> and _ as _. I moved the implementations to sealed trait Axis[A]:
def extent(size: Int): AxisExtent[A] = AxisExtent(this, size)
def ->(size: Int): AxisExtent[A] = this.extent(size)
def at(index: Int): AxisAtIndex[A] = AxisAtIndex(this, index)
def at(range: Range): AxisAtRange[A] = AxisAtRange(this, range)
def at(indices: Seq[Int]): AxisAtIndices[A] = AxisAtIndices(this, indices)
def at(index: Tensor0[Int]): AxisAtTensorIndex[A] = AxisAtTensorIndex(this, index)
def as[U](newAxis: Axis[U]): (Axis[A], Axis[U]) = (this, newAxis) |
benikm91
approved these changes
Jan 21, 2026
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 the construction
Axis[T]->5was used to create a tuple(Axis, Int), which was given the type aliasDim.As this takes a prominent role in the code and is often used to construct new Tensor shapes from old one, keeping
Dimas a type alias seems inadequate. This PR therefore proposes to make it a class. AsDimis not a great name, we also propose to call itAxisExtent.The syntax
Axis[T]->5is nice and should be kept. Therefore an extension method onAxisis introduced to keep it.As this creates a tension with tuple constructions, that are used in the
slicemethod to specify slicing dimensions and in relabel, these mechanisms are also changed.For Slicing, we propose to use the syntax
~>, which is another extension method on Axis that creates anAxisRangeorAxisIndex. For relabel, an infix methodaswas added.The semantics of all the operations remains the same.