From 79220e6c52da1dcefa26f46cb4d3fd5c7aee569b Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Tue, 26 Aug 2014 12:17:51 -0400 Subject: [PATCH] Fix #83 --- src/linpred.jl | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/linpred.jl b/src/linpred.jl index eb18beb3..2acb1813 100644 --- a/src/linpred.jl +++ b/src/linpred.jl @@ -1,5 +1,3 @@ - - ## Return the linear predictor vector linpred(p::LinPred, f::Real=1.) = p.X * (f == 0. ? p.beta0 : fma(p.beta0, p.delbeta, f)) @@ -24,8 +22,6 @@ type DensePredQR{T<:BlasReal} <: DensePred end DensePredQR{T<:BlasReal}(X::Matrix{T}) = DensePredQR{T}(X, zeros(T,size(X,2))) -cholfact{T<:FP}(p::DensePredQR{T}) = Cholesky{T}(p.qr[:R],'U') - delbeta!{T<:BlasReal}(p::DensePredQR{T}, r::Vector{T}) = (p.delbeta = p.qr\r; p) type DensePredChol{T<:BlasReal} <: DensePred @@ -40,20 +36,23 @@ type DensePredChol{T<:BlasReal} <: DensePred end DensePredChol{T<:BlasReal}(X::Matrix{T}) = DensePredChol{T}(X, zeros(T,size(X,2))) -solve!{T<:BlasReal}(C::Cholesky{T}, B::StridedVecOrMat{T}) = potrs!(C.uplo, C.UL, B) - -cholfact{T<:FP}(p::DensePredChol{T}) = (c = p.chol; Cholesky{T}(copy(c.UL),c.uplo)) +if VERSION >= v"0.4.0-dev+122" + cholfact{T<:FP}(p::DensePredQR{T}) = Cholesky{T,Matrix{T},:U}(p.qr[:R]) + cholfact{T<:FP}(p::DensePredChol{T}) = (c = p.chol; typeof(c)(copy(c.UL))) +else + cholfact{T<:FP}(p::DensePredQR{T}) = Cholesky(p.qr[:R], :U) + cholfact{T<:FP}(p::DensePredChol{T}) = (c = p.chol; Cholesky(copy(c.UL),c.uplo)) +end function delbeta!{T<:BlasReal}(p::DensePredChol{T}, r::Vector{T}) - solve!(p.chol, gemv!('T', 1.0, p.X, r, 0.0, p.delbeta)) + A_ldiv_B!(p.chol, At_mul_B!(p.delbeta, p.X, r)) p end function delbeta!{T<:BlasReal}(p::DensePredChol{T}, r::Vector{T}, wt::Vector{T}, scr::Matrix{T}) vbroadcast!(Multiply(), scr, p.X, wt, 1) - fac, info = potrf!('U', gemm!('T', 'N', 1.0, scr, p.X, 0.0, p.chol.UL)) - info == 0 || error("Singularity detected at column $info of weighted model matrix") - solve!(p.chol, gemv!('T', 1.0, scr, r, 0.0, p.delbeta)) + cholfact!(At_mul_B!(p.chol.UL, scr, p.X), :U) + A_ldiv_B!(p.chol, At_mul_B!(p.delbeta, scr, r)) p end