Skip to content

Commit

Permalink
Merge pull request #22 from stelmo/mk-gen-substs
Browse files Browse the repository at this point in the history
generalize the substitutions
  • Loading branch information
exaexa authored Oct 28, 2024
2 parents 8fcc44c + d6c2ace commit 31cb65e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/constraint_trees.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ ConstraintTrees.var_count(x::ParameterQuadraticValue) =
end

# substitute in the variables as symbolic numbers - useful to construct the KKT function
ConstraintTrees.substitute(x::ParameterLinearValue, y::Vector{Expression}) =
ConstraintTrees.substitute(x::ParameterLinearValue, y) =
ConstraintTrees.sum(
(idx == 0 ? x.weights[i] : x.weights[i] * y[idx] for (i, idx) in enumerate(x.idxs)),
init = Expression(0.0),
init = zero(eltype(y)),
)

ConstraintTrees.substitute(x::ParameterQuadraticValue, y::Vector{Expression}) =
ConstraintTrees.substitute(x::ParameterQuadraticValue, y) =
ConstraintTrees.sum(
(
let (idx1, idx2) = x.idxs[i]
(idx1 == 0 ? 1.0 : y[idx1]) * (idx2 == 0 ? 1.0 : y[idx2]) * w
end for (i, w) in enumerate(x.weights)
),
init = Expression(0.0),
init = zero(eltype(y)),
)

0 comments on commit 31cb65e

Please sign in to comment.