Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bvdmitri committed Sep 28, 2023
1 parent 6aeb793 commit 4977473
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
PositiveFactorizations = "85a6dd25-e78a-55b7-8502-1745935b8125"

[compat]
PositiveFactorizations = "0.2"
julia = "1"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

[targets]
test = ["Test"]
test = ["Test", "StaticArrays"]
13 changes: 4 additions & 9 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using FastCholesky
using Documenter

DocMeta.setdocmeta!(FastCholesky, :DocTestSetup, :(using FastCholesky); recursive=true)
DocMeta.setdocmeta!(FastCholesky, :DocTestSetup, :(using FastCholesky, LinearAlgebra); recursive=true)

makedocs(;
modules=[FastCholesky],
authors="Bagaev Dmitry <bvdmitri@gmail.com> and contributors",
authors="Bart van Erp <b.v.erp@tue.nl>, Bagaev Dmitry <d.v.bagaev@tue.nl> and contributors",
repo="https://github.com/biaslab/FastCholesky.jl/blob/{commit}{path}#{line}",
sitename="FastCholesky.jl",
format=Documenter.HTML(;
Expand All @@ -14,12 +14,7 @@ makedocs(;
edit_link="main",
assets=String[],
),
pages=[
"Home" => "index.md",
],
pages=["Home" => "index.md"],
)

deploydocs(;
repo="github.com/biaslab/FastCholesky.jl",
devbranch="main",
)
deploydocs(; repo="github.com/biaslab/FastCholesky.jl", devbranch="main")
2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ CurrentModule = FastCholesky

# FastCholesky

Documentation for [FastCholesky](https://github.com/biaslab/FastCholesky.jl).
This package exports `fastcholesky` function, which works exactly like the `cholesky` from the Julia, but faster!

```@index
```
Expand Down
18 changes: 18 additions & 0 deletions src/FastCholesky.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ export fastcholesky, fastcholesky!, cholinv, cholsqrt, chollogdet, cholinv_logde
Returns the `Cholesky` factorization of the `input` in the same format as `LinearAlgebra.cholesky`.
By default fallbacks to `LinearAlgebra.cholesky(PositiveFactorizations.Positive, input)`, thus does not requires the input to be perfectly symmetric.
Provides more efficient implementations for certain inputs.
```jldoctest
julia> fastcholesky([ 1.0 0.5; 0.5 1.0 ])
Cholesky{Float64, Matrix{Float64}}
L factor:
2×2 LowerTriangular{Float64, Matrix{Float64}}:
1.0 ⋅
0.5 0.866025
```
"""
function fastcholesky(input::AbstractMatrix)
return cholesky(PositiveFactorizations.Positive, Hermitian(input))
Expand Down Expand Up @@ -42,6 +51,15 @@ end
In-place version of the `fastcholesky`. Does not check the positive-definiteness of the `input` and does not throw.
Use `LinearAlgebra.issuccess` to check if the result is a proper Cholesky factorization.
```jldoctest
julia> fastcholesky!([ 1.0 0.5; 0.5 1.0 ])
Cholesky{Float64, Matrix{Float64}}
L factor:
2×2 LowerTriangular{Float64, Matrix{Float64}}:
1.0 ⋅
0.5 0.866025
```
"""
function fastcholesky! end

Expand Down
13 changes: 9 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using FastCholesky
using Test
using LinearAlgebra
using StaticArrays

make_rand_diagonal(size::Number) = Diagonal(10rand(size))
make_rand_posdef(size::Number) = make_rand_posdef(make_rand_lowertriangular(size))
Expand All @@ -9,21 +10,26 @@ make_rand_posdef(L::LowerTriangular) = L * L' + size(L, 1) * I
make_rand_lowertriangular(size) = LowerTriangular(10rand(size, size))

function make_rand_inputs(size)
return [
inputs = [
make_rand_diagonal(size), make_rand_posdef(size), make_rand_hermitian(size), 1.0 * I(size)
]
# StaticArrays do not work efficiently for large inputs anyway
if size < 32
push!(inputs, SMatrix{size, size}(make_rand_posdef(size)))
end
return inputs
end

@testset "FastCholesky.jl" begin

# General properties
for size in 1:20:40
for size in 1:20:1000
for input in make_rand_inputs(size)

# We check only posdef inputs
@test isposdef(input)

@testset let input = input
let input = input
C = fastcholesky(input)

@test issuccess(C)
Expand All @@ -37,7 +43,6 @@ end
@test cholsqrt(input) * cholsqrt(input)' sqrt(input) * sqrt(input)'
@test cholsqrt(input) * cholsqrt(input)' input

# @test @elapsed(fastcholesky(input)) < @elapsed(cholesky(input))
end


Expand Down

0 comments on commit 4977473

Please sign in to comment.