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
end
function sparsify!{T}(U::Array{T}, eps=eps(T))
function sparsify{T}(U::Array{T}, eps=eps(T))
n = rank(U)
W = deepcopy(U)
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!")
W = U
end
U = sparse(U)
dropzeros!(U)
return U
W = sparse(W)
dropzeros!(W)
return W
end
function sparsify!{T}(U::SparseMatrixCSC{T}, eps=eps(T))
@ -53,8 +53,6 @@ function sparsify!{T}(U::SparseMatrixCSC{T}, eps=eps(T))
return U
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)
function init_model(Uπs)