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.001557 seconds (4.51 k allocations: 11.738 MiB)
  0.001241 seconds (11.07 k allocations: 759.438 KiB)

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.001687 seconds (8.00 k allocations: 11.875 MiB)
  0.069336 seconds (39.21 k allocations: 41.886 MiB, 57.93% 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(X), A * X == b)
end
@time solve!(p, ECOS.Optimizer; silent_solver = true)
Matrix constraint example
  0.000065 seconds (20 allocations: 313.375 KiB)
  1.437838 seconds (2.98 k allocations: 196.152 MiB)

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(X' - A), X[1, 1] == 1);
solve!(p, ECOS.Optimizer; silent_solver = true)
#end
Transpose example
  0.000141 seconds (3.81 k allocations: 397.078 KiB)
  0.000800 seconds (2.78 k allocations: 127.703 KiB)

This page was generated using Literate.jl.