Skip to content

Commit 17daa96

Browse files
committedNov 16, 2024
finegrain homespace permutation and selection
1 parent 3e78086 commit 17daa96

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed
 

‎src/spaces/homspace.jl

+10
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,16 @@ function permute(W::HomSpace{S}, (p₁, p₂)::Index2Tuple{N₁,N₂}) where {S,
132132
p = (p₁..., p₂...)
133133
TupleTools.isperm(p) && length(p) == numind(W) ||
134134
throw(ArgumentError("$((p₁, p₂)) is not a valid permutation for $(W)"))
135+
return select(W, (p₁, p₂))
136+
end
137+
138+
"""
139+
select(W::HomSpace, (p₁, p₂)::Index2Tuple{N₁,N₂})
140+
141+
Return the `HomSpace` obtained by a selection from the domain and codomain of `W` according
142+
to the indices in `p₁` and `p₂` respectively.
143+
"""
144+
function select(W::HomSpace{S}, (p₁, p₂)::Index2Tuple{N₁,N₂}) where {S,N₁,N₂}
135145
cod = ProductSpace{S,N₁}(map(n -> W[n], p₁))
136146
dom = ProductSpace{S,N₂}(map(n -> dual(W[n]), p₂))
137147
return cod dom

‎src/tensors/diagtensor.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -276,4 +276,4 @@ for f in
276276
(:exp, :cos, :sin, :tan, :cot, :cosh, :sinh, :tanh, :coth, :atan, :acot, :asinh, :sqrt,
277277
:log, :asin, :acos, :acosh, :atanh, :acoth)
278278
@eval Base.$f(d::DiagonalTensorMap) = DiagonalTensorMap($f.(d.data), d.domain)
279-
end
279+
end

‎src/tensors/tensoroperations.jl

+3-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ end
5959
function TO.tensoradd_structure(A::AbstractTensorMap, pA::Index2Tuple{N₁,N₂},
6060
conjA::Bool) where {N₁,N₂}
6161
if !conjA
62-
return permute(space(A), pA)
62+
# don't use `permute` as this is also used when indices are traced
63+
return select(space(A), pA)
6364
else
6465
return TO.tensoradd_structure(adjoint(A), adjointtensorindices(A, pA), false)
6566
end
@@ -172,7 +173,7 @@ function trace_permute!(tdst::AbstractTensorMap,
172173
N₁, N₂ = length(p₁), length(p₂)
173174

174175
@boundscheck begin
175-
space(tdst) == permute(space(tsrc), (p₁, p₂)) ||
176+
space(tdst) == select(space(tsrc), (p₁, p₂)) ||
176177
throw(SpaceMismatch("trace: tsrc = $(codomain(tsrc))$(domain(tsrc)),
177178
tdst = $(codomain(tdst))$(domain(tdst)), p₁ = $(p₁), p₂ = $(p₂)"))
178179
all(i -> space(tsrc, q₁[i]) == dual(space(tsrc, q₂[i])), 1:N₃) ||

‎test/diagtensors.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,4 @@ diagspacelist = ((ℂ^4)', ℂ[Z2Irrep](0 => 2, 1 => 3),
122122
@test t1 * u' TensorMap(t1) * u'
123123
@test t1 \ u' TensorMap(t1) \ u'
124124
end
125-
end
125+
end

0 commit comments

Comments
 (0)