Skip to content

Commit 2b79107

Browse files
committed
adds ProjectTo for DiagonalTensorMap
1 parent 660bdf7 commit 2b79107

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

ext/TensorKitChainRulesCoreExt/utility.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,15 @@ function (::ProjectTo{T1})(x::T2) where {S,N1,N2,T1<:AbstractTensorMap{<:Any,S,N
2929
end
3030
return y
3131
end
32+
33+
function (::ProjectTo{T1})(x::T2) where {S,NumType,StorType,
34+
T1<:DiagonalTensorMap{NumType,S,StorType},
35+
T2<:AbstractTensorMap{<:Any,S,1,1}}
36+
T1 === T2 && return x
37+
y = DiagonalTensorMap{NumType,S,StorType}(undef, space(x, 1))
38+
for (c, b) in blocks(y)
39+
p = ProjectTo(b)
40+
b .= p(block(x, c))
41+
end
42+
return y
43+
end

0 commit comments

Comments
 (0)