Skip to content

Commit 4f07d8b

Browse files
committed
check coloring of all component spaces + fix tests
1 parent e3ab406 commit 4f07d8b

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

src/vectorspaces/sumspace.jl

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,27 @@ end
171171
TensorKit.unitspace(S::Type{<:SumSpace}) = SumSpace(TensorKit.unitspace(eltype(S)))
172172
TensorKit.zerospace(::Type{SumSpace{S}}) where {S} = SumSpace{S}()
173173

174-
TensorKit.leftunitspace(S::SumSpace{<:GradedSpace}) = SumSpace(leftunitspace(first(S)))
175-
TensorKit.rightunitspace(S::SumSpace{<:GradedSpace}) = SumSpace(rightunitspace(first(S)))
174+
function TensorKit.leftunitspace(S::SumSpace{<:GradedSpace})
175+
I = sectortype(S)
176+
if UnitStyle(I) isa GenericUnit
177+
!isempty(sectors(S)) || throw(ArgumentError("Cannot determine the left unit of an empty SumSpace"))
178+
TensorKit._allequal(leftunit, sectors(S)) ||
179+
throw(ArgumentError("sectors of $S do not have the same left unit"))
180+
end
181+
182+
return SumSpace(leftunitspace(first(S)))
183+
end
184+
185+
function TensorKit.rightunitspace(S::SumSpace{<:GradedSpace})
186+
I = sectortype(S)
187+
if UnitStyle(I) isa GenericUnit
188+
!isempty(sectors(S)) || throw(ArgumentError("Cannot determine the right unit of an empty SumSpace"))
189+
TensorKit._allequal(rightunit, sectors(S)) ||
190+
throw(ArgumentError("sectors of $S do not have the same right unit"))
191+
end
192+
193+
return SumSpace(rightunitspace(first(S)))
194+
end
176195
TensorKit.isunitspace(S::SumSpace{<:GradedSpace}) = all(isunitspace, S.spaces)
177196

178197
# Promotion and conversion

test/vectorspaces/sumspace.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,10 @@ end
209209
@test unitspace(typeof(W)) == (Vect[IsingBimodule]((1, 1, 0) => 1, (2, 2, 0) => 1))
210210
end
211211

212-
@test leftunitspace(V) == (WC, WD, WC)
213-
@test rightunitspace(V) == (WC, WD, WD)
212+
@test_throws ArgumentError leftunitspace(V)
213+
@test_throws ArgumentError rightunitspace(V)
214+
@test leftunitspace(SumSpace(V1, V3)) == WC
215+
@test rightunitspace(SumSpace(V2, V3)) == WD
214216
@test leftunitspace(WMop) == WD && rightunitspace(WMop) == WC
215217
@test leftunitspace(WM) == WC && rightunitspace(WM) == WD
216218
@test unitspace(WM) == unitspace(WMop) == (Vect[IsingBimodule]((1, 1, 0) => 1, (2, 2, 0) => 1))

0 commit comments

Comments
 (0)