Skip to content

Commit

Permalink
Merge pull request #268 from JuliaLang/anj/chol
Browse files Browse the repository at this point in the history
Add entry for the cholfact(HermOrSym) family
  • Loading branch information
andreasnoack authored Sep 9, 2016
2 parents e8e69d1 + 00eb20f commit f373714
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
31 changes: 28 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

2 comments on commit f373714

@maximerischard
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just what I needed! Could a version tag be created for this commit please?

@andreasnoack
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.