From 00eb20fe71331459701273b95be1b9edfd956584 Mon Sep 17 00:00:00 2001 From: Andreas Noack Date: Mon, 8 Aug 2016 22:04:01 -0400 Subject: [PATCH] Add entry for the cholfact(HermOrSym) family --- README.md | 4 ++++ src/Compat.jl | 10 ++++++++++ test/runtests.jl | 31 ++++++++++++++++++++++++++++--- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8915036b0..ed8743e34 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,10 @@ Currently, the `@compat` macro supports the following syntaxes: * `OS_NAME` is now `Sys.KERNEL`. OS information available as `is_apple`, `is_bsd`, `is_linux`, `is_unix`, and `is_windows`. [16219](https://github.com/JuliaLang/julia/pull/16219) +* `cholfact`, `cholfact!`, and `chol` require that input is either `Hermitian`, `Symmetric` +or that the elements are perfectly symmetric or Hermitian on 0.5. Compat now defines methods +for `HermOrSym` such that using the new methods are backward compatible. + ## New types Currently, no new exported types are introduced by Compat. diff --git a/src/Compat.jl b/src/Compat.jl index 4767b6549..9224e03b8 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -1647,4 +1647,14 @@ macro dep_vectorize_2arg(S, f) end end +if VERSION < v"0.5.0-dev+4677" + using Base.LinAlg: HermOrSym + Base.chol(A::HermOrSym) = Base.LinAlg.chol!(A.uplo == 'U' ? copy(A.data) : A.data') + Base.cholfact(A::HermOrSym) = cholfact(A.data, Symbol(A.uplo)) + Base.cholfact!(A::HermOrSym) = cholfact!(A.data, Symbol(A.uplo)) + + Base.cholfact(A::HermOrSym, T::Type) = cholfact(A.data, Symbol(A.uplo), T) + Base.cholfact!(A::HermOrSym, T::Type) = cholfact!(A.data, Symbol(A.uplo), T) +end + end # module diff --git a/test/runtests.jl b/test/runtests.jl index 567cfee00..c38af9f6f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -303,11 +303,11 @@ for x in [:RTLD_LOCAL,:RTLD_GLOBAL,:find_library,:dlsym,:RTLD_LAZY,:RTLD_NODELET end # Test unsafe_convert -type A; end +type Au_c; end x = "abc" @test @compat String(unsafe_string(Compat.unsafe_convert(Ptr{UInt8}, x))) == x -Compat.unsafe_convert(::Ptr{A}, x) = x -@test Compat.unsafe_convert(pointer([A()]), 1) == 1 +Compat.unsafe_convert(::Ptr{Au_c}, x) = x +@test Compat.unsafe_convert(pointer([Au_c()]), 1) == 1 # Test Ptr{T}(0) @test @compat(Ptr{Int}(0)) == C_NULL @@ -1430,3 +1430,28 @@ mktemp() do fname, f @test f17302([1.0], [1]) == [2.0] end end + +# 0.5.0-dev+4677 +for A in (Hermitian(randn(5,5) + 10I), + Symmetric(randn(5,5) + 10I), + Symmetric(randn(5,5) + 10I, :L)) + F = cholfact(A) + @test F[:U]'F[:U] ≈ A + @test F[:L]*F[:L]' ≈ A + + Ac = copy(A) + F = cholfact!(Ac) + @test F[:U]'F[:U] ≈ A + @test F[:L]*F[:L]' ≈ A + + @test istriu(chol(A)) + @test chol(A) ≈ F[:U] + + F = cholfact(A, Val{true}) + @test F[:U]'F[:U] ≈ A[F[:p], F[:p]] + @test F[:L]*F[:L]' ≈ A[F[:p], F[:p]] + Ac = copy(A) + F = cholfact!(Ac, Val{true}) + @test F[:U]'F[:U] ≈ A[F[:p], F[:p]] + @test F[:L]*F[:L]' ≈ A[F[:p], F[:p]] +end