Skip to content

Commit dc3f4f3

Browse files
committed
wip
1 parent f37d752 commit dc3f4f3

17 files changed

Lines changed: 173 additions & 191 deletions

File tree

Project.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ version = "0.16.0"
55
[deps]
66
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
77
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
8-
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
98
LDLFactorizations = "40e66cde-538c-5869-a4ad-c39174c6795b"
109
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1110
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"

src/Context.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ mutable struct Context{T,M}
1818
detected_infeasible_during_formulation::Ref{Bool}
1919

2020
# Cache
21-
conic_form_cache::DataStructures.WeakKeyIdDict{Any, Any}
21+
# conic_form_cache::DataStructures.WeakKeyIdDict{Any, Any}
22+
conic_form_cache::IdDict{Any, Any}
2223
end
2324

2425
function Context{T}(optimizer) where {T}
@@ -38,3 +39,4 @@ function Context{T}(optimizer) where {T}
3839
IdDict{Any,Any}()
3940
)
4041
end
42+

src/Convex.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ using SparseArrays
77
using LDLFactorizations
88
using AbstractTrees: AbstractTrees, children
99
using SuiteSparseGraphBLAS
10-
using DataStructures
10+
# using DataStructures
1111

1212
using MathOptInterface
1313
const MOI = MathOptInterface
@@ -130,6 +130,12 @@ function vec_tril(M)
130130
return M[inds]
131131
end
132132

133+
const SPARSE_VECTOR{T} = GBVector{T,T}
134+
const SPARSE_MATRIX{T} = GBMatrix{T,T}
135+
spzeros(T, d) = GBVector{T,T}(d)
136+
spzeros(T, n, m) = GBMatrix{T,T}(n, m)
137+
spidentity(T, d) = GBMatrix{T,T}(Diagonal(ones(T, d)))
138+
133139
include("Context.jl")
134140
### modeling framework
135141
include("dcp.jl")

src/SparseTape.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
struct SparseAffineOperation{T}
2-
matrix::Union{GBMatrix{T,T}}
3-
vector::Union{GBVector{T,T}}
2+
matrix::SPARSE_MATRIX{T}
3+
vector::SPARSE_VECTOR{T}
44
end
55

66
# function Base.convert(
@@ -16,7 +16,7 @@ function SparseAffineOperation(
1616
A::AbstractMatrix{T},
1717
b::AbstractVector{T},
1818
) where {T}
19-
return SparseAffineOperation{T}(GBMatrix{T,T}(A), GBVector{T, T}(b))
19+
return SparseAffineOperation{T}(SPARSE_MATRIX{T}(A), GBVector{T, T}(b))
2020
end
2121

2222

src/atoms/affine/diag.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function _conic_form!(context::Context{T}, x::DiagAtom) where {T}
7878
sz_diag = Base.min(num_rows + k, num_cols)
7979
end
8080

81-
select_diag = GBMatrix{T,T}(sz_diag, length(x.children[1]))
81+
select_diag = SPARSE_MATRIX{T}(sz_diag, length(x.children[1]))
8282
for i in 1:sz_diag
8383
select_diag[i, start_index] = 1
8484
start_index += num_rows + 1

src/atoms/affine/diagm.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ function _conic_form!(context::Context{T}, x::DiagMatrixAtom) where {T}
6363
obj = conic_form!(context, only(children(x)))
6464

6565
sz = x.size[1]
66-
I = 1:sz+1:sz*sz
67-
J = 1:sz
66+
I = collect(1:sz+1:sz*sz)
67+
J = collect(1:sz)
6868
V = one(T)
6969
coeff = GBMatrix{T, T}(I, J, V, sz * sz, sz)
7070
# coeff = sparse(, 1:sz, one(T),

src/atoms/affine/index.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ function _conic_form!(context::Context{T}, x::IndexAtom) where {T}
7171
end
7272
end
7373

74-
index_matrix = GBMatrix{T,T}(collect(1:sz), J, one(T), m, n)
74+
index_matrix = SPARSE_MATRIX{T}(collect(1:sz), J, one(T), m, n)
7575
else
76-
index_matrix = GBMatrix{T,T}(collect(1:length(x.inds)), collect(x.inds), one(T), m, n)
76+
index_matrix = SPARSE_MATRIX{T}(collect(1:length(x.inds)), collect(x.inds), one(T), m, n)
7777
end
7878

7979
return operate(add_operation, T, sign(x), index_matrix, obj)

src/atoms/affine/multiply_divide.jl

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,18 @@ function real_convert(::Type{T}, x::Number) where {T}
6666
return T(x)
6767
end
6868
function real_convert(::Type{T}, x::AbstractMatrix) where {T}
69-
return GBMatrix{T, T}(x)
69+
return GBMatrix{T,T}(x)
7070
end
7171

72-
function real_convert(::Type{T}, x::GBMatrix{T,T}) where {T}
72+
function real_convert(::Type{T}, x::SPARSE_MATRIX{T}) where {T}
7373
return x
7474
end
7575

76-
function real_convert(::Type{T}, x::GBVector{T,T}) where {T}
76+
function real_convert(::Type{T}, x::SPARSE_VECTOR{T}) where {T}
7777
return x
7878
end
7979
function real_convert(::Type{T}, x::AbstractVector) where {T}
80-
return GBVector{T,T}(x)
80+
return SPARSE_VECTOR{T}(x)
8181
end
8282

8383
function _conic_form!(context::Context{T}, x::MultiplyAtom) where {T}
@@ -158,7 +158,7 @@ function _conic_form!(context::Context{T}, x::MultiplyAtom) where {T}
158158
end
159159

160160
# _id(T, n) = Diagonal(one(T)*I, n)
161-
_id(T, n) = gbidentity(T, n)
161+
_id(T, n) = spidentity(T, n)
162162

163163
function *(x::AbstractExpr, y::AbstractExpr)
164164
if isequal(x, y) && x.size == (1, 1)
@@ -171,6 +171,32 @@ end
171171
*(x::AbstractExpr, y::Value) = MultiplyAtom(x, constant(y))
172172
/(x::AbstractExpr, y::Value) = MultiplyAtom(x, constant(1 ./ y))
173173

174+
# ambiguity
175+
function Base.:(*)(
176+
x::Convex.AbstractExpr,
177+
y::Union{
178+
LinearAlgebra.Transpose{
179+
<:Any,
180+
<:SuiteSparseGraphBLAS.AbstractGBArray{T,F,O},
181+
},
182+
SuiteSparseGraphBLAS.AbstractGBArray{T,F,O},
183+
},
184+
) where {T,F,O}
185+
return MultiplyAtom(x, constant(y))
186+
end
187+
function Base.:(*)(
188+
x::Union{
189+
LinearAlgebra.Transpose{
190+
<:Any,
191+
<:SuiteSparseGraphBLAS.AbstractGBArray{T,F,O},
192+
},
193+
SuiteSparseGraphBLAS.AbstractGBArray{T,F,O},
194+
},
195+
y::Convex.AbstractExpr,
196+
) where {T,F,O}
197+
return MultiplyAtom(constant(x), y)
198+
end
199+
174200
function dotmultiply(x, y)
175201
if vexity(x) != ConstVexity()
176202
if vexity(y) != ConstVexity()

src/atoms/affine/partialtrace.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
# This function returns the jth term in the sum, namely
66
# (I ⊗ <j| ⊗ I) x (I ⊗ |j> ⊗ I).
77
function _term(x, j::Int, sys, dims)
8-
a = sparse(1.0I, 1, 1)
9-
b = sparse(1.0I, 1, 1)
8+
a = spidentity(Float64, 1)
9+
b = spidentity(Float64, 1)
1010
for (i_sys, dim) in enumerate(dims)
1111
if i_sys == sys
1212
# create a vector that is only 1 at its jth component
13-
v = spzeros(dim, 1)
13+
v = spzeros(Float64, dim, 1)
1414
v[j] = 1
1515
a = kron(a, v')
1616
b = kron(b, v)
1717
else
18-
a = kron(a, sparse(1.0I, dim, dim))
19-
b = kron(b, sparse(1.0I, dim, dim))
18+
a = kron(a, spidentity(Float64, dim))
19+
b = kron(b, spidentity(Float64, dim))
2020
end
2121
end
2222
return a * x * b

src/atoms/exp_+_sdp_cone/logdet.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function _conic_form!(context::Context{T}, x::LogDetAtom) where {T}
4242
X = conic_form!(context, v)
4343

4444
t = conic_form!(context, Variable())
45-
f = operate(vcat, T, sign(x), t, [one(T)], X)
45+
f = operate(vcat, T, sign(x), t, SPARSE_VECTOR{T}([one(T)]), X)
4646
side_dimension = size(only(children(x)), 1)
4747

4848
set = MOI.LogDetConeTriangle(side_dimension)

0 commit comments

Comments
 (0)