Skip to content

Commit

Permalink
Add Parameters struct (#6)
Browse files Browse the repository at this point in the history
* Add Parameters struct

* Fix kwdef

* Fix
  • Loading branch information
blegat authored Nov 16, 2023
1 parent 37c8ec0 commit a5afb31
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 225 deletions.
58 changes: 32 additions & 26 deletions src/SDPLR.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@ function solve_sdpa_file(file)
return run(`$(SDPLR_jll.sdplr()) $file`)
end

# Default values taken from `SDPLR-1.03-beta/source/params.c`
Base.@kwdef struct Parameters
#inputtype = 1
rho_f::Cdouble = 1.0e-5
rho_c::Cdouble = 1.0e-1
sigmafac::Cdouble = 2.0
rankreduce::Csize_t = 0
timelim::Csize_t = 3600
printlevel::Csize_t = 1
dthresh_dim::Csize_t = 10
dthresh_dens::Cdouble = 0.75
numbfgsvecs::Csize_t = 4
rankredtol::Cdouble = 2.2204460492503131e-16
gaptol::Cdouble = 1.0e-3
checkbd::Cptrdiff_t = -1
typebd::Cptrdiff_t = 1
end

function solve(
blksz::Vector{Cptrdiff_t},
blktype::Vector{Cchar},
Expand All @@ -15,19 +33,7 @@ function solve(
CAcol::Vector{Csize_t},
CAinfo_entptr::Vector{Csize_t},
CAinfo_type::Vector{Cchar},
numbfgsvecs::Integer,
rho_f::Cdouble,
rho_c::Cdouble,
sigmafac::Cdouble,
rankreduce::Integer,
gaptol::Cdouble,
checkbd::Integer,
typebd::Integer,
dthresh_dim::Integer,
dthresh_dens::Cdouble,
timelim::Integer,
rankredtol::Cdouble,
printlevel::Integer,
params::Parameters,
R::Vector{Cdouble},
lambda::Vector{Cdouble},
maxranks::Vector{Csize_t},
Expand Down Expand Up @@ -55,19 +61,19 @@ function solve(
CAcol::Ptr{Csize_t},
CAinfo_entptr::Ptr{Csize_t},
CAinfo_type::Ptr{Cchar},
numbfgsvecs::Csize_t,
rho_f::Cdouble,
rho_c::Cdouble,
sigmafac::Cdouble,
rankreduce::Csize_t,
gaptol::Cdouble,
checkbd::Cptrdiff_t,
typebd::Csize_t,
dthresh_dim::Csize_t,
dthresh_dens::Cdouble,
timelim::Csize_t,
rankredtol::Cdouble,
printlevel::Csize_t,
params.numbfgsvecs::Csize_t,
params.rho_f::Cdouble,
params.rho_c::Cdouble,
params.sigmafac::Cdouble,
params.rankreduce::Csize_t,
params.gaptol::Cdouble,
params.checkbd::Cptrdiff_t,
params.typebd::Csize_t,
params.dthresh_dim::Csize_t,
params.dthresh_dens::Cdouble,
params.timelim::Csize_t,
params.rankredtol::Cdouble,
params.printlevel::Csize_t,
R::Ptr{Cdouble},
lambda::Ptr{Cdouble},
maxranks::Ptr{Csize_t},
Expand Down
4 changes: 1 addition & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
using SDPLR

SDPLR.solve_sdpa_file("vibra1.dat-s")
include("test_vibra.jl")
25 changes: 25 additions & 0 deletions test/test_vibra.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Test
import SDPLR
@testset "Solve vibra with sdplr executable" begin
SDPLR.solve_sdpa_file("vibra1.dat-s")
end
@testset "Solve vibra with sdplrlib" begin
include("vibra.jl")
ret = SDPLR.solve(
blksz,
blktype,
b,
CAent,
CArow,
CAcol,
CAinfo_entptr,
CAinfo_type,
SDPLR.Parameters(),
R,
lambda,
maxranks,
ranks,
pieces,
)
@test iszero(ret)
end
198 changes: 2 additions & 196 deletions test/vibra.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using Test
import SDPLR
ct = 449
m = 36
numblk = 3
blksz = Cptrdiff_t[24, 25, 36]
Expand Down Expand Up @@ -1510,132 +1507,7 @@ CAcol = Csize_t[
24,
36,
]
CAinfo_type = Cchar[
's',
's',
'd',
's',
's',
'd',
's',
's',
'd',
's',
's',
'd',
's',
's',
'd',
's',
's',
'd',
's',
's',
'd',
's',
's',
'd',
's',
's',
'd',
's',
's',
'd',
's',
's',
'd',
's',
's',
'd',
's',
's',
'd',
's',
's',
'd',
's',
's',
'd',
's',
's',
'd',
's',
's',
'd',
's',
's',
'd',
's',
's',
'd',
's',
's',
'd',
's',
's',
'd',
's',
's',
'd',
's',
's',
'd',
's',
's',
'd',
's',
's',
'd',
's',
's',
'd',
's',
's',
'd',
's',
's',
'd',
's',
's',
'd',
's',
's',
'd',
's',
's',
'd',
's',
's',
'd',
's',
's',
'd',
's',
's',
'd',
's',
's',
'd',
's',
's',
'd',
's',
's',
'd',
]
numbfgsvecs = 4
rho_f = 0.000010
rho_c = 0.100000
sigmafac = 2.000000
rankreduce = 0
gaptol = 0.001000
checkbd = -1
typebd = 1
dthresh_dim = 10
dthresh_dens = 0.750000
timelim = 3600
rankredtol = 0.000000
printlevel = 1
CAinfo_type = repeat(blktype, m + 1)
R = Cdouble[
0.409043,
0.849300,
Expand Down Expand Up @@ -2115,44 +1987,7 @@ R = Cdouble[
-0.267370,
-0.527711,
]
lambda = Cdouble[
0.000000,
0.000000,
0.000000,
0.000000,
0.000000,
0.000000,
0.000000,
0.000000,
0.000000,
0.000000,
0.000000,
0.000000,
0.000000,
0.000000,
0.000000,
0.000000,
0.000000,
0.000000,
0.000000,
0.000000,
0.000000,
0.000000,
0.000000,
0.000000,
0.000000,
0.000000,
0.000000,
0.000000,
0.000000,
0.000000,
0.000000,
0.000000,
0.000000,
0.000000,
0.000000,
0.000000,
]
lambda = zeros(m)
maxranks = Csize_t[9, 9, 1]
ranks = Csize_t[9, 9, 1]
pieces = Cdouble[
Expand All @@ -2165,32 +2000,3 @@ pieces = Cdouble[
0.011765,
1.000000,
]
ret = SDPLR.solve(
blksz,
blktype,
b,
CAent,
CArow,
CAcol,
CAinfo_entptr,
CAinfo_type,
numbfgsvecs,
rho_f,
rho_c,
sigmafac,
rankreduce,
gaptol,
checkbd,
typebd,
dthresh_dim,
dthresh_dens,
timelim,
rankredtol,
printlevel,
R,
lambda,
maxranks,
ranks,
pieces,
)
@test iszero(ret)

0 comments on commit a5afb31

Please sign in to comment.