Skip to content

Commit

Permalink
Add tests rrules converters
Browse files Browse the repository at this point in the history
  • Loading branch information
lkdvos committed Jun 28, 2024
1 parent 1148fe9 commit c15b7ab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ext/TensorKitChainRulesCoreExt/constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

function ChainRulesCore.rrule(::Type{<:TensorMap}, d::DenseArray, args...)
function TensorMap_pullback(Δt)
∂d = convert(Array, Δt)
return NoTangent(), ∂d, fill(NoTangent(), length(args))...
∂d = convert(Array, unthunk(Δt))
return NoTangent(), ∂d, ntuple(_ -> NoTangent(), length(args))...
end
return TensorMap(d, args...), TensorMap_pullback
end
Expand All @@ -21,7 +21,7 @@ function ChainRulesCore.rrule(::typeof(Base.convert), T::Type{<:Array},
t::AbstractTensorMap)
A = convert(T, t)
function convert_pullback(ΔA)
∂t = TensorMap(ΔA, codomain(t), domain(t))
∂t = TensorMap(unthunk(ΔA), codomain(t), domain(t))
return NoTangent(), NoTangent(), ∂t
end
return A, convert_pullback
Expand Down
6 changes: 6 additions & 0 deletions test/ad.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ Vlist = ((ℂ^2, (ℂ^3)', ℂ^3, ℂ^2, (ℂ^2)'),
P1 = ProjectTo(T1)
@test P1(T1) == T1
@test P1(T2) == real(T2)

test_rrule(copy, T1)
test_rrule(copy, T2)

test_rrule(convert, Array, T1)
test_rrule(TensorMap, convert(Array, T1), space(T1))
end

@timedtestset "Basic Linear Algebra with scalartype $T" for T in (Float64, ComplexF64)
Expand Down

0 comments on commit c15b7ab

Please sign in to comment.