diff --git a/Project.toml b/Project.toml index fb66182..3fba43c 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "GradedArrays" uuid = "bc96ca6e-b7c8-4bb6-888e-c93f838762c2" authors = ["ITensor developers and contributors"] -version = "0.5.1" +version = "0.5.2" [deps] ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" diff --git a/src/GradedArrays.jl b/src/GradedArrays.jl index 477f22d..236168a 100644 --- a/src/GradedArrays.jl +++ b/src/GradedArrays.jl @@ -2,12 +2,12 @@ module GradedArrays include("gradedunitrange_interface.jl") -include("abstractsector.jl") +include("sectorrange.jl") include("sectorunitrange.jl") include("gradedunitrange.jl") include("namedtuple_operations.jl") -include("sector_product.jl") +include("sectorproduct.jl") include("fusion.jl") include("gradedarray.jl") diff --git a/src/gradedunitrange.jl b/src/gradedunitrange.jl index 97d709f..f274017 100644 --- a/src/gradedunitrange.jl +++ b/src/gradedunitrange.jl @@ -27,6 +27,8 @@ using Compat: allequal abstract type AbstractGradedUnitRange{T, BlockLasts} <: AbstractBlockedUnitRange{T, BlockLasts} end +to_gradedrange(r::AbstractGradedUnitRange) = r + struct GradedUnitRange{T, SUR <: SectorOneTo{T}, BR <: AbstractUnitRange{T}, BlockLasts} <: AbstractGradedUnitRange{T, BlockLasts} eachblockaxis::Vector{SUR} diff --git a/src/sector_product.jl b/src/sectorproduct.jl similarity index 95% rename from src/sector_product.jl rename to src/sectorproduct.jl index 3aa48cb..418392d 100644 --- a/src/sector_product.jl +++ b/src/sectorproduct.jl @@ -21,15 +21,12 @@ SectorProduct(c::SectorProduct) = _SectorProduct(arguments(c)) SectorProduct(c::SectorRange...) = _SectorProduct(map(label, c)) # SectorProduct(::TKS.Trivial) = _SectorProduct((;)) # empty tuple -arguments(s::SectorProduct) = s.arguments +arguments(s::SectorProduct) = getfield(s, :arguments) arguments_type(::Type{SectorProduct{T}}) where {T} = T -function arguments(r::SectorProductRange{T}) where {T <: SectorProduct{<:Tuple}} +function arguments(r::SectorProductRange) return map(SectorRange, arguments(label(r))) end -function arguments(r::SectorProductRange{T}) where {T <: SectorProduct{<:NamedTuple}} - return NamedTuple(k => SectorRange(v) for (k, v) in pairs(arguments(label(r)))) -end function to_sector(nt::NamedTuple{<:Any, T}) where {T <: Tuple{Vararg{TKS.Sector}}} return SectorRange(SectorProduct(nt)) @@ -141,14 +138,13 @@ function Base.isless(s1::SectorProductRange, s2::SectorProductRange) return arguments(s1′) < arguments(s2′) end -function Base.show(io::IO, r::SectorRange{<:SectorProduct}) - s = label(r) - (length(arguments(s)) < 2) && print(io, "sector") +function Base.show(io::IO, r::SectorProductRange) + (length(arguments(r)) < 2) && print(io, "sector") print(io, "(") symbol = "" - for p in pairs(arguments(s)) + for (k, v) in pairs(arguments(r)) print(io, symbol) - sector_show(io, p[1], SectorRange(p[2])) + sector_show(io, k, v) symbol = " × " end return print(io, ")") @@ -177,6 +173,9 @@ const sectorproduct = × ×(c1::SectorRange, c2::SectorRange) = SectorRange(×(label(c1), label(c2))) ×(c1::TKS.Sector, c2::TKS.Sector) = ×(SectorProduct(c1), SectorProduct(c2)) +# n-arg implemented as a left fold. +×(r1, r2, r3, r_rest...) = ×(×(r1, r2), r3, r_rest...) + function ×(p1::SectorProduct{<:Tuple}, p2::SectorProduct{<:Tuple}) return SectorProduct(arguments(p1)..., arguments(p2)...) end diff --git a/src/abstractsector.jl b/src/sectorrange.jl similarity index 98% rename from src/abstractsector.jl rename to src/sectorrange.jl index ef91251..4678179 100644 --- a/src/abstractsector.jl +++ b/src/sectorrange.jl @@ -68,7 +68,7 @@ function sector_label(c::TKS.Sector) end quantum_dimension(g::AbstractUnitRange) = length(g) -quantum_dimension(r::SectorRange) = quantum_dimension(label(r)) +quantum_dimension(r::SectorRange) = TKS.dim(label(r)) quantum_dimension(s::TKS.Sector) = TKS.dim(s) to_sector(x::TKS.Sector) = SectorRange(x) @@ -190,6 +190,7 @@ function sector_label(c::TKS.CU1Irrep) c.j end end +zero_odd(::Type{O2}) = O2(-1) const SU2 = SectorRange{TKS.SU2Irrep} sector_label(c::TKS.SU2Irrep) = c.j diff --git a/test/test_symmetrysectors_fusion_rules.jl b/test/test_fusion_rule.jl similarity index 100% rename from test/test_symmetrysectors_fusion_rules.jl rename to test/test_fusion_rule.jl diff --git a/test/test_gradedunitrange.jl b/test/test_gradedunitrange.jl index 2c60fdd..c6f4680 100644 --- a/test/test_gradedunitrange.jl +++ b/test/test_gradedunitrange.jl @@ -34,7 +34,8 @@ using GradedArrays: sector_type, sectors, sectorrange, - space_isequal + space_isequal, + to_gradedrange using Test: @test, @test_throws, @testset @testset "GradedUnitRanges basics" begin @@ -43,11 +44,12 @@ using Test: @test, @test_throws, @testset g1 = gradedrange(["x" => 2, "y" => 3, "z" => 2]) @test g1 isa GradedOneTo @test !isdual(g1) + @test to_gradedrange(g1) ≡ g1 # Base.Slice - @test axes(Base.Slice(g1)) === (g1,) - @test Base.axes1(Base.Slice(g1)) === g1 - @test Base.unsafe_indices(Base.Slice(g1)) === (g1,) + @test axes(Base.Slice(g1)) ≡ (g1,) + @test Base.axes1(Base.Slice(g1)) ≡ g1 + @test Base.unsafe_indices(Base.Slice(g1)) ≡ (g1,) g2 = gradedrange(1, ["x" => 2, "y" => 3, "z" => 2]) @test !(g2 isa GradedOneTo) @@ -58,13 +60,13 @@ using Test: @test, @test_throws, @testset @test isdual(g1d) # Base.Slice - @test axes(Base.Slice(g1d)) === (g1d,) - @test Base.axes1(Base.Slice(g1d)) === g1d - @test Base.unsafe_indices(Base.Slice(g1d)) === (g1d,) + @test axes(Base.Slice(g1d)) ≡ (g1d,) + @test Base.axes1(Base.Slice(g1d)) ≡ g1d + @test Base.unsafe_indices(Base.Slice(g1d)) ≡ (g1d,) for g in (g1, g2, g1d) @test g isa GradedUnitRange - @test sector_type(g) === String + @test sector_type(g) ≡ String @test blockisequal(g, b0) @test space_isequal(g, g) @test space_isequal(copy(g), g) @@ -138,7 +140,7 @@ using Test: @test, @test_throws, @testset @test a isa SectorUnitRange @test space_isequal(a, sectorrange("x" => 2, isdual(g))) @test space_isequal(g, g[:]) - @test typeof(g[:]) === typeof(g) + @test typeof(g[:]) ≡ typeof(g) a = g[Block(2)[2:3]] @test a isa SectorUnitRange @@ -276,7 +278,7 @@ end @test space_isequal(g[Block(1)], sectorrange(SU2(0), 2)) @test space_isequal(g[Block(2)], sectorrange(SU2(1), 3:8)) - @test sector_type(g) === SU2 + @test sector_type(g) ≡ SU2 @test space_isequal(g, g) @test g == 1:8 @test space_isequal(dual(g), gradedrange([SU2(0) => 2, SU2(1) => 2]; isdual = true)) @@ -306,7 +308,7 @@ end @test a isa SectorUnitRange @test space_isequal(a, sectorrange(SU2(0) => 2)) @test space_isequal(g, g[:]) - @test typeof(g[:]) === typeof(g) + @test typeof(g[:]) ≡ typeof(g) a = g[Block(2)[2:3]] @test a isa UnitRange diff --git a/test/test_symmetrysectors_sector_product.jl b/test/test_sectorproduct.jl similarity index 99% rename from test/test_symmetrysectors_sector_product.jl rename to test/test_sectorproduct.jl index 3726f0c..5070262 100644 --- a/test/test_symmetrysectors_sector_product.jl +++ b/test/test_sectorproduct.jl @@ -41,6 +41,8 @@ import TensorKitSectors as TKS @test (@constinferred trivial(s)) == SectorProduct(TKS.U1Irrep(0), TKS.U1Irrep(0)) s = U1(1) × SU2(1 // 2) × U1(3) + @test s ≡ sectorproduct(U1(1), SU2(1 // 2), U1(3)) + @test s ≡ ×(U1(1), SU2(1 // 2), U1(3)) @test length(arguments(s)) == 3 @test (@constinferred quantum_dimension(s)) == 2 @test (@constinferred dual(s)) == U1(-1) × SU2(1 // 2) × U1(-3) diff --git a/test/test_symmetrysectors_simple_sectors.jl b/test/test_sectors.jl similarity index 99% rename from test/test_symmetrysectors_simple_sectors.jl rename to test/test_sectors.jl index 2541fdb..304c658 100644 --- a/test/test_symmetrysectors_simple_sectors.jl +++ b/test/test_sectors.jl @@ -12,7 +12,8 @@ using GradedArrays: modulus, quantum_dimension, sector_type, - trivial + trivial, + zero_odd using SUNRepresentations: SUNRepresentations using Test: @test, @test_throws, @testset using TestExtras: @constinferred @@ -100,6 +101,7 @@ fundamental(::Type{SU{N}}) where {N} = SU{N}((1, zeros(Int, N - 2)...)) @test trivial(O2) == s0e @test istrivial(s0e) + @test zero_odd(O2) == s0o @test (@constinferred quantum_dimension(s0e)) == 1 @test (@constinferred quantum_dimension(s0o)) == 1 diff --git a/test/test_show.jl b/test/test_show.jl index 15ac565..620a1b7 100644 --- a/test/test_show.jl +++ b/test/test_show.jl @@ -12,7 +12,8 @@ show_non_namespaced(x) = sprint(show, x) @testset "show SymmetrySector" begin q1 = U1(1) @test show_namespaced(q1) == "U1(1)" - @test show_non_namespaced(q1) == "GradedArrays.U1(1)" + @test show_non_namespaced(q1) == "GradedArrays.U1(1)" || + show_non_namespaced(q1) == "U1(1)" s0e = O2(0) s0o = O2(-1)