Skip to content

Commit 3114c76

Browse files
authored
Fixes needed for FusionTensors.jl (#76)
1 parent 3e4c87a commit 3114c76

File tree

10 files changed

+36
-27
lines changed

10 files changed

+36
-27
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "GradedArrays"
22
uuid = "bc96ca6e-b7c8-4bb6-888e-c93f838762c2"
33
authors = ["ITensor developers <[email protected]> and contributors"]
4-
version = "0.5.1"
4+
version = "0.5.2"
55

66
[deps]
77
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"

src/GradedArrays.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ module GradedArrays
22

33
include("gradedunitrange_interface.jl")
44

5-
include("abstractsector.jl")
5+
include("sectorrange.jl")
66
include("sectorunitrange.jl")
77
include("gradedunitrange.jl")
88

99
include("namedtuple_operations.jl")
10-
include("sector_product.jl")
10+
include("sectorproduct.jl")
1111

1212
include("fusion.jl")
1313
include("gradedarray.jl")

src/gradedunitrange.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ using Compat: allequal
2727
abstract type AbstractGradedUnitRange{T, BlockLasts} <:
2828
AbstractBlockedUnitRange{T, BlockLasts} end
2929

30+
to_gradedrange(r::AbstractGradedUnitRange) = r
31+
3032
struct GradedUnitRange{T, SUR <: SectorOneTo{T}, BR <: AbstractUnitRange{T}, BlockLasts} <:
3133
AbstractGradedUnitRange{T, BlockLasts}
3234
eachblockaxis::Vector{SUR}

src/sector_product.jl renamed to src/sectorproduct.jl

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,12 @@ SectorProduct(c::SectorProduct) = _SectorProduct(arguments(c))
2121
SectorProduct(c::SectorRange...) = _SectorProduct(map(label, c))
2222
# SectorProduct(::TKS.Trivial) = _SectorProduct((;)) # empty tuple
2323

24-
arguments(s::SectorProduct) = s.arguments
24+
arguments(s::SectorProduct) = getfield(s, :arguments)
2525
arguments_type(::Type{SectorProduct{T}}) where {T} = T
2626

27-
function arguments(r::SectorProductRange{T}) where {T <: SectorProduct{<:Tuple}}
27+
function arguments(r::SectorProductRange)
2828
return map(SectorRange, arguments(label(r)))
2929
end
30-
function arguments(r::SectorProductRange{T}) where {T <: SectorProduct{<:NamedTuple}}
31-
return NamedTuple(k => SectorRange(v) for (k, v) in pairs(arguments(label(r))))
32-
end
3330

3431
function to_sector(nt::NamedTuple{<:Any, T}) where {T <: Tuple{Vararg{TKS.Sector}}}
3532
return SectorRange(SectorProduct(nt))
@@ -141,14 +138,13 @@ function Base.isless(s1::SectorProductRange, s2::SectorProductRange)
141138
return arguments(s1′) < arguments(s2′)
142139
end
143140

144-
function Base.show(io::IO, r::SectorRange{<:SectorProduct})
145-
s = label(r)
146-
(length(arguments(s)) < 2) && print(io, "sector")
141+
function Base.show(io::IO, r::SectorProductRange)
142+
(length(arguments(r)) < 2) && print(io, "sector")
147143
print(io, "(")
148144
symbol = ""
149-
for p in pairs(arguments(s))
145+
for (k, v) in pairs(arguments(r))
150146
print(io, symbol)
151-
sector_show(io, p[1], SectorRange(p[2]))
147+
sector_show(io, k, v)
152148
symbol = " × "
153149
end
154150
return print(io, ")")
@@ -177,6 +173,9 @@ const sectorproduct = ×
177173
×(c1::SectorRange, c2::SectorRange) = SectorRange(×(label(c1), label(c2)))
178174
×(c1::TKS.Sector, c2::TKS.Sector) = ×(SectorProduct(c1), SectorProduct(c2))
179175

176+
# n-arg implemented as a left fold.
177+
×(r1, r2, r3, r_rest...) = ×(×(r1, r2), r3, r_rest...)
178+
180179
function ×(p1::SectorProduct{<:Tuple}, p2::SectorProduct{<:Tuple})
181180
return SectorProduct(arguments(p1)..., arguments(p2)...)
182181
end

src/abstractsector.jl renamed to src/sectorrange.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function sector_label(c::TKS.Sector)
6868
end
6969

7070
quantum_dimension(g::AbstractUnitRange) = length(g)
71-
quantum_dimension(r::SectorRange) = quantum_dimension(label(r))
71+
quantum_dimension(r::SectorRange) = TKS.dim(label(r))
7272
quantum_dimension(s::TKS.Sector) = TKS.dim(s)
7373

7474
to_sector(x::TKS.Sector) = SectorRange(x)
@@ -190,6 +190,7 @@ function sector_label(c::TKS.CU1Irrep)
190190
c.j
191191
end
192192
end
193+
zero_odd(::Type{O2}) = O2(-1)
193194

194195
const SU2 = SectorRange{TKS.SU2Irrep}
195196
sector_label(c::TKS.SU2Irrep) = c.j
File renamed without changes.

test/test_gradedunitrange.jl

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ using GradedArrays:
3434
sector_type,
3535
sectors,
3636
sectorrange,
37-
space_isequal
37+
space_isequal,
38+
to_gradedrange
3839
using Test: @test, @test_throws, @testset
3940

4041
@testset "GradedUnitRanges basics" begin
@@ -43,11 +44,12 @@ using Test: @test, @test_throws, @testset
4344
g1 = gradedrange(["x" => 2, "y" => 3, "z" => 2])
4445
@test g1 isa GradedOneTo
4546
@test !isdual(g1)
47+
@test to_gradedrange(g1) g1
4648

4749
# Base.Slice
48-
@test axes(Base.Slice(g1)) === (g1,)
49-
@test Base.axes1(Base.Slice(g1)) === g1
50-
@test Base.unsafe_indices(Base.Slice(g1)) === (g1,)
50+
@test axes(Base.Slice(g1)) (g1,)
51+
@test Base.axes1(Base.Slice(g1)) g1
52+
@test Base.unsafe_indices(Base.Slice(g1)) (g1,)
5153

5254
g2 = gradedrange(1, ["x" => 2, "y" => 3, "z" => 2])
5355
@test !(g2 isa GradedOneTo)
@@ -58,13 +60,13 @@ using Test: @test, @test_throws, @testset
5860
@test isdual(g1d)
5961

6062
# Base.Slice
61-
@test axes(Base.Slice(g1d)) === (g1d,)
62-
@test Base.axes1(Base.Slice(g1d)) === g1d
63-
@test Base.unsafe_indices(Base.Slice(g1d)) === (g1d,)
63+
@test axes(Base.Slice(g1d)) (g1d,)
64+
@test Base.axes1(Base.Slice(g1d)) g1d
65+
@test Base.unsafe_indices(Base.Slice(g1d)) (g1d,)
6466

6567
for g in (g1, g2, g1d)
6668
@test g isa GradedUnitRange
67-
@test sector_type(g) === String
69+
@test sector_type(g) String
6870
@test blockisequal(g, b0)
6971
@test space_isequal(g, g)
7072
@test space_isequal(copy(g), g)
@@ -138,7 +140,7 @@ using Test: @test, @test_throws, @testset
138140
@test a isa SectorUnitRange
139141
@test space_isequal(a, sectorrange("x" => 2, isdual(g)))
140142
@test space_isequal(g, g[:])
141-
@test typeof(g[:]) === typeof(g)
143+
@test typeof(g[:]) typeof(g)
142144

143145
a = g[Block(2)[2:3]]
144146
@test a isa SectorUnitRange
@@ -276,7 +278,7 @@ end
276278
@test space_isequal(g[Block(1)], sectorrange(SU2(0), 2))
277279
@test space_isequal(g[Block(2)], sectorrange(SU2(1), 3:8))
278280

279-
@test sector_type(g) === SU2
281+
@test sector_type(g) SU2
280282
@test space_isequal(g, g)
281283
@test g == 1:8
282284
@test space_isequal(dual(g), gradedrange([SU2(0) => 2, SU2(1) => 2]; isdual = true))
@@ -306,7 +308,7 @@ end
306308
@test a isa SectorUnitRange
307309
@test space_isequal(a, sectorrange(SU2(0) => 2))
308310
@test space_isequal(g, g[:])
309-
@test typeof(g[:]) === typeof(g)
311+
@test typeof(g[:]) typeof(g)
310312

311313
a = g[Block(2)[2:3]]
312314
@test a isa UnitRange

test/test_symmetrysectors_sector_product.jl renamed to test/test_sectorproduct.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ import TensorKitSectors as TKS
4141
@test (@constinferred trivial(s)) == SectorProduct(TKS.U1Irrep(0), TKS.U1Irrep(0))
4242

4343
s = U1(1) × SU2(1 // 2) × U1(3)
44+
@test s sectorproduct(U1(1), SU2(1 // 2), U1(3))
45+
@test s ×(U1(1), SU2(1 // 2), U1(3))
4446
@test length(arguments(s)) == 3
4547
@test (@constinferred quantum_dimension(s)) == 2
4648
@test (@constinferred dual(s)) == U1(-1) × SU2(1 // 2) × U1(-3)

test/test_symmetrysectors_simple_sectors.jl renamed to test/test_sectors.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ using GradedArrays:
1212
modulus,
1313
quantum_dimension,
1414
sector_type,
15-
trivial
15+
trivial,
16+
zero_odd
1617
using SUNRepresentations: SUNRepresentations
1718
using Test: @test, @test_throws, @testset
1819
using TestExtras: @constinferred
@@ -100,6 +101,7 @@ fundamental(::Type{SU{N}}) where {N} = SU{N}((1, zeros(Int, N - 2)...))
100101

101102
@test trivial(O2) == s0e
102103
@test istrivial(s0e)
104+
@test zero_odd(O2) == s0o
103105

104106
@test (@constinferred quantum_dimension(s0e)) == 1
105107
@test (@constinferred quantum_dimension(s0o)) == 1

test/test_show.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ show_non_namespaced(x) = sprint(show, x)
1212
@testset "show SymmetrySector" begin
1313
q1 = U1(1)
1414
@test show_namespaced(q1) == "U1(1)"
15-
@test show_non_namespaced(q1) == "GradedArrays.U1(1)"
15+
@test show_non_namespaced(q1) == "GradedArrays.U1(1)" ||
16+
show_non_namespaced(q1) == "U1(1)"
1617

1718
s0e = O2(0)
1819
s0o = O2(-1)

0 commit comments

Comments
 (0)