Skip to content

Commit 8e84679

Browse files
committed
Updated for Julia 0.7
1 parent 0dcc6df commit 8e84679

18 files changed

+1280
-1246
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ julia> using GenericLinearAlgebra
2828

2929
julia> A = randn(1000,1000); A = A'A;
3030

31-
julia> cholfact(A);
31+
julia> cholesky(A);
3232

33-
julia> @time cholfact(A);
33+
julia> @time cholesky(A);
3434
0.013036 seconds (16 allocations: 7.630 MB)
3535

36-
julia> GenericLinearAlgebra.CholeskyModule.cholRecursive!(copy(A), Val{:L});
36+
julia> GenericLinearAlgebra.cholRecursive!(copy(A), Val{:L});
3737

38-
julia> @time GenericLinearAlgebra.CholeskyModule.cholRecursive!(copy(A), Val{:L});
38+
julia> @time GenericLinearAlgebra.cholRecursive!(copy(A), Val{:L});
3939
0.012098 seconds (7.00 k allocations: 7.934 MB)
4040
```

src/GenericLinearAlgebra.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ __precompile__()
22

33
module GenericLinearAlgebra
44

5+
import LinearAlgebra: mul!, ldiv!
6+
57
include("juliaBLAS.jl")
68
include("lapack.jl")
79
include("cholesky.jl")

src/cholesky.jl

Lines changed: 47 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,51 @@
1-
module CholeskyModule
2-
3-
using ..JuliaBLAS
4-
using Base.LinAlg: A_rdiv_Bc!
5-
6-
function cholUnblocked!(A::AbstractMatrix{T}, ::Type{Val{:L}}) where T<:Number
7-
n = LinAlg.checksquare(A)
8-
A[1,1] = sqrt(A[1,1])
9-
if n > 1
10-
a21 = view(A, 2:n, 1)
11-
scale!(a21, inv(real(A[1,1])))
12-
13-
A22 = view(A, 2:n, 2:n)
14-
rankUpdate!(-one(real(T)), a21, Hermitian(A22, :L))
15-
cholUnblocked!(A22, Val{:L})
16-
end
17-
A
1+
using LinearAlgebra: rdiv!
2+
3+
function cholUnblocked!(A::AbstractMatrix{T}, ::Type{Val{:L}}) where T<:Number
4+
n = LinearAlgebra.checksquare(A)
5+
A[1,1] = sqrt(A[1,1])
6+
if n > 1
7+
a21 = view(A, 2:n, 1)
8+
rmul!(a21, inv(real(A[1,1])))
9+
10+
A22 = view(A, 2:n, 2:n)
11+
rankUpdate!(-one(real(T)), a21, Hermitian(A22, :L))
12+
cholUnblocked!(A22, Val{:L})
1813
end
19-
20-
function cholBlocked!(A::AbstractMatrix{T}, ::Type{Val{:L}}, blocksize::Integer) where T<:Number
21-
n = LinAlg.checksquare(A)
22-
mnb = min(n, blocksize)
23-
A11 = view(A, 1:mnb, 1:mnb)
24-
cholUnblocked!(A11, Val{:L})
25-
if n > blocksize
26-
A21 = view(A, (blocksize + 1):n, 1:blocksize)
27-
A_rdiv_Bc!(A21, LowerTriangular(A11))
28-
29-
A22 = view(A, (blocksize + 1):n, (blocksize + 1):n)
30-
rankUpdate!(-one(real(T)), A21, Hermitian(A22, :L))
31-
cholBlocked!(A22, Val{:L}, blocksize)
32-
end
33-
A
14+
A
15+
end
16+
17+
function cholBlocked!(A::AbstractMatrix{T}, ::Type{Val{:L}}, blocksize::Integer) where T<:Number
18+
n = LinearAlgebra.checksquare(A)
19+
mnb = min(n, blocksize)
20+
A11 = view(A, 1:mnb, 1:mnb)
21+
cholUnblocked!(A11, Val{:L})
22+
if n > blocksize
23+
A21 = view(A, (blocksize + 1):n, 1:blocksize)
24+
rdiv!(A21, LowerTriangular(A11)')
25+
26+
A22 = view(A, (blocksize + 1):n, (blocksize + 1):n)
27+
rankUpdate!(-one(real(T)), A21, Hermitian(A22, :L))
28+
cholBlocked!(A22, Val{:L}, blocksize)
3429
end
30+
A
31+
end
3532

36-
function cholRecursive!(A::StridedMatrix{T}, ::Type{Val{:L}}, cutoff = 1) where T
37-
n = LinAlg.checksquare(A)
38-
if n == 1
39-
A[1,1] = sqrt(A[1,1])
40-
elseif n < cutoff
41-
cholUnblocked!(A, Val{:L})
42-
else
43-
n2 = div(n, 2)
44-
A11 = view(A, 1:n2, 1:n2)
45-
cholRecursive!(A11, Val{:L})
46-
A21 = view(A, n2 + 1:n, 1:n2)
47-
A_rdiv_Bc!(A21, LowerTriangular(A11))
48-
49-
A22 = view(A, n2 + 1:n, n2 + 1:n)
50-
rankUpdate!(-real(one(T)), A21, Hermitian(A22, :L))
51-
cholRecursive!(A22, Val{:L}, cutoff)
52-
end
53-
return LowerTriangular(A)
33+
function cholRecursive!(A::StridedMatrix{T}, ::Type{Val{:L}}, cutoff = 1) where T
34+
n = LinearAlgebra.checksquare(A)
35+
if n == 1
36+
A[1,1] = sqrt(A[1,1])
37+
elseif n < cutoff
38+
cholUnblocked!(A, Val{:L})
39+
else
40+
n2 = div(n, 2)
41+
A11 = view(A, 1:n2, 1:n2)
42+
cholRecursive!(A11, Val{:L})
43+
A21 = view(A, n2 + 1:n, 1:n2)
44+
rdiv!(A21, LowerTriangular(A11)')
45+
46+
A22 = view(A, n2 + 1:n, n2 + 1:n)
47+
rankUpdate!(-real(one(T)), A21, Hermitian(A22, :L))
48+
cholRecursive!(A22, Val{:L}, cutoff)
5449
end
55-
56-
end
50+
return LowerTriangular(A)
51+
end

0 commit comments

Comments
 (0)