Skip to content

Commit a9506f5

Browse files
authored
Avoid allocations in reduction over adjoints (#48120)
1 parent a77774a commit a9506f5

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

stdlib/LinearAlgebra/src/adjtrans.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ Base.mapreducedim!(f::typeof(identity), op::Union{typeof(*),typeof(Base.mul_prod
406406
(Base.mapreducedim!(fadjoint, op, switch_dim12(B), parent(A)); B)
407407

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

0 commit comments

Comments
 (0)