Skip to content

Commit de52f7a

Browse files
authored
Change to isunit for GenericUnit (#38)
* change `isunit` for `GenericUnit` * add tests * minor change * add `leftunit` and `rightunit` for product sectors w/ tests * remove old todo * bump version
1 parent af845df commit de52f7a

File tree

6 files changed

+20
-4
lines changed

6 files changed

+20
-4
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "TensorKitSectors"
22
uuid = "13a9c161-d5da-41f0-bcbd-e1a08ae0647f"
33
authors = ["Lukas Devos", "Jutho Haegeman"]
4-
version = "0.3.2"
4+
version = "0.3.3"
55

66
[deps]
77
HalfIntegers = "f0d1745a-41c9-11e9-1dd9-e5d34d218721"

src/product.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ function allunits(::Type{ProductSector{T}}) where {T}
6969
iterators = map(allunits, _sectors(T))
7070
return SectorSet{ProductSector{T}}(Base.Iterators.product(iterators...))
7171
end
72+
function leftunit(a::P) where {P <: ProductSector}
73+
return P(map(leftunit, a.sectors))
74+
end
75+
function rightunit(a::P) where {P <: ProductSector}
76+
return P(map(rightunit, a.sectors))
77+
end
7278

7379
dual(p::ProductSector) = ProductSector(map(dual, p.sectors))
7480
function (p1::P, p2::P) where {P <: ProductSector}

src/sectors.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ function isunit(a::Sector)
128128
return if UnitStyle(a) === SimpleUnit()
129129
a == unit(a)
130130
else
131-
leftunit(a) == a == rightunit(a)
131+
a in allunits(typeof(a))
132132
end
133133
end
134134
Base.isone(a::Sector) = isunit(a)
@@ -328,7 +328,7 @@ This can be either
328328
* `SimpleUnit()`: the unit is simple (e.g. fusion categories);
329329
* `GenericUnit()`: the unit is semisimple.
330330
"""
331-
abstract type UnitStyle end #TODO: rename
331+
abstract type UnitStyle end
332332
UnitStyle(a::Sector) = UnitStyle(typeof(a))
333333

334334
struct SimpleUnit <: UnitStyle end

test/multifusion.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ Istr = TensorKitSectors.type_repr(I)
3636
@test length(allunits(I)) == 2
3737
@test allunits(I) == (C0, D0)
3838

39+
@test !isunit(C0 C1)
40+
@test !isunit(C0 D1)
41+
@test isunit(C0 C0)
42+
@test isunit(D0 D0)
43+
@test isunit(C0 D0)
44+
@test length(allunits(I I)) == 4
45+
46+
@test leftunit(M Mop) == C0 D0 == rightunit(Mop M)
47+
3948
@test eval(Meta.parse(sprint(show, s))) == s
4049
@test @constinferred(hash(s)) == hash(deepcopy(s))
4150
@constinferred dual(s)

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ end
6363
@test typeof(a b) == I1 I2
6464

6565
@test @constinferred(length(allunits(I1 I2))) == 1
66+
@test @constinferred(unit(I1 I2)) == leftunit(a b) == rightunit(a b)
6667
end
6768
@test @constinferred(Tuple(SU2Irrep(1) U1Irrep(0))) == (SU2Irrep(1), U1Irrep(0))
6869
@test @constinferred(length(FermionParity(1) SU2Irrep(1 // 2) U1Irrep(1))) == 3

test/testsetup.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function randsector(::Type{I}) where {I <: Sector}
3030
end
3131
return a
3232
end
33-
randsector(::Type{I}) where {I <: Union{Trivial, PlanarTrivial}} = one(I)
33+
randsector(::Type{I}) where {I <: Union{Trivial, PlanarTrivial}} = unit(I)
3434

3535
function hasfusiontensor(I::Type{<:Sector})
3636
try

0 commit comments

Comments
 (0)