Skip to content

Commit 6a19a83

Browse files
authored
No need for custom twist rule (#483)
1 parent 832ceb7 commit 6a19a83

2 files changed

Lines changed: 4 additions & 27 deletions

File tree

ext/TensorKitEnzymeExt/indexmanipulations.jl

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -116,33 +116,6 @@ function EnzymeRules.reverse(
116116
return nothing, nothing, nothing, nothing, Δαr, Δβr, map(Returns(nothing), ba)...
117117
end
118118

119-
function EnzymeRules.augmented_primal(
120-
config::EnzymeRules.RevConfigWidth{1},
121-
func::Const{typeof(twist!)},
122-
::Type{RT},
123-
t::Annotation{<:AbstractTensorMap},
124-
inds::Const;
125-
inv::Bool = false
126-
) where {RT}
127-
twist!(t.val, inds.val; inv)
128-
primal = EnzymeRules.needs_primal(config) ? t.val : nothing
129-
shadow = EnzymeRules.needs_shadow(config) ? t.dval : nothing
130-
return EnzymeRules.AugmentedReturn(primal, shadow, nothing)
131-
end
132-
133-
function EnzymeRules.reverse(
134-
config::EnzymeRules.RevConfigWidth{1},
135-
func::Const{typeof(twist!)},
136-
::Type{RT},
137-
cache,
138-
t::Annotation{<:AbstractTensorMap},
139-
inds::Const;
140-
inv::Bool = false
141-
) where {RT}
142-
!isa(t, Const) && twist!(t.dval, inds.val; inv = !inv)
143-
return (nothing, nothing)
144-
end
145-
146119
function EnzymeRules.augmented_primal(
147120
config::EnzymeRules.RevConfigWidth{1},
148121
func::Const{typeof(flip)},

test/enzyme-indexmanipulations-flip-twist/twist.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ if !Sys.iswindows() && VERSION > v"1.11.0-rc"
2020
EnzymeTestUtils.test_reverse(twist!, TA, (copy(A), TA), ([1, 3], Const); atol, rtol, fkwargs = (inv = true,))
2121
EnzymeTestUtils.test_reverse(twist!, TA, (copy(A), TA), (1, Const); atol, rtol)
2222
EnzymeTestUtils.test_reverse(twist!, TA, (copy(A), TA), ([1, 3], Const); atol, rtol)
23+
EnzymeTestUtils.test_forward(twist!, TA, (copy(A), TA), (1, Const); atol, rtol, fkwargs = (inv = false,))
24+
EnzymeTestUtils.test_forward(twist!, TA, (copy(A), TA), ([1, 3], Const); atol, rtol, fkwargs = (inv = true,))
25+
EnzymeTestUtils.test_forward(twist!, TA, (copy(A), TA), (1, Const); atol, rtol)
26+
EnzymeTestUtils.test_forward(twist!, TA, (copy(A), TA), ([1, 3], Const); atol, rtol)
2327
end
2428
end
2529
end

0 commit comments

Comments
 (0)