1
0
mirror of https://github.com/kalmarek/PropertyT.jl.git synced 2024-11-19 07:20:28 +01:00

optimisation in constraintLHS!

This commit is contained in:
kalmarek 2019-01-10 04:48:30 +01:00
parent d6bb71b3cb
commit 760dfdc7d5
2 changed files with 11 additions and 6 deletions

View File

@ -107,11 +107,7 @@ function sparsify!{T}(M::AbstractArray{T}, eps=eps(T); verbose=false)
info("Sparsifying $(size(M))-matrix... ")
end
for n in eachindex(M)
if abs(M[n]) < eps
M[n] = zero(T)
end
end
clamp_small!(M, eps)
if verbose
info("$(rpad(densM, 20))$(rpad(dens(M),20))), ($(countnz(M)) non-zeros)")
@ -120,6 +116,15 @@ function sparsify!{T}(M::AbstractArray{T}, eps=eps(T); verbose=false)
return sparse(M)
end
function clamp_small!(M::AbstractArray{T}, eps=eps(T)) where T
for n in eachindex(M)
if abs(M[n]) < eps
M[n] = zero(T)
end
end
return M
end
sparsify{T}(U::AbstractArray{T}, tol=eps(T); verbose=false) = sparsify!(deepcopy(U), tol, verbose=verbose)
###############################################################################

View File

@ -97,7 +97,7 @@ end
function constraintLHS!(M, cnstr, Us, Ust, dims, eps=1000*eps(eltype(first(M))))
for π in 1:endof(Us)
M[π] = PropertyT.sparsify!(dims[π].*Ust[π]*cnstr*Us[π], eps)
M[π] = dims[π].*PropertyT.clamp_small!(Ust[π]*cnstr*Us[π], eps)
end
end