Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into profile
Browse files Browse the repository at this point in the history
  • Loading branch information
dmbates committed Oct 27, 2017
2 parents df4d332 + 17c4d17 commit 2868693
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/linalg/rankUpdate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ function rankUpdate!(α::T, A::SparseMatrixCSC{T}, C::Diagonal{T}) where T <: Nu
rv = rowvals(A)
for j in 1:n
nzr = nzrange(A, j)
length(nzr) == 1 || throw(ArgumentError("A*A' has off-diagonal elements"))
k = nzr[1]
@inbounds dd[rv[k]] += α * abs2(nz[k])
if !isempty(nzr)
length(nzr) == 1 || throw(ArgumentError("A*A' has off-diagonal elements"))
k = nzr[1]
@inbounds dd[rv[k]] += α * abs2(nz[k])
end
end
C
end
Expand Down
18 changes: 18 additions & 0 deletions src/modelterms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,24 @@ function Base.Ac_mul_B(A::ScalarFactorReTerm{T,V,R},
end
end

function Base.Ac_mul_B(A::VectorFactorReTerm, B::ScalarFactorReTerm)
nzeros = copy(A.wtz)
k, n = size(nzeros)
rowind = Matrix{Int32}(k, n)
refs = A.f.refs
bwtz = B.wtz
for j in 1:n
bwtzj = bwtz[j]
offset = k * (refs[j] - 1)
for i in 1:k
rowind[i, j] = i + offset
nzeros[i, j] *= bwtzj
end
end
sparse(vec(rowind), Vector{Int32}(repeat(B.f.refs, inner=k)), vec(nzeros),
k * nlevs(A), nlevs(B))
end

function Base.Ac_mul_B(A::VectorFactorReTerm{T}, B::VectorFactorReTerm{T}) where T
if A === B
l = vsize(A)
Expand Down
4 changes: 3 additions & 1 deletion src/pls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ Convert sparse `S` to `Diagonal` if `S` is diagonal or to `full(S)` if
the proportion of nonzeros exceeds `threshold`.
"""
function densify(S::SparseMatrixCSC, threshold::Real = 0.3)
dropzeros!(S)
m, n = size(S)
if m == n && isdiag(S) # convert diagonal sparse to Diagonal
Diagonal(diag(S))
elseif nnz(S)/(*(size(S)...)) threshold # very sparse matrices left as is
elseif nnz(S)/(*(size(S)...)) threshold || # very sparse matrices left as is
all(d -> iszero(d) || d == 1, diff(S.colptr))
S
else
full(S)
Expand Down
4 changes: 4 additions & 0 deletions test/FactorReTerm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ end
@test isa(vrp, UniformBlockDiagonal{Float64})
@test size(vrp) == (36, 36)

scl = ScalarFactorReTerm(slp[:G], Array(slp[:U]), Array(slp[:U]), :G, ["U"], 1.0)

@test sparse(corr)'sparse(scl) == corr'scl

@test MixedModels.Λ_mul_B!(Vector{Float64}(36), corr, ones(36)) == repeat([0.5, 1.0], outer=18)

@testset "reweight!" begin
Expand Down

0 comments on commit 2868693

Please sign in to comment.