Add a to_range interface for building ranges from length specs#189
Merged
Conversation
mtfishman
added a commit
to ITensor/GradedArrays.jl
that referenced
this pull request
Jun 28, 2026
## Summary Extends `to_range` (introduced in ITensor/TensorAlgebra.jl#189) so a vector of sector-to-multiplicity pairs builds a `GradedOneTo`, delegating to `gradedrange`. The method is defined over both `SectorRange` keys (what sector constructors like `U1` produce) and raw `TensorKitSectors.Sector` keys, so `[U1(0) => 2, U1(1) => 3]` builds a graded range.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #189 +/- ##
==========================================
- Coverage 79.61% 79.52% -0.09%
==========================================
Files 21 22 +1
Lines 667 669 +2
==========================================
+ Hits 531 532 +1
- Misses 136 137 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
mtfishman
added a commit
to ITensor/GradedArrays.jl
that referenced
this pull request
Jun 28, 2026
## Summary Extends `to_range` (introduced in ITensor/TensorAlgebra.jl#189) so a vector of sector-to-multiplicity pairs builds a `GradedOneTo`, delegating to `gradedrange`. The method is defined over both `SectorRange` keys (what sector constructors like `U1` produce) and raw `TensorKitSectors.Sector` keys, so `[U1(0) => 2, U1(1) => 3]` builds a graded range.
mtfishman
added a commit
to ITensor/ITensorBase.jl
that referenced
this pull request
Jun 28, 2026
## Summary
Routes the `NamedUnitRange{Name}` length argument, and so `Index`, through `to_range` (introduced in ITensor/TensorAlgebra.jl#189), collapsing the separate integer and range constructors into one. `Index` now uniformly accepts an integer, an existing range, or, with GradedArrays loaded, a vector of sector-to-multiplicity pairs like `Index([U1(0) => 2, U1(1) => 3])`. This adds no dependency on GradedArrays: `to_range` dispatches on the spec type, and a caller writing the sector form already has GradedArrays loaded.
mtfishman
added a commit
to ITensor/ITensorBase.jl
that referenced
this pull request
Jun 28, 2026
## Summary
Routes the `NamedUnitRange{Name}` length argument, and so `Index`, through `to_range` (introduced in ITensor/TensorAlgebra.jl#189), collapsing the separate integer and range constructors into one. `Index` now uniformly accepts an integer, an existing range, or, with GradedArrays loaded, a vector of sector-to-multiplicity pairs like `Index([U1(0) => 2, U1(1) => 3])`. This adds no dependency on GradedArrays: `to_range` dispatches on the spec type, and a caller writing the sector form already has GradedArrays loaded.
mtfishman
added a commit
to ITensor/GradedArrays.jl
that referenced
this pull request
Jun 29, 2026
## Summary Extends `to_range` (introduced in ITensor/TensorAlgebra.jl#189) so a vector of sector-to-multiplicity pairs builds a `GradedOneTo`, delegating to `gradedrange`. The method is defined over both `SectorRange` keys (what sector constructors like `U1` produce) and raw `TensorKitSectors.Sector` keys, so `[U1(0) => 2, U1(1) => 3]` builds a graded range.
mtfishman
added a commit
to ITensor/ITensorBase.jl
that referenced
this pull request
Jun 29, 2026
## Summary
Routes the `NamedUnitRange{Name}` length argument, and so `Index`, through `to_range` (introduced in ITensor/TensorAlgebra.jl#189), collapsing the separate integer and range constructors into one. `Index` now uniformly accepts an integer, an existing range, or, with GradedArrays loaded, a vector of sector-to-multiplicity pairs like `Index([U1(0) => 2, U1(1) => 3])`. This adds no dependency on GradedArrays: `to_range` dispatches on the spec type, and a caller writing the sector form already has GradedArrays loaded.
Adds `to_range`, which converts a length-like specification into a default range type: an `Integer` becomes a `Base.OneTo`, and an existing range is returned unchanged. Range and axis constructors can route a length argument through it instead of each reimplementing the conversion. It is marked `public` and declared here with the non-graded defaults. Downstream packages extend it, for example GradedArrays adds a method that turns a vector of sector-to-multiplicity pairs into a graded range.
mtfishman
added a commit
to ITensor/GradedArrays.jl
that referenced
this pull request
Jun 29, 2026
## Summary Extends `to_range` (introduced in ITensor/TensorAlgebra.jl#189) so a vector of sector-to-multiplicity pairs builds a `GradedOneTo`, delegating to `gradedrange`. The method is defined over both `SectorRange` keys (what sector constructors like `U1` produce) and raw `TensorKitSectors.Sector` keys, so `[U1(0) => 2, U1(1) => 3]` builds a graded range.
mtfishman
added a commit
to ITensor/ITensorBase.jl
that referenced
this pull request
Jun 29, 2026
## Summary
Routes the `NamedUnitRange{Name}` length argument, and so `Index`, through `to_range` (introduced in ITensor/TensorAlgebra.jl#189), collapsing the separate integer and range constructors into one. `Index` now uniformly accepts an integer, an existing range, or, with GradedArrays loaded, a vector of sector-to-multiplicity pairs like `Index([U1(0) => 2, U1(1) => 3])`. This adds no dependency on GradedArrays: `to_range` dispatches on the spec type, and a caller writing the sector form already has GradedArrays loaded.
mtfishman
added a commit
to ITensor/GradedArrays.jl
that referenced
this pull request
Jun 29, 2026
## Summary Extends `to_range` (introduced in ITensor/TensorAlgebra.jl#189) so a vector of sector-to-multiplicity pairs builds a `GradedOneTo`, delegating to `gradedrange`. The method is defined over both `SectorRange` keys (what sector constructors like `U1` produce) and raw `TensorKitSectors.Sector` keys, so `[U1(0) => 2, U1(1) => 3]` builds a graded range.
mtfishman
added a commit
to ITensor/ITensorBase.jl
that referenced
this pull request
Jun 29, 2026
## Summary
Routes the `NamedUnitRange{Name}` length argument, and so `Index`, through `to_range` (introduced in ITensor/TensorAlgebra.jl#189), collapsing the separate integer and range constructors into one. `Index` now uniformly accepts an integer, an existing range, or, with GradedArrays loaded, a vector of sector-to-multiplicity pairs like `Index([U1(0) => 2, U1(1) => 3])`. This adds no dependency on GradedArrays: `to_range` dispatches on the spec type, and a caller writing the sector form already has GradedArrays loaded.
mtfishman
added a commit
to ITensor/GradedArrays.jl
that referenced
this pull request
Jun 29, 2026
Extends `to_range` (introduced in ITensor/TensorAlgebra.jl#189) so a vector of sector-to-multiplicity pairs builds a `GradedOneTo`, delegating to `gradedrange`. The method is defined over both `SectorRange` keys (what sector constructors like `U1` produce) and raw `TensorKitSectors.Sector` keys, so `[U1(0) => 2, U1(1) => 3]` builds a graded range.
mtfishman
added a commit
to ITensor/ITensorBase.jl
that referenced
this pull request
Jun 29, 2026
) ## Summary Routes the `NamedUnitRange{Name}` constructor argument, and so `Index`, through `to_range` (introduced in ITensor/TensorAlgebra.jl#189), so the same constructor accepts an integer, an existing range, or, with GradedArrays loaded, a vector of sector-to-multiplicity pairs like `Index([U1(0) => 2, U1(1) => 3])`. This adds no dependency on GradedArrays: `to_range` dispatches on the argument type, and a caller writing the sector form already has GradedArrays loaded.
mtfishman
added a commit
to ITensor/GradedArrays.jl
that referenced
this pull request
Jun 29, 2026
## Summary Extends `to_range` (introduced in ITensor/TensorAlgebra.jl#189) so a vector of sector-to-multiplicity pairs builds a `GradedOneTo`, delegating to `gradedrange`. The method is defined over both `SectorRange` keys (what sector constructors like `U1` produce) and raw `TensorKitSectors.Sector` keys, so `[U1(0) => 2, U1(1) => 3]` builds a graded range.
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.
Summary
Adds
to_range, which converts a description of a space into a default range type: anIntegerbecomes aBase.OneTo, and an existing range is returned unchanged. Range and axis constructors can route their argument through it instead of each reimplementing the conversion. It is markedpublicand declared here with the non-graded defaults. Downstream packages extend it, for example GradedArrays adds a method that turns a vector of sector-to-multiplicity pairs into a graded range.