In [4]:
function make_matrix(n, s=5.0)
A = randn(n,n)
for i = 1:n
A[i,i] += s
end
A
end
Out[4]:
In [5]:
nonsymm2symm(A) = (A + A')/2.0
Out[5]:
In [6]:
make_symmat(n) = nonsymm2symm(make_matrix(n))
Out[6]:
In [7]:
n = 5
A = make_symmat(n)
Out[7]:
In [9]:
type MatrixDecomp
nb::Int
ni::Int
Abb::Array{Float64,2}
Aii::Array{Float64,2}
Abi::Array{Float64,2}
Aib::Array{Float64,2}
function MatrixDecomp(A, nb, ni)
Abb = A[1:nb, 1:nb]
Abi = A[1:nb, (nb+1):end]
Aib = A[(nb+1):end, 1:nb]
Aii = A[(nb+1):end, (nb+1):end]
new(nb, ni, Abb, Aii, Abi, Aib)
end
end
In [10]:
X = MatrixDecomp(A, 3, 2)
Out[10]:
In [12]:
using Base.LinAlg.LAPACK.getrf!
using Base.LinAlg.LAPACK.getrs!
using Base.LinAlg.BLAS.gemm!
type StaticCond
nb::Int
ni::Int
B::Array{Float64,2}
iAii::Array{Float64,2}
X::Array{Float64,2}
Y::Array{Float64,2}
function StaticCond(A::MatrixDecomp)
nb = A.nb
ni = A.ni
B = zeros(nb, nb)
iAii = copy(A.Aii)
iAii, ipiv, info = getrf!(iAii)
X = A.Abi'
getrs!('T', iAii, ipiv, X)
Y = copy(A.Aib)
getrs!('N', iAii, ipiv, Y)
B = copy(A.Abb)
gemm!('T', 'N', -1.0, X, A.Aib, 1.0, B)
new(nb, ni, B, iAii, X, Y)
end
end
In [ ]: