Skip to content

Commit

Permalink
More tests for the Julia interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
amontoison committed Feb 12, 2024
1 parent 939e2d7 commit 0a07832
Show file tree
Hide file tree
Showing 18 changed files with 2,257 additions and 720 deletions.
57 changes: 33 additions & 24 deletions GALAHAD.jl/gen/examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ function examples(package::String, example::String)
dst = "../test/test_" * package * ".jl"
text = replace(text, " " => "")
text = replace(text, "int main(void) {\n\n" => "# test_$package.jl\n# Simple code to test the Julia interface to " * uppercase(package) * "\n\nusing GALAHAD\nusing Test\nusing Printf\nusing Accessors\n\nfunction test_$package()\n")
text = replace(text, "\" i_ipc_ \"" => "i")
text = replace(text, "\" d_ipc_ \"" => "d")
text = replace(text, "ipc_" => "int")
text = replace(text, "rpc_" => "real_wp_")
text = replace(text, "//" => "#")
text = replace(text, ";" => "")
text = replace(text, "&" => "")
Expand All @@ -27,6 +31,7 @@ function examples(package::String, example::String)
text = replace(text, "printf" => "@printf")
text = replace(text, "else if" => "elseif")
text = replace(text, "}else{" => "else")
text = replace(text, "}elseif" => "elseif")
text = replace(text, "} else {" => "else")
text = replace(text, "void *data" => "data = Ref{Ptr{Cvoid}}()")
text = replace(text, "struct $(package)_control_type control" => "control = Ref{$(package)_control_type{Float64}}()")
Expand All @@ -39,38 +44,38 @@ function examples(package::String, example::String)
for var in ("A_val", "A_dense", "b", "c", "c_l", "c_u", "x_l", "x_u", "y_l", "y_u", "z_l", "z_u", "g", "x_0",
"w", "x", "y", "z", "val", "dense", "rhs", "rhst", "sol", "H_val", "H_dense", "C_val",
"C_dense", "H_diag", "C_diag", "H_scid", "C_scid", "Ao_val", "r", "M_val", "M_dense",
"M_diag", "y", "W")
text = replace(text, "rpc_ $var[] = {" => "$var = Float64[")
"M_diag", "y", "W", "Ao_dense")
text = replace(text, "real_wp_ $var[] = {" => "$var = Float64[")
end
for var in ("f", "power", "weight", "shift", "radius", "half_radius", "x_l", "x_u", "sigma", "rho_g", "rho_b")
text = replace(text, "rpc_ $var =" => "$var =")
text = replace(text, "real_wp_ $var =" => "$var =")
end
for var in ("n", "ne", "m", "A_ne", "A_dense_ne", "H_ne", "H_dense_ne", "C_dense_ne",
"C_ne", "dense_ne", "o", "Ao_ne", "Ao_ptr_ne", "A_ptr_ne", "m_equal",
"M_ne", "M_dense_ne", "j_ne", "h_ne", "p_ne")
text = replace(text, "ipc_ $var =" => "$var =")
"M_ne", "M_dense_ne", "j_ne", "h_ne", "p_ne", "Ao_dense_ne")
text = replace(text, "int $var =" => "$var =")
end
for var in ("A_row", "A_col", "A_ptr", "row", "col", "ptr", "c_stat", "x_stat", "H_row", "H_col", "H_ptr",
"C_row", "C_col", "C_ptr", "Ao_col", "Ao_ptr", "Ao_row", "M_row",
"M_col", "M_ptr", "J_row", "J_col", "J_ptr", "P_row", "P_ptr")
text = replace(text, "ipc_ $var[] = {" => "$var = Cint[")
text = replace(text, "int $var[] = {" => "$var = Cint[")
end
for val in ("1", "3", "5", "6", "7", "n", "n+m")
text = replace(text, "for( ipc_ d=1 d <= $val d++){" => "for d = 1:$val")
text = replace(text, "for(ipc_ d=1 d <= $val d++){" => "for d = 1:$val")
text = replace(text, "for( int d=1 d <= $val d++){" => "for d = 1:$val")
text = replace(text, "for(int d=1 d <= $val d++){" => "for d = 1:$val")
end
for index in ("unit_m", "new_radius", "a_is", "m_is")
text = replace(text, "for( ipc_ $index=0 $index <= 1 $index++){" => "for $index = 0:1")
text = replace(text, "for(ipc_ $index=0 $index <= 1 $index++){" => "for $index = 0:1")
text = replace(text, "for( int $index=0 $index <= 1 $index++){" => "for $index = 0:1")
text = replace(text, "for(int $index=0 $index <= 1 $index++){" => "for $index = 0:1")
end
for val in ("c", "g", "u", "v", "x", "r", "vector", "h_vector", "error")
text = replace(text, "rpc_ $val[n]" => "$val = zeros(Float64, n)")
text = replace(text, "rpc_ $val[m]" => "$val = zeros(Float64, m)")
text = replace(text, "rpc_ $val[o]" => "$val = zeros(Float64, o)")
for val in ("c", "g", "u", "v", "x", "w", "z", "x_l", "x_u", "r", "vector", "h_vector", "error")
text = replace(text, "real_wp_ $val[n]" => "$val = zeros(Float64, n)")
text = replace(text, "real_wp_ $val[m]" => "$val = zeros(Float64, m)")
text = replace(text, "real_wp_ $val[o]" => "$val = zeros(Float64, o)")
end
for val in ("x_stat", "c_stat", "index_nz_u", "index_nz_v", "depen")
text = replace(text, "ipc_ $val[n]" => "$val = zeros(Cint, n)")
text = replace(text, "ipc_ $val[m]" => "$val = zeros(Cint, m)")
text = replace(text, "int $val[n]" => "$val = zeros(Cint, n)")
text = replace(text, "int $val[m]" => "$val = zeros(Cint, m)")
end

text = replace(text, "if(" => "if ")
Expand All @@ -81,9 +86,9 @@ function examples(package::String, example::String)
text = replace(text, "}\n" => "]\n")
text = replace(text, "NULL" => "Cint[]")
text = replace(text, "char st" => "st = ' '")
text = replace(text, "ipc_ status" => "status = Ref{Cint}()")
text = replace(text, "ipc_ n_depen" => "n_depen = Ref{Cint}()")
text = replace(text, "rpc_ radius" => "radius = Ref{Float64}()")
text = replace(text, "int status" => "status = Ref{Cint}()")
text = replace(text, "int n_depen" => "n_depen = Ref{Cint}()")
text = replace(text, "real_wp_ radius" => "radius = Ref{Float64}()")
text = replace(text, " ]" => "]")
text = replace(text, "== 0)" => "== 0")
text = replace(text, "case 1: # sparse co-ordinate storage" => "# sparse co-ordinate storage\nif d == 1")
Expand All @@ -94,14 +99,18 @@ function examples(package::String, example::String)
text = replace(text, "case 6: # identity" => "# identity\nif d == 6")
text = replace(text, "case 7: # zero" => "# zero\nif d == 7")
text = replace(text, "break\n" => "end\n")
text = replace(text, "ipc_ maxabsarray(rpc_ a[], ipc_ n, rpc_ *maxabs)" => "maxabsarray(a) = maximum(abs.(a))")
text = replace(text, "int maxabsarray(real_wp_ a[], int n, real_wp_ *maxabs)" => "maxabsarray(a) = maximum(abs.(a))")
for i = 0:5
text = replace(text, "( status == $i ) {" => "status == $i")
end
text = replace(text, "( status < 0 ) {" => "status < 0")
text = replace(text, "while(true)" => "while true")
text = replace(text, "for( ipc_ i = 0 i < n i++)" => "for i = 1:n")
text = replace(text, "for( ipc_ i = 0 i < m i++)" => "for i = 1:m")
text = replace(text, "for( int i = 0 i < n i++)" => "for i = 1:n")
text = replace(text, "for( int i = 0 i < m i++)" => "for i = 1:m")
text = replace(text, "for( int i = 1 i < n i++)" => "for i = 2:n")
text = replace(text, "for( int i = 1 i < m i++)" => "for i = 2:m")
text = replace(text, "for( int i = 2 i < n i++)" => "for i = 3:n")
text = replace(text, "for( int i = 2 i < m i++)" => "for i = 3:m")
text = replace(text, "constrastatus = Ref{Cint}()" => "constraint status")
text = replace(text, "}#" => "] #")
text = replace(text, "#for" => "# for")
Expand All @@ -113,8 +122,8 @@ function examples(package::String, example::String)
text = replace(text, "for(i=0 i<n i++)" => "for i = 1:n\n")
text = replace(text, "}\n" => "end\n")
for var in ("x", "u", "v", "hval", "g")
text = replace(text, "const rpc_ $var[]" => "var::Vector{Float64}")
text = replace(text, "rpc_ $var[]" => "$var::Vector{Float64}")
text = replace(text, "const real_wp_ $var[]" => "var::Vector{Float64}")
text = replace(text, "real_wp_ $var[]" => "$var::Vector{Float64}")
end
text = text * "end\n\n@testset \"" * uppercase(package) * "\" begin\n @test test_$package() == 0\nend\n"
write(dst, text)
Expand Down
Empty file added GALAHAD.jl/test/UGO.SPC
Empty file.
12 changes: 6 additions & 6 deletions GALAHAD.jl/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ include("test_structures.jl")

# include("test_arc.jl")
# include("test_bgo.jl")
# include("test_blls.jl")
## include("test_blls.jl")
include("test_bllsb.jl")
# include("test_bqp.jl")
include("test_bqpb.jl")
Expand All @@ -15,11 +15,11 @@ include("test_clls.jl")
include("test_convert.jl")
include("test_cqp.jl")
include("test_cro.jl")
# include("test_dgo.jl")
## include("test_dgo.jl")
include("test_dps.jl")
# include("test_dqp.jl")
include("test_dqp.jl")
include("test_eqp.jl")
# include("test_fdc.jl")
include("test_fdc.jl")
include("test_fit.jl")
include("test_glrt.jl")
include("test_gls.jl")
Expand All @@ -28,7 +28,7 @@ include("test_hash.jl")
include("test_ir.jl")
include("test_l2rt.jl")
include("test_lhs.jl")
# include("test_llsr.jl")
## include("test_llsr.jl")
## include("test_llst.jl")
include("test_lms.jl")
include("test_lpa.jl")
Expand All @@ -43,7 +43,7 @@ include("test_qpa.jl")
include("test_qpb.jl")
include("test_roots.jl")
# include("test_rpd.jl")
# include("test_rqs.jl")
## include("test_rqs.jl")
include("test_sbls.jl")
## include("test_scu.jl")
include("test_sec.jl")
Expand Down
Loading

0 comments on commit 0a07832

Please sign in to comment.