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 = 1:1000
global e
e += x;
end
p = minimize(e, x>=1);
end
@time solve!(p, () -> ECOS.Optimizer(verbose=0))
Summation example
0.043382 seconds (4.65 k allocations: 11.764 MiB, 57.17% gc time)
1.502483 seconds (1.88 M allocations: 93.280 MiB, 7.14% gc time)

Indexing.

println("Indexing example")
x = Variable(1000, 1);
e = 0;
@time begin
for i = 1:1000
global e
e += x[i];
end
p = minimize(e, x >= ones(1000, 1));
end
@time solve!(p, () -> ECOS.Optimizer(verbose=0))
Indexing example
0.239141 seconds (124.84 k allocations: 17.617 MiB, 11.34% gc time)
0.458959 seconds (586.95 k allocations: 101.843 MiB, 22.36% gc 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(verbose=0))
Matrix constraint example
0.131930 seconds (148.40 k allocations: 7.158 MiB)
3.562755 seconds (728.31 k allocations: 334.766 MiB, 34.32% gc 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(verbose=0))

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(verbose=0))
#end
Transpose example
0.063485 seconds (75.76 k allocations: 3.727 MiB)
0.044608 seconds (42.61 k allocations: 2.198 MiB)