mirror of
https://github.com/kalmarek/PropertyT.jl.git
synced 2024-12-01 10:15:28 +01:00
a bit on support for constraints
This commit is contained in:
parent
49b4c6f510
commit
3f11b2df9a
@ -147,16 +147,22 @@ function LinearAlgebra.dot(cm::ConstraintMatrix, m::AbstractMatrix{T}) where {T}
|
|||||||
return convert(eltype(cm), cm.val) * (pos - neg)
|
return convert(eltype(cm), cm.val) * (pos - neg)
|
||||||
end
|
end
|
||||||
|
|
||||||
function constraints(A::StarAlgebras.StarAlgebra; augmented::Bool)
|
function constraints(
|
||||||
return constraints(basis(A), A.mstructure; augmented = augmented)
|
A::StarAlgebras.StarAlgebra,
|
||||||
|
support = axes(A.mstructure, 1);
|
||||||
|
augmented::Bool,
|
||||||
|
)
|
||||||
|
return constraints(basis(A), support, A.mstructure; augmented = augmented)
|
||||||
end
|
end
|
||||||
|
|
||||||
function constraints(
|
function constraints(
|
||||||
basis::StarAlgebras.AbstractBasis,
|
basis::StarAlgebras.AbstractBasis,
|
||||||
|
support,
|
||||||
mstr::StarAlgebras.MultiplicativeStructure;
|
mstr::StarAlgebras.MultiplicativeStructure;
|
||||||
augmented = false,
|
augmented = false,
|
||||||
)
|
)
|
||||||
cnstrs = _constraints(
|
cnstrs = _constraints(
|
||||||
|
support,
|
||||||
mstr;
|
mstr;
|
||||||
augmented = augmented,
|
augmented = augmented,
|
||||||
num_constraints = length(basis),
|
num_constraints = length(basis),
|
||||||
@ -170,6 +176,7 @@ function constraints(
|
|||||||
end
|
end
|
||||||
|
|
||||||
function _constraints(
|
function _constraints(
|
||||||
|
support::AbstractVector{<:Integer},
|
||||||
mstr::StarAlgebras.MultiplicativeStructure;
|
mstr::StarAlgebras.MultiplicativeStructure;
|
||||||
augmented::Bool = false,
|
augmented::Bool = false,
|
||||||
num_constraints = maximum(mstr),
|
num_constraints = maximum(mstr),
|
||||||
@ -178,9 +185,11 @@ function _constraints(
|
|||||||
cnstrs = [signed(eltype(mstr))[] for _ in 1:num_constraints]
|
cnstrs = [signed(eltype(mstr))[] for _ in 1:num_constraints]
|
||||||
LI = LinearIndices(size(mstr))
|
LI = LinearIndices(size(mstr))
|
||||||
|
|
||||||
for ci in CartesianIndices(size(mstr))
|
l = length(support)
|
||||||
k = LI[ci]
|
for ci in CartesianIndices((l, l))
|
||||||
i, j = Tuple(ci)
|
i1, j1 = Tuple(ci)
|
||||||
|
i, j = support[i1], support[j1]
|
||||||
|
k = LI[CartesianIndex(i, j)]
|
||||||
a_star_b = mstr[-i, j]
|
a_star_b = mstr[-i, j]
|
||||||
push!(cnstrs[a_star_b], k)
|
push!(cnstrs[a_star_b], k)
|
||||||
if augmented
|
if augmented
|
||||||
@ -193,3 +202,17 @@ function _constraints(
|
|||||||
end
|
end
|
||||||
return cnstrs
|
return cnstrs
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function SparseArrays.sparse(cm::ConstraintMatrix{Tv,Ti}) where {Tv,Ti}
|
||||||
|
I = Ti[]
|
||||||
|
J = Ti[]
|
||||||
|
V = Tv[]
|
||||||
|
CI = CartesianIndices(cm)
|
||||||
|
for (idx, v) in nzpairs(cm)
|
||||||
|
ci = CI[idx]
|
||||||
|
push!(I, ci[1])
|
||||||
|
push!(J, ci[2])
|
||||||
|
push!(V, v)
|
||||||
|
end
|
||||||
|
return SparseArrays.sparse(I, J, V, size(cm)...)
|
||||||
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user