Skip to content

Add a to_range interface for building ranges from length specs#189

Merged
mtfishman merged 1 commit into
mainfrom
mf/to_range
Jun 29, 2026
Merged

Add a to_range interface for building ranges from length specs#189
mtfishman merged 1 commit into
mainfrom
mf/to_range

Conversation

@mtfishman

@mtfishman mtfishman commented Jun 28, 2026

Copy link
Copy Markdown
Member

Summary

Adds to_range, which converts a description of a space into a default range type: an Integer becomes a Base.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 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 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

codecov Bot commented Jun 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.52%. Comparing base (c73876e) to head (d82a732).

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     
Flag Coverage Δ
docs 29.51% <0.00%> (-0.10%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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 mtfishman merged commit 6180458 into main Jun 29, 2026
25 of 26 checks passed
@mtfishman mtfishman deleted the mf/to_range branch June 29, 2026 00:40
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.
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.

1 participant