From 484a323e6e79117f9d006f354f88206801c0b421 Mon Sep 17 00:00:00 2001 From: lkdvos Date: Mon, 16 Oct 2023 23:21:33 +0200 Subject: [PATCH] Less lazy `ProjectTo` fix --- ext/TensorKitChainRulesCoreExt.jl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ext/TensorKitChainRulesCoreExt.jl b/ext/TensorKitChainRulesCoreExt.jl index fac03e91..6abd207f 100644 --- a/ext/TensorKitChainRulesCoreExt.jl +++ b/ext/TensorKitChainRulesCoreExt.jl @@ -59,7 +59,16 @@ function ChainRulesCore.rrule(::typeof(Base.copy), t::AbstractTensorMap) end ChainRulesCore.ProjectTo(::T) where {T<:AbstractTensorMap} = ProjectTo{T}() -(::ProjectTo{T})(x::AbstractTensorMap) where {T<:AbstractTensorMap} = convert(T, x) +function (::ProjectTo{T1})(x::T2) where {S,N1,N2,T1<:AbstractTensorMap{S,N1,N2}, + T2<:AbstractTensorMap{S,N1,N2}} + T1 === T2 && return x + y = similar(x, scalartype(T1)) + for (c, b) in blocks(y) + p = ProjectTo(b) + b .= p(block(x, c)) + end + return y +end # Base Linear Algebra # -------------------