Skip to content

Commit

Permalink
Less lazy ProjectTo fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lkdvos committed Oct 16, 2023
1 parent df0091f commit 484a323
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion ext/TensorKitChainRulesCoreExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
# -------------------
Expand Down

0 comments on commit 484a323

Please sign in to comment.