Skip to content

Commit 58f23cd

Browse files
authored
Improve performance of GeoMeanAtom (#621)
1 parent ed144dc commit 58f23cd

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/atoms/GeoMeanAtom.jl

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,15 @@ function new_conic_form!(context::Context{T}, q::GeoMeanAtom) where {T}
4040
n = length(q.children)
4141
x = first(q.children)
4242
t = Variable(size(x))
43-
for i in 1:size(x, 1), j in 1:size(x, 2)
44-
f = operate(
45-
vcat,
46-
T,
47-
sign(q),
48-
conic_form!(context, t[i, j]),
49-
(conic_form!(context, y[i, j]) for y in q.children)...,
50-
)
51-
MOI_add_constraint(context.model, f, MOI.GeometricMeanCone(n + 1))
43+
t_tape = conic_form!(context, t)
44+
child_fns = map(q.children) do y
45+
return MOI.Utilities.scalarize(to_vaf(conic_form!(context, y)))
5246
end
53-
return conic_form!(context, t)
47+
for (i, ti) in enumerate(t_tape.variables)
48+
f = MOI.Utilities.operate(vcat, T, ti, getindex.(child_fns, i)...)
49+
MOI.add_constraint(context.model, f, MOI.GeometricMeanCone(n + 1))
50+
end
51+
return t_tape
5452
end
5553

5654
geomean(args::Union{AbstractExpr,Value}...) = GeoMeanAtom(args...)

0 commit comments

Comments
 (0)