From 1816aab22c4636cdace44cda427b9f39d5532a92 Mon Sep 17 00:00:00 2001 From: Paul Brehmer Date: Thu, 7 Mar 2024 16:32:09 +0100 Subject: [PATCH] Fix AD problem with rotate_north for non-symmetric unit cells --- src/utility/rotations.jl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/utility/rotations.jl b/src/utility/rotations.jl index f1bb0af1..5b202bf9 100644 --- a/src/utility/rotations.jl +++ b/src/utility/rotations.jl @@ -17,8 +17,12 @@ function rotate_north(A::AbstractArray{T,3}, dir) where {T} # Initialize copy with rotated sizes A′ = Zygote.Buffer(Array{T,3}(undef, size(A, 1), size(A, 3), size(A, 2))) for dir in 1:size(A, 1) - # TODO: throws setindex! error for non-symmetric unit cells? - A′[_prev(dir, size(A, 1)), :, :] = rotl90(A[dir, :, :]) + # A′[_prev(dir, size(A, 1)), :, :] = rotl90(A[dir, :, :]) + # throws setindex! error for non-symmetric unit cells + rA = rotl90(A[dir, :, :]) + for r in 1:size(A, 3), c in 1:size(A, 2) + A′[_prev(dir, size(A, 1)), r, c] = rA[r, c] + end end A = A′ end