Skip to content

Commit

Permalink
add converter for fusiontreepair to array
Browse files Browse the repository at this point in the history
  • Loading branch information
lkdvos committed Jul 2, 2024
1 parent 1827d6a commit 5003daa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
14 changes: 14 additions & 0 deletions src/fusiontrees/fusiontrees.jl
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,20 @@ function Base.convert(A::Type{<:AbstractArray}, f::FusionTree{I,N}) where {I,N}
Ctail, ((1,), Base.tail(trivialtuple)), :N, true, false)
end

# TODO: is this piracy?
function Base.convert(A::Type{<:AbstractArray},
(f₁, f₂)::Tuple{FusionTree{I},FusionTree{I}}) where {I}
F₁ = convert(A, f₁)
F₂ = convert(A, f₂)
sz1 = size(F₁)
sz2 = size(F₂)
d1 = TupleTools.front(sz1)
d2 = TupleTools.front(sz2)

return reshape(reshape(F₁, TupleTools.prod(d1), sz1[end]) *
reshape(F₂, TupleTools.prod(d2), sz2[end])', (d1..., d2...))
end

# Show methods
function Base.show(io::IO, t::FusionTree{I,N,M,K,Nothing}) where {I<:Sector,N,M,K}
return print(IOContext(io, :typeinfo => I), "FusionTree{", type_repr(I), "}(",
Expand Down
9 changes: 1 addition & 8 deletions src/tensors/abstracttensor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,7 @@ function Base.convert(::Type{Array}, t::AbstractTensorMap{S,N₁,N₂}) where {S
dom = domain(t)
local A
for (f₁, f₂) in fusiontrees(t)
F₁ = convert(Array, f₁)
F₂ = convert(Array, f₂)
sz1 = size(F₁)
sz2 = size(F₂)
d1 = TupleTools.front(sz1)
d2 = TupleTools.front(sz2)
F = reshape(reshape(F₁, TupleTools.prod(d1), sz1[end]) *
reshape(F₂, TupleTools.prod(d2), sz2[end])', (d1..., d2...))
F = convert(Array, (f₁, f₂))
if !(@isdefined A)
if eltype(F) <: Complex
T = complex(float(scalartype(t)))
Expand Down

0 comments on commit 5003daa

Please sign in to comment.