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

Merge branch 'AutFn' into enh/julia-v0.7

This commit is contained in:
kalmarek 2019-01-17 08:39:13 +01:00
commit 4768bb6e35
2 changed files with 12 additions and 7 deletions

View File

@ -107,11 +107,7 @@ function sparsify!(M::AbstractArray{T}, eps=eps(T); verbose=false) where T
@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))), ($(count(!iszero, M)) non-zeros)") @info("$(rpad(densM, 20))$(rpad(dens(M),20))), ($(count(!iszero, M)) non-zeros)")
@ -120,6 +116,15 @@ function sparsify!(M::AbstractArray{T}, eps=eps(T); verbose=false) where T
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
function sparsify(U::AbstractArray{T}, tol=eps(T); verbose=false) where T function sparsify(U::AbstractArray{T}, tol=eps(T); verbose=false) where T
return sparsify!(deepcopy(U), tol, verbose=verbose) return sparsify!(deepcopy(U), tol, verbose=verbose)
end end

View File

@ -96,8 +96,8 @@ function SOS_problem(X::GroupRingElem, orderunit::GroupRingElem, data::OrbitData
end 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 eachindex(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