Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add 🐬 functionality #189

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/spaces/homspace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,22 @@ function select(W::HomSpace{S}, (p₁, p₂)::Index2Tuple{N₁,N₂}) where {S,N
return cod ← dom
end

"""
flip(W::HomSpace, I)

Return a new `HomSpace` object by applying `flip` to each of the spaces in the domain and
codomain of `W` for which the linear index `i` satisfies `i ∈ I`.
"""
function flip(W::HomSpace{S}, I) where {S}
cod′ = let cod = codomain(W)
ProductSpace{S}(ntuple(i -> i ∈ I ? flip(cod[i]) : cod[i], numout(W)))
end
dom′ = let dom = domain(W)
ProductSpace{S}(ntuple(i -> (i + numout(W)) ∈ I ? flip(dom[i]) : dom[i], numin(W)))
end
return cod′ ← dom′
end

"""
compose(W::HomSpace, V::HomSpace)

Expand Down
16 changes: 16 additions & 0 deletions src/tensors/indexmanipulations.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Index manipulations
#---------------------
"""
flip(t::AbstractTensorMap, I) -> t′::AbstractTensorMap

Return a new tensor that is isomorphic to `t` but where the arrows on the indices `i` that satisfy
`i ∈ I` are flipped, i.e. `space(t′, i) = flip(space(t, i))`.
"""
function flip(t::AbstractTensorMap, I)
P = flip(space(t), I)
t2 = similar(t, P)
for (c, b) in blocks(t)
copy!(t2[c], b)
end
return t
end
flip(t::TensorMap, I) = TensorMap(t.data, flip(space(t), I))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here it's probably best to also include a copy keyword, similar to permute, which can be used to control the sharing of data. At least, it's good to have this in the docstring somewhere


"""
permute!(tdst::AbstractTensorMap, tsrc::AbstractTensorMap, (p₁, p₂)::Index2Tuple)
-> tdst
Expand Down
17 changes: 17 additions & 0 deletions test/tensors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,23 @@ for V in spacelist
@test HrA12array ≈ convert(Array, HrA12)
end
end
if BraidingStyle(I) isa Bosonic # TODO: add fermionic tests by including parity tensors
@timedtestset "Index flipping: test via contraction" begin
t1 = rand(ComplexF64, V1 ⊗ V2 ⊗ V3 ← V4)
t2 = rand(ComplexF64, V2' ⊗ V5 ← V4' ⊗ V1)
@tensor ta[a, b] := t1[x, y, a, z] * t2[y, b, z, x]
@tensor tb[a, b] := flip(t1, 1)[x, y, a, z] * flip(t2, 4)[y, b, z, x]
@test ta ≈ tb
@tensor tb[a, b] := flip(t1, (2, 4))[x, y, a, z] *
flip(t2, (1, 3))[y, b, z, x]
@test ta ≈ tb
@tensor tb[a, b] := flip(t1, (1, 2, 4))[x, y, a, z] *
flip(t2, (1, 3, 4))[y, b, z, x]
@tensor tb[a, b] := flip(t1, (1, 3))[x, y, a, z] *
flip(t2, (2, 4))[y, b, z, x]
@test flip(ta, (1, 2)) ≈ tb
end
end
@timedtestset "Multiplication of isometries: test properties" begin
W2 = V4 ⊗ V5
W1 = W2 ⊗ (oneunit(V1) ⊕ oneunit(V1))
Expand Down
Loading