Skip to content

Commit

Permalink
Methods for special case of very sparse nested factors.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmbates committed Oct 27, 2017
1 parent 531ca2d commit 17c4d17
Show file tree
Hide file tree
Showing 2 changed files with 8 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
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

0 comments on commit 17c4d17

Please sign in to comment.