All of the examples can be found in Jupyter notebook form here.

# Paper examples

using Convex, ECOS

Summation.

println("Summation example")
x = Variable();
e = 0;
@time begin
for i in 1:1000
global e
e += x
end
p = minimize(e, x >= 1)
end
@time solve!(p, ECOS.Optimizer; silent_solver = true)
Summation example
0.025423 seconds (4.61 k allocations: 11.759 MiB, 66.51% compilation time)
5.225760 seconds (6.67 M allocations: 401.237 MiB, 2.87% gc time, 0.39% compilation time)

Indexing.

println("Indexing example")
x = Variable(1000, 1);
e = 0;
@time begin
for i in 1:1000
global e
e += x[i]
end
p = minimize(e, x >= ones(1000, 1))
end
@time solve!(p, ECOS.Optimizer; silent_solver = true)
Indexing example
0.170428 seconds (92.33 k allocations: 16.337 MiB, 56.92% compilation time)
0.164420 seconds (189.35 k allocations: 65.260 MiB, 36.77% gc time, 11.52% compilation time)

Matrix constraints.

println("Matrix constraint example")
n, m, p = 100, 100, 100
X = Variable(m, n);
A = randn(p, m);
b = randn(p, n);
@time begin
p = minimize(norm(vec(X)), A * X == b)
end
@time solve!(p, ECOS.Optimizer; silent_solver = true)
Matrix constraint example
0.042614 seconds (48.07 k allocations: 2.489 MiB, 99.73% compilation time)
2.206558 seconds (392.59 k allocations: 174.421 MiB, 1.93% gc time, 0.56% compilation time)

Transpose.

println("Transpose example")
X = Variable(5, 5);
A = randn(5, 5);
@time begin
p = minimize(norm2(X - A), X' == X)
end
@time solve!(p, ECOS.Optimizer; silent_solver = true)

n = 3
A = randn(n, n);
#@time begin
X = Variable(n, n);
p = minimize(norm(vec(X' - A)), X[1, 1] == 1);
solve!(p, ECOS.Optimizer; silent_solver = true)
#end
Transpose example
0.064357 seconds (57.03 k allocations: 2.959 MiB, 99.61% compilation time)
0.035313 seconds (20.79 k allocations: 1.102 MiB, 96.14% compilation time)