diff --git a/examples/.gitignore b/examples/.gitignore deleted file mode 100644 index 0ec597f..0000000 --- a/examples/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -prob.dat-s -prob.sol diff --git a/examples/example.jl b/examples/example.jl deleted file mode 100644 index c1cbd9a..0000000 --- a/examples/example.jl +++ /dev/null @@ -1,103 +0,0 @@ -# Copyright (c) 2016: CSDP.jl contributors -# -# Use of this source code is governed by an MIT-style license that can be found -# in the LICENSE.md file or at https://opensource.org/licenses/MIT. - -using CSDP - -#= -# Example copied from `example/example.c` - An example showing how to call the easy_sdp() interface to CSDP. In - this example, we solve the problem - - max tr(C*X) - tr(A1*X)=1 - tr(A2*X)=2 - X >= 0 (X is PSD) - - where - - C=[2 1 - 1 2 - 3 0 1 - 0 2 0 - 1 0 3 - 0 - 0] - - A1=[3 1 - 1 3 - 0 0 0 - 0 0 0 - 0 0 0 - 1 - 0] - - A2=[0 0 - 0 0 - 3 0 1 - 0 4 0 - 1 0 5 - 0 - 1] - - Notice that all of the matrices have block diagonal structure. The first - block is of size 2x2. The second block is of size 3x3. The third block - is a diagonal block of size 2. - -=# - -C = BlockMatrix( - [ - 2 1 - 1 2 - ], - [ - 3 0 1 - 0 2 0 - 1 0 3 - ], - Diagonal([0, 0]), -) - -b = [1.0, 2.0] - -A1 = ConstraintMatrix( - 1, - [ - 3 1 - 1 3 - ], - [ - 0 0 0 - 0 0 0 - 0 0 0 - ], - Diagonal([1, 0]), -) - -A2 = ConstraintMatrix( - 2, - [ - 0 0 - 0 0 - ], - [ - 3 0 1 - 0 4 0 - 1 0 5 - ], - Diagonal([0, 1]), -) - -constraints = [A.csdp for A in [A1, A2]] - -CSDP.write_prob("prob.dat-s", C, b, constraints) - -X, y, Z = initsoln(C, b, constraints) - -pobj, dobj = easy_sdp(C, b, constraints, X, y, Z) - -@static if !Sys.iswindows() - CSDP.write_sol("prob.sol", X, y, Z) -end diff --git a/examples/prob-expected.dat-s b/examples/prob-expected.dat-s deleted file mode 100644 index 226e900..0000000 --- a/examples/prob-expected.dat-s +++ /dev/null @@ -1,20 +0,0 @@ -2 -3 -2 3 -2 -1.000000000000000000e+00 2.000000000000000000e+00 -0 1 1 1 2.000000000000000000e+00 -0 1 1 2 1.000000000000000000e+00 -0 1 2 2 2.000000000000000000e+00 -0 2 1 1 3.000000000000000000e+00 -0 2 1 3 1.000000000000000000e+00 -0 2 2 2 2.000000000000000000e+00 -0 2 3 3 3.000000000000000000e+00 -1 1 1 1 3.000000000000000000e+00 -1 1 1 2 1.000000000000000000e+00 -1 1 2 2 3.000000000000000000e+00 -1 3 1 1 1.000000000000000000e+00 -2 2 1 1 3.000000000000000000e+00 -2 2 2 2 4.000000000000000000e+00 -2 2 1 3 1.000000000000000000e+00 -2 2 3 3 5.000000000000000000e+00 -2 3 2 2 1.000000000000000000e+00 diff --git a/examples/prob-expected.sol b/examples/prob-expected.sol deleted file mode 100644 index 8a38e3a..0000000 --- a/examples/prob-expected.sol +++ /dev/null @@ -1,19 +0,0 @@ -7.499999999674811235e-01 9.999999995736339464e-01 -1 1 1 1 2.500000018710683558e-01 -1 1 1 2 -2.500000000325188765e-01 -1 1 2 2 2.500000018710683558e-01 -1 2 1 1 6.895272851166299839e-10 -1 2 1 3 -4.263659873690322971e-10 -1 2 2 2 2.000000000263161493e+00 -1 2 3 3 1.999999999836795217e+00 -1 3 1 1 7.500000019361060533e-01 -1 3 2 2 1.000000001542258765e+00 -2 1 1 1 1.250000001467082567e-01 -2 1 1 2 1.249999992664581894e-01 -2 1 2 2 1.250000001467082567e-01 -2 2 1 1 6.666669670820889460e-01 -2 2 1 3 -4.518334811557613299e-07 -2 2 2 2 2.200629338781868638e-10 -2 2 3 3 2.200635109078066153e-10 -2 3 1 1 5.868341556421193509e-10 -2 3 2 2 4.401258478797860908e-10 diff --git a/test/.gitignore b/test/.gitignore index 6929121..dab435d 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -1 +1,3 @@ *.prob* +prob.dat-s +prob.sol diff --git a/test/bug.jl b/test/bug.jl deleted file mode 100644 index 806dead..0000000 --- a/test/bug.jl +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright (c) 2016: CSDP.jl contributors -# -# Use of this source code is governed by an MIT-style license that can be found -# in the LICENSE.md file or at https://opensource.org/licenses/MIT. - -using CSDP -using MathOptInterface -const MOI = MathOptInterface -using SemidefiniteOptInterface -const SOI = SemidefiniteOptInterface -m = CSDP.CSDPSolverInstance() -SOI.initinstance!(m, [-2], 0) -SOI.setobjectivecoefficient!(m, -1.0, 1, 1, 1) -SOI.setobjectivecoefficient!(m, -1.0, 1, 2, 2) -MOI.optimize!(m) -@show m.status diff --git a/test/check_blas.jl b/test/check_blas.jl deleted file mode 100644 index 42765ab..0000000 --- a/test/check_blas.jl +++ /dev/null @@ -1,55 +0,0 @@ -# Copyright (c) 2016: CSDP.jl contributors -# -# Use of this source code is governed by an MIT-style license that can be found -# in the LICENSE.md file or at https://opensource.org/licenses/MIT. - -#!/usr/bin/env julia - -""" -Check integer size of a blas library. -Seems like all BLAS routines return just positive indices. -""" - -const blas_prec = (:ilaprec_64_, BLAS.libblas) -ccall(blas_prec, Clong, (Cstring,), "X") - -const libblas = "/usr/lib/libblas.so.3" -const openblas = "/usr/lib/libopenblas.so.0" - -A = [1.0 0.0; 0.0 -1.0] -lda = max(1, stride(A, 2)) -infot = Ref{LinearAlgebra.BlasInt}() -uplo = 'U' -ccall( - (:dpotrf_64_, LinearAlgebra.BLAS.libblas), - Void, - ( - Ptr{UInt8}, - Ptr{LinearAlgebra.BlasInt}, - Ptr{eltype(A)}, - Ptr{LinearAlgebra.BlasInt}, - Ptr{LinearAlgebra.BlasInt}, - ), - &uplo, - &size(A, 1), - A, - &lda, - info, -) - -ccall( - (:dpotrf_, openblas), - Void, - ( - Ptr{UInt8}, - Ptr{LinearAlgebra.BlasInt}, - Ptr{eltype(A)}, - Ptr{LinearAlgebra.BlasInt}, - Ptr{LinearAlgebra.BlasInt}, - ), - &uplo, - &size(A, 1), - A, - &lda, - infot, -) diff --git a/test/jl_ref.jl b/test/jl_ref.jl deleted file mode 100644 index 5ccddba..0000000 --- a/test/jl_ref.jl +++ /dev/null @@ -1,51 +0,0 @@ -# Copyright (c) 2016: CSDP.jl contributors -# -# Use of this source code is governed by an MIT-style license that can be found -# in the LICENSE.md file or at https://opensource.org/licenses/MIT. - -# Test Julia's Ref mechanism and compare it to Ptr. -# - -if !isdefined(:libn) - const refc = Pkg.dir("CSDP", "test", "ref.c") - const libn = Pkg.dir("CSDP", "deps", "usr", "lib", "ref.$(Libdl.dlext)") - isdir(dirname(libn)) || mkdir(dirname(libn)) -end -run(`gcc -fPIC -shared -o $libn -std=c99 $refc`) - -const OP1 = UInt32(0) -const OP2 = UInt32(1) - -"""Simple type containing an enum and Ptr""" -mutable struct S - c::UInt32 - n::Cint - e::Ptr{Cdouble} -end - -"""Use Ref instead of Ptr""" -mutable struct R - c::UInt32 - n::Cint - e::Ref{Cdouble} -end - -# Say hello, print sizeof(int) -println(ccall((:hello, libn), Cdouble, ())) - -vec = Cdouble[1.0, 2.0] -println("&vec = $(pointer(vec))") - -# Call with S --> should work -s = S(OP1, length(vec), pointer(vec)) -ccall((:sum, libn), Cdouble, (S,), s) - -# Call with R --> does not work -r = R(OP2, length(vec), Ref(vec)) -ccall((:sum, libn), Cdouble, (R,), r) - -# Now call with S, instead of R -function Base.cconvert(::Type{R}, r::R) - return S(r.c, r.n, Base.unsafe_convert(Ptr{Cdouble}, r.e)) -end -ccall((:sum, libn), Cdouble, (S,), r) diff --git a/test/param.csdp b/test/param.csdp deleted file mode 100644 index b32aa34..0000000 --- a/test/param.csdp +++ /dev/null @@ -1,16 +0,0 @@ -axtol=1.0e-8 -atytol=1.0e-8 -objtol=1.0e-8 -pinftol=1.0e8 -dinftol=1.0e8 -maxiter=100 -minstepfrac=0.90 -maxstepfrac=0.97 -minstepp=1.0e-8 -minstepd=1.0e-8 -usexzgap=1 -tweakgap=0 -affine=0 -printlevel=0 -perturbobj=1 -fastmode=0 diff --git a/test/rebuild.jl b/test/rebuild.jl deleted file mode 100644 index ce32ec7..0000000 --- a/test/rebuild.jl +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2016: CSDP.jl contributors -# -# Use of this source code is governed by an MIT-style license that can be found -# in the LICENSE.md file or at https://opensource.org/licenses/MIT. - -# Rebuild shared library -try - using CSDP - isfile(CSDP.csdp) && rm(CSDP.csdp) -catch - println("Lib unloadable") -end - -Pkg.build("CSDP") diff --git a/test/ref.c b/test/ref.c deleted file mode 100644 index dfacf26..0000000 --- a/test/ref.c +++ /dev/null @@ -1,37 +0,0 @@ -#include - -enum category {OP1, OP2}; - -struct S { - enum category c; - int n; - double *e; -}; - - -double hello() { - printf("Hello Worls"); - return 13.42; -} - - -double sum(struct S s) { - printf("sum(struct S)\n"); - switch (s.c) { - case OP1: - printf("OP1\n"); - break; - case OP2: - printf("OP2\n"); - break; - default: - printf("s.category = %d\n", (int) s.c); - } - double r = 0; - printf("sum(s): s.n = %d, s.e = %p\n", s.n, s.e); - for (int i = 0; i < s.n; i++) { - printf("s.e[%d] = %f\n", i, s.e[i]); - r += s.e[i]; - } - return r; -} diff --git a/test/runtests.jl b/test/runtests.jl index 5e11497..99c22d5 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -3,75 +3,70 @@ # Use of this source code is governed by an MIT-style license that can be found # in the LICENSE.md file or at https://opensource.org/licenses/MIT. -using CSDP - using Test -using LinearAlgebra # For Diagonal +using CSDP +import LinearAlgebra -@testset "Interact with BLAS" begin +@testset "Call libcsdp.norm1" begin vec = Cdouble[1.0, 2.0, 0.0, -1.0] - l = length(vec) - inc = 1 - n1 = ccall( - (BLAS.@blasfunc(dasum_), LinearAlgebra.BLAS.libblas), - Cdouble, - (Ref{LinearAlgebra.BlasInt}, Ptr{Cdouble}, Ref{LinearAlgebra.BlasInt}), - l, - vec, - inc, + n1 = @ccall( + CSDP.libcsdp.norm1(length(vec)::Cint, vec::Ptr{Cdouble})::Cdouble ) @test abs(n1 - 4) < 1e-15 end -@testset "Call libcsdp.norm1" begin - vec = Cdouble[1.0, 2.0, 0.0, -1.0] - try - n1 = ccall( - (:norm1, CSDP.libcsdp), - Cdouble, - (Cint, Ptr{Cdouble}), - length(vec), - vec, - ) - @test abs(n1 - 4) < 1e-15 - catch - println("n1 = $n1, vec=$vec, length(vec)=$(length(vec))") - rethrow() - end +function test_example() + C = BlockMatrix( + [2 1; 1 2], + [3 0 1; 0 2 0; 1 0 3], + LinearAlgebra.Diagonal([0, 0]), + ) + b = [1.0, 2.0] + constraints = [ + ConstraintMatrix( + 1, + [3 1; 1 3], + [0 0 0; 0 0 0; 0 0 0], + LinearAlgebra.Diagonal([1, 0]), + ).csdp, + ConstraintMatrix( + 2, + [0 0; 0 0], + [3 0 1; 0 4 0; 1 0 5], + LinearAlgebra.Diagonal([0, 1]), + ).csdp, + ] + CSDP.write_prob("prob.dat-s", C, b, constraints) + X, y, Z = initsoln(C, b, constraints) + pobj, dobj = easy_sdp(C, b, constraints, X, y, Z) + CSDP.write_sol("prob.sol", X, y, Z) + X✓ = [ + 3 3 0 0 0 0 0 + 3 3 0 0 0 0 0 + 0 0 16 0 0 0 0 + 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 + ] + @test isapprox(X, X✓ / 24; atol = 1e-6) + @test isapprox(y, [0.75, 1.0]; atol = 1e-6) + Z✓ = [ + 1 -1 0 0 0 0 0 + -1 1 0 0 0 0 0 + 0 0 0 0 0 0 0 + 0 0 0 8 0 0 0 + 0 0 0 0 8 0 0 + 0 0 0 0 0 3 0 + 0 0 0 0 0 0 4 + ] + @test isapprox(Z, Z✓ / 4; atol = 1e-6) + return end -@static if !Sys.iswindows() # FIXME Segfault on Windows - @testset "Example" begin - cd(joinpath(dirname(dirname(pathof(CSDP))), "examples")) do - include(joinpath(pwd(), "example.jl")) - @test size(X) == (7, 7) - @test length(y) == 2 - @test size(Z) == (7, 7) - X✓ = - [ - 3 3 0 0 0 0 0 - 3 3 0 0 0 0 0 - 0 0 16 0 0 0 0 - 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 - ] / 24 - @test norm(convert(AbstractArray, X) - X✓) < 1e-6 - y✓ = [3, 4] / 4 - @test norm(convert(AbstractArray, y) - y✓) < 1e-6 - Z✓ = - [ - 1 -1 0 0 0 0 0 - -1 1 0 0 0 0 0 - 0 0 0 0 0 0 0 - 0 0 0 8 0 0 0 - 0 0 0 0 8 0 0 - 0 0 0 0 0 3 0 - 0 0 0 0 0 0 4 - ] / 4 - @test norm(convert(AbstractArray, Z) - Z✓) < 1e-6 - end +@testset "Example" begin + if !Sys.iswindows() + test_example() end end diff --git a/test/triu.jl b/test/triu.jl deleted file mode 100644 index e29b256..0000000 --- a/test/triu.jl +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright (c) 2016: CSDP.jl contributors -# -# Use of this source code is governed by an MIT-style license that can be found -# in the LICENSE.md file or at https://opensource.org/licenses/MIT. - -using CSDP - -if !isdefined(:J) || !isa(J, AbstractArray) - J = [ - 1 3 - 5 6 - ] - J = map(Float64, J) -end - -br = CSDP.brec(reshape(J, length(J)), CSDP.MATRIX, 4) -ccall((:printb, CSDP.csdp), Void, (CSDP.blockrec,), br) -bra = [br, br] -block = CSDP.blockmatrix(1, pointer(bra)) -println(block) -# ccall((:printm, CSDP.csdp), Void, (CSDP.blockmatrix,), block) -CSDP.triu(block) diff --git a/test/writesol.jl b/test/writesol.jl deleted file mode 100644 index 5b12721..0000000 --- a/test/writesol.jl +++ /dev/null @@ -1,47 +0,0 @@ -# Copyright (c) 2016: CSDP.jl contributors -# -# Use of this source code is governed by an MIT-style license that can be found -# in the LICENSE.md file or at https://opensource.org/licenses/MIT. - -using CSDP - -X_sol = Blockmatrix( - [ - 2 1 - 1 2 - ], - [ - 3 0 1 - 0 2 0 - 1 0 3 - ], - Diagonal([0, 0]), -) - -Z_sol = Blockmatrix( - [ - 4 1 - 1 2 - ], - [ - 3 0 1 - 0 2 0 - 1 0 3 - ], - Diagonal([0, 0]), -) - -y_origin = [5.5, 6.2] -y = Cvector{Cdouble}(CSDP.fptr(y_origin)) - -k = 2 -n = 7 - -Xs = CSDP.blockmatrix(X_sol) -println("********** Alright **********") - -ys = y.e -Zs = CSDP.blockmatrix(Z_sol) -@printf "********** Alright %s\n" @__FILE__ - -CSDP.write_sol("prob.dat-s", n, k, X_sol, y, Z_sol)