fix sparsify for dense matrices

This commit is contained in:
kalmar 2017-06-21 16:38:19 +02:00
parent 1aba4efa21
commit 8ce128d926

View File

@ -34,7 +34,7 @@ immutable Settings
tol::Float64 tol::Float64
end end
function sparsify!{T}(U::Array{T}, eps=eps(T)) function sparsify{T}(U::Array{T}, eps=eps(T))
n = rank(U) n = rank(U)
W = deepcopy(U) W = deepcopy(U)
W[abs.(W) .< eps] = zero(T) W[abs.(W) .< eps] = zero(T)
@ -42,9 +42,9 @@ function sparsify!{T}(U::Array{T}, eps=eps(T))
warn("Sparsification would decrease the rank!") warn("Sparsification would decrease the rank!")
W = U W = U
end end
U = sparse(U) W = sparse(W)
dropzeros!(U) dropzeros!(W)
return U return W
end end
function sparsify!{T}(U::SparseMatrixCSC{T}, eps=eps(T)) function sparsify!{T}(U::SparseMatrixCSC{T}, eps=eps(T))
@ -53,8 +53,6 @@ function sparsify!{T}(U::SparseMatrixCSC{T}, eps=eps(T))
return U return U
end end
sparsify{T}(U::AbstractArray{T}, eps=eps(T)) = sparsify!(deepcopy(U), eps)
small_to_zero!{T}(A::AbstractArray{T}, eps=eps(T)) = A[abs(A) .< eps] = zero(T) small_to_zero!{T}(A::AbstractArray{T}, eps=eps(T)) = A[abs(A) .< eps] = zero(T)
function init_model(Uπs) function init_model(Uπs)