Skip to content

Commit eb133ab

Browse files
mschauerandreasnoack
authored andcommitted
Define chol for UniformScaling's (#22633)
* Define chol for UniformScaling's * Move test for chol(lambda*I) to test/linalg/uniformscaling.jl
1 parent 88435c0 commit eb133ab

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

base/linalg/uniformscaling.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,3 +313,27 @@ function hvcat(rows::Tuple{Vararg{Int}}, A::Union{AbstractVecOrMat,UniformScalin
313313
end
314314
return hvcat(rows, promote_to_arrays(n,1, promote_to_array_type(A), A...)...)
315315
end
316+
317+
318+
## Cholesky
319+
function _chol!(J::UniformScaling, uplo)
320+
c, info = _chol!(J.λ, uplo)
321+
UniformScaling(c), info
322+
end
323+
324+
chol!(J::UniformScaling, uplo) = ((J, info) = _chol!(J, uplo); @assertposdef J info)
325+
326+
"""
327+
chol(J::UniformScaling) -> C
328+
329+
Compute the square root of a non-negative UniformScaling `J`.
330+
331+
# Examples
332+
```jldoctest
333+
julia> chol(16I)
334+
UniformScaling{Float64}
335+
4.0*I
336+
```
337+
"""
338+
chol(J::UniformScaling, args...) = ((C, info) = _chol!(J, nothing); @assertposdef C info)
339+

test/linalg/uniformscaling.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,11 @@ end
173173
hvcat((2,1,2),B,2eye(3,3),eye(6,6),3eye(3,3),4eye(3,3))
174174
end
175175
end
176+
177+
@testset "chol" begin
178+
for T in (Float64, Complex64, BigFloat, Int)
179+
λ = T(4)
180+
@test chol*I) λ*I
181+
@test_throws LinAlg.PosDefException chol(-λ*I)
182+
end
183+
end

0 commit comments

Comments
 (0)