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.025713 seconds (4.61 k allocations: 11.759 MiB, 69.03% compilation time)
6.087871 seconds (6.79 M allocations: 413.121 MiB, 4.14% 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.186960 seconds (92.36 k allocations: 16.338 MiB, 57.33% compilation time)
0.102709 seconds (191.04 k allocations: 65.288 MiB, 17.72% 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.056181 seconds (48.09 k allocations: 2.490 MiB, 99.62% compilation time)
2.391595 seconds (407.92 k allocations: 174.982 MiB, 2.54% gc time, 0.60% 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.068207 seconds (57.05 k allocations: 2.960 MiB, 99.58% compilation time)
0.038113 seconds (21.49 k allocations: 1.114 MiB, 95.40% compilation time)