Skip to content

Commit

Permalink
Define chol for UniformScaling's
Browse files Browse the repository at this point in the history
  • Loading branch information
mschauer committed Jun 30, 2017
1 parent f4501ff commit 4ee514d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
25 changes: 25 additions & 0 deletions base/linalg/uniformscaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,28 @@ 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`.
# Example
```jldoctest
julia> chol(16I)
UniformScaling{Float64}
4.0*I
```
"""
chol(J::UniformScaling, args...) = ((C, info) = _chol!(J, nothing); @assertposdef C info)

3 changes: 3 additions & 0 deletions test/linalg/cholesky.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ using Base.LinAlg: BlasComplex, BlasFloat, BlasReal, QRPivoted, PosDefException
@test all(x -> x apos, cholfact(apos).factors)
@test_throws PosDefException chol(-one(eltya))

@test apos*I chol(apos*I)
@test_throws PosDefException chol(-one(eltya)*I)

# Test cholfact with Symmetric/Hermitian upper/lower
apds = Symmetric(apd)
apdsL = Symmetric(apd, :L)
Expand Down

0 comments on commit 4ee514d

Please sign in to comment.