Skip to content

Commit 852f279

Browse files
author
Katharine Hyatt
committed
Only copy if needed
1 parent 89ecc25 commit 852f279

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

‎ext/TensorKitEnzymeExt/indexmanipulations.jl‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ for transform in (:permute, :transpose)
1818
# and store that instead of repeating the permutation in the pullback each time.
1919
# effectively, we replace `add_permute` by `add ∘ permute`.
2020
Ap = if !isa(α, Const)
21-
# without copy=true, this may just alias A if
22-
# the permutation is an identity or the space
23-
# is Trivial and has_shared_permute is true
24-
Ap = $transform(A.val, p.val; copy = true)
21+
# this may just alias A if the permutation is an identity or the space
22+
# is Trivial and has_shared_permute is true.
23+
Ap_needs_copy = (p.val == (TensorKit.codomainind(A.val), TensorKit.domainind(A.val)) || TensorKit.has_shared_permute(A.val, p.val))
24+
Ap = $transform(A.val, p.val; copy = Ap_needs_copy)
2525
add!(C.val, Ap, α.val, β.val)
2626
Ap
2727
else

0 commit comments

Comments
 (0)