Skip to content

Commit

Permalink
Avoid allocations in reduction over adjoints (#48120)
Browse files Browse the repository at this point in the history
(cherry picked from commit a9506f5)
  • Loading branch information
dkarrasch authored and KristofferC committed Jan 10, 2023
1 parent bf8d4ed commit 46cd080
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions stdlib/LinearAlgebra/src/adjtrans.jl
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ Base.mapreducedim!(f::typeof(identity), op::Union{typeof(*),typeof(Base.mul_prod
(Base.mapreducedim!(fadjoint, op, switch_dim12(B), parent(A)); B)

switch_dim12(B::AbstractVector) = permutedims(B)
switch_dim12(B::AbstractVector{<:Number}) = transpose(B) # avoid allocs due to permutedims
switch_dim12(B::AbstractArray{<:Any,0}) = B
switch_dim12(B::AbstractArray) = PermutedDimsArray(B, (2, 1, ntuple(Base.Fix1(+,2), ndims(B) - 2)...))

Expand Down

0 comments on commit 46cd080

Please sign in to comment.