function get_epsilonh!(epsilon::AbstractVector{U},H::AbstractMatrix{U},
iFv::AbstractVector{U},K::AbstractMatrix{U},
...
...
@@ -65,6 +80,14 @@ function get_epsilonh!(epsilon::AbstractVector{U}, H::AbstractMatrix{U},
mul!(epsilon,H,tmp1)
end
# epsilon_t = -H_t*KDKinf'*r0_t (DK p. 135)
function get_epsilonh!(epsilon::AbstractVector{T},H::AbstractMatrix{T},
KDKinf::AbstractMatrix{T},r0::AbstractVector{T},
tmp::AbstractVector{T})whereT<:AbstractFloat
mul!(tmp,transpose(KDKinf),r0)
mul!(epsilon,H,tmp,-1.0,0.0)
end
# etah = Q*R'*r_t
function get_etah!(etah::AbstractVector{T},Q::AbstractMatrix{T},
R::AbstractMatrix{T},r::AbstractVector{T},
...
...
@@ -144,6 +167,15 @@ function get_iFZ!(iFZ::AbstractArray{T}, cholF::AbstractArray{T}, Z::AbstractArr
LAPACK.potrs!('U',cholF,iFZ)
end
function get_iFZ!(iFZ::AbstractArray{T},cholF::AbstractArray{T},z::AbstractVector{U})where{T<:AbstractFloat,U<:Integer}
n=length(z)
fill!(iFZ,0.0)
@inbounds@simdfori=1:n
iFZ[i,z[i]]=1.0
end
LAPACK.potrs!('U',cholF,iFZ)
end
# K = iF*Z*P
function get_K!(K::AbstractArray{T},ZP::AbstractArray{T},cholF::AbstractArray{T})whereT<:AbstractFloat
copy!(K,ZP)
...
...
@@ -163,35 +195,52 @@ function get_Kstar!(Kstar::AbstractArray{T}, z::AbstractVector{U}, Pstar::Abstra
end
# L_t = T - K(DK)_t*Z (DK 4.29)
function get_L!(L::AbstractArray{U},T::AbstractArray{U},K::AbstractArray{U},Z::AbstractArray{U},L1::AbstractArray{U})whereU<:AbstractFloat
function get_L!(L::AbstractArray{U},T::AbstractArray{U},K::AbstractArray{U},Z::AbstractArray{U})whereU<:AbstractFloat
copy!(L,T)
mul!(L,K,Z,-1.0,1.0)
end
# L_t = T - K(DK)_t*z (DK 4.29)
function get_L!(L::AbstractArray{U},T::AbstractArray{U},K::AbstractArray{U},z::AbstractArray{W})where{U<:AbstractFloat,W<:Integer}
copy!(L,T)
gemm!('N','N',-1.0,K,Z,1.0,L)
forj=1:length(z)
zj=z[j]
fori=1:size(L,1)
L[i,zj]+=K[i,j]
end
end
end
# L = T(I - K'*Z)
function get_L_alternative!(L::AbstractArray{U},T::AbstractArray{U},K::AbstractArray{U},Z::AbstractArray{U},L1::AbstractArray{U})whereU<:AbstractFloat
fill!(L1,0.0)
@inbounds@simdfori=1:size(L1,1)
L1[i,i]=1.0
function get_L_alternative!(L::AbstractArray{U},T::AbstractArray{U},K::AbstractArray{U},Z::AbstractArray{U},Tmp::AbstractArray{U})whereU<:AbstractFloat
fill!(Tmp,0.0)
@inbounds@simdfori=1:size(Tmp,1)
Tmp[i,i]=1.0
end
gemm!('T','N',-1.0,K,Z,1.0,L1)
mul!(L,T,L1)
mul!(Tmp,transpose(K),Z,-1.0,1.0)
mul!(L,T,Tmp)
end
# L = T(I - K'*z)
function get_L!(L::AbstractArray{U},T::AbstractArray{U},K::AbstractArray{U},z::AbstractArray{W},L1::AbstractArray{U})where{U<:AbstractFloat,W<:Integer}
function get_L!(L::AbstractArray{U},T::AbstractArray{U},K::AbstractArray{U},z::AbstractArray{W},Tmp::AbstractArray{U})where{U<:AbstractFloat,W<:Integer}
m,n=size(K)
fill!(L1,0.0)
fill!(Tmp,0.0)
@inboundsforj=1:m
zj=z[j]
@simdfork=1:n
L1[k,zj]=-K[j,k]
Tmp[k,zj]=-K[j,k]
end
end
@inbounds@simdfori=1:n
L1[i,i]+=1.0
Tmp[i,i]+=1.0
end
mul!(L,T,L1)
mul!(L,T,Tmp)
end
# L1_t = - KDK*Z (DK 5.12)
function get_L1!(L1::AbstractMatrix{T},KDK::AbstractMatrix{T},Zsmall::AbstractVector{U})where{T<:AbstractFloat,U<:Integer}
vL1=view(L1,:,Zsmall)
vL1.=-KDK
end
function get_M!(y::AbstractArray{T},x::AbstractArray{T},work::AbstractArray{T})whereT<:AbstractFloat
...
...
@@ -328,6 +377,23 @@ function get_Valpha!(V::AbstractArray{T}, P::AbstractArray{T}, N::AbstractArray{
function get_Vepsilon!(Vepsilon::AbstractArray{T},H::AbstractArray{T},D::AbstractArray{T},tmp::AbstractArray{T})whereT<:AbstractFloat
copy!(Vepsilon,H)
...
...
@@ -405,7 +471,7 @@ end
# a = d + T*att
function update_a!(a1::AbstractVector{U},d::AbstractVector{U},T::AbstractMatrix{U},att::AbstractVector{U})whereU<:AbstractFloat
copy!(a1,d)
mul!(a1,T,att)
mul!(a1,T,att,1.0,1.0)
end
# a = d + a + K'*v
...
...
@@ -442,15 +508,62 @@ end
function update_N!(N1::AbstractArray{T},Z::AbstractArray{T},iFZ::AbstractArray{T},L::AbstractArray{T},N::AbstractArray{T},Ptmp::AbstractArray{T})whereT<:AbstractFloat
mul!(N1,transpose(Z),iFZ)
mul!(Ptmp,transpose(L),N)
gemm!('N','N',1.0,Ptmp,L,1.0,N1)
mul!(N1,Ptmp,L,1.0,1.0)
end
function update_N!(N1::AbstractArray{T},z::AbstractArray{U},iFZ::AbstractArray{T},L::AbstractArray{T},N::AbstractArray{T},Ptmp::AbstractArray{T})where{T<:AbstractFloat,U<:Integer}
function update_N!(N1::AbstractArray{T},z::AbstractVector{U},iFZ::AbstractArray{T},L::AbstractArray{T},N::AbstractArray{T},Tmp::AbstractArray{T})where{T<:AbstractFloat,U<:Integer}
fill!(N1,0.0)
vN1=view(N1,z,:)
vN1.=iFZ
mul!(Ptmp,transpose(L),N)
gemm!('N','N',1.0,Ptmp,L,1.0,N1)
mul!(Tmp,transpose(L),N)
mul!(N1,Tmp,L,1.0,1.0)
end
# N0_{t-1} = L0_t'N0_t*L0_t (DK 5.29)
function update_N0!(N0,L0,N0_1,PTmp)
mul!(PTmp,transpose(L0),N0_1)
mul!(N0,PTmp,L0)
end
# F1 = inv(Finf)
# N1_{t-1} = Z'*F1*Z + L0'*N1_t*L0 + L1'*N0_t*L0
function update_N1!(N1::AbstractMatrix{T},Z::AbstractMatrix{T},
function update_W!(W::AbstractArray{U},ZW::AbstractArray{U},cholF::AbstractArray{U},T::AbstractArray{U},K::AbstractArray{U},iFZW::AbstractArray{U},KtiFZW::AbstractArray{U})whereU<:AbstractFloat