From f3fe910b72837684c8c52319739638ea6343b741 Mon Sep 17 00:00:00 2001 From: Andreas Noack Date: Wed, 24 Aug 2016 21:05:58 -0700 Subject: [PATCH] Fix chol for Symmetric(A, :L). (#18142) --- base/linalg/cholesky.jl | 4 ++-- test/linalg/cholesky.jl | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/base/linalg/cholesky.jl b/base/linalg/cholesky.jl index 246f1b3c8c140..46e7ac367514b 100644 --- a/base/linalg/cholesky.jl +++ b/base/linalg/cholesky.jl @@ -140,7 +140,7 @@ function chol(A::Hermitian) if A.uplo == 'U' copy!(AA, A.data) else - Base.ccopy!(AA, A.data) + Base.ctranspose!(AA, A.data) end chol!(Hermitian(AA, :U)) end @@ -150,7 +150,7 @@ function chol{T<:Real,S<:AbstractMatrix}(A::Symmetric{T,S}) if A.uplo == 'U' copy!(AA, A.data) else - Base.ccopy!(AA, A.data) + Base.ctranspose!(AA, A.data) end chol!(Hermitian(AA, :U)) end diff --git a/test/linalg/cholesky.jl b/test/linalg/cholesky.jl index 1c61f12060e5f..c747ff06a8f8a 100644 --- a/test/linalg/cholesky.jl +++ b/test/linalg/cholesky.jl @@ -25,7 +25,9 @@ for eltya in (Float32, Float64, Complex64, Complex128, BigFloat, Int) a = eltya == Int ? rand(1:7, n, n) : convert(Matrix{eltya}, eltya <: Complex ? complex(areal, aimg) : areal) a2 = eltya == Int ? rand(1:7, n, n) : convert(Matrix{eltya}, eltya <: Complex ? complex(a2real, a2img) : a2real) apd = a'*a # symmetric positive-definite - apds = Symmetric(apd) + + apds = Symmetric(apd) + apdsL = Symmetric(apd, :L) ε = εa = eps(abs(float(one(eltya)))) @inferred cholfact(apd) @@ -78,11 +80,15 @@ for eltya in (Float32, Float64, Complex64, Complex128, BigFloat, Int) @test tril(lapd.factors) ≈ capd[:L] if eltya <: Real capds = cholfact(apds) - lapds = cholfact(Symmetric(apds.data, :L)) + lapds = cholfact(apdsL) + cl = chol(apdsL) ls = lapds[:L] @test ls*ls' ≈ apd @test triu(capds.factors) ≈ lapds[:U] @test tril(lapds.factors) ≈ capds[:L] + @test istriu(cl) + @test cl'cl ≈ apds + @test cl'cl ≈ apdsL end #pivoted upper Cholesky