Skip to content

Commit 5ec0569

Browse files
committed
Fix format
1 parent 333e92f commit 5ec0569

File tree

4 files changed

+82
-23
lines changed

4 files changed

+82
-23
lines changed

src/DSDP.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import DSDP_jll
1010
using LinearAlgebra
1111

1212
macro dsdp_ccall(f, args...)
13-
quote
13+
return quote
1414
# QuoteNode prevents the interpretion of the symbol
1515
# and leave it as a symbol
1616
info =

src/MOI_wrapper.jl

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,8 @@ const _SetWithDotProd = MOI.SetWithDotProducts{
234234
MOI.TriangleVectorization{Cdouble,MOI.LowRankMatrix{Cdouble}},
235235
}
236236

237-
const SupportedSets = Union{
238-
MOI.Nonnegatives,
239-
MOI.PositiveSemidefiniteConeTriangle,
240-
_SetWithDotProd,
241-
}
237+
const SupportedSets =
238+
Union{MOI.Nonnegatives,MOI.PositiveSemidefiniteConeTriangle,_SetWithDotProd}
242239

243240
function MOI.supports_add_constrained_variables(
244241
::Optimizer,
@@ -287,7 +284,7 @@ function new_block(model::Optimizer, set::_SetWithDotProd)
287284
push!(model.varmap, (blk, 0, 0))
288285
push!(model.rank_one, set.vectors[i].matrix)
289286
end
290-
new_block(model, set.set)
287+
return new_block(model, set.set)
291288
end
292289

293290
function _add_constrained_variables(optimizer::Optimizer, set::SupportedSets)
@@ -339,7 +336,12 @@ function constrain_variables_on_creation(
339336
return
340337
end
341338

342-
function _setcoefficient!(dest::Optimizer, coef, constr::Integer, vi::MOI.VariableIndex)
339+
function _setcoefficient!(
340+
dest::Optimizer,
341+
coef,
342+
constr::Integer,
343+
vi::MOI.VariableIndex,
344+
)
343345
blk, i, j = varmap(dest, vi)
344346
rank_one = dest.rank_one[vi.value]
345347
if isnothing(rank_one)
@@ -350,15 +352,18 @@ function _setcoefficient!(dest::Optimizer, coef, constr::Integer, vi::MOI.Variab
350352
push!(dest.lpcoefs, coef)
351353
else
352354
sdp = dest.blk[blk]
353-
push!(dest.sdpdinds[end][sdp], i + (j - 1) * dest.blockdims[blk] - 1)
355+
push!(
356+
dest.sdpdinds[end][sdp],
357+
i + (j - 1) * dest.blockdims[blk] - 1,
358+
)
354359
if i != j
355360
coef /= 2
356361
end
357362
push!(dest.sdpdcoefs[end][sdp], coef)
358363
end
359364
else
360365
d = Cint(dest.blockdims[blk])
361-
push!(dest.cached_ind, collect(Cint(0):(d - 1)))
366+
push!(dest.cached_ind, collect(Cint(0):(d-1)))
362367
# We use `Add` and not `Set` because I think (if I interpret the name correctly) that would allow mixing with sparse matrices for the same block and constraint
363368
DSDP.SDPCone.SetARankOneMat(
364369
dest.sdpcone,
@@ -385,8 +390,27 @@ end
385390
function _set_A_matrices(m::Optimizer, i)
386391
for (blk, blkdim) in zip(m.blk, m.blockdims)
387392
if blkdim > 0 && !isempty(m.sdpdcoefs[end][blk])
388-
@show (blk - 1, i, blkdim, 1.0, 0, m.sdpdinds[end][blk], m.sdpdcoefs[end][blk], length(m.sdpdcoefs[end][blk]))
389-
SDPCone.SetASparseVecMat(m.sdpcone, blk - 1, i, blkdim, 1.0, 0, m.sdpdinds[end][blk], m.sdpdcoefs[end][blk], length(m.sdpdcoefs[end][blk]))
393+
@show (
394+
blk - 1,
395+
i,
396+
blkdim,
397+
1.0,
398+
0,
399+
m.sdpdinds[end][blk],
400+
m.sdpdcoefs[end][blk],
401+
length(m.sdpdcoefs[end][blk]),
402+
)
403+
SDPCone.SetASparseVecMat(
404+
m.sdpcone,
405+
blk - 1,
406+
i,
407+
blkdim,
408+
1.0,
409+
0,
410+
m.sdpdinds[end][blk],
411+
m.sdpdcoefs[end][blk],
412+
length(m.sdpdcoefs[end][blk]),
413+
)
390414
end
391415
end
392416
return
@@ -416,12 +440,7 @@ function MOI.copy_to(dest::Optimizer, src::MOI.ModelLike)
416440
index_map,
417441
MOI.PositiveSemidefiniteConeTriangle,
418442
)
419-
constrain_variables_on_creation(
420-
dest,
421-
src,
422-
index_map,
423-
_SetWithDotProd,
424-
)
443+
constrain_variables_on_creation(dest, src, index_map, _SetWithDotProd)
425444
vis_src = MOI.get(src, MOI.ListOfVariableIndices())
426445
if length(vis_src) < length(index_map.var_map)
427446
_error(

src/sdpcone.jl

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,28 @@ function SetADenseVecMat(
9595
) sdpcone arg2 arg3 arg4 arg5 arg6 arg7
9696
end
9797

98-
function SetARankOneMat(sdpcone::SDPConeT, blockj::Integer, vari::Integer, n::Integer, alpha::Cdouble, ishift::Integer, ind::Vector{Cint}, val::Vector{Cdouble}, nnz::Integer)
99-
@dsdp_ccall SDPConeSetARankOneMat (SDPConeT, Cint, Cint, Cint, Cdouble, Cint, Ptr{Cint}, Ptr{Cdouble}, Cint) sdpcone blockj vari n alpha ishift ind val nnz
98+
function SetARankOneMat(
99+
sdpcone::SDPConeT,
100+
blockj::Integer,
101+
vari::Integer,
102+
n::Integer,
103+
alpha::Cdouble,
104+
ishift::Integer,
105+
ind::Vector{Cint},
106+
val::Vector{Cdouble},
107+
nnz::Integer,
108+
)
109+
@dsdp_ccall SDPConeSetARankOneMat (
110+
SDPConeT,
111+
Cint,
112+
Cint,
113+
Cint,
114+
Cdouble,
115+
Cint,
116+
Ptr{Cint},
117+
Ptr{Cdouble},
118+
Cint,
119+
) sdpcone blockj vari n alpha ishift ind val nnz
100120
end
101121

102122
function SetConstantMat(
@@ -200,8 +220,28 @@ function AddIdentity(
200220
@dsdp_ccall SDPConeAddIdentity (SDPConeT, Cint, Cint, Cint, Cdouble) sdpcone arg2 arg3 arg4 arg5
201221
end
202222

203-
function AddARankOneMat(sdpcone::SDPConeT, blockj::Integer, vari::Integer, n::Integer, alpha::Cdouble, ishift::Integer, ind::Vector{Cint}, val::Vector{Cdouble}, nnz::Integer)
204-
@dsdp_ccall SDPConeAddARankOneMat (SDPConeT, Cint, Cint, Cint, Cdouble, Cint, Ptr{Cint}, Ptr{Cdouble}, Cint) sdpcone blockj vari n alpha ishift ind val nnz
223+
function AddARankOneMat(
224+
sdpcone::SDPConeT,
225+
blockj::Integer,
226+
vari::Integer,
227+
n::Integer,
228+
alpha::Cdouble,
229+
ishift::Integer,
230+
ind::Vector{Cint},
231+
val::Vector{Cdouble},
232+
nnz::Integer,
233+
)
234+
@dsdp_ccall SDPConeAddARankOneMat (
235+
SDPConeT,
236+
Cint,
237+
Cint,
238+
Cint,
239+
Cdouble,
240+
Cint,
241+
Ptr{Cint},
242+
Ptr{Cdouble},
243+
Cint,
244+
) sdpcone blockj vari n alpha ishift ind val nnz
205245
end
206246

207247
function AddSparseVecMat(

test/maxcut.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function maxcut(nnodes, edges)
7070
yy = zeros(nnodes)
7171
indd = zeros(Cint, nnodes + nedges)
7272
val = zeros(nnodes + nedges)
73-
indd[nedges.+(1:nnodes)] = iptr
73+
indd[nedges .+ (1:nnodes)] = iptr
7474
tval = 0.0
7575
for (i, (u, v, w)) in enumerate(edges)
7676
indd[i] = di(u, v)

0 commit comments

Comments
 (0)