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

[GradedAxes] [BUG] Iterating over GradedUnitRange yields unexpected type change #1416

Closed
ogauthe opened this issue May 7, 2024 · 3 comments · Fixed by #1468
Closed

[GradedAxes] [BUG] Iterating over GradedUnitRange yields unexpected type change #1416

ogauthe opened this issue May 7, 2024 · 3 comments · Fixed by #1468
Labels
bug Something isn't working GradedAxes NDTensors Requires changes to the NDTensors.jl library.

Comments

@ogauthe
Copy link
Contributor

ogauthe commented May 7, 2024

using NDTensors.Sectors: U1
using NDTensors.GradedAxes: gradedrange

g1 = gradedrange([U1(0) => 2, U1(1)=>1])
for s in g1
    println(s, " ", typeof(s))
end

outputs

NDTensors.LabelledNumbers.LabelledInteger{Int64, U1{Int64}}(1, U(1)[0]) NDTensors.LabelledNumbers.LabelledInteger{Int64, U1{Int64}}
2 Int64
3 Int64

with a change in iterator type beyond the first element. One obtains the same result with s in eachindex(g1) (I guess they are the same internally)

@ogauthe ogauthe added bug Something isn't working NDTensors Requires changes to the NDTensors.jl library. labels May 7, 2024
@emstoudenmire
Copy link
Collaborator

emstoudenmire commented May 8, 2024

I dug into this a bit. Best I can tell, the iteration in BlockArrays (which GradedUnitRange is implemented through) internally calls to a function inc which produces the next value in the iteration by adding the integer 1, like this:

inc(state::Tuple{Integer}, start::Tuple{Integer}, stop::Tuple{Integer}) = (state[1]+1,)

(the above is line 411 of BlockArrays/src/blockindices.jl).
Then for a labeled integer, adding +1 returns a regular integer. So I think that is the origin of the current behavior.
(Just giving some background so we can consider the next step to take / fix.)

@mtfishman mtfishman changed the title [NDTensors] [BUG] Iterating over GradedUnitRange yields unexpected type change [GradedAxes] [BUG] Iterating over GradedUnitRange yields unexpected type change May 10, 2024
@mtfishman
Copy link
Member

mtfishman commented May 24, 2024

This will be fixed in a rewrite I will do of GradedAxes which will account for the new BlockArrays.jl v1.0 release.

@mtfishman
Copy link
Member

It was easy enough to fix in #1468 without rewriting the GradedUnitRange type for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working GradedAxes NDTensors Requires changes to the NDTensors.jl library.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants