Skip to content

Commit

Permalink
Define chol for UniformScaling's (JuliaLang#22633)
Browse files Browse the repository at this point in the history
* Define chol for UniformScaling's

* Move test for chol(lambda*I) to test/linalg/uniformscaling.jl
  • Loading branch information
mschauer authored and andreasnoack committed Jul 18, 2017
1 parent 88435c0 commit eb133ab
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
24 changes: 24 additions & 0 deletions base/linalg/uniformscaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,27 @@ function hvcat(rows::Tuple{Vararg{Int}}, A::Union{AbstractVecOrMat,UniformScalin
end
return hvcat(rows, promote_to_arrays(n,1, promote_to_array_type(A), A...)...)
end


## Cholesky
function _chol!(J::UniformScaling, uplo)
c, info = _chol!(J.λ, uplo)
UniformScaling(c), info
end

chol!(J::UniformScaling, uplo) = ((J, info) = _chol!(J, uplo); @assertposdef J info)

"""
chol(J::UniformScaling) -> C
Compute the square root of a non-negative UniformScaling `J`.
# Examples
```jldoctest
julia> chol(16I)
UniformScaling{Float64}
4.0*I
```
"""
chol(J::UniformScaling, args...) = ((C, info) = _chol!(J, nothing); @assertposdef C info)

8 changes: 8 additions & 0 deletions test/linalg/uniformscaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,11 @@ end
hvcat((2,1,2),B,2eye(3,3),eye(6,6),3eye(3,3),4eye(3,3))
end
end

@testset "chol" begin
for T in (Float64, Complex64, BigFloat, Int)
λ = T(4)
@test chol*I) λ*I
@test_throws LinAlg.PosDefException chol(-λ*I)
end
end

0 comments on commit eb133ab

Please sign in to comment.