mirror of
https://github.com/kalmarek/PropertyT.jl.git
synced 2024-12-24 18:10:29 +01:00
optimisation in constraintLHS!
This commit is contained in:
parent
d6bb71b3cb
commit
760dfdc7d5
@ -107,11 +107,7 @@ function sparsify!{T}(M::AbstractArray{T}, eps=eps(T); verbose=false)
|
|||||||
info("Sparsifying $(size(M))-matrix... ")
|
info("Sparsifying $(size(M))-matrix... ")
|
||||||
end
|
end
|
||||||
|
|
||||||
for n in eachindex(M)
|
clamp_small!(M, eps)
|
||||||
if abs(M[n]) < eps
|
|
||||||
M[n] = zero(T)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if verbose
|
if verbose
|
||||||
info("$(rpad(densM, 20)) → $(rpad(dens(M),20))), ($(countnz(M)) non-zeros)")
|
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)
|
return sparse(M)
|
||||||
end
|
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)
|
sparsify{T}(U::AbstractArray{T}, tol=eps(T); verbose=false) = sparsify!(deepcopy(U), tol, verbose=verbose)
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
@ -97,7 +97,7 @@ end
|
|||||||
|
|
||||||
function constraintLHS!(M, cnstr, Us, Ust, dims, eps=1000*eps(eltype(first(M))))
|
function constraintLHS!(M, cnstr, Us, Ust, dims, eps=1000*eps(eltype(first(M))))
|
||||||
for π in 1:endof(Us)
|
for π in 1:endof(Us)
|
||||||
M[π] = PropertyT.sparsify!(dims[π].*Ust[π]*cnstr*Us[π], eps)
|
M[π] = dims[π].*PropertyT.clamp_small!(Ust[π]*cnstr*Us[π], eps)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user