Skip to content

Commit d4373b9

Browse files
committed
fix BraidingTensor instantiation
1 parent c3e8d37 commit d4373b9

1 file changed

Lines changed: 22 additions & 16 deletions

File tree

src/tensors/tensoroperations.jl

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
@noinline function _check_spacetype(
2+
::Type{S₁}, ::Type{S₂}
3+
) where {S₁<:ElementarySpace,S₂<:ElementarySpace}
4+
S₁ === S₂ ||
5+
S₁ === SumSpace{S₂} ||
6+
SumSpace{S₁} === S₂ ||
7+
throw(SpaceMismatch(lazy"incompatible spacetypes: $S₁ and $S₂"))
8+
return nothing
9+
end
10+
111
# TensorOperations
212
# ----------------
313
function TO.tensoradd_type(
@@ -33,12 +43,12 @@ function TO.tensorcontract_type(
3343
::Bool,
3444
::Index2Tuple{N₁,N₂},
3545
) where {N₁,N₂}
36-
spacetype(A) == spacetype(B) ||
37-
throw(SpaceMismatch("incompatible space types: $(spacetype(A))$(spacetype(B))"))
46+
_check_spacetype(spacetype(A), spacetype(B))
3847

3948
I = sectortype(A)
4049
Tnew = sectorscalartype(I) <: Real ? TC : complex(TC)
4150
M = promote_storagetype(Tnew, eltype(A), eltype(B))
51+
4252
return if issparse(A) && issparse(B)
4353
sparseblocktensormaptype(spacetype(A), N₁, N₂, M)
4454
else
@@ -55,12 +65,12 @@ function TO.tensorcontract_type(
5565
conjB::Bool,
5666
pAB::Index2Tuple{N₁,N₂},
5767
) where {N₁,N₂}
58-
spacetype(A) == spacetype(B) ||
59-
throw(SpaceMismatch("incompatible space types: $(spacetype(A))$(spacetype(B))"))
68+
_check_spacetype(spacetype(A), spacetype(B))
6069

6170
I = sectortype(A)
6271
Tnew = sectorscalartype(I) <: Real ? TC : complex(TC)
6372
M = promote_storagetype(Tnew, typeof(A), eltype(B))
73+
6474
return if issparse(A) && issparse(B)
6575
sparseblocktensormaptype(spacetype(A), N₁, N₂, M)
6676
else
@@ -77,12 +87,12 @@ function TO.tensorcontract_type(
7787
::Bool,
7888
::Index2Tuple{N₁,N₂},
7989
) where {N₁,N₂}
80-
spacetype(A) == spacetype(B) ||
81-
throw(SpaceMismatch("incompatible space types: $(spacetype(A))$(spacetype(B))"))
90+
_check_spacetype(spacetype(A), spacetype(B))
8291

8392
I = sectortype(A)
8493
Tnew = sectorscalartype(I) <: Real ? TC : complex(TC)
8594
M = promote_storagetype(Tnew, eltype(A), typeof(B))
95+
8696
return if issparse(A) && issparse(B)
8797
sparseblocktensormaptype(spacetype(A), N₁, N₂, M)
8898
else
@@ -181,8 +191,7 @@ function TK.trace_permute!(
181191
backend::AbstractBackend=TO.DefaultBackend(),
182192
)
183193
# some input checks
184-
(S = spacetype(tdst)) == spacetype(tsrc) ||
185-
throw(SpaceMismatch("incompatible spacetypes"))
194+
_check_spacetype(spacetype(tdst), spacetype(tsrc))
186195
if !(BraidingStyle(sectortype(S)) isa SymmetricBraiding)
187196
throw(
188197
SectorMismatch(
@@ -216,19 +225,16 @@ end
216225
# PlanarOperations
217226
# ----------------
218227

219-
function TK.BraidingTensor(V1::SumSpace{S}, V2::SumSpace{S}) where {S}
220-
τtype = if BraidingStyle(sectortype(S)) isa SymmetricBraiding
221-
BraidingTensor{Float64,S}
222-
else
223-
BraidingTensor{ComplexF64,S}
224-
end
228+
function TK.BraidingTensor{T,S}(
229+
V1::SumSpace{S}, V2::SumSpace{S}, adjoint::Bool=false
230+
) where {T,S}
231+
τtype = BraidingTensor{T,S}
225232
tdst = SparseBlockTensorMap{τtype}(undef, V2 V1, V1 V2)
226233
Vs = eachspace(tdst)
227234
@inbounds for I in CartesianIndices(tdst)
228235
if I[1] == I[4] && I[2] == I[3]
229236
V = Vs[I]
230-
@assert domain(V)[2] == codomain(V)[1] && domain(V)[1] == codomain(V)[2]
231-
tdst[I] = TK.BraidingTensor(V[2], V[1])
237+
tdst[I] = TK.BraidingTensor{T,S}(V[2], V[1], adjoint)
232238
end
233239
end
234240
return tdst

0 commit comments

Comments
 (0)