Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "GradedArrays"
uuid = "bc96ca6e-b7c8-4bb6-888e-c93f838762c2"
authors = ["ITensor developers <[email protected]> and contributors"]
version = "0.5.1"
version = "0.5.2"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand Down
4 changes: 2 additions & 2 deletions src/GradedArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions src/gradedunitrange.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
19 changes: 9 additions & 10 deletions src/sector_product.jl → src/sectorproduct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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, ")")
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/abstractsector.jl → src/sectorrange.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
File renamed without changes.
24 changes: 13 additions & 11 deletions test/test_gradedunitrange.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion test/test_show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading