Skip to content

Commit ef0bcf3

Browse files
committed
Faster Adjoint/Transpose-UniformScaling arithmetic
1 parent c4a477f commit ef0bcf3

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/uniformscaling.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,22 @@ function (-)(J::UniformScaling{<:Complex}, A::Hermitian)
217217
return B
218218
end
219219

220+
for f in (:+, :-)
221+
@eval begin
222+
function $f(A::AdjOrTransAbsMat, J::UniformScaling)
223+
checksquare(A)
224+
op = wrapperop(A)
225+
op($f(op(A), op(J)))
226+
end
227+
228+
function $f(J::UniformScaling, A::AdjOrTransAbsMat)
229+
checksquare(A)
230+
op = wrapperop(A)
231+
op($f(op(J), op(A)))
232+
end
233+
end
234+
end
235+
220236
function (+)(A::AbstractMatrix, J::UniformScaling)
221237
checksquare(A)
222238
B = copymutable_oftype(A, Base.promote_op(+, eltype(A), typeof(J)))

test/uniformscaling.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,19 @@ let
335335
@test @inferred(J - T) == J - Array(T)
336336
end
337337

338+
@testset for f in (transpose, adjoint)
339+
if isa(A, Array)
340+
T = f(randn(ComplexF64,3,3))
341+
else
342+
T = f(view(randn(ComplexF64,3,3), 1:3, 1:3))
343+
end
344+
TA = Array(T)
345+
@test @inferred(T + J) == TA + J
346+
@test @inferred(J + T) == J + TA
347+
@test @inferred(T - J) == TA - J
348+
@test @inferred(J - T) == J - TA
349+
end
350+
338351
@test @inferred(I\A) == A
339352
@test @inferred(A\I) == inv(A)
340353
@test @inferred\I) === UniformScaling(1/λ)

0 commit comments

Comments
 (0)