Skip to content

Commit ae3a3cc

Browse files
authored
Improve performance for dot(AdjTrans,AdjTrans) (#39004)
* Improve performance for dot(AdjTrans,AdjTrans) * generalize to Adjoint/Transpose
1 parent fc3fe4f commit ae3a3cc

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

stdlib/LinearAlgebra/src/generic.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,9 @@ function dot(x::AbstractArray, y::AbstractArray)
918918
s
919919
end
920920

921+
dot(x::Adjoint, y::Adjoint) = conj(dot(parent(x), parent(y)))
922+
dot(x::Transpose, y::Transpose) = dot(parent(x), parent(y))
923+
921924
"""
922925
dot(x, A, y)
923926

stdlib/LinearAlgebra/test/generic.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,24 @@ end
453453
@test all(!isnan, lmul!(false, Any[NaN]))
454454
end
455455

456+
@testset "adjtrans dot" begin
457+
for t in (transpose, adjoint)
458+
x, y = t(rand(ComplexF64, 10)), t(rand(ComplexF64, 10))
459+
X, Y = copy(x), copy(y)
460+
@test dot(x, y) dot(X, Y)
461+
x, y = t([rand(ComplexF64, 2, 2) for _ in 1:5]), t([rand(ComplexF64, 2, 2) for _ in 1:5])
462+
X, Y = copy(x), copy(y)
463+
@test dot(x, y) dot(X, Y)
464+
x, y = t(rand(ComplexF64, 10, 5)), t(rand(ComplexF64, 10, 5))
465+
X, Y = copy(x), copy(y)
466+
@test dot(x, y) dot(X, Y)
467+
x = t([rand(ComplexF64, 2, 2) for _ in 1:5, _ in 1:5])
468+
y = t([rand(ComplexF64, 2, 2) for _ in 1:5, _ in 1:5])
469+
X, Y = copy(x), copy(y)
470+
@test dot(x, y) dot(X, Y)
471+
end
472+
end
473+
456474
@testset "generalized dot #32739" begin
457475
for elty in (Int, Float32, Float64, BigFloat, ComplexF32, ComplexF64, Complex{BigFloat})
458476
n = 10

0 commit comments

Comments
 (0)