Skip to content

Commit

Permalink
implement inv() for UniformScaling
Browse files Browse the repository at this point in the history
  • Loading branch information
garrison committed Dec 13, 2014
1 parent 3234254 commit 425dbf7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion base/linalg/uniformscaling.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Base: copy, ctranspose, getindex, showarray, transpose, one, zero
import Base: copy, ctranspose, getindex, showarray, transpose, one, zero, inv
import Base.LinAlg: SingularException

immutable UniformScaling{T<:Number}
Expand Down Expand Up @@ -64,6 +64,8 @@ function -{TA,TJ<:Number}(J::UniformScaling{TJ}, A::AbstractMatrix{TA})
B
end

inv(J::UniformScaling) = UniformScaling(inv(J.λ))

*(J1::UniformScaling, J2::UniformScaling) = UniformScaling(J1.λ*J2.λ)
*(B::BitArray{2}, J::UniformScaling) = *(bitunpack(B), J::UniformScaling)
*(J::UniformScaling, B::BitArray{2}) = *(J::UniformScaling, bitunpack(B))
Expand Down
2 changes: 2 additions & 0 deletions test/linalg2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,8 @@ end
J = UniformScaling(λ)
@test J*eye(2) == conj(J'eye(2)) # ctranpose (and A(c)_mul_B)
@test I + I === UniformScaling(2) # +
@test inv(I) == I
@test inv(J) == UniformScaling(inv(λ))
B = randbool(2,2)
@test B + I == B + eye(B)
@test I + B == B + eye(B)
Expand Down

0 comments on commit 425dbf7

Please sign in to comment.