Skip to content

Commit

Permalink
Add cond method for UniformScaling (#19906)
Browse files Browse the repository at this point in the history
* cond method for UniformScaling with tests
  • Loading branch information
dmbates authored and andreasnoack committed Jan 11, 2017
1 parent 512339b commit a65ce80
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion base/linalg/uniformscaling.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

import Base: copy, ctranspose, getindex, show, transpose, one, zero, inv,
import Base: cond, copy, ctranspose, getindex, show, transpose, one, zero, inv,
@_pure_meta, hcat, vcat, hvcat
import Base.LinAlg: SingularException

Expand Down Expand Up @@ -178,6 +178,11 @@ function copy!(A::AbstractMatrix, J::UniformScaling)
return A
end

function cond{T}(J::UniformScaling{T})
onereal = inv(one(real(J.λ)))
return J.λ zero(T) ? onereal : oftype(onereal, Inf)
end

# promote_to_arrays(n,k, T, A...) promotes any UniformScaling matrices
# in A to matrices of type T and sizes given by n[k:end]. n is an array
# so that the same promotion code can be used for hvcat. We pass the type T
Expand Down
2 changes: 2 additions & 0 deletions test/linalg/uniformscaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ J = UniformScaling(λ)
@test I + I === UniformScaling(2) # +
@test inv(I) == I
@test inv(J) == UniformScaling(inv(λ))
@test cond(I) == 1
@test cond(J) == zero(λ) ? one(real(λ)) : oftype(real(λ), Inf))
end

B = bitrand(2,2)
Expand Down

2 comments on commit a65ce80

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily benchmark build, I will reply here when finished:

@nanosoldier runbenchmarks(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @jrevels

Please sign in to comment.