Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/uniformscaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,22 @@ function (-)(J::UniformScaling{<:Complex}, A::Hermitian)
return B
end

for f in (:+, :-)
@eval begin
function $f(A::AdjOrTransAbsMat, J::UniformScaling)
checksquare(A)
op = wrapperop(A)
op($f(op(A), op(J)))
end

function $f(J::UniformScaling, A::AdjOrTransAbsMat)
checksquare(A)
op = wrapperop(A)
op($f(op(J), op(A)))
end
end
end

function (+)(A::AbstractMatrix, J::UniformScaling)
checksquare(A)
B = copymutable_oftype(A, Base.promote_op(+, eltype(A), typeof(J)))
Expand Down
13 changes: 13 additions & 0 deletions test/uniformscaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,19 @@ let
@test @inferred(J - T) == J - Array(T)
end

@testset for f in (transpose, adjoint)
if isa(A, Array)
T = f(randn(ComplexF64,3,3))
else
T = f(view(randn(ComplexF64,3,3), 1:3, 1:3))
end
TA = Array(T)
@test @inferred(T + J) == TA + J
@test @inferred(J + T) == J + TA
@test @inferred(T - J) == TA - J
@test @inferred(J - T) == J - TA
end

@test @inferred(I\A) == A
@test @inferred(A\I) == inv(A)
@test @inferred(λ\I) === UniformScaling(1/λ)
Expand Down