From 5af726de0c9c1573dec046fc0cf1e909bd8d4bbc Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Sat, 20 Jan 2024 23:33:32 -0500 Subject: [PATCH 01/33] [GALAHAD.jl] Regenerate the Julia wrappers --- GALAHAD.jl/gen/rewriter.jl | 32 +++---- GALAHAD.jl/gen/wrapper.jl | 5 +- GALAHAD.jl/src/wrappers/arc.jl | 105 +++++++------------- GALAHAD.jl/src/wrappers/bgo.jl | 98 +++++++------------ GALAHAD.jl/src/wrappers/blls.jl | 115 +++++++++------------- GALAHAD.jl/src/wrappers/bllsb.jl | 69 +++++-------- GALAHAD.jl/src/wrappers/bqp.jl | 85 +++++++--------- GALAHAD.jl/src/wrappers/bqpb.jl | 79 +++++---------- GALAHAD.jl/src/wrappers/bsc.jl | 24 ++--- GALAHAD.jl/src/wrappers/ccqp.jl | 108 ++++++++------------- GALAHAD.jl/src/wrappers/clls.jl | 69 +++++-------- GALAHAD.jl/src/wrappers/convert.jl | 32 +++---- GALAHAD.jl/src/wrappers/cqp.jl | 97 +++++++------------ GALAHAD.jl/src/wrappers/cro.jl | 100 ++++++++----------- GALAHAD.jl/src/wrappers/dgo.jl | 98 +++++++------------ GALAHAD.jl/src/wrappers/dps.jl | 70 +++++--------- GALAHAD.jl/src/wrappers/dqp.jl | 96 +++++++------------ GALAHAD.jl/src/wrappers/eqp.jl | 81 ++++++---------- GALAHAD.jl/src/wrappers/fdc.jl | 51 ++++------ GALAHAD.jl/src/wrappers/fit.jl | 24 ++--- GALAHAD.jl/src/wrappers/glrt.jl | 32 +++---- GALAHAD.jl/src/wrappers/gls.jl | 54 +++++------ GALAHAD.jl/src/wrappers/gltr.jl | 35 +++---- GALAHAD.jl/src/wrappers/hash.jl | 31 +++--- GALAHAD.jl/src/wrappers/hsl.jl | 100 +++++-------------- GALAHAD.jl/src/wrappers/ir.jl | 24 ++--- GALAHAD.jl/src/wrappers/l2rt.jl | 32 +++---- GALAHAD.jl/src/wrappers/lhs.jl | 40 ++++---- GALAHAD.jl/src/wrappers/llsr.jl | 68 +++++-------- GALAHAD.jl/src/wrappers/llst.jl | 72 +++++--------- GALAHAD.jl/src/wrappers/lms.jl | 32 +++---- GALAHAD.jl/src/wrappers/lpa.jl | 75 ++++++--------- GALAHAD.jl/src/wrappers/lpb.jl | 88 ++++++----------- GALAHAD.jl/src/wrappers/lsqp.jl | 72 ++++++-------- GALAHAD.jl/src/wrappers/lsrt.jl | 32 +++---- GALAHAD.jl/src/wrappers/lstr.jl | 32 +++---- GALAHAD.jl/src/wrappers/nls.jl | 144 +++++++++------------------- GALAHAD.jl/src/wrappers/presolve.jl | 111 ++++++++++----------- GALAHAD.jl/src/wrappers/psls.jl | 57 ++++------- GALAHAD.jl/src/wrappers/qpa.jl | 99 ++++++++----------- GALAHAD.jl/src/wrappers/qpb.jl | 84 ++++++---------- GALAHAD.jl/src/wrappers/roots.jl | 24 ++--- GALAHAD.jl/src/wrappers/rpd.jl | 41 ++++---- GALAHAD.jl/src/wrappers/rqs.jl | 62 ++++-------- GALAHAD.jl/src/wrappers/sbls.jl | 82 ++++++---------- GALAHAD.jl/src/wrappers/scu.jl | 20 ++-- GALAHAD.jl/src/wrappers/sec.jl | 24 ++--- GALAHAD.jl/src/wrappers/sha.jl | 36 ++++--- GALAHAD.jl/src/wrappers/sils.jl | 48 ++++------ GALAHAD.jl/src/wrappers/slls.jl | 87 +++++++---------- GALAHAD.jl/src/wrappers/sls.jl | 60 ++++-------- GALAHAD.jl/src/wrappers/ssids.jl | 8 +- GALAHAD.jl/src/wrappers/trb.jl | 107 ++++++++------------- GALAHAD.jl/src/wrappers/trs.jl | 62 ++++-------- GALAHAD.jl/src/wrappers/tru.jl | 107 +++++++-------------- GALAHAD.jl/src/wrappers/ugo.jl | 44 ++++----- GALAHAD.jl/src/wrappers/uls.jl | 50 ++++------ GALAHAD.jl/src/wrappers/wcp.jl | 64 +++++-------- 58 files changed, 1370 insertions(+), 2308 deletions(-) diff --git a/GALAHAD.jl/gen/rewriter.jl b/GALAHAD.jl/gen/rewriter.jl index d93dc7b1f9..da97ed27ef 100644 --- a/GALAHAD.jl/gen/rewriter.jl +++ b/GALAHAD.jl/gen/rewriter.jl @@ -11,8 +11,9 @@ types = ("control", "time", "inform", "history", "subproblem_control", "subprobl nonparametric_structures = ("slls_time_type", "sha_control_type", "sha_inform_type", "sec_inform_type", "scu_control_type", "scu_inform_type", "rpd_control_type", "rpd_inform_type", "roots_inform_type", "presolve_inform_type", - "lhs_control_type", "lhs_inform_type", "hash_control_type", "hash_inform_type", - "gls_sinfo_type", "bqp_time_type", "bsc_control_type", "convert_control_type", + "lhs_control_type", "lhs_inform_type", "lms_control_type", + "hash_control_type", "hash_inform_type", "gls_sinfo_type", + "bqp_time_type", "bsc_control_type", "convert_control_type", "fit_control_type", "fit_inform_type", "spral_ssids_inform", "ma48_sinfo", "mc64_control", "mc64_info", "mc68_control", "mc68_info") @@ -20,9 +21,7 @@ function rewrite!(path::String, name::String, optimized::Bool) structures = "# Structures for $name\n" text = read(path, String) if optimized - text = replace(text, "struct " => "mutable struct ") text = replace(text, "real_sp_" => "Float32") - text = replace(text, "Ptr{$name" => "Ref{$name") text = replace(text, "\n " => "\n ") # Special case for gls @@ -82,22 +81,16 @@ function rewrite!(path::String, name::String, optimized::Bool) text = text * "\n" * "export " * function_name * "_s\n" * routine_single text = text * "\n" * "export " * function_name * "\n" * routine_double end - elseif contains(code, "mutable struct") + elseif contains(code, "struct ") structure = code * "end\n" - structure_name = split(split(code, "mutable struct ")[2], "\n")[1] + structure_name = split(split(code, "struct ")[2], "\n")[1] structure = replace(structure, "real_wp_" => "T") if structure_name ∉ nonparametric_structures structure = replace(structure, structure_name => structure_name * "{T}") - structures = structures * "$(structure_name){Float32}()\n" - structures = structures * "$(structure_name){Float64}()\n" - if count("_type", structure) > 1 - structure = replace(structure, "end\n" => "\n function " * structure_name * "{T}() where T\n type = new()\n # TODO!\n return type\n end\nend\n") - else - structure = replace(structure, "end\n" => "\n " * structure_name * "{T}() where T = new()\nend\n") - end + structures = structures * "Ref{$(structure_name){Float32}}()\n" + structures = structures * "Ref{$(structure_name){Float64}}()\n" else - structure = replace(structure, "end\n" => "\n " * structure_name * "() = new()\nend\n") - structures = structures * "$(structure_name)()\n" + structures = structures * "Ref{$(structure_name)}()\n" end if index == 1 text = text * "export " * structure_name * "\n\n" * structure @@ -108,11 +101,12 @@ function rewrite!(path::String, name::String, optimized::Bool) text = text * code end end + + isfile("../test/test_structures.jl") || write("../test/test_structures.jl", "") + test = read("../test/test_structures.jl", String) + structures = structures * "\n" + write("../test/test_structures.jl", test * structures) end - isfile("../test/test_structures.jl") || write("../test/test_structures.jl", "") - test = read("../test/test_structures.jl", String) - structures = structures * "\n" - write("../test/test_structures.jl", test * structures) write(path, text) end diff --git a/GALAHAD.jl/gen/wrapper.jl b/GALAHAD.jl/gen/wrapper.jl index f52fbb081c..0a44644cf0 100644 --- a/GALAHAD.jl/gen/wrapper.jl +++ b/GALAHAD.jl/gen/wrapper.jl @@ -40,8 +40,8 @@ function wrapper(name::String, headers::Vector{String}, optimized::Bool; targets path = options["general"]["output_file_path"] - format_file(path, YASStyle()) rewrite!(path, name, optimized) + format_file(path, YASStyle(), indent=2) # Generate a symbolic link for the Julia wrappers if (name ≠ "hsl") && (name ≠ "ssids") @@ -61,6 +61,9 @@ function main(name::String="all"; optimized::Bool=true) haskey(ENV, "JULIA_GALAHAD_LIBRARY_PATH") || error("The environment variable JULIA_GALAHAD_LIBRARY_PATH is not defined.") galahad = joinpath(ENV["JULIA_GALAHAD_LIBRARY_PATH"], "..", "include") + # Regenerate test_structures.jl + (name == "all") && optimized && isfile("../test/test_structures.jl") && rm("../test/test_structures.jl") + (name == "all" || name == "arc") && wrapper("arc", ["$galahad/galahad_arc.h"], optimized) (name == "all" || name == "bgo") && wrapper("bgo", ["$galahad/galahad_bgo.h"], optimized) (name == "all" || name == "blls") && wrapper("blls", ["$galahad/galahad_blls.h"], optimized) diff --git a/GALAHAD.jl/src/wrappers/arc.jl b/GALAHAD.jl/src/wrappers/arc.jl index a7c52fd970..17e54160ea 100644 --- a/GALAHAD.jl/src/wrappers/arc.jl +++ b/GALAHAD.jl/src/wrappers/arc.jl @@ -1,6 +1,6 @@ export arc_control_type -mutable struct arc_control_type{T} +struct arc_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -50,26 +50,14 @@ mutable struct arc_control_type{T} glrt_control::glrt_control_type{T} dps_control::dps_control_type{T} psls_control::psls_control_type{T} - lms_control::lms_control_type{T} - lms_control_prec::lms_control_type{T} + lms_control::lms_control_type + lms_control_prec::lms_control_type sha_control::sha_control_type - - function arc_control_type{T}() where T - type = new() - type.rqs_control = rqs_control_type{T}() - type.glrt_control = glrt_control_type{T}() - type.dps_control = dps_control_type{T}() - type.psls_control = psls_control_type{T}() - type.lms_control = lms_control_type{T}() - type.lms_control_prec = lms_control_type{T}() - type.sha_control = sha_control_type() - return type - end end export arc_time_type -mutable struct arc_time_type{T} +struct arc_time_type{T} total::Float32 preprocess::Float32 analyse::Float32 @@ -80,13 +68,11 @@ mutable struct arc_time_type{T} clock_analyse::T clock_factorize::T clock_solve::T - - arc_time_type{T}() where T = new() end export arc_inform_type -mutable struct arc_inform_type{T} +struct arc_inform_type{T} status::Cint alloc_status::Cint bad_alloc::NTuple{81,Cchar} @@ -112,26 +98,13 @@ mutable struct arc_inform_type{T} lms_inform::lms_inform_type{T} lms_inform_prec::lms_inform_type{T} sha_inform::sha_inform_type - - function arc_inform_type{T}() where T - type = new() - type.time = arc_time_type{T}() - type.rqs_inform = rqs_inform_type{T}() - type.glrt_inform = glrt_inform_type{T}() - type.dps_inform = dps_inform_type{T}() - type.psls_inform = psls_inform_type{T}() - type.lms_inform = lms_inform_type{T}() - type.lms_inform_prec = lms_inform_type{T}() - type.sha_inform = sha_inform_type() - return type - end end export arc_initialize_s function arc_initialize_s(data, control, status) @ccall libgalahad_single.arc_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{arc_control_type{Float32}}, + control::Ptr{arc_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -139,28 +112,28 @@ export arc_initialize function arc_initialize(data, control, status) @ccall libgalahad_double.arc_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{arc_control_type{Float64}}, + control::Ptr{arc_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export arc_read_specfile_s function arc_read_specfile_s(control, specfile) - @ccall libgalahad_single.arc_read_specfile_s(control::Ref{arc_control_type{Float32}}, + @ccall libgalahad_single.arc_read_specfile_s(control::Ptr{arc_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export arc_read_specfile function arc_read_specfile(control, specfile) - @ccall libgalahad_double.arc_read_specfile(control::Ref{arc_control_type{Float64}}, + @ccall libgalahad_double.arc_read_specfile(control::Ptr{arc_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export arc_import_s function arc_import_s(control, data, status, n, H_type, ne, H_row, H_col, H_ptr) - @ccall libgalahad_single.arc_import_s(control::Ref{arc_control_type{Float32}}, + @ccall libgalahad_single.arc_import_s(control::Ptr{arc_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, H_type::Ptr{Cchar}, ne::Cint, H_row::Ptr{Cint}, H_col::Ptr{Cint}, H_ptr::Ptr{Cint})::Cvoid @@ -169,7 +142,7 @@ end export arc_import function arc_import(control, data, status, n, H_type, ne, H_row, H_col, H_ptr) - @ccall libgalahad_double.arc_import(control::Ref{arc_control_type{Float64}}, + @ccall libgalahad_double.arc_import(control::Ptr{arc_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, H_type::Ptr{Cchar}, ne::Cint, H_row::Ptr{Cint}, H_col::Ptr{Cint}, H_ptr::Ptr{Cint})::Cvoid @@ -178,7 +151,7 @@ end export arc_reset_control_s function arc_reset_control_s(control, data, status) - @ccall libgalahad_single.arc_reset_control_s(control::Ref{arc_control_type{Float32}}, + @ccall libgalahad_single.arc_reset_control_s(control::Ptr{arc_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -186,7 +159,7 @@ end export arc_reset_control function arc_reset_control(control, data, status) - @ccall libgalahad_double.arc_reset_control(control::Ref{arc_control_type{Float64}}, + @ccall libgalahad_double.arc_reset_control(control::Ptr{arc_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -194,31 +167,30 @@ end export arc_solve_with_mat_s function arc_solve_with_mat_s(data, userdata, status, n, x, g, ne, eval_f, eval_g, eval_h, - eval_prec) + eval_prec) @ccall libgalahad_single.arc_solve_with_mat_s(data::Ptr{Ptr{Cvoid}}, userdata::Ptr{Cvoid}, - status::Ptr{Cint}, n::Cint, - x::Ptr{Float32}, g::Ptr{Float32}, - ne::Cint, eval_f::Ptr{Cvoid}, - eval_g::Ptr{Cvoid}, eval_h::Ptr{Cvoid}, + status::Ptr{Cint}, n::Cint, x::Ptr{Float32}, + g::Ptr{Float32}, ne::Cint, + eval_f::Ptr{Cvoid}, eval_g::Ptr{Cvoid}, + eval_h::Ptr{Cvoid}, eval_prec::Ptr{Cvoid})::Cvoid end export arc_solve_with_mat function arc_solve_with_mat(data, userdata, status, n, x, g, ne, eval_f, eval_g, eval_h, - eval_prec) + eval_prec) @ccall libgalahad_double.arc_solve_with_mat(data::Ptr{Ptr{Cvoid}}, userdata::Ptr{Cvoid}, - status::Ptr{Cint}, n::Cint, - x::Ptr{Float64}, g::Ptr{Float64}, - ne::Cint, eval_f::Ptr{Cvoid}, + status::Ptr{Cint}, n::Cint, x::Ptr{Float64}, + g::Ptr{Float64}, ne::Cint, eval_f::Ptr{Cvoid}, eval_g::Ptr{Cvoid}, eval_h::Ptr{Cvoid}, eval_prec::Ptr{Cvoid})::Cvoid end export arc_solve_without_mat_s -function arc_solve_without_mat_s(data, userdata, status, n, x, g, eval_f, eval_g, eval_hprod, - eval_prec) +function arc_solve_without_mat_s(data, userdata, status, n, x, g, eval_f, eval_g, + eval_hprod, eval_prec) @ccall libgalahad_single.arc_solve_without_mat_s(data::Ptr{Ptr{Cvoid}}, userdata::Ptr{Cvoid}, status::Ptr{Cint}, n::Cint, x::Ptr{Float32}, @@ -231,19 +203,19 @@ end export arc_solve_without_mat function arc_solve_without_mat(data, userdata, status, n, x, g, eval_f, eval_g, eval_hprod, - eval_prec) + eval_prec) @ccall libgalahad_double.arc_solve_without_mat(data::Ptr{Ptr{Cvoid}}, userdata::Ptr{Cvoid}, status::Ptr{Cint}, - n::Cint, x::Ptr{Float64}, - g::Ptr{Float64}, eval_f::Ptr{Cvoid}, - eval_g::Ptr{Cvoid}, + n::Cint, x::Ptr{Float64}, g::Ptr{Float64}, + eval_f::Ptr{Cvoid}, eval_g::Ptr{Cvoid}, eval_hprod::Ptr{Cvoid}, eval_prec::Ptr{Cvoid})::Cvoid end export arc_solve_reverse_with_mat_s -function arc_solve_reverse_with_mat_s(data, status, eval_status, n, x, f, g, ne, H_val, u, v) +function arc_solve_reverse_with_mat_s(data, status, eval_status, n, x, f, g, ne, H_val, u, + v) @ccall libgalahad_single.arc_solve_reverse_with_mat_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, eval_status::Ptr{Cint}, n::Cint, @@ -262,8 +234,7 @@ function arc_solve_reverse_with_mat(data, status, eval_status, n, x, f, g, ne, H eval_status::Ptr{Cint}, n::Cint, x::Ptr{Float64}, f::Float64, g::Ptr{Float64}, ne::Cint, - H_val::Ptr{Float64}, - u::Ptr{Float64}, + H_val::Ptr{Float64}, u::Ptr{Float64}, v::Ptr{Float64})::Cvoid end @@ -274,8 +245,7 @@ function arc_solve_reverse_without_mat_s(data, status, eval_status, n, x, f, g, status::Ptr{Cint}, eval_status::Ptr{Cint}, n::Cint, x::Ptr{Float32}, f::Float32, - g::Ptr{Float32}, - u::Ptr{Float32}, + g::Ptr{Float32}, u::Ptr{Float32}, v::Ptr{Float32})::Cvoid end @@ -286,8 +256,7 @@ function arc_solve_reverse_without_mat(data, status, eval_status, n, x, f, g, u, status::Ptr{Cint}, eval_status::Ptr{Cint}, n::Cint, x::Ptr{Float64}, f::Float64, - g::Ptr{Float64}, - u::Ptr{Float64}, + g::Ptr{Float64}, u::Ptr{Float64}, v::Ptr{Float64})::Cvoid end @@ -295,7 +264,7 @@ export arc_information_s function arc_information_s(data, inform, status) @ccall libgalahad_single.arc_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{arc_inform_type{Float32}}, + inform::Ptr{arc_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -303,7 +272,7 @@ export arc_information function arc_information(data, inform, status) @ccall libgalahad_double.arc_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{arc_inform_type{Float64}}, + inform::Ptr{arc_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -311,14 +280,14 @@ export arc_terminate_s function arc_terminate_s(data, control, inform) @ccall libgalahad_single.arc_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{arc_control_type{Float32}}, - inform::Ref{arc_inform_type{Float32}})::Cvoid + control::Ptr{arc_control_type{Float32}}, + inform::Ptr{arc_inform_type{Float32}})::Cvoid end export arc_terminate function arc_terminate(data, control, inform) @ccall libgalahad_double.arc_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{arc_control_type{Float64}}, - inform::Ref{arc_inform_type{Float64}})::Cvoid + control::Ptr{arc_control_type{Float64}}, + inform::Ptr{arc_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/bgo.jl b/GALAHAD.jl/src/wrappers/bgo.jl index e25143f246..261e6bb2b0 100644 --- a/GALAHAD.jl/src/wrappers/bgo.jl +++ b/GALAHAD.jl/src/wrappers/bgo.jl @@ -1,6 +1,6 @@ export bgo_control_type -mutable struct bgo_control_type{T} +struct bgo_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -23,32 +23,22 @@ mutable struct bgo_control_type{T} ugo_control::ugo_control_type{T} lhs_control::lhs_control_type trb_control::trb_control_type{T} - - function bgo_control_type{T}() where T - type = new() - type.ugo_control = ugo_control_type{T}() - type.lhs_control = lhs_control_type() - type.trb_control = trb_control_type{T}() - return type - end end export bgo_time_type -mutable struct bgo_time_type{T} +struct bgo_time_type{T} total::Float32 univariate_global::Float32 multivariate_local::Float32 clock_total::T clock_univariate_global::T clock_multivariate_local::T - - bgo_time_type{T}() where T = new() end export bgo_inform_type -mutable struct bgo_inform_type{T} +struct bgo_inform_type{T} status::Cint alloc_status::Cint bad_alloc::NTuple{81,Cchar} @@ -61,22 +51,13 @@ mutable struct bgo_inform_type{T} ugo_inform::ugo_inform_type{T} lhs_inform::lhs_inform_type trb_inform::trb_inform_type{T} - - function bgo_inform_type{T}() where T - type = new() - type.time = bgo_time_type{T}() - type.ugo_inform = ugo_inform_type{T}() - type.lhs_inform = lhs_inform_type() - type.trb_inform = trb_inform_type{T}() - return type - end end export bgo_initialize_s function bgo_initialize_s(data, control, status) @ccall libgalahad_single.bgo_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{bgo_control_type{Float32}}, + control::Ptr{bgo_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -84,28 +65,28 @@ export bgo_initialize function bgo_initialize(data, control, status) @ccall libgalahad_double.bgo_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{bgo_control_type{Float64}}, + control::Ptr{bgo_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export bgo_read_specfile_s function bgo_read_specfile_s(control, specfile) - @ccall libgalahad_single.bgo_read_specfile_s(control::Ref{bgo_control_type{Float32}}, + @ccall libgalahad_single.bgo_read_specfile_s(control::Ptr{bgo_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export bgo_read_specfile function bgo_read_specfile(control, specfile) - @ccall libgalahad_double.bgo_read_specfile(control::Ref{bgo_control_type{Float64}}, + @ccall libgalahad_double.bgo_read_specfile(control::Ptr{bgo_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export bgo_import_s function bgo_import_s(control, data, status, n, x_l, x_u, H_type, ne, H_row, H_col, H_ptr) - @ccall libgalahad_single.bgo_import_s(control::Ref{bgo_control_type{Float32}}, + @ccall libgalahad_single.bgo_import_s(control::Ptr{bgo_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, x_l::Ptr{Float32}, x_u::Ptr{Float32}, H_type::Ptr{Cchar}, ne::Cint, H_row::Ptr{Cint}, @@ -115,7 +96,7 @@ end export bgo_import function bgo_import(control, data, status, n, x_l, x_u, H_type, ne, H_row, H_col, H_ptr) - @ccall libgalahad_double.bgo_import(control::Ref{bgo_control_type{Float64}}, + @ccall libgalahad_double.bgo_import(control::Ptr{bgo_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, x_l::Ptr{Float64}, x_u::Ptr{Float64}, H_type::Ptr{Cchar}, ne::Cint, H_row::Ptr{Cint}, @@ -125,7 +106,7 @@ end export bgo_reset_control_s function bgo_reset_control_s(control, data, status) - @ccall libgalahad_single.bgo_reset_control_s(control::Ref{bgo_control_type{Float32}}, + @ccall libgalahad_single.bgo_reset_control_s(control::Ptr{bgo_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -133,7 +114,7 @@ end export bgo_reset_control function bgo_reset_control(control, data, status) - @ccall libgalahad_double.bgo_reset_control(control::Ref{bgo_control_type{Float64}}, + @ccall libgalahad_double.bgo_reset_control(control::Ptr{bgo_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -141,24 +122,22 @@ end export bgo_solve_with_mat_s function bgo_solve_with_mat_s(data, userdata, status, n, x, g, ne, eval_f, eval_g, eval_h, - eval_hprod, eval_prec) + eval_hprod, eval_prec) @ccall libgalahad_single.bgo_solve_with_mat_s(data::Ptr{Ptr{Cvoid}}, userdata::Ptr{Cvoid}, - status::Ptr{Cint}, n::Cint, - x::Ptr{Float32}, g::Ptr{Float32}, - ne::Cint, eval_f::Ptr{Cvoid}, - eval_g::Ptr{Cvoid}, eval_h::Ptr{Cvoid}, - eval_hprod::Ptr{Cvoid}, + status::Ptr{Cint}, n::Cint, x::Ptr{Float32}, + g::Ptr{Float32}, ne::Cint, + eval_f::Ptr{Cvoid}, eval_g::Ptr{Cvoid}, + eval_h::Ptr{Cvoid}, eval_hprod::Ptr{Cvoid}, eval_prec::Ptr{Cvoid})::Cvoid end export bgo_solve_with_mat function bgo_solve_with_mat(data, userdata, status, n, x, g, ne, eval_f, eval_g, eval_h, - eval_hprod, eval_prec) + eval_hprod, eval_prec) @ccall libgalahad_double.bgo_solve_with_mat(data::Ptr{Ptr{Cvoid}}, userdata::Ptr{Cvoid}, - status::Ptr{Cint}, n::Cint, - x::Ptr{Float64}, g::Ptr{Float64}, - ne::Cint, eval_f::Ptr{Cvoid}, + status::Ptr{Cint}, n::Cint, x::Ptr{Float64}, + g::Ptr{Float64}, ne::Cint, eval_f::Ptr{Cvoid}, eval_g::Ptr{Cvoid}, eval_h::Ptr{Cvoid}, eval_hprod::Ptr{Cvoid}, eval_prec::Ptr{Cvoid})::Cvoid @@ -166,8 +145,8 @@ end export bgo_solve_without_mat_s -function bgo_solve_without_mat_s(data, userdata, status, n, x, g, eval_f, eval_g, eval_hprod, - eval_shprod, eval_prec) +function bgo_solve_without_mat_s(data, userdata, status, n, x, g, eval_f, eval_g, + eval_hprod, eval_shprod, eval_prec) @ccall libgalahad_single.bgo_solve_without_mat_s(data::Ptr{Ptr{Cvoid}}, userdata::Ptr{Cvoid}, status::Ptr{Cint}, n::Cint, x::Ptr{Float32}, @@ -181,12 +160,11 @@ end export bgo_solve_without_mat function bgo_solve_without_mat(data, userdata, status, n, x, g, eval_f, eval_g, eval_hprod, - eval_shprod, eval_prec) + eval_shprod, eval_prec) @ccall libgalahad_double.bgo_solve_without_mat(data::Ptr{Ptr{Cvoid}}, userdata::Ptr{Cvoid}, status::Ptr{Cint}, - n::Cint, x::Ptr{Float64}, - g::Ptr{Float64}, eval_f::Ptr{Cvoid}, - eval_g::Ptr{Cvoid}, + n::Cint, x::Ptr{Float64}, g::Ptr{Float64}, + eval_f::Ptr{Cvoid}, eval_g::Ptr{Cvoid}, eval_hprod::Ptr{Cvoid}, eval_shprod::Ptr{Cvoid}, eval_prec::Ptr{Cvoid})::Cvoid @@ -194,7 +172,8 @@ end export bgo_solve_reverse_with_mat_s -function bgo_solve_reverse_with_mat_s(data, status, eval_status, n, x, f, g, ne, H_val, u, v) +function bgo_solve_reverse_with_mat_s(data, status, eval_status, n, x, f, g, ne, H_val, u, + v) @ccall libgalahad_single.bgo_solve_reverse_with_mat_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, eval_status::Ptr{Cint}, n::Cint, @@ -213,21 +192,19 @@ function bgo_solve_reverse_with_mat(data, status, eval_status, n, x, f, g, ne, H eval_status::Ptr{Cint}, n::Cint, x::Ptr{Float64}, f::Float64, g::Ptr{Float64}, ne::Cint, - H_val::Ptr{Float64}, - u::Ptr{Float64}, + H_val::Ptr{Float64}, u::Ptr{Float64}, v::Ptr{Float64})::Cvoid end export bgo_solve_reverse_without_mat_s function bgo_solve_reverse_without_mat_s(data, status, eval_status, n, x, f, g, u, v, - index_nz_v, nnz_v, index_nz_u, nnz_u) + index_nz_v, nnz_v, index_nz_u, nnz_u) @ccall libgalahad_single.bgo_solve_reverse_without_mat_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, eval_status::Ptr{Cint}, n::Cint, x::Ptr{Float32}, f::Float32, - g::Ptr{Float32}, - u::Ptr{Float32}, + g::Ptr{Float32}, u::Ptr{Float32}, v::Ptr{Float32}, index_nz_v::Ptr{Cint}, nnz_v::Ptr{Cint}, @@ -238,13 +215,12 @@ end export bgo_solve_reverse_without_mat function bgo_solve_reverse_without_mat(data, status, eval_status, n, x, f, g, u, v, - index_nz_v, nnz_v, index_nz_u, nnz_u) + index_nz_v, nnz_v, index_nz_u, nnz_u) @ccall libgalahad_double.bgo_solve_reverse_without_mat(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, eval_status::Ptr{Cint}, n::Cint, x::Ptr{Float64}, f::Float64, - g::Ptr{Float64}, - u::Ptr{Float64}, + g::Ptr{Float64}, u::Ptr{Float64}, v::Ptr{Float64}, index_nz_v::Ptr{Cint}, nnz_v::Ptr{Cint}, @@ -256,7 +232,7 @@ export bgo_information_s function bgo_information_s(data, inform, status) @ccall libgalahad_single.bgo_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{bgo_inform_type{Float32}}, + inform::Ptr{bgo_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -264,7 +240,7 @@ export bgo_information function bgo_information(data, inform, status) @ccall libgalahad_double.bgo_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{bgo_inform_type{Float64}}, + inform::Ptr{bgo_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -272,14 +248,14 @@ export bgo_terminate_s function bgo_terminate_s(data, control, inform) @ccall libgalahad_single.bgo_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{bgo_control_type{Float32}}, - inform::Ref{bgo_inform_type{Float32}})::Cvoid + control::Ptr{bgo_control_type{Float32}}, + inform::Ptr{bgo_inform_type{Float32}})::Cvoid end export bgo_terminate function bgo_terminate(data, control, inform) @ccall libgalahad_double.bgo_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{bgo_control_type{Float64}}, - inform::Ref{bgo_inform_type{Float64}})::Cvoid + control::Ptr{bgo_control_type{Float64}}, + inform::Ptr{bgo_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/blls.jl b/GALAHAD.jl/src/wrappers/blls.jl index ad6cef3b35..fbcce5a3dc 100644 --- a/GALAHAD.jl/src/wrappers/blls.jl +++ b/GALAHAD.jl/src/wrappers/blls.jl @@ -1,6 +1,6 @@ export blls_control_type -mutable struct blls_control_type{T} +struct blls_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -38,18 +38,11 @@ mutable struct blls_control_type{T} prefix::NTuple{31,Cchar} sbls_control::sbls_control_type{T} convert_control::convert_control_type - - function blls_control_type{T}() where T - type = new() - type.sbls_control = sbls_control_type{T}() - type.convert_control = convert_control_type() - return type - end end export blls_time_type -mutable struct blls_time_type{T} +struct blls_time_type{T} total::T analyse::T factorize::T @@ -58,13 +51,11 @@ mutable struct blls_time_type{T} clock_analyse::T clock_factorize::T clock_solve::T - - blls_time_type{T}() where T = new() end export blls_inform_type -mutable struct blls_inform_type{T} +struct blls_inform_type{T} status::Cint alloc_status::Cint factorization_status::Cint @@ -76,21 +67,13 @@ mutable struct blls_inform_type{T} time::blls_time_type{T} sbls_inform::sbls_inform_type{T} convert_inform::convert_inform_type{T} - - function blls_inform_type{T}() where T - type = new() - type.time = blls_time_type{T}() - type.sbls_inform = sbls_inform_type{T}() - type.convert_inform = convert_inform_type{T}() - return type - end end export blls_initialize_s function blls_initialize_s(data, control, status) @ccall libgalahad_single.blls_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{blls_control_type{Float32}}, + control::Ptr{blls_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -98,52 +81,50 @@ export blls_initialize function blls_initialize(data, control, status) @ccall libgalahad_double.blls_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{blls_control_type{Float64}}, + control::Ptr{blls_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export blls_read_specfile_s function blls_read_specfile_s(control, specfile) - @ccall libgalahad_single.blls_read_specfile_s(control::Ref{blls_control_type{Float32}}, + @ccall libgalahad_single.blls_read_specfile_s(control::Ptr{blls_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export blls_read_specfile function blls_read_specfile(control, specfile) - @ccall libgalahad_double.blls_read_specfile(control::Ref{blls_control_type{Float64}}, + @ccall libgalahad_double.blls_read_specfile(control::Ptr{blls_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export blls_import_s -function blls_import_s(control, data, status, n, o, - Ao_type, Ao_ne, Ao_row, Ao_col, Ao_ptr_ne, Ao_ptr) - @ccall libgalahad_single.blls_import_s(control::Ref{blls_control_type{Float32}}, +function blls_import_s(control, data, status, n, o, Ao_type, Ao_ne, Ao_row, Ao_col, + Ao_ptr_ne, Ao_ptr) + @ccall libgalahad_single.blls_import_s(control::Ptr{blls_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, o::Cint, Ao_type::Ptr{Cchar}, Ao_ne::Cint, Ao_row::Ptr{Cint}, Ao_col::Ptr{Cint}, - Ao_ptr_ne::Cint, - Ao_ptr::Ptr{Cint})::Cvoid + Ao_ptr_ne::Cint, Ao_ptr::Ptr{Cint})::Cvoid end export blls_import -function blls_import(control, data, status, n, o, - Ao_type, Ao_ne, Ao_row, Ao_col, Ao_ptr_ne, Ao_ptr) - @ccall libgalahad_double.blls_import(control::Ref{blls_control_type{Float64}}, +function blls_import(control, data, status, n, o, Ao_type, Ao_ne, Ao_row, Ao_col, Ao_ptr_ne, + Ao_ptr) + @ccall libgalahad_double.blls_import(control::Ptr{blls_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, o::Cint, Ao_type::Ptr{Cchar}, Ao_ne::Cint, Ao_row::Ptr{Cint}, Ao_col::Ptr{Cint}, - Ao_ptr_ne::Cint, - Ao_ptr::Ptr{Cint})::Cvoid + Ao_ptr_ne::Cint, Ao_ptr::Ptr{Cint})::Cvoid end export blls_import_without_a_s function blls_import_without_a_s(control, data, status, n, o) - @ccall libgalahad_single.blls_import_without_a_s(control::Ref{blls_control_type{Float32}}, + @ccall libgalahad_single.blls_import_without_a_s(control::Ptr{blls_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, o::Cint)::Cvoid end @@ -151,7 +132,7 @@ end export blls_import_without_a function blls_import_without_a(control, data, status, n, o) - @ccall libgalahad_double.blls_import_without_a(control::Ref{blls_control_type{Float64}}, + @ccall libgalahad_double.blls_import_without_a(control::Ptr{blls_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, o::Cint)::Cvoid end @@ -159,7 +140,7 @@ end export blls_reset_control_s function blls_reset_control_s(control, data, status) - @ccall libgalahad_single.blls_reset_control_s(control::Ref{blls_control_type{Float32}}, + @ccall libgalahad_single.blls_reset_control_s(control::Ptr{blls_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -167,15 +148,15 @@ end export blls_reset_control function blls_reset_control(control, data, status) - @ccall libgalahad_double.blls_reset_control(control::Ref{blls_control_type{Float64}}, + @ccall libgalahad_double.blls_reset_control(control::Ptr{blls_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end export blls_solve_given_a_s -function blls_solve_given_a_s(data, userdata, status, n, o, Ao_ne, Ao_val, b, x_l, x_u, x, z, r, - g, x_stat, w, eval_prec) +function blls_solve_given_a_s(data, userdata, status, n, o, Ao_ne, Ao_val, b, x_l, x_u, x, + z, r, g, x_stat, w, eval_prec) @ccall libgalahad_single.blls_solve_given_a_s(data::Ptr{Ptr{Cvoid}}, userdata::Ptr{Cvoid}, status::Ptr{Cint}, n::Cint, o::Cint, Ao_ne::Cint, Ao_val::Ptr{Float32}, @@ -189,8 +170,8 @@ end export blls_solve_given_a -function blls_solve_given_a(data, userdata, status, n, o, Ao_ne, Ao_val, b, x_l, x_u, x, z, r, - g, x_stat, w, eval_prec) +function blls_solve_given_a(data, userdata, status, n, o, Ao_ne, Ao_val, b, x_l, x_u, x, z, + r, g, x_stat, w, eval_prec) @ccall libgalahad_double.blls_solve_given_a(data::Ptr{Ptr{Cvoid}}, userdata::Ptr{Cvoid}, status::Ptr{Cint}, n::Cint, o::Cint, Ao_ne::Cint, Ao_val::Ptr{Float64}, @@ -198,25 +179,23 @@ function blls_solve_given_a(data, userdata, status, n, o, Ao_ne, Ao_val, b, x_l, x_u::Ptr{Float64}, x::Ptr{Float64}, z::Ptr{Float64}, r::Ptr{Float64}, g::Ptr{Float64}, x_stat::Ptr{Cint}, - w::Ptr{Float64}, - eval_prec::Ptr{Cvoid})::Cvoid + w::Ptr{Float64}, eval_prec::Ptr{Cvoid})::Cvoid end export blls_solve_reverse_a_prod_s -function blls_solve_reverse_a_prod_s(data, status, eval_status, n, o, b, x_l, x_u, x, z, r, g, - x_stat, v, p, nz_v, nz_v_start, nz_v_end, nz_p, nz_p_end, - w) +function blls_solve_reverse_a_prod_s(data, status, eval_status, n, o, b, x_l, x_u, x, z, r, + g, x_stat, v, p, nz_v, nz_v_start, nz_v_end, nz_p, + nz_p_end, w) @ccall libgalahad_single.blls_solve_reverse_a_prod_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, eval_status::Ptr{Cint}, n::Cint, o::Cint, b::Ptr{Float32}, - x_l::Ptr{Float32}, - x_u::Ptr{Float32}, x::Ptr{Float32}, - z::Ptr{Float32}, r::Ptr{Float32}, - g::Ptr{Float32}, x_stat::Ptr{Cint}, - v::Ptr{Float32}, p::Ptr{Float32}, - nz_v::Ptr{Cint}, + x_l::Ptr{Float32}, x_u::Ptr{Float32}, + x::Ptr{Float32}, z::Ptr{Float32}, + r::Ptr{Float32}, g::Ptr{Float32}, + x_stat::Ptr{Cint}, v::Ptr{Float32}, + p::Ptr{Float32}, nz_v::Ptr{Cint}, nz_v_start::Ptr{Cint}, nz_v_end::Ptr{Cint}, nz_p::Ptr{Cint}, nz_p_end::Cint, @@ -226,29 +205,27 @@ end export blls_solve_reverse_a_prod function blls_solve_reverse_a_prod(data, status, eval_status, n, o, b, x_l, x_u, x, z, r, g, - x_stat, v, p, nz_v, nz_v_start, nz_v_end, nz_p, nz_p_end, - w) + x_stat, v, p, nz_v, nz_v_start, nz_v_end, nz_p, nz_p_end, + w) @ccall libgalahad_double.blls_solve_reverse_a_prod(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, eval_status::Ptr{Cint}, n::Cint, o::Cint, b::Ptr{Float64}, - x_l::Ptr{Float64}, - x_u::Ptr{Float64}, x::Ptr{Float64}, - z::Ptr{Float64}, r::Ptr{Float64}, - g::Ptr{Float64}, x_stat::Ptr{Cint}, - v::Ptr{Float64}, p::Ptr{Float64}, - nz_v::Ptr{Cint}, + x_l::Ptr{Float64}, x_u::Ptr{Float64}, + x::Ptr{Float64}, z::Ptr{Float64}, + r::Ptr{Float64}, g::Ptr{Float64}, + x_stat::Ptr{Cint}, v::Ptr{Float64}, + p::Ptr{Float64}, nz_v::Ptr{Cint}, nz_v_start::Ptr{Cint}, nz_v_end::Ptr{Cint}, nz_p::Ptr{Cint}, - nz_p_end::Cint, - w::Ptr{Float64})::Cvoid + nz_p_end::Cint, w::Ptr{Float64})::Cvoid end export blls_information_s function blls_information_s(data, inform, status) @ccall libgalahad_single.blls_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{blls_inform_type{Float32}}, + inform::Ptr{blls_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -256,7 +233,7 @@ export blls_information function blls_information(data, inform, status) @ccall libgalahad_double.blls_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{blls_inform_type{Float64}}, + inform::Ptr{blls_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -264,14 +241,14 @@ export blls_terminate_s function blls_terminate_s(data, control, inform) @ccall libgalahad_single.blls_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{blls_control_type{Float32}}, - inform::Ref{blls_inform_type{Float32}})::Cvoid + control::Ptr{blls_control_type{Float32}}, + inform::Ptr{blls_inform_type{Float32}})::Cvoid end export blls_terminate function blls_terminate(data, control, inform) @ccall libgalahad_double.blls_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{blls_control_type{Float64}}, - inform::Ref{blls_inform_type{Float64}})::Cvoid + control::Ptr{blls_control_type{Float64}}, + inform::Ptr{blls_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/bllsb.jl b/GALAHAD.jl/src/wrappers/bllsb.jl index beb8f6ca28..1dbe2b4bb5 100644 --- a/GALAHAD.jl/src/wrappers/bllsb.jl +++ b/GALAHAD.jl/src/wrappers/bllsb.jl @@ -1,6 +1,6 @@ export bllsb_control_type -mutable struct bllsb_control_type{T} +struct bllsb_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -62,22 +62,11 @@ mutable struct bllsb_control_type{T} fit_control::fit_control_type roots_control::roots_control_type{T} cro_control::cro_control_type{T} - - function bllsb_control_type{T}() where T - type = new() - type.fdc_control = fdc_control_type{T}() - type.sls_control = sls_control_type{T}() - type.sls_pounce_control = sls_control_type{T}() - type.fit_control = fit_control_type() - type.roots_control = roots_control_type{T}() - type.cro_control = cro_control_type{T}() - return type - end end export bllsb_time_type -mutable struct bllsb_time_type{T} +struct bllsb_time_type{T} total::T preprocess::T find_dependent::T @@ -90,13 +79,11 @@ mutable struct bllsb_time_type{T} clock_analyse::T clock_factorize::T clock_solve::T - - bllsb_time_type{T}() where T = new() end export bllsb_inform_type -mutable struct bllsb_inform_type{T} +struct bllsb_inform_type{T} status::Cint alloc_status::Cint bad_alloc::NTuple{81,Cchar} @@ -123,25 +110,13 @@ mutable struct bllsb_inform_type{T} roots_inform::roots_inform_type cro_inform::cro_inform_type{T} rpd_inform::rpd_inform_type - - function bllsb_inform_type{T}() where T - type = new() - type.fdc_inform = fdc_inform_type{T}() - type.sls_inform = sls_inform_type{T}() - type.sls_pounce_inform = sls_inform_type{T}() - type.fit_inform = fit_inform_type() - type.roots_inform = roots_inform_type() - type.cro_inform = cro_inform_type{T}() - type.rpd_inform = rpd_inform_type() - return type - end end export bllsb_initialize_s function bllsb_initialize_s(data, control, status) @ccall libgalahad_single.bllsb_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{bllsb_control_type{Float32}}, + control::Ptr{bllsb_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -149,29 +124,29 @@ export bllsb_initialize function bllsb_initialize(data, control, status) @ccall libgalahad_double.bllsb_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{bllsb_control_type{Float64}}, + control::Ptr{bllsb_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export bllsb_read_specfile_s function bllsb_read_specfile_s(control, specfile) - @ccall libgalahad_single.bllsb_read_specfile_s(control::Ref{bllsb_control_type{Float32}}, + @ccall libgalahad_single.bllsb_read_specfile_s(control::Ptr{bllsb_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export bllsb_read_specfile function bllsb_read_specfile(control, specfile) - @ccall libgalahad_double.bllsb_read_specfile(control::Ref{bllsb_control_type{Float64}}, + @ccall libgalahad_double.bllsb_read_specfile(control::Ptr{bllsb_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export bllsb_import_s function bllsb_import_s(control, data, status, n, o, Ao_type, Ao_ne, Ao_row, Ao_col, - Ao_ptr_ne, Ao_ptr) - @ccall libgalahad_single.bllsb_import_s(control::Ref{bllsb_control_type{Float32}}, + Ao_ptr_ne, Ao_ptr) + @ccall libgalahad_single.bllsb_import_s(control::Ptr{bllsb_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, o::Cint, Ao_type::Ptr{Cchar}, Ao_ne::Cint, Ao_row::Ptr{Cint}, Ao_col::Ptr{Cint}, @@ -181,8 +156,8 @@ end export bllsb_import function bllsb_import(control, data, status, n, o, Ao_type, Ao_ne, Ao_row, Ao_col, - Ao_ptr_ne, Ao_ptr) - @ccall libgalahad_double.bllsb_import(control::Ref{bllsb_control_type{Float64}}, + Ao_ptr_ne, Ao_ptr) + @ccall libgalahad_double.bllsb_import(control::Ptr{bllsb_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, o::Cint, Ao_type::Ptr{Cchar}, Ao_ne::Cint, Ao_row::Ptr{Cint}, Ao_col::Ptr{Cint}, @@ -192,7 +167,7 @@ end export bllsb_reset_control_s function bllsb_reset_control_s(control, data, status) - @ccall libgalahad_single.bllsb_reset_control_s(control::Ref{bllsb_control_type{Float32}}, + @ccall libgalahad_single.bllsb_reset_control_s(control::Ptr{bllsb_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -200,15 +175,15 @@ end export bllsb_reset_control function bllsb_reset_control(control, data, status) - @ccall libgalahad_double.bllsb_reset_control(control::Ref{bllsb_control_type{Float64}}, + @ccall libgalahad_double.bllsb_reset_control(control::Ptr{bllsb_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end export bllsb_solve_blls_s -function bllsb_solve_blls_s(data, status, n, o, Ao_ne, Ao_val, b, regularization_weight, x_l, - x_u, x, r, z, x_stat, w) +function bllsb_solve_blls_s(data, status, n, o, Ao_ne, Ao_val, b, regularization_weight, + x_l, x_u, x, r, z, x_stat, w) @ccall libgalahad_single.bllsb_solve_blls_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, o::Cint, Ao_ne::Cint, Ao_val::Ptr{Float32}, b::Ptr{Float32}, @@ -222,7 +197,7 @@ end export bllsb_solve_blls function bllsb_solve_blls(data, status, n, o, Ao_ne, Ao_val, b, regularization_weight, x_l, - x_u, x, r, z, x_stat, w) + x_u, x, r, z, x_stat, w) @ccall libgalahad_double.bllsb_solve_blls(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, o::Cint, Ao_ne::Cint, Ao_val::Ptr{Float64}, b::Ptr{Float64}, @@ -237,7 +212,7 @@ export bllsb_information_s function bllsb_information_s(data, inform, status) @ccall libgalahad_single.bllsb_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{bllsb_inform_type{Float32}}, + inform::Ptr{bllsb_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -245,7 +220,7 @@ export bllsb_information function bllsb_information(data, inform, status) @ccall libgalahad_double.bllsb_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{bllsb_inform_type{Float64}}, + inform::Ptr{bllsb_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -253,14 +228,14 @@ export bllsb_terminate_s function bllsb_terminate_s(data, control, inform) @ccall libgalahad_single.bllsb_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{bllsb_control_type{Float32}}, - inform::Ref{bllsb_inform_type{Float32}})::Cvoid + control::Ptr{bllsb_control_type{Float32}}, + inform::Ptr{bllsb_inform_type{Float32}})::Cvoid end export bllsb_terminate function bllsb_terminate(data, control, inform) @ccall libgalahad_double.bllsb_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{bllsb_control_type{Float64}}, - inform::Ref{bllsb_inform_type{Float64}})::Cvoid + control::Ptr{bllsb_control_type{Float64}}, + inform::Ptr{bllsb_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/bqp.jl b/GALAHAD.jl/src/wrappers/bqp.jl index 7d9c0e9620..ceb1d9b3ef 100644 --- a/GALAHAD.jl/src/wrappers/bqp.jl +++ b/GALAHAD.jl/src/wrappers/bqp.jl @@ -1,6 +1,6 @@ export bqp_control_type -mutable struct bqp_control_type{T} +struct bqp_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -30,28 +30,20 @@ mutable struct bqp_control_type{T} sif_file_name::NTuple{31,Cchar} prefix::NTuple{31,Cchar} sbls_control::sbls_control_type{T} - - function bqp_control_type{T}() where T - type = new() - type.sbls_control = sbls_control_type{T}() - return type - end end export bqp_time_type -mutable struct bqp_time_type +struct bqp_time_type total::Float32 analyse::Float32 factorize::Float32 solve::Float32 - - bqp_time_type() = new() end export bqp_inform_type -mutable struct bqp_inform_type{T} +struct bqp_inform_type{T} status::Cint alloc_status::Cint factorization_status::Cint @@ -62,20 +54,13 @@ mutable struct bqp_inform_type{T} bad_alloc::NTuple{81,Cchar} time::bqp_time_type sbls_inform::sbls_inform_type{T} - - function bqp_inform_type{T}() where T - type = new() - type.time = bqp_time_type() - type.sbls_inform = sbls_inform_type{T}() - return type - end end export bqp_initialize_s function bqp_initialize_s(data, control, status) @ccall libgalahad_single.bqp_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{bqp_control_type{Float32}}, + control::Ptr{bqp_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -83,28 +68,28 @@ export bqp_initialize function bqp_initialize(data, control, status) @ccall libgalahad_double.bqp_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{bqp_control_type{Float64}}, + control::Ptr{bqp_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export bqp_read_specfile_s function bqp_read_specfile_s(control, specfile) - @ccall libgalahad_single.bqp_read_specfile_s(control::Ref{bqp_control_type{Float32}}, + @ccall libgalahad_single.bqp_read_specfile_s(control::Ptr{bqp_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export bqp_read_specfile function bqp_read_specfile(control, specfile) - @ccall libgalahad_double.bqp_read_specfile(control::Ref{bqp_control_type{Float64}}, + @ccall libgalahad_double.bqp_read_specfile(control::Ptr{bqp_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export bqp_import_s function bqp_import_s(control, data, status, n, H_type, ne, H_row, H_col, H_ptr) - @ccall libgalahad_single.bqp_import_s(control::Ref{bqp_control_type{Float32}}, + @ccall libgalahad_single.bqp_import_s(control::Ptr{bqp_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, H_type::Ptr{Cchar}, ne::Cint, H_row::Ptr{Cint}, H_col::Ptr{Cint}, H_ptr::Ptr{Cint})::Cvoid @@ -113,7 +98,7 @@ end export bqp_import function bqp_import(control, data, status, n, H_type, ne, H_row, H_col, H_ptr) - @ccall libgalahad_double.bqp_import(control::Ref{bqp_control_type{Float64}}, + @ccall libgalahad_double.bqp_import(control::Ptr{bqp_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, H_type::Ptr{Cchar}, ne::Cint, H_row::Ptr{Cint}, H_col::Ptr{Cint}, H_ptr::Ptr{Cint})::Cvoid @@ -122,7 +107,7 @@ end export bqp_import_without_h_s function bqp_import_without_h_s(control, data, status, n) - @ccall libgalahad_single.bqp_import_without_h_s(control::Ref{bqp_control_type{Float32}}, + @ccall libgalahad_single.bqp_import_without_h_s(control::Ptr{bqp_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint)::Cvoid end @@ -130,7 +115,7 @@ end export bqp_import_without_h function bqp_import_without_h(control, data, status, n) - @ccall libgalahad_double.bqp_import_without_h(control::Ref{bqp_control_type{Float64}}, + @ccall libgalahad_double.bqp_import_without_h(control::Ptr{bqp_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint)::Cvoid end @@ -138,7 +123,7 @@ end export bqp_reset_control_s function bqp_reset_control_s(control, data, status) - @ccall libgalahad_single.bqp_reset_control_s(control::Ref{bqp_control_type{Float32}}, + @ccall libgalahad_single.bqp_reset_control_s(control::Ptr{bqp_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -146,7 +131,7 @@ end export bqp_reset_control function bqp_reset_control(control, data, status) - @ccall libgalahad_double.bqp_reset_control(control::Ref{bqp_control_type{Float64}}, + @ccall libgalahad_double.bqp_reset_control(control::Ptr{bqp_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -167,24 +152,22 @@ export bqp_solve_given_h function bqp_solve_given_h(data, status, n, h_ne, H_val, g, f, x_l, x_u, x, z, x_stat) @ccall libgalahad_double.bqp_solve_given_h(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, h_ne::Cint, H_val::Ptr{Float64}, - g::Ptr{Float64}, f::Float64, - x_l::Ptr{Float64}, x_u::Ptr{Float64}, - x::Ptr{Float64}, z::Ptr{Float64}, - x_stat::Ptr{Cint})::Cvoid + g::Ptr{Float64}, f::Float64, x_l::Ptr{Float64}, + x_u::Ptr{Float64}, x::Ptr{Float64}, + z::Ptr{Float64}, x_stat::Ptr{Cint})::Cvoid end export bqp_solve_reverse_h_prod_s function bqp_solve_reverse_h_prod_s(data, status, n, g, f, x_l, x_u, x, z, x_stat, v, prod, - nz_v, nz_v_start, nz_v_end, nz_prod, nz_prod_end) + nz_v, nz_v_start, nz_v_end, nz_prod, nz_prod_end) @ccall libgalahad_single.bqp_solve_reverse_h_prod_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, g::Ptr{Float32}, f::Float32, - x_l::Ptr{Float32}, - x_u::Ptr{Float32}, x::Ptr{Float32}, - z::Ptr{Float32}, x_stat::Ptr{Cint}, - v::Ptr{Float32}, prod::Ptr{Float32}, - nz_v::Ptr{Cint}, + x_l::Ptr{Float32}, x_u::Ptr{Float32}, + x::Ptr{Float32}, z::Ptr{Float32}, + x_stat::Ptr{Cint}, v::Ptr{Float32}, + prod::Ptr{Float32}, nz_v::Ptr{Cint}, nz_v_start::Ptr{Cint}, nz_v_end::Ptr{Cint}, nz_prod::Ptr{Cint}, @@ -194,18 +177,16 @@ end export bqp_solve_reverse_h_prod function bqp_solve_reverse_h_prod(data, status, n, g, f, x_l, x_u, x, z, x_stat, v, prod, - nz_v, nz_v_start, nz_v_end, nz_prod, nz_prod_end) + nz_v, nz_v_start, nz_v_end, nz_prod, nz_prod_end) @ccall libgalahad_double.bqp_solve_reverse_h_prod(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, g::Ptr{Float64}, f::Float64, - x_l::Ptr{Float64}, - x_u::Ptr{Float64}, x::Ptr{Float64}, - z::Ptr{Float64}, x_stat::Ptr{Cint}, - v::Ptr{Float64}, prod::Ptr{Float64}, - nz_v::Ptr{Cint}, + x_l::Ptr{Float64}, x_u::Ptr{Float64}, + x::Ptr{Float64}, z::Ptr{Float64}, + x_stat::Ptr{Cint}, v::Ptr{Float64}, + prod::Ptr{Float64}, nz_v::Ptr{Cint}, nz_v_start::Ptr{Cint}, - nz_v_end::Ptr{Cint}, - nz_prod::Ptr{Cint}, + nz_v_end::Ptr{Cint}, nz_prod::Ptr{Cint}, nz_prod_end::Cint)::Cvoid end @@ -213,7 +194,7 @@ export bqp_information_s function bqp_information_s(data, inform, status) @ccall libgalahad_single.bqp_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{bqp_inform_type{Float32}}, + inform::Ptr{bqp_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -221,7 +202,7 @@ export bqp_information function bqp_information(data, inform, status) @ccall libgalahad_double.bqp_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{bqp_inform_type{Float64}}, + inform::Ptr{bqp_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -229,14 +210,14 @@ export bqp_terminate_s function bqp_terminate_s(data, control, inform) @ccall libgalahad_single.bqp_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{bqp_control_type{Float32}}, - inform::Ref{bqp_inform_type{Float32}})::Cvoid + control::Ptr{bqp_control_type{Float32}}, + inform::Ptr{bqp_inform_type{Float32}})::Cvoid end export bqp_terminate function bqp_terminate(data, control, inform) @ccall libgalahad_double.bqp_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{bqp_control_type{Float64}}, - inform::Ref{bqp_inform_type{Float64}})::Cvoid + control::Ptr{bqp_control_type{Float64}}, + inform::Ptr{bqp_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/bqpb.jl b/GALAHAD.jl/src/wrappers/bqpb.jl index 6f639fbadc..e482b9a615 100644 --- a/GALAHAD.jl/src/wrappers/bqpb.jl +++ b/GALAHAD.jl/src/wrappers/bqpb.jl @@ -1,6 +1,6 @@ export bqpb_control_type -mutable struct bqpb_control_type{T} +struct bqpb_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -62,21 +62,11 @@ mutable struct bqpb_control_type{T} fit_control::fit_control_type roots_control::roots_control_type{T} cro_control::cro_control_type{T} - - function bqpb_control_type{T}() where T - type = new() - type.fdc_control = fdc_control_type{T}() - type.sbls_control = sbls_control_type{T}() - type.fit_control = fit_control_type() - type.roots_control = roots_control_type{T}() - type.cro_control = cro_control_type{T}() - return type - end end export bqpb_time_type -mutable struct bqpb_time_type{T} +struct bqpb_time_type{T} total::T preprocess::T find_dependent::T @@ -89,13 +79,11 @@ mutable struct bqpb_time_type{T} clock_analyse::T clock_factorize::T clock_solve::T - - bqpb_time_type{T}() where T = new() end export bqpb_inform_type -mutable struct bqpb_inform_type{T} +struct bqpb_inform_type{T} status::Cint alloc_status::Cint bad_alloc::NTuple{81,Cchar} @@ -125,25 +113,13 @@ mutable struct bqpb_inform_type{T} roots_inform::roots_inform_type cro_inform::cro_inform_type{T} rpd_inform::rpd_inform_type - - function bqpb_inform_type{T}() where T - type = new() - type.time = bqpb_time_type{T}() - type.fdc_inform = fdc_inform_type{T}() - type.sbls_inform = sbls_inform_type{T}() - type.fit_inform = fit_inform_type() - type.roots_inform = roots_inform_type() - type.cro_inform = cro_inform_type{T}() - type.rpd_inform = rpd_inform_type() - return type - end end export bqpb_initialize_s function bqpb_initialize_s(data, control, status) @ccall libgalahad_single.bqpb_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{bqpb_control_type{Float32}}, + control::Ptr{bqpb_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -151,28 +127,28 @@ export bqpb_initialize function bqpb_initialize(data, control, status) @ccall libgalahad_double.bqpb_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{bqpb_control_type{Float64}}, + control::Ptr{bqpb_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export bqpb_read_specfile_s function bqpb_read_specfile_s(control, specfile) - @ccall libgalahad_single.bqpb_read_specfile_s(control::Ref{bqpb_control_type{Float32}}, + @ccall libgalahad_single.bqpb_read_specfile_s(control::Ptr{bqpb_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export bqpb_read_specfile function bqpb_read_specfile(control, specfile) - @ccall libgalahad_double.bqpb_read_specfile(control::Ref{bqpb_control_type{Float64}}, + @ccall libgalahad_double.bqpb_read_specfile(control::Ptr{bqpb_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export bqpb_import_s function bqpb_import_s(control, data, status, n, H_type, H_ne, H_row, H_col, H_ptr) - @ccall libgalahad_single.bqpb_import_s(control::Ref{bqpb_control_type{Float32}}, + @ccall libgalahad_single.bqpb_import_s(control::Ptr{bqpb_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, H_type::Ptr{Cchar}, H_ne::Cint, H_row::Ptr{Cint}, H_col::Ptr{Cint}, H_ptr::Ptr{Cint})::Cvoid @@ -181,7 +157,7 @@ end export bqpb_import function bqpb_import(control, data, status, n, H_type, H_ne, H_row, H_col, H_ptr) - @ccall libgalahad_double.bqpb_import(control::Ref{bqpb_control_type{Float64}}, + @ccall libgalahad_double.bqpb_import(control::Ptr{bqpb_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, H_type::Ptr{Cchar}, H_ne::Cint, H_row::Ptr{Cint}, H_col::Ptr{Cint}, H_ptr::Ptr{Cint})::Cvoid @@ -190,7 +166,7 @@ end export bqpb_reset_control_s function bqpb_reset_control_s(control, data, status) - @ccall libgalahad_single.bqpb_reset_control_s(control::Ref{bqpb_control_type{Float32}}, + @ccall libgalahad_single.bqpb_reset_control_s(control::Ptr{bqpb_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -198,7 +174,7 @@ end export bqpb_reset_control function bqpb_reset_control(control, data, status) - @ccall libgalahad_double.bqpb_reset_control(control::Ref{bqpb_control_type{Float64}}, + @ccall libgalahad_double.bqpb_reset_control(control::Ptr{bqpb_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -208,19 +184,17 @@ export bqpb_solve_qp_s function bqpb_solve_qp_s(data, status, n, h_ne, H_val, g, f, x_l, x_u, x, z, x_stat) @ccall libgalahad_single.bqpb_solve_qp_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, h_ne::Cint, H_val::Ptr{Float32}, - g::Ptr{Float32}, f::Float32, - x_l::Ptr{Float32}, x_u::Ptr{Float32}, - x::Ptr{Float32}, z::Ptr{Float32}, - x_stat::Ptr{Cint})::Cvoid + g::Ptr{Float32}, f::Float32, x_l::Ptr{Float32}, + x_u::Ptr{Float32}, x::Ptr{Float32}, + z::Ptr{Float32}, x_stat::Ptr{Cint})::Cvoid end export bqpb_solve_qp function bqpb_solve_qp(data, status, n, h_ne, H_val, g, f, x_l, x_u, x, z, x_stat) - @ccall libgalahad_double.bqpb_solve_qp(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, - n::Cint, h_ne::Cint, H_val::Ptr{Float64}, - g::Ptr{Float64}, f::Float64, - x_l::Ptr{Float64}, x_u::Ptr{Float64}, + @ccall libgalahad_double.bqpb_solve_qp(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, + h_ne::Cint, H_val::Ptr{Float64}, g::Ptr{Float64}, + f::Float64, x_l::Ptr{Float64}, x_u::Ptr{Float64}, x::Ptr{Float64}, z::Ptr{Float64}, x_stat::Ptr{Cint})::Cvoid end @@ -241,17 +215,16 @@ export bqpb_solve_sldqp function bqpb_solve_sldqp(data, status, n, w, x0, g, f, x_l, x_u, x, z, x_stat) @ccall libgalahad_double.bqpb_solve_sldqp(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, w::Ptr{Float64}, x0::Ptr{Float64}, - g::Ptr{Float64}, f::Float64, - x_l::Ptr{Float64}, x_u::Ptr{Float64}, - x::Ptr{Float64}, z::Ptr{Float64}, - x_stat::Ptr{Cint})::Cvoid + g::Ptr{Float64}, f::Float64, x_l::Ptr{Float64}, + x_u::Ptr{Float64}, x::Ptr{Float64}, + z::Ptr{Float64}, x_stat::Ptr{Cint})::Cvoid end export bqpb_information_s function bqpb_information_s(data, inform, status) @ccall libgalahad_single.bqpb_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{bqpb_inform_type{Float32}}, + inform::Ptr{bqpb_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -259,7 +232,7 @@ export bqpb_information function bqpb_information(data, inform, status) @ccall libgalahad_double.bqpb_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{bqpb_inform_type{Float64}}, + inform::Ptr{bqpb_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -267,14 +240,14 @@ export bqpb_terminate_s function bqpb_terminate_s(data, control, inform) @ccall libgalahad_single.bqpb_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{bqpb_control_type{Float32}}, - inform::Ref{bqpb_inform_type{Float32}})::Cvoid + control::Ptr{bqpb_control_type{Float32}}, + inform::Ptr{bqpb_inform_type{Float32}})::Cvoid end export bqpb_terminate function bqpb_terminate(data, control, inform) @ccall libgalahad_double.bqpb_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{bqpb_control_type{Float64}}, - inform::Ref{bqpb_inform_type{Float64}})::Cvoid + control::Ptr{bqpb_control_type{Float64}}, + inform::Ptr{bqpb_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/bsc.jl b/GALAHAD.jl/src/wrappers/bsc.jl index f4eb1ee06e..73de892f63 100644 --- a/GALAHAD.jl/src/wrappers/bsc.jl +++ b/GALAHAD.jl/src/wrappers/bsc.jl @@ -1,6 +1,6 @@ export bsc_control_type -mutable struct bsc_control_type +struct bsc_control_type f_indexing::Bool error::Cint out::Cint @@ -12,13 +12,11 @@ mutable struct bsc_control_type space_critical::Bool deallocate_error_fatal::Bool prefix::NTuple{31,Cchar} - - bsc_control_type() = new() end export bsc_inform_type -mutable struct bsc_inform_type{T} +struct bsc_inform_type{T} status::Cint alloc_status::Cint bad_alloc::NTuple{81,Cchar} @@ -26,15 +24,13 @@ mutable struct bsc_inform_type{T} exceeds_max_col::Cint time::T clock_time::T - - bsc_inform_type{T}() where T = new() end export bsc_initialize_s function bsc_initialize_s(data, control, status) @ccall libgalahad_single.bsc_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{bsc_control_type}, + control::Ptr{bsc_control_type}, status::Ptr{Cint})::Cvoid end @@ -42,7 +38,7 @@ export bsc_initialize function bsc_initialize(data, control, status) @ccall libgalahad_double.bsc_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{bsc_control_type}, + control::Ptr{bsc_control_type}, status::Ptr{Cint})::Cvoid end @@ -50,7 +46,7 @@ export bsc_information_s function bsc_information_s(data, inform, status) @ccall libgalahad_single.bsc_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{bsc_inform_type{Float32}}, + inform::Ptr{bsc_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -58,7 +54,7 @@ export bsc_information function bsc_information(data, inform, status) @ccall libgalahad_double.bsc_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{bsc_inform_type{Float64}}, + inform::Ptr{bsc_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -66,14 +62,14 @@ export bsc_terminate_s function bsc_terminate_s(data, control, inform) @ccall libgalahad_single.bsc_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{bsc_control_type}, - inform::Ref{bsc_inform_type{Float32}})::Cvoid + control::Ptr{bsc_control_type}, + inform::Ptr{bsc_inform_type{Float32}})::Cvoid end export bsc_terminate function bsc_terminate(data, control, inform) @ccall libgalahad_double.bsc_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{bsc_control_type}, - inform::Ref{bsc_inform_type{Float64}})::Cvoid + control::Ptr{bsc_control_type}, + inform::Ptr{bsc_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/ccqp.jl b/GALAHAD.jl/src/wrappers/ccqp.jl index 09c8446ae0..3cf8dcaee2 100644 --- a/GALAHAD.jl/src/wrappers/ccqp.jl +++ b/GALAHAD.jl/src/wrappers/ccqp.jl @@ -1,6 +1,6 @@ export ccqp_control_type -mutable struct ccqp_control_type{T} +struct ccqp_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -62,21 +62,11 @@ mutable struct ccqp_control_type{T} fit_control::fit_control_type roots_control::roots_control_type{T} cro_control::cro_control_type{T} - - function ccqp_control_type{T}() where T - type = new() - type.fdc_control = fdc_control_type{T}() - type.sbls_control = sbls_control_type{T}() - type.fit_control = fit_control_type() - type.roots_control = roots_control_type{T}() - type.cro_control = cro_control_type{T}() - return type - end end export ccqp_time_type -mutable struct ccqp_time_type{T} +struct ccqp_time_type{T} total::T preprocess::T find_dependent::T @@ -89,13 +79,11 @@ mutable struct ccqp_time_type{T} clock_analyse::T clock_factorize::T clock_solve::T - - ccqp_time_type{T}() where T = new() end export ccqp_inform_type -mutable struct ccqp_inform_type{T} +struct ccqp_inform_type{T} status::Cint alloc_status::Cint bad_alloc::NTuple{81,Cchar} @@ -125,25 +113,13 @@ mutable struct ccqp_inform_type{T} roots_inform::roots_inform_type cro_inform::cro_inform_type{T} rpd_inform::rpd_inform_type - - function ccqp_inform_type{T}() where T - type = new() - type.time = ccqp_time_type{T}() - type.fdc_inform = fdc_inform_type{T}() - type.sbls_inform = sbls_inform_type{T}() - type.fit_inform = fit_inform_type() - type.roots_inform = roots_inform_type() - type.cro_inform = cro_inform_type{T}() - type.rpd_inform = rpd_inform_type() - return type - end end export ccqp_initialize_s function ccqp_initialize_s(data, control, status) @ccall libgalahad_single.ccqp_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{ccqp_control_type{Float32}}, + control::Ptr{ccqp_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -151,29 +127,29 @@ export ccqp_initialize function ccqp_initialize(data, control, status) @ccall libgalahad_double.ccqp_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{ccqp_control_type{Float64}}, + control::Ptr{ccqp_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export ccqp_read_specfile_s function ccqp_read_specfile_s(control, specfile) - @ccall libgalahad_single.ccqp_read_specfile_s(control::Ref{ccqp_control_type{Float32}}, + @ccall libgalahad_single.ccqp_read_specfile_s(control::Ptr{ccqp_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export ccqp_read_specfile function ccqp_read_specfile(control, specfile) - @ccall libgalahad_double.ccqp_read_specfile(control::Ref{ccqp_control_type{Float64}}, + @ccall libgalahad_double.ccqp_read_specfile(control::Ptr{ccqp_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export ccqp_import_s -function ccqp_import_s(control, data, status, n, m, H_type, H_ne, H_row, H_col, H_ptr, A_type, - A_ne, A_row, A_col, A_ptr) - @ccall libgalahad_single.ccqp_import_s(control::Ref{ccqp_control_type{Float32}}, +function ccqp_import_s(control, data, status, n, m, H_type, H_ne, H_row, H_col, H_ptr, + A_type, A_ne, A_row, A_col, A_ptr) + @ccall libgalahad_single.ccqp_import_s(control::Ptr{ccqp_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, H_type::Ptr{Cchar}, H_ne::Cint, H_row::Ptr{Cint}, H_col::Ptr{Cint}, @@ -185,20 +161,19 @@ end export ccqp_import function ccqp_import(control, data, status, n, m, H_type, H_ne, H_row, H_col, H_ptr, A_type, - A_ne, A_row, A_col, A_ptr) - @ccall libgalahad_double.ccqp_import(control::Ref{ccqp_control_type{Float64}}, + A_ne, A_row, A_col, A_ptr) + @ccall libgalahad_double.ccqp_import(control::Ptr{ccqp_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, H_type::Ptr{Cchar}, H_ne::Cint, - H_row::Ptr{Cint}, H_col::Ptr{Cint}, - H_ptr::Ptr{Cint}, A_type::Ptr{Cchar}, A_ne::Cint, - A_row::Ptr{Cint}, A_col::Ptr{Cint}, - A_ptr::Ptr{Cint})::Cvoid + H_row::Ptr{Cint}, H_col::Ptr{Cint}, H_ptr::Ptr{Cint}, + A_type::Ptr{Cchar}, A_ne::Cint, A_row::Ptr{Cint}, + A_col::Ptr{Cint}, A_ptr::Ptr{Cint})::Cvoid end export ccqp_reset_control_s function ccqp_reset_control_s(control, data, status) - @ccall libgalahad_single.ccqp_reset_control_s(control::Ref{ccqp_control_type{Float32}}, + @ccall libgalahad_single.ccqp_reset_control_s(control::Ptr{ccqp_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -206,7 +181,7 @@ end export ccqp_reset_control function ccqp_reset_control(control, data, status) - @ccall libgalahad_double.ccqp_reset_control(control::Ref{ccqp_control_type{Float64}}, + @ccall libgalahad_double.ccqp_reset_control(control::Ptr{ccqp_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -214,11 +189,11 @@ end export ccqp_solve_qp_s function ccqp_solve_qp_s(data, status, n, m, h_ne, H_val, g, f, a_ne, A_val, c_l, c_u, x_l, - x_u, x, c, y, z, x_stat, c_stat) + x_u, x, c, y, z, x_stat, c_stat) @ccall libgalahad_single.ccqp_solve_qp_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, h_ne::Cint, - H_val::Ptr{Float32}, g::Ptr{Float32}, - f::Float32, a_ne::Cint, A_val::Ptr{Float32}, + H_val::Ptr{Float32}, g::Ptr{Float32}, f::Float32, + a_ne::Cint, A_val::Ptr{Float32}, c_l::Ptr{Float32}, c_u::Ptr{Float32}, x_l::Ptr{Float32}, x_u::Ptr{Float32}, x::Ptr{Float32}, c::Ptr{Float32}, @@ -229,26 +204,25 @@ end export ccqp_solve_qp function ccqp_solve_qp(data, status, n, m, h_ne, H_val, g, f, a_ne, A_val, c_l, c_u, x_l, - x_u, x, c, y, z, x_stat, c_stat) - @ccall libgalahad_double.ccqp_solve_qp(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, - n::Cint, m::Cint, h_ne::Cint, - H_val::Ptr{Float64}, g::Ptr{Float64}, - f::Float64, a_ne::Cint, A_val::Ptr{Float64}, - c_l::Ptr{Float64}, c_u::Ptr{Float64}, - x_l::Ptr{Float64}, x_u::Ptr{Float64}, - x::Ptr{Float64}, c::Ptr{Float64}, - y::Ptr{Float64}, z::Ptr{Float64}, + x_u, x, c, y, z, x_stat, c_stat) + @ccall libgalahad_double.ccqp_solve_qp(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, + m::Cint, h_ne::Cint, H_val::Ptr{Float64}, + g::Ptr{Float64}, f::Float64, a_ne::Cint, + A_val::Ptr{Float64}, c_l::Ptr{Float64}, + c_u::Ptr{Float64}, x_l::Ptr{Float64}, + x_u::Ptr{Float64}, x::Ptr{Float64}, + c::Ptr{Float64}, y::Ptr{Float64}, z::Ptr{Float64}, x_stat::Ptr{Cint}, c_stat::Ptr{Cint})::Cvoid end export ccqp_solve_sldqp_s -function ccqp_solve_sldqp_s(data, status, n, m, w, x0, g, f, a_ne, A_val, c_l, c_u, x_l, x_u, - x, c, y, z, x_stat, c_stat) +function ccqp_solve_sldqp_s(data, status, n, m, w, x0, g, f, a_ne, A_val, c_l, c_u, x_l, + x_u, x, c, y, z, x_stat, c_stat) @ccall libgalahad_single.ccqp_solve_sldqp_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, w::Ptr{Float32}, - x0::Ptr{Float32}, g::Ptr{Float32}, - f::Float32, a_ne::Cint, A_val::Ptr{Float32}, + x0::Ptr{Float32}, g::Ptr{Float32}, f::Float32, + a_ne::Cint, A_val::Ptr{Float32}, c_l::Ptr{Float32}, c_u::Ptr{Float32}, x_l::Ptr{Float32}, x_u::Ptr{Float32}, x::Ptr{Float32}, c::Ptr{Float32}, @@ -259,11 +233,11 @@ end export ccqp_solve_sldqp function ccqp_solve_sldqp(data, status, n, m, w, x0, g, f, a_ne, A_val, c_l, c_u, x_l, x_u, - x, c, y, z, x_stat, c_stat) + x, c, y, z, x_stat, c_stat) @ccall libgalahad_double.ccqp_solve_sldqp(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, w::Ptr{Float64}, - x0::Ptr{Float64}, g::Ptr{Float64}, - f::Float64, a_ne::Cint, A_val::Ptr{Float64}, + x0::Ptr{Float64}, g::Ptr{Float64}, f::Float64, + a_ne::Cint, A_val::Ptr{Float64}, c_l::Ptr{Float64}, c_u::Ptr{Float64}, x_l::Ptr{Float64}, x_u::Ptr{Float64}, x::Ptr{Float64}, c::Ptr{Float64}, @@ -275,7 +249,7 @@ export ccqp_information_s function ccqp_information_s(data, inform, status) @ccall libgalahad_single.ccqp_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{ccqp_inform_type{Float32}}, + inform::Ptr{ccqp_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -283,7 +257,7 @@ export ccqp_information function ccqp_information(data, inform, status) @ccall libgalahad_double.ccqp_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{ccqp_inform_type{Float64}}, + inform::Ptr{ccqp_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -291,14 +265,14 @@ export ccqp_terminate_s function ccqp_terminate_s(data, control, inform) @ccall libgalahad_single.ccqp_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{ccqp_control_type{Float32}}, - inform::Ref{ccqp_inform_type{Float32}})::Cvoid + control::Ptr{ccqp_control_type{Float32}}, + inform::Ptr{ccqp_inform_type{Float32}})::Cvoid end export ccqp_terminate function ccqp_terminate(data, control, inform) @ccall libgalahad_double.ccqp_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{ccqp_control_type{Float64}}, - inform::Ref{ccqp_inform_type{Float64}})::Cvoid + control::Ptr{ccqp_control_type{Float64}}, + inform::Ptr{ccqp_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/clls.jl b/GALAHAD.jl/src/wrappers/clls.jl index 70083d988d..49623ef642 100644 --- a/GALAHAD.jl/src/wrappers/clls.jl +++ b/GALAHAD.jl/src/wrappers/clls.jl @@ -1,6 +1,6 @@ export clls_control_type -mutable struct clls_control_type{T} +struct clls_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -62,22 +62,11 @@ mutable struct clls_control_type{T} fit_control::fit_control_type roots_control::roots_control_type{T} cro_control::cro_control_type{T} - - function clls_control_type{T}() where T - type = new() - type.fdc_control = fdc_control_type{T}() - type.sls_control = sls_control_type{T}() - type.sls_pounce_control = sls_control_type{T}() - type.fit_control = fit_control_type() - type.roots_control = roots_control_type{T}() - type.cro_control = cro_control_type{T}() - return type - end end export clls_time_type -mutable struct clls_time_type{T} +struct clls_time_type{T} total::T preprocess::T find_dependent::T @@ -90,13 +79,11 @@ mutable struct clls_time_type{T} clock_analyse::T clock_factorize::T clock_solve::T - - clls_time_type{T}() where T = new() end export clls_inform_type -mutable struct clls_inform_type{T} +struct clls_inform_type{T} status::Cint alloc_status::Cint bad_alloc::NTuple{81,Cchar} @@ -123,26 +110,13 @@ mutable struct clls_inform_type{T} roots_inform::roots_inform_type cro_inform::cro_inform_type{T} rpd_inform::rpd_inform_type - - function clls_inform_type{T}() where T - type = new() - type.time = clls_time_type{T}() - type.fdc_inform = fdc_inform_type{T}() - type.sls_inform = sls_inform_type{T}() - type.sls_pounce_inform = sls_inform_type{T}() - type.fit_inform = fit_inform_type() - type.roots_inform = roots_inform_type() - type.cro_inform = cro_inform_type{T}() - type.rpd_inform = rpd_inform_type() - return type - end end export clls_initialize_s function clls_initialize_s(data, control, status) @ccall libgalahad_single.clls_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{clls_control_type{Float32}}, + control::Ptr{clls_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -150,29 +124,29 @@ export clls_initialize function clls_initialize(data, control, status) @ccall libgalahad_double.clls_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{clls_control_type{Float64}}, + control::Ptr{clls_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export clls_read_specfile_s function clls_read_specfile_s(control, specfile) - @ccall libgalahad_single.clls_read_specfile_s(control::Ref{clls_control_type{Float32}}, + @ccall libgalahad_single.clls_read_specfile_s(control::Ptr{clls_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export clls_read_specfile function clls_read_specfile(control, specfile) - @ccall libgalahad_double.clls_read_specfile(control::Ref{clls_control_type{Float64}}, + @ccall libgalahad_double.clls_read_specfile(control::Ptr{clls_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export clls_import_s function clls_import_s(control, data, status, n, o, m, Ao_type, Ao_ne, Ao_row, Ao_col, - Ao_ptr_ne, Ao_ptr, A_type, A_ne, A_row, A_col, A_ptr_ne, A_ptr) - @ccall libgalahad_single.clls_import_s(control::Ref{clls_control_type{Float32}}, + Ao_ptr_ne, Ao_ptr, A_type, A_ne, A_row, A_col, A_ptr_ne, A_ptr) + @ccall libgalahad_single.clls_import_s(control::Ptr{clls_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, o::Cint, m::Cint, Ao_type::Ptr{Cchar}, Ao_ne::Cint, Ao_row::Ptr{Cint}, Ao_col::Ptr{Cint}, @@ -185,8 +159,8 @@ end export clls_import function clls_import(control, data, status, n, o, m, Ao_type, Ao_ne, Ao_row, Ao_col, - Ao_ptr_ne, Ao_ptr, A_type, A_ne, A_row, A_col, A_ptr_ne, A_ptr) - @ccall libgalahad_double.clls_import(control::Ref{clls_control_type{Float64}}, + Ao_ptr_ne, Ao_ptr, A_type, A_ne, A_row, A_col, A_ptr_ne, A_ptr) + @ccall libgalahad_double.clls_import(control::Ptr{clls_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, o::Cint, m::Cint, Ao_type::Ptr{Cchar}, Ao_ne::Cint, Ao_row::Ptr{Cint}, Ao_col::Ptr{Cint}, @@ -199,7 +173,7 @@ end export clls_reset_control_s function clls_reset_control_s(control, data, status) - @ccall libgalahad_single.clls_reset_control_s(control::Ref{clls_control_type{Float32}}, + @ccall libgalahad_single.clls_reset_control_s(control::Ptr{clls_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -207,7 +181,7 @@ end export clls_reset_control function clls_reset_control(control, data, status) - @ccall libgalahad_double.clls_reset_control(control::Ref{clls_control_type{Float64}}, + @ccall libgalahad_double.clls_reset_control(control::Ptr{clls_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -215,7 +189,8 @@ end export clls_solve_clls_s function clls_solve_clls_s(data, status, n, o, m, Ao_ne, Ao_val, b, regularization_weight, - A_ne, A_val, c_l, c_u, x_l, x_u, x, r, c, y, z, x_stat, c_stat, w) + A_ne, A_val, c_l, c_u, x_l, x_u, x, r, c, y, z, x_stat, c_stat, + w) @ccall libgalahad_single.clls_solve_clls_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, o::Cint, m::Cint, Ao_ne::Cint, Ao_val::Ptr{Float32}, b::Ptr{Float32}, @@ -232,7 +207,7 @@ end export clls_solve_clls function clls_solve_clls(data, status, n, o, m, Ao_ne, Ao_val, b, regularization_weight, - A_ne, A_val, c_l, c_u, x_l, x_u, x, r, c, y, z, x_stat, c_stat, w) + A_ne, A_val, c_l, c_u, x_l, x_u, x, r, c, y, z, x_stat, c_stat, w) @ccall libgalahad_double.clls_solve_clls(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, o::Cint, m::Cint, Ao_ne::Cint, Ao_val::Ptr{Float64}, b::Ptr{Float64}, @@ -250,7 +225,7 @@ export clls_information_s function clls_information_s(data, inform, status) @ccall libgalahad_single.clls_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{clls_inform_type{Float32}}, + inform::Ptr{clls_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -258,7 +233,7 @@ export clls_information function clls_information(data, inform, status) @ccall libgalahad_double.clls_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{clls_inform_type{Float64}}, + inform::Ptr{clls_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -266,14 +241,14 @@ export clls_terminate_s function clls_terminate_s(data, control, inform) @ccall libgalahad_single.clls_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{clls_control_type{Float32}}, - inform::Ref{clls_inform_type{Float32}})::Cvoid + control::Ptr{clls_control_type{Float32}}, + inform::Ptr{clls_inform_type{Float32}})::Cvoid end export clls_terminate function clls_terminate(data, control, inform) @ccall libgalahad_double.clls_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{clls_control_type{Float64}}, - inform::Ref{clls_inform_type{Float64}})::Cvoid + control::Ptr{clls_control_type{Float64}}, + inform::Ptr{clls_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/convert.jl b/GALAHAD.jl/src/wrappers/convert.jl index 4eac5378c5..a036be964f 100644 --- a/GALAHAD.jl/src/wrappers/convert.jl +++ b/GALAHAD.jl/src/wrappers/convert.jl @@ -1,6 +1,6 @@ export convert_control_type -mutable struct convert_control_type +struct convert_control_type f_indexing::Bool error::Cint out::Cint @@ -11,40 +11,30 @@ mutable struct convert_control_type space_critical::Bool deallocate_error_fatal::Bool prefix::NTuple{31,Cchar} - - convert_control_type() = new() end export convert_time_type -mutable struct convert_time_type{T} +struct convert_time_type{T} total::T clock_total::T - - convert_time_type{T}() where T = new() end export convert_inform_type -mutable struct convert_inform_type{T} +struct convert_inform_type{T} status::Cint alloc_status::Cint duplicates::Cint bad_alloc::NTuple{81,Cchar} time::convert_time_type{T} - - function convert_inform_type{T}() where T - type = new() - type.time = convert_time_type{T}() - return type - end end export convert_initialize_s function convert_initialize_s(data, control, status) @ccall libgalahad_single.convert_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{convert_control_type}, + control::Ptr{convert_control_type}, status::Ptr{Cint})::Cvoid end @@ -52,7 +42,7 @@ export convert_initialize function convert_initialize(data, control, status) @ccall libgalahad_double.convert_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{convert_control_type}, + control::Ptr{convert_control_type}, status::Ptr{Cint})::Cvoid end @@ -60,7 +50,7 @@ export convert_information_s function convert_information_s(data, inform, status) @ccall libgalahad_single.convert_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{convert_inform_type{Float32}}, + inform::Ptr{convert_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -68,7 +58,7 @@ export convert_information function convert_information(data, inform, status) @ccall libgalahad_double.convert_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{convert_inform_type{Float64}}, + inform::Ptr{convert_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -76,14 +66,14 @@ export convert_terminate_s function convert_terminate_s(data, control, inform) @ccall libgalahad_single.convert_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{convert_control_type}, - inform::Ref{convert_inform_type{Float32}})::Cvoid + control::Ptr{convert_control_type}, + inform::Ptr{convert_inform_type{Float32}})::Cvoid end export convert_terminate function convert_terminate(data, control, inform) @ccall libgalahad_double.convert_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{convert_control_type}, - inform::Ref{convert_inform_type{Float64}})::Cvoid + control::Ptr{convert_control_type}, + inform::Ptr{convert_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/cqp.jl b/GALAHAD.jl/src/wrappers/cqp.jl index 91d618ffe4..37f5a88659 100644 --- a/GALAHAD.jl/src/wrappers/cqp.jl +++ b/GALAHAD.jl/src/wrappers/cqp.jl @@ -1,6 +1,6 @@ export cqp_control_type -mutable struct cqp_control_type{T} +struct cqp_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -62,21 +62,11 @@ mutable struct cqp_control_type{T} fit_control::fit_control_type roots_control::roots_control_type{T} cro_control::cro_control_type{T} - - function cqp_control_type{T}() where T - type = new() - type.fdc_control = fdc_control_type{T}() - type.sbls_control = sbls_control_type{T}() - type.fit_control = fit_control_type() - type.roots_control = roots_control_type{T}() - type.cro_control = cro_control_type{T}() - return type - end end export cqp_time_type -mutable struct cqp_time_type{T} +struct cqp_time_type{T} total::T preprocess::T find_dependent::T @@ -89,13 +79,11 @@ mutable struct cqp_time_type{T} clock_analyse::T clock_factorize::T clock_solve::T - - cqp_time_type{T}() where T = new() end export cqp_inform_type -mutable struct cqp_inform_type{T} +struct cqp_inform_type{T} status::Cint alloc_status::Cint bad_alloc::NTuple{81,Cchar} @@ -125,25 +113,13 @@ mutable struct cqp_inform_type{T} roots_inform::roots_inform_type cro_inform::cro_inform_type{T} rpd_inform::rpd_inform_type - - function cqp_inform_type{T}() where T - type = new() - type.time = cqp_time_type{T}() - type.fdc_inform = fdc_inform_type{T}() - type.sbls_inform = sbls_inform_type{T}() - type.fit_inform = fit_inform_type() - type.roots_inform = roots_inform_type() - type.cro_inform = cro_inform_type{T}() - type.rpd_inform = rpd_inform_type() - return type - end end export cqp_initialize_s function cqp_initialize_s(data, control, status) @ccall libgalahad_single.cqp_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{cqp_control_type{Float32}}, + control::Ptr{cqp_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -151,29 +127,29 @@ export cqp_initialize function cqp_initialize(data, control, status) @ccall libgalahad_double.cqp_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{cqp_control_type{Float64}}, + control::Ptr{cqp_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export cqp_read_specfile_s function cqp_read_specfile_s(control, specfile) - @ccall libgalahad_single.cqp_read_specfile_s(control::Ref{cqp_control_type{Float32}}, + @ccall libgalahad_single.cqp_read_specfile_s(control::Ptr{cqp_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export cqp_read_specfile function cqp_read_specfile(control, specfile) - @ccall libgalahad_double.cqp_read_specfile(control::Ref{cqp_control_type{Float64}}, + @ccall libgalahad_double.cqp_read_specfile(control::Ptr{cqp_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export cqp_import_s -function cqp_import_s(control, data, status, n, m, H_type, H_ne, H_row, H_col, H_ptr, A_type, - A_ne, A_row, A_col, A_ptr) - @ccall libgalahad_single.cqp_import_s(control::Ref{cqp_control_type{Float32}}, +function cqp_import_s(control, data, status, n, m, H_type, H_ne, H_row, H_col, H_ptr, + A_type, A_ne, A_row, A_col, A_ptr) + @ccall libgalahad_single.cqp_import_s(control::Ptr{cqp_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, H_type::Ptr{Cchar}, H_ne::Cint, H_row::Ptr{Cint}, H_col::Ptr{Cint}, @@ -185,20 +161,19 @@ end export cqp_import function cqp_import(control, data, status, n, m, H_type, H_ne, H_row, H_col, H_ptr, A_type, - A_ne, A_row, A_col, A_ptr) - @ccall libgalahad_double.cqp_import(control::Ref{cqp_control_type{Float64}}, + A_ne, A_row, A_col, A_ptr) + @ccall libgalahad_double.cqp_import(control::Ptr{cqp_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, H_type::Ptr{Cchar}, H_ne::Cint, - H_row::Ptr{Cint}, H_col::Ptr{Cint}, - H_ptr::Ptr{Cint}, A_type::Ptr{Cchar}, A_ne::Cint, - A_row::Ptr{Cint}, A_col::Ptr{Cint}, - A_ptr::Ptr{Cint})::Cvoid + H_row::Ptr{Cint}, H_col::Ptr{Cint}, H_ptr::Ptr{Cint}, + A_type::Ptr{Cchar}, A_ne::Cint, A_row::Ptr{Cint}, + A_col::Ptr{Cint}, A_ptr::Ptr{Cint})::Cvoid end export cqp_reset_control_s function cqp_reset_control_s(control, data, status) - @ccall libgalahad_single.cqp_reset_control_s(control::Ref{cqp_control_type{Float32}}, + @ccall libgalahad_single.cqp_reset_control_s(control::Ptr{cqp_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -206,7 +181,7 @@ end export cqp_reset_control function cqp_reset_control(control, data, status) - @ccall libgalahad_double.cqp_reset_control(control::Ref{cqp_control_type{Float64}}, + @ccall libgalahad_double.cqp_reset_control(control::Ptr{cqp_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -214,41 +189,39 @@ end export cqp_solve_qp_s function cqp_solve_qp_s(data, status, n, m, h_ne, H_val, g, f, a_ne, A_val, c_l, c_u, x_l, - x_u, x, c, y, z, x_stat, c_stat) + x_u, x, c, y, z, x_stat, c_stat) @ccall libgalahad_single.cqp_solve_qp_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, h_ne::Cint, H_val::Ptr{Float32}, g::Ptr{Float32}, f::Float32, a_ne::Cint, A_val::Ptr{Float32}, c_l::Ptr{Float32}, c_u::Ptr{Float32}, x_l::Ptr{Float32}, x_u::Ptr{Float32}, x::Ptr{Float32}, - c::Ptr{Float32}, y::Ptr{Float32}, - z::Ptr{Float32}, x_stat::Ptr{Cint}, - c_stat::Ptr{Cint})::Cvoid + c::Ptr{Float32}, y::Ptr{Float32}, z::Ptr{Float32}, + x_stat::Ptr{Cint}, c_stat::Ptr{Cint})::Cvoid end export cqp_solve_qp function cqp_solve_qp(data, status, n, m, h_ne, H_val, g, f, a_ne, A_val, c_l, c_u, x_l, - x_u, x, c, y, z, x_stat, c_stat) + x_u, x, c, y, z, x_stat, c_stat) @ccall libgalahad_double.cqp_solve_qp(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, h_ne::Cint, H_val::Ptr{Float64}, g::Ptr{Float64}, f::Float64, a_ne::Cint, A_val::Ptr{Float64}, c_l::Ptr{Float64}, c_u::Ptr{Float64}, x_l::Ptr{Float64}, - x_u::Ptr{Float64}, x::Ptr{Float64}, - c::Ptr{Float64}, y::Ptr{Float64}, - z::Ptr{Float64}, x_stat::Ptr{Cint}, + x_u::Ptr{Float64}, x::Ptr{Float64}, c::Ptr{Float64}, + y::Ptr{Float64}, z::Ptr{Float64}, x_stat::Ptr{Cint}, c_stat::Ptr{Cint})::Cvoid end export cqp_solve_sldqp_s function cqp_solve_sldqp_s(data, status, n, m, w, x0, g, f, a_ne, A_val, c_l, c_u, x_l, x_u, - x, c, y, z, x_stat, c_stat) + x, c, y, z, x_stat, c_stat) @ccall libgalahad_single.cqp_solve_sldqp_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, w::Ptr{Float32}, - x0::Ptr{Float32}, g::Ptr{Float32}, - f::Float32, a_ne::Cint, A_val::Ptr{Float32}, + x0::Ptr{Float32}, g::Ptr{Float32}, f::Float32, + a_ne::Cint, A_val::Ptr{Float32}, c_l::Ptr{Float32}, c_u::Ptr{Float32}, x_l::Ptr{Float32}, x_u::Ptr{Float32}, x::Ptr{Float32}, c::Ptr{Float32}, @@ -259,11 +232,11 @@ end export cqp_solve_sldqp function cqp_solve_sldqp(data, status, n, m, w, x0, g, f, a_ne, A_val, c_l, c_u, x_l, x_u, - x, c, y, z, x_stat, c_stat) + x, c, y, z, x_stat, c_stat) @ccall libgalahad_double.cqp_solve_sldqp(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, w::Ptr{Float64}, - x0::Ptr{Float64}, g::Ptr{Float64}, - f::Float64, a_ne::Cint, A_val::Ptr{Float64}, + x0::Ptr{Float64}, g::Ptr{Float64}, f::Float64, + a_ne::Cint, A_val::Ptr{Float64}, c_l::Ptr{Float64}, c_u::Ptr{Float64}, x_l::Ptr{Float64}, x_u::Ptr{Float64}, x::Ptr{Float64}, c::Ptr{Float64}, @@ -275,7 +248,7 @@ export cqp_information_s function cqp_information_s(data, inform, status) @ccall libgalahad_single.cqp_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{cqp_inform_type{Float32}}, + inform::Ptr{cqp_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -283,7 +256,7 @@ export cqp_information function cqp_information(data, inform, status) @ccall libgalahad_double.cqp_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{cqp_inform_type{Float64}}, + inform::Ptr{cqp_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -291,14 +264,14 @@ export cqp_terminate_s function cqp_terminate_s(data, control, inform) @ccall libgalahad_single.cqp_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{cqp_control_type{Float32}}, - inform::Ref{cqp_inform_type{Float32}})::Cvoid + control::Ptr{cqp_control_type{Float32}}, + inform::Ptr{cqp_inform_type{Float32}})::Cvoid end export cqp_terminate function cqp_terminate(data, control, inform) @ccall libgalahad_double.cqp_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{cqp_control_type{Float64}}, - inform::Ref{cqp_inform_type{Float64}})::Cvoid + control::Ptr{cqp_control_type{Float64}}, + inform::Ptr{cqp_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/cro.jl b/GALAHAD.jl/src/wrappers/cro.jl index a78c4a8307..e510535230 100644 --- a/GALAHAD.jl/src/wrappers/cro.jl +++ b/GALAHAD.jl/src/wrappers/cro.jl @@ -1,6 +1,6 @@ export cro_control_type -mutable struct cro_control_type{T} +struct cro_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -19,20 +19,11 @@ mutable struct cro_control_type{T} sbls_control::sbls_control_type{T} uls_control::uls_control_type{T} ir_control::ir_control_type{T} - - function cro_control_type{T}() where T - type = new() - type.sls_control = sls_control_type{T}() - type.sbls_control = sbls_control_type{T}() - type.uls_control = uls_control_type{T}() - type.ir_control = ir_control_type{T}() - return type - end end export cro_time_type -mutable struct cro_time_type{T} +struct cro_time_type{T} total::Float32 analyse::Float32 factorize::Float32 @@ -41,13 +32,11 @@ mutable struct cro_time_type{T} clock_analyse::T clock_factorize::T clock_solve::T - - cro_time_type{T}() where T = new() end export cro_inform_type -mutable struct cro_inform_type{T} +struct cro_inform_type{T} status::Cint alloc_status::Cint bad_alloc::NTuple{81,Cchar} @@ -59,24 +48,13 @@ mutable struct cro_inform_type{T} scu_status::Cint scu_inform::scu_inform_type ir_inform::ir_inform_type{T} - - function cro_inform_type{T}() where T - type = new() - type.time = cro_time_type{T}() - type.sls_inform = sls_inform_type{T}() - type.sbls_inform = sbls_inform_type{T}() - type.uls_inform = uls_inform_type{T}() - type.scu_inform = scu_inform_type() - type.ir_inform = ir_inform_type{T}() - return type - end end export cro_initialize_s function cro_initialize_s(data, control, status) @ccall libgalahad_single.cro_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{cro_control_type{Float32}}, + control::Ptr{cro_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -84,63 +62,63 @@ export cro_initialize function cro_initialize(data, control, status) @ccall libgalahad_double.cro_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{cro_control_type{Float64}}, + control::Ptr{cro_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export cro_read_specfile_s function cro_read_specfile_s(control, specfile) - @ccall libgalahad_single.cro_read_specfile_s(control::Ref{cro_control_type{Float32}}, + @ccall libgalahad_single.cro_read_specfile_s(control::Ptr{cro_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export cro_read_specfile function cro_read_specfile(control, specfile) - @ccall libgalahad_double.cro_read_specfile(control::Ref{cro_control_type{Float64}}, + @ccall libgalahad_double.cro_read_specfile(control::Ptr{cro_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export cro_crossover_solution_s function cro_crossover_solution_s(data, control, inform, n, m, m_equal, h_ne, H_val, H_col, - H_ptr, a_ne, A_val, A_col, A_ptr, g, c_l, c_u, x_l, x_u, x, - c, y, z, x_stat, c_stat) + H_ptr, a_ne, A_val, A_col, A_ptr, g, c_l, c_u, x_l, x_u, + x, c, y, z, x_stat, c_stat) @ccall libgalahad_single.cro_crossover_solution_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{cro_control_type{Float32}}, - inform::Ref{cro_inform_type{Float32}}, n::Cint, - m::Cint, m_equal::Cint, h_ne::Cint, - H_val::Ptr{Float32}, H_col::Ptr{Cint}, - H_ptr::Ptr{Cint}, a_ne::Cint, - A_val::Ptr{Float32}, A_col::Ptr{Cint}, - A_ptr::Ptr{Cint}, g::Ptr{Float32}, - c_l::Ptr{Float32}, c_u::Ptr{Float32}, - x_l::Ptr{Float32}, x_u::Ptr{Float32}, - x::Ptr{Float32}, c::Ptr{Float32}, - y::Ptr{Float32}, z::Ptr{Float32}, - x_stat::Ptr{Cint}, + control::Ptr{cro_control_type{Float32}}, + inform::Ptr{cro_inform_type{Float32}}, + n::Cint, m::Cint, m_equal::Cint, + h_ne::Cint, H_val::Ptr{Float32}, + H_col::Ptr{Cint}, H_ptr::Ptr{Cint}, + a_ne::Cint, A_val::Ptr{Float32}, + A_col::Ptr{Cint}, A_ptr::Ptr{Cint}, + g::Ptr{Float32}, c_l::Ptr{Float32}, + c_u::Ptr{Float32}, x_l::Ptr{Float32}, + x_u::Ptr{Float32}, x::Ptr{Float32}, + c::Ptr{Float32}, y::Ptr{Float32}, + z::Ptr{Float32}, x_stat::Ptr{Cint}, c_stat::Ptr{Cint})::Cvoid end export cro_crossover_solution function cro_crossover_solution(data, control, inform, n, m, m_equal, h_ne, H_val, H_col, - H_ptr, a_ne, A_val, A_col, A_ptr, g, c_l, c_u, x_l, x_u, x, - c, y, z, x_stat, c_stat) + H_ptr, a_ne, A_val, A_col, A_ptr, g, c_l, c_u, x_l, x_u, x, + c, y, z, x_stat, c_stat) @ccall libgalahad_double.cro_crossover_solution(data::Ptr{Ptr{Cvoid}}, - control::Ref{cro_control_type{Float64}}, - inform::Ref{cro_inform_type{Float64}}, n::Cint, - m::Cint, m_equal::Cint, h_ne::Cint, - H_val::Ptr{Float64}, H_col::Ptr{Cint}, - H_ptr::Ptr{Cint}, a_ne::Cint, - A_val::Ptr{Float64}, A_col::Ptr{Cint}, - A_ptr::Ptr{Cint}, g::Ptr{Float64}, - c_l::Ptr{Float64}, c_u::Ptr{Float64}, - x_l::Ptr{Float64}, x_u::Ptr{Float64}, - x::Ptr{Float64}, c::Ptr{Float64}, - y::Ptr{Float64}, z::Ptr{Float64}, - x_stat::Ptr{Cint}, + control::Ptr{cro_control_type{Float64}}, + inform::Ptr{cro_inform_type{Float64}}, + n::Cint, m::Cint, m_equal::Cint, + h_ne::Cint, H_val::Ptr{Float64}, + H_col::Ptr{Cint}, H_ptr::Ptr{Cint}, + a_ne::Cint, A_val::Ptr{Float64}, + A_col::Ptr{Cint}, A_ptr::Ptr{Cint}, + g::Ptr{Float64}, c_l::Ptr{Float64}, + c_u::Ptr{Float64}, x_l::Ptr{Float64}, + x_u::Ptr{Float64}, x::Ptr{Float64}, + c::Ptr{Float64}, y::Ptr{Float64}, + z::Ptr{Float64}, x_stat::Ptr{Cint}, c_stat::Ptr{Cint})::Cvoid end @@ -148,14 +126,14 @@ export cro_terminate_s function cro_terminate_s(data, control, inform) @ccall libgalahad_single.cro_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{cro_control_type{Float32}}, - inform::Ref{cro_inform_type{Float32}})::Cvoid + control::Ptr{cro_control_type{Float32}}, + inform::Ptr{cro_inform_type{Float32}})::Cvoid end export cro_terminate function cro_terminate(data, control, inform) @ccall libgalahad_double.cro_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{cro_control_type{Float64}}, - inform::Ref{cro_inform_type{Float64}})::Cvoid + control::Ptr{cro_control_type{Float64}}, + inform::Ptr{cro_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/dgo.jl b/GALAHAD.jl/src/wrappers/dgo.jl index 58ffa18298..d6118c46fc 100644 --- a/GALAHAD.jl/src/wrappers/dgo.jl +++ b/GALAHAD.jl/src/wrappers/dgo.jl @@ -1,6 +1,6 @@ export dgo_control_type -mutable struct dgo_control_type{T} +struct dgo_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -31,32 +31,22 @@ mutable struct dgo_control_type{T} hash_control::hash_control_type ugo_control::ugo_control_type{T} trb_control::trb_control_type{T} - - function dgo_control_type{T}() where T - type = new() - type.hash_control = hash_control_type() - type.ugo_control = ugo_control_type{T}() - type.trb_control = trb_control_type{T}() - return type - end end export dgo_time_type -mutable struct dgo_time_type{T} +struct dgo_time_type{T} total::Float32 univariate_global::Float32 multivariate_local::Float32 clock_total::T clock_univariate_global::T clock_multivariate_local::T - - dgo_time_type{T}() where T = new() end export dgo_inform_type -mutable struct dgo_inform_type{T} +struct dgo_inform_type{T} status::Cint alloc_status::Cint bad_alloc::NTuple{81,Cchar} @@ -73,22 +63,13 @@ mutable struct dgo_inform_type{T} hash_inform::hash_inform_type ugo_inform::ugo_inform_type{T} trb_inform::trb_inform_type{T} - - function dgo_inform_type{T}() where T - type = new() - type.time = dgo_time_type{T}() - type.hash_inform = hash_inform_type() - type.ugo_inform = ugo_inform_type{T}() - type.trb_inform = trb_inform_type{T}() - return type - end end export dgo_initialize_s function dgo_initialize_s(data, control, status) @ccall libgalahad_single.dgo_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{dgo_control_type{Float32}}, + control::Ptr{dgo_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -96,28 +77,28 @@ export dgo_initialize function dgo_initialize(data, control, status) @ccall libgalahad_double.dgo_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{dgo_control_type{Float64}}, + control::Ptr{dgo_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export dgo_read_specfile_s function dgo_read_specfile_s(control, specfile) - @ccall libgalahad_single.dgo_read_specfile_s(control::Ref{dgo_control_type{Float32}}, + @ccall libgalahad_single.dgo_read_specfile_s(control::Ptr{dgo_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export dgo_read_specfile function dgo_read_specfile(control, specfile) - @ccall libgalahad_double.dgo_read_specfile(control::Ref{dgo_control_type{Float64}}, + @ccall libgalahad_double.dgo_read_specfile(control::Ptr{dgo_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export dgo_import_s function dgo_import_s(control, data, status, n, x_l, x_u, H_type, ne, H_row, H_col, H_ptr) - @ccall libgalahad_single.dgo_import_s(control::Ref{dgo_control_type{Float32}}, + @ccall libgalahad_single.dgo_import_s(control::Ptr{dgo_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, x_l::Ptr{Float32}, x_u::Ptr{Float32}, H_type::Ptr{Cchar}, ne::Cint, H_row::Ptr{Cint}, @@ -127,7 +108,7 @@ end export dgo_import function dgo_import(control, data, status, n, x_l, x_u, H_type, ne, H_row, H_col, H_ptr) - @ccall libgalahad_double.dgo_import(control::Ref{dgo_control_type{Float64}}, + @ccall libgalahad_double.dgo_import(control::Ptr{dgo_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, x_l::Ptr{Float64}, x_u::Ptr{Float64}, H_type::Ptr{Cchar}, ne::Cint, H_row::Ptr{Cint}, @@ -137,7 +118,7 @@ end export dgo_reset_control_s function dgo_reset_control_s(control, data, status) - @ccall libgalahad_single.dgo_reset_control_s(control::Ref{dgo_control_type{Float32}}, + @ccall libgalahad_single.dgo_reset_control_s(control::Ptr{dgo_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -145,7 +126,7 @@ end export dgo_reset_control function dgo_reset_control(control, data, status) - @ccall libgalahad_double.dgo_reset_control(control::Ref{dgo_control_type{Float64}}, + @ccall libgalahad_double.dgo_reset_control(control::Ptr{dgo_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -153,24 +134,22 @@ end export dgo_solve_with_mat_s function dgo_solve_with_mat_s(data, userdata, status, n, x, g, ne, eval_f, eval_g, eval_h, - eval_hprod, eval_prec) + eval_hprod, eval_prec) @ccall libgalahad_single.dgo_solve_with_mat_s(data::Ptr{Ptr{Cvoid}}, userdata::Ptr{Cvoid}, - status::Ptr{Cint}, n::Cint, - x::Ptr{Float32}, g::Ptr{Float32}, - ne::Cint, eval_f::Ptr{Cvoid}, - eval_g::Ptr{Cvoid}, eval_h::Ptr{Cvoid}, - eval_hprod::Ptr{Cvoid}, + status::Ptr{Cint}, n::Cint, x::Ptr{Float32}, + g::Ptr{Float32}, ne::Cint, + eval_f::Ptr{Cvoid}, eval_g::Ptr{Cvoid}, + eval_h::Ptr{Cvoid}, eval_hprod::Ptr{Cvoid}, eval_prec::Ptr{Cvoid})::Cvoid end export dgo_solve_with_mat function dgo_solve_with_mat(data, userdata, status, n, x, g, ne, eval_f, eval_g, eval_h, - eval_hprod, eval_prec) + eval_hprod, eval_prec) @ccall libgalahad_double.dgo_solve_with_mat(data::Ptr{Ptr{Cvoid}}, userdata::Ptr{Cvoid}, - status::Ptr{Cint}, n::Cint, - x::Ptr{Float64}, g::Ptr{Float64}, - ne::Cint, eval_f::Ptr{Cvoid}, + status::Ptr{Cint}, n::Cint, x::Ptr{Float64}, + g::Ptr{Float64}, ne::Cint, eval_f::Ptr{Cvoid}, eval_g::Ptr{Cvoid}, eval_h::Ptr{Cvoid}, eval_hprod::Ptr{Cvoid}, eval_prec::Ptr{Cvoid})::Cvoid @@ -178,8 +157,8 @@ end export dgo_solve_without_mat_s -function dgo_solve_without_mat_s(data, userdata, status, n, x, g, eval_f, eval_g, eval_hprod, - eval_shprod, eval_prec) +function dgo_solve_without_mat_s(data, userdata, status, n, x, g, eval_f, eval_g, + eval_hprod, eval_shprod, eval_prec) @ccall libgalahad_single.dgo_solve_without_mat_s(data::Ptr{Ptr{Cvoid}}, userdata::Ptr{Cvoid}, status::Ptr{Cint}, n::Cint, x::Ptr{Float32}, @@ -193,12 +172,11 @@ end export dgo_solve_without_mat function dgo_solve_without_mat(data, userdata, status, n, x, g, eval_f, eval_g, eval_hprod, - eval_shprod, eval_prec) + eval_shprod, eval_prec) @ccall libgalahad_double.dgo_solve_without_mat(data::Ptr{Ptr{Cvoid}}, userdata::Ptr{Cvoid}, status::Ptr{Cint}, - n::Cint, x::Ptr{Float64}, - g::Ptr{Float64}, eval_f::Ptr{Cvoid}, - eval_g::Ptr{Cvoid}, + n::Cint, x::Ptr{Float64}, g::Ptr{Float64}, + eval_f::Ptr{Cvoid}, eval_g::Ptr{Cvoid}, eval_hprod::Ptr{Cvoid}, eval_shprod::Ptr{Cvoid}, eval_prec::Ptr{Cvoid})::Cvoid @@ -206,7 +184,8 @@ end export dgo_solve_reverse_with_mat_s -function dgo_solve_reverse_with_mat_s(data, status, eval_status, n, x, f, g, ne, H_val, u, v) +function dgo_solve_reverse_with_mat_s(data, status, eval_status, n, x, f, g, ne, H_val, u, + v) @ccall libgalahad_single.dgo_solve_reverse_with_mat_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, eval_status::Ptr{Cint}, n::Cint, @@ -225,21 +204,19 @@ function dgo_solve_reverse_with_mat(data, status, eval_status, n, x, f, g, ne, H eval_status::Ptr{Cint}, n::Cint, x::Ptr{Float64}, f::Float64, g::Ptr{Float64}, ne::Cint, - H_val::Ptr{Float64}, - u::Ptr{Float64}, + H_val::Ptr{Float64}, u::Ptr{Float64}, v::Ptr{Float64})::Cvoid end export dgo_solve_reverse_without_mat_s function dgo_solve_reverse_without_mat_s(data, status, eval_status, n, x, f, g, u, v, - index_nz_v, nnz_v, index_nz_u, nnz_u) + index_nz_v, nnz_v, index_nz_u, nnz_u) @ccall libgalahad_single.dgo_solve_reverse_without_mat_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, eval_status::Ptr{Cint}, n::Cint, x::Ptr{Float32}, f::Float32, - g::Ptr{Float32}, - u::Ptr{Float32}, + g::Ptr{Float32}, u::Ptr{Float32}, v::Ptr{Float32}, index_nz_v::Ptr{Cint}, nnz_v::Ptr{Cint}, @@ -250,13 +227,12 @@ end export dgo_solve_reverse_without_mat function dgo_solve_reverse_without_mat(data, status, eval_status, n, x, f, g, u, v, - index_nz_v, nnz_v, index_nz_u, nnz_u) + index_nz_v, nnz_v, index_nz_u, nnz_u) @ccall libgalahad_double.dgo_solve_reverse_without_mat(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, eval_status::Ptr{Cint}, n::Cint, x::Ptr{Float64}, f::Float64, - g::Ptr{Float64}, - u::Ptr{Float64}, + g::Ptr{Float64}, u::Ptr{Float64}, v::Ptr{Float64}, index_nz_v::Ptr{Cint}, nnz_v::Ptr{Cint}, @@ -268,7 +244,7 @@ export dgo_information_s function dgo_information_s(data, inform, status) @ccall libgalahad_single.dgo_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{dgo_inform_type{Float32}}, + inform::Ptr{dgo_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -276,7 +252,7 @@ export dgo_information function dgo_information(data, inform, status) @ccall libgalahad_double.dgo_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{dgo_inform_type{Float64}}, + inform::Ptr{dgo_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -284,14 +260,14 @@ export dgo_terminate_s function dgo_terminate_s(data, control, inform) @ccall libgalahad_single.dgo_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{dgo_control_type{Float32}}, - inform::Ref{dgo_inform_type{Float32}})::Cvoid + control::Ptr{dgo_control_type{Float32}}, + inform::Ptr{dgo_inform_type{Float32}})::Cvoid end export dgo_terminate function dgo_terminate(data, control, inform) @ccall libgalahad_double.dgo_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{dgo_control_type{Float64}}, - inform::Ref{dgo_inform_type{Float64}})::Cvoid + control::Ptr{dgo_control_type{Float64}}, + inform::Ptr{dgo_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/dps.jl b/GALAHAD.jl/src/wrappers/dps.jl index cf6d10575f..22bcca2106 100644 --- a/GALAHAD.jl/src/wrappers/dps.jl +++ b/GALAHAD.jl/src/wrappers/dps.jl @@ -1,6 +1,6 @@ export dps_control_type -mutable struct dps_control_type{T} +struct dps_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -20,17 +20,11 @@ mutable struct dps_control_type{T} symmetric_linear_solver::NTuple{31,Cchar} prefix::NTuple{31,Cchar} sls_control::sls_control_type{T} - - function dps_control_type{T}() where T - type = new() - type.sls_control = sls_control_type{T}() - return type - end end export dps_time_type -mutable struct dps_time_type{T} +struct dps_time_type{T} total::T analyse::T factorize::T @@ -39,13 +33,11 @@ mutable struct dps_time_type{T} clock_analyse::T clock_factorize::T clock_solve::T - - dps_time_type{T}() where T = new() end export dps_inform_type -mutable struct dps_inform_type{T} +struct dps_inform_type{T} status::Cint alloc_status::Cint mod_1by1::Cint @@ -59,20 +51,13 @@ mutable struct dps_inform_type{T} bad_alloc::NTuple{81,Cchar} time::dps_time_type{T} sls_inform::sls_inform_type{T} - - function dps_inform_type{T}() where T - type = new() - type.time = dps_time_type{T}() - type.sls_inform = sls_inform_type{T}() - return type - end end export dps_initialize_s function dps_initialize_s(data, control, status) @ccall libgalahad_single.dps_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{dps_control_type{Float32}}, + control::Ptr{dps_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -80,28 +65,28 @@ export dps_initialize function dps_initialize(data, control, status) @ccall libgalahad_double.dps_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{dps_control_type{Float64}}, + control::Ptr{dps_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export dps_read_specfile_s function dps_read_specfile_s(control, specfile) - @ccall libgalahad_single.dps_read_specfile_s(control::Ref{dps_control_type{Float32}}, + @ccall libgalahad_single.dps_read_specfile_s(control::Ptr{dps_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export dps_read_specfile function dps_read_specfile(control, specfile) - @ccall libgalahad_double.dps_read_specfile(control::Ref{dps_control_type{Float64}}, + @ccall libgalahad_double.dps_read_specfile(control::Ptr{dps_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export dps_import_s function dps_import_s(control, data, status, n, H_type, ne, H_row, H_col, H_ptr) - @ccall libgalahad_single.dps_import_s(control::Ref{dps_control_type{Float32}}, + @ccall libgalahad_single.dps_import_s(control::Ptr{dps_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, H_type::Ptr{Cchar}, ne::Cint, H_row::Ptr{Cint}, H_col::Ptr{Cint}, H_ptr::Ptr{Cint})::Cvoid @@ -110,7 +95,7 @@ end export dps_import function dps_import(control, data, status, n, H_type, ne, H_row, H_col, H_ptr) - @ccall libgalahad_double.dps_import(control::Ref{dps_control_type{Float64}}, + @ccall libgalahad_double.dps_import(control::Ptr{dps_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, H_type::Ptr{Cchar}, ne::Cint, H_row::Ptr{Cint}, H_col::Ptr{Cint}, H_ptr::Ptr{Cint})::Cvoid @@ -119,7 +104,7 @@ end export dps_reset_control_s function dps_reset_control_s(control, data, status) - @ccall libgalahad_single.dps_reset_control_s(control::Ref{dps_control_type{Float32}}, + @ccall libgalahad_single.dps_reset_control_s(control::Ptr{dps_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -127,7 +112,7 @@ end export dps_reset_control function dps_reset_control(control, data, status) - @ccall libgalahad_double.dps_reset_control(control::Ref{dps_control_type{Float64}}, + @ccall libgalahad_double.dps_reset_control(control::Ptr{dps_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -165,9 +150,8 @@ export dps_solve_rq_problem function dps_solve_rq_problem(data, status, n, ne, H_val, c, f, power, weight, x) @ccall libgalahad_double.dps_solve_rq_problem(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, ne::Cint, H_val::Ptr{Float64}, - c::Ptr{Float64}, f::Float64, - power::Float64, weight::Float64, - x::Ptr{Float64})::Cvoid + c::Ptr{Float64}, f::Float64, power::Float64, + weight::Float64, x::Ptr{Float64})::Cvoid end export dps_resolve_tr_problem_s @@ -176,18 +160,15 @@ function dps_resolve_tr_problem_s(data, status, n, c, f, radius, x) @ccall libgalahad_single.dps_resolve_tr_problem_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, c::Ptr{Float32}, f::Float32, - radius::Float32, - x::Ptr{Float32})::Cvoid + radius::Float32, x::Ptr{Float32})::Cvoid end export dps_resolve_tr_problem function dps_resolve_tr_problem(data, status, n, c, f, radius, x) - @ccall libgalahad_double.dps_resolve_tr_problem(data::Ptr{Ptr{Cvoid}}, - status::Ptr{Cint}, n::Cint, - c::Ptr{Float64}, f::Float64, - radius::Float64, - x::Ptr{Float64})::Cvoid + @ccall libgalahad_double.dps_resolve_tr_problem(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, + n::Cint, c::Ptr{Float64}, f::Float64, + radius::Float64, x::Ptr{Float64})::Cvoid end export dps_resolve_rq_problem_s @@ -203,9 +184,8 @@ end export dps_resolve_rq_problem function dps_resolve_rq_problem(data, status, n, c, f, power, weight, x) - @ccall libgalahad_double.dps_resolve_rq_problem(data::Ptr{Ptr{Cvoid}}, - status::Ptr{Cint}, n::Cint, - c::Ptr{Float64}, f::Float64, + @ccall libgalahad_double.dps_resolve_rq_problem(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, + n::Cint, c::Ptr{Float64}, f::Float64, power::Float64, weight::Float64, x::Ptr{Float64})::Cvoid end @@ -214,7 +194,7 @@ export dps_information_s function dps_information_s(data, inform, status) @ccall libgalahad_single.dps_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{dps_inform_type{Float32}}, + inform::Ptr{dps_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -222,7 +202,7 @@ export dps_information function dps_information(data, inform, status) @ccall libgalahad_double.dps_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{dps_inform_type{Float64}}, + inform::Ptr{dps_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -230,14 +210,14 @@ export dps_terminate_s function dps_terminate_s(data, control, inform) @ccall libgalahad_single.dps_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{dps_control_type{Float32}}, - inform::Ref{dps_inform_type{Float32}})::Cvoid + control::Ptr{dps_control_type{Float32}}, + inform::Ptr{dps_inform_type{Float32}})::Cvoid end export dps_terminate function dps_terminate(data, control, inform) @ccall libgalahad_double.dps_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{dps_control_type{Float64}}, - inform::Ref{dps_inform_type{Float64}})::Cvoid + control::Ptr{dps_control_type{Float64}}, + inform::Ptr{dps_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/dqp.jl b/GALAHAD.jl/src/wrappers/dqp.jl index c4b1df7760..8db04e9e5c 100644 --- a/GALAHAD.jl/src/wrappers/dqp.jl +++ b/GALAHAD.jl/src/wrappers/dqp.jl @@ -1,6 +1,6 @@ export dqp_control_type -mutable struct dqp_control_type{T} +struct dqp_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -57,20 +57,11 @@ mutable struct dqp_control_type{T} sls_control::sls_control_type{T} sbls_control::sbls_control_type{T} gltr_control::gltr_control_type{T} - - function dqp_control_type{T}() where T - type = new() - type.fdc_control = fdc_control_type{T}() - type.sls_control = sls_control_type{T}() - type.sbls_control = sbls_control_type{T}() - type.gltr_control = gltr_control_type{T}() - return type - end end export dqp_time_type -mutable struct dqp_time_type{T} +struct dqp_time_type{T} total::T preprocess::T find_dependent::T @@ -85,13 +76,11 @@ mutable struct dqp_time_type{T} clock_factorize::T clock_solve::T clock_search::T - - dqp_time_type{T}() where T = new() end export dqp_inform_type -mutable struct dqp_inform_type{T} +struct dqp_inform_type{T} status::Cint alloc_status::Cint bad_alloc::NTuple{81,Cchar} @@ -118,25 +107,13 @@ mutable struct dqp_inform_type{T} scu_status::Cint scu_inform::scu_inform_type rpd_inform::rpd_inform_type - - function dqp_inform_type{T}() where T - type = new() - type.time = dqp_time_type{T}() - type.fdc_inform = fdc_inform_type{T}() - type.sls_inform = sls_inform_type{T}() - type.sbls_inform = sbls_inform_type{T}() - type.gltr_inform = gltr_inform_type{T}() - type.scu_inform = scu_inform_type() - type.rpd_inform = rpd_inform_type() - return type - end end export dqp_initialize_s function dqp_initialize_s(data, control, status) @ccall libgalahad_single.dqp_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{dqp_control_type{Float32}}, + control::Ptr{dqp_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -144,29 +121,29 @@ export dqp_initialize function dqp_initialize(data, control, status) @ccall libgalahad_double.dqp_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{dqp_control_type{Float64}}, + control::Ptr{dqp_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export dqp_read_specfile_s function dqp_read_specfile_s(control, specfile) - @ccall libgalahad_single.dqp_read_specfile_s(control::Ref{dqp_control_type{Float32}}, + @ccall libgalahad_single.dqp_read_specfile_s(control::Ptr{dqp_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export dqp_read_specfile function dqp_read_specfile(control, specfile) - @ccall libgalahad_double.dqp_read_specfile(control::Ref{dqp_control_type{Float64}}, + @ccall libgalahad_double.dqp_read_specfile(control::Ptr{dqp_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export dqp_import_s -function dqp_import_s(control, data, status, n, m, H_type, H_ne, H_row, H_col, H_ptr, A_type, - A_ne, A_row, A_col, A_ptr) - @ccall libgalahad_single.dqp_import_s(control::Ref{dqp_control_type{Float32}}, +function dqp_import_s(control, data, status, n, m, H_type, H_ne, H_row, H_col, H_ptr, + A_type, A_ne, A_row, A_col, A_ptr) + @ccall libgalahad_single.dqp_import_s(control::Ptr{dqp_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, H_type::Ptr{Cchar}, H_ne::Cint, H_row::Ptr{Cint}, H_col::Ptr{Cint}, @@ -178,20 +155,19 @@ end export dqp_import function dqp_import(control, data, status, n, m, H_type, H_ne, H_row, H_col, H_ptr, A_type, - A_ne, A_row, A_col, A_ptr) - @ccall libgalahad_double.dqp_import(control::Ref{dqp_control_type{Float64}}, + A_ne, A_row, A_col, A_ptr) + @ccall libgalahad_double.dqp_import(control::Ptr{dqp_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, H_type::Ptr{Cchar}, H_ne::Cint, - H_row::Ptr{Cint}, H_col::Ptr{Cint}, - H_ptr::Ptr{Cint}, A_type::Ptr{Cchar}, A_ne::Cint, - A_row::Ptr{Cint}, A_col::Ptr{Cint}, - A_ptr::Ptr{Cint})::Cvoid + H_row::Ptr{Cint}, H_col::Ptr{Cint}, H_ptr::Ptr{Cint}, + A_type::Ptr{Cchar}, A_ne::Cint, A_row::Ptr{Cint}, + A_col::Ptr{Cint}, A_ptr::Ptr{Cint})::Cvoid end export dqp_reset_control_s function dqp_reset_control_s(control, data, status) - @ccall libgalahad_single.dqp_reset_control_s(control::Ref{dqp_control_type{Float32}}, + @ccall libgalahad_single.dqp_reset_control_s(control::Ptr{dqp_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -199,7 +175,7 @@ end export dqp_reset_control function dqp_reset_control(control, data, status) - @ccall libgalahad_double.dqp_reset_control(control::Ref{dqp_control_type{Float64}}, + @ccall libgalahad_double.dqp_reset_control(control::Ptr{dqp_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -207,41 +183,39 @@ end export dqp_solve_qp_s function dqp_solve_qp_s(data, status, n, m, h_ne, H_val, g, f, a_ne, A_val, c_l, c_u, x_l, - x_u, x, c, y, z, x_stat, c_stat) + x_u, x, c, y, z, x_stat, c_stat) @ccall libgalahad_single.dqp_solve_qp_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, h_ne::Cint, H_val::Ptr{Float32}, g::Ptr{Float32}, f::Float32, a_ne::Cint, A_val::Ptr{Float32}, c_l::Ptr{Float32}, c_u::Ptr{Float32}, x_l::Ptr{Float32}, x_u::Ptr{Float32}, x::Ptr{Float32}, - c::Ptr{Float32}, y::Ptr{Float32}, - z::Ptr{Float32}, x_stat::Ptr{Cint}, - c_stat::Ptr{Cint})::Cvoid + c::Ptr{Float32}, y::Ptr{Float32}, z::Ptr{Float32}, + x_stat::Ptr{Cint}, c_stat::Ptr{Cint})::Cvoid end export dqp_solve_qp function dqp_solve_qp(data, status, n, m, h_ne, H_val, g, f, a_ne, A_val, c_l, c_u, x_l, - x_u, x, c, y, z, x_stat, c_stat) + x_u, x, c, y, z, x_stat, c_stat) @ccall libgalahad_double.dqp_solve_qp(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, h_ne::Cint, H_val::Ptr{Float64}, g::Ptr{Float64}, f::Float64, a_ne::Cint, A_val::Ptr{Float64}, c_l::Ptr{Float64}, c_u::Ptr{Float64}, x_l::Ptr{Float64}, - x_u::Ptr{Float64}, x::Ptr{Float64}, - c::Ptr{Float64}, y::Ptr{Float64}, - z::Ptr{Float64}, x_stat::Ptr{Cint}, + x_u::Ptr{Float64}, x::Ptr{Float64}, c::Ptr{Float64}, + y::Ptr{Float64}, z::Ptr{Float64}, x_stat::Ptr{Cint}, c_stat::Ptr{Cint})::Cvoid end export dqp_solve_sldqp_s function dqp_solve_sldqp_s(data, status, n, m, w, x0, g, f, a_ne, A_val, c_l, c_u, x_l, x_u, - x, c, y, z, x_stat, c_stat) + x, c, y, z, x_stat, c_stat) @ccall libgalahad_single.dqp_solve_sldqp_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, w::Ptr{Float32}, - x0::Ptr{Float32}, g::Ptr{Float32}, - f::Float32, a_ne::Cint, A_val::Ptr{Float32}, + x0::Ptr{Float32}, g::Ptr{Float32}, f::Float32, + a_ne::Cint, A_val::Ptr{Float32}, c_l::Ptr{Float32}, c_u::Ptr{Float32}, x_l::Ptr{Float32}, x_u::Ptr{Float32}, x::Ptr{Float32}, c::Ptr{Float32}, @@ -252,11 +226,11 @@ end export dqp_solve_sldqp function dqp_solve_sldqp(data, status, n, m, w, x0, g, f, a_ne, A_val, c_l, c_u, x_l, x_u, - x, c, y, z, x_stat, c_stat) + x, c, y, z, x_stat, c_stat) @ccall libgalahad_double.dqp_solve_sldqp(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, w::Ptr{Float64}, - x0::Ptr{Float64}, g::Ptr{Float64}, - f::Float64, a_ne::Cint, A_val::Ptr{Float64}, + x0::Ptr{Float64}, g::Ptr{Float64}, f::Float64, + a_ne::Cint, A_val::Ptr{Float64}, c_l::Ptr{Float64}, c_u::Ptr{Float64}, x_l::Ptr{Float64}, x_u::Ptr{Float64}, x::Ptr{Float64}, c::Ptr{Float64}, @@ -268,7 +242,7 @@ export dqp_information_s function dqp_information_s(data, inform, status) @ccall libgalahad_single.dqp_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{dqp_inform_type{Float32}}, + inform::Ptr{dqp_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -276,7 +250,7 @@ export dqp_information function dqp_information(data, inform, status) @ccall libgalahad_double.dqp_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{dqp_inform_type{Float64}}, + inform::Ptr{dqp_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -284,14 +258,14 @@ export dqp_terminate_s function dqp_terminate_s(data, control, inform) @ccall libgalahad_single.dqp_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{dqp_control_type{Float32}}, - inform::Ref{dqp_inform_type{Float32}})::Cvoid + control::Ptr{dqp_control_type{Float32}}, + inform::Ptr{dqp_inform_type{Float32}})::Cvoid end export dqp_terminate function dqp_terminate(data, control, inform) @ccall libgalahad_double.dqp_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{dqp_control_type{Float64}}, - inform::Ref{dqp_inform_type{Float64}})::Cvoid + control::Ptr{dqp_control_type{Float64}}, + inform::Ptr{dqp_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/eqp.jl b/GALAHAD.jl/src/wrappers/eqp.jl index 167dac052b..3f1633689f 100644 --- a/GALAHAD.jl/src/wrappers/eqp.jl +++ b/GALAHAD.jl/src/wrappers/eqp.jl @@ -1,6 +1,6 @@ export eqp_control_type -mutable struct eqp_control_type{T} +struct eqp_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -38,19 +38,11 @@ mutable struct eqp_control_type{T} fdc_control::fdc_control_type{T} sbls_control::sbls_control_type{T} gltr_control::gltr_control_type{T} - - function eqp_control_type{T}() where T - type = new() - type.fdc_control = fdc_control_type{T}() - type.sbls_control = sbls_control_type{T}() - type.gltr_control = gltr_control_type{T}() - return type - end end export eqp_time_type -mutable struct eqp_time_type{T} +struct eqp_time_type{T} total::T find_dependent::T factorize::T @@ -60,13 +52,11 @@ mutable struct eqp_time_type{T} clock_find_dependent::T clock_factorize::T clock_solve::T - - eqp_time_type{T}() where T = new() end export eqp_inform_type -mutable struct eqp_inform_type{T} +struct eqp_inform_type{T} status::Cint alloc_status::Cint bad_alloc::NTuple{81,Cchar} @@ -79,22 +69,13 @@ mutable struct eqp_inform_type{T} fdc_inform::fdc_inform_type{T} sbls_inform::sbls_inform_type{T} gltr_inform::gltr_inform_type{T} - - function eqp_inform_type{T}() where T - type = new() - type.time = eqp_time_type{T}() - type.fdc_inform = fdc_inform_type{T}() - type.sbls_inform = sbls_inform_type{T}() - type.gltr_inform = gltr_inform_type{T}() - return type - end end export eqp_initialize_s function eqp_initialize_s(data, control, status) @ccall libgalahad_single.eqp_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{eqp_control_type{Float32}}, + control::Ptr{eqp_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -102,29 +83,29 @@ export eqp_initialize function eqp_initialize(data, control, status) @ccall libgalahad_double.eqp_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{eqp_control_type{Float64}}, + control::Ptr{eqp_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export eqp_read_specfile_s function eqp_read_specfile_s(control, specfile) - @ccall libgalahad_single.eqp_read_specfile_s(control::Ref{eqp_control_type{Float32}}, + @ccall libgalahad_single.eqp_read_specfile_s(control::Ptr{eqp_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export eqp_read_specfile function eqp_read_specfile(control, specfile) - @ccall libgalahad_double.eqp_read_specfile(control::Ref{eqp_control_type{Float64}}, + @ccall libgalahad_double.eqp_read_specfile(control::Ptr{eqp_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export eqp_import_s -function eqp_import_s(control, data, status, n, m, H_type, H_ne, H_row, H_col, H_ptr, A_type, - A_ne, A_row, A_col, A_ptr) - @ccall libgalahad_single.eqp_import_s(control::Ref{eqp_control_type{Float32}}, +function eqp_import_s(control, data, status, n, m, H_type, H_ne, H_row, H_col, H_ptr, + A_type, A_ne, A_row, A_col, A_ptr) + @ccall libgalahad_single.eqp_import_s(control::Ptr{eqp_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, H_type::Ptr{Cchar}, H_ne::Cint, H_row::Ptr{Cint}, H_col::Ptr{Cint}, @@ -136,20 +117,19 @@ end export eqp_import function eqp_import(control, data, status, n, m, H_type, H_ne, H_row, H_col, H_ptr, A_type, - A_ne, A_row, A_col, A_ptr) - @ccall libgalahad_double.eqp_import(control::Ref{eqp_control_type{Float64}}, + A_ne, A_row, A_col, A_ptr) + @ccall libgalahad_double.eqp_import(control::Ptr{eqp_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, H_type::Ptr{Cchar}, H_ne::Cint, - H_row::Ptr{Cint}, H_col::Ptr{Cint}, - H_ptr::Ptr{Cint}, A_type::Ptr{Cchar}, A_ne::Cint, - A_row::Ptr{Cint}, A_col::Ptr{Cint}, - A_ptr::Ptr{Cint})::Cvoid + H_row::Ptr{Cint}, H_col::Ptr{Cint}, H_ptr::Ptr{Cint}, + A_type::Ptr{Cchar}, A_ne::Cint, A_row::Ptr{Cint}, + A_col::Ptr{Cint}, A_ptr::Ptr{Cint})::Cvoid end export eqp_reset_control_s function eqp_reset_control_s(control, data, status) - @ccall libgalahad_single.eqp_reset_control_s(control::Ref{eqp_control_type{Float32}}, + @ccall libgalahad_single.eqp_reset_control_s(control::Ptr{eqp_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -157,7 +137,7 @@ end export eqp_reset_control function eqp_reset_control(control, data, status) - @ccall libgalahad_double.eqp_reset_control(control::Ref{eqp_control_type{Float64}}, + @ccall libgalahad_double.eqp_reset_control(control::Ptr{eqp_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -187,8 +167,8 @@ export eqp_solve_sldqp_s function eqp_solve_sldqp_s(data, status, n, m, w, x0, g, f, a_ne, A_val, c, x, y) @ccall libgalahad_single.eqp_solve_sldqp_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, w::Ptr{Float32}, - x0::Ptr{Float32}, g::Ptr{Float32}, - f::Float32, a_ne::Cint, A_val::Ptr{Float32}, + x0::Ptr{Float32}, g::Ptr{Float32}, f::Float32, + a_ne::Cint, A_val::Ptr{Float32}, c::Ptr{Float32}, x::Ptr{Float32}, y::Ptr{Float32})::Cvoid end @@ -198,10 +178,9 @@ export eqp_solve_sldqp function eqp_solve_sldqp(data, status, n, m, w, x0, g, f, a_ne, A_val, c, x, y) @ccall libgalahad_double.eqp_solve_sldqp(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, w::Ptr{Float64}, - x0::Ptr{Float64}, g::Ptr{Float64}, - f::Float64, a_ne::Cint, A_val::Ptr{Float64}, - c::Ptr{Float64}, x::Ptr{Float64}, - y::Ptr{Float64})::Cvoid + x0::Ptr{Float64}, g::Ptr{Float64}, f::Float64, + a_ne::Cint, A_val::Ptr{Float64}, c::Ptr{Float64}, + x::Ptr{Float64}, y::Ptr{Float64})::Cvoid end export eqp_resolve_qp_s @@ -216,8 +195,8 @@ end export eqp_resolve_qp function eqp_resolve_qp(data, status, n, m, g, f, c, x, y) - @ccall libgalahad_double.eqp_resolve_qp(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, - n::Cint, m::Cint, g::Ptr{Float64}, f::Float64, + @ccall libgalahad_double.eqp_resolve_qp(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, + m::Cint, g::Ptr{Float64}, f::Float64, c::Ptr{Float64}, x::Ptr{Float64}, y::Ptr{Float64})::Cvoid end @@ -226,7 +205,7 @@ export eqp_information_s function eqp_information_s(data, inform, status) @ccall libgalahad_single.eqp_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{eqp_inform_type{Float32}}, + inform::Ptr{eqp_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -234,7 +213,7 @@ export eqp_information function eqp_information(data, inform, status) @ccall libgalahad_double.eqp_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{eqp_inform_type{Float64}}, + inform::Ptr{eqp_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -242,14 +221,14 @@ export eqp_terminate_s function eqp_terminate_s(data, control, inform) @ccall libgalahad_single.eqp_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{eqp_control_type{Float32}}, - inform::Ref{eqp_inform_type{Float32}})::Cvoid + control::Ptr{eqp_control_type{Float32}}, + inform::Ptr{eqp_inform_type{Float32}})::Cvoid end export eqp_terminate function eqp_terminate(data, control, inform) @ccall libgalahad_double.eqp_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{eqp_control_type{Float64}}, - inform::Ref{eqp_inform_type{Float64}})::Cvoid + control::Ptr{eqp_control_type{Float64}}, + inform::Ptr{eqp_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/fdc.jl b/GALAHAD.jl/src/wrappers/fdc.jl index aec6e6a7ac..4fa4b43710 100644 --- a/GALAHAD.jl/src/wrappers/fdc.jl +++ b/GALAHAD.jl/src/wrappers/fdc.jl @@ -1,6 +1,6 @@ export fdc_control_type -mutable struct fdc_control_type{T} +struct fdc_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -19,31 +19,22 @@ mutable struct fdc_control_type{T} prefix::NTuple{31,Cchar} sls_control::sls_control_type{T} uls_control::uls_control_type{T} - - function fdc_control_type{T}() where T - type = new() - type.sls_control = sls_control_type{T}() - type.uls_control = uls_control_type{T}() - return type - end end export fdc_time_type -mutable struct fdc_time_type{T} +struct fdc_time_type{T} total::T analyse::T factorize::T clock_total::T clock_analyse::T clock_factorize::T - - fdc_time_type{T}() where T = new() end export fdc_inform_type -mutable struct fdc_inform_type{T} +struct fdc_inform_type{T} status::Cint alloc_status::Cint bad_alloc::NTuple{81,Cchar} @@ -54,21 +45,13 @@ mutable struct fdc_inform_type{T} time::fdc_time_type{T} sls_inform::sls_inform_type{T} uls_inform::uls_inform_type{T} - - function fdc_inform_type{T}() where T - type = new() - type.time = fdc_time_type{T}() - type.sls_inform = sls_inform_type{T}() - type.uls_inform = uls_inform_type{T}() - return type - end end export fdc_initialize_s function fdc_initialize_s(data, control, status) @ccall libgalahad_single.fdc_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{fdc_control_type{Float32}}, + control::Ptr{fdc_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -76,31 +59,31 @@ export fdc_initialize function fdc_initialize(data, control, status) @ccall libgalahad_double.fdc_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{fdc_control_type{Float64}}, + control::Ptr{fdc_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export fdc_read_specfile_s function fdc_read_specfile_s(control, specfile) - @ccall libgalahad_single.fdc_read_specfile_s(control::Ref{fdc_control_type{Float32}}, + @ccall libgalahad_single.fdc_read_specfile_s(control::Ptr{fdc_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export fdc_read_specfile function fdc_read_specfile(control, specfile) - @ccall libgalahad_double.fdc_read_specfile(control::Ref{fdc_control_type{Float64}}, + @ccall libgalahad_double.fdc_read_specfile(control::Ptr{fdc_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export fdc_find_dependent_rows_s function fdc_find_dependent_rows_s(control, data, inform, status, m, n, A_ne, A_col, A_ptr, - A_val, b, n_depen, depen) - @ccall libgalahad_single.fdc_find_dependent_rows_s(control::Ref{fdc_control_type{Float32}}, + A_val, b, n_depen, depen) + @ccall libgalahad_single.fdc_find_dependent_rows_s(control::Ptr{fdc_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, - inform::Ref{fdc_inform_type{Float32}}, + inform::Ptr{fdc_inform_type{Float32}}, status::Ptr{Cint}, m::Cint, n::Cint, A_ne::Cint, A_col::Ptr{Cint}, A_ptr::Ptr{Cint}, A_val::Ptr{Float32}, @@ -111,10 +94,10 @@ end export fdc_find_dependent_rows function fdc_find_dependent_rows(control, data, inform, status, m, n, A_ne, A_col, A_ptr, - A_val, b, n_depen, depen) - @ccall libgalahad_double.fdc_find_dependent_rows(control::Ref{fdc_control_type{Float64}}, + A_val, b, n_depen, depen) + @ccall libgalahad_double.fdc_find_dependent_rows(control::Ptr{fdc_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, - inform::Ref{fdc_inform_type{Float64}}, + inform::Ptr{fdc_inform_type{Float64}}, status::Ptr{Cint}, m::Cint, n::Cint, A_ne::Cint, A_col::Ptr{Cint}, A_ptr::Ptr{Cint}, A_val::Ptr{Float64}, @@ -126,14 +109,14 @@ export fdc_terminate_s function fdc_terminate_s(data, control, inform) @ccall libgalahad_single.fdc_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{fdc_control_type{Float32}}, - inform::Ref{fdc_inform_type{Float32}})::Cvoid + control::Ptr{fdc_control_type{Float32}}, + inform::Ptr{fdc_inform_type{Float32}})::Cvoid end export fdc_terminate function fdc_terminate(data, control, inform) @ccall libgalahad_double.fdc_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{fdc_control_type{Float64}}, - inform::Ref{fdc_inform_type{Float64}})::Cvoid + control::Ptr{fdc_control_type{Float64}}, + inform::Ptr{fdc_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/fit.jl b/GALAHAD.jl/src/wrappers/fit.jl index fa458da712..440f74c7ce 100644 --- a/GALAHAD.jl/src/wrappers/fit.jl +++ b/GALAHAD.jl/src/wrappers/fit.jl @@ -1,6 +1,6 @@ export fit_control_type -mutable struct fit_control_type +struct fit_control_type f_indexing::Bool error::Cint out::Cint @@ -8,25 +8,21 @@ mutable struct fit_control_type space_critical::Bool deallocate_error_fatal::Bool prefix::NTuple{31,Cchar} - - fit_control_type() = new() end export fit_inform_type -mutable struct fit_inform_type +struct fit_inform_type status::Cint alloc_status::Cint bad_alloc::NTuple{81,Cchar} - - fit_inform_type() = new() end export fit_initialize_s function fit_initialize_s(data, control, status) @ccall libgalahad_single.fit_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{fit_control_type}, + control::Ptr{fit_control_type}, status::Ptr{Cint})::Cvoid end @@ -34,7 +30,7 @@ export fit_initialize function fit_initialize(data, control, status) @ccall libgalahad_double.fit_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{fit_control_type}, + control::Ptr{fit_control_type}, status::Ptr{Cint})::Cvoid end @@ -42,7 +38,7 @@ export fit_information_s function fit_information_s(data, inform, status) @ccall libgalahad_single.fit_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{fit_inform_type}, + inform::Ptr{fit_inform_type}, status::Ptr{Cint})::Cvoid end @@ -50,7 +46,7 @@ export fit_information function fit_information(data, inform, status) @ccall libgalahad_double.fit_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{fit_inform_type}, + inform::Ptr{fit_inform_type}, status::Ptr{Cint})::Cvoid end @@ -58,14 +54,14 @@ export fit_terminate_s function fit_terminate_s(data, control, inform) @ccall libgalahad_single.fit_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{fit_control_type}, - inform::Ref{fit_inform_type})::Cvoid + control::Ptr{fit_control_type}, + inform::Ptr{fit_inform_type})::Cvoid end export fit_terminate function fit_terminate(data, control, inform) @ccall libgalahad_double.fit_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{fit_control_type}, - inform::Ref{fit_inform_type})::Cvoid + control::Ptr{fit_control_type}, + inform::Ptr{fit_inform_type})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/glrt.jl b/GALAHAD.jl/src/wrappers/glrt.jl index 997f053b91..63abdcae17 100644 --- a/GALAHAD.jl/src/wrappers/glrt.jl +++ b/GALAHAD.jl/src/wrappers/glrt.jl @@ -1,6 +1,6 @@ export glrt_control_type -mutable struct glrt_control_type{T} +struct glrt_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -22,13 +22,11 @@ mutable struct glrt_control_type{T} print_ritz_values::Bool ritz_file_name::NTuple{31,Cchar} prefix::NTuple{31,Cchar} - - glrt_control_type{T}() where T = new() end export glrt_inform_type -mutable struct glrt_inform_type{T} +struct glrt_inform_type{T} status::Cint alloc_status::Cint bad_alloc::NTuple{81,Cchar} @@ -41,15 +39,13 @@ mutable struct glrt_inform_type{T} leftmost::T negative_curvature::Bool hard_case::Bool - - glrt_inform_type{T}() where T = new() end export glrt_initialize_s function glrt_initialize_s(data, control, status) @ccall libgalahad_single.glrt_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{glrt_control_type{Float32}}, + control::Ptr{glrt_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -57,28 +53,28 @@ export glrt_initialize function glrt_initialize(data, control, status) @ccall libgalahad_double.glrt_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{glrt_control_type{Float64}}, + control::Ptr{glrt_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export glrt_read_specfile_s function glrt_read_specfile_s(control, specfile) - @ccall libgalahad_single.glrt_read_specfile_s(control::Ref{glrt_control_type{Float32}}, + @ccall libgalahad_single.glrt_read_specfile_s(control::Ptr{glrt_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export glrt_read_specfile function glrt_read_specfile(control, specfile) - @ccall libgalahad_double.glrt_read_specfile(control::Ref{glrt_control_type{Float64}}, + @ccall libgalahad_double.glrt_read_specfile(control::Ptr{glrt_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export glrt_import_control_s function glrt_import_control_s(control, data, status) - @ccall libgalahad_single.glrt_import_control_s(control::Ref{glrt_control_type{Float32}}, + @ccall libgalahad_single.glrt_import_control_s(control::Ptr{glrt_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -86,7 +82,7 @@ end export glrt_import_control function glrt_import_control(control, data, status) - @ccall libgalahad_double.glrt_import_control(control::Ref{glrt_control_type{Float64}}, + @ccall libgalahad_double.glrt_import_control(control::Ptr{glrt_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -113,7 +109,7 @@ export glrt_information_s function glrt_information_s(data, inform, status) @ccall libgalahad_single.glrt_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{glrt_inform_type{Float32}}, + inform::Ptr{glrt_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -121,7 +117,7 @@ export glrt_information function glrt_information(data, inform, status) @ccall libgalahad_double.glrt_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{glrt_inform_type{Float64}}, + inform::Ptr{glrt_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -129,14 +125,14 @@ export glrt_terminate_s function glrt_terminate_s(data, control, inform) @ccall libgalahad_single.glrt_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{glrt_control_type{Float32}}, - inform::Ref{glrt_inform_type{Float32}})::Cvoid + control::Ptr{glrt_control_type{Float32}}, + inform::Ptr{glrt_inform_type{Float32}})::Cvoid end export glrt_terminate function glrt_terminate(data, control, inform) @ccall libgalahad_double.glrt_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{glrt_control_type{Float64}}, - inform::Ref{glrt_inform_type{Float64}})::Cvoid + control::Ptr{glrt_control_type{Float64}}, + inform::Ptr{glrt_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/gls.jl b/GALAHAD.jl/src/wrappers/gls.jl index 527bb9ddf7..c22396ad7e 100644 --- a/GALAHAD.jl/src/wrappers/gls.jl +++ b/GALAHAD.jl/src/wrappers/gls.jl @@ -1,6 +1,6 @@ export gls_control_type -mutable struct gls_control_type{T} +struct gls_control_type{T} f_indexing::Bool lp::Cint wp::Cint @@ -24,13 +24,11 @@ mutable struct gls_control_type{T} cgce::T diagonal_pivoting::Bool struct_abort::Bool - - gls_control_type{T}() where T = new() end export gls_ainfo_type -mutable struct gls_ainfo_type{T} +struct gls_ainfo_type{T} flag::Cint more::Cint len_analyse::Cint @@ -46,13 +44,11 @@ mutable struct gls_ainfo_type{T} sblock::Cint tblock::Cint ops::T - - gls_ainfo_type{T}() where T = new() end export gls_finfo_type -mutable struct gls_finfo_type{T} +struct gls_finfo_type{T} flag::Cint more::Cint size_factor::Cint @@ -61,66 +57,62 @@ mutable struct gls_finfo_type{T} rank::Cint stat::Cint ops::T - - gls_finfo_type{T}() where T = new() end export gls_sinfo_type -mutable struct gls_sinfo_type +struct gls_sinfo_type flag::Cint more::Cint stat::Cint - - gls_sinfo_type() = new() end export gls_initialize_s function gls_initialize_s(data, control) @ccall libgalahad_single.gls_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{gls_control_type{Float32}})::Cvoid + control::Ptr{gls_control_type{Float32}})::Cvoid end export gls_initialize function gls_initialize(data, control) @ccall libgalahad_double.gls_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{gls_control_type{Float64}})::Cvoid + control::Ptr{gls_control_type{Float64}})::Cvoid end export gls_read_specfile_s function gls_read_specfile_s(control, specfile) - @ccall libgalahad_single.gls_read_specfile_s(control::Ref{gls_control_type{Float32}}, + @ccall libgalahad_single.gls_read_specfile_s(control::Ptr{gls_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export gls_read_specfile function gls_read_specfile(control, specfile) - @ccall libgalahad_double.gls_read_specfile(control::Ref{gls_control_type{Float64}}, + @ccall libgalahad_double.gls_read_specfile(control::Ptr{gls_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export gls_import_s function gls_import_s(control, data, status) - @ccall libgalahad_single.gls_import_s(control::Ref{gls_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, - status::Ptr{Cint})::Cvoid + @ccall libgalahad_single.gls_import_s(control::Ptr{gls_control_type{Float32}}, + data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end export gls_import function gls_import(control, data, status) - @ccall libgalahad_double.gls_import(control::Ref{gls_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, - status::Ptr{Cint})::Cvoid + @ccall libgalahad_double.gls_import(control::Ptr{gls_control_type{Float64}}, + data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end export gls_reset_control_s function gls_reset_control_s(control, data, status) - @ccall libgalahad_single.gls_reset_control_s(control::Ref{gls_control_type{Float32}}, + @ccall libgalahad_single.gls_reset_control_s(control::Ptr{gls_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -128,7 +120,7 @@ end export gls_reset_control function gls_reset_control(control, data, status) - @ccall libgalahad_double.gls_reset_control(control::Ref{gls_control_type{Float64}}, + @ccall libgalahad_double.gls_reset_control(control::Ptr{gls_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -136,29 +128,35 @@ end export gls_information_s function gls_information_s(data, ainfo, finfo, sinfo, status) - @ccall libgalahad_single.gls_information_s(data::Ptr{Ptr{Cvoid}}, ainfo::Ref{gls_ainfo_type{Float32}}, - finfo::Ref{gls_finfo_type{Float32}}, sinfo::Ref{gls_sinfo_type}, + @ccall libgalahad_single.gls_information_s(data::Ptr{Ptr{Cvoid}}, + ainfo::Ptr{gls_ainfo_type{Float32}}, + finfo::Ptr{gls_finfo_type{Float32}}, + sinfo::Ptr{gls_sinfo_type}, status::Ptr{Cint})::Cvoid end export gls_information function gls_information(data, ainfo, finfo, sinfo, status) - @ccall libgalahad_double.gls_information(data::Ptr{Ptr{Cvoid}}, ainfo::Ref{gls_ainfo_type{Float64}}, - finfo::Ref{gls_finfo_type{Float64}}, sinfo::Ref{gls_sinfo_type}, + @ccall libgalahad_double.gls_information(data::Ptr{Ptr{Cvoid}}, + ainfo::Ptr{gls_ainfo_type{Float64}}, + finfo::Ptr{gls_finfo_type{Float64}}, + sinfo::Ptr{gls_sinfo_type}, status::Ptr{Cint})::Cvoid end export gls_finalize_s function gls_finalize_s(data, control, status) - @ccall libgalahad_single.gls_finalize_s(data::Ptr{Ptr{Cvoid}}, control::Ref{gls_control_type{Float32}}, + @ccall libgalahad_single.gls_finalize_s(data::Ptr{Ptr{Cvoid}}, + control::Ptr{gls_control_type{Float32}}, status::Ptr{Cint})::Cvoid end export gls_finalize function gls_finalize(data, control, status) - @ccall libgalahad_double.gls_finalize(data::Ptr{Ptr{Cvoid}}, control::Ref{gls_control_type{Float64}}, + @ccall libgalahad_double.gls_finalize(data::Ptr{Ptr{Cvoid}}, + control::Ptr{gls_control_type{Float64}}, status::Ptr{Cint})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/gltr.jl b/GALAHAD.jl/src/wrappers/gltr.jl index e38b659a0a..90a1d16d10 100644 --- a/GALAHAD.jl/src/wrappers/gltr.jl +++ b/GALAHAD.jl/src/wrappers/gltr.jl @@ -1,6 +1,6 @@ export gltr_control_type -mutable struct gltr_control_type{T} +struct gltr_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -24,13 +24,11 @@ mutable struct gltr_control_type{T} print_ritz_values::Bool ritz_file_name::NTuple{31,Cchar} prefix::NTuple{31,Cchar} - - gltr_control_type{T}() where T = new() end export gltr_inform_type -mutable struct gltr_inform_type{T} +struct gltr_inform_type{T} status::Cint alloc_status::Cint bad_alloc::NTuple{81,Cchar} @@ -45,15 +43,13 @@ mutable struct gltr_inform_type{T} leftmost::T negative_curvature::Bool hard_case::Bool - - gltr_inform_type{T}() where T = new() end export gltr_initialize_s function gltr_initialize_s(data, control, status) @ccall libgalahad_single.gltr_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{gltr_control_type{Float32}}, + control::Ptr{gltr_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -61,28 +57,28 @@ export gltr_initialize function gltr_initialize(data, control, status) @ccall libgalahad_double.gltr_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{gltr_control_type{Float64}}, + control::Ptr{gltr_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export gltr_read_specfile_s function gltr_read_specfile_s(control, specfile) - @ccall libgalahad_single.gltr_read_specfile_s(control::Ref{gltr_control_type{Float32}}, + @ccall libgalahad_single.gltr_read_specfile_s(control::Ptr{gltr_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export gltr_read_specfile function gltr_read_specfile(control, specfile) - @ccall libgalahad_double.gltr_read_specfile(control::Ref{gltr_control_type{Float64}}, + @ccall libgalahad_double.gltr_read_specfile(control::Ptr{gltr_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export gltr_import_control_s function gltr_import_control_s(control, data, status) - @ccall libgalahad_single.gltr_import_control_s(control::Ref{gltr_control_type{Float32}}, + @ccall libgalahad_single.gltr_import_control_s(control::Ptr{gltr_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -90,7 +86,7 @@ end export gltr_import_control function gltr_import_control(control, data, status) - @ccall libgalahad_double.gltr_import_control(control::Ref{gltr_control_type{Float64}}, + @ccall libgalahad_double.gltr_import_control(control::Ptr{gltr_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -109,15 +105,14 @@ export gltr_solve_problem function gltr_solve_problem(data, status, n, radius, x, r, vector) @ccall libgalahad_double.gltr_solve_problem(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, radius::Float64, x::Ptr{Float64}, - r::Ptr{Float64}, - vector::Ptr{Float64})::Cvoid + r::Ptr{Float64}, vector::Ptr{Float64})::Cvoid end export gltr_information_s function gltr_information_s(data, inform, status) @ccall libgalahad_single.gltr_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{gltr_inform_type{Float32}}, + inform::Ptr{gltr_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -125,7 +120,7 @@ export gltr_information function gltr_information(data, inform, status) @ccall libgalahad_double.gltr_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{gltr_inform_type{Float64}}, + inform::Ptr{gltr_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -133,14 +128,14 @@ export gltr_terminate_s function gltr_terminate_s(data, control, inform) @ccall libgalahad_single.gltr_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{gltr_control_type{Float32}}, - inform::Ref{gltr_inform_type{Float32}})::Cvoid + control::Ptr{gltr_control_type{Float32}}, + inform::Ptr{gltr_inform_type{Float32}})::Cvoid end export gltr_terminate function gltr_terminate(data, control, inform) @ccall libgalahad_double.gltr_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{gltr_control_type{Float64}}, - inform::Ref{gltr_inform_type{Float64}})::Cvoid + control::Ptr{gltr_control_type{Float64}}, + inform::Ptr{gltr_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/hash.jl b/GALAHAD.jl/src/wrappers/hash.jl index 763f6bbc99..db806add5a 100644 --- a/GALAHAD.jl/src/wrappers/hash.jl +++ b/GALAHAD.jl/src/wrappers/hash.jl @@ -1,24 +1,20 @@ export hash_control_type -mutable struct hash_control_type +struct hash_control_type error::Cint out::Cint print_level::Cint space_critical::Bool deallocate_error_fatal::Bool prefix::NTuple{31,Cchar} - - hash_control_type() = new() end export hash_inform_type -mutable struct hash_inform_type +struct hash_inform_type status::Cint alloc_status::Cint bad_alloc::NTuple{81,Cchar} - - hash_inform_type() = new() end export hash_initialize_s @@ -26,24 +22,23 @@ export hash_initialize_s function hash_initialize_s(nchar, length, data, control, inform) @ccall libgalahad_single.hash_initialize_s(nchar::Cint, length::Cint, data::Ptr{Ptr{Cvoid}}, - control::Ref{hash_control_type}, - inform::Ref{hash_inform_type})::Cvoid + control::Ptr{hash_control_type}, + inform::Ptr{hash_inform_type})::Cvoid end export hash_initialize function hash_initialize(nchar, length, data, control, inform) - @ccall libgalahad_double.hash_initialize(nchar::Cint, length::Cint, - data::Ptr{Ptr{Cvoid}}, - control::Ref{hash_control_type}, - inform::Ref{hash_inform_type})::Cvoid + @ccall libgalahad_double.hash_initialize(nchar::Cint, length::Cint, data::Ptr{Ptr{Cvoid}}, + control::Ptr{hash_control_type}, + inform::Ptr{hash_inform_type})::Cvoid end export hash_information_s function hash_information_s(data, inform, status) @ccall libgalahad_single.hash_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{hash_inform_type}, + inform::Ptr{hash_inform_type}, status::Ptr{Cint})::Cvoid end @@ -51,7 +46,7 @@ export hash_information function hash_information(data, inform, status) @ccall libgalahad_double.hash_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{hash_inform_type}, + inform::Ptr{hash_inform_type}, status::Ptr{Cint})::Cvoid end @@ -59,14 +54,14 @@ export hash_terminate_s function hash_terminate_s(data, control, inform) @ccall libgalahad_single.hash_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{hash_control_type}, - inform::Ref{hash_inform_type})::Cvoid + control::Ptr{hash_control_type}, + inform::Ptr{hash_inform_type})::Cvoid end export hash_terminate function hash_terminate(data, control, inform) @ccall libgalahad_double.hash_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{hash_control_type}, - inform::Ref{hash_inform_type})::Cvoid + control::Ptr{hash_control_type}, + inform::Ptr{hash_inform_type})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/hsl.jl b/GALAHAD.jl/src/wrappers/hsl.jl index f61528bb7a..245f7bcf79 100644 --- a/GALAHAD.jl/src/wrappers/hsl.jl +++ b/GALAHAD.jl/src/wrappers/hsl.jl @@ -1,6 +1,6 @@ export ma48_control -mutable struct ma48_control{T} +struct ma48_control{T} f_arrays::Cint multiplier::T u::T @@ -21,13 +21,11 @@ mutable struct ma48_control{T} diagonal_pivoting::Cint fill_in::Cint switch_mode::Cint - - ma48_control{T}() where T = new() end export ma48_ainfo -mutable struct ma48_ainfo{T} +struct ma48_ainfo{T} ops::T flag::Cint more::Cint @@ -45,13 +43,11 @@ mutable struct ma48_ainfo{T} lblock::Cint sblock::Cint tblock::Clong - - ma48_ainfo{T}() where T = new() end export ma48_finfo -mutable struct ma48_finfo{T} +struct ma48_finfo{T} ops::T flag::Cint more::Cint @@ -61,23 +57,19 @@ mutable struct ma48_finfo{T} drop::Clong rank::Cint stat::Cint - - ma48_finfo{T}() where T = new() end export ma48_sinfo -mutable struct ma48_sinfo +struct ma48_sinfo flag::Cint more::Cint stat::Cint - - ma48_sinfo() = new() end export ma57_control -mutable struct ma57_control{T} +struct ma57_control{T} f_arrays::Cint multiplier::T reduce::T @@ -106,13 +98,11 @@ mutable struct ma57_control{T} rank_deficient::Cint ispare::NTuple{5,Cint} rspare::NTuple{10,T} - - ma57_control{T}() where T = new() end export ma57_ainfo -mutable struct ma57_ainfo{T} +struct ma57_ainfo{T} opsa::T opse::T flag::Cint @@ -132,13 +122,11 @@ mutable struct ma57_ainfo{T} stat::Cint ispare::NTuple{5,Cint} rspare::NTuple{10,T} - - ma57_ainfo{T}() where T = new() end export ma57_finfo -mutable struct ma57_finfo{T} +struct ma57_finfo{T} opsa::T opse::T opsb::T @@ -167,13 +155,11 @@ mutable struct ma57_finfo{T} stat::Cint ispare::NTuple{5,Cint} rspare::NTuple{10,T} - - ma57_finfo{T}() where T = new() end export ma57_sinfo -mutable struct ma57_sinfo{T} +struct ma57_sinfo{T} cond::T cond2::T berr::T @@ -183,13 +169,11 @@ mutable struct ma57_sinfo{T} stat::Cint ispare::NTuple{5,Cint} rspare::NTuple{10,T} - - ma57_sinfo{T}() where T = new() end export ma77_control -mutable struct ma77_control{T} +struct ma77_control{T} f_arrays::Cint print_level::Cint unit_diagnostics::Cint @@ -219,13 +203,11 @@ mutable struct ma77_control{T} ispare::NTuple{5,Cint} lspare::NTuple{5,Clong} rspare::NTuple{5,T} - - ma77_control{T}() where T = new() end export ma77_info -mutable struct ma77_info{T} +struct ma77_info{T} detlog::T detsign::Cint flag::Cint @@ -260,13 +242,11 @@ mutable struct ma77_info{T} ispare::NTuple{5,Cint} lspare::NTuple{5,Clong} rspare::NTuple{5,T} - - ma77_info{T}() where T = new() end export ma86_control -mutable struct ma86_control{T} +struct ma86_control{T} f_arrays::Cint diagnostics_level::Cint unit_diagnostics::Cint @@ -282,13 +262,11 @@ mutable struct ma86_control{T} u::T umin::T scaling::Cint - - ma86_control{T}() where T = new() end export ma86_info -mutable struct ma86_info{T} +struct ma86_info{T} detlog::T detsign::Cint flag::Cint @@ -305,13 +283,11 @@ mutable struct ma86_info{T} pool_size::Cint stat::Cint usmall::T - - ma86_info{T}() where T = new() end export ma87_control -mutable struct ma87_control{T} +struct ma87_control{T} f_arrays::Cint diagnostics_level::Cint unit_diagnostics::Cint @@ -323,13 +299,11 @@ mutable struct ma87_control{T} diag_zero_minus::T diag_zero_plus::T unused::NTuple{40,Cchar} - - ma87_control{T}() where T = new() end export ma87_info -mutable struct ma87_info{T} +struct ma87_info{T} detlog::T flag::Cint maxdepth::Cint @@ -340,13 +314,11 @@ mutable struct ma87_info{T} stat::Cint num_zero::Cint unused::NTuple{40,Cchar} - - ma87_info{T}() where T = new() end export ma97_control -mutable struct ma97_control{T} +struct ma97_control{T} f_arrays::Cint action::Cint nemin::Cint @@ -366,13 +338,11 @@ mutable struct ma97_control{T} consist_tol::T ispare::NTuple{5,Cint} rspare::NTuple{10,T} - - ma97_control{T}() where T = new() end export ma97_info -mutable struct ma97_info{T} +struct ma97_info{T} flag::Cint flag68::Cint flag77::Cint @@ -392,37 +362,31 @@ mutable struct ma97_info{T} stat::Cint ispare::NTuple{5,Cint} rspare::NTuple{10,T} - - ma97_info{T}() where T = new() end export mc64_control -mutable struct mc64_control +struct mc64_control f_arrays::Cint lp::Cint wp::Cint sp::Cint ldiag::Cint checking::Cint - - mc64_control() = new() end export mc64_info -mutable struct mc64_info +struct mc64_info flag::Cint more::Cint strucrank::Cint stat::Cint - - mc64_info() = new() end export mc68_control -mutable struct mc68_control +struct mc68_control f_array_in::Cint f_array_out::Cint min_l_workspace::Cint @@ -433,13 +397,11 @@ mutable struct mc68_control print_level::Cint row_full_thresh::Cint row_search::Cint - - mc68_control() = new() end export mc68_info -mutable struct mc68_info +struct mc68_info flag::Cint iostat::Cint stat::Cint @@ -450,13 +412,11 @@ mutable struct mc68_info l_workspace::Clong zb01_info::Cint n_dense_rows::Cint - - mc68_info() = new() end export mi20_control -mutable struct mi20_control{T} +struct mi20_control{T} f_arrays::Cint aggressive::Cint c_fail::Cint @@ -480,13 +440,11 @@ mutable struct mi20_control{T} print::Cint error::Cint one_pass_coarsen::Cint - - mi20_control{T}() where T = new() end export mi20_solve_control -mutable struct mi20_solve_control{T} +struct mi20_solve_control{T} abs_tol::T breakdown_tol::T gmres_restart::Cint @@ -495,13 +453,11 @@ mutable struct mi20_solve_control{T} max_its::Cint preconditioner_side::Cint rel_tol::T - - mi20_solve_control{T}() where T = new() end export mi20_info -mutable struct mi20_info{T} +struct mi20_info{T} flag::Cint clevels::Cint cpoints::Cint @@ -510,13 +466,11 @@ mutable struct mi20_info{T} getrf_info::Cint iterations::Cint residual::T - - mi20_info{T}() where T = new() end export mi28_control -mutable struct mi28_control{T} +struct mi28_control{T} f_arrays::Cint alpha::T check::Bool @@ -532,13 +486,11 @@ mutable struct mi28_control{T} tau2::T unit_error::Cint unit_warning::Cint - - mi28_control{T}() where T = new() end export mi28_info -mutable struct mi28_info{T} +struct mi28_info{T} band_after::Cint band_before::Cint dup::Cint @@ -555,6 +507,4 @@ mutable struct mi28_info{T} size_r::Clong stat::Cint alpha::T - - mi28_info{T}() where T = new() end diff --git a/GALAHAD.jl/src/wrappers/ir.jl b/GALAHAD.jl/src/wrappers/ir.jl index 1839532392..a7c3a67983 100644 --- a/GALAHAD.jl/src/wrappers/ir.jl +++ b/GALAHAD.jl/src/wrappers/ir.jl @@ -1,6 +1,6 @@ export ir_control_type -mutable struct ir_control_type{T} +struct ir_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -13,27 +13,23 @@ mutable struct ir_control_type{T} space_critical::Bool deallocate_error_fatal::Bool prefix::NTuple{31,Cchar} - - ir_control_type{T}() where T = new() end export ir_inform_type -mutable struct ir_inform_type{T} +struct ir_inform_type{T} status::Cint alloc_status::Cint bad_alloc::NTuple{81,Cchar} norm_initial_residual::T norm_final_residual::T - - ir_inform_type{T}() where T = new() end export ir_initialize_s function ir_initialize_s(data, control, status) @ccall libgalahad_single.ir_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{ir_control_type{Float32}}, + control::Ptr{ir_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -41,7 +37,7 @@ export ir_initialize function ir_initialize(data, control, status) @ccall libgalahad_double.ir_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{ir_control_type{Float64}}, + control::Ptr{ir_control_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -49,7 +45,7 @@ export ir_information_s function ir_information_s(data, inform, status) @ccall libgalahad_single.ir_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{ir_inform_type{Float32}}, + inform::Ptr{ir_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -57,7 +53,7 @@ export ir_information function ir_information(data, inform, status) @ccall libgalahad_double.ir_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{ir_inform_type{Float64}}, + inform::Ptr{ir_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -65,14 +61,14 @@ export ir_terminate_s function ir_terminate_s(data, control, inform) @ccall libgalahad_single.ir_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{ir_control_type{Float32}}, - inform::Ref{ir_inform_type{Float32}})::Cvoid + control::Ptr{ir_control_type{Float32}}, + inform::Ptr{ir_inform_type{Float32}})::Cvoid end export ir_terminate function ir_terminate(data, control, inform) @ccall libgalahad_double.ir_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{ir_control_type{Float64}}, - inform::Ref{ir_inform_type{Float64}})::Cvoid + control::Ptr{ir_control_type{Float64}}, + inform::Ptr{ir_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/l2rt.jl b/GALAHAD.jl/src/wrappers/l2rt.jl index 004779e0ce..ca7589ac8d 100644 --- a/GALAHAD.jl/src/wrappers/l2rt.jl +++ b/GALAHAD.jl/src/wrappers/l2rt.jl @@ -1,6 +1,6 @@ export l2rt_control_type -mutable struct l2rt_control_type{T} +struct l2rt_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -21,13 +21,11 @@ mutable struct l2rt_control_type{T} space_critical::Bool deallocate_error_fatal::Bool prefix::NTuple{31,Cchar} - - l2rt_control_type{T}() where T = new() end export l2rt_inform_type -mutable struct l2rt_inform_type{T} +struct l2rt_inform_type{T} status::Cint alloc_status::Cint bad_alloc::NTuple{81,Cchar} @@ -42,15 +40,13 @@ mutable struct l2rt_inform_type{T} r_norm::T Atr_norm::T biter_mean::T - - l2rt_inform_type{T}() where T = new() end export l2rt_initialize_s function l2rt_initialize_s(data, control, status) @ccall libgalahad_single.l2rt_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{l2rt_control_type{Float32}}, + control::Ptr{l2rt_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -58,28 +54,28 @@ export l2rt_initialize function l2rt_initialize(data, control, status) @ccall libgalahad_double.l2rt_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{l2rt_control_type{Float64}}, + control::Ptr{l2rt_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export l2rt_read_specfile_s function l2rt_read_specfile_s(control, specfile) - @ccall libgalahad_single.l2rt_read_specfile_s(control::Ref{l2rt_control_type{Float32}}, + @ccall libgalahad_single.l2rt_read_specfile_s(control::Ptr{l2rt_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export l2rt_read_specfile function l2rt_read_specfile(control, specfile) - @ccall libgalahad_double.l2rt_read_specfile(control::Ref{l2rt_control_type{Float64}}, + @ccall libgalahad_double.l2rt_read_specfile(control::Ptr{l2rt_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export l2rt_import_control_s function l2rt_import_control_s(control, data, status) - @ccall libgalahad_single.l2rt_import_control_s(control::Ref{l2rt_control_type{Float32}}, + @ccall libgalahad_single.l2rt_import_control_s(control::Ptr{l2rt_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -87,7 +83,7 @@ end export l2rt_import_control function l2rt_import_control(control, data, status) - @ccall libgalahad_double.l2rt_import_control(control::Ref{l2rt_control_type{Float64}}, + @ccall libgalahad_double.l2rt_import_control(control::Ptr{l2rt_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -116,7 +112,7 @@ export l2rt_information_s function l2rt_information_s(data, inform, status) @ccall libgalahad_single.l2rt_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{l2rt_inform_type{Float32}}, + inform::Ptr{l2rt_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -124,7 +120,7 @@ export l2rt_information function l2rt_information(data, inform, status) @ccall libgalahad_double.l2rt_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{l2rt_inform_type{Float64}}, + inform::Ptr{l2rt_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -132,14 +128,14 @@ export l2rt_terminate_s function l2rt_terminate_s(data, control, inform) @ccall libgalahad_single.l2rt_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{l2rt_control_type{Float32}}, - inform::Ref{l2rt_inform_type{Float32}})::Cvoid + control::Ptr{l2rt_control_type{Float32}}, + inform::Ptr{l2rt_inform_type{Float32}})::Cvoid end export l2rt_terminate function l2rt_terminate(data, control, inform) @ccall libgalahad_double.l2rt_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{l2rt_control_type{Float64}}, - inform::Ref{l2rt_inform_type{Float64}})::Cvoid + control::Ptr{l2rt_control_type{Float64}}, + inform::Ptr{l2rt_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/lhs.jl b/GALAHAD.jl/src/wrappers/lhs.jl index 2b920e497d..9d59a3cf44 100644 --- a/GALAHAD.jl/src/wrappers/lhs.jl +++ b/GALAHAD.jl/src/wrappers/lhs.jl @@ -1,6 +1,6 @@ export lhs_control_type -mutable struct lhs_control_type +struct lhs_control_type error::Cint out::Cint print_level::Cint @@ -8,47 +8,43 @@ mutable struct lhs_control_type space_critical::Bool deallocate_error_fatal::Bool prefix::NTuple{31,Cchar} - - lhs_control_type() = new() end export lhs_inform_type -mutable struct lhs_inform_type +struct lhs_inform_type status::Cint alloc_status::Cint bad_alloc::NTuple{81,Cchar} - - lhs_inform_type() = new() end export lhs_initialize_s function lhs_initialize_s(data, control, inform) @ccall libgalahad_single.lhs_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{lhs_control_type}, - inform::Ref{lhs_inform_type})::Cvoid + control::Ptr{lhs_control_type}, + inform::Ptr{lhs_inform_type})::Cvoid end export lhs_initialize function lhs_initialize(data, control, inform) @ccall libgalahad_double.lhs_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{lhs_control_type}, - inform::Ref{lhs_inform_type})::Cvoid + control::Ptr{lhs_control_type}, + inform::Ptr{lhs_inform_type})::Cvoid end export lhs_read_specfile_s function lhs_read_specfile_s(control, specfile) - @ccall libgalahad_single.lhs_read_specfile_s(control::Ref{lhs_control_type}, + @ccall libgalahad_single.lhs_read_specfile_s(control::Ptr{lhs_control_type}, specfile::Ptr{Cchar})::Cvoid end export lhs_read_specfile function lhs_read_specfile(control, specfile) - @ccall libgalahad_double.lhs_read_specfile(control::Ref{lhs_control_type}, + @ccall libgalahad_double.lhs_read_specfile(control::Ptr{lhs_control_type}, specfile::Ptr{Cchar})::Cvoid end @@ -56,8 +52,8 @@ export lhs_ihs_s function lhs_ihs_s(n_dimen, n_points, seed, X, control, inform, data) @ccall libgalahad_single.lhs_ihs_s(n_dimen::Cint, n_points::Cint, seed::Ptr{Cint}, - X::Ptr{Ptr{Cint}}, control::Ref{lhs_control_type}, - inform::Ref{lhs_inform_type}, + X::Ptr{Ptr{Cint}}, control::Ptr{lhs_control_type}, + inform::Ptr{lhs_inform_type}, data::Ptr{Ptr{Cvoid}})::Cvoid end @@ -65,8 +61,8 @@ export lhs_ihs function lhs_ihs(n_dimen, n_points, seed, X, control, inform, data) @ccall libgalahad_double.lhs_ihs(n_dimen::Cint, n_points::Cint, seed::Ptr{Cint}, - X::Ptr{Ptr{Cint}}, control::Ref{lhs_control_type}, - inform::Ref{lhs_inform_type}, + X::Ptr{Ptr{Cint}}, control::Ptr{lhs_control_type}, + inform::Ptr{lhs_inform_type}, data::Ptr{Ptr{Cvoid}})::Cvoid end @@ -86,7 +82,7 @@ export lhs_information_s function lhs_information_s(data, inform, status) @ccall libgalahad_single.lhs_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{lhs_inform_type}, + inform::Ptr{lhs_inform_type}, status::Ptr{Cint})::Cvoid end @@ -94,7 +90,7 @@ export lhs_information function lhs_information(data, inform, status) @ccall libgalahad_double.lhs_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{lhs_inform_type}, + inform::Ptr{lhs_inform_type}, status::Ptr{Cint})::Cvoid end @@ -102,14 +98,14 @@ export lhs_terminate_s function lhs_terminate_s(data, control, inform) @ccall libgalahad_single.lhs_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{lhs_control_type}, - inform::Ref{lhs_inform_type})::Cvoid + control::Ptr{lhs_control_type}, + inform::Ptr{lhs_inform_type})::Cvoid end export lhs_terminate function lhs_terminate(data, control, inform) @ccall libgalahad_double.lhs_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{lhs_control_type}, - inform::Ref{lhs_inform_type})::Cvoid + control::Ptr{lhs_control_type}, + inform::Ptr{lhs_inform_type})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/llsr.jl b/GALAHAD.jl/src/wrappers/llsr.jl index fb4407fe9b..cadc36f4eb 100644 --- a/GALAHAD.jl/src/wrappers/llsr.jl +++ b/GALAHAD.jl/src/wrappers/llsr.jl @@ -1,6 +1,6 @@ export llsr_control_type -mutable struct llsr_control_type{T} +struct llsr_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -21,19 +21,11 @@ mutable struct llsr_control_type{T} sbls_control::sbls_control_type{T} sls_control::sls_control_type{T} ir_control::ir_control_type{T} - - function llsr_control_type{T}() where T - type = new() - type.sbls_control = sbls_control_type{T}() - type.sls_control = sls_control_type{T}() - type.ir_control = ir_control_type{T}() - return type - end end export llsr_time_type -mutable struct llsr_time_type{T} +struct llsr_time_type{T} total::T assemble::T analyse::T @@ -44,23 +36,19 @@ mutable struct llsr_time_type{T} clock_analyse::T clock_factorize::T clock_solve::T - - llsr_time_type{T}() where T = new() end export llsr_history_type -mutable struct llsr_history_type{T} +struct llsr_history_type{T} lambda::T x_norm::T r_norm::T - - llsr_history_type{T}() where T = new() end export llsr_inform_type -mutable struct llsr_inform_type{T} +struct llsr_inform_type{T} status::Cint alloc_status::Cint factorizations::Cint @@ -70,27 +58,17 @@ mutable struct llsr_inform_type{T} multiplier::T bad_alloc::NTuple{81,Cchar} time::llsr_time_type{T} - history::NTuple{100,llsr_history_type{T}} + history::NTuple{100,llsr_history_type} sbls_inform::sbls_inform_type{T} sls_inform::sls_inform_type{T} ir_inform::ir_inform_type{T} - - function llsr_inform_type{T}() where T - type = new() - type.time = llsr_time_type{T}() - type.history = ntuple(x -> llsr_history_type{T}(), 100) - type.sbls_inform = sbls_inform_type{T}() - type.sls_inform = sls_inform_type{T}() - type.ir_inform = ir_inform_type{T}() - return type - end end export llsr_initialize_s function llsr_initialize_s(data, control, status) @ccall libgalahad_single.llsr_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{llsr_control_type{Float32}}, + control::Ptr{llsr_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -98,28 +76,28 @@ export llsr_initialize function llsr_initialize(data, control, status) @ccall libgalahad_double.llsr_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{llsr_control_type{Float64}}, + control::Ptr{llsr_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export llsr_read_specfile_s function llsr_read_specfile_s(control, specfile) - @ccall libgalahad_single.llsr_read_specfile_s(control::Ref{llsr_control_type{Float32}}, + @ccall libgalahad_single.llsr_read_specfile_s(control::Ptr{llsr_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export llsr_read_specfile function llsr_read_specfile(control, specfile) - @ccall libgalahad_double.llsr_read_specfile(control::Ref{llsr_control_type{Float64}}, + @ccall libgalahad_double.llsr_read_specfile(control::Ptr{llsr_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export llsr_import_s function llsr_import_s(control, data, status, m, n, A_type, A_ne, A_row, A_col, A_ptr) - @ccall libgalahad_single.llsr_import_s(control::Ref{llsr_control_type{Float32}}, + @ccall libgalahad_single.llsr_import_s(control::Ptr{llsr_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, m::Cint, n::Cint, A_type::Ptr{Cchar}, A_ne::Cint, A_row::Ptr{Cint}, A_col::Ptr{Cint}, @@ -129,7 +107,7 @@ end export llsr_import function llsr_import(control, data, status, m, n, A_type, A_ne, A_row, A_col, A_ptr) - @ccall libgalahad_double.llsr_import(control::Ref{llsr_control_type{Float64}}, + @ccall libgalahad_double.llsr_import(control::Ptr{llsr_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, m::Cint, n::Cint, A_type::Ptr{Cchar}, A_ne::Cint, A_row::Ptr{Cint}, A_col::Ptr{Cint}, @@ -139,7 +117,7 @@ end export llsr_import_scaling_s function llsr_import_scaling_s(control, data, status, n, S_type, S_ne, S_row, S_col, S_ptr) - @ccall libgalahad_single.llsr_import_scaling_s(control::Ref{llsr_control_type{Float32}}, + @ccall libgalahad_single.llsr_import_scaling_s(control::Ptr{llsr_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, S_type::Ptr{Cchar}, S_ne::Cint, S_row::Ptr{Cint}, S_col::Ptr{Cint}, @@ -149,7 +127,7 @@ end export llsr_import_scaling function llsr_import_scaling(control, data, status, n, S_type, S_ne, S_row, S_col, S_ptr) - @ccall libgalahad_double.llsr_import_scaling(control::Ref{llsr_control_type{Float64}}, + @ccall libgalahad_double.llsr_import_scaling(control::Ptr{llsr_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, S_type::Ptr{Cchar}, S_ne::Cint, S_row::Ptr{Cint}, S_col::Ptr{Cint}, @@ -159,7 +137,7 @@ end export llsr_reset_control_s function llsr_reset_control_s(control, data, status) - @ccall libgalahad_single.llsr_reset_control_s(control::Ref{llsr_control_type{Float32}}, + @ccall libgalahad_single.llsr_reset_control_s(control::Ptr{llsr_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -167,7 +145,7 @@ end export llsr_reset_control function llsr_reset_control(control, data, status) - @ccall libgalahad_double.llsr_reset_control(control::Ref{llsr_control_type{Float64}}, + @ccall libgalahad_double.llsr_reset_control(control::Ptr{llsr_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -175,7 +153,7 @@ end export llsr_solve_problem_s function llsr_solve_problem_s(data, status, m, n, power, weight, A_ne, A_val, b, x, S_ne, - S_val) + S_val) @ccall libgalahad_single.llsr_solve_problem_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, m::Cint, n::Cint, power::Float32, weight::Float32, A_ne::Cint, @@ -187,7 +165,7 @@ end export llsr_solve_problem function llsr_solve_problem(data, status, m, n, power, weight, A_ne, A_val, b, x, S_ne, - S_val) + S_val) @ccall libgalahad_double.llsr_solve_problem(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, m::Cint, n::Cint, power::Float64, weight::Float64, A_ne::Cint, @@ -200,7 +178,7 @@ export llsr_information_s function llsr_information_s(data, inform, status) @ccall libgalahad_single.llsr_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{llsr_inform_type{Float32}}, + inform::Ptr{llsr_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -208,7 +186,7 @@ export llsr_information function llsr_information(data, inform, status) @ccall libgalahad_double.llsr_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{llsr_inform_type{Float64}}, + inform::Ptr{llsr_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -216,14 +194,14 @@ export llsr_terminate_s function llsr_terminate_s(data, control, inform) @ccall libgalahad_single.llsr_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{llsr_control_type{Float32}}, - inform::Ref{llsr_inform_type{Float32}})::Cvoid + control::Ptr{llsr_control_type{Float32}}, + inform::Ptr{llsr_inform_type{Float32}})::Cvoid end export llsr_terminate function llsr_terminate(data, control, inform) @ccall libgalahad_double.llsr_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{llsr_control_type{Float64}}, - inform::Ref{llsr_inform_type{Float64}})::Cvoid + control::Ptr{llsr_control_type{Float64}}, + inform::Ptr{llsr_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/llst.jl b/GALAHAD.jl/src/wrappers/llst.jl index 079be6c698..d928d78f9d 100644 --- a/GALAHAD.jl/src/wrappers/llst.jl +++ b/GALAHAD.jl/src/wrappers/llst.jl @@ -1,6 +1,6 @@ export llst_control_type -mutable struct llst_control_type{T} +struct llst_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -22,19 +22,11 @@ mutable struct llst_control_type{T} sbls_control::sbls_control_type{T} sls_control::sls_control_type{T} ir_control::ir_control_type{T} - - function llst_control_type{T}() where T - type = new() - type.sbls_control = sbls_control_type{T}() - type.sls_control = sls_control_type{T}() - type.ir_control = ir_control_type{T}() - return type - end end export llst_time_type -mutable struct llst_time_type{T} +struct llst_time_type{T} total::T assemble::T analyse::T @@ -45,23 +37,19 @@ mutable struct llst_time_type{T} clock_analyse::T clock_factorize::T clock_solve::T - - llst_time_type{T}() where T = new() end export llst_history_type -mutable struct llst_history_type{T} +struct llst_history_type{T} lambda::T x_norm::T r_norm::T - - llst_history_type{T}() where T = new() end export llst_inform_type -mutable struct llst_inform_type{T} +struct llst_inform_type{T} status::Cint alloc_status::Cint factorizations::Cint @@ -71,27 +59,17 @@ mutable struct llst_inform_type{T} multiplier::T bad_alloc::NTuple{81,Cchar} time::llst_time_type{T} - history::NTuple{100,llst_history_type{T}} + history::NTuple{100,llst_history_type} sbls_inform::sbls_inform_type{T} sls_inform::sls_inform_type{T} ir_inform::ir_inform_type{T} - - function llst_inform_type{T}() where T - type = new() - type.time = llst_time_type{T}() - type.history = ntuple(x -> llst_history_type{T}(), 100) - type.sbls_inform = sbls_inform_type{T}() - type.sls_inform = sls_inform_type{T}() - type.ir_inform = ir_inform_type{T}() - return type - end end export llst_initialize_s function llst_initialize_s(data, control, status) @ccall libgalahad_single.llst_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{llst_control_type{Float32}}, + control::Ptr{llst_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -99,28 +77,28 @@ export llst_initialize function llst_initialize(data, control, status) @ccall libgalahad_double.llst_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{llst_control_type{Float64}}, + control::Ptr{llst_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export llst_read_specfile_s function llst_read_specfile_s(control, specfile) - @ccall libgalahad_single.llst_read_specfile_s(control::Ref{llst_control_type{Float32}}, + @ccall libgalahad_single.llst_read_specfile_s(control::Ptr{llst_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export llst_read_specfile function llst_read_specfile(control, specfile) - @ccall libgalahad_double.llst_read_specfile(control::Ref{llst_control_type{Float64}}, + @ccall libgalahad_double.llst_read_specfile(control::Ptr{llst_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export llst_import_s function llst_import_s(control, data, status, m, n, A_type, A_ne, A_row, A_col, A_ptr) - @ccall libgalahad_single.llst_import_s(control::Ref{llst_control_type{Float32}}, + @ccall libgalahad_single.llst_import_s(control::Ptr{llst_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, m::Cint, n::Cint, A_type::Ptr{Cchar}, A_ne::Cint, A_row::Ptr{Cint}, A_col::Ptr{Cint}, @@ -130,7 +108,7 @@ end export llst_import function llst_import(control, data, status, m, n, A_type, A_ne, A_row, A_col, A_ptr) - @ccall libgalahad_double.llst_import(control::Ref{llst_control_type{Float64}}, + @ccall libgalahad_double.llst_import(control::Ptr{llst_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, m::Cint, n::Cint, A_type::Ptr{Cchar}, A_ne::Cint, A_row::Ptr{Cint}, A_col::Ptr{Cint}, @@ -140,7 +118,7 @@ end export llst_import_scaling_s function llst_import_scaling_s(control, data, status, n, S_type, S_ne, S_row, S_col, S_ptr) - @ccall libgalahad_single.llst_import_scaling_s(control::Ref{llst_control_type{Float32}}, + @ccall libgalahad_single.llst_import_scaling_s(control::Ptr{llst_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, S_type::Ptr{Cchar}, S_ne::Cint, S_row::Ptr{Cint}, S_col::Ptr{Cint}, @@ -150,7 +128,7 @@ end export llst_import_scaling function llst_import_scaling(control, data, status, n, S_type, S_ne, S_row, S_col, S_ptr) - @ccall libgalahad_double.llst_import_scaling(control::Ref{llst_control_type{Float64}}, + @ccall libgalahad_double.llst_import_scaling(control::Ptr{llst_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, S_type::Ptr{Cchar}, S_ne::Cint, S_row::Ptr{Cint}, S_col::Ptr{Cint}, @@ -160,7 +138,7 @@ end export llst_reset_control_s function llst_reset_control_s(control, data, status) - @ccall libgalahad_single.llst_reset_control_s(control::Ref{llst_control_type{Float32}}, + @ccall libgalahad_single.llst_reset_control_s(control::Ptr{llst_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -168,7 +146,7 @@ end export llst_reset_control function llst_reset_control(control, data, status) - @ccall libgalahad_double.llst_reset_control(control::Ref{llst_control_type{Float64}}, + @ccall libgalahad_double.llst_reset_control(control::Ptr{llst_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -187,17 +165,17 @@ export llst_solve_problem function llst_solve_problem(data, status, m, n, radius, A_ne, A_val, b, x, S_ne, S_val) @ccall libgalahad_double.llst_solve_problem(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, - m::Cint, n::Cint, radius::Float64, - A_ne::Cint, A_val::Ptr{Float64}, - b::Ptr{Float64}, x::Ptr{Float64}, - S_ne::Cint, S_val::Ptr{Float64})::Cvoid + m::Cint, n::Cint, radius::Float64, A_ne::Cint, + A_val::Ptr{Float64}, b::Ptr{Float64}, + x::Ptr{Float64}, S_ne::Cint, + S_val::Ptr{Float64})::Cvoid end export llst_information_s function llst_information_s(data, inform, status) @ccall libgalahad_single.llst_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{llst_inform_type{Float32}}, + inform::Ptr{llst_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -205,7 +183,7 @@ export llst_information function llst_information(data, inform, status) @ccall libgalahad_double.llst_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{llst_inform_type{Float64}}, + inform::Ptr{llst_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -213,14 +191,14 @@ export llst_terminate_s function llst_terminate_s(data, control, inform) @ccall libgalahad_single.llst_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{llst_control_type{Float32}}, - inform::Ref{llst_inform_type{Float32}})::Cvoid + control::Ptr{llst_control_type{Float32}}, + inform::Ptr{llst_inform_type{Float32}})::Cvoid end export llst_terminate function llst_terminate(data, control, inform) @ccall libgalahad_double.llst_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{llst_control_type{Float64}}, - inform::Ref{llst_inform_type{Float64}})::Cvoid + control::Ptr{llst_control_type{Float64}}, + inform::Ptr{llst_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/lms.jl b/GALAHAD.jl/src/wrappers/lms.jl index b4d0292414..6ac39c6b90 100644 --- a/GALAHAD.jl/src/wrappers/lms.jl +++ b/GALAHAD.jl/src/wrappers/lms.jl @@ -1,6 +1,6 @@ export lms_control_type -mutable struct lms_control_type{T} +struct lms_control_type f_indexing::Bool error::Cint out::Cint @@ -11,13 +11,11 @@ mutable struct lms_control_type{T} space_critical::Bool deallocate_error_fatal::Bool prefix::NTuple{31,Cchar} - - lms_control_type{T}() where T = new() end export lms_time_type -mutable struct lms_time_type{T} +struct lms_time_type{T} total::T setup::T form::T @@ -26,32 +24,24 @@ mutable struct lms_time_type{T} clock_setup::T clock_form::T clock_apply::T - - lms_time_type{T}() where T = new() end export lms_inform_type -mutable struct lms_inform_type{T} +struct lms_inform_type{T} status::Cint alloc_status::Cint length::Cint updates_skipped::Bool bad_alloc::NTuple{81,Cchar} time::lms_time_type{T} - - function lms_inform_type{T}() where T - type = new() - type.time = lms_time_type{T}() - return type - end end export lms_initialize_s function lms_initialize_s(data, control, status) @ccall libgalahad_single.lms_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{lms_control_type{Float32}}, + control::Ptr{lms_control_type}, status::Ptr{Cint})::Cvoid end @@ -59,7 +49,7 @@ export lms_initialize function lms_initialize(data, control, status) @ccall libgalahad_double.lms_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{lms_control_type{Float64}}, + control::Ptr{lms_control_type}, status::Ptr{Cint})::Cvoid end @@ -67,7 +57,7 @@ export lms_information_s function lms_information_s(data, inform, status) @ccall libgalahad_single.lms_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{lms_inform_type{Float32}}, + inform::Ptr{lms_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -75,7 +65,7 @@ export lms_information function lms_information(data, inform, status) @ccall libgalahad_double.lms_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{lms_inform_type{Float64}}, + inform::Ptr{lms_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -83,14 +73,14 @@ export lms_terminate_s function lms_terminate_s(data, control, inform) @ccall libgalahad_single.lms_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{lms_control_type{Float32}}, - inform::Ref{lms_inform_type{Float32}})::Cvoid + control::Ptr{lms_control_type}, + inform::Ptr{lms_inform_type{Float32}})::Cvoid end export lms_terminate function lms_terminate(data, control, inform) @ccall libgalahad_double.lms_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{lms_control_type{Float64}}, - inform::Ref{lms_inform_type{Float64}})::Cvoid + control::Ptr{lms_control_type}, + inform::Ptr{lms_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/lpa.jl b/GALAHAD.jl/src/wrappers/lpa.jl index bb547684c5..b82d5e170d 100644 --- a/GALAHAD.jl/src/wrappers/lpa.jl +++ b/GALAHAD.jl/src/wrappers/lpa.jl @@ -1,6 +1,6 @@ export lpa_control_type -mutable struct lpa_control_type{T} +struct lpa_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -35,24 +35,20 @@ mutable struct lpa_control_type{T} sif_file_name::NTuple{31,Cchar} qplib_file_name::NTuple{31,Cchar} prefix::NTuple{31,Cchar} - - lpa_control_type{T}() where T = new() end export lpa_time_type -mutable struct lpa_time_type{T} +struct lpa_time_type{T} total::T preprocess::T clock_total::T clock_preprocess::T - - lpa_time_type{T}() where T = new() end export lpa_inform_type -mutable struct lpa_inform_type{T} +struct lpa_inform_type{T} status::Cint alloc_status::Cint bad_alloc::NTuple{81,Cchar} @@ -65,20 +61,13 @@ mutable struct lpa_inform_type{T} RINFO::NTuple{40,T} time::lpa_time_type{T} rpd_inform::rpd_inform_type - - function lpa_inform_type{T}() where T - type = new() - type.time = lpa_time_type{T}() - type.rpd_inform = rpd_inform_type() - return type - end end export lpa_initialize_s function lpa_initialize_s(data, control, status) @ccall libgalahad_single.lpa_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{lpa_control_type{Float32}}, + control::Ptr{lpa_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -86,28 +75,28 @@ export lpa_initialize function lpa_initialize(data, control, status) @ccall libgalahad_double.lpa_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{lpa_control_type{Float64}}, + control::Ptr{lpa_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export lpa_read_specfile_s function lpa_read_specfile_s(control, specfile) - @ccall libgalahad_single.lpa_read_specfile_s(control::Ref{lpa_control_type{Float32}}, + @ccall libgalahad_single.lpa_read_specfile_s(control::Ptr{lpa_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export lpa_read_specfile function lpa_read_specfile(control, specfile) - @ccall libgalahad_double.lpa_read_specfile(control::Ref{lpa_control_type{Float64}}, + @ccall libgalahad_double.lpa_read_specfile(control::Ptr{lpa_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export lpa_import_s function lpa_import_s(control, data, status, n, m, A_type, A_ne, A_row, A_col, A_ptr) - @ccall libgalahad_single.lpa_import_s(control::Ref{lpa_control_type{Float32}}, + @ccall libgalahad_single.lpa_import_s(control::Ptr{lpa_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, A_type::Ptr{Cchar}, A_ne::Cint, A_row::Ptr{Cint}, A_col::Ptr{Cint}, @@ -117,7 +106,7 @@ end export lpa_import function lpa_import(control, data, status, n, m, A_type, A_ne, A_row, A_col, A_ptr) - @ccall libgalahad_double.lpa_import(control::Ref{lpa_control_type{Float64}}, + @ccall libgalahad_double.lpa_import(control::Ptr{lpa_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, A_type::Ptr{Cchar}, A_ne::Cint, A_row::Ptr{Cint}, A_col::Ptr{Cint}, @@ -127,7 +116,7 @@ end export lpa_reset_control_s function lpa_reset_control_s(control, data, status) - @ccall libgalahad_single.lpa_reset_control_s(control::Ref{lpa_control_type{Float32}}, + @ccall libgalahad_single.lpa_reset_control_s(control::Ptr{lpa_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -135,44 +124,42 @@ end export lpa_reset_control function lpa_reset_control(control, data, status) - @ccall libgalahad_double.lpa_reset_control(control::Ref{lpa_control_type{Float64}}, + @ccall libgalahad_double.lpa_reset_control(control::Ptr{lpa_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end export lpa_solve_lp_s -function lpa_solve_lp_s(data, status, n, m, g, f, a_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat) +function lpa_solve_lp_s(data, status, n, m, g, f, a_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, + z, x_stat, c_stat) @ccall libgalahad_single.lpa_solve_lp_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, - m::Cint, g::Ptr{Float32}, f::Float32, - a_ne::Cint, A_val::Ptr{Float32}, - c_l::Ptr{Float32}, c_u::Ptr{Float32}, - x_l::Ptr{Float32}, x_u::Ptr{Float32}, - x::Ptr{Float32}, c::Ptr{Float32}, - y::Ptr{Float32}, z::Ptr{Float32}, + m::Cint, g::Ptr{Float32}, f::Float32, a_ne::Cint, + A_val::Ptr{Float32}, c_l::Ptr{Float32}, + c_u::Ptr{Float32}, x_l::Ptr{Float32}, + x_u::Ptr{Float32}, x::Ptr{Float32}, + c::Ptr{Float32}, y::Ptr{Float32}, z::Ptr{Float32}, x_stat::Ptr{Cint}, c_stat::Ptr{Cint})::Cvoid end export lpa_solve_lp function lpa_solve_lp(data, status, n, m, g, f, a_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat) + x_stat, c_stat) @ccall libgalahad_double.lpa_solve_lp(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, - m::Cint, g::Ptr{Float64}, f::Float64, - a_ne::Cint, A_val::Ptr{Float64}, - c_l::Ptr{Float64}, c_u::Ptr{Float64}, - x_l::Ptr{Float64}, x_u::Ptr{Float64}, - x::Ptr{Float64}, c::Ptr{Float64}, - y::Ptr{Float64}, z::Ptr{Float64}, - x_stat::Ptr{Cint}, c_stat::Ptr{Cint})::Cvoid + m::Cint, g::Ptr{Float64}, f::Float64, a_ne::Cint, + A_val::Ptr{Float64}, c_l::Ptr{Float64}, + c_u::Ptr{Float64}, x_l::Ptr{Float64}, + x_u::Ptr{Float64}, x::Ptr{Float64}, c::Ptr{Float64}, + y::Ptr{Float64}, z::Ptr{Float64}, x_stat::Ptr{Cint}, + c_stat::Ptr{Cint})::Cvoid end export lpa_information_s function lpa_information_s(data, inform, status) @ccall libgalahad_single.lpa_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{lpa_inform_type{Float32}}, + inform::Ptr{lpa_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -180,7 +167,7 @@ export lpa_information function lpa_information(data, inform, status) @ccall libgalahad_double.lpa_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{lpa_inform_type{Float64}}, + inform::Ptr{lpa_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -188,14 +175,14 @@ export lpa_terminate_s function lpa_terminate_s(data, control, inform) @ccall libgalahad_single.lpa_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{lpa_control_type{Float32}}, - inform::Ref{lpa_inform_type{Float32}})::Cvoid + control::Ptr{lpa_control_type{Float32}}, + inform::Ptr{lpa_inform_type{Float32}})::Cvoid end export lpa_terminate function lpa_terminate(data, control, inform) @ccall libgalahad_double.lpa_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{lpa_control_type{Float64}}, - inform::Ref{lpa_inform_type{Float64}})::Cvoid + control::Ptr{lpa_control_type{Float64}}, + inform::Ptr{lpa_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/lpb.jl b/GALAHAD.jl/src/wrappers/lpb.jl index 55cfd96de0..a4ccc9f5f7 100644 --- a/GALAHAD.jl/src/wrappers/lpb.jl +++ b/GALAHAD.jl/src/wrappers/lpb.jl @@ -1,6 +1,6 @@ export lpb_control_type -mutable struct lpb_control_type{T} +struct lpb_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -60,21 +60,11 @@ mutable struct lpb_control_type{T} fit_control::fit_control_type roots_control::roots_control_type{T} cro_control::cro_control_type{T} - - function lpb_control_type{T}() where T - type = new() - type.fdc_control = fdc_control_type{T}() - type.sbls_control = sbls_control_type{T}() - type.fit_control = fit_control_type() - type.roots_control = roots_control_type{T}() - type.cro_control = cro_control_type{T}() - return type - end end export lpb_time_type -mutable struct lpb_time_type{T} +struct lpb_time_type{T} total::T preprocess::T find_dependent::T @@ -87,13 +77,11 @@ mutable struct lpb_time_type{T} clock_analyse::T clock_factorize::T clock_solve::T - - lpb_time_type{T}() where T = new() end export lpb_inform_type -mutable struct lpb_inform_type{T} +struct lpb_inform_type{T} status::Cint alloc_status::Cint bad_alloc::NTuple{81,Cchar} @@ -123,25 +111,13 @@ mutable struct lpb_inform_type{T} roots_inform::roots_inform_type cro_inform::cro_inform_type{T} rpd_inform::rpd_inform_type - - function lpb_inform_type{T}() where T - type = new() - type.time = lpb_time_type{T}() - type.fdc_inform = fdc_inform_type{T}() - type.sbls_inform = sbls_inform_type{T}() - type.fit_inform = fit_inform_type() - type.roots_inform = roots_inform_type() - type.cro_inform = cro_inform_type{T}() - type.rpd_inform = rpd_inform_type() - return type - end end export lpb_initialize_s function lpb_initialize_s(data, control, status) @ccall libgalahad_single.lpb_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{lpb_control_type{Float32}}, + control::Ptr{lpb_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -149,28 +125,28 @@ export lpb_initialize function lpb_initialize(data, control, status) @ccall libgalahad_double.lpb_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{lpb_control_type{Float64}}, + control::Ptr{lpb_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export lpb_read_specfile_s function lpb_read_specfile_s(control, specfile) - @ccall libgalahad_single.lpb_read_specfile_s(control::Ref{lpb_control_type{Float32}}, + @ccall libgalahad_single.lpb_read_specfile_s(control::Ptr{lpb_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export lpb_read_specfile function lpb_read_specfile(control, specfile) - @ccall libgalahad_double.lpb_read_specfile(control::Ref{lpb_control_type{Float64}}, + @ccall libgalahad_double.lpb_read_specfile(control::Ptr{lpb_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export lpb_import_s function lpb_import_s(control, data, status, n, m, A_type, A_ne, A_row, A_col, A_ptr) - @ccall libgalahad_single.lpb_import_s(control::Ref{lpb_control_type{Float32}}, + @ccall libgalahad_single.lpb_import_s(control::Ptr{lpb_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, A_type::Ptr{Cchar}, A_ne::Cint, A_row::Ptr{Cint}, A_col::Ptr{Cint}, @@ -180,7 +156,7 @@ end export lpb_import function lpb_import(control, data, status, n, m, A_type, A_ne, A_row, A_col, A_ptr) - @ccall libgalahad_double.lpb_import(control::Ref{lpb_control_type{Float64}}, + @ccall libgalahad_double.lpb_import(control::Ptr{lpb_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, A_type::Ptr{Cchar}, A_ne::Cint, A_row::Ptr{Cint}, A_col::Ptr{Cint}, @@ -190,7 +166,7 @@ end export lpb_reset_control_s function lpb_reset_control_s(control, data, status) - @ccall libgalahad_single.lpb_reset_control_s(control::Ref{lpb_control_type{Float32}}, + @ccall libgalahad_single.lpb_reset_control_s(control::Ptr{lpb_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -198,44 +174,42 @@ end export lpb_reset_control function lpb_reset_control(control, data, status) - @ccall libgalahad_double.lpb_reset_control(control::Ref{lpb_control_type{Float64}}, + @ccall libgalahad_double.lpb_reset_control(control::Ptr{lpb_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end export lpb_solve_lp_s -function lpb_solve_lp_s(data, status, n, m, g, f, a_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat) +function lpb_solve_lp_s(data, status, n, m, g, f, a_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, + z, x_stat, c_stat) @ccall libgalahad_single.lpb_solve_lp_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, - m::Cint, g::Ptr{Float32}, f::Float32, - a_ne::Cint, A_val::Ptr{Float32}, - c_l::Ptr{Float32}, c_u::Ptr{Float32}, - x_l::Ptr{Float32}, x_u::Ptr{Float32}, - x::Ptr{Float32}, c::Ptr{Float32}, - y::Ptr{Float32}, z::Ptr{Float32}, + m::Cint, g::Ptr{Float32}, f::Float32, a_ne::Cint, + A_val::Ptr{Float32}, c_l::Ptr{Float32}, + c_u::Ptr{Float32}, x_l::Ptr{Float32}, + x_u::Ptr{Float32}, x::Ptr{Float32}, + c::Ptr{Float32}, y::Ptr{Float32}, z::Ptr{Float32}, x_stat::Ptr{Cint}, c_stat::Ptr{Cint})::Cvoid end export lpb_solve_lp function lpb_solve_lp(data, status, n, m, g, f, a_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat) + x_stat, c_stat) @ccall libgalahad_double.lpb_solve_lp(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, - m::Cint, g::Ptr{Float64}, f::Float64, - a_ne::Cint, A_val::Ptr{Float64}, - c_l::Ptr{Float64}, c_u::Ptr{Float64}, - x_l::Ptr{Float64}, x_u::Ptr{Float64}, - x::Ptr{Float64}, c::Ptr{Float64}, - y::Ptr{Float64}, z::Ptr{Float64}, - x_stat::Ptr{Cint}, c_stat::Ptr{Cint})::Cvoid + m::Cint, g::Ptr{Float64}, f::Float64, a_ne::Cint, + A_val::Ptr{Float64}, c_l::Ptr{Float64}, + c_u::Ptr{Float64}, x_l::Ptr{Float64}, + x_u::Ptr{Float64}, x::Ptr{Float64}, c::Ptr{Float64}, + y::Ptr{Float64}, z::Ptr{Float64}, x_stat::Ptr{Cint}, + c_stat::Ptr{Cint})::Cvoid end export lpb_information_s function lpb_information_s(data, inform, status) @ccall libgalahad_single.lpb_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{lpb_inform_type{Float32}}, + inform::Ptr{lpb_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -243,7 +217,7 @@ export lpb_information function lpb_information(data, inform, status) @ccall libgalahad_double.lpb_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{lpb_inform_type{Float64}}, + inform::Ptr{lpb_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -251,14 +225,14 @@ export lpb_terminate_s function lpb_terminate_s(data, control, inform) @ccall libgalahad_single.lpb_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{lpb_control_type{Float32}}, - inform::Ref{lpb_inform_type{Float32}})::Cvoid + control::Ptr{lpb_control_type{Float32}}, + inform::Ptr{lpb_inform_type{Float32}})::Cvoid end export lpb_terminate function lpb_terminate(data, control, inform) @ccall libgalahad_double.lpb_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{lpb_control_type{Float64}}, - inform::Ref{lpb_inform_type{Float64}})::Cvoid + control::Ptr{lpb_control_type{Float64}}, + inform::Ptr{lpb_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/lsqp.jl b/GALAHAD.jl/src/wrappers/lsqp.jl index e89513a836..36822e5377 100644 --- a/GALAHAD.jl/src/wrappers/lsqp.jl +++ b/GALAHAD.jl/src/wrappers/lsqp.jl @@ -1,6 +1,6 @@ export lsqp_control_type -mutable struct lsqp_control_type{T} +struct lsqp_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -57,18 +57,11 @@ mutable struct lsqp_control_type{T} prefix::NTuple{31,Cchar} fdc_control::fdc_control_type{T} sbls_control::sbls_control_type{T} - - function lsqp_control_type{T}() where T - type = new() - type.fdc_control = fdc_control_type{T}() - type.sbls_control = sbls_control_type{T}() - return type - end end export lsqp_time_type -mutable struct lsqp_time_type{T} +struct lsqp_time_type{T} total::T preprocess::T find_dependent::T @@ -81,13 +74,11 @@ mutable struct lsqp_time_type{T} clock_analyse::T clock_factorize::T clock_solve::T - - lsqp_time_type{T}() where T = new() end export lsqp_inform_type -mutable struct lsqp_inform_type{T} +struct lsqp_inform_type{T} status::Cint alloc_status::Cint bad_alloc::NTuple{81,Cchar} @@ -104,21 +95,13 @@ mutable struct lsqp_inform_type{T} time::lsqp_time_type{T} fdc_inform::fdc_inform_type{T} sbls_inform::sbls_inform_type{T} - - function lsqp_inform_type{T}() where T - type = new() - type.time = lsqp_time_type{T}() - type.fdc_inform = fdc_inform_type{T}() - type.sbls_inform = sbls_inform_type{T}() - return type - end end export lsqp_initialize_s function lsqp_initialize_s(data, control, status) @ccall libgalahad_single.lsqp_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{lsqp_control_type{Float32}}, + control::Ptr{lsqp_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -126,28 +109,28 @@ export lsqp_initialize function lsqp_initialize(data, control, status) @ccall libgalahad_double.lsqp_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{lsqp_control_type{Float64}}, + control::Ptr{lsqp_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export lsqp_read_specfile_s function lsqp_read_specfile_s(control, specfile) - @ccall libgalahad_single.lsqp_read_specfile_s(control::Ref{lsqp_control_type{Float32}}, + @ccall libgalahad_single.lsqp_read_specfile_s(control::Ptr{lsqp_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export lsqp_read_specfile function lsqp_read_specfile(control, specfile) - @ccall libgalahad_double.lsqp_read_specfile(control::Ref{lsqp_control_type{Float64}}, + @ccall libgalahad_double.lsqp_read_specfile(control::Ptr{lsqp_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export lsqp_import_s function lsqp_import_s(control, data, status, n, m, A_type, A_ne, A_row, A_col, A_ptr) - @ccall libgalahad_single.lsqp_import_s(control::Ref{lsqp_control_type{Float32}}, + @ccall libgalahad_single.lsqp_import_s(control::Ptr{lsqp_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, A_type::Ptr{Cchar}, A_ne::Cint, A_row::Ptr{Cint}, A_col::Ptr{Cint}, @@ -157,7 +140,7 @@ end export lsqp_import function lsqp_import(control, data, status, n, m, A_type, A_ne, A_row, A_col, A_ptr) - @ccall libgalahad_double.lsqp_import(control::Ref{lsqp_control_type{Float64}}, + @ccall libgalahad_double.lsqp_import(control::Ptr{lsqp_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, A_type::Ptr{Cchar}, A_ne::Cint, A_row::Ptr{Cint}, A_col::Ptr{Cint}, @@ -167,7 +150,7 @@ end export lsqp_reset_control_s function lsqp_reset_control_s(control, data, status) - @ccall libgalahad_single.lsqp_reset_control_s(control::Ref{lsqp_control_type{Float32}}, + @ccall libgalahad_single.lsqp_reset_control_s(control::Ptr{lsqp_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -175,15 +158,15 @@ end export lsqp_reset_control function lsqp_reset_control(control, data, status) - @ccall libgalahad_double.lsqp_reset_control(control::Ref{lsqp_control_type{Float64}}, + @ccall libgalahad_double.lsqp_reset_control(control::Ptr{lsqp_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end export lsqp_solve_qp_s -function lsqp_solve_qp_s(data, status, n, m, w, x0, g, f, a_ne, A_val, c_l, c_u, x_l, x_u, x, - c, y, z, x_stat, c_stat) +function lsqp_solve_qp_s(data, status, n, m, w, x0, g, f, a_ne, A_val, c_l, c_u, x_l, x_u, + x, c, y, z, x_stat, c_stat) @ccall libgalahad_single.lsqp_solve_qp_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, w::Ptr{Float32}, x0::Ptr{Float32}, g::Ptr{Float32}, f::Float32, @@ -198,15 +181,14 @@ end export lsqp_solve_qp function lsqp_solve_qp(data, status, n, m, w, x0, g, f, a_ne, A_val, c_l, c_u, x_l, x_u, x, - c, y, z, x_stat, c_stat) - @ccall libgalahad_double.lsqp_solve_qp(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, - n::Cint, m::Cint, w::Ptr{Float64}, - x0::Ptr{Float64}, g::Ptr{Float64}, f::Float64, - a_ne::Cint, A_val::Ptr{Float64}, - c_l::Ptr{Float64}, c_u::Ptr{Float64}, - x_l::Ptr{Float64}, x_u::Ptr{Float64}, - x::Ptr{Float64}, c::Ptr{Float64}, - y::Ptr{Float64}, z::Ptr{Float64}, + c, y, z, x_stat, c_stat) + @ccall libgalahad_double.lsqp_solve_qp(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, + m::Cint, w::Ptr{Float64}, x0::Ptr{Float64}, + g::Ptr{Float64}, f::Float64, a_ne::Cint, + A_val::Ptr{Float64}, c_l::Ptr{Float64}, + c_u::Ptr{Float64}, x_l::Ptr{Float64}, + x_u::Ptr{Float64}, x::Ptr{Float64}, + c::Ptr{Float64}, y::Ptr{Float64}, z::Ptr{Float64}, x_stat::Ptr{Cint}, c_stat::Ptr{Cint})::Cvoid end @@ -214,7 +196,7 @@ export lsqp_information_s function lsqp_information_s(data, inform, status) @ccall libgalahad_single.lsqp_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{lsqp_inform_type{Float32}}, + inform::Ptr{lsqp_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -222,7 +204,7 @@ export lsqp_information function lsqp_information(data, inform, status) @ccall libgalahad_double.lsqp_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{lsqp_inform_type{Float64}}, + inform::Ptr{lsqp_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -230,14 +212,14 @@ export lsqp_terminate_s function lsqp_terminate_s(data, control, inform) @ccall libgalahad_single.lsqp_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{lsqp_control_type{Float32}}, - inform::Ref{lsqp_inform_type{Float32}})::Cvoid + control::Ptr{lsqp_control_type{Float32}}, + inform::Ptr{lsqp_inform_type{Float32}})::Cvoid end export lsqp_terminate function lsqp_terminate(data, control, inform) @ccall libgalahad_double.lsqp_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{lsqp_control_type{Float64}}, - inform::Ref{lsqp_inform_type{Float64}})::Cvoid + control::Ptr{lsqp_control_type{Float64}}, + inform::Ptr{lsqp_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/lsrt.jl b/GALAHAD.jl/src/wrappers/lsrt.jl index aa9e95d533..1068e6fe90 100644 --- a/GALAHAD.jl/src/wrappers/lsrt.jl +++ b/GALAHAD.jl/src/wrappers/lsrt.jl @@ -1,6 +1,6 @@ export lsrt_control_type -mutable struct lsrt_control_type{T} +struct lsrt_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -21,13 +21,11 @@ mutable struct lsrt_control_type{T} space_critical::Bool deallocate_error_fatal::Bool prefix::NTuple{31,Cchar} - - lsrt_control_type{T}() where T = new() end export lsrt_inform_type -mutable struct lsrt_inform_type{T} +struct lsrt_inform_type{T} status::Cint alloc_status::Cint bad_alloc::NTuple{81,Cchar} @@ -42,15 +40,13 @@ mutable struct lsrt_inform_type{T} r_norm::T Atr_norm::T biter_mean::T - - lsrt_inform_type{T}() where T = new() end export lsrt_initialize_s function lsrt_initialize_s(data, control, status) @ccall libgalahad_single.lsrt_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{lsrt_control_type{Float32}}, + control::Ptr{lsrt_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -58,28 +54,28 @@ export lsrt_initialize function lsrt_initialize(data, control, status) @ccall libgalahad_double.lsrt_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{lsrt_control_type{Float64}}, + control::Ptr{lsrt_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export lsrt_read_specfile_s function lsrt_read_specfile_s(control, specfile) - @ccall libgalahad_single.lsrt_read_specfile_s(control::Ref{lsrt_control_type{Float32}}, + @ccall libgalahad_single.lsrt_read_specfile_s(control::Ptr{lsrt_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export lsrt_read_specfile function lsrt_read_specfile(control, specfile) - @ccall libgalahad_double.lsrt_read_specfile(control::Ref{lsrt_control_type{Float64}}, + @ccall libgalahad_double.lsrt_read_specfile(control::Ptr{lsrt_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export lsrt_import_control_s function lsrt_import_control_s(control, data, status) - @ccall libgalahad_single.lsrt_import_control_s(control::Ref{lsrt_control_type{Float32}}, + @ccall libgalahad_single.lsrt_import_control_s(control::Ptr{lsrt_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -87,7 +83,7 @@ end export lsrt_import_control function lsrt_import_control(control, data, status) - @ccall libgalahad_double.lsrt_import_control(control::Ref{lsrt_control_type{Float64}}, + @ccall libgalahad_double.lsrt_import_control(control::Ptr{lsrt_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -114,7 +110,7 @@ export lsrt_information_s function lsrt_information_s(data, inform, status) @ccall libgalahad_single.lsrt_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{lsrt_inform_type{Float32}}, + inform::Ptr{lsrt_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -122,7 +118,7 @@ export lsrt_information function lsrt_information(data, inform, status) @ccall libgalahad_double.lsrt_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{lsrt_inform_type{Float64}}, + inform::Ptr{lsrt_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -130,14 +126,14 @@ export lsrt_terminate_s function lsrt_terminate_s(data, control, inform) @ccall libgalahad_single.lsrt_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{lsrt_control_type{Float32}}, - inform::Ref{lsrt_inform_type{Float32}})::Cvoid + control::Ptr{lsrt_control_type{Float32}}, + inform::Ptr{lsrt_inform_type{Float32}})::Cvoid end export lsrt_terminate function lsrt_terminate(data, control, inform) @ccall libgalahad_double.lsrt_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{lsrt_control_type{Float64}}, - inform::Ref{lsrt_inform_type{Float64}})::Cvoid + control::Ptr{lsrt_control_type{Float64}}, + inform::Ptr{lsrt_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/lstr.jl b/GALAHAD.jl/src/wrappers/lstr.jl index abd04707ce..d952cb12f5 100644 --- a/GALAHAD.jl/src/wrappers/lstr.jl +++ b/GALAHAD.jl/src/wrappers/lstr.jl @@ -1,6 +1,6 @@ export lstr_control_type -mutable struct lstr_control_type{T} +struct lstr_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -21,13 +21,11 @@ mutable struct lstr_control_type{T} space_critical::Bool deallocate_error_fatal::Bool prefix::NTuple{31,Cchar} - - lstr_control_type{T}() where T = new() end export lstr_inform_type -mutable struct lstr_inform_type{T} +struct lstr_inform_type{T} status::Cint alloc_status::Cint bad_alloc::NTuple{81,Cchar} @@ -41,15 +39,13 @@ mutable struct lstr_inform_type{T} r_norm::T Atr_norm::T biter_mean::T - - lstr_inform_type{T}() where T = new() end export lstr_initialize_s function lstr_initialize_s(data, control, status) @ccall libgalahad_single.lstr_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{lstr_control_type{Float32}}, + control::Ptr{lstr_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -57,28 +53,28 @@ export lstr_initialize function lstr_initialize(data, control, status) @ccall libgalahad_double.lstr_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{lstr_control_type{Float64}}, + control::Ptr{lstr_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export lstr_read_specfile_s function lstr_read_specfile_s(control, specfile) - @ccall libgalahad_single.lstr_read_specfile_s(control::Ref{lstr_control_type{Float32}}, + @ccall libgalahad_single.lstr_read_specfile_s(control::Ptr{lstr_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export lstr_read_specfile function lstr_read_specfile(control, specfile) - @ccall libgalahad_double.lstr_read_specfile(control::Ref{lstr_control_type{Float64}}, + @ccall libgalahad_double.lstr_read_specfile(control::Ptr{lstr_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export lstr_import_control_s function lstr_import_control_s(control, data, status) - @ccall libgalahad_single.lstr_import_control_s(control::Ref{lstr_control_type{Float32}}, + @ccall libgalahad_single.lstr_import_control_s(control::Ptr{lstr_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -86,7 +82,7 @@ end export lstr_import_control function lstr_import_control(control, data, status) - @ccall libgalahad_double.lstr_import_control(control::Ref{lstr_control_type{Float64}}, + @ccall libgalahad_double.lstr_import_control(control::Ptr{lstr_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -113,7 +109,7 @@ export lstr_information_s function lstr_information_s(data, inform, status) @ccall libgalahad_single.lstr_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{lstr_inform_type{Float32}}, + inform::Ptr{lstr_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -121,7 +117,7 @@ export lstr_information function lstr_information(data, inform, status) @ccall libgalahad_double.lstr_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{lstr_inform_type{Float64}}, + inform::Ptr{lstr_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -129,14 +125,14 @@ export lstr_terminate_s function lstr_terminate_s(data, control, inform) @ccall libgalahad_single.lstr_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{lstr_control_type{Float32}}, - inform::Ref{lstr_inform_type{Float32}})::Cvoid + control::Ptr{lstr_control_type{Float32}}, + inform::Ptr{lstr_inform_type{Float32}})::Cvoid end export lstr_terminate function lstr_terminate(data, control, inform) @ccall libgalahad_double.lstr_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{lstr_control_type{Float64}}, - inform::Ref{lstr_inform_type{Float64}})::Cvoid + control::Ptr{lstr_control_type{Float64}}, + inform::Ptr{lstr_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/nls.jl b/GALAHAD.jl/src/wrappers/nls.jl index 3affbf3474..f037a771ef 100644 --- a/GALAHAD.jl/src/wrappers/nls.jl +++ b/GALAHAD.jl/src/wrappers/nls.jl @@ -1,6 +1,6 @@ export nls_subproblem_control_type -mutable struct nls_subproblem_control_type{T} +struct nls_subproblem_control_type{T} error::Cint out::Cint print_level::Cint @@ -50,21 +50,11 @@ mutable struct nls_subproblem_control_type{T} psls_control::psls_control_type{T} bsc_control::bsc_control_type roots_control::roots_control_type{T} - - function nls_subproblem_control_type{T}() where T - type = new() - type.rqs_control = rqs_control_type{T}() - type.glrt_control = glrt_control_type{T}() - type.psls_control = psls_control_type{T}() - type.bsc_control = bsc_control_type() - type.roots_control = roots_control_type{T}() - return type - end end export nls_control_type -mutable struct nls_control_type{T} +struct nls_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -116,22 +106,11 @@ mutable struct nls_control_type{T} bsc_control::bsc_control_type roots_control::roots_control_type{T} subproblem_control::nls_subproblem_control_type{T} - - function nls_control_type{T}() where T - type = new() - type.rqs_control = rqs_control_type{T}() - type.glrt_control = glrt_control_type{T}() - type.psls_control = psls_control_type{T}() - type.bsc_control = bsc_control_type() - type.roots_control = roots_control_type{T}() - type.subproblem_control = nls_subproblem_control_type{T}() - return type - end end export nls_time_type -mutable struct nls_time_type{T} +struct nls_time_type{T} total::Float32 preprocess::Float32 analyse::Float32 @@ -142,13 +121,11 @@ mutable struct nls_time_type{T} clock_analyse::T clock_factorize::T clock_solve::T - - nls_time_type{T}() where T = new() end export nls_subproblem_inform_type -mutable struct nls_subproblem_inform_type{T} +struct nls_subproblem_inform_type{T} status::Cint alloc_status::Cint bad_alloc::NTuple{81,Cchar} @@ -174,22 +151,11 @@ mutable struct nls_subproblem_inform_type{T} psls_inform::psls_inform_type{T} bsc_inform::bsc_inform_type{T} roots_inform::roots_inform_type - - function nls_subproblem_inform_type{T}() where T - type = new() - type.time = nls_time_type{T}() - type.rqs_inform = rqs_inform_type{T}() - type.glrt_inform = glrt_inform_type{T}() - type.psls_inform = psls_inform_type{T}() - type.bsc_inform = bsc_inform_type{T}() - type.roots_inform = roots_inform_type() - return type - end end export nls_inform_type -mutable struct nls_inform_type{T} +struct nls_inform_type{T} status::Cint alloc_status::Cint bad_alloc::NTuple{81,Cchar} @@ -216,55 +182,44 @@ mutable struct nls_inform_type{T} psls_inform::psls_inform_type{T} bsc_inform::bsc_inform_type{T} roots_inform::roots_inform_type - - function nls_inform_type{T}() where T - type = new() - type.time = nls_time_type{T}() - type.subproblem_inform = nls_subproblem_inform_type{T}() - type.rqs_inform = rqs_inform_type{T}() - type.glrt_inform = glrt_inform_type{T}() - type.psls_inform = psls_inform_type{T}() - type.bsc_inform = bsc_inform_type{T}() - type.roots_inform = roots_inform_type() - return type - end end export nls_initialize_s function nls_initialize_s(data, control, inform) @ccall libgalahad_single.nls_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{nls_control_type{Float32}}, - inform::Ref{nls_inform_type{Float32}})::Cvoid + control::Ptr{nls_control_type{Float32}}, + inform::Ptr{nls_inform_type{Float32}})::Cvoid end export nls_initialize function nls_initialize(data, control, inform) @ccall libgalahad_double.nls_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{nls_control_type{Float64}}, - inform::Ref{nls_inform_type{Float64}})::Cvoid + control::Ptr{nls_control_type{Float64}}, + inform::Ptr{nls_inform_type{Float64}})::Cvoid end export nls_read_specfile_s function nls_read_specfile_s(control, specfile) - @ccall libgalahad_single.nls_read_specfile_s(control::Ref{nls_control_type{Float32}}, + @ccall libgalahad_single.nls_read_specfile_s(control::Ptr{nls_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export nls_read_specfile function nls_read_specfile(control, specfile) - @ccall libgalahad_double.nls_read_specfile(control::Ref{nls_control_type{Float64}}, + @ccall libgalahad_double.nls_read_specfile(control::Ptr{nls_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export nls_import_s -function nls_import_s(control, data, status, n, m, J_type, J_ne, J_row, J_col, J_ptr, H_type, - H_ne, H_row, H_col, H_ptr, P_type, P_ne, P_row, P_col, P_ptr, w) - @ccall libgalahad_single.nls_import_s(control::Ref{nls_control_type{Float32}}, +function nls_import_s(control, data, status, n, m, J_type, J_ne, J_row, J_col, J_ptr, + H_type, H_ne, H_row, H_col, H_ptr, P_type, P_ne, P_row, P_col, P_ptr, + w) + @ccall libgalahad_single.nls_import_s(control::Ptr{nls_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, J_type::Ptr{Cchar}, J_ne::Cint, J_row::Ptr{Cint}, J_col::Ptr{Cint}, @@ -278,22 +233,22 @@ end export nls_import function nls_import(control, data, status, n, m, J_type, J_ne, J_row, J_col, J_ptr, H_type, - H_ne, H_row, H_col, H_ptr, P_type, P_ne, P_row, P_col, P_ptr, w) - @ccall libgalahad_double.nls_import(control::Ref{nls_control_type{Float64}}, + H_ne, H_row, H_col, H_ptr, P_type, P_ne, P_row, P_col, P_ptr, w) + @ccall libgalahad_double.nls_import(control::Ptr{nls_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, J_type::Ptr{Cchar}, J_ne::Cint, - J_row::Ptr{Cint}, J_col::Ptr{Cint}, - J_ptr::Ptr{Cint}, H_type::Ptr{Cchar}, H_ne::Cint, - H_row::Ptr{Cint}, H_col::Ptr{Cint}, - H_ptr::Ptr{Cint}, P_type::Ptr{Cchar}, P_ne::Cint, - P_row::Ptr{Cint}, P_col::Ptr{Cint}, - P_ptr::Ptr{Cint}, w::Ptr{Float64})::Cvoid + J_row::Ptr{Cint}, J_col::Ptr{Cint}, J_ptr::Ptr{Cint}, + H_type::Ptr{Cchar}, H_ne::Cint, H_row::Ptr{Cint}, + H_col::Ptr{Cint}, H_ptr::Ptr{Cint}, + P_type::Ptr{Cchar}, P_ne::Cint, P_row::Ptr{Cint}, + P_col::Ptr{Cint}, P_ptr::Ptr{Cint}, + w::Ptr{Float64})::Cvoid end export nls_reset_control_s function nls_reset_control_s(control, data, status) - @ccall libgalahad_single.nls_reset_control_s(control::Ref{nls_control_type{Float32}}, + @ccall libgalahad_single.nls_reset_control_s(control::Ptr{nls_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -301,7 +256,7 @@ end export nls_reset_control function nls_reset_control(control, data, status) - @ccall libgalahad_double.nls_reset_control(control::Ref{nls_control_type{Float64}}, + @ccall libgalahad_double.nls_reset_control(control::Ptr{nls_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -309,7 +264,7 @@ end export nls_solve_with_mat_s function nls_solve_with_mat_s(data, userdata, status, n, m, x, c, g, eval_c, j_ne, eval_j, - h_ne, eval_h, p_ne, eval_hprods) + h_ne, eval_h, p_ne, eval_hprods) @ccall libgalahad_single.nls_solve_with_mat_s(data::Ptr{Ptr{Cvoid}}, userdata::Ptr{Cvoid}, status::Ptr{Cint}, n::Cint, m::Cint, x::Ptr{Float32}, c::Ptr{Float32}, @@ -322,7 +277,7 @@ end export nls_solve_with_mat function nls_solve_with_mat(data, userdata, status, n, m, x, c, g, eval_c, j_ne, eval_j, - h_ne, eval_h, p_ne, eval_hprods) + h_ne, eval_h, p_ne, eval_hprods) @ccall libgalahad_double.nls_solve_with_mat(data::Ptr{Ptr{Cvoid}}, userdata::Ptr{Cvoid}, status::Ptr{Cint}, n::Cint, m::Cint, x::Ptr{Float64}, c::Ptr{Float64}, @@ -335,7 +290,7 @@ end export nls_solve_without_mat_s function nls_solve_without_mat_s(data, userdata, status, n, m, x, c, g, eval_c, eval_jprod, - eval_hprod, p_ne, eval_hprods) + eval_hprod, p_ne, eval_hprods) @ccall libgalahad_single.nls_solve_without_mat_s(data::Ptr{Ptr{Cvoid}}, userdata::Ptr{Cvoid}, status::Ptr{Cint}, n::Cint, m::Cint, x::Ptr{Float32}, @@ -349,13 +304,12 @@ end export nls_solve_without_mat function nls_solve_without_mat(data, userdata, status, n, m, x, c, g, eval_c, eval_jprod, - eval_hprod, p_ne, eval_hprods) + eval_hprod, p_ne, eval_hprods) @ccall libgalahad_double.nls_solve_without_mat(data::Ptr{Ptr{Cvoid}}, userdata::Ptr{Cvoid}, status::Ptr{Cint}, n::Cint, m::Cint, x::Ptr{Float64}, c::Ptr{Float64}, g::Ptr{Float64}, - eval_c::Ptr{Cvoid}, - eval_jprod::Ptr{Cvoid}, + eval_c::Ptr{Cvoid}, eval_jprod::Ptr{Cvoid}, eval_hprod::Ptr{Cvoid}, p_ne::Cint, eval_hprods::Ptr{Cvoid})::Cvoid end @@ -363,7 +317,7 @@ end export nls_solve_reverse_with_mat_s function nls_solve_reverse_with_mat_s(data, status, eval_status, n, m, x, c, g, j_ne, J_val, - y, h_ne, H_val, v, p_ne, P_val) + y, h_ne, H_val, v, p_ne, P_val) @ccall libgalahad_single.nls_solve_reverse_with_mat_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, eval_status::Ptr{Cint}, n::Cint, @@ -379,7 +333,7 @@ end export nls_solve_reverse_with_mat function nls_solve_reverse_with_mat(data, status, eval_status, n, m, x, c, g, j_ne, J_val, - y, h_ne, H_val, v, p_ne, P_val) + y, h_ne, H_val, v, p_ne, P_val) @ccall libgalahad_double.nls_solve_reverse_with_mat(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, eval_status::Ptr{Cint}, n::Cint, @@ -387,24 +341,22 @@ function nls_solve_reverse_with_mat(data, status, eval_status, n, m, x, c, g, j_ c::Ptr{Float64}, g::Ptr{Float64}, j_ne::Cint, J_val::Ptr{Float64}, y::Ptr{Float64}, h_ne::Cint, - H_val::Ptr{Float64}, - v::Ptr{Float64}, p_ne::Cint, + H_val::Ptr{Float64}, v::Ptr{Float64}, + p_ne::Cint, P_val::Ptr{Float64})::Cvoid end export nls_solve_reverse_without_mat_s -function nls_solve_reverse_without_mat_s(data, status, eval_status, n, m, x, c, g, transpose, - u, v, y, p_ne, P_val) +function nls_solve_reverse_without_mat_s(data, status, eval_status, n, m, x, c, g, + transpose, u, v, y, p_ne, P_val) @ccall libgalahad_single.nls_solve_reverse_without_mat_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, eval_status::Ptr{Cint}, n::Cint, m::Cint, x::Ptr{Float32}, - c::Ptr{Float32}, - g::Ptr{Float32}, + c::Ptr{Float32}, g::Ptr{Float32}, transpose::Ptr{Bool}, - u::Ptr{Float32}, - v::Ptr{Float32}, + u::Ptr{Float32}, v::Ptr{Float32}, y::Ptr{Float32}, p_ne::Cint, P_val::Ptr{Float32})::Cvoid end @@ -412,16 +364,14 @@ end export nls_solve_reverse_without_mat function nls_solve_reverse_without_mat(data, status, eval_status, n, m, x, c, g, transpose, - u, v, y, p_ne, P_val) + u, v, y, p_ne, P_val) @ccall libgalahad_double.nls_solve_reverse_without_mat(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, eval_status::Ptr{Cint}, n::Cint, m::Cint, x::Ptr{Float64}, - c::Ptr{Float64}, - g::Ptr{Float64}, + c::Ptr{Float64}, g::Ptr{Float64}, transpose::Ptr{Bool}, - u::Ptr{Float64}, - v::Ptr{Float64}, + u::Ptr{Float64}, v::Ptr{Float64}, y::Ptr{Float64}, p_ne::Cint, P_val::Ptr{Float64})::Cvoid end @@ -430,7 +380,7 @@ export nls_information_s function nls_information_s(data, inform, status) @ccall libgalahad_single.nls_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{nls_inform_type{Float32}}, + inform::Ptr{nls_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -438,7 +388,7 @@ export nls_information function nls_information(data, inform, status) @ccall libgalahad_double.nls_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{nls_inform_type{Float64}}, + inform::Ptr{nls_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -446,14 +396,14 @@ export nls_terminate_s function nls_terminate_s(data, control, inform) @ccall libgalahad_single.nls_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{nls_control_type{Float32}}, - inform::Ref{nls_inform_type{Float32}})::Cvoid + control::Ptr{nls_control_type{Float32}}, + inform::Ptr{nls_inform_type{Float32}})::Cvoid end export nls_terminate function nls_terminate(data, control, inform) @ccall libgalahad_double.nls_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{nls_control_type{Float64}}, - inform::Ref{nls_inform_type{Float64}})::Cvoid + control::Ptr{nls_control_type{Float64}}, + inform::Ptr{nls_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/presolve.jl b/GALAHAD.jl/src/wrappers/presolve.jl index 711c342c30..61f5d53a01 100644 --- a/GALAHAD.jl/src/wrappers/presolve.jl +++ b/GALAHAD.jl/src/wrappers/presolve.jl @@ -1,6 +1,6 @@ export presolve_control_type -mutable struct presolve_control_type{T} +struct presolve_control_type{T} f_indexing::Bool termination::Cint max_nbr_transforms::Cint @@ -38,27 +38,23 @@ mutable struct presolve_control_type{T} pivot_tol::T min_rel_improve::T max_growth_factor::T - - presolve_control_type{T}() where T = new() end export presolve_inform_type -mutable struct presolve_inform_type +struct presolve_inform_type status::Cint status_continue::Cint status_continued::Cint nbr_transforms::Cint message::NTuple{3,NTuple{81,Cchar}} - - presolve_inform_type() = new() end export presolve_initialize_s function presolve_initialize_s(data, control, status) @ccall libgalahad_single.presolve_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{presolve_control_type{Float32}}, + control::Ptr{presolve_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -66,31 +62,31 @@ export presolve_initialize function presolve_initialize(data, control, status) @ccall libgalahad_double.presolve_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{presolve_control_type{Float64}}, + control::Ptr{presolve_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export presolve_read_specfile_s function presolve_read_specfile_s(control, specfile) - @ccall libgalahad_single.presolve_read_specfile_s(control::Ref{presolve_control_type{Float32}}, + @ccall libgalahad_single.presolve_read_specfile_s(control::Ptr{presolve_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export presolve_read_specfile function presolve_read_specfile(control, specfile) - @ccall libgalahad_double.presolve_read_specfile(control::Ref{presolve_control_type{Float64}}, + @ccall libgalahad_double.presolve_read_specfile(control::Ptr{presolve_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export presolve_import_problem_s function presolve_import_problem_s(control, data, status, n, m, H_type, H_ne, H_row, H_col, - H_ptr, H_val, g, f, A_type, A_ne, A_row, A_col, A_ptr, - A_val, c_l, c_u, x_l, x_u, n_out, m_out, H_ne_out, - A_ne_out) - @ccall libgalahad_single.presolve_import_problem_s(control::Ref{presolve_control_type{Float32}}, + H_ptr, H_val, g, f, A_type, A_ne, A_row, A_col, A_ptr, + A_val, c_l, c_u, x_l, x_u, n_out, m_out, H_ne_out, + A_ne_out) + @ccall libgalahad_single.presolve_import_problem_s(control::Ptr{presolve_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, H_type::Ptr{Cchar}, H_ne::Cint, @@ -110,31 +106,30 @@ end export presolve_import_problem function presolve_import_problem(control, data, status, n, m, H_type, H_ne, H_row, H_col, - H_ptr, H_val, g, f, A_type, A_ne, A_row, A_col, A_ptr, - A_val, c_l, c_u, x_l, x_u, n_out, m_out, H_ne_out, - A_ne_out) - @ccall libgalahad_double.presolve_import_problem(control::Ref{presolve_control_type{Float64}}, - data::Ptr{Ptr{Cvoid}}, - status::Ptr{Cint}, n::Cint, m::Cint, - H_type::Ptr{Cchar}, H_ne::Cint, - H_row::Ptr{Cint}, H_col::Ptr{Cint}, - H_ptr::Ptr{Cint}, H_val::Ptr{Float64}, - g::Ptr{Float64}, f::Float64, - A_type::Ptr{Cchar}, A_ne::Cint, - A_row::Ptr{Cint}, A_col::Ptr{Cint}, - A_ptr::Ptr{Cint}, A_val::Ptr{Float64}, - c_l::Ptr{Float64}, c_u::Ptr{Float64}, - x_l::Ptr{Float64}, x_u::Ptr{Float64}, - n_out::Ptr{Cint}, m_out::Ptr{Cint}, - H_ne_out::Ptr{Cint}, + H_ptr, H_val, g, f, A_type, A_ne, A_row, A_col, A_ptr, + A_val, c_l, c_u, x_l, x_u, n_out, m_out, H_ne_out, + A_ne_out) + @ccall libgalahad_double.presolve_import_problem(control::Ptr{presolve_control_type{Float64}}, + data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, + n::Cint, m::Cint, H_type::Ptr{Cchar}, + H_ne::Cint, H_row::Ptr{Cint}, + H_col::Ptr{Cint}, H_ptr::Ptr{Cint}, + H_val::Ptr{Float64}, g::Ptr{Float64}, + f::Float64, A_type::Ptr{Cchar}, + A_ne::Cint, A_row::Ptr{Cint}, + A_col::Ptr{Cint}, A_ptr::Ptr{Cint}, + A_val::Ptr{Float64}, c_l::Ptr{Float64}, + c_u::Ptr{Float64}, x_l::Ptr{Float64}, + x_u::Ptr{Float64}, n_out::Ptr{Cint}, + m_out::Ptr{Cint}, H_ne_out::Ptr{Cint}, A_ne_out::Ptr{Cint})::Cvoid end export presolve_transform_problem_s function presolve_transform_problem_s(data, status, n, m, H_ne, H_col, H_ptr, H_val, g, f, - A_ne, A_col, A_ptr, A_val, c_l, c_u, x_l, x_u, y_l, y_u, - z_l, z_u) + A_ne, A_col, A_ptr, A_val, c_l, c_u, x_l, x_u, y_l, + y_u, z_l, z_u) @ccall libgalahad_single.presolve_transform_problem_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, H_ne::Cint, H_col::Ptr{Cint}, @@ -157,23 +152,18 @@ end export presolve_transform_problem function presolve_transform_problem(data, status, n, m, H_ne, H_col, H_ptr, H_val, g, f, - A_ne, A_col, A_ptr, A_val, c_l, c_u, x_l, x_u, y_l, y_u, - z_l, z_u) + A_ne, A_col, A_ptr, A_val, c_l, c_u, x_l, x_u, y_l, y_u, + z_l, z_u) @ccall libgalahad_double.presolve_transform_problem(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, H_ne::Cint, H_col::Ptr{Cint}, - H_ptr::Ptr{Cint}, - H_val::Ptr{Float64}, + H_ptr::Ptr{Cint}, H_val::Ptr{Float64}, g::Ptr{Float64}, f::Ptr{Float64}, A_ne::Cint, A_col::Ptr{Cint}, - A_ptr::Ptr{Cint}, - A_val::Ptr{Float64}, - c_l::Ptr{Float64}, - c_u::Ptr{Float64}, - x_l::Ptr{Float64}, - x_u::Ptr{Float64}, - y_l::Ptr{Float64}, - y_u::Ptr{Float64}, + A_ptr::Ptr{Cint}, A_val::Ptr{Float64}, + c_l::Ptr{Float64}, c_u::Ptr{Float64}, + x_l::Ptr{Float64}, x_u::Ptr{Float64}, + y_l::Ptr{Float64}, y_u::Ptr{Float64}, z_l::Ptr{Float64}, z_u::Ptr{Float64})::Cvoid end @@ -181,30 +171,29 @@ end export presolve_restore_solution_s function presolve_restore_solution_s(data, status, n_in, m_in, x_in, c_in, y_in, z_in, n, m, - x, c, y, z) + x, c, y, z) @ccall libgalahad_single.presolve_restore_solution_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n_in::Cint, m_in::Cint, x_in::Ptr{Float32}, c_in::Ptr{Float32}, y_in::Ptr{Float32}, - z_in::Ptr{Float32}, n::Cint, - m::Cint, x::Ptr{Float32}, - c::Ptr{Float32}, y::Ptr{Float32}, + z_in::Ptr{Float32}, n::Cint, m::Cint, + x::Ptr{Float32}, c::Ptr{Float32}, + y::Ptr{Float32}, z::Ptr{Float32})::Cvoid end export presolve_restore_solution function presolve_restore_solution(data, status, n_in, m_in, x_in, c_in, y_in, z_in, n, m, - x, c, y, z) + x, c, y, z) @ccall libgalahad_double.presolve_restore_solution(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n_in::Cint, m_in::Cint, x_in::Ptr{Float64}, - c_in::Ptr{Float64}, - y_in::Ptr{Float64}, - z_in::Ptr{Float64}, n::Cint, - m::Cint, x::Ptr{Float64}, - c::Ptr{Float64}, y::Ptr{Float64}, + c_in::Ptr{Float64}, y_in::Ptr{Float64}, + z_in::Ptr{Float64}, n::Cint, m::Cint, + x::Ptr{Float64}, c::Ptr{Float64}, + y::Ptr{Float64}, z::Ptr{Float64})::Cvoid end @@ -212,7 +201,7 @@ export presolve_information_s function presolve_information_s(data, inform, status) @ccall libgalahad_single.presolve_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{presolve_inform_type}, + inform::Ptr{presolve_inform_type}, status::Ptr{Cint})::Cvoid end @@ -220,7 +209,7 @@ export presolve_information function presolve_information(data, inform, status) @ccall libgalahad_double.presolve_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{presolve_inform_type}, + inform::Ptr{presolve_inform_type}, status::Ptr{Cint})::Cvoid end @@ -228,14 +217,14 @@ export presolve_terminate_s function presolve_terminate_s(data, control, inform) @ccall libgalahad_single.presolve_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{presolve_control_type{Float32}}, - inform::Ref{presolve_inform_type})::Cvoid + control::Ptr{presolve_control_type{Float32}}, + inform::Ptr{presolve_inform_type})::Cvoid end export presolve_terminate function presolve_terminate(data, control, inform) @ccall libgalahad_double.presolve_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{presolve_control_type{Float64}}, - inform::Ref{presolve_inform_type})::Cvoid + control::Ptr{presolve_control_type{Float64}}, + inform::Ptr{presolve_inform_type})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/psls.jl b/GALAHAD.jl/src/wrappers/psls.jl index f9df2e1700..254dd6e7da 100644 --- a/GALAHAD.jl/src/wrappers/psls.jl +++ b/GALAHAD.jl/src/wrappers/psls.jl @@ -1,6 +1,6 @@ export psls_control_type -mutable struct psls_control_type{T} +struct psls_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -23,18 +23,11 @@ mutable struct psls_control_type{T} prefix::NTuple{31,Cchar} sls_control::sls_control_type{T} mi28_control::mi28_control{T} - - function psls_control_type{T}() where T - type = new() - type.sls_control = sls_control_type{T}() - type.mi28_control = mi28_control{T}() - return type - end end export psls_time_type -mutable struct psls_time_type{T} +struct psls_time_type{T} total::Float32 assemble::Float32 analyse::Float32 @@ -47,13 +40,11 @@ mutable struct psls_time_type{T} clock_factorize::T clock_solve::T clock_update::T - - psls_time_type{T}() where T = new() end export psls_inform_type -mutable struct psls_inform_type{T} +struct psls_inform_type{T} status::Cint alloc_status::Cint analyse_status::Cint @@ -80,21 +71,13 @@ mutable struct psls_inform_type{T} time::psls_time_type{T} sls_inform::sls_inform_type{T} mi28_info::mi28_info{T} - - function psls_inform_type{T}() where T - type = new() - type.time = psls_time_type{T}() - type.sls_inform = sls_inform_type{T}() - type.mi28_info = mi28_info{T}() - return type - end end export psls_initialize_s function psls_initialize_s(data, control, status) @ccall libgalahad_single.psls_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{psls_control_type{Float32}}, + control::Ptr{psls_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -102,28 +85,28 @@ export psls_initialize function psls_initialize(data, control, status) @ccall libgalahad_double.psls_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{psls_control_type{Float64}}, + control::Ptr{psls_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export psls_read_specfile_s function psls_read_specfile_s(control, specfile) - @ccall libgalahad_single.psls_read_specfile_s(control::Ref{psls_control_type{Float32}}, + @ccall libgalahad_single.psls_read_specfile_s(control::Ptr{psls_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export psls_read_specfile function psls_read_specfile(control, specfile) - @ccall libgalahad_double.psls_read_specfile(control::Ref{psls_control_type{Float64}}, + @ccall libgalahad_double.psls_read_specfile(control::Ptr{psls_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export psls_import_s function psls_import_s(control, data, status, n, type, ne, row, col, ptr) - @ccall libgalahad_single.psls_import_s(control::Ref{psls_control_type{Float32}}, + @ccall libgalahad_single.psls_import_s(control::Ptr{psls_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, type::Ptr{Cchar}, ne::Cint, row::Ptr{Cint}, col::Ptr{Cint}, ptr::Ptr{Cint})::Cvoid @@ -132,7 +115,7 @@ end export psls_import function psls_import(control, data, status, n, type, ne, row, col, ptr) - @ccall libgalahad_double.psls_import(control::Ref{psls_control_type{Float64}}, + @ccall libgalahad_double.psls_import(control::Ptr{psls_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, type::Ptr{Cchar}, ne::Cint, row::Ptr{Cint}, col::Ptr{Cint}, ptr::Ptr{Cint})::Cvoid @@ -141,7 +124,7 @@ end export psls_reset_control_s function psls_reset_control_s(control, data, status) - @ccall libgalahad_single.psls_reset_control_s(control::Ref{psls_control_type{Float32}}, + @ccall libgalahad_single.psls_reset_control_s(control::Ptr{psls_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -149,7 +132,7 @@ end export psls_reset_control function psls_reset_control(control, data, status) - @ccall libgalahad_double.psls_reset_control(control::Ref{psls_control_type{Float64}}, + @ccall libgalahad_double.psls_reset_control(control::Ptr{psls_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -175,8 +158,7 @@ export psls_form_subset_preconditioner_s function psls_form_subset_preconditioner_s(data, status, ne, val, n_sub, sub) @ccall libgalahad_single.psls_form_subset_preconditioner_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, ne::Cint, - val::Ptr{Float32}, - n_sub::Cint, + val::Ptr{Float32}, n_sub::Cint, sub::Ptr{Cint})::Cvoid end @@ -185,8 +167,7 @@ export psls_form_subset_preconditioner function psls_form_subset_preconditioner(data, status, ne, val, n_sub, sub) @ccall libgalahad_double.psls_form_subset_preconditioner(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, ne::Cint, - val::Ptr{Float64}, - n_sub::Cint, + val::Ptr{Float64}, n_sub::Cint, sub::Ptr{Cint})::Cvoid end @@ -228,7 +209,7 @@ export psls_information_s function psls_information_s(data, inform, status) @ccall libgalahad_single.psls_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{psls_inform_type{Float32}}, + inform::Ptr{psls_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -236,7 +217,7 @@ export psls_information function psls_information(data, inform, status) @ccall libgalahad_double.psls_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{psls_inform_type{Float64}}, + inform::Ptr{psls_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -244,14 +225,14 @@ export psls_terminate_s function psls_terminate_s(data, control, inform) @ccall libgalahad_single.psls_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{psls_control_type{Float32}}, - inform::Ref{psls_inform_type{Float32}})::Cvoid + control::Ptr{psls_control_type{Float32}}, + inform::Ptr{psls_inform_type{Float32}})::Cvoid end export psls_terminate function psls_terminate(data, control, inform) @ccall libgalahad_double.psls_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{psls_control_type{Float64}}, - inform::Ref{psls_inform_type{Float64}})::Cvoid + control::Ptr{psls_control_type{Float64}}, + inform::Ptr{psls_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/qpa.jl b/GALAHAD.jl/src/wrappers/qpa.jl index e5fd0d6cbb..adeb6cc72b 100644 --- a/GALAHAD.jl/src/wrappers/qpa.jl +++ b/GALAHAD.jl/src/wrappers/qpa.jl @@ -1,6 +1,6 @@ export qpa_control_type -mutable struct qpa_control_type{T} +struct qpa_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -52,17 +52,11 @@ mutable struct qpa_control_type{T} prefix::NTuple{31,Cchar} each_interval::Bool sls_control::sls_control_type{T} - - function qpa_control_type{T}() where T - type = new() - type.sls_control = sls_control_type{T}() - return type - end end export qpa_time_type -mutable struct qpa_time_type{T} +struct qpa_time_type{T} total::T preprocess::T analyse::T @@ -73,13 +67,11 @@ mutable struct qpa_time_type{T} clock_analyse::T clock_factorize::T clock_solve::T - - qpa_time_type{T}() where T = new() end export qpa_inform_type -mutable struct qpa_inform_type{T} +struct qpa_inform_type{T} status::Cint alloc_status::Cint bad_alloc::NTuple{81,Cchar} @@ -99,20 +91,13 @@ mutable struct qpa_inform_type{T} merit::T time::qpa_time_type{T} sls_inform::sls_inform_type{T} - - function qpa_inform_type{T}() where T - type = new() - type.time = qpa_time_type{T}() - type.sls_inform = sls_inform_type{T}() - return type - end end export qpa_initialize_s function qpa_initialize_s(data, control, status) @ccall libgalahad_single.qpa_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{qpa_control_type{Float32}}, + control::Ptr{qpa_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -120,29 +105,29 @@ export qpa_initialize function qpa_initialize(data, control, status) @ccall libgalahad_double.qpa_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{qpa_control_type{Float64}}, + control::Ptr{qpa_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export qpa_read_specfile_s function qpa_read_specfile_s(control, specfile) - @ccall libgalahad_single.qpa_read_specfile_s(control::Ref{qpa_control_type{Float32}}, + @ccall libgalahad_single.qpa_read_specfile_s(control::Ptr{qpa_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export qpa_read_specfile function qpa_read_specfile(control, specfile) - @ccall libgalahad_double.qpa_read_specfile(control::Ref{qpa_control_type{Float64}}, + @ccall libgalahad_double.qpa_read_specfile(control::Ptr{qpa_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export qpa_import_s -function qpa_import_s(control, data, status, n, m, H_type, H_ne, H_row, H_col, H_ptr, A_type, - A_ne, A_row, A_col, A_ptr) - @ccall libgalahad_single.qpa_import_s(control::Ref{qpa_control_type{Float32}}, +function qpa_import_s(control, data, status, n, m, H_type, H_ne, H_row, H_col, H_ptr, + A_type, A_ne, A_row, A_col, A_ptr) + @ccall libgalahad_single.qpa_import_s(control::Ptr{qpa_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, H_type::Ptr{Cchar}, H_ne::Cint, H_row::Ptr{Cint}, H_col::Ptr{Cint}, @@ -154,20 +139,19 @@ end export qpa_import function qpa_import(control, data, status, n, m, H_type, H_ne, H_row, H_col, H_ptr, A_type, - A_ne, A_row, A_col, A_ptr) - @ccall libgalahad_double.qpa_import(control::Ref{qpa_control_type{Float64}}, + A_ne, A_row, A_col, A_ptr) + @ccall libgalahad_double.qpa_import(control::Ptr{qpa_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, H_type::Ptr{Cchar}, H_ne::Cint, - H_row::Ptr{Cint}, H_col::Ptr{Cint}, - H_ptr::Ptr{Cint}, A_type::Ptr{Cchar}, A_ne::Cint, - A_row::Ptr{Cint}, A_col::Ptr{Cint}, - A_ptr::Ptr{Cint})::Cvoid + H_row::Ptr{Cint}, H_col::Ptr{Cint}, H_ptr::Ptr{Cint}, + A_type::Ptr{Cchar}, A_ne::Cint, A_row::Ptr{Cint}, + A_col::Ptr{Cint}, A_ptr::Ptr{Cint})::Cvoid end export qpa_reset_control_s function qpa_reset_control_s(control, data, status) - @ccall libgalahad_single.qpa_reset_control_s(control::Ref{qpa_control_type{Float32}}, + @ccall libgalahad_single.qpa_reset_control_s(control::Ptr{qpa_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -175,7 +159,7 @@ end export qpa_reset_control function qpa_reset_control(control, data, status) - @ccall libgalahad_double.qpa_reset_control(control::Ref{qpa_control_type{Float64}}, + @ccall libgalahad_double.qpa_reset_control(control::Ptr{qpa_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -183,37 +167,35 @@ end export qpa_solve_qp_s function qpa_solve_qp_s(data, status, n, m, h_ne, H_val, g, f, a_ne, A_val, c_l, c_u, x_l, - x_u, x, c, y, z, x_stat, c_stat) + x_u, x, c, y, z, x_stat, c_stat) @ccall libgalahad_single.qpa_solve_qp_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, h_ne::Cint, H_val::Ptr{Float32}, g::Ptr{Float32}, f::Float32, a_ne::Cint, A_val::Ptr{Float32}, c_l::Ptr{Float32}, c_u::Ptr{Float32}, x_l::Ptr{Float32}, x_u::Ptr{Float32}, x::Ptr{Float32}, - c::Ptr{Float32}, y::Ptr{Float32}, - z::Ptr{Float32}, x_stat::Ptr{Cint}, - c_stat::Ptr{Cint})::Cvoid + c::Ptr{Float32}, y::Ptr{Float32}, z::Ptr{Float32}, + x_stat::Ptr{Cint}, c_stat::Ptr{Cint})::Cvoid end export qpa_solve_qp function qpa_solve_qp(data, status, n, m, h_ne, H_val, g, f, a_ne, A_val, c_l, c_u, x_l, - x_u, x, c, y, z, x_stat, c_stat) + x_u, x, c, y, z, x_stat, c_stat) @ccall libgalahad_double.qpa_solve_qp(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, h_ne::Cint, H_val::Ptr{Float64}, g::Ptr{Float64}, f::Float64, a_ne::Cint, A_val::Ptr{Float64}, c_l::Ptr{Float64}, c_u::Ptr{Float64}, x_l::Ptr{Float64}, - x_u::Ptr{Float64}, x::Ptr{Float64}, - c::Ptr{Float64}, y::Ptr{Float64}, - z::Ptr{Float64}, x_stat::Ptr{Cint}, + x_u::Ptr{Float64}, x::Ptr{Float64}, c::Ptr{Float64}, + y::Ptr{Float64}, z::Ptr{Float64}, x_stat::Ptr{Cint}, c_stat::Ptr{Cint})::Cvoid end export qpa_solve_l1qp_s function qpa_solve_l1qp_s(data, status, n, m, h_ne, H_val, g, f, rho_g, rho_b, a_ne, A_val, - c_l, c_u, x_l, x_u, x, c, y, z, x_stat, c_stat) + c_l, c_u, x_l, x_u, x, c, y, z, x_stat, c_stat) @ccall libgalahad_single.qpa_solve_l1qp_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, h_ne::Cint, H_val::Ptr{Float32}, g::Ptr{Float32}, @@ -229,23 +211,22 @@ end export qpa_solve_l1qp function qpa_solve_l1qp(data, status, n, m, h_ne, H_val, g, f, rho_g, rho_b, a_ne, A_val, - c_l, c_u, x_l, x_u, x, c, y, z, x_stat, c_stat) - @ccall libgalahad_double.qpa_solve_l1qp(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, - n::Cint, m::Cint, h_ne::Cint, - H_val::Ptr{Float64}, g::Ptr{Float64}, - f::Float64, rho_g::Float64, rho_b::Float64, - a_ne::Cint, A_val::Ptr{Float64}, + c_l, c_u, x_l, x_u, x, c, y, z, x_stat, c_stat) + @ccall libgalahad_double.qpa_solve_l1qp(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, + m::Cint, h_ne::Cint, H_val::Ptr{Float64}, + g::Ptr{Float64}, f::Float64, rho_g::Float64, + rho_b::Float64, a_ne::Cint, A_val::Ptr{Float64}, c_l::Ptr{Float64}, c_u::Ptr{Float64}, x_l::Ptr{Float64}, x_u::Ptr{Float64}, - x::Ptr{Float64}, c::Ptr{Float64}, - y::Ptr{Float64}, z::Ptr{Float64}, - x_stat::Ptr{Cint}, c_stat::Ptr{Cint})::Cvoid + x::Ptr{Float64}, c::Ptr{Float64}, y::Ptr{Float64}, + z::Ptr{Float64}, x_stat::Ptr{Cint}, + c_stat::Ptr{Cint})::Cvoid end export qpa_solve_bcl1qp_s function qpa_solve_bcl1qp_s(data, status, n, m, h_ne, H_val, g, f, rho_g, a_ne, A_val, c_l, - c_u, x_l, x_u, x, c, y, z, x_stat, c_stat) + c_u, x_l, x_u, x, c, y, z, x_stat, c_stat) @ccall libgalahad_single.qpa_solve_bcl1qp_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, h_ne::Cint, H_val::Ptr{Float32}, g::Ptr{Float32}, @@ -261,7 +242,7 @@ end export qpa_solve_bcl1qp function qpa_solve_bcl1qp(data, status, n, m, h_ne, H_val, g, f, rho_g, a_ne, A_val, c_l, - c_u, x_l, x_u, x, c, y, z, x_stat, c_stat) + c_u, x_l, x_u, x, c, y, z, x_stat, c_stat) @ccall libgalahad_double.qpa_solve_bcl1qp(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, h_ne::Cint, H_val::Ptr{Float64}, g::Ptr{Float64}, @@ -278,7 +259,7 @@ export qpa_information_s function qpa_information_s(data, inform, status) @ccall libgalahad_single.qpa_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{qpa_inform_type{Float32}}, + inform::Ptr{qpa_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -286,7 +267,7 @@ export qpa_information function qpa_information(data, inform, status) @ccall libgalahad_double.qpa_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{qpa_inform_type{Float64}}, + inform::Ptr{qpa_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -294,14 +275,14 @@ export qpa_terminate_s function qpa_terminate_s(data, control, inform) @ccall libgalahad_single.qpa_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{qpa_control_type{Float32}}, - inform::Ref{qpa_inform_type{Float32}})::Cvoid + control::Ptr{qpa_control_type{Float32}}, + inform::Ptr{qpa_inform_type{Float32}})::Cvoid end export qpa_terminate function qpa_terminate(data, control, inform) @ccall libgalahad_double.qpa_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{qpa_control_type{Float64}}, - inform::Ref{qpa_inform_type{Float64}})::Cvoid + control::Ptr{qpa_control_type{Float64}}, + inform::Ptr{qpa_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/qpb.jl b/GALAHAD.jl/src/wrappers/qpb.jl index a6d882f4f7..d40230a93d 100644 --- a/GALAHAD.jl/src/wrappers/qpb.jl +++ b/GALAHAD.jl/src/wrappers/qpb.jl @@ -1,6 +1,6 @@ export qpb_control_type -mutable struct qpb_control_type{T} +struct qpb_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -67,21 +67,11 @@ mutable struct qpb_control_type{T} sbls_control::sbls_control_type{T} gltr_control::gltr_control_type{T} fit_control::fit_control_type - - function qpb_control_type{T}() where T - type = new() - type.lsqp_control = lsqp_control_type{T}() - type.fdc_control = fdc_control_type{T}() - type.sbls_control = sbls_control_type{T}() - type.gltr_control = gltr_control_type{T}() - type.fit_control = fit_control_type() - return type - end end export qpb_time_type -mutable struct qpb_time_type{T} +struct qpb_time_type{T} total::T preprocess::T find_dependent::T @@ -102,13 +92,11 @@ mutable struct qpb_time_type{T} clock_phase1_analyse::T clock_phase1_factorize::T clock_phase1_solve::T - - qpb_time_type{T}() where T = new() end export qpb_inform_type -mutable struct qpb_inform_type{T} +struct qpb_inform_type{T} status::Cint alloc_status::Cint bad_alloc::NTuple{81,Cchar} @@ -129,24 +117,13 @@ mutable struct qpb_inform_type{T} sbls_inform::sbls_inform_type{T} gltr_inform::gltr_inform_type{T} fit_inform::fit_inform_type - - function qpb_inform_type{T}() where T - type = new() - type.time = qpb_time_type{T}() - type.lsqp_inform = lsqp_inform_type{T}() - type.fdc_inform = fdc_inform_type{T}() - type.sbls_inform = sbls_inform_type{T}() - type.gltr_inform = gltr_inform_type{T}() - type.fit_inform = fit_inform_type() - return type - end end export qpb_initialize_s function qpb_initialize_s(data, control, status) @ccall libgalahad_single.qpb_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{qpb_control_type{Float32}}, + control::Ptr{qpb_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -154,29 +131,29 @@ export qpb_initialize function qpb_initialize(data, control, status) @ccall libgalahad_double.qpb_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{qpb_control_type{Float64}}, + control::Ptr{qpb_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export qpb_read_specfile_s function qpb_read_specfile_s(control, specfile) - @ccall libgalahad_single.qpb_read_specfile_s(control::Ref{qpb_control_type{Float32}}, + @ccall libgalahad_single.qpb_read_specfile_s(control::Ptr{qpb_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export qpb_read_specfile function qpb_read_specfile(control, specfile) - @ccall libgalahad_double.qpb_read_specfile(control::Ref{qpb_control_type{Float64}}, + @ccall libgalahad_double.qpb_read_specfile(control::Ptr{qpb_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export qpb_import_s -function qpb_import_s(control, data, status, n, m, H_type, H_ne, H_row, H_col, H_ptr, A_type, - A_ne, A_row, A_col, A_ptr) - @ccall libgalahad_single.qpb_import_s(control::Ref{qpb_control_type{Float32}}, +function qpb_import_s(control, data, status, n, m, H_type, H_ne, H_row, H_col, H_ptr, + A_type, A_ne, A_row, A_col, A_ptr) + @ccall libgalahad_single.qpb_import_s(control::Ptr{qpb_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, H_type::Ptr{Cchar}, H_ne::Cint, H_row::Ptr{Cint}, H_col::Ptr{Cint}, @@ -188,20 +165,19 @@ end export qpb_import function qpb_import(control, data, status, n, m, H_type, H_ne, H_row, H_col, H_ptr, A_type, - A_ne, A_row, A_col, A_ptr) - @ccall libgalahad_double.qpb_import(control::Ref{qpb_control_type{Float64}}, + A_ne, A_row, A_col, A_ptr) + @ccall libgalahad_double.qpb_import(control::Ptr{qpb_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, H_type::Ptr{Cchar}, H_ne::Cint, - H_row::Ptr{Cint}, H_col::Ptr{Cint}, - H_ptr::Ptr{Cint}, A_type::Ptr{Cchar}, A_ne::Cint, - A_row::Ptr{Cint}, A_col::Ptr{Cint}, - A_ptr::Ptr{Cint})::Cvoid + H_row::Ptr{Cint}, H_col::Ptr{Cint}, H_ptr::Ptr{Cint}, + A_type::Ptr{Cchar}, A_ne::Cint, A_row::Ptr{Cint}, + A_col::Ptr{Cint}, A_ptr::Ptr{Cint})::Cvoid end export qpb_reset_control_s function qpb_reset_control_s(control, data, status) - @ccall libgalahad_single.qpb_reset_control_s(control::Ref{qpb_control_type{Float32}}, + @ccall libgalahad_single.qpb_reset_control_s(control::Ptr{qpb_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -209,7 +185,7 @@ end export qpb_reset_control function qpb_reset_control(control, data, status) - @ccall libgalahad_double.qpb_reset_control(control::Ref{qpb_control_type{Float64}}, + @ccall libgalahad_double.qpb_reset_control(control::Ptr{qpb_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -217,30 +193,28 @@ end export qpb_solve_qp_s function qpb_solve_qp_s(data, status, n, m, h_ne, H_val, g, f, a_ne, A_val, c_l, c_u, x_l, - x_u, x, c, y, z, x_stat, c_stat) + x_u, x, c, y, z, x_stat, c_stat) @ccall libgalahad_single.qpb_solve_qp_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, h_ne::Cint, H_val::Ptr{Float32}, g::Ptr{Float32}, f::Float32, a_ne::Cint, A_val::Ptr{Float32}, c_l::Ptr{Float32}, c_u::Ptr{Float32}, x_l::Ptr{Float32}, x_u::Ptr{Float32}, x::Ptr{Float32}, - c::Ptr{Float32}, y::Ptr{Float32}, - z::Ptr{Float32}, x_stat::Ptr{Cint}, - c_stat::Ptr{Cint})::Cvoid + c::Ptr{Float32}, y::Ptr{Float32}, z::Ptr{Float32}, + x_stat::Ptr{Cint}, c_stat::Ptr{Cint})::Cvoid end export qpb_solve_qp function qpb_solve_qp(data, status, n, m, h_ne, H_val, g, f, a_ne, A_val, c_l, c_u, x_l, - x_u, x, c, y, z, x_stat, c_stat) + x_u, x, c, y, z, x_stat, c_stat) @ccall libgalahad_double.qpb_solve_qp(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, h_ne::Cint, H_val::Ptr{Float64}, g::Ptr{Float64}, f::Float64, a_ne::Cint, A_val::Ptr{Float64}, c_l::Ptr{Float64}, c_u::Ptr{Float64}, x_l::Ptr{Float64}, - x_u::Ptr{Float64}, x::Ptr{Float64}, - c::Ptr{Float64}, y::Ptr{Float64}, - z::Ptr{Float64}, x_stat::Ptr{Cint}, + x_u::Ptr{Float64}, x::Ptr{Float64}, c::Ptr{Float64}, + y::Ptr{Float64}, z::Ptr{Float64}, x_stat::Ptr{Cint}, c_stat::Ptr{Cint})::Cvoid end @@ -248,7 +222,7 @@ export qpb_information_s function qpb_information_s(data, inform, status) @ccall libgalahad_single.qpb_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{qpb_inform_type{Float32}}, + inform::Ptr{qpb_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -256,7 +230,7 @@ export qpb_information function qpb_information(data, inform, status) @ccall libgalahad_double.qpb_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{qpb_inform_type{Float64}}, + inform::Ptr{qpb_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -264,14 +238,14 @@ export qpb_terminate_s function qpb_terminate_s(data, control, inform) @ccall libgalahad_single.qpb_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{qpb_control_type{Float32}}, - inform::Ref{qpb_inform_type{Float32}})::Cvoid + control::Ptr{qpb_control_type{Float32}}, + inform::Ptr{qpb_inform_type{Float32}})::Cvoid end export qpb_terminate function qpb_terminate(data, control, inform) @ccall libgalahad_double.qpb_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{qpb_control_type{Float64}}, - inform::Ref{qpb_inform_type{Float64}})::Cvoid + control::Ptr{qpb_control_type{Float64}}, + inform::Ptr{qpb_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/roots.jl b/GALAHAD.jl/src/wrappers/roots.jl index 2c76b0b31d..0adf117d17 100644 --- a/GALAHAD.jl/src/wrappers/roots.jl +++ b/GALAHAD.jl/src/wrappers/roots.jl @@ -1,6 +1,6 @@ export roots_control_type -mutable struct roots_control_type{T} +struct roots_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -11,25 +11,21 @@ mutable struct roots_control_type{T} space_critical::Bool deallocate_error_fatal::Bool prefix::NTuple{31,Cchar} - - roots_control_type{T}() where T = new() end export roots_inform_type -mutable struct roots_inform_type +struct roots_inform_type status::Cint alloc_status::Cint bad_alloc::NTuple{81,Cchar} - - roots_inform_type() = new() end export roots_initialize_s function roots_initialize_s(data, control, status) @ccall libgalahad_single.roots_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{roots_control_type{Float32}}, + control::Ptr{roots_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -37,7 +33,7 @@ export roots_initialize function roots_initialize(data, control, status) @ccall libgalahad_double.roots_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{roots_control_type{Float64}}, + control::Ptr{roots_control_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -45,7 +41,7 @@ export roots_information_s function roots_information_s(data, inform, status) @ccall libgalahad_single.roots_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{roots_inform_type}, + inform::Ptr{roots_inform_type}, status::Ptr{Cint})::Cvoid end @@ -53,7 +49,7 @@ export roots_information function roots_information(data, inform, status) @ccall libgalahad_double.roots_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{roots_inform_type}, + inform::Ptr{roots_inform_type}, status::Ptr{Cint})::Cvoid end @@ -61,14 +57,14 @@ export roots_terminate_s function roots_terminate_s(data, control, inform) @ccall libgalahad_single.roots_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{roots_control_type{Float32}}, - inform::Ref{roots_inform_type})::Cvoid + control::Ptr{roots_control_type{Float32}}, + inform::Ptr{roots_inform_type})::Cvoid end export roots_terminate function roots_terminate(data, control, inform) @ccall libgalahad_double.roots_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{roots_control_type{Float64}}, - inform::Ref{roots_inform_type})::Cvoid + control::Ptr{roots_control_type{Float64}}, + inform::Ptr{roots_inform_type})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/rpd.jl b/GALAHAD.jl/src/wrappers/rpd.jl index 6f153dddf5..c28c2de861 100644 --- a/GALAHAD.jl/src/wrappers/rpd.jl +++ b/GALAHAD.jl/src/wrappers/rpd.jl @@ -1,6 +1,6 @@ export rpd_control_type -mutable struct rpd_control_type +struct rpd_control_type f_indexing::Bool qplib::Cint error::Cint @@ -8,28 +8,24 @@ mutable struct rpd_control_type print_level::Cint space_critical::Bool deallocate_error_fatal::Bool - - rpd_control_type() = new() end export rpd_inform_type -mutable struct rpd_inform_type +struct rpd_inform_type status::Cint alloc_status::Cint bad_alloc::NTuple{81,Cchar} io_status::Cint line::Cint p_type::NTuple{4,Cchar} - - rpd_inform_type() = new() end export rpd_initialize_s function rpd_initialize_s(data, control, status) @ccall libgalahad_single.rpd_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{rpd_control_type}, + control::Ptr{rpd_control_type}, status::Ptr{Cint})::Cvoid end @@ -37,16 +33,16 @@ export rpd_initialize function rpd_initialize(data, control, status) @ccall libgalahad_double.rpd_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{rpd_control_type}, + control::Ptr{rpd_control_type}, status::Ptr{Cint})::Cvoid end export rpd_get_stats_s function rpd_get_stats_s(qplib_file, qplib_file_len, control, data, status, p_type, n, m, - h_ne, a_ne, h_c_ne) + h_ne, a_ne, h_c_ne) @ccall libgalahad_single.rpd_get_stats_s(qplib_file::Ptr{Cchar}, qplib_file_len::Cint, - control::Ref{rpd_control_type}, + control::Ptr{rpd_control_type}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, p_type::Ptr{Cchar}, n::Ptr{Cint}, m::Ptr{Cint}, h_ne::Ptr{Cint}, a_ne::Ptr{Cint}, @@ -56,9 +52,9 @@ end export rpd_get_stats function rpd_get_stats(qplib_file, qplib_file_len, control, data, status, p_type, n, m, - h_ne, a_ne, h_c_ne) + h_ne, a_ne, h_c_ne) @ccall libgalahad_double.rpd_get_stats(qplib_file::Ptr{Cchar}, qplib_file_len::Cint, - control::Ref{rpd_control_type}, + control::Ptr{rpd_control_type}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, p_type::Ptr{Cchar}, n::Ptr{Cint}, m::Ptr{Cint}, h_ne::Ptr{Cint}, a_ne::Ptr{Cint}, @@ -166,9 +162,8 @@ export rpd_get_h_c function rpd_get_h_c(data, status, h_c_ne, h_c_ptr, h_c_row, h_c_col, h_c_val) @ccall libgalahad_double.rpd_get_h_c(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, - h_c_ne::Cint, h_c_ptr::Ptr{Cint}, - h_c_row::Ptr{Cint}, h_c_col::Ptr{Cint}, - h_c_val::Ptr{Float64})::Cvoid + h_c_ne::Cint, h_c_ptr::Ptr{Cint}, h_c_row::Ptr{Cint}, + h_c_col::Ptr{Cint}, h_c_val::Ptr{Float64})::Cvoid end export rpd_get_x_type_s @@ -181,8 +176,8 @@ end export rpd_get_x_type function rpd_get_x_type(data, status, n, x_type) - @ccall libgalahad_double.rpd_get_x_type(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, - n::Cint, x_type::Ptr{Cint})::Cvoid + @ccall libgalahad_double.rpd_get_x_type(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, + x_type::Ptr{Cint})::Cvoid end export rpd_get_x_s @@ -231,7 +226,7 @@ export rpd_information_s function rpd_information_s(data, inform, status) @ccall libgalahad_single.rpd_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{rpd_inform_type}, + inform::Ptr{rpd_inform_type}, status::Ptr{Cint})::Cvoid end @@ -239,7 +234,7 @@ export rpd_information function rpd_information(data, inform, status) @ccall libgalahad_double.rpd_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{rpd_inform_type}, + inform::Ptr{rpd_inform_type}, status::Ptr{Cint})::Cvoid end @@ -247,14 +242,14 @@ export rpd_terminate_s function rpd_terminate_s(data, control, inform) @ccall libgalahad_single.rpd_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{rpd_control_type}, - inform::Ref{rpd_inform_type})::Cvoid + control::Ptr{rpd_control_type}, + inform::Ptr{rpd_inform_type})::Cvoid end export rpd_terminate function rpd_terminate(data, control, inform) @ccall libgalahad_double.rpd_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{rpd_control_type}, - inform::Ref{rpd_inform_type})::Cvoid + control::Ptr{rpd_control_type}, + inform::Ptr{rpd_inform_type})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/rqs.jl b/GALAHAD.jl/src/wrappers/rqs.jl index da86c87d63..050d3c91a6 100644 --- a/GALAHAD.jl/src/wrappers/rqs.jl +++ b/GALAHAD.jl/src/wrappers/rqs.jl @@ -1,6 +1,6 @@ export rqs_control_type -mutable struct rqs_control_type{T} +struct rqs_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -30,18 +30,11 @@ mutable struct rqs_control_type{T} prefix::NTuple{31,Cchar} sls_control::sls_control_type{T} ir_control::ir_control_type{T} - - function rqs_control_type{T}() where T - type = new() - type.sls_control = sls_control_type{T}() - type.ir_control = ir_control_type{T}() - return type - end end export rqs_time_type -mutable struct rqs_time_type{T} +struct rqs_time_type{T} total::T assemble::T analyse::T @@ -52,22 +45,18 @@ mutable struct rqs_time_type{T} clock_analyse::T clock_factorize::T clock_solve::T - - rqs_time_type{T}() where T = new() end export rqs_history_type -mutable struct rqs_history_type{T} +struct rqs_history_type{T} lambda::T x_norm::T - - rqs_history_type{T}() where T = new() end export rqs_inform_type -mutable struct rqs_inform_type{T} +struct rqs_inform_type{T} status::Cint alloc_status::Cint factorizations::Cint @@ -82,25 +71,16 @@ mutable struct rqs_inform_type{T} hard_case::Bool bad_alloc::NTuple{81,Cchar} time::rqs_time_type{T} - history::NTuple{100,rqs_history_type{T}} + history::NTuple{100,rqs_history_type} sls_inform::sls_inform_type{T} ir_inform::ir_inform_type{T} - - function rqs_inform_type{T}() where T - type = new() - type.time = rqs_time_type{T}() - type.history = ntuple(x -> rqs_history_type{T}(), 100) - type.sls_inform = sls_inform_type{T}() - type.ir_inform = ir_inform_type{T}() - return type - end end export rqs_initialize_s function rqs_initialize_s(data, control, status) @ccall libgalahad_single.rqs_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{rqs_control_type{Float32}}, + control::Ptr{rqs_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -108,28 +88,28 @@ export rqs_initialize function rqs_initialize(data, control, status) @ccall libgalahad_double.rqs_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{rqs_control_type{Float64}}, + control::Ptr{rqs_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export rqs_read_specfile_s function rqs_read_specfile_s(control, specfile) - @ccall libgalahad_single.rqs_read_specfile_s(control::Ref{rqs_control_type{Float32}}, + @ccall libgalahad_single.rqs_read_specfile_s(control::Ptr{rqs_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export rqs_read_specfile function rqs_read_specfile(control, specfile) - @ccall libgalahad_double.rqs_read_specfile(control::Ref{rqs_control_type{Float64}}, + @ccall libgalahad_double.rqs_read_specfile(control::Ptr{rqs_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export rqs_import_s function rqs_import_s(control, data, status, n, H_type, H_ne, H_row, H_col, H_ptr) - @ccall libgalahad_single.rqs_import_s(control::Ref{rqs_control_type{Float32}}, + @ccall libgalahad_single.rqs_import_s(control::Ptr{rqs_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, H_type::Ptr{Cchar}, H_ne::Cint, H_row::Ptr{Cint}, H_col::Ptr{Cint}, H_ptr::Ptr{Cint})::Cvoid @@ -138,7 +118,7 @@ end export rqs_import function rqs_import(control, data, status, n, H_type, H_ne, H_row, H_col, H_ptr) - @ccall libgalahad_double.rqs_import(control::Ref{rqs_control_type{Float64}}, + @ccall libgalahad_double.rqs_import(control::Ptr{rqs_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, H_type::Ptr{Cchar}, H_ne::Cint, H_row::Ptr{Cint}, H_col::Ptr{Cint}, H_ptr::Ptr{Cint})::Cvoid @@ -179,7 +159,7 @@ end export rqs_reset_control_s function rqs_reset_control_s(control, data, status) - @ccall libgalahad_single.rqs_reset_control_s(control::Ref{rqs_control_type{Float32}}, + @ccall libgalahad_single.rqs_reset_control_s(control::Ptr{rqs_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -187,7 +167,7 @@ end export rqs_reset_control function rqs_reset_control(control, data, status) - @ccall libgalahad_double.rqs_reset_control(control::Ref{rqs_control_type{Float64}}, + @ccall libgalahad_double.rqs_reset_control(control::Ptr{rqs_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -195,7 +175,7 @@ end export rqs_solve_problem_s function rqs_solve_problem_s(data, status, n, power, weight, f, c, H_ne, H_val, x, M_ne, - M_val, m, A_ne, A_val, y) + M_val, m, A_ne, A_val, y) @ccall libgalahad_single.rqs_solve_problem_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, power::Float32, weight::Float32, f::Float32, c::Ptr{Float32}, H_ne::Cint, @@ -208,7 +188,7 @@ end export rqs_solve_problem function rqs_solve_problem(data, status, n, power, weight, f, c, H_ne, H_val, x, M_ne, - M_val, m, A_ne, A_val, y) + M_val, m, A_ne, A_val, y) @ccall libgalahad_double.rqs_solve_problem(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, power::Float64, weight::Float64, f::Float64, c::Ptr{Float64}, H_ne::Cint, @@ -222,7 +202,7 @@ export rqs_information_s function rqs_information_s(data, inform, status) @ccall libgalahad_single.rqs_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{rqs_inform_type{Float32}}, + inform::Ptr{rqs_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -230,7 +210,7 @@ export rqs_information function rqs_information(data, inform, status) @ccall libgalahad_double.rqs_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{rqs_inform_type{Float64}}, + inform::Ptr{rqs_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -238,14 +218,14 @@ export rqs_terminate_s function rqs_terminate_s(data, control, inform) @ccall libgalahad_single.rqs_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{rqs_control_type{Float32}}, - inform::Ref{rqs_inform_type{Float32}})::Cvoid + control::Ptr{rqs_control_type{Float32}}, + inform::Ptr{rqs_inform_type{Float32}})::Cvoid end export rqs_terminate function rqs_terminate(data, control, inform) @ccall libgalahad_double.rqs_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{rqs_control_type{Float64}}, - inform::Ref{rqs_inform_type{Float64}})::Cvoid + control::Ptr{rqs_control_type{Float64}}, + inform::Ptr{rqs_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/sbls.jl b/GALAHAD.jl/src/wrappers/sbls.jl index b64a9206a8..0770510947 100644 --- a/GALAHAD.jl/src/wrappers/sbls.jl +++ b/GALAHAD.jl/src/wrappers/sbls.jl @@ -1,6 +1,6 @@ export sbls_control_type -mutable struct sbls_control_type{T} +struct sbls_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -42,18 +42,11 @@ mutable struct sbls_control_type{T} prefix::NTuple{31,Cchar} sls_control::sls_control_type{T} uls_control::uls_control_type{T} - - function sbls_control_type{T}() where T - type = new() - type.sls_control = sls_control_type{T}() - type.uls_control = uls_control_type{T}() - return type - end end export sbls_time_type -mutable struct sbls_time_type{T} +struct sbls_time_type{T} total::T form::T factorize::T @@ -62,13 +55,11 @@ mutable struct sbls_time_type{T} clock_form::T clock_factorize::T clock_apply::T - - sbls_time_type{T}() where T = new() end export sbls_inform_type -mutable struct sbls_inform_type{T} +struct sbls_inform_type{T} status::Cint alloc_status::Cint bad_alloc::NTuple{81,Cchar} @@ -87,21 +78,13 @@ mutable struct sbls_inform_type{T} time::sbls_time_type{T} sls_inform::sls_inform_type{T} uls_inform::uls_inform_type{T} - - function sbls_inform_type{T}() where T - type = new() - type.time = sbls_time_type{T}() - type.sls_inform = sls_inform_type{T}() - type.uls_inform = uls_inform_type{T}() - return type - end end export sbls_initialize_s function sbls_initialize_s(data, control, status) @ccall libgalahad_single.sbls_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{sbls_control_type{Float32}}, + control::Ptr{sbls_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -109,29 +92,29 @@ export sbls_initialize function sbls_initialize(data, control, status) @ccall libgalahad_double.sbls_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{sbls_control_type{Float64}}, + control::Ptr{sbls_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export sbls_read_specfile_s function sbls_read_specfile_s(control, specfile) - @ccall libgalahad_single.sbls_read_specfile_s(control::Ref{sbls_control_type{Float32}}, + @ccall libgalahad_single.sbls_read_specfile_s(control::Ptr{sbls_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export sbls_read_specfile function sbls_read_specfile(control, specfile) - @ccall libgalahad_double.sbls_read_specfile(control::Ref{sbls_control_type{Float64}}, + @ccall libgalahad_double.sbls_read_specfile(control::Ptr{sbls_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export sbls_import_s -function sbls_import_s(control, data, status, n, m, H_type, H_ne, H_row, H_col, H_ptr, A_type, - A_ne, A_row, A_col, A_ptr, C_type, C_ne, C_row, C_col, C_ptr) - @ccall libgalahad_single.sbls_import_s(control::Ref{sbls_control_type{Float32}}, +function sbls_import_s(control, data, status, n, m, H_type, H_ne, H_row, H_col, H_ptr, + A_type, A_ne, A_row, A_col, A_ptr, C_type, C_ne, C_row, C_col, C_ptr) + @ccall libgalahad_single.sbls_import_s(control::Ptr{sbls_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, H_type::Ptr{Cchar}, H_ne::Cint, H_row::Ptr{Cint}, H_col::Ptr{Cint}, @@ -145,22 +128,21 @@ end export sbls_import function sbls_import(control, data, status, n, m, H_type, H_ne, H_row, H_col, H_ptr, A_type, - A_ne, A_row, A_col, A_ptr, C_type, C_ne, C_row, C_col, C_ptr) - @ccall libgalahad_double.sbls_import(control::Ref{sbls_control_type{Float64}}, + A_ne, A_row, A_col, A_ptr, C_type, C_ne, C_row, C_col, C_ptr) + @ccall libgalahad_double.sbls_import(control::Ptr{sbls_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, H_type::Ptr{Cchar}, H_ne::Cint, - H_row::Ptr{Cint}, H_col::Ptr{Cint}, - H_ptr::Ptr{Cint}, A_type::Ptr{Cchar}, A_ne::Cint, - A_row::Ptr{Cint}, A_col::Ptr{Cint}, - A_ptr::Ptr{Cint}, C_type::Ptr{Cchar}, C_ne::Cint, - C_row::Ptr{Cint}, C_col::Ptr{Cint}, - C_ptr::Ptr{Cint})::Cvoid + H_row::Ptr{Cint}, H_col::Ptr{Cint}, H_ptr::Ptr{Cint}, + A_type::Ptr{Cchar}, A_ne::Cint, A_row::Ptr{Cint}, + A_col::Ptr{Cint}, A_ptr::Ptr{Cint}, + C_type::Ptr{Cchar}, C_ne::Cint, C_row::Ptr{Cint}, + C_col::Ptr{Cint}, C_ptr::Ptr{Cint})::Cvoid end export sbls_reset_control_s function sbls_reset_control_s(control, data, status) - @ccall libgalahad_single.sbls_reset_control_s(control::Ref{sbls_control_type{Float32}}, + @ccall libgalahad_single.sbls_reset_control_s(control::Ptr{sbls_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -168,7 +150,7 @@ end export sbls_reset_control function sbls_reset_control(control, data, status) - @ccall libgalahad_double.sbls_reset_control(control::Ref{sbls_control_type{Float64}}, + @ccall libgalahad_double.sbls_reset_control(control::Ptr{sbls_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -177,10 +159,9 @@ export sbls_factorize_matrix_s function sbls_factorize_matrix_s(data, status, n, h_ne, H_val, a_ne, A_val, c_ne, C_val, D) @ccall libgalahad_single.sbls_factorize_matrix_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, - n::Cint, h_ne::Cint, - H_val::Ptr{Float32}, a_ne::Cint, - A_val::Ptr{Float32}, c_ne::Cint, - C_val::Ptr{Float32}, + n::Cint, h_ne::Cint, H_val::Ptr{Float32}, + a_ne::Cint, A_val::Ptr{Float32}, + c_ne::Cint, C_val::Ptr{Float32}, D::Ptr{Float32})::Cvoid end @@ -188,10 +169,9 @@ export sbls_factorize_matrix function sbls_factorize_matrix(data, status, n, h_ne, H_val, a_ne, A_val, c_ne, C_val, D) @ccall libgalahad_double.sbls_factorize_matrix(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, - n::Cint, h_ne::Cint, - H_val::Ptr{Float64}, a_ne::Cint, - A_val::Ptr{Float64}, c_ne::Cint, - C_val::Ptr{Float64}, + n::Cint, h_ne::Cint, H_val::Ptr{Float64}, + a_ne::Cint, A_val::Ptr{Float64}, + c_ne::Cint, C_val::Ptr{Float64}, D::Ptr{Float64})::Cvoid end @@ -213,7 +193,7 @@ export sbls_information_s function sbls_information_s(data, inform, status) @ccall libgalahad_single.sbls_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{sbls_inform_type{Float32}}, + inform::Ptr{sbls_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -221,7 +201,7 @@ export sbls_information function sbls_information(data, inform, status) @ccall libgalahad_double.sbls_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{sbls_inform_type{Float64}}, + inform::Ptr{sbls_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -229,14 +209,14 @@ export sbls_terminate_s function sbls_terminate_s(data, control, inform) @ccall libgalahad_single.sbls_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{sbls_control_type{Float32}}, - inform::Ref{sbls_inform_type{Float32}})::Cvoid + control::Ptr{sbls_control_type{Float32}}, + inform::Ptr{sbls_inform_type{Float32}})::Cvoid end export sbls_terminate function sbls_terminate(data, control, inform) @ccall libgalahad_double.sbls_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{sbls_control_type{Float64}}, - inform::Ref{sbls_inform_type{Float64}})::Cvoid + control::Ptr{sbls_control_type{Float64}}, + inform::Ptr{sbls_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/scu.jl b/GALAHAD.jl/src/wrappers/scu.jl index a74610963e..1b8116f46a 100644 --- a/GALAHAD.jl/src/wrappers/scu.jl +++ b/GALAHAD.jl/src/wrappers/scu.jl @@ -1,26 +1,22 @@ export scu_control_type -mutable struct scu_control_type +struct scu_control_type f_indexing::Bool - - scu_control_type() = new() end export scu_inform_type -mutable struct scu_inform_type +struct scu_inform_type status::Cint alloc_status::Cint inertia::NTuple{3,Cint} - - scu_inform_type() = new() end export scu_information_s function scu_information_s(data, inform, status) @ccall libgalahad_single.scu_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{scu_inform_type}, + inform::Ptr{scu_inform_type}, status::Ptr{Cint})::Cvoid end @@ -28,7 +24,7 @@ export scu_information function scu_information(data, inform, status) @ccall libgalahad_double.scu_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{scu_inform_type}, + inform::Ptr{scu_inform_type}, status::Ptr{Cint})::Cvoid end @@ -36,14 +32,14 @@ export scu_terminate_s function scu_terminate_s(data, control, inform) @ccall libgalahad_single.scu_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{scu_control_type}, - inform::Ref{scu_inform_type})::Cvoid + control::Ptr{scu_control_type}, + inform::Ptr{scu_inform_type})::Cvoid end export scu_terminate function scu_terminate(data, control, inform) @ccall libgalahad_double.scu_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{scu_control_type}, - inform::Ref{scu_inform_type})::Cvoid + control::Ptr{scu_control_type}, + inform::Ptr{scu_inform_type})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/sec.jl b/GALAHAD.jl/src/wrappers/sec.jl index effb38accf..dd7e0dbe23 100644 --- a/GALAHAD.jl/src/wrappers/sec.jl +++ b/GALAHAD.jl/src/wrappers/sec.jl @@ -1,6 +1,6 @@ export sec_control_type -mutable struct sec_control_type{T} +struct sec_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -8,29 +8,25 @@ mutable struct sec_control_type{T} h_initial::T update_skip_tol::T prefix::NTuple{31,Cchar} - - sec_control_type{T}() where T = new() end export sec_inform_type -mutable struct sec_inform_type +struct sec_inform_type status::Cint - - sec_inform_type() = new() end export sec_initialize_s function sec_initialize_s(control, status) - @ccall libgalahad_single.sec_initialize_s(control::Ref{sec_control_type{Float32}}, + @ccall libgalahad_single.sec_initialize_s(control::Ptr{sec_control_type{Float32}}, status::Ptr{Cint})::Cvoid end export sec_initialize function sec_initialize(control, status) - @ccall libgalahad_double.sec_initialize(control::Ref{sec_control_type{Float64}}, + @ccall libgalahad_double.sec_initialize(control::Ptr{sec_control_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -38,7 +34,7 @@ export sec_information_s function sec_information_s(data, inform, status) @ccall libgalahad_single.sec_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{sec_inform_type}, + inform::Ptr{sec_inform_type}, status::Ptr{Cint})::Cvoid end @@ -46,7 +42,7 @@ export sec_information function sec_information(data, inform, status) @ccall libgalahad_double.sec_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{sec_inform_type}, + inform::Ptr{sec_inform_type}, status::Ptr{Cint})::Cvoid end @@ -54,14 +50,14 @@ export sec_terminate_s function sec_terminate_s(data, control, inform) @ccall libgalahad_single.sec_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{sec_control_type{Float32}}, - inform::Ref{sec_inform_type})::Cvoid + control::Ptr{sec_control_type{Float32}}, + inform::Ptr{sec_inform_type})::Cvoid end export sec_terminate function sec_terminate(data, control, inform) @ccall libgalahad_double.sec_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{sec_control_type{Float64}}, - inform::Ref{sec_inform_type})::Cvoid + control::Ptr{sec_control_type{Float64}}, + inform::Ptr{sec_inform_type})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/sha.jl b/GALAHAD.jl/src/wrappers/sha.jl index 28074aaa02..08dd590fe2 100644 --- a/GALAHAD.jl/src/wrappers/sha.jl +++ b/GALAHAD.jl/src/wrappers/sha.jl @@ -1,6 +1,6 @@ export sha_control_type -mutable struct sha_control_type +struct sha_control_type f_indexing::Bool error::Cint out::Cint @@ -12,13 +12,11 @@ mutable struct sha_control_type space_critical::Bool deallocate_error_fatal::Bool prefix::NTuple{31,Cchar} - - sha_control_type() = new() end export sha_inform_type -mutable struct sha_inform_type +struct sha_inform_type status::Cint alloc_status::Cint max_degree::Cint @@ -27,15 +25,13 @@ mutable struct sha_inform_type max_reduced_degree::Cint bad_row::Cint bad_alloc::NTuple{81,Cchar} - - sha_inform_type() = new() end export sha_initialize_s function sha_initialize_s(data, control, status) @ccall libgalahad_single.sha_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{sha_control_type}, + control::Ptr{sha_control_type}, status::Ptr{Cint})::Cvoid end @@ -43,14 +39,14 @@ export sha_initialize function sha_initialize(data, control, status) @ccall libgalahad_double.sha_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{sha_control_type}, + control::Ptr{sha_control_type}, status::Ptr{Cint})::Cvoid end export sha_reset_control_s function sha_reset_control_s(control, data, status) - @ccall libgalahad_single.sha_reset_control_s(control::Ref{sha_control_type}, + @ccall libgalahad_single.sha_reset_control_s(control::Ptr{sha_control_type}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -58,7 +54,7 @@ end export sha_reset_control function sha_reset_control(control, data, status) - @ccall libgalahad_double.sha_reset_control(control::Ref{sha_control_type}, + @ccall libgalahad_double.sha_reset_control(control::Ptr{sha_control_type}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -66,7 +62,7 @@ end export sha_analyse_matrix_s function sha_analyse_matrix_s(control, data, status, n, ne, row, col, m) - @ccall libgalahad_single.sha_analyse_matrix_s(control::Ref{sha_control_type}, + @ccall libgalahad_single.sha_analyse_matrix_s(control::Ptr{sha_control_type}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, ne::Cint, row::Ptr{Cint}, col::Ptr{Cint}, m::Ptr{Cint})::Cvoid @@ -75,7 +71,7 @@ end export sha_analyse_matrix function sha_analyse_matrix(control, data, status, n, ne, row, col, m) - @ccall libgalahad_double.sha_analyse_matrix(control::Ref{sha_control_type}, + @ccall libgalahad_double.sha_analyse_matrix(control::Ptr{sha_control_type}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, ne::Cint, row::Ptr{Cint}, col::Ptr{Cint}, m::Ptr{Cint})::Cvoid @@ -84,7 +80,7 @@ end export sha_recover_matrix_s function sha_recover_matrix_s(data, status, ne, m, ls1, ls2, strans, ly1, ly2, ytrans, val, - precedence) + precedence) @ccall libgalahad_single.sha_recover_matrix_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, ne::Cint, m::Cint, ls1::Cint, ls2::Cint, strans::Ptr{Ptr{Float32}}, ly1::Cint, @@ -96,7 +92,7 @@ end export sha_recover_matrix function sha_recover_matrix(data, status, ne, m, ls1, ls2, strans, ly1, ly2, ytrans, val, - precedence) + precedence) @ccall libgalahad_double.sha_recover_matrix(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, ne::Cint, m::Cint, ls1::Cint, ls2::Cint, strans::Ptr{Ptr{Float64}}, ly1::Cint, @@ -109,7 +105,7 @@ export sha_information_s function sha_information_s(data, inform, status) @ccall libgalahad_single.sha_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{sha_inform_type}, + inform::Ptr{sha_inform_type}, status::Ptr{Cint})::Cvoid end @@ -117,7 +113,7 @@ export sha_information function sha_information(data, inform, status) @ccall libgalahad_double.sha_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{sha_inform_type}, + inform::Ptr{sha_inform_type}, status::Ptr{Cint})::Cvoid end @@ -125,14 +121,14 @@ export sha_terminate_s function sha_terminate_s(data, control, inform) @ccall libgalahad_single.sha_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{sha_control_type}, - inform::Ref{sha_inform_type})::Cvoid + control::Ptr{sha_control_type}, + inform::Ptr{sha_inform_type})::Cvoid end export sha_terminate function sha_terminate(data, control, inform) @ccall libgalahad_double.sha_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{sha_control_type}, - inform::Ref{sha_inform_type})::Cvoid + control::Ptr{sha_control_type}, + inform::Ptr{sha_inform_type})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/sils.jl b/GALAHAD.jl/src/wrappers/sils.jl index 219e0be06d..8b260ed2ab 100644 --- a/GALAHAD.jl/src/wrappers/sils.jl +++ b/GALAHAD.jl/src/wrappers/sils.jl @@ -1,6 +1,6 @@ export sils_control_type -mutable struct sils_control_type{T} +struct sils_control_type{T} f_indexing::Bool ICNTL::NTuple{30,Cint} lp::Cint @@ -27,13 +27,11 @@ mutable struct sils_control_type{T} static_level::T tolerance::T convergence::T - - sils_control_type{T}() where T = new() end export sils_ainfo_type -mutable struct sils_ainfo_type{T} +struct sils_ainfo_type{T} flag::Cint more::Cint nsteps::Cint @@ -51,13 +49,11 @@ mutable struct sils_ainfo_type{T} faulty::Cint opsa::T opse::T - - sils_ainfo_type{T}() where T = new() end export sils_finfo_type -mutable struct sils_finfo_type{T} +struct sils_finfo_type{T} flag::Cint more::Cint maxfrt::Cint @@ -86,13 +82,11 @@ mutable struct sils_finfo_type{T} maxchange::T smin::T smax::T - - sils_finfo_type{T}() where T = new() end export sils_sinfo_type -mutable struct sils_sinfo_type{T} +struct sils_sinfo_type{T} flag::Cint stat::Cint cond::T @@ -100,15 +94,13 @@ mutable struct sils_sinfo_type{T} berr::T berr2::T error::T - - sils_sinfo_type{T}() where T = new() end export sils_initialize_s function sils_initialize_s(data, control, status) @ccall libgalahad_single.sils_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{sils_control_type{Float32}}, + control::Ptr{sils_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -116,42 +108,42 @@ export sils_initialize function sils_initialize(data, control, status) @ccall libgalahad_double.sils_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{sils_control_type{Float64}}, + control::Ptr{sils_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export sils_read_specfile_s function sils_read_specfile_s(control, specfile) - @ccall libgalahad_single.sils_read_specfile_s(control::Ref{sils_control_type{Float32}}, + @ccall libgalahad_single.sils_read_specfile_s(control::Ptr{sils_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export sils_read_specfile function sils_read_specfile(control, specfile) - @ccall libgalahad_double.sils_read_specfile(control::Ref{sils_control_type{Float64}}, + @ccall libgalahad_double.sils_read_specfile(control::Ptr{sils_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export sils_import_s function sils_import_s(control, data, status) - @ccall libgalahad_single.sils_import_s(control::Ref{sils_control_type{Float32}}, + @ccall libgalahad_single.sils_import_s(control::Ptr{sils_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end export sils_import function sils_import(control, data, status) - @ccall libgalahad_double.sils_import(control::Ref{sils_control_type{Float64}}, + @ccall libgalahad_double.sils_import(control::Ptr{sils_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end export sils_reset_control_s function sils_reset_control_s(control, data, status) - @ccall libgalahad_single.sils_reset_control_s(control::Ref{sils_control_type{Float32}}, + @ccall libgalahad_single.sils_reset_control_s(control::Ptr{sils_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -159,7 +151,7 @@ end export sils_reset_control function sils_reset_control(control, data, status) - @ccall libgalahad_double.sils_reset_control(control::Ref{sils_control_type{Float64}}, + @ccall libgalahad_double.sils_reset_control(control::Ptr{sils_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -168,9 +160,9 @@ export sils_information_s function sils_information_s(data, ainfo, finfo, sinfo, status) @ccall libgalahad_single.sils_information_s(data::Ptr{Ptr{Cvoid}}, - ainfo::Ref{sils_ainfo_type{Float32}}, - finfo::Ref{sils_finfo_type{Float32}}, - sinfo::Ref{sils_sinfo_type{Float32}}, + ainfo::Ptr{sils_ainfo_type{Float32}}, + finfo::Ptr{sils_finfo_type{Float32}}, + sinfo::Ptr{sils_sinfo_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -178,9 +170,9 @@ export sils_information function sils_information(data, ainfo, finfo, sinfo, status) @ccall libgalahad_double.sils_information(data::Ptr{Ptr{Cvoid}}, - ainfo::Ref{sils_ainfo_type{Float64}}, - finfo::Ref{sils_finfo_type{Float64}}, - sinfo::Ref{sils_sinfo_type{Float64}}, + ainfo::Ptr{sils_ainfo_type{Float64}}, + finfo::Ptr{sils_finfo_type{Float64}}, + sinfo::Ptr{sils_sinfo_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -188,7 +180,7 @@ export sils_finalize_s function sils_finalize_s(data, control, status) @ccall libgalahad_single.sils_finalize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{sils_control_type{Float32}}, + control::Ptr{sils_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -196,6 +188,6 @@ export sils_finalize function sils_finalize(data, control, status) @ccall libgalahad_double.sils_finalize(data::Ptr{Ptr{Cvoid}}, - control::Ref{sils_control_type{Float64}}, + control::Ptr{sils_control_type{Float64}}, status::Ptr{Cint})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/slls.jl b/GALAHAD.jl/src/wrappers/slls.jl index 186eb2594d..eabf47f1c1 100644 --- a/GALAHAD.jl/src/wrappers/slls.jl +++ b/GALAHAD.jl/src/wrappers/slls.jl @@ -1,6 +1,6 @@ export slls_control_type -mutable struct slls_control_type{T} +struct slls_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -35,29 +35,20 @@ mutable struct slls_control_type{T} prefix::NTuple{31,Cchar} sbls_control::sbls_control_type{T} convert_control::convert_control_type - - function slls_control_type{T}() where T - type = new() - type.sbls_control = sbls_control_type{T}() - type.convert_control = convert_control_type() - return type - end end export slls_time_type -mutable struct slls_time_type +struct slls_time_type total::Float32 analyse::Float32 factorize::Float32 solve::Float32 - - slls_time_type() = new() end export slls_inform_type -mutable struct slls_inform_type{T} +struct slls_inform_type{T} status::Cint alloc_status::Cint factorization_status::Cint @@ -69,21 +60,13 @@ mutable struct slls_inform_type{T} time::slls_time_type sbls_inform::sbls_inform_type{T} convert_inform::convert_inform_type{T} - - function slls_inform_type{T}() where T - type = new() - type.time = slls_time_type() - type.sbls_inform = sbls_inform_type{T}() - type.convert_inform = convert_inform_type{T}() - return type - end end export slls_initialize_s function slls_initialize_s(data, control, status) @ccall libgalahad_single.slls_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{slls_control_type{Float32}}, + control::Ptr{slls_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -91,50 +74,50 @@ export slls_initialize function slls_initialize(data, control, status) @ccall libgalahad_double.slls_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{slls_control_type{Float64}}, + control::Ptr{slls_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export slls_read_specfile_s function slls_read_specfile_s(control, specfile) - @ccall libgalahad_single.slls_read_specfile_s(control::Ref{slls_control_type{Float32}}, + @ccall libgalahad_single.slls_read_specfile_s(control::Ptr{slls_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export slls_read_specfile function slls_read_specfile(control, specfile) - @ccall libgalahad_double.slls_read_specfile(control::Ref{slls_control_type{Float64}}, + @ccall libgalahad_double.slls_read_specfile(control::Ptr{slls_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export slls_import_s -function slls_import_s(control, data, status, n, o, Ao_type, Ao_ne, Ao_row, Ao_col, Ao_ptr_ne, Ao_ptr) - @ccall libgalahad_single.slls_import_s(control::Ref{slls_control_type{Float32}}, +function slls_import_s(control, data, status, n, m, Ao_type, Ao_ne, Ao_row, Ao_col, + Ao_ptr_ne, Ao_ptr) + @ccall libgalahad_single.slls_import_s(control::Ptr{slls_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, - o::Cint, Ao_type::Ptr{Cchar}, Ao_ne::Cint, + m::Cint, Ao_type::Ptr{Cchar}, Ao_ne::Cint, Ao_row::Ptr{Cint}, Ao_col::Ptr{Cint}, - Ao_ptr_ne::Cint, - Ao_ptr::Ptr{Cint})::Cvoid + Ao_ptr_ne::Cint, Ao_ptr::Ptr{Cint})::Cvoid end export slls_import -function slls_import(control, data, status, n, o, Ao_type, Ao_ne, Ao_row, Ao_col, Ao_ptr_ne, Ao_ptr) - @ccall libgalahad_double.slls_import(control::Ref{slls_control_type{Float64}}, +function slls_import(control, data, status, n, m, Ao_type, Ao_ne, Ao_row, Ao_col, Ao_ptr_ne, + Ao_ptr) + @ccall libgalahad_double.slls_import(control::Ptr{slls_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, - o::Cint, Ao_type::Ptr{Cchar}, Ao_ne::Cint, + m::Cint, Ao_type::Ptr{Cchar}, Ao_ne::Cint, Ao_row::Ptr{Cint}, Ao_col::Ptr{Cint}, - Ao_ptr_ne::Cint, - Ao_ptr::Ptr{Cint})::Cvoid + Ao_ptr_ne::Cint, Ao_ptr::Ptr{Cint})::Cvoid end export slls_import_without_a_s function slls_import_without_a_s(control, data, status, n, o) - @ccall libgalahad_single.slls_import_without_a_s(control::Ref{slls_control_type{Float32}}, + @ccall libgalahad_single.slls_import_without_a_s(control::Ptr{slls_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, o::Cint)::Cvoid end @@ -142,7 +125,7 @@ end export slls_import_without_a function slls_import_without_a(control, data, status, n, o) - @ccall libgalahad_double.slls_import_without_a(control::Ref{slls_control_type{Float64}}, + @ccall libgalahad_double.slls_import_without_a(control::Ptr{slls_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, o::Cint)::Cvoid end @@ -150,7 +133,7 @@ end export slls_reset_control_s function slls_reset_control_s(control, data, status) - @ccall libgalahad_single.slls_reset_control_s(control::Ref{slls_control_type{Float32}}, + @ccall libgalahad_single.slls_reset_control_s(control::Ptr{slls_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -158,15 +141,15 @@ end export slls_reset_control function slls_reset_control(control, data, status) - @ccall libgalahad_double.slls_reset_control(control::Ref{slls_control_type{Float64}}, + @ccall libgalahad_double.slls_reset_control(control::Ptr{slls_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end export slls_solve_given_a_s -function slls_solve_given_a_s(data, userdata, status, n, o, Ao_ne, Ao_val, - b, x, z, r, g, x_stat, eval_prec) +function slls_solve_given_a_s(data, userdata, status, n, o, Ao_ne, Ao_val, b, x, z, r, g, + x_stat, eval_prec) @ccall libgalahad_single.slls_solve_given_a_s(data::Ptr{Ptr{Cvoid}}, userdata::Ptr{Cvoid}, status::Ptr{Cint}, n::Cint, o::Cint, Ao_ne::Cint, Ao_val::Ptr{Float32}, @@ -178,8 +161,8 @@ end export slls_solve_given_a -function slls_solve_given_a(data, userdata, status, n, o, Ao_ne, Ao_val, - b, x, z, r, g,x_stat, eval_prec) +function slls_solve_given_a(data, userdata, status, n, o, Ao_ne, Ao_val, b, x, z, r, g, + x_stat, eval_prec) @ccall libgalahad_double.slls_solve_given_a(data::Ptr{Ptr{Cvoid}}, userdata::Ptr{Cvoid}, status::Ptr{Cint}, n::Cint, o::Cint, Ao_ne::Cint, Ao_val::Ptr{Float64}, @@ -192,7 +175,7 @@ end export slls_solve_reverse_a_prod_s function slls_solve_reverse_a_prod_s(data, status, eval_status, n, o, b, x, z, r, g, x_stat, - v, p, nz_v, nz_v_start, nz_v_end, nz_p, nz_p_end) + v, p, nz_v, nz_v_start, nz_v_end, nz_p, nz_p_end) @ccall libgalahad_single.slls_solve_reverse_a_prod_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, eval_status::Ptr{Cint}, n::Cint, @@ -209,13 +192,13 @@ end export slls_solve_reverse_a_prod function slls_solve_reverse_a_prod(data, status, eval_status, n, o, b, x, z, r, g, x_stat, - v, p, nz_v, nz_v_start, nz_v_end, nz_p, nz_p_end) + v, p, nz_v, nz_v_start, nz_v_end, nz_p, nz_p_end) @ccall libgalahad_double.slls_solve_reverse_a_prod(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, eval_status::Ptr{Cint}, n::Cint, - m::Cint, b::Ptr{Float64}, + o::Cint, b::Ptr{Float64}, x::Ptr{Float64}, z::Ptr{Float64}, - c::Ptr{Float64}, g::Ptr{Float64}, + r::Ptr{Float64}, g::Ptr{Float64}, x_stat::Ptr{Cint}, v::Ptr{Float64}, p::Ptr{Float64}, nz_v::Ptr{Cint}, nz_v_start::Ptr{Cint}, @@ -227,7 +210,7 @@ export slls_information_s function slls_information_s(data, inform, status) @ccall libgalahad_single.slls_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{slls_inform_type{Float32}}, + inform::Ptr{slls_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -235,7 +218,7 @@ export slls_information function slls_information(data, inform, status) @ccall libgalahad_double.slls_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{slls_inform_type{Float64}}, + inform::Ptr{slls_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -243,14 +226,14 @@ export slls_terminate_s function slls_terminate_s(data, control, inform) @ccall libgalahad_single.slls_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{slls_control_type{Float32}}, - inform::Ref{slls_inform_type{Float32}})::Cvoid + control::Ptr{slls_control_type{Float32}}, + inform::Ptr{slls_inform_type{Float32}})::Cvoid end export slls_terminate function slls_terminate(data, control, inform) @ccall libgalahad_double.slls_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{slls_control_type{Float64}}, - inform::Ref{slls_inform_type{Float64}})::Cvoid + control::Ptr{slls_control_type{Float64}}, + inform::Ptr{slls_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/sls.jl b/GALAHAD.jl/src/wrappers/sls.jl index 0d6c3342e7..42daf0b418 100644 --- a/GALAHAD.jl/src/wrappers/sls.jl +++ b/GALAHAD.jl/src/wrappers/sls.jl @@ -1,6 +1,6 @@ export sls_control_type -mutable struct sls_control_type{T} +struct sls_control_type{T} f_indexing::Bool error::Cint warning::Cint @@ -52,13 +52,11 @@ mutable struct sls_control_type{T} out_of_core_indefinite_file::NTuple{401,Cchar} out_of_core_restart_file::NTuple{501,Cchar} prefix::NTuple{31,Cchar} - - sls_control_type{T}() where T = new() end export sls_time_type -mutable struct sls_time_type{T} +struct sls_time_type{T} total::T analyse::T factorize::T @@ -75,13 +73,11 @@ mutable struct sls_time_type{T} clock_analyse_external::T clock_factorize_external::T clock_solve_external::T - - sls_time_type{T}() where T = new() end export sls_inform_type -mutable struct sls_inform_type{T} +struct sls_inform_type{T} status::Cint alloc_status::Cint bad_alloc::NTuple{81,Cchar} @@ -159,32 +155,13 @@ mutable struct sls_inform_type{T} wsmp_dparm::NTuple{64,T} mpi_ierr::Cint lapack_error::Cint - - function sls_inform_type{T}() where T - type = new() - type.time = sls_time_type{T}() - type.sils_ainfo = sils_ainfo_type{T}() - type.sils_finfo = sils_finfo_type{T}() - type.sils_sinfo = sils_sinfo_type{T}() - type.ma57_ainfo = ma57_ainfo{T}() - type.ma57_finfo = ma57_finfo{T}() - type.ma57_sinfo = ma57_sinfo{T}() - type.ma77_info = ma77_info{T}() - type.ma86_info = ma86_info{T}() - type.ma87_info = ma87_info{T}() - type.ma97_info = ma97_info{T}() - type.ssids_inform = spral_ssids_inform() - type.mc64_info = mc64_info() - type.mc68_info = mc68_info() - return type - end end export sls_initialize_s function sls_initialize_s(solver, data, control, status) @ccall libgalahad_single.sls_initialize_s(solver::Ptr{Cchar}, data::Ptr{Ptr{Cvoid}}, - control::Ref{sls_control_type{Float32}}, + control::Ptr{sls_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -192,28 +169,28 @@ export sls_initialize function sls_initialize(solver, data, control, status) @ccall libgalahad_double.sls_initialize(solver::Ptr{Cchar}, data::Ptr{Ptr{Cvoid}}, - control::Ref{sls_control_type{Float64}}, + control::Ptr{sls_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export sls_read_specfile_s function sls_read_specfile_s(control, specfile) - @ccall libgalahad_single.sls_read_specfile_s(control::Ref{sls_control_type{Float32}}, + @ccall libgalahad_single.sls_read_specfile_s(control::Ptr{sls_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export sls_read_specfile function sls_read_specfile(control, specfile) - @ccall libgalahad_double.sls_read_specfile(control::Ref{sls_control_type{Float64}}, + @ccall libgalahad_double.sls_read_specfile(control::Ptr{sls_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export sls_analyse_matrix_s function sls_analyse_matrix_s(control, data, status, n, type, ne, row, col, ptr) - @ccall libgalahad_single.sls_analyse_matrix_s(control::Ref{sls_control_type{Float32}}, + @ccall libgalahad_single.sls_analyse_matrix_s(control::Ptr{sls_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, type::Ptr{Cchar}, ne::Cint, row::Ptr{Cint}, col::Ptr{Cint}, @@ -223,7 +200,7 @@ end export sls_analyse_matrix function sls_analyse_matrix(control, data, status, n, type, ne, row, col, ptr) - @ccall libgalahad_double.sls_analyse_matrix(control::Ref{sls_control_type{Float64}}, + @ccall libgalahad_double.sls_analyse_matrix(control::Ptr{sls_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, type::Ptr{Cchar}, ne::Cint, row::Ptr{Cint}, col::Ptr{Cint}, @@ -233,7 +210,7 @@ end export sls_reset_control_s function sls_reset_control_s(control, data, status) - @ccall libgalahad_single.sls_reset_control_s(control::Ref{sls_control_type{Float32}}, + @ccall libgalahad_single.sls_reset_control_s(control::Ptr{sls_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -241,7 +218,7 @@ end export sls_reset_control function sls_reset_control(control, data, status) - @ccall libgalahad_double.sls_reset_control(control::Ref{sls_control_type{Float64}}, + @ccall libgalahad_double.sls_reset_control(control::Ptr{sls_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -286,8 +263,7 @@ end export sls_partial_solve_system function sls_partial_solve_system(part, data, status, n, sol) - @ccall libgalahad_double.sls_partial_solve_system(part::Ptr{Cchar}, - data::Ptr{Ptr{Cvoid}}, + @ccall libgalahad_double.sls_partial_solve_system(part::Ptr{Cchar}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, sol::Ptr{Float64})::Cvoid end @@ -296,7 +272,7 @@ export sls_information_s function sls_information_s(data, inform, status) @ccall libgalahad_single.sls_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{sls_inform_type{Float32}}, + inform::Ptr{sls_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -304,7 +280,7 @@ export sls_information function sls_information(data, inform, status) @ccall libgalahad_double.sls_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{sls_inform_type{Float64}}, + inform::Ptr{sls_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -312,14 +288,14 @@ export sls_terminate_s function sls_terminate_s(data, control, inform) @ccall libgalahad_single.sls_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{sls_control_type{Float32}}, - inform::Ref{sls_inform_type{Float32}})::Cvoid + control::Ptr{sls_control_type{Float32}}, + inform::Ptr{sls_inform_type{Float32}})::Cvoid end export sls_terminate function sls_terminate(data, control, inform) @ccall libgalahad_double.sls_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{sls_control_type{Float64}}, - inform::Ref{sls_inform_type{Float64}})::Cvoid + control::Ptr{sls_control_type{Float64}}, + inform::Ptr{sls_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/ssids.jl b/GALAHAD.jl/src/wrappers/ssids.jl index 9f0d94353c..9b163592e2 100644 --- a/GALAHAD.jl/src/wrappers/ssids.jl +++ b/GALAHAD.jl/src/wrappers/ssids.jl @@ -1,6 +1,6 @@ export spral_ssids_options -mutable struct spral_ssids_options{T} +struct spral_ssids_options{T} array_base::Cint print_level::Cint unit_diagnostics::Cint @@ -25,13 +25,11 @@ mutable struct spral_ssids_options{T} multiplier::T min_loadbalance::Cfloat failed_pivot_method::Cint - - spral_ssids_options{T}() where T = new() end export spral_ssids_inform -mutable struct spral_ssids_inform +struct spral_ssids_inform flag::Cint matrix_dup::Cint matrix_missing_diag::Cint @@ -54,6 +52,4 @@ mutable struct spral_ssids_inform nparts::Cint cpu_flops::Int64 gpu_flops::Int64 - - spral_ssids_inform() = new() end diff --git a/GALAHAD.jl/src/wrappers/trb.jl b/GALAHAD.jl/src/wrappers/trb.jl index f932b5f287..b5a1f98283 100644 --- a/GALAHAD.jl/src/wrappers/trb.jl +++ b/GALAHAD.jl/src/wrappers/trb.jl @@ -1,6 +1,6 @@ export trb_control_type -mutable struct trb_control_type{T} +struct trb_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -51,25 +51,14 @@ mutable struct trb_control_type{T} trs_control::trs_control_type{T} gltr_control::gltr_control_type{T} psls_control::psls_control_type{T} - lms_control::lms_control_type{T} - lms_control_prec::lms_control_type{T} + lms_control::lms_control_type + lms_control_prec::lms_control_type sha_control::sha_control_type - - function trb_control_type{T}() where T - type = new() - type.trs_control = trs_control_type{T}() - type.gltr_control = gltr_control_type{T}() - type.psls_control = psls_control_type{T}() - type.lms_control = lms_control_type{T}() - type.lms_control_prec = lms_control_type{T}() - type.sha_control = sha_control_type() - return type - end end export trb_time_type -mutable struct trb_time_type{T} +struct trb_time_type{T} total::Float32 preprocess::Float32 analyse::Float32 @@ -80,13 +69,11 @@ mutable struct trb_time_type{T} clock_analyse::T clock_factorize::T clock_solve::T - - trb_time_type{T}() where T = new() end export trb_inform_type -mutable struct trb_inform_type{T} +struct trb_inform_type{T} status::Cint alloc_status::Cint bad_alloc::NTuple{81,Cchar} @@ -112,25 +99,13 @@ mutable struct trb_inform_type{T} lms_inform::lms_inform_type{T} lms_inform_prec::lms_inform_type{T} sha_inform::sha_inform_type - - function trb_inform_type{T}() where T - type = new() - type.time = trb_time_type{T}() - type.trs_inform = trs_inform_type{T}() - type.gltr_inform = gltr_inform_type{T}() - type.psls_inform = psls_inform_type{T}() - type.lms_inform = lms_inform_type{T}() - type.lms_inform_prec = lms_inform_type{T}() - type.sha_inform = sha_inform_type() - return type - end end export trb_initialize_s function trb_initialize_s(data, control, status) @ccall libgalahad_single.trb_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{trb_control_type{Float32}}, + control::Ptr{trb_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -138,28 +113,28 @@ export trb_initialize function trb_initialize(data, control, status) @ccall libgalahad_double.trb_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{trb_control_type{Float64}}, + control::Ptr{trb_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export trb_read_specfile_s function trb_read_specfile_s(control, specfile) - @ccall libgalahad_single.trb_read_specfile_s(control::Ref{trb_control_type{Float32}}, + @ccall libgalahad_single.trb_read_specfile_s(control::Ptr{trb_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export trb_read_specfile function trb_read_specfile(control, specfile) - @ccall libgalahad_double.trb_read_specfile(control::Ref{trb_control_type{Float64}}, + @ccall libgalahad_double.trb_read_specfile(control::Ptr{trb_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export trb_import_s function trb_import_s(control, data, status, n, x_l, x_u, H_type, ne, H_row, H_col, H_ptr) - @ccall libgalahad_single.trb_import_s(control::Ref{trb_control_type{Float32}}, + @ccall libgalahad_single.trb_import_s(control::Ptr{trb_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, x_l::Ptr{Float32}, x_u::Ptr{Float32}, H_type::Ptr{Cchar}, ne::Cint, H_row::Ptr{Cint}, @@ -169,7 +144,7 @@ end export trb_import function trb_import(control, data, status, n, x_l, x_u, H_type, ne, H_row, H_col, H_ptr) - @ccall libgalahad_double.trb_import(control::Ref{trb_control_type{Float64}}, + @ccall libgalahad_double.trb_import(control::Ptr{trb_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, x_l::Ptr{Float64}, x_u::Ptr{Float64}, H_type::Ptr{Cchar}, ne::Cint, H_row::Ptr{Cint}, @@ -179,7 +154,7 @@ end export trb_reset_control_s function trb_reset_control_s(control, data, status) - @ccall libgalahad_single.trb_reset_control_s(control::Ref{trb_control_type{Float32}}, + @ccall libgalahad_single.trb_reset_control_s(control::Ptr{trb_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -187,7 +162,7 @@ end export trb_reset_control function trb_reset_control(control, data, status) - @ccall libgalahad_double.trb_reset_control(control::Ref{trb_control_type{Float64}}, + @ccall libgalahad_double.trb_reset_control(control::Ptr{trb_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -195,31 +170,30 @@ end export trb_solve_with_mat_s function trb_solve_with_mat_s(data, userdata, status, n, x, g, ne, eval_f, eval_g, eval_h, - eval_prec) + eval_prec) @ccall libgalahad_single.trb_solve_with_mat_s(data::Ptr{Ptr{Cvoid}}, userdata::Ptr{Cvoid}, - status::Ptr{Cint}, n::Cint, - x::Ptr{Float32}, g::Ptr{Float32}, - ne::Cint, eval_f::Ptr{Cvoid}, - eval_g::Ptr{Cvoid}, eval_h::Ptr{Cvoid}, + status::Ptr{Cint}, n::Cint, x::Ptr{Float32}, + g::Ptr{Float32}, ne::Cint, + eval_f::Ptr{Cvoid}, eval_g::Ptr{Cvoid}, + eval_h::Ptr{Cvoid}, eval_prec::Ptr{Cvoid})::Cvoid end export trb_solve_with_mat function trb_solve_with_mat(data, userdata, status, n, x, g, ne, eval_f, eval_g, eval_h, - eval_prec) + eval_prec) @ccall libgalahad_double.trb_solve_with_mat(data::Ptr{Ptr{Cvoid}}, userdata::Ptr{Cvoid}, - status::Ptr{Cint}, n::Cint, - x::Ptr{Float64}, g::Ptr{Float64}, - ne::Cint, eval_f::Ptr{Cvoid}, + status::Ptr{Cint}, n::Cint, x::Ptr{Float64}, + g::Ptr{Float64}, ne::Cint, eval_f::Ptr{Cvoid}, eval_g::Ptr{Cvoid}, eval_h::Ptr{Cvoid}, eval_prec::Ptr{Cvoid})::Cvoid end export trb_solve_without_mat_s -function trb_solve_without_mat_s(data, userdata, status, n, x, g, eval_f, eval_g, eval_hprod, - eval_shprod, eval_prec) +function trb_solve_without_mat_s(data, userdata, status, n, x, g, eval_f, eval_g, + eval_hprod, eval_shprod, eval_prec) @ccall libgalahad_single.trb_solve_without_mat_s(data::Ptr{Ptr{Cvoid}}, userdata::Ptr{Cvoid}, status::Ptr{Cint}, n::Cint, x::Ptr{Float32}, @@ -233,12 +207,11 @@ end export trb_solve_without_mat function trb_solve_without_mat(data, userdata, status, n, x, g, eval_f, eval_g, eval_hprod, - eval_shprod, eval_prec) + eval_shprod, eval_prec) @ccall libgalahad_double.trb_solve_without_mat(data::Ptr{Ptr{Cvoid}}, userdata::Ptr{Cvoid}, status::Ptr{Cint}, - n::Cint, x::Ptr{Float64}, - g::Ptr{Float64}, eval_f::Ptr{Cvoid}, - eval_g::Ptr{Cvoid}, + n::Cint, x::Ptr{Float64}, g::Ptr{Float64}, + eval_f::Ptr{Cvoid}, eval_g::Ptr{Cvoid}, eval_hprod::Ptr{Cvoid}, eval_shprod::Ptr{Cvoid}, eval_prec::Ptr{Cvoid})::Cvoid @@ -246,7 +219,8 @@ end export trb_solve_reverse_with_mat_s -function trb_solve_reverse_with_mat_s(data, status, eval_status, n, x, f, g, ne, H_val, u, v) +function trb_solve_reverse_with_mat_s(data, status, eval_status, n, x, f, g, ne, H_val, u, + v) @ccall libgalahad_single.trb_solve_reverse_with_mat_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, eval_status::Ptr{Cint}, n::Cint, @@ -265,21 +239,19 @@ function trb_solve_reverse_with_mat(data, status, eval_status, n, x, f, g, ne, H eval_status::Ptr{Cint}, n::Cint, x::Ptr{Float64}, f::Float64, g::Ptr{Float64}, ne::Cint, - H_val::Ptr{Float64}, - u::Ptr{Float64}, + H_val::Ptr{Float64}, u::Ptr{Float64}, v::Ptr{Float64})::Cvoid end export trb_solve_reverse_without_mat_s function trb_solve_reverse_without_mat_s(data, status, eval_status, n, x, f, g, u, v, - index_nz_v, nnz_v, index_nz_u, nnz_u) + index_nz_v, nnz_v, index_nz_u, nnz_u) @ccall libgalahad_single.trb_solve_reverse_without_mat_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, eval_status::Ptr{Cint}, n::Cint, x::Ptr{Float32}, f::Float32, - g::Ptr{Float32}, - u::Ptr{Float32}, + g::Ptr{Float32}, u::Ptr{Float32}, v::Ptr{Float32}, index_nz_v::Ptr{Cint}, nnz_v::Ptr{Cint}, @@ -290,13 +262,12 @@ end export trb_solve_reverse_without_mat function trb_solve_reverse_without_mat(data, status, eval_status, n, x, f, g, u, v, - index_nz_v, nnz_v, index_nz_u, nnz_u) + index_nz_v, nnz_v, index_nz_u, nnz_u) @ccall libgalahad_double.trb_solve_reverse_without_mat(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, eval_status::Ptr{Cint}, n::Cint, x::Ptr{Float64}, f::Float64, - g::Ptr{Float64}, - u::Ptr{Float64}, + g::Ptr{Float64}, u::Ptr{Float64}, v::Ptr{Float64}, index_nz_v::Ptr{Cint}, nnz_v::Ptr{Cint}, @@ -308,7 +279,7 @@ export trb_information_s function trb_information_s(data, inform, status) @ccall libgalahad_single.trb_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{trb_inform_type{Float32}}, + inform::Ptr{trb_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -316,7 +287,7 @@ export trb_information function trb_information(data, inform, status) @ccall libgalahad_double.trb_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{trb_inform_type{Float64}}, + inform::Ptr{trb_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -324,14 +295,14 @@ export trb_terminate_s function trb_terminate_s(data, control, inform) @ccall libgalahad_single.trb_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{trb_control_type{Float32}}, - inform::Ref{trb_inform_type{Float32}})::Cvoid + control::Ptr{trb_control_type{Float32}}, + inform::Ptr{trb_inform_type{Float32}})::Cvoid end export trb_terminate function trb_terminate(data, control, inform) @ccall libgalahad_double.trb_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{trb_control_type{Float64}}, - inform::Ref{trb_inform_type{Float64}})::Cvoid + control::Ptr{trb_control_type{Float64}}, + inform::Ptr{trb_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/trs.jl b/GALAHAD.jl/src/wrappers/trs.jl index 88fefa2ec4..bee2a30964 100644 --- a/GALAHAD.jl/src/wrappers/trs.jl +++ b/GALAHAD.jl/src/wrappers/trs.jl @@ -1,6 +1,6 @@ export trs_control_type -mutable struct trs_control_type{T} +struct trs_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -33,18 +33,11 @@ mutable struct trs_control_type{T} prefix::NTuple{31,Cchar} sls_control::sls_control_type{T} ir_control::ir_control_type{T} - - function trs_control_type{T}() where T - type = new() - type.sls_control = sls_control_type{T}() - type.ir_control = ir_control_type{T}() - return type - end end export trs_time_type -mutable struct trs_time_type{T} +struct trs_time_type{T} total::T assemble::T analyse::T @@ -55,22 +48,18 @@ mutable struct trs_time_type{T} clock_analyse::T clock_factorize::T clock_solve::T - - trs_time_type{T}() where T = new() end export trs_history_type -mutable struct trs_history_type{T} +struct trs_history_type{T} lambda::T x_norm::T - - trs_history_type{T}() where T = new() end export trs_inform_type -mutable struct trs_inform_type{T} +struct trs_inform_type{T} status::Cint alloc_status::Cint factorizations::Cint @@ -84,25 +73,16 @@ mutable struct trs_inform_type{T} hard_case::Bool bad_alloc::NTuple{81,Cchar} time::trs_time_type{T} - history::NTuple{100,trs_history_type{T}} + history::NTuple{100,trs_history_type} sls_inform::sls_inform_type{T} ir_inform::ir_inform_type{T} - - function trs_inform_type{T}() where T - type = new() - type.time = trs_time_type{T}() - type.history = ntuple(x -> trs_history_type{T}(), 100) - type.sls_inform = sls_inform_type{T}() - type.ir_inform = ir_inform_type{T}() - return type - end end export trs_initialize_s function trs_initialize_s(data, control, status) @ccall libgalahad_single.trs_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{trs_control_type{Float32}}, + control::Ptr{trs_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -110,28 +90,28 @@ export trs_initialize function trs_initialize(data, control, status) @ccall libgalahad_double.trs_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{trs_control_type{Float64}}, + control::Ptr{trs_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export trs_read_specfile_s function trs_read_specfile_s(control, specfile) - @ccall libgalahad_single.trs_read_specfile_s(control::Ref{trs_control_type{Float32}}, + @ccall libgalahad_single.trs_read_specfile_s(control::Ptr{trs_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export trs_read_specfile function trs_read_specfile(control, specfile) - @ccall libgalahad_double.trs_read_specfile(control::Ref{trs_control_type{Float64}}, + @ccall libgalahad_double.trs_read_specfile(control::Ptr{trs_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export trs_import_s function trs_import_s(control, data, status, n, H_type, H_ne, H_row, H_col, H_ptr) - @ccall libgalahad_single.trs_import_s(control::Ref{trs_control_type{Float32}}, + @ccall libgalahad_single.trs_import_s(control::Ptr{trs_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, H_type::Ptr{Cchar}, H_ne::Cint, H_row::Ptr{Cint}, H_col::Ptr{Cint}, H_ptr::Ptr{Cint})::Cvoid @@ -140,7 +120,7 @@ end export trs_import function trs_import(control, data, status, n, H_type, H_ne, H_row, H_col, H_ptr) - @ccall libgalahad_double.trs_import(control::Ref{trs_control_type{Float64}}, + @ccall libgalahad_double.trs_import(control::Ptr{trs_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, H_type::Ptr{Cchar}, H_ne::Cint, H_row::Ptr{Cint}, H_col::Ptr{Cint}, H_ptr::Ptr{Cint})::Cvoid @@ -181,7 +161,7 @@ end export trs_reset_control_s function trs_reset_control_s(control, data, status) - @ccall libgalahad_single.trs_reset_control_s(control::Ref{trs_control_type{Float32}}, + @ccall libgalahad_single.trs_reset_control_s(control::Ptr{trs_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -189,7 +169,7 @@ end export trs_reset_control function trs_reset_control(control, data, status) - @ccall libgalahad_double.trs_reset_control(control::Ref{trs_control_type{Float64}}, + @ccall libgalahad_double.trs_reset_control(control::Ptr{trs_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -197,7 +177,7 @@ end export trs_solve_problem_s function trs_solve_problem_s(data, status, n, radius, f, c, H_ne, H_val, x, M_ne, M_val, m, - A_ne, A_val, y) + A_ne, A_val, y) @ccall libgalahad_single.trs_solve_problem_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, radius::Float32, f::Float32, c::Ptr{Float32}, H_ne::Cint, @@ -210,7 +190,7 @@ end export trs_solve_problem function trs_solve_problem(data, status, n, radius, f, c, H_ne, H_val, x, M_ne, M_val, m, - A_ne, A_val, y) + A_ne, A_val, y) @ccall libgalahad_double.trs_solve_problem(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, radius::Float64, f::Float64, c::Ptr{Float64}, H_ne::Cint, @@ -224,7 +204,7 @@ export trs_information_s function trs_information_s(data, inform, status) @ccall libgalahad_single.trs_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{trs_inform_type{Float32}}, + inform::Ptr{trs_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -232,7 +212,7 @@ export trs_information function trs_information(data, inform, status) @ccall libgalahad_double.trs_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{trs_inform_type{Float64}}, + inform::Ptr{trs_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -240,14 +220,14 @@ export trs_terminate_s function trs_terminate_s(data, control, inform) @ccall libgalahad_single.trs_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{trs_control_type{Float32}}, - inform::Ref{trs_inform_type{Float32}})::Cvoid + control::Ptr{trs_control_type{Float32}}, + inform::Ptr{trs_inform_type{Float32}})::Cvoid end export trs_terminate function trs_terminate(data, control, inform) @ccall libgalahad_double.trs_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{trs_control_type{Float64}}, - inform::Ref{trs_inform_type{Float64}})::Cvoid + control::Ptr{trs_control_type{Float64}}, + inform::Ptr{trs_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/tru.jl b/GALAHAD.jl/src/wrappers/tru.jl index 17bbd3742e..c280ec799c 100644 --- a/GALAHAD.jl/src/wrappers/tru.jl +++ b/GALAHAD.jl/src/wrappers/tru.jl @@ -1,6 +1,6 @@ export tru_control_type -mutable struct tru_control_type{T} +struct tru_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -46,28 +46,15 @@ mutable struct tru_control_type{T} gltr_control::gltr_control_type{T} dps_control::dps_control_type{T} psls_control::psls_control_type{T} - lms_control::lms_control_type{T} - lms_control_prec::lms_control_type{T} + lms_control::lms_control_type + lms_control_prec::lms_control_type sec_control::sec_control_type{T} sha_control::sha_control_type - - function tru_control_type{T}() where T - type = new() - type.trs_control = trs_control_type{T}() - type.gltr_control = gltr_control_type{T}() - type.dps_control = dps_control_type{T}() - type.psls_control = psls_control_type{T}() - type.lms_control = lms_control_type{T}() - type.lms_control_prec = lms_control_type{T}() - type.sec_control = sec_control_type{T}() - type.sha_control = sha_control_type() - return type - end end export tru_time_type -mutable struct tru_time_type{T} +struct tru_time_type{T} total::Float32 preprocess::Float32 analyse::Float32 @@ -78,13 +65,11 @@ mutable struct tru_time_type{T} clock_analyse::T clock_factorize::T clock_solve::T - - tru_time_type{T}() where T = new() end export tru_inform_type -mutable struct tru_inform_type{T} +struct tru_inform_type{T} status::Cint alloc_status::Cint bad_alloc::NTuple{81,Cchar} @@ -111,27 +96,13 @@ mutable struct tru_inform_type{T} lms_inform_prec::lms_inform_type{T} sec_inform::sec_inform_type sha_inform::sha_inform_type - - function tru_inform_type{T}() where T - type = new() - type.time = tru_time_type{T}() - type.trs_inform = trs_inform_type{T}() - type.gltr_inform = gltr_inform_type{T}() - type.dps_inform = dps_inform_type{T}() - type.psls_inform = psls_inform_type{T}() - type.lms_inform = lms_inform_type{T}() - type.lms_inform_prec = lms_inform_type{T}() - type.sec_inform = sec_inform_type() - type.sha_inform = sha_inform_type() - return type - end end export tru_initialize_s function tru_initialize_s(data, control, status) @ccall libgalahad_single.tru_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{tru_control_type{Float32}}, + control::Ptr{tru_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -139,28 +110,28 @@ export tru_initialize function tru_initialize(data, control, status) @ccall libgalahad_double.tru_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{tru_control_type{Float64}}, + control::Ptr{tru_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export tru_read_specfile_s function tru_read_specfile_s(control, specfile) - @ccall libgalahad_single.tru_read_specfile_s(control::Ref{tru_control_type{Float32}}, + @ccall libgalahad_single.tru_read_specfile_s(control::Ptr{tru_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export tru_read_specfile function tru_read_specfile(control, specfile) - @ccall libgalahad_double.tru_read_specfile(control::Ref{tru_control_type{Float64}}, + @ccall libgalahad_double.tru_read_specfile(control::Ptr{tru_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export tru_import_s function tru_import_s(control, data, status, n, H_type, ne, H_row, H_col, H_ptr) - @ccall libgalahad_single.tru_import_s(control::Ref{tru_control_type{Float32}}, + @ccall libgalahad_single.tru_import_s(control::Ptr{tru_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, H_type::Ptr{Cchar}, ne::Cint, H_row::Ptr{Cint}, H_col::Ptr{Cint}, H_ptr::Ptr{Cint})::Cvoid @@ -169,7 +140,7 @@ end export tru_import function tru_import(control, data, status, n, H_type, ne, H_row, H_col, H_ptr) - @ccall libgalahad_double.tru_import(control::Ref{tru_control_type{Float64}}, + @ccall libgalahad_double.tru_import(control::Ptr{tru_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, H_type::Ptr{Cchar}, ne::Cint, H_row::Ptr{Cint}, H_col::Ptr{Cint}, H_ptr::Ptr{Cint})::Cvoid @@ -178,7 +149,7 @@ end export tru_reset_control_s function tru_reset_control_s(control, data, status) - @ccall libgalahad_single.tru_reset_control_s(control::Ref{tru_control_type{Float32}}, + @ccall libgalahad_single.tru_reset_control_s(control::Ptr{tru_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -186,7 +157,7 @@ end export tru_reset_control function tru_reset_control(control, data, status) - @ccall libgalahad_double.tru_reset_control(control::Ref{tru_control_type{Float64}}, + @ccall libgalahad_double.tru_reset_control(control::Ptr{tru_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -194,31 +165,30 @@ end export tru_solve_with_mat_s function tru_solve_with_mat_s(data, userdata, status, n, x, g, ne, eval_f, eval_g, eval_h, - eval_prec) + eval_prec) @ccall libgalahad_single.tru_solve_with_mat_s(data::Ptr{Ptr{Cvoid}}, userdata::Ptr{Cvoid}, - status::Ptr{Cint}, n::Cint, - x::Ptr{Float32}, g::Ptr{Float32}, - ne::Cint, eval_f::Ptr{Cvoid}, - eval_g::Ptr{Cvoid}, eval_h::Ptr{Cvoid}, + status::Ptr{Cint}, n::Cint, x::Ptr{Float32}, + g::Ptr{Float32}, ne::Cint, + eval_f::Ptr{Cvoid}, eval_g::Ptr{Cvoid}, + eval_h::Ptr{Cvoid}, eval_prec::Ptr{Cvoid})::Cvoid end export tru_solve_with_mat function tru_solve_with_mat(data, userdata, status, n, x, g, ne, eval_f, eval_g, eval_h, - eval_prec) + eval_prec) @ccall libgalahad_double.tru_solve_with_mat(data::Ptr{Ptr{Cvoid}}, userdata::Ptr{Cvoid}, - status::Ptr{Cint}, n::Cint, - x::Ptr{Float64}, g::Ptr{Float64}, - ne::Cint, eval_f::Ptr{Cvoid}, + status::Ptr{Cint}, n::Cint, x::Ptr{Float64}, + g::Ptr{Float64}, ne::Cint, eval_f::Ptr{Cvoid}, eval_g::Ptr{Cvoid}, eval_h::Ptr{Cvoid}, eval_prec::Ptr{Cvoid})::Cvoid end export tru_solve_without_mat_s -function tru_solve_without_mat_s(data, userdata, status, n, x, g, eval_f, eval_g, eval_hprod, - eval_prec) +function tru_solve_without_mat_s(data, userdata, status, n, x, g, eval_f, eval_g, + eval_hprod, eval_prec) @ccall libgalahad_single.tru_solve_without_mat_s(data::Ptr{Ptr{Cvoid}}, userdata::Ptr{Cvoid}, status::Ptr{Cint}, n::Cint, x::Ptr{Float32}, @@ -231,19 +201,19 @@ end export tru_solve_without_mat function tru_solve_without_mat(data, userdata, status, n, x, g, eval_f, eval_g, eval_hprod, - eval_prec) + eval_prec) @ccall libgalahad_double.tru_solve_without_mat(data::Ptr{Ptr{Cvoid}}, userdata::Ptr{Cvoid}, status::Ptr{Cint}, - n::Cint, x::Ptr{Float64}, - g::Ptr{Float64}, eval_f::Ptr{Cvoid}, - eval_g::Ptr{Cvoid}, + n::Cint, x::Ptr{Float64}, g::Ptr{Float64}, + eval_f::Ptr{Cvoid}, eval_g::Ptr{Cvoid}, eval_hprod::Ptr{Cvoid}, eval_prec::Ptr{Cvoid})::Cvoid end export tru_solve_reverse_with_mat_s -function tru_solve_reverse_with_mat_s(data, status, eval_status, n, x, f, g, ne, H_val, u, v) +function tru_solve_reverse_with_mat_s(data, status, eval_status, n, x, f, g, ne, H_val, u, + v) @ccall libgalahad_single.tru_solve_reverse_with_mat_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, eval_status::Ptr{Cint}, n::Cint, @@ -262,8 +232,7 @@ function tru_solve_reverse_with_mat(data, status, eval_status, n, x, f, g, ne, H eval_status::Ptr{Cint}, n::Cint, x::Ptr{Float64}, f::Float64, g::Ptr{Float64}, ne::Cint, - H_val::Ptr{Float64}, - u::Ptr{Float64}, + H_val::Ptr{Float64}, u::Ptr{Float64}, v::Ptr{Float64})::Cvoid end @@ -274,8 +243,7 @@ function tru_solve_reverse_without_mat_s(data, status, eval_status, n, x, f, g, status::Ptr{Cint}, eval_status::Ptr{Cint}, n::Cint, x::Ptr{Float32}, f::Float32, - g::Ptr{Float32}, - u::Ptr{Float32}, + g::Ptr{Float32}, u::Ptr{Float32}, v::Ptr{Float32})::Cvoid end @@ -286,8 +254,7 @@ function tru_solve_reverse_without_mat(data, status, eval_status, n, x, f, g, u, status::Ptr{Cint}, eval_status::Ptr{Cint}, n::Cint, x::Ptr{Float64}, f::Float64, - g::Ptr{Float64}, - u::Ptr{Float64}, + g::Ptr{Float64}, u::Ptr{Float64}, v::Ptr{Float64})::Cvoid end @@ -295,7 +262,7 @@ export tru_information_s function tru_information_s(data, inform, status) @ccall libgalahad_single.tru_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{tru_inform_type{Float32}}, + inform::Ptr{tru_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -303,7 +270,7 @@ export tru_information function tru_information(data, inform, status) @ccall libgalahad_double.tru_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{tru_inform_type{Float64}}, + inform::Ptr{tru_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -311,14 +278,14 @@ export tru_terminate_s function tru_terminate_s(data, control, inform) @ccall libgalahad_single.tru_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{tru_control_type{Float32}}, - inform::Ref{tru_inform_type{Float32}})::Cvoid + control::Ptr{tru_control_type{Float32}}, + inform::Ptr{tru_inform_type{Float32}})::Cvoid end export tru_terminate function tru_terminate(data, control, inform) @ccall libgalahad_double.tru_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{tru_control_type{Float64}}, - inform::Ref{tru_inform_type{Float64}})::Cvoid + control::Ptr{tru_control_type{Float64}}, + inform::Ptr{tru_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/ugo.jl b/GALAHAD.jl/src/wrappers/ugo.jl index f2f56afc14..b7ae13b6b1 100644 --- a/GALAHAD.jl/src/wrappers/ugo.jl +++ b/GALAHAD.jl/src/wrappers/ugo.jl @@ -1,6 +1,6 @@ export ugo_control_type -mutable struct ugo_control_type{T} +struct ugo_control_type{T} error::Cint out::Cint print_level::Cint @@ -29,22 +29,18 @@ mutable struct ugo_control_type{T} space_critical::Bool deallocate_error_fatal::Bool prefix::NTuple{31,Cchar} - - ugo_control_type{T}() where T = new() end export ugo_time_type -mutable struct ugo_time_type{T} +struct ugo_time_type{T} total::Float32 clock_total::T - - ugo_time_type{T}() where T = new() end export ugo_inform_type -mutable struct ugo_inform_type{T} +struct ugo_inform_type{T} status::Cint eval_status::Cint alloc_status::Cint @@ -54,19 +50,13 @@ mutable struct ugo_inform_type{T} g_eval::Cint h_eval::Cint time::ugo_time_type{T} - - function ugo_inform_type{T}() where T - type = new() - type.time = ugo_time_type{T}() - return type - end end export ugo_initialize_s function ugo_initialize_s(data, control, status) @ccall libgalahad_single.ugo_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{ugo_control_type{Float32}}, + control::Ptr{ugo_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -74,28 +64,28 @@ export ugo_initialize function ugo_initialize(data, control, status) @ccall libgalahad_double.ugo_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{ugo_control_type{Float64}}, + control::Ptr{ugo_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export ugo_read_specfile_s function ugo_read_specfile_s(control, specfile) - @ccall libgalahad_single.ugo_read_specfile_s(control::Ref{ugo_control_type{Float32}}, + @ccall libgalahad_single.ugo_read_specfile_s(control::Ptr{ugo_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export ugo_read_specfile function ugo_read_specfile(control, specfile) - @ccall libgalahad_double.ugo_read_specfile(control::Ref{ugo_control_type{Float64}}, + @ccall libgalahad_double.ugo_read_specfile(control::Ptr{ugo_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export ugo_import_s function ugo_import_s(control, data, status, x_l, x_u) - @ccall libgalahad_single.ugo_import_s(control::Ref{ugo_control_type{Float32}}, + @ccall libgalahad_single.ugo_import_s(control::Ptr{ugo_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, x_l::Ptr{Float32}, x_u::Ptr{Float32})::Cvoid end @@ -103,7 +93,7 @@ end export ugo_import function ugo_import(control, data, status, x_l, x_u) - @ccall libgalahad_double.ugo_import(control::Ref{ugo_control_type{Float64}}, + @ccall libgalahad_double.ugo_import(control::Ptr{ugo_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, x_l::Ptr{Float64}, x_u::Ptr{Float64})::Cvoid end @@ -111,7 +101,7 @@ end export ugo_reset_control_s function ugo_reset_control_s(control, data, status) - @ccall libgalahad_single.ugo_reset_control_s(control::Ref{ugo_control_type{Float32}}, + @ccall libgalahad_single.ugo_reset_control_s(control::Ptr{ugo_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -119,7 +109,7 @@ end export ugo_reset_control function ugo_reset_control(control, data, status) - @ccall libgalahad_double.ugo_reset_control(control::Ref{ugo_control_type{Float64}}, + @ccall libgalahad_double.ugo_reset_control(control::Ptr{ugo_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -164,7 +154,7 @@ export ugo_information_s function ugo_information_s(data, inform, status) @ccall libgalahad_single.ugo_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{ugo_inform_type{Float32}}, + inform::Ptr{ugo_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -172,7 +162,7 @@ export ugo_information function ugo_information(data, inform, status) @ccall libgalahad_double.ugo_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{ugo_inform_type{Float64}}, + inform::Ptr{ugo_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -180,14 +170,14 @@ export ugo_terminate_s function ugo_terminate_s(data, control, inform) @ccall libgalahad_single.ugo_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{ugo_control_type{Float32}}, - inform::Ref{ugo_inform_type{Float32}})::Cvoid + control::Ptr{ugo_control_type{Float32}}, + inform::Ptr{ugo_inform_type{Float32}})::Cvoid end export ugo_terminate function ugo_terminate(data, control, inform) @ccall libgalahad_double.ugo_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{ugo_control_type{Float64}}, - inform::Ref{ugo_inform_type{Float64}})::Cvoid + control::Ptr{ugo_control_type{Float64}}, + inform::Ptr{ugo_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/uls.jl b/GALAHAD.jl/src/wrappers/uls.jl index c71ce04580..4ca37e4428 100644 --- a/GALAHAD.jl/src/wrappers/uls.jl +++ b/GALAHAD.jl/src/wrappers/uls.jl @@ -1,6 +1,6 @@ export uls_control_type -mutable struct uls_control_type{T} +struct uls_control_type{T} f_indexing::Bool error::Cint warning::Cint @@ -27,13 +27,11 @@ mutable struct uls_control_type{T} acceptable_residual_relative::T acceptable_residual_absolute::T prefix::NTuple{31,Cchar} - - uls_control_type{T}() where T = new() end export uls_inform_type -mutable struct uls_inform_type{T} +struct uls_inform_type{T} status::Cint alloc_status::Cint bad_alloc::NTuple{81,Cchar} @@ -57,24 +55,13 @@ mutable struct uls_inform_type{T} ma48_finfo::ma48_finfo{T} ma48_sinfo::ma48_sinfo lapack_error::Cint - - function uls_inform_type{T}() where T - type = new() - type.gls_ainfo_type = gls_ainfo_type{T}() - type.gls_finfo_type = gls_finfo_type{T}() - type.gls_sinfo_type = gls_sinfo_type() - type.ma48_ainfo = ma48_ainfo{T}() - type.ma48_finfo = ma48_finfo{T}() - type.ma48_sinfo = ma48_sinfo() - return type - end end export uls_initialize_s function uls_initialize_s(solver, data, control, status) @ccall libgalahad_single.uls_initialize_s(solver::Ptr{Cchar}, data::Ptr{Ptr{Cvoid}}, - control::Ref{uls_control_type{Float32}}, + control::Ptr{uls_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -82,28 +69,28 @@ export uls_initialize function uls_initialize(solver, data, control, status) @ccall libgalahad_double.uls_initialize(solver::Ptr{Cchar}, data::Ptr{Ptr{Cvoid}}, - control::Ref{uls_control_type{Float64}}, + control::Ptr{uls_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export uls_read_specfile_s function uls_read_specfile_s(control, specfile) - @ccall libgalahad_single.uls_read_specfile_s(control::Ref{uls_control_type{Float32}}, + @ccall libgalahad_single.uls_read_specfile_s(control::Ptr{uls_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export uls_read_specfile function uls_read_specfile(control, specfile) - @ccall libgalahad_double.uls_read_specfile(control::Ref{uls_control_type{Float64}}, + @ccall libgalahad_double.uls_read_specfile(control::Ptr{uls_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export uls_factorize_matrix_s function uls_factorize_matrix_s(control, data, status, m, n, type, ne, val, row, col, ptr) - @ccall libgalahad_single.uls_factorize_matrix_s(control::Ref{uls_control_type{Float32}}, + @ccall libgalahad_single.uls_factorize_matrix_s(control::Ptr{uls_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, m::Cint, n::Cint, type::Ptr{Cchar}, ne::Cint, val::Ptr{Float32}, @@ -114,18 +101,17 @@ end export uls_factorize_matrix function uls_factorize_matrix(control, data, status, m, n, type, ne, val, row, col, ptr) - @ccall libgalahad_double.uls_factorize_matrix(control::Ref{uls_control_type{Float64}}, + @ccall libgalahad_double.uls_factorize_matrix(control::Ptr{uls_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, m::Cint, n::Cint, type::Ptr{Cchar}, - ne::Cint, val::Ptr{Float64}, - row::Ptr{Cint}, col::Ptr{Cint}, - ptr::Ptr{Cint})::Cvoid + ne::Cint, val::Ptr{Float64}, row::Ptr{Cint}, + col::Ptr{Cint}, ptr::Ptr{Cint})::Cvoid end export uls_reset_control_s function uls_reset_control_s(control, data, status) - @ccall libgalahad_single.uls_reset_control_s(control::Ref{uls_control_type{Float32}}, + @ccall libgalahad_single.uls_reset_control_s(control::Ptr{uls_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -133,7 +119,7 @@ end export uls_reset_control function uls_reset_control(control, data, status) - @ccall libgalahad_double.uls_reset_control(control::Ref{uls_control_type{Float64}}, + @ccall libgalahad_double.uls_reset_control(control::Ptr{uls_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -158,7 +144,7 @@ export uls_information_s function uls_information_s(data, inform, status) @ccall libgalahad_single.uls_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{uls_inform_type{Float32}}, + inform::Ptr{uls_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -166,7 +152,7 @@ export uls_information function uls_information(data, inform, status) @ccall libgalahad_double.uls_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{uls_inform_type{Float64}}, + inform::Ptr{uls_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -174,14 +160,14 @@ export uls_terminate_s function uls_terminate_s(data, control, inform) @ccall libgalahad_single.uls_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{uls_control_type{Float32}}, - inform::Ref{uls_inform_type{Float32}})::Cvoid + control::Ptr{uls_control_type{Float32}}, + inform::Ptr{uls_inform_type{Float32}})::Cvoid end export uls_terminate function uls_terminate(data, control, inform) @ccall libgalahad_double.uls_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{uls_control_type{Float64}}, - inform::Ref{uls_inform_type{Float64}})::Cvoid + control::Ptr{uls_control_type{Float64}}, + inform::Ptr{uls_inform_type{Float64}})::Cvoid end diff --git a/GALAHAD.jl/src/wrappers/wcp.jl b/GALAHAD.jl/src/wrappers/wcp.jl index fa62074bda..6d25a93548 100644 --- a/GALAHAD.jl/src/wrappers/wcp.jl +++ b/GALAHAD.jl/src/wrappers/wcp.jl @@ -1,6 +1,6 @@ export wcp_control_type -mutable struct wcp_control_type{T} +struct wcp_control_type{T} f_indexing::Bool error::Cint out::Cint @@ -52,18 +52,11 @@ mutable struct wcp_control_type{T} prefix::NTuple{31,Cchar} fdc_control::fdc_control_type{T} sbls_control::sbls_control_type{T} - - function wcp_control_type{T}() where T - type = new() - type.fdc_control = fdc_control_type{T}() - type.sbls_control = sbls_control_type{T}() - return type - end end export wcp_time_type -mutable struct wcp_time_type{T} +struct wcp_time_type{T} total::T preprocess::T find_dependent::T @@ -76,13 +69,11 @@ mutable struct wcp_time_type{T} clock_analyse::T clock_factorize::T clock_solve::T - - wcp_time_type{T}() where T = new() end export wcp_inform_type -mutable struct wcp_inform_type{T} +struct wcp_inform_type{T} status::Cint alloc_status::Cint bad_alloc::NTuple{81,Cchar} @@ -102,21 +93,13 @@ mutable struct wcp_inform_type{T} time::wcp_time_type{T} fdc_inform::fdc_inform_type{T} sbls_inform::sbls_inform_type{T} - - function wcp_inform_type{T}() where T - type = new() - type.time = wcp_time_type{T}() - type.fdc_inform = fdc_inform_type{T}() - type.sbls_inform = sbls_inform_type{T}() - return type - end end export wcp_initialize_s function wcp_initialize_s(data, control, status) @ccall libgalahad_single.wcp_initialize_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{wcp_control_type{Float32}}, + control::Ptr{wcp_control_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -124,28 +107,28 @@ export wcp_initialize function wcp_initialize(data, control, status) @ccall libgalahad_double.wcp_initialize(data::Ptr{Ptr{Cvoid}}, - control::Ref{wcp_control_type{Float64}}, + control::Ptr{wcp_control_type{Float64}}, status::Ptr{Cint})::Cvoid end export wcp_read_specfile_s function wcp_read_specfile_s(control, specfile) - @ccall libgalahad_single.wcp_read_specfile_s(control::Ref{wcp_control_type{Float32}}, + @ccall libgalahad_single.wcp_read_specfile_s(control::Ptr{wcp_control_type{Float32}}, specfile::Ptr{Cchar})::Cvoid end export wcp_read_specfile function wcp_read_specfile(control, specfile) - @ccall libgalahad_double.wcp_read_specfile(control::Ref{wcp_control_type{Float64}}, + @ccall libgalahad_double.wcp_read_specfile(control::Ptr{wcp_control_type{Float64}}, specfile::Ptr{Cchar})::Cvoid end export wcp_import_s function wcp_import_s(control, data, status, n, m, A_type, A_ne, A_row, A_col, A_ptr) - @ccall libgalahad_single.wcp_import_s(control::Ref{wcp_control_type{Float32}}, + @ccall libgalahad_single.wcp_import_s(control::Ptr{wcp_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, A_type::Ptr{Cchar}, A_ne::Cint, A_row::Ptr{Cint}, A_col::Ptr{Cint}, @@ -155,7 +138,7 @@ end export wcp_import function wcp_import(control, data, status, n, m, A_type, A_ne, A_row, A_col, A_ptr) - @ccall libgalahad_double.wcp_import(control::Ref{wcp_control_type{Float64}}, + @ccall libgalahad_double.wcp_import(control::Ptr{wcp_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, A_type::Ptr{Cchar}, A_ne::Cint, A_row::Ptr{Cint}, A_col::Ptr{Cint}, @@ -165,7 +148,7 @@ end export wcp_reset_control_s function wcp_reset_control_s(control, data, status) - @ccall libgalahad_single.wcp_reset_control_s(control::Ref{wcp_control_type{Float32}}, + @ccall libgalahad_single.wcp_reset_control_s(control::Ptr{wcp_control_type{Float32}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -173,7 +156,7 @@ end export wcp_reset_control function wcp_reset_control(control, data, status) - @ccall libgalahad_double.wcp_reset_control(control::Ref{wcp_control_type{Float64}}, + @ccall libgalahad_double.wcp_reset_control(control::Ptr{wcp_control_type{Float64}}, data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint})::Cvoid end @@ -181,7 +164,7 @@ end export wcp_find_wcp_s function wcp_find_wcp_s(data, status, n, m, g, a_ne, A_val, c_l, c_u, x_l, x_u, x, c, y_l, - y_u, z_l, z_u, x_stat, c_stat) + y_u, z_l, z_u, x_stat, c_stat) @ccall libgalahad_single.wcp_find_wcp_s(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, g::Ptr{Float32}, a_ne::Cint, A_val::Ptr{Float32}, c_l::Ptr{Float32}, @@ -196,23 +179,22 @@ end export wcp_find_wcp function wcp_find_wcp(data, status, n, m, g, a_ne, A_val, c_l, c_u, x_l, x_u, x, c, y_l, - y_u, z_l, z_u, x_stat, c_stat) + y_u, z_l, z_u, x_stat, c_stat) @ccall libgalahad_double.wcp_find_wcp(data::Ptr{Ptr{Cvoid}}, status::Ptr{Cint}, n::Cint, m::Cint, g::Ptr{Float64}, a_ne::Cint, A_val::Ptr{Float64}, c_l::Ptr{Float64}, c_u::Ptr{Float64}, x_l::Ptr{Float64}, - x_u::Ptr{Float64}, x::Ptr{Float64}, - c::Ptr{Float64}, y_l::Ptr{Float64}, - y_u::Ptr{Float64}, z_l::Ptr{Float64}, - z_u::Ptr{Float64}, x_stat::Ptr{Cint}, - c_stat::Ptr{Cint})::Cvoid + x_u::Ptr{Float64}, x::Ptr{Float64}, c::Ptr{Float64}, + y_l::Ptr{Float64}, y_u::Ptr{Float64}, + z_l::Ptr{Float64}, z_u::Ptr{Float64}, + x_stat::Ptr{Cint}, c_stat::Ptr{Cint})::Cvoid end export wcp_information_s function wcp_information_s(data, inform, status) @ccall libgalahad_single.wcp_information_s(data::Ptr{Ptr{Cvoid}}, - inform::Ref{wcp_inform_type{Float32}}, + inform::Ptr{wcp_inform_type{Float32}}, status::Ptr{Cint})::Cvoid end @@ -220,7 +202,7 @@ export wcp_information function wcp_information(data, inform, status) @ccall libgalahad_double.wcp_information(data::Ptr{Ptr{Cvoid}}, - inform::Ref{wcp_inform_type{Float64}}, + inform::Ptr{wcp_inform_type{Float64}}, status::Ptr{Cint})::Cvoid end @@ -228,14 +210,14 @@ export wcp_terminate_s function wcp_terminate_s(data, control, inform) @ccall libgalahad_single.wcp_terminate_s(data::Ptr{Ptr{Cvoid}}, - control::Ref{wcp_control_type{Float32}}, - inform::Ref{wcp_inform_type{Float32}})::Cvoid + control::Ptr{wcp_control_type{Float32}}, + inform::Ptr{wcp_inform_type{Float32}})::Cvoid end export wcp_terminate function wcp_terminate(data, control, inform) @ccall libgalahad_double.wcp_terminate(data::Ptr{Ptr{Cvoid}}, - control::Ref{wcp_control_type{Float64}}, - inform::Ref{wcp_inform_type{Float64}})::Cvoid + control::Ptr{wcp_control_type{Float64}}, + inform::Ptr{wcp_inform_type{Float64}})::Cvoid end From e94c216de3ba32b047b6a6e90936b7f5ea108fd5 Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Sat, 20 Jan 2024 23:34:46 -0500 Subject: [PATCH 02/33] Update test_structures.jl --- GALAHAD.jl/test/test_structures.jl | 668 ++++++++++++++--------------- 1 file changed, 334 insertions(+), 334 deletions(-) diff --git a/GALAHAD.jl/test/test_structures.jl b/GALAHAD.jl/test/test_structures.jl index 2fe5e8e75c..3063bef470 100644 --- a/GALAHAD.jl/test/test_structures.jl +++ b/GALAHAD.jl/test/test_structures.jl @@ -1,445 +1,445 @@ # Structures for arc -arc_control_type{Float32}() -arc_control_type{Float64}() -arc_time_type{Float32}() -arc_time_type{Float64}() -arc_inform_type{Float32}() -arc_inform_type{Float64}() +Ref{arc_control_type{Float32}}() +Ref{arc_control_type{Float64}}() +Ref{arc_time_type{Float32}}() +Ref{arc_time_type{Float64}}() +Ref{arc_inform_type{Float32}}() +Ref{arc_inform_type{Float64}}() # Structures for bgo -bgo_control_type{Float32}() -bgo_control_type{Float64}() -bgo_time_type{Float32}() -bgo_time_type{Float64}() -bgo_inform_type{Float32}() -bgo_inform_type{Float64}() +Ref{bgo_control_type{Float32}}() +Ref{bgo_control_type{Float64}}() +Ref{bgo_time_type{Float32}}() +Ref{bgo_time_type{Float64}}() +Ref{bgo_inform_type{Float32}}() +Ref{bgo_inform_type{Float64}}() # Structures for blls -blls_control_type{Float32}() -blls_control_type{Float64}() -blls_time_type{Float32}() -blls_time_type{Float64}() -blls_inform_type{Float32}() -blls_inform_type{Float64}() +Ref{blls_control_type{Float32}}() +Ref{blls_control_type{Float64}}() +Ref{blls_time_type{Float32}}() +Ref{blls_time_type{Float64}}() +Ref{blls_inform_type{Float32}}() +Ref{blls_inform_type{Float64}}() # Structures for bllsb -bllsb_control_type{Float32}() -bllsb_control_type{Float64}() -bllsb_time_type{Float32}() -bllsb_time_type{Float64}() -bllsb_inform_type{Float32}() -bllsb_inform_type{Float64}() +Ref{bllsb_control_type{Float32}}() +Ref{bllsb_control_type{Float64}}() +Ref{bllsb_time_type{Float32}}() +Ref{bllsb_time_type{Float64}}() +Ref{bllsb_inform_type{Float32}}() +Ref{bllsb_inform_type{Float64}}() # Structures for bqp -bqp_control_type{Float32}() -bqp_control_type{Float64}() -bqp_time_type() -bqp_inform_type{Float32}() -bqp_inform_type{Float64}() +Ref{bqp_control_type{Float32}}() +Ref{bqp_control_type{Float64}}() +Ref{bqp_time_type}() +Ref{bqp_inform_type{Float32}}() +Ref{bqp_inform_type{Float64}}() # Structures for bqpb -bqpb_control_type{Float32}() -bqpb_control_type{Float64}() -bqpb_time_type{Float32}() -bqpb_time_type{Float64}() -bqpb_inform_type{Float32}() -bqpb_inform_type{Float64}() +Ref{bqpb_control_type{Float32}}() +Ref{bqpb_control_type{Float64}}() +Ref{bqpb_time_type{Float32}}() +Ref{bqpb_time_type{Float64}}() +Ref{bqpb_inform_type{Float32}}() +Ref{bqpb_inform_type{Float64}}() # Structures for bsc -bsc_control_type() -bsc_inform_type{Float32}() -bsc_inform_type{Float64}() +Ref{bsc_control_type}() +Ref{bsc_inform_type{Float32}}() +Ref{bsc_inform_type{Float64}}() # Structures for ccqp -ccqp_control_type{Float32}() -ccqp_control_type{Float64}() -ccqp_time_type{Float32}() -ccqp_time_type{Float64}() -ccqp_inform_type{Float32}() -ccqp_inform_type{Float64}() +Ref{ccqp_control_type{Float32}}() +Ref{ccqp_control_type{Float64}}() +Ref{ccqp_time_type{Float32}}() +Ref{ccqp_time_type{Float64}}() +Ref{ccqp_inform_type{Float32}}() +Ref{ccqp_inform_type{Float64}}() # Structures for clls -clls_control_type{Float32}() -clls_control_type{Float64}() -clls_time_type{Float32}() -clls_time_type{Float64}() -clls_inform_type{Float32}() -clls_inform_type{Float64}() +Ref{clls_control_type{Float32}}() +Ref{clls_control_type{Float64}}() +Ref{clls_time_type{Float32}}() +Ref{clls_time_type{Float64}}() +Ref{clls_inform_type{Float32}}() +Ref{clls_inform_type{Float64}}() # Structures for convert -convert_control_type() -convert_time_type{Float32}() -convert_time_type{Float64}() -convert_inform_type{Float32}() -convert_inform_type{Float64}() +Ref{convert_control_type}() +Ref{convert_time_type{Float32}}() +Ref{convert_time_type{Float64}}() +Ref{convert_inform_type{Float32}}() +Ref{convert_inform_type{Float64}}() # Structures for cqp -cqp_control_type{Float32}() -cqp_control_type{Float64}() -cqp_time_type{Float32}() -cqp_time_type{Float64}() -cqp_inform_type{Float32}() -cqp_inform_type{Float64}() +Ref{cqp_control_type{Float32}}() +Ref{cqp_control_type{Float64}}() +Ref{cqp_time_type{Float32}}() +Ref{cqp_time_type{Float64}}() +Ref{cqp_inform_type{Float32}}() +Ref{cqp_inform_type{Float64}}() # Structures for cro -cro_control_type{Float32}() -cro_control_type{Float64}() -cro_time_type{Float32}() -cro_time_type{Float64}() -cro_inform_type{Float32}() -cro_inform_type{Float64}() +Ref{cro_control_type{Float32}}() +Ref{cro_control_type{Float64}}() +Ref{cro_time_type{Float32}}() +Ref{cro_time_type{Float64}}() +Ref{cro_inform_type{Float32}}() +Ref{cro_inform_type{Float64}}() # Structures for dgo -dgo_control_type{Float32}() -dgo_control_type{Float64}() -dgo_time_type{Float32}() -dgo_time_type{Float64}() -dgo_inform_type{Float32}() -dgo_inform_type{Float64}() +Ref{dgo_control_type{Float32}}() +Ref{dgo_control_type{Float64}}() +Ref{dgo_time_type{Float32}}() +Ref{dgo_time_type{Float64}}() +Ref{dgo_inform_type{Float32}}() +Ref{dgo_inform_type{Float64}}() # Structures for dps -dps_control_type{Float32}() -dps_control_type{Float64}() -dps_time_type{Float32}() -dps_time_type{Float64}() -dps_inform_type{Float32}() -dps_inform_type{Float64}() +Ref{dps_control_type{Float32}}() +Ref{dps_control_type{Float64}}() +Ref{dps_time_type{Float32}}() +Ref{dps_time_type{Float64}}() +Ref{dps_inform_type{Float32}}() +Ref{dps_inform_type{Float64}}() # Structures for dqp -dqp_control_type{Float32}() -dqp_control_type{Float64}() -dqp_time_type{Float32}() -dqp_time_type{Float64}() -dqp_inform_type{Float32}() -dqp_inform_type{Float64}() +Ref{dqp_control_type{Float32}}() +Ref{dqp_control_type{Float64}}() +Ref{dqp_time_type{Float32}}() +Ref{dqp_time_type{Float64}}() +Ref{dqp_inform_type{Float32}}() +Ref{dqp_inform_type{Float64}}() # Structures for eqp -eqp_control_type{Float32}() -eqp_control_type{Float64}() -eqp_time_type{Float32}() -eqp_time_type{Float64}() -eqp_inform_type{Float32}() -eqp_inform_type{Float64}() +Ref{eqp_control_type{Float32}}() +Ref{eqp_control_type{Float64}}() +Ref{eqp_time_type{Float32}}() +Ref{eqp_time_type{Float64}}() +Ref{eqp_inform_type{Float32}}() +Ref{eqp_inform_type{Float64}}() # Structures for fdc -fdc_control_type{Float32}() -fdc_control_type{Float64}() -fdc_time_type{Float32}() -fdc_time_type{Float64}() -fdc_inform_type{Float32}() -fdc_inform_type{Float64}() +Ref{fdc_control_type{Float32}}() +Ref{fdc_control_type{Float64}}() +Ref{fdc_time_type{Float32}}() +Ref{fdc_time_type{Float64}}() +Ref{fdc_inform_type{Float32}}() +Ref{fdc_inform_type{Float64}}() # Structures for fit -fit_control_type() -fit_inform_type() +Ref{fit_control_type}() +Ref{fit_inform_type}() # Structures for glrt -glrt_control_type{Float32}() -glrt_control_type{Float64}() -glrt_inform_type{Float32}() -glrt_inform_type{Float64}() +Ref{glrt_control_type{Float32}}() +Ref{glrt_control_type{Float64}}() +Ref{glrt_inform_type{Float32}}() +Ref{glrt_inform_type{Float64}}() # Structures for gls -gls_control_type{Float32}() -gls_control_type{Float64}() -gls_ainfo_type{Float32}() -gls_ainfo_type{Float64}() -gls_finfo_type{Float32}() -gls_finfo_type{Float64}() -gls_sinfo_type() +Ref{gls_control_type{Float32}}() +Ref{gls_control_type{Float64}}() +Ref{gls_ainfo_type{Float32}}() +Ref{gls_ainfo_type{Float64}}() +Ref{gls_finfo_type{Float32}}() +Ref{gls_finfo_type{Float64}}() +Ref{gls_sinfo_type}() # Structures for gltr -gltr_control_type{Float32}() -gltr_control_type{Float64}() -gltr_inform_type{Float32}() -gltr_inform_type{Float64}() +Ref{gltr_control_type{Float32}}() +Ref{gltr_control_type{Float64}}() +Ref{gltr_inform_type{Float32}}() +Ref{gltr_inform_type{Float64}}() # Structures for hash -hash_control_type() -hash_inform_type() +Ref{hash_control_type}() +Ref{hash_inform_type}() # Structures for hsl -ma48_control{Float32}() -ma48_control{Float64}() -ma48_ainfo{Float32}() -ma48_ainfo{Float64}() -ma48_finfo{Float32}() -ma48_finfo{Float64}() -ma48_sinfo() -ma57_control{Float32}() -ma57_control{Float64}() -ma57_ainfo{Float32}() -ma57_ainfo{Float64}() -ma57_finfo{Float32}() -ma57_finfo{Float64}() -ma57_sinfo{Float32}() -ma57_sinfo{Float64}() -ma77_control{Float32}() -ma77_control{Float64}() -ma77_info{Float32}() -ma77_info{Float64}() -ma86_control{Float32}() -ma86_control{Float64}() -ma86_info{Float32}() -ma86_info{Float64}() -ma87_control{Float32}() -ma87_control{Float64}() -ma87_info{Float32}() -ma87_info{Float64}() -ma97_control{Float32}() -ma97_control{Float64}() -ma97_info{Float32}() -ma97_info{Float64}() -mc64_control() -mc64_info() -mc68_control() -mc68_info() -mi20_control{Float32}() -mi20_control{Float64}() -mi20_solve_control{Float32}() -mi20_solve_control{Float64}() -mi20_info{Float32}() -mi20_info{Float64}() -mi28_control{Float32}() -mi28_control{Float64}() -mi28_info{Float32}() -mi28_info{Float64}() +Ref{ma48_control{Float32}}() +Ref{ma48_control{Float64}}() +Ref{ma48_ainfo{Float32}}() +Ref{ma48_ainfo{Float64}}() +Ref{ma48_finfo{Float32}}() +Ref{ma48_finfo{Float64}}() +Ref{ma48_sinfo}() +Ref{ma57_control{Float32}}() +Ref{ma57_control{Float64}}() +Ref{ma57_ainfo{Float32}}() +Ref{ma57_ainfo{Float64}}() +Ref{ma57_finfo{Float32}}() +Ref{ma57_finfo{Float64}}() +Ref{ma57_sinfo{Float32}}() +Ref{ma57_sinfo{Float64}}() +Ref{ma77_control{Float32}}() +Ref{ma77_control{Float64}}() +Ref{ma77_info{Float32}}() +Ref{ma77_info{Float64}}() +Ref{ma86_control{Float32}}() +Ref{ma86_control{Float64}}() +Ref{ma86_info{Float32}}() +Ref{ma86_info{Float64}}() +Ref{ma87_control{Float32}}() +Ref{ma87_control{Float64}}() +Ref{ma87_info{Float32}}() +Ref{ma87_info{Float64}}() +Ref{ma97_control{Float32}}() +Ref{ma97_control{Float64}}() +Ref{ma97_info{Float32}}() +Ref{ma97_info{Float64}}() +Ref{mc64_control}() +Ref{mc64_info}() +Ref{mc68_control}() +Ref{mc68_info}() +Ref{mi20_control{Float32}}() +Ref{mi20_control{Float64}}() +Ref{mi20_solve_control{Float32}}() +Ref{mi20_solve_control{Float64}}() +Ref{mi20_info{Float32}}() +Ref{mi20_info{Float64}}() +Ref{mi28_control{Float32}}() +Ref{mi28_control{Float64}}() +Ref{mi28_info{Float32}}() +Ref{mi28_info{Float64}}() # Structures for ir -ir_control_type{Float32}() -ir_control_type{Float64}() -ir_inform_type{Float32}() -ir_inform_type{Float64}() +Ref{ir_control_type{Float32}}() +Ref{ir_control_type{Float64}}() +Ref{ir_inform_type{Float32}}() +Ref{ir_inform_type{Float64}}() # Structures for l2rt -l2rt_control_type{Float32}() -l2rt_control_type{Float64}() -l2rt_inform_type{Float32}() -l2rt_inform_type{Float64}() +Ref{l2rt_control_type{Float32}}() +Ref{l2rt_control_type{Float64}}() +Ref{l2rt_inform_type{Float32}}() +Ref{l2rt_inform_type{Float64}}() # Structures for lhs -lhs_control_type() -lhs_inform_type() +Ref{lhs_control_type}() +Ref{lhs_inform_type}() # Structures for llsr -llsr_control_type{Float32}() -llsr_control_type{Float64}() -llsr_time_type{Float32}() -llsr_time_type{Float64}() -llsr_history_type{Float32}() -llsr_history_type{Float64}() -llsr_inform_type{Float32}() -llsr_inform_type{Float64}() +Ref{llsr_control_type{Float32}}() +Ref{llsr_control_type{Float64}}() +Ref{llsr_time_type{Float32}}() +Ref{llsr_time_type{Float64}}() +Ref{llsr_history_type{Float32}}() +Ref{llsr_history_type{Float64}}() +Ref{llsr_inform_type{Float32}}() +Ref{llsr_inform_type{Float64}}() # Structures for llst -llst_control_type{Float32}() -llst_control_type{Float64}() -llst_time_type{Float32}() -llst_time_type{Float64}() -llst_history_type{Float32}() -llst_history_type{Float64}() -llst_inform_type{Float32}() -llst_inform_type{Float64}() +Ref{llst_control_type{Float32}}() +Ref{llst_control_type{Float64}}() +Ref{llst_time_type{Float32}}() +Ref{llst_time_type{Float64}}() +Ref{llst_history_type{Float32}}() +Ref{llst_history_type{Float64}}() +Ref{llst_inform_type{Float32}}() +Ref{llst_inform_type{Float64}}() # Structures for lms -lms_control_type{Float32}() -lms_control_type{Float64}() -lms_time_type{Float32}() -lms_time_type{Float64}() -lms_inform_type{Float32}() -lms_inform_type{Float64}() +Ref{lms_control_type}() +Ref{lms_time_type{Float32}}() +Ref{lms_time_type{Float64}}() +Ref{lms_inform_type{Float32}}() +Ref{lms_inform_type{Float64}}() # Structures for lpa -lpa_control_type{Float32}() -lpa_control_type{Float64}() -lpa_time_type{Float32}() -lpa_time_type{Float64}() -lpa_inform_type{Float32}() -lpa_inform_type{Float64}() +Ref{lpa_control_type{Float32}}() +Ref{lpa_control_type{Float64}}() +Ref{lpa_time_type{Float32}}() +Ref{lpa_time_type{Float64}}() +Ref{lpa_inform_type{Float32}}() +Ref{lpa_inform_type{Float64}}() # Structures for lpb -lpb_control_type{Float32}() -lpb_control_type{Float64}() -lpb_time_type{Float32}() -lpb_time_type{Float64}() -lpb_inform_type{Float32}() -lpb_inform_type{Float64}() +Ref{lpb_control_type{Float32}}() +Ref{lpb_control_type{Float64}}() +Ref{lpb_time_type{Float32}}() +Ref{lpb_time_type{Float64}}() +Ref{lpb_inform_type{Float32}}() +Ref{lpb_inform_type{Float64}}() # Structures for lsqp -lsqp_control_type{Float32}() -lsqp_control_type{Float64}() -lsqp_time_type{Float32}() -lsqp_time_type{Float64}() -lsqp_inform_type{Float32}() -lsqp_inform_type{Float64}() +Ref{lsqp_control_type{Float32}}() +Ref{lsqp_control_type{Float64}}() +Ref{lsqp_time_type{Float32}}() +Ref{lsqp_time_type{Float64}}() +Ref{lsqp_inform_type{Float32}}() +Ref{lsqp_inform_type{Float64}}() # Structures for lsrt -lsrt_control_type{Float32}() -lsrt_control_type{Float64}() -lsrt_inform_type{Float32}() -lsrt_inform_type{Float64}() +Ref{lsrt_control_type{Float32}}() +Ref{lsrt_control_type{Float64}}() +Ref{lsrt_inform_type{Float32}}() +Ref{lsrt_inform_type{Float64}}() # Structures for lstr -lstr_control_type{Float32}() -lstr_control_type{Float64}() -lstr_inform_type{Float32}() -lstr_inform_type{Float64}() +Ref{lstr_control_type{Float32}}() +Ref{lstr_control_type{Float64}}() +Ref{lstr_inform_type{Float32}}() +Ref{lstr_inform_type{Float64}}() # Structures for nls -nls_subproblem_control_type{Float32}() -nls_subproblem_control_type{Float64}() -nls_control_type{Float32}() -nls_control_type{Float64}() -nls_time_type{Float32}() -nls_time_type{Float64}() -nls_subproblem_inform_type{Float32}() -nls_subproblem_inform_type{Float64}() -nls_inform_type{Float32}() -nls_inform_type{Float64}() +Ref{nls_subproblem_control_type{Float32}}() +Ref{nls_subproblem_control_type{Float64}}() +Ref{nls_control_type{Float32}}() +Ref{nls_control_type{Float64}}() +Ref{nls_time_type{Float32}}() +Ref{nls_time_type{Float64}}() +Ref{nls_subproblem_inform_type{Float32}}() +Ref{nls_subproblem_inform_type{Float64}}() +Ref{nls_inform_type{Float32}}() +Ref{nls_inform_type{Float64}}() # Structures for presolve -presolve_control_type{Float32}() -presolve_control_type{Float64}() -presolve_inform_type() +Ref{presolve_control_type{Float32}}() +Ref{presolve_control_type{Float64}}() +Ref{presolve_inform_type}() # Structures for psls -psls_control_type{Float32}() -psls_control_type{Float64}() -psls_time_type{Float32}() -psls_time_type{Float64}() -psls_inform_type{Float32}() -psls_inform_type{Float64}() +Ref{psls_control_type{Float32}}() +Ref{psls_control_type{Float64}}() +Ref{psls_time_type{Float32}}() +Ref{psls_time_type{Float64}}() +Ref{psls_inform_type{Float32}}() +Ref{psls_inform_type{Float64}}() # Structures for qpa -qpa_control_type{Float32}() -qpa_control_type{Float64}() -qpa_time_type{Float32}() -qpa_time_type{Float64}() -qpa_inform_type{Float32}() -qpa_inform_type{Float64}() +Ref{qpa_control_type{Float32}}() +Ref{qpa_control_type{Float64}}() +Ref{qpa_time_type{Float32}}() +Ref{qpa_time_type{Float64}}() +Ref{qpa_inform_type{Float32}}() +Ref{qpa_inform_type{Float64}}() # Structures for qpb -qpb_control_type{Float32}() -qpb_control_type{Float64}() -qpb_time_type{Float32}() -qpb_time_type{Float64}() -qpb_inform_type{Float32}() -qpb_inform_type{Float64}() +Ref{qpb_control_type{Float32}}() +Ref{qpb_control_type{Float64}}() +Ref{qpb_time_type{Float32}}() +Ref{qpb_time_type{Float64}}() +Ref{qpb_inform_type{Float32}}() +Ref{qpb_inform_type{Float64}}() # Structures for roots -roots_control_type{Float32}() -roots_control_type{Float64}() -roots_inform_type() +Ref{roots_control_type{Float32}}() +Ref{roots_control_type{Float64}}() +Ref{roots_inform_type}() # Structures for rpd -rpd_control_type() -rpd_inform_type() +Ref{rpd_control_type}() +Ref{rpd_inform_type}() # Structures for rqs -rqs_control_type{Float32}() -rqs_control_type{Float64}() -rqs_time_type{Float32}() -rqs_time_type{Float64}() -rqs_history_type{Float32}() -rqs_history_type{Float64}() -rqs_inform_type{Float32}() -rqs_inform_type{Float64}() +Ref{rqs_control_type{Float32}}() +Ref{rqs_control_type{Float64}}() +Ref{rqs_time_type{Float32}}() +Ref{rqs_time_type{Float64}}() +Ref{rqs_history_type{Float32}}() +Ref{rqs_history_type{Float64}}() +Ref{rqs_inform_type{Float32}}() +Ref{rqs_inform_type{Float64}}() # Structures for sbls -sbls_control_type{Float32}() -sbls_control_type{Float64}() -sbls_time_type{Float32}() -sbls_time_type{Float64}() -sbls_inform_type{Float32}() -sbls_inform_type{Float64}() +Ref{sbls_control_type{Float32}}() +Ref{sbls_control_type{Float64}}() +Ref{sbls_time_type{Float32}}() +Ref{sbls_time_type{Float64}}() +Ref{sbls_inform_type{Float32}}() +Ref{sbls_inform_type{Float64}}() # Structures for scu -scu_control_type() -scu_inform_type() +Ref{scu_control_type}() +Ref{scu_inform_type}() # Structures for sec -sec_control_type{Float32}() -sec_control_type{Float64}() -sec_inform_type() +Ref{sec_control_type{Float32}}() +Ref{sec_control_type{Float64}}() +Ref{sec_inform_type}() # Structures for sha -sha_control_type() -sha_inform_type() +Ref{sha_control_type}() +Ref{sha_inform_type}() # Structures for sils -sils_control_type{Float32}() -sils_control_type{Float64}() -sils_ainfo_type{Float32}() -sils_ainfo_type{Float64}() -sils_finfo_type{Float32}() -sils_finfo_type{Float64}() -sils_sinfo_type{Float32}() -sils_sinfo_type{Float64}() +Ref{sils_control_type{Float32}}() +Ref{sils_control_type{Float64}}() +Ref{sils_ainfo_type{Float32}}() +Ref{sils_ainfo_type{Float64}}() +Ref{sils_finfo_type{Float32}}() +Ref{sils_finfo_type{Float64}}() +Ref{sils_sinfo_type{Float32}}() +Ref{sils_sinfo_type{Float64}}() # Structures for slls -slls_control_type{Float32}() -slls_control_type{Float64}() -slls_time_type() -slls_inform_type{Float32}() -slls_inform_type{Float64}() +Ref{slls_control_type{Float32}}() +Ref{slls_control_type{Float64}}() +Ref{slls_time_type}() +Ref{slls_inform_type{Float32}}() +Ref{slls_inform_type{Float64}}() # Structures for sls -sls_control_type{Float32}() -sls_control_type{Float64}() -sls_time_type{Float32}() -sls_time_type{Float64}() -sls_inform_type{Float32}() -sls_inform_type{Float64}() +Ref{sls_control_type{Float32}}() +Ref{sls_control_type{Float64}}() +Ref{sls_time_type{Float32}}() +Ref{sls_time_type{Float64}}() +Ref{sls_inform_type{Float32}}() +Ref{sls_inform_type{Float64}}() # Structures for ssids -spral_ssids_options{Float32}() -spral_ssids_options{Float64}() -spral_ssids_inform() +Ref{spral_ssids_options{Float32}}() +Ref{spral_ssids_options{Float64}}() +Ref{spral_ssids_inform}() # Structures for trb -trb_control_type{Float32}() -trb_control_type{Float64}() -trb_time_type{Float32}() -trb_time_type{Float64}() -trb_inform_type{Float32}() -trb_inform_type{Float64}() +Ref{trb_control_type{Float32}}() +Ref{trb_control_type{Float64}}() +Ref{trb_time_type{Float32}}() +Ref{trb_time_type{Float64}}() +Ref{trb_inform_type{Float32}}() +Ref{trb_inform_type{Float64}}() # Structures for trs -trs_control_type{Float32}() -trs_control_type{Float64}() -trs_time_type{Float32}() -trs_time_type{Float64}() -trs_history_type{Float32}() -trs_history_type{Float64}() -trs_inform_type{Float32}() -trs_inform_type{Float64}() +Ref{trs_control_type{Float32}}() +Ref{trs_control_type{Float64}}() +Ref{trs_time_type{Float32}}() +Ref{trs_time_type{Float64}}() +Ref{trs_history_type{Float32}}() +Ref{trs_history_type{Float64}}() +Ref{trs_inform_type{Float32}}() +Ref{trs_inform_type{Float64}}() # Structures for tru -tru_control_type{Float32}() -tru_control_type{Float64}() -tru_time_type{Float32}() -tru_time_type{Float64}() -tru_inform_type{Float32}() -tru_inform_type{Float64}() +Ref{tru_control_type{Float32}}() +Ref{tru_control_type{Float64}}() +Ref{tru_time_type{Float32}}() +Ref{tru_time_type{Float64}}() +Ref{tru_inform_type{Float32}}() +Ref{tru_inform_type{Float64}}() # Structures for ugo -ugo_control_type{Float32}() -ugo_control_type{Float64}() -ugo_time_type{Float32}() -ugo_time_type{Float64}() -ugo_inform_type{Float32}() -ugo_inform_type{Float64}() +Ref{ugo_control_type{Float32}}() +Ref{ugo_control_type{Float64}}() +Ref{ugo_time_type{Float32}}() +Ref{ugo_time_type{Float64}}() +Ref{ugo_inform_type{Float32}}() +Ref{ugo_inform_type{Float64}}() # Structures for uls -uls_control_type{Float32}() -uls_control_type{Float64}() -uls_inform_type{Float32}() -uls_inform_type{Float64}() +Ref{uls_control_type{Float32}}() +Ref{uls_control_type{Float64}}() +Ref{uls_inform_type{Float32}}() +Ref{uls_inform_type{Float64}}() # Structures for wcp -wcp_control_type{Float32}() -wcp_control_type{Float64}() -wcp_time_type{Float32}() -wcp_time_type{Float64}() -wcp_inform_type{Float32}() -wcp_inform_type{Float64}() +Ref{wcp_control_type{Float32}}() +Ref{wcp_control_type{Float64}}() +Ref{wcp_time_type{Float32}}() +Ref{wcp_time_type{Float64}}() +Ref{wcp_inform_type{Float32}}() +Ref{wcp_inform_type{Float64}}() + From 0e5cf0dc8e71e78b052fc191fbd4c26ed907cc43 Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Sun, 21 Jan 2024 15:31:01 -0500 Subject: [PATCH 03/33] Remove the empty C interface of dlp --- src/dlp/C/dlp_ciface.F90 | 0 src/dlp/meson.build | 2 -- 2 files changed, 2 deletions(-) delete mode 100644 src/dlp/C/dlp_ciface.F90 diff --git a/src/dlp/C/dlp_ciface.F90 b/src/dlp/C/dlp_ciface.F90 deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/src/dlp/meson.build b/src/dlp/meson.build index 75c12f5d5c..fe580a7f92 100644 --- a/src/dlp/meson.build +++ b/src/dlp/meson.build @@ -2,8 +2,6 @@ libgalahad_src += files('dlp.F90') galahad_binaries += [['indlp', files('indlp.F90')]] -libgalahad_c_src += files('C/dlp_ciface.F90') - libgalahad_cutest_src += files('usedlp.F90') galahad_cutest_binaries += [['rundlp_sif', files('rundlp_sif.F90')]] From f5a4af1ecce4090f2794790b16eaf9154f81544c Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Sun, 21 Jan 2024 16:07:13 -0500 Subject: [PATCH 04/33] Fix a typo in the C files of UGO --- src/ugo/C/ugos.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ugo/C/ugos.c b/src/ugo/C/ugos.c index 69e06157bd..ed86b71d03 100644 --- a/src/ugo/C/ugos.c +++ b/src/ugo/C/ugos.c @@ -67,7 +67,7 @@ int main(void) { printf("%" i_ipc_ " evaluations. Optimal objective value = %5.2f" " at x = %5.2f, status = %1" i_ipc_ "\n", inform.f_eval, f, x, inform.status); }else{ - printf("BGO_solve exit status = %1" i_ipc_ "\n", inform.status); + printf("UGO_solve exit status = %1" i_ipc_ "\n", inform.status); } // Delete internal workspace From 35e932af533c2d96d333b6a8fb29b958fb8bac0f Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Sun, 21 Jan 2024 16:08:06 -0500 Subject: [PATCH 05/33] [GALAHAD.jl] Update README.md --- GALAHAD.jl/README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/GALAHAD.jl/README.md b/GALAHAD.jl/README.md index a0a76ee9c4..cb3c9e2fd1 100644 --- a/GALAHAD.jl/README.md +++ b/GALAHAD.jl/README.md @@ -57,7 +57,5 @@ permanently in the shell's startup file, or in ## Documentation -Documentation is available online from - - https://ralna.github.io/galahad_docs/html/Julia +Documentation is available online from [https://ralna.github.io/galahad_docs/html/Julia](https://ralna.github.io/galahad_docs/html/Julia). From 0f0818d17dc3d4380f7eca02dfbbc5cbf7a5f53c Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Sun, 21 Jan 2024 16:12:57 -0500 Subject: [PATCH 06/33] [GALAHAD.jl] Update the gen folder --- GALAHAD.jl/gen/examples.jl | 165 ++++++++++++++++++++----------------- GALAHAD.jl/gen/rewriter.jl | 2 +- GALAHAD.jl/gen/wrapper.jl | 5 +- 3 files changed, 94 insertions(+), 78 deletions(-) diff --git a/GALAHAD.jl/gen/examples.jl b/GALAHAD.jl/gen/examples.jl index 165fc8f632..4d7a2d40ad 100644 --- a/GALAHAD.jl/gen/examples.jl +++ b/GALAHAD.jl/gen/examples.jl @@ -1,13 +1,24 @@ +using JuliaFormatter + function examples(package::String, example::String) if example == "" - text = "# test_" * package * ".jl\n# Simple code to test the Julia interface to " * uppercase(package) * "\n" + text = "# test_" * package * ".jl\n# Simple code to test the Julia interface to " * uppercase(package) * "\n\n" + text = text * "using GALAHAD\nusing Test\n\nfunction test_$package()\n" + text = text * " data = Ref{Ptr{Cvoid}}()\n" + text = text * " control = Ref{$(package)_control_type{Float64}}()\n" + text = text * " inform = Ref{$(package)_inform_type{Float64}}()\n\n" + text = text * " status = Ref{Cint}()\n" + text = text * " $(package)_initialize(data, control, status)\n" + text = text * " $(package)_information(data, inform, status)\n" + text = text * " $(package)_terminate(data, control, inform)\n\n" + text = text * " return 0\n" else src = "../../src/$package/C/" * package * example * ".c" text = read(src, String) end 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 Printf\n\n") + 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, "//" => "#") text = replace(text, ";" => "") text = replace(text, "&" => "") @@ -17,19 +28,21 @@ function examples(package::String, example::String) text = replace(text, "else if" => "elseif") text = replace(text, "}else{" => "else") text = replace(text, "} else {" => "else") - text = replace(text, "void *data" => "data = [Ptr{Ptr{Cvoid}}()]") - text = replace(text, "struct $(package)_control_type control" => "control = $(package)_control_type{Float64}()") - text = replace(text, "struct $(package)_inform_type inform" => "inform = $(package)_inform_type{Float64}()") + text = replace(text, "void *data" => "data = Ref{Ptr{Cvoid}}()") + text = replace(text, "struct $(package)_control_type control" => "control = Ref{$(package)_control_type{Float64}}()") + text = replace(text, "struct $(package)_inform_type inform" => "inform = Ref{$(package)_inform_type{Float64}}()") + text = replace(text, "control." => "control[].") + text = replace(text, "inform." => "inform[].") text = replace(text, "} #" => "] #") text = replace(text, "} #" => "] #") text = replace(text, "} #" => "] #") - for var in ("f", "power", "weight", "shift", "radius", "half_radius") - text = replace(text, "real_wp_ $var =" => "$var =") - end 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") text = replace(text, "real_wp_ $var[] = {" => "$var = Float64[") end + for var in ("f", "power", "weight", "shift", "radius", "half_radius", "x_l", "x_u") + text = replace(text, "real_wp_ $var =" => "$var =") + end for var in ("n", "ne", "m", "A_ne", "A_dense_ne", "H_ne", "H_dense_ne") text = replace(text, "int $var =" => "$var =") end @@ -85,77 +98,81 @@ function examples(package::String, example::String) text = replace(text, "#for" => "# for") text = replace(text, "#@" => "# @") text = replace(text, "# for i = 1:n @" => "# for i = 1:n\n# @") + text = replace(text, "( " => "(") + text = replace(text, " )" => ")") + text = text * "end\n\n@testset \"" * uppercase(package) * "\" begin\n @test test_$package() == 0\nend\n" write(dst, text) + (example == "") && clean_example(package) # Generate a symbolic link for the Julia tests - current_folder = pwd() - cd("../../src/$package") - !isdir("Julia") && mkdir("Julia") - cd("Julia") - rm("test_$package.jl", force=true) - symlink("../../../GALAHAD.jl/test/test_$package.jl", "test_$package.jl") - cd(current_folder) - end + current_folder = pwd() + cd("../../src/$package") + !isdir("Julia") && mkdir("Julia") + cd("Julia") + rm("test_$package.jl", force=true) + symlink("../../../GALAHAD.jl/test/test_$package.jl", "test_$package.jl") + cd(current_folder) end -function main(name::String="all") - (name == "all" || name == "arc") && examples("arc" , "tf") - (name == "all" || name == "bgo") && examples("bgo" , "tf") - (name == "all" || name == "blls") && examples("blls" , "tf") - (name == "all" || name == "bllsb") && examples("bllsb" , "tf") - (name == "all" || name == "bqp") && examples("bqp" , "tf") - (name == "all" || name == "bqpb") && examples("bqpb" , "tf") - (name == "all" || name == "bsc") && examples("bsc" , "" ) - (name == "all" || name == "ccqp") && examples("ccqp" , "tf") - (name == "all" || name == "clls") && examples("clls" , "tf") - (name == "all" || name == "convert") && examples("convert" , "" ) - (name == "all" || name == "cqp") && examples("cqp" , "tf") - (name == "all" || name == "cro") && examples("cro" , "tf") - (name == "all" || name == "dgo") && examples("dgo" , "tf") - (name == "all" || name == "dps") && examples("dps" , "tf") - (name == "all" || name == "dqp") && examples("dqp" , "tf") - (name == "all" || name == "eqp") && examples("eqp" , "tf") - (name == "all" || name == "fdc") && examples("fdc" , "tf") - (name == "all" || name == "fit") && examples("fit" , "" ) - (name == "all" || name == "glrt") && examples("glrt" , "t" ) - (name == "all" || name == "gls") && examples("gls" , "" ) - (name == "all" || name == "gltr") && examples("gltr" , "t" ) - (name == "all" || name == "hash") && examples("hash" , "" ) - (name == "all" || name == "ir") && examples("ir" , "" ) - (name == "all" || name == "l2rt") && examples("l2rt" , "t" ) - (name == "all" || name == "lhs") && examples("lhs" , "t" ) - (name == "all" || name == "llsr") && examples("llsr" , "tf") - (name == "all" || name == "llst") && examples("llst" , "tf") - (name == "all" || name == "lms") && examples("lms" , "" ) - (name == "all" || name == "lpa") && examples("lpa" , "tf") - (name == "all" || name == "lpb") && examples("lpb" , "tf") - (name == "all" || name == "lsqp") && examples("lsqp" , "tf") - (name == "all" || name == "lsrt") && examples("lsrt" , "t" ) - (name == "all" || name == "lstr") && examples("lstr" , "t" ) - (name == "all" || name == "nls") && examples("nls" , "tf") - (name == "all" || name == "presolve") && examples("presolve", "tf") - (name == "all" || name == "psls") && examples("psls" , "tf") - (name == "all" || name == "qpa") && examples("qpa" , "tf") - (name == "all" || name == "qpb") && examples("qpb" , "tf") - (name == "all" || name == "roots") && examples("roots" , "" ) - (name == "all" || name == "rpd") && examples("rpd" , "tf") - (name == "all" || name == "rqs") && examples("rqs" , "tf") - (name == "all" || name == "sbls") && examples("sbls" , "tf") - (name == "all" || name == "scu") && examples("scu" , "" ) - (name == "all" || name == "sec") && examples("sec" , "" ) - (name == "all" || name == "sha") && examples("sha" , "" ) - (name == "all" || name == "sils") && examples("sils" , "" ) - (name == "all" || name == "slls") && examples("slls" , "tf") - (name == "all" || name == "sls") && examples("sls" , "tf") - (name == "all" || name == "trb") && examples("trb" , "tf") - (name == "all" || name == "trs") && examples("trs" , "tf") - (name == "all" || name == "tru") && examples("tru" , "tf") - (name == "all" || name == "ugo") && examples("ugo" , "t" ) - (name == "all" || name == "uls") && examples("uls" , "tf") - (name == "all" || name == "wcp") && examples("wcp" , "tf") +function main(name::String) + (name == "arc") && examples("arc" , "tf") + (name == "bgo") && examples("bgo" , "tf") + (name == "blls") && examples("blls" , "tf") + (name == "bllsb") && examples("bllsb" , "tf") + (name == "bqp") && examples("bqp" , "tf") + (name == "bqpb") && examples("bqpb" , "tf") + (name == "bsc") && examples("bsc" , "" ) + (name == "ccqp") && examples("ccqp" , "tf") + (name == "clls") && examples("clls" , "tf") + (name == "convert") && examples("convert" , "" ) + (name == "cqp") && examples("cqp" , "tf") + (name == "cro") && examples("cro" , "tf") + (name == "dgo") && examples("dgo" , "tf") + (name == "dps") && examples("dps" , "tf") + (name == "dqp") && examples("dqp" , "tf") + (name == "eqp") && examples("eqp" , "tf") + (name == "fdc") && examples("fdc" , "tf") + (name == "fit") && examples("fit" , "" ) + (name == "glrt") && examples("glrt" , "t" ) + (name == "gls") && examples("gls" , "" ) + (name == "gltr") && examples("gltr" , "t" ) + (name == "hash") && examples("hash" , "" ) + (name == "ir") && examples("ir" , "" ) + (name == "l2rt") && examples("l2rt" , "t" ) + (name == "lhs") && examples("lhs" , "t" ) + (name == "llsr") && examples("llsr" , "tf") + (name == "llst") && examples("llst" , "tf") + (name == "lms") && examples("lms" , "" ) + (name == "lpa") && examples("lpa" , "tf") + (name == "lpb") && examples("lpb" , "tf") + (name == "lsqp") && examples("lsqp" , "tf") + (name == "lsrt") && examples("lsrt" , "t" ) + (name == "lstr") && examples("lstr" , "t" ) + (name == "nls") && examples("nls" , "tf") + (name == "presolve") && examples("presolve", "tf") + (name == "psls") && examples("psls" , "tf") + (name == "qpa") && examples("qpa" , "tf") + (name == "qpb") && examples("qpb" , "tf") + (name == "roots") && examples("roots" , "" ) + (name == "rpd") && examples("rpd" , "tf") + (name == "rqs") && examples("rqs" , "tf") + (name == "sbls") && examples("sbls" , "tf") + (name == "scu") && examples("scu" , "" ) + (name == "sec") && examples("sec" , "" ) + (name == "sha") && examples("sha" , "" ) + (name == "sils") && examples("sils" , "" ) + (name == "slls") && examples("slls" , "tf") + (name == "sls") && examples("sls" , "tf") + (name == "trb") && examples("trb" , "tf") + (name == "trs") && examples("trs" , "tf") + (name == "tru") && examples("tru" , "tf") + (name == "ugo") && examples("ugo" , "t" ) + (name == "uls") && examples("uls" , "tf") + (name == "wcp") && examples("wcp" , "tf") end -# If we want to use the file as a script with `julia wrapper.jl` -if abspath(PROGRAM_FILE) == @__FILE__ - main() +function clean_example(package::String) + path = "../test/test_" * package * ".jl" + isfile(path) || error("The file test_$package.jl doesn't exist.") + format_file(path, YASStyle(), indent=2) end diff --git a/GALAHAD.jl/gen/rewriter.jl b/GALAHAD.jl/gen/rewriter.jl index da97ed27ef..2330d480e6 100644 --- a/GALAHAD.jl/gen/rewriter.jl +++ b/GALAHAD.jl/gen/rewriter.jl @@ -102,7 +102,7 @@ function rewrite!(path::String, name::String, optimized::Bool) end end - isfile("../test/test_structures.jl") || write("../test/test_structures.jl", "") + isfile("../test/test_structures.jl") || write("../test/test_structures.jl", "using GALAHAD\n\n") test = read("../test/test_structures.jl", String) structures = structures * "\n" write("../test/test_structures.jl", test * structures) diff --git a/GALAHAD.jl/gen/wrapper.jl b/GALAHAD.jl/gen/wrapper.jl index 0a44644cf0..2f391aea30 100644 --- a/GALAHAD.jl/gen/wrapper.jl +++ b/GALAHAD.jl/gen/wrapper.jl @@ -87,12 +87,11 @@ function main(name::String="all"; optimized::Bool=true) (name == "all" || name == "gltr") && wrapper("gltr", ["$galahad/galahad_gltr.h"], optimized) (name == "all" || name == "hash") && wrapper("hash", ["$galahad/galahad_hash.h"], optimized) (name == "all" || name == "hsl") && wrapper("hsl", ["$galahad/hsl_ma48.h", "$galahad/hsl_ma57.h", "$galahad/hsl_ma77.h", "$galahad/hsl_ma86.h", "$galahad/hsl_ma87.h", "$galahad/hsl_ma97.h", "$galahad/hsl_mc64.h", "$galahad/hsl_mc68.h", "$galahad/hsl_mi20.h", "$galahad/hsl_mi28.h"], optimized) - # (name == "all" || name == "icfs") && wrapper("icfs", ["$galahad/galahad_icfs.h"], optimized) (name == "all" || name == "ir") && wrapper("ir", ["$galahad/galahad_ir.h"], optimized) (name == "all" || name == "l2rt") && wrapper("l2rt", ["$galahad/galahad_l2rt.h"], optimized) (name == "all" || name == "lhs") && wrapper("lhs", ["$galahad/galahad_lhs.h"], optimized) - (name == "all" || name == "llsr") && wrapper("llsr", ["$galahad/galahad_llsr.h"], optimized) - (name == "all" || name == "llst") && wrapper("llst", ["$galahad/galahad_llst.h"], optimized) + (name == "all" || name == "llsr") && wrapper("llsr", ["$galahad/galahad_llsr.h"], optimized) + (name == "all" || name == "llst") && wrapper("llst", ["$galahad/galahad_llst.h"], optimized) (name == "all" || name == "lms") && wrapper("lms", ["$galahad/galahad_lms.h"], optimized) (name == "all" || name == "lpa") && wrapper("lpa", ["$galahad/galahad_lpa.h"], optimized) (name == "all" || name == "lpb") && wrapper("lpb", ["$galahad/galahad_lpb.h"], optimized) From b2acb82bd82d896b475d22185c0e184a582cdc9e Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Sun, 21 Jan 2024 16:13:37 -0500 Subject: [PATCH 07/33] [GALAHAD.jl] Add Accessors in the Poject.toml --- GALAHAD.jl/Project.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/GALAHAD.jl/Project.toml b/GALAHAD.jl/Project.toml index 431f3264e4..2ffa4d8cc8 100644 --- a/GALAHAD.jl/Project.toml +++ b/GALAHAD.jl/Project.toml @@ -13,6 +13,7 @@ julia = "1.9" [extras] Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697" [targets] -test = ["Test", "Printf"] +test = ["Test", "Printf", "Accessors"] From a7c490340b6947025f272b7cdfca52402b2f664f Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Sun, 21 Jan 2024 16:18:36 -0500 Subject: [PATCH 08/33] [GALAHAD.jl] Update the Julia tests --- GALAHAD.jl/test/runtests.jl | 69 ++++++++++++++++++++++++------ GALAHAD.jl/test/test_bsc.jl | 20 +++++++++ GALAHAD.jl/test/test_convert.jl | 20 +++++++++ GALAHAD.jl/test/test_fit.jl | 20 +++++++++ GALAHAD.jl/test/test_gls.jl | 22 ++++++++++ GALAHAD.jl/test/test_hash.jl | 22 ++++++++++ GALAHAD.jl/test/test_ir.jl | 20 +++++++++ GALAHAD.jl/test/test_lms.jl | 20 +++++++++ GALAHAD.jl/test/test_roots.jl | 20 +++++++++ GALAHAD.jl/test/test_scu.jl | 20 +++++++++ GALAHAD.jl/test/test_sec.jl | 20 +++++++++ GALAHAD.jl/test/test_sha.jl | 20 +++++++++ GALAHAD.jl/test/test_sils.jl | 22 ++++++++++ GALAHAD.jl/test/test_structures.jl | 2 + 14 files changed, 303 insertions(+), 14 deletions(-) diff --git a/GALAHAD.jl/test/runtests.jl b/GALAHAD.jl/test/runtests.jl index 1dab326142..d20ed23da1 100644 --- a/GALAHAD.jl/test/runtests.jl +++ b/GALAHAD.jl/test/runtests.jl @@ -1,18 +1,59 @@ -using Test, GALAHAD +using GALAHAD @info("GALAHAD_INSTALLATION : $(GALAHAD.GALAHAD_INSTALLATION)") - -packages = ("arc", "bgo", "blls", "bqp", "bqpb", "bsc", "ccqp", "convert", - "cqp", "cro", "dgo", "dps", "dqp", "eqp", "fdc", "fit", "glrt", - "gls", "gltr", "hash", "ir", "l2rt", "lhs", "llsr", "llst", "lms", - "lpa", "lpb", "lsqp", "lsrt", "lstr", "nls", "presolve", "psls", - "qpa", "qpb", "roots", "rpd", "rqs", "sbls", "scu", "sec", "sha", - "sils", "slls", "sls", "trb", "trs", "tru", "ugo", "uls", "wcp") - include("test_structures.jl") -# for package in packages -# @testset "$package" begin -# include("test_$package.jl") -# end -# end +# include("test_arc.jl") +# include("test_bgo.jl") +# include("test_blls.jl") +# include("test_bllsb.jl") +# include("test_bqp.jl") +# include("test_bqpb.jl") +include("test_bsc.jl") +# include("test_ccqp.jl") +# include("test_clls.jl") +include("test_convert.jl") +# include("test_cqp.jl") +# include("test_cro.jl") +# include("test_dgo.jl") +# include("test_dps.jl") +# include("test_dqp.jl") +# include("test_eqp.jl") +# include("test_fdc.jl") +include("test_fit.jl") +# include("test_glrt.jl") +include("test_gls.jl") +# include("test_gltr.jl") +include("test_hash.jl") +include("test_ir.jl") +# include("test_l2rt.jl") +# include("test_lhs.jl") +# include("test_llsr.jl") +# include("test_llst.jl") +include("test_lms.jl") +# include("test_lpa.jl") +# include("test_lpb.jl") +# include("test_lsqp.jl") +# include("test_lsrt.jl") +# include("test_lstr.jl") +# include("test_nls.jl") +# include("test_presolve.jl") +# include("test_psls.jl") +# include("test_qpa.jl") +# include("test_qpb.jl") +include("test_roots.jl") +# include("test_rpd.jl") +# include("test_rqs.jl") +# include("test_sbls.jl") +## include("test_scu.jl") +include("test_sec.jl") +include("test_sha.jl") +include("test_sils.jl") +# include("test_slls.jl") +# include("test_sls.jl") +# include("test_trb.jl") +# include("test_trs.jl") +# include("test_tru.jl") +# include("test_ugo.jl") +# include("test_uls.jl") +# include("test_wcp.jl") diff --git a/GALAHAD.jl/test/test_bsc.jl b/GALAHAD.jl/test/test_bsc.jl index 61d46371a7..fd099c20fc 100644 --- a/GALAHAD.jl/test/test_bsc.jl +++ b/GALAHAD.jl/test/test_bsc.jl @@ -1,2 +1,22 @@ # test_bsc.jl # Simple code to test the Julia interface to BSC + +using GALAHAD +using Test + +function test_bsc() + data = Ref{Ptr{Cvoid}}() + control = Ref{bsc_control_type}() + inform = Ref{bsc_inform_type{Float64}}() + + status = Ref{Cint}() + bsc_initialize(data, control, status) + bsc_information(data, inform, status) + bsc_terminate(data, control, inform) + + return 0 +end + +@testset "BSC" begin + @test test_bsc() == 0 +end diff --git a/GALAHAD.jl/test/test_convert.jl b/GALAHAD.jl/test/test_convert.jl index df290e9b3e..d52b3c9c2d 100644 --- a/GALAHAD.jl/test/test_convert.jl +++ b/GALAHAD.jl/test/test_convert.jl @@ -1,2 +1,22 @@ # test_convert.jl # Simple code to test the Julia interface to CONVERT + +using GALAHAD +using Test + +function test_convert() + data = Ref{Ptr{Cvoid}}() + control = Ref{convert_control_type}() + inform = Ref{convert_inform_type{Float64}}() + + status = Ref{Cint}() + convert_initialize(data, control, status) + convert_information(data, inform, status) + convert_terminate(data, control, inform) + + return 0 +end + +@testset "CONVERT" begin + @test test_convert() == 0 +end diff --git a/GALAHAD.jl/test/test_fit.jl b/GALAHAD.jl/test/test_fit.jl index 90a9b91006..904f006cf1 100644 --- a/GALAHAD.jl/test/test_fit.jl +++ b/GALAHAD.jl/test/test_fit.jl @@ -1,2 +1,22 @@ # test_fit.jl # Simple code to test the Julia interface to FIT + +using GALAHAD +using Test + +function test_fit() + data = Ref{Ptr{Cvoid}}() + control = Ref{fit_control_type}() + inform = Ref{fit_inform_type}() + + status = Ref{Cint}() + fit_initialize(data, control, status) + fit_information(data, inform, status) + fit_terminate(data, control, inform) + + return 0 +end + +@testset "FIT" begin + @test test_fit() == 0 +end diff --git a/GALAHAD.jl/test/test_gls.jl b/GALAHAD.jl/test/test_gls.jl index 310167c405..e7d62d3ec6 100644 --- a/GALAHAD.jl/test/test_gls.jl +++ b/GALAHAD.jl/test/test_gls.jl @@ -1,2 +1,24 @@ # test_gls.jl # Simple code to test the Julia interface to GLS + +using GALAHAD +using Test + +function test_gls() + data = Ref{Ptr{Cvoid}}() + control = Ref{gls_control_type{Float64}}() + ainfo = Ref{gls_ainfo_type{Float64}}() + finfo = Ref{gls_finfo_type{Float64}}() + sinfo = Ref{gls_sinfo_type}() + + status = Ref{Cint}() + gls_initialize(data, control) + gls_information(data, ainfo, finfo, sinfo, status) + gls_finalize(data, control, status) + + return 0 +end + +@testset "GLS" begin + @test test_gls() == 0 +end diff --git a/GALAHAD.jl/test/test_hash.jl b/GALAHAD.jl/test/test_hash.jl index 46411d013e..1f64a3101d 100644 --- a/GALAHAD.jl/test/test_hash.jl +++ b/GALAHAD.jl/test/test_hash.jl @@ -1,2 +1,24 @@ # test_hash.jl # Simple code to test the Julia interface to HASH + +using GALAHAD +using Test + +function test_hash() + data = Ref{Ptr{Cvoid}}() + control = Ref{hash_control_type}() + inform = Ref{hash_inform_type}() + + status = Ref{Cint}() + nchar = Cint(10) + length = Cint(100) + hash_initialize(nchar, length, data, control, inform) + hash_information(data, inform, status) + hash_terminate(data, control, inform) + + return 0 +end + +@testset "HASH" begin + @test test_hash() == 0 +end diff --git a/GALAHAD.jl/test/test_ir.jl b/GALAHAD.jl/test/test_ir.jl index db8e98f9c7..4be6e6d4c5 100644 --- a/GALAHAD.jl/test/test_ir.jl +++ b/GALAHAD.jl/test/test_ir.jl @@ -1,2 +1,22 @@ # test_ir.jl # Simple code to test the Julia interface to IR + +using GALAHAD +using Test + +function test_ir() + data = Ref{Ptr{Cvoid}}() + control = Ref{ir_control_type{Float64}}() + inform = Ref{ir_inform_type{Float64}}() + + status = Ref{Cint}() + ir_initialize(data, control, status) + ir_information(data, inform, status) + ir_terminate(data, control, inform) + + return 0 +end + +@testset "IR" begin + @test test_ir() == 0 +end diff --git a/GALAHAD.jl/test/test_lms.jl b/GALAHAD.jl/test/test_lms.jl index ba51677d52..ac43f8dcd5 100644 --- a/GALAHAD.jl/test/test_lms.jl +++ b/GALAHAD.jl/test/test_lms.jl @@ -1,2 +1,22 @@ # test_lms.jl # Simple code to test the Julia interface to LMS + +using GALAHAD +using Test + +function test_lms() + data = Ref{Ptr{Cvoid}}() + control = Ref{lms_control_type}() + inform = Ref{lms_inform_type{Float64}}() + + status = Ref{Cint}() + lms_initialize(data, control, status) + lms_information(data, inform, status) + lms_terminate(data, control, inform) + + return 0 +end + +@testset "LMS" begin + @test test_lms() == 0 +end diff --git a/GALAHAD.jl/test/test_roots.jl b/GALAHAD.jl/test/test_roots.jl index bfba92c705..3766df919f 100644 --- a/GALAHAD.jl/test/test_roots.jl +++ b/GALAHAD.jl/test/test_roots.jl @@ -1,2 +1,22 @@ # test_roots.jl # Simple code to test the Julia interface to ROOTS + +using GALAHAD +using Test + +function test_roots() + data = Ref{Ptr{Cvoid}}() + control = Ref{roots_control_type{Float64}}() + inform = Ref{roots_inform_type}() + + status = Ref{Cint}() + roots_initialize(data, control, status) + roots_information(data, inform, status) + roots_terminate(data, control, inform) + + return 0 +end + +@testset "ROOTS" begin + @test test_roots() == 0 +end diff --git a/GALAHAD.jl/test/test_scu.jl b/GALAHAD.jl/test/test_scu.jl index e6fa27ce92..1da9214e60 100644 --- a/GALAHAD.jl/test/test_scu.jl +++ b/GALAHAD.jl/test/test_scu.jl @@ -1,2 +1,22 @@ # test_scu.jl # Simple code to test the Julia interface to SCU + +using GALAHAD +using Test + +function test_scu() + data = Ref{Ptr{Cvoid}}() + control = Ref{scu_control_type}() + inform = Ref{scu_inform_type}() + + status = Ref{Cint}() + scu_initialize(data, control, status) + scu_information(data, inform, status) + scu_terminate(data, control, inform) + + return 0 +end + +@testset "SCU" begin + @test test_scu() == 0 +end diff --git a/GALAHAD.jl/test/test_sec.jl b/GALAHAD.jl/test/test_sec.jl index bacc8f7818..f4d63e5a18 100644 --- a/GALAHAD.jl/test/test_sec.jl +++ b/GALAHAD.jl/test/test_sec.jl @@ -1,2 +1,22 @@ # test_sec.jl # Simple code to test the Julia interface to SEC + +using GALAHAD +using Test + +function test_sec() + data = Ref{Ptr{Cvoid}}() + control = Ref{sec_control_type{Float64}}() + inform = Ref{sec_inform_type}() + + status = Ref{Cint}() + sec_initialize(control, status) + sec_information(data, inform, status) + sec_terminate(data, control, inform) + + return 0 +end + +@testset "SEC" begin + @test test_sec() == 0 +end diff --git a/GALAHAD.jl/test/test_sha.jl b/GALAHAD.jl/test/test_sha.jl index 099de4cdda..b35feb20c2 100644 --- a/GALAHAD.jl/test/test_sha.jl +++ b/GALAHAD.jl/test/test_sha.jl @@ -1,2 +1,22 @@ # test_sha.jl # Simple code to test the Julia interface to SHA + +using GALAHAD +using Test + +function test_sha() + data = Ref{Ptr{Cvoid}}() + control = Ref{sha_control_type}() + inform = Ref{sha_inform_type}() + + status = Ref{Cint}() + sha_initialize(data, control, status) + sha_information(data, inform, status) + sha_terminate(data, control, inform) + + return 0 +end + +@testset "SHA" begin + @test test_sha() == 0 +end diff --git a/GALAHAD.jl/test/test_sils.jl b/GALAHAD.jl/test/test_sils.jl index 8f0cf5148a..e6737a1b55 100644 --- a/GALAHAD.jl/test/test_sils.jl +++ b/GALAHAD.jl/test/test_sils.jl @@ -1,2 +1,24 @@ # test_sils.jl # Simple code to test the Julia interface to SILS + +using GALAHAD +using Test + +function test_sils() + data = Ref{Ptr{Cvoid}}() + control = Ref{sils_control_type{Float64}}() + ainfo = Ref{sils_ainfo_type{Float64}}() + finfo = Ref{sils_finfo_type{Float64}}() + sinfo = Ref{sils_sinfo_type{Float64}}() + + status = Ref{Cint}() + sils_initialize(data, control, status) + sils_information(data, ainfo, finfo, sinfo, status) + sils_finalize(data, control, status) + + return 0 +end + +@testset "SILS" begin + @test test_sils() == 0 +end diff --git a/GALAHAD.jl/test/test_structures.jl b/GALAHAD.jl/test/test_structures.jl index 3063bef470..f5e176d9c0 100644 --- a/GALAHAD.jl/test/test_structures.jl +++ b/GALAHAD.jl/test/test_structures.jl @@ -1,3 +1,5 @@ +using GALAHAD + # Structures for arc Ref{arc_control_type{Float32}}() Ref{arc_control_type{Float64}}() From 403db8da926b9c532bbdafe5f64ac8f88b62f977 Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Sun, 21 Jan 2024 20:39:23 -0500 Subject: [PATCH 09/33] [CI] Update JULIA_GALAHAD_LIBRARY_PATH for Windows --- .github/workflows/meson.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/meson.yml b/.github/workflows/meson.yml index 17ecc4d0c0..e41f40e229 100644 --- a/.github/workflows/meson.yml +++ b/.github/workflows/meson.yml @@ -81,16 +81,18 @@ jobs: shell: bash run: | echo "GALAHAD=$GITHUB_WORKSPACE" >> $GITHUB_ENV - echo "JULIA_GALAHAD_LIBRARY_PATH=$GITHUB_WORKSPACE/galahad/lib" >> $GITHUB_ENV echo "DEPS=$GITHUB_WORKSPACE/.." >> $GITHUB_ENV if [[ "${{matrix.os}}" == "ubuntu-latest" ]]; then echo "LIBDIR=lib" >> $GITHUB_ENV + echo "JULIA_GALAHAD_LIBRARY_PATH=$GITHUB_WORKSPACE/galahad/lib" >> $GITHUB_ENV fi if [[ "${{matrix.os}}" == "macos-latest" ]]; then echo "LIBDIR=lib" >> $GITHUB_ENV + echo "JULIA_GALAHAD_LIBRARY_PATH=$GITHUB_WORKSPACE/galahad/lib" >> $GITHUB_ENV fi if [[ "${{matrix.os}}" == "windows-latest" ]]; then echo "LIBDIR=bin" >> $GITHUB_ENV + echo "JULIA_GALAHAD_LIBRARY_PATH=$GITHUB_WORKSPACE/galahad/bin" >> $GITHUB_ENV fi - name: Install dependencies From 0cd272ce20211f5efd86b88c91497988bc3880ee Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Mon, 22 Jan 2024 01:07:33 -0500 Subject: [PATCH 10/33] [GALAHAD.jl] Continue to test the Julia interfaces --- GALAHAD.jl/gen/wrapper.jl | 6 +- GALAHAD.jl/test/runtests.jl | 18 +- GALAHAD.jl/test/test_bqpb.jl | 347 +++++++++++++++++----------------- GALAHAD.jl/test/test_lsqp.jl | 208 ++++++++++---------- GALAHAD.jl/test/test_lsrt.jl | 106 ++++++----- GALAHAD.jl/test/test_lstr.jl | 120 ++++++------ GALAHAD.jl/test/test_psls.jl | 177 +++++++++-------- GALAHAD.jl/test/test_sbls.jl | 357 ++++++++++++++++++----------------- GALAHAD.jl/test/test_sls.jl | 243 ++++++++++++++---------- GALAHAD.jl/test/test_ugo.jl | 172 +++++++++-------- GALAHAD.jl/test/test_wcp.jl | 192 ++++++++++--------- 11 files changed, 1035 insertions(+), 911 deletions(-) diff --git a/GALAHAD.jl/gen/wrapper.jl b/GALAHAD.jl/gen/wrapper.jl index 2f391aea30..e67e0ce362 100644 --- a/GALAHAD.jl/gen/wrapper.jl +++ b/GALAHAD.jl/gen/wrapper.jl @@ -10,7 +10,7 @@ function wrapper(name::String, headers::Vector{String}, optimized::Bool; targets @info "Wrapping $name" cd(@__DIR__) - include_dir = joinpath(ENV["JULIA_GALAHAD_LIBRARY_PATH"], "..", "include") + include_dir = joinpath(ENV["GALAHAD"], "include") options = load_options(joinpath(@__DIR__, "galahad.toml")) options["general"]["library_name"] = "libgalahad_double" @@ -58,8 +58,8 @@ function wrapper(name::String, headers::Vector{String}, optimized::Bool; targets end function main(name::String="all"; optimized::Bool=true) - haskey(ENV, "JULIA_GALAHAD_LIBRARY_PATH") || error("The environment variable JULIA_GALAHAD_LIBRARY_PATH is not defined.") - galahad = joinpath(ENV["JULIA_GALAHAD_LIBRARY_PATH"], "..", "include") + haskey(ENV, "GALAHAD") || error("The environment variable GALAHAD is not defined.") + galahad = joinpath(ENV["GALAHAD"], "include") # Regenerate test_structures.jl (name == "all") && optimized && isfile("../test/test_structures.jl") && rm("../test/test_structures.jl") diff --git a/GALAHAD.jl/test/runtests.jl b/GALAHAD.jl/test/runtests.jl index d20ed23da1..157665b3f0 100644 --- a/GALAHAD.jl/test/runtests.jl +++ b/GALAHAD.jl/test/runtests.jl @@ -8,7 +8,7 @@ include("test_structures.jl") # include("test_blls.jl") # include("test_bllsb.jl") # include("test_bqp.jl") -# include("test_bqpb.jl") +include("test_bqpb.jl") include("test_bsc.jl") # include("test_ccqp.jl") # include("test_clls.jl") @@ -33,27 +33,27 @@ include("test_ir.jl") include("test_lms.jl") # include("test_lpa.jl") # include("test_lpb.jl") -# include("test_lsqp.jl") -# include("test_lsrt.jl") -# include("test_lstr.jl") +include("test_lsqp.jl") +include("test_lsrt.jl") +include("test_lstr.jl") # include("test_nls.jl") # include("test_presolve.jl") -# include("test_psls.jl") +include("test_psls.jl") # include("test_qpa.jl") # include("test_qpb.jl") include("test_roots.jl") # include("test_rpd.jl") # include("test_rqs.jl") -# include("test_sbls.jl") +include("test_sbls.jl") ## include("test_scu.jl") include("test_sec.jl") include("test_sha.jl") include("test_sils.jl") # include("test_slls.jl") -# include("test_sls.jl") +include("test_sls.jl") # include("test_trb.jl") # include("test_trs.jl") # include("test_tru.jl") -# include("test_ugo.jl") +include("test_ugo.jl") # include("test_uls.jl") -# include("test_wcp.jl") +include("test_wcp.jl") diff --git a/GALAHAD.jl/test/test_bqpb.jl b/GALAHAD.jl/test/test_bqpb.jl index 1f3c91dab9..83280ac803 100644 --- a/GALAHAD.jl/test/test_bqpb.jl +++ b/GALAHAD.jl/test/test_bqpb.jl @@ -2,191 +2,200 @@ # Simple code to test the Julia interface to BQPB using GALAHAD +using Test using Printf - -# Derived types -data = [Ptr{Ptr{Cvoid}}()] -control = bqpb_control_type{Float64}() -inform = bqpb_inform_type{Float64}() - -# Set problem data -n = 3 # dimension -H_ne = 3 # Hesssian elements -H_row = Cint[1, 2, 3] # row indices, NB lower triangle -H_col = Cint[1, 2, 3] # column indices, NB lower triangle -H_ptr = Cint[1, 2, 3, 4] # row pointers -H_val = Float64[1.0, 1.0, 1.0] # values -g = Float64[2.0, 0.0, 0.0] # linear term in the objective -f = 1.0 # constant term in the objective -x_l = Float64[-1.0, -Inf, -Inf] # variable lower bound -x_u = Float64[1.0, Inf, 2.0] # variable upper bound - -# Set output storage -x_stat = zeros(Cint, n) # variable status -st = ' ' -status = Ref{Cint}() - -@printf(" Fortran sparse matrix indexing\n\n") -@printf(" basic tests of qp storage formats\n\n") - -for d = 1:7 - # Initialize BQPB - bqpb_initialize( data, control, status ) - - # Set user-defined control options - control.f_indexing = true # Fortran sparse matrix indexing - - # Start from 0 - x = Float64[0.0,0.0,0.0] - z = Float64[0.0,0.0,0.0] - - # sparse co-ordinate storage - if d == 1 - global st = 'C' - - bqpb_import( control, data, status, n, - "coordinate", H_ne, H_row, H_col, Cint[] ) - - bqpb_solve_qp( data, status, n, H_ne, H_val, g, f, - x_l, x_u, x, z, x_stat ) - end - - # sparse by rows - if d == 2 - global st = 'R' - - bqpb_import( control, data, status, n, - "sparse_by_rows", H_ne, Cint[], H_col, H_ptr ) - - bqpb_solve_qp( data, status, n, H_ne, H_val, g, f, - x_l, x_u, x, z, x_stat ) - end - - # dense - if d == 3 - global st = 'D' - H_dense_ne = 6 # number of elements of H - H_dense = Float64[1.0, 0.0, 1.0, 0.0, 0.0, 1.0] - - bqpb_import( control, data, status, n, - "dense", H_ne, Cint[], Cint[], Cint[] ) - - bqpb_solve_qp( data, status, n, H_dense_ne, H_dense, g, f, - x_l, x_u, x, z, x_stat ) +using Accessors + +function test_bqpb() + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{bqpb_control_type{Float64}}() + inform = Ref{bqpb_inform_type{Float64}}() + + # Set problem data + n = 3 # dimension + H_ne = 3 # Hesssian elements + H_row = Cint[1, 2, 3] # row indices, NB lower triangle + H_col = Cint[1, 2, 3] # column indices, NB lower triangle + H_ptr = Cint[1, 2, 3, 4] # row pointers + H_val = Float64[1.0, 1.0, 1.0] # values + g = Float64[2.0, 0.0, 0.0] # linear term in the objective + f = 1.0 # constant term in the objective + x_l = Float64[-1.0, -Inf, -Inf] # variable lower bound + x_u = Float64[1.0, Inf, 2.0] # variable upper bound + + # Set output storage + x_stat = zeros(Cint, n) # variable status + st = ' ' + status = Ref{Cint}() + + @printf(" Fortran sparse matrix indexing\n\n") + + @printf(" basic tests of qp storage formats\n\n") + + for d in 1:7 + + # Initialize BQPB + bqpb_initialize(data, control, status) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + + # Start from 0 + x = Float64[0.0, 0.0, 0.0] + z = Float64[0.0, 0.0, 0.0] + + # sparse co-ordinate storage + if d == 1 + st = 'C' + bqpb_import(control, data, status, n, + "coordinate", H_ne, H_row, H_col, Cint[]) + + bqpb_solve_qp(data, status, n, H_ne, H_val, g, f, + x_l, x_u, x, z, x_stat) + end + + # sparse by rows + if d == 2 + st = 'R' + bqpb_import(control, data, status, n, + "sparse_by_rows", H_ne, Cint[], H_col, H_ptr) + + bqpb_solve_qp(data, status, n, H_ne, H_val, g, f, + x_l, x_u, x, z, x_stat) + end + + # dense + if d == 3 + st = 'D' + H_dense_ne = 6 # number of elements of H + H_dense = Float64[1.0, 0.0, 1.0, 0.0, 0.0, 1.0] + bqpb_import(control, data, status, n, + "dense", H_ne, Cint[], Cint[], Cint[]) + + bqpb_solve_qp(data, status, n, H_dense_ne, H_dense, g, f, + x_l, x_u, x, z, x_stat) + end + + # diagonal + if d == 4 + st = 'L' + bqpb_import(control, data, status, n, + "diagonal", H_ne, Cint[], Cint[], Cint[]) + + bqpb_solve_qp(data, status, n, H_ne, H_val, g, f, + x_l, x_u, x, z, x_stat) + end + + # scaled identity + if d == 5 + st = 'S' + bqpb_import(control, data, status, n, + "scaled_identity", H_ne, Cint[], Cint[], Cint[]) + + bqpb_solve_qp(data, status, n, H_ne, H_val, g, f, + x_l, x_u, x, z, x_stat) + end + + # identity + if d == 6 + st = 'I' + bqpb_import(control, data, status, n, + "identity", H_ne, Cint[], Cint[], Cint[]) + + bqpb_solve_qp(data, status, n, H_ne, H_val, g, f, + x_l, x_u, x, z, x_stat) + end + + # zero + if d == 7 + st = 'Z' + bqpb_import(control, data, status, n, + "zero", H_ne, Cint[], Cint[], Cint[]) + + bqpb_solve_qp(data, status, n, H_ne, H_val, g, f, + x_l, x_u, x, z, x_stat) + end + + bqpb_information(data, inform, status) + + if inform[].status == 0 + @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", + st, inform[].iter, inform[].obj, inform[].status) + else + @printf("%c: BQPB_solve exit status = %1i\n", st, inform[].status) + end + + # @printf("x: ") + # for i = 1:n + # @printf("%f ", x[i]) + # end + # @printf("\n") + # @printf("gradient: ") + # for i = 1:n + # @printf("%f ", g[i]) + # end + # @printf("\n") + + # Delete internal workspace + bqpb_terminate(data, control, inform) end - # diagonal - if d == 4 - global st = 'L' + # test shifted least-distance interface + for d in 1:1 - bqpb_import( control, data, status, n, - "diagonal", H_ne, Cint[], Cint[], Cint[] ) + # Initialize BQPB + bqpb_initialize(data, control, status) - bqpb_solve_qp( data, status, n, H_ne, H_val, g, f, - x_l, x_u, x, z, x_stat ) - end + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing - # scaled identity - if d == 5 - global st = 'S' + # Start from 0 + x = Float64[0.0, 0.0, 0.0] + z = Float64[0.0, 0.0, 0.0] - bqpb_import( control, data, status, n, - "scaled_identity", H_ne, Cint[], Cint[], Cint[] ) + # Set shifted least-distance data - bqpb_solve_qp( data, status, n, H_ne, H_val, g, f, - x_l, x_u, x, z, x_stat ) - end + w = Float64[1.0, 1.0, 1.0] + x_0 = Float64[0.0, 0.0, 0.0] - # identity - if d == 6 - global st = 'I' + # sparse co-ordinate storage + if d == 1 + st = 'W' + bqpb_import(control, data, status, n, + "shifted_least_distance", H_ne, Cint[], Cint[], Cint[]) - bqpb_import( control, data, status, n, - "identity", H_ne, Cint[], Cint[], Cint[] ) + bqpb_solve_sldqp(data, status, n, w, x_0, g, f, + x_l, x_u, x, z, x_stat) + end - bqpb_solve_qp( data, status, n, H_ne, H_val, g, f, - x_l, x_u, x, z, x_stat ) - end + bqpb_information(data, inform, status) - # zero - if d == 7 - global st = 'Z' + if inform[].status == 0 + @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", + st, inform[].iter, inform[].obj, inform[].status) + else + @printf("%c: BQPB_solve exit status = %1i\n", st, inform[].status) + end - bqpb_import( control, data, status, n, - "zero", H_ne, Cint[], Cint[], Cint[] ) + # @printf("x: ") + # for i = 1:n + # @printf("%f ", x[i]) + # end + # @printf("\n") + # @printf("gradient: ") + # for i = 1:n + # @printf("%f ", g[i]) + # end + # @printf("\n") - bqpb_solve_qp( data, status, n, H_ne, H_val, g, f, - x_l, x_u, x, z, x_stat ) + # Delete internal workspace + bqpb_terminate(data, control, inform) end - bqpb_information( data, inform, status ) - - if inform.status == 0 - @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", st, inform.iter, inform.obj, inform.status) - else - @printf("%c: BQPB_solve exit status = %1i\n", st, inform.status) - end - - # @printf("x: ") - # for i = 1:n - # @printf("%f ", x[i]) - # end - # @printf("\n") - # @printf("gradient: ") - # for i = 1:n - # @printf("%f ", g[i]) - # end - # @printf("\n") - - # Delete internal workspace - bqpb_terminate( data, control, inform ) + return 0 end -# test shifted least-distance interface -for d = 1:1 - # Initialize BQPB - bqpb_initialize( data, control, status ) - - # Set user-defined control options - control.f_indexing = true # Fortran sparse matrix indexing - - # Start from 0 - x = Float64[0.0,0.0,0.0] - z = Float64[0.0,0.0,0.0] - - # Set shifted least-distance data - w = Float64[1.0,1.0,1.0] - x_0 = Float64[0.0,0.0,0.0] - - # sparse co-ordinate storage - if d == 1 - global st = 'W' - - bqpb_import( control, data, status, n, - "shifted_least_distance", H_ne, Cint[], Cint[], Cint[] ) - - bqpb_solve_sldqp( data, status, n, w, x_0, g, f, - x_l, x_u, x, z, x_stat ) - end - - bqpb_information( data, inform, status ) - - if inform.status == 0 - @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", st, inform.iter, inform.obj, inform.status) - else - @printf("%c: BQPB_solve exit status = %1i\n", st, inform.status) - - # @printf("x: ") - # for i = 1:n - # @printf("%f ", x[i]) - # end - # @printf("\n") - # @printf("gradient: ") - # for i = 1:n - # @printf("%f ", g[i]) - # end - # @printf("\n") - - # Delete internal workspace - bqpb_terminate( data, control, inform ) +@testset "BQPB" begin + @test test_bqpb() == 0 end diff --git a/GALAHAD.jl/test/test_lsqp.jl b/GALAHAD.jl/test/test_lsqp.jl index 3bda5e4b02..2c8b6b3cd0 100644 --- a/GALAHAD.jl/test/test_lsqp.jl +++ b/GALAHAD.jl/test/test_lsqp.jl @@ -2,109 +2,115 @@ # Simple code to test the Julia interface to LSQP using GALAHAD +using Test using Printf - -# Derived types -data = [Ptr{Ptr{Cvoid}}()] -control = lsqp_control_type{Float64}() -inform = lsqp_inform_type{Float64}() - -# Set problem data -n = 3 # dimension -m = 2 # number of general constraints -g = Float64[0.0, 2.0, 0.0] # linear term in the objective -f = 1.0 # constant term in the objective -A_ne = 4 # Jacobian elements -A_row = Cint[1, 1, 2, 2] # row indices -A_col = Cint[1, 2, 2, 3] # column indices -A_ptr = Cint[1, 3, 5] # row pointers -A_val = Float64[2.0, 1.0, 1.0, 1.0] # values -c_l = Float64[1.0, 2.0] # constraint lower bound -c_u = Float64[2.0, 2.0] # constraint upper bound -x_l = Float64[-1.0, -Inf, -Inf] # variable lower bound -x_u = Float64[1.0, Inf, 2.0] # variable upper bound -w = Float64[1.0,1.0,1.0] -x_0 = Float64[0.0,0.0,0.0] - -# Set output storage -c = zeros(Float64, m) # constraint values -x_stat = zeros(Cint, n) # variable status -c_stat = zeros(Cint, m) # constraint status -st = ' ' -status = Ref{Cint}() - -@printf(" Fortran sparse matrix indexing\n\n") -@printf(" basic tests of qp storage formats\n\n") - -for d = 1:3 - # Initialize LSQP - lsqp_initialize( data, control, status ) - - # Set user-defined control options - control.f_indexing = true # Fortran sparse matrix indexing - - # Start from 0 - x = Float64[0.0,0.0,0.0] - y = Float64[0.0,0.0] - z = Float64[0.0,0.0,0.0] - - # sparse co-ordinate storage - if d == 1 - global st = 'C' - - lsqp_import( control, data, status, n, m, - "coordinate", A_ne, A_row, A_col, Cint[] ) - - lsqp_solve_qp( data, status, n, m, w, x_0, g, f, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) - end - - # sparse by rows - if d == 2 - global st = 'R' - - lsqp_import( control, data, status, n, m, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr ) - - lsqp_solve_qp( data, status, n, m, w, x_0, g, f, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) - end - - # dense - if d == 3 - global st = 'D' - A_dense_ne = 6 # number of elements of A - A_dense = Float64[2.0, 1.0, 0.0, 0.0, 1.0, 1.0] - - lsqp_import( control, data, status, n, m, - "dense", A_dense_ne, Cint[], Cint[], Cint[] ) - - lsqp_solve_qp( data, status, n, m, w, x_0, g, f, - A_dense_ne, A_dense, c_l, c_u, x_l, x_u, - x, c, y, z, x_stat, c_stat ) +using Accessors + +function test_lsqp() + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{lsqp_control_type{Float64}}() + inform = Ref{lsqp_inform_type{Float64}}() + + # Set problem data + n = 3 # dimension + m = 2 # number of general constraints + g = Float64[0.0, 2.0, 0.0] # linear term in the objective + f = 1.0 # constant term in the objective + A_ne = 4 # Jacobian elements + A_row = Cint[1, 1, 2, 2] # row indices + A_col = Cint[1, 2, 2, 3] # column indices + A_ptr = Cint[1, 3, 5] # row pointers + A_val = Float64[2.0, 1.0, 1.0, 1.0] # values + c_l = Float64[1.0, 2.0] # constraint lower bound + c_u = Float64[2.0, 2.0] # constraint upper bound + x_l = Float64[-1.0, -Inf, -Inf] # variable lower bound + x_u = Float64[1.0, Inf, 2.0] # variable upper bound + w = Float64[1.0, 1.0, 1.0] + x_0 = Float64[0.0, 0.0, 0.0] + + # Set output storage + c = zeros(Float64, m) # constraint values + x_stat = zeros(Cint, n) # variable status + c_stat = zeros(Cint, m) # constraint status + st = ' ' + status = Ref{Cint}() + + @printf(" Fortran sparse matrix indexing\n\n") + @printf(" basic tests of qp storage formats\n\n") + + for d in 1:3 + # Initialize LSQP + lsqp_initialize(data, control, status) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + + # Start from 0 + x = Float64[0.0, 0.0, 0.0] + y = Float64[0.0, 0.0] + z = Float64[0.0, 0.0, 0.0] + + # sparse co-ordinate storage + if d == 1 + st = 'C' + lsqp_import(control, data, status, n, m, + "coordinate", A_ne, A_row, A_col, Cint[]) + + lsqp_solve_qp(data, status, n, m, w, x_0, g, f, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + end + + # sparse by rows + if d == 2 + st = 'R' + lsqp_import(control, data, status, n, m, + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + + lsqp_solve_qp(data, status, n, m, w, x_0, g, f, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + end + + # dense + if d == 3 + st = 'D' + A_dense_ne = 6 # number of elements of A + A_dense = Float64[2.0, 1.0, 0.0, 0.0, 1.0, 1.0] + + lsqp_import(control, data, status, n, m, + "dense", A_dense_ne, Cint[], Cint[], Cint[]) + + lsqp_solve_qp(data, status, n, m, w, x_0, g, f, + A_dense_ne, A_dense, c_l, c_u, x_l, x_u, + x, c, y, z, x_stat, c_stat) + end + + lsqp_information(data, inform, status) + + if inform[].status == 0 + @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", + st, inform[].iter, inform[].obj, inform[].status) + else + @printf("%c: LSQP_solve exit status = %1i\n", st, inform[].status) + end + # @printf("x: ") + # for i = 1:n + # @printf("%f ", x[i]) + # @printf("\n") + # @printf("gradient: ") + # for i = 1:n + # @printf("%f ", g[i]) + # @printf("\n") + + # Delete internal workspace + lsqp_terminate(data, control, inform) end - lsqp_information( data, inform, status ) - - if inform.status == 0 - @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", st, inform.iter, inform.obj, inform.status) - else - @printf("%c: LSQP_solve exit status = %1i\n", st, inform.status) - end + return 0 +end - # @printf("x: ") - # for i = 1:n - # @printf("%f ", x[i]) - # end - # @printf("\n") - # @printf("gradient: ") - # for i = 1:n - # @printf("%f ", g[i]) - # end - # @printf("\n") - - # Delete internal workspace - lsqp_terminate( data, control, inform ) +@testset "LSQP" begin + @test test_lsqp() == 0 end diff --git a/GALAHAD.jl/test/test_lsrt.jl b/GALAHAD.jl/test/test_lsrt.jl index 849cc913b8..f8e130922f 100644 --- a/GALAHAD.jl/test/test_lsrt.jl +++ b/GALAHAD.jl/test/test_lsrt.jl @@ -2,62 +2,74 @@ # Simple code to test the Julia interface to LSRT using GALAHAD +using Test using Printf +using Accessors -# Derived types -data = [Ptr{Ptr{Cvoid}}()] -control = lsrt_control_type{Float64}() -inform = lsrt_inform_type{Float64}() +function test_lsrt() + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{lsrt_control_type{Float64}}() + inform = Ref{lsrt_inform_type{Float64}}() -# Set problem data -n = 50 # dimensions -m = 2 * n + # Set problem data + n = 50 # dimensions + m = 2 * n -status = Ref{Cint}() -power = 3.0 -weight = 1.0 -x = zeros(Float64, n) -u = zeros(Float64, m) -v = zeros(Float64, n) + status = Ref{Cint}() + power = 3.0 + weight = 1.0 + x = zeros(Float64, n) + u = zeros(Float64, m) + v = zeros(Float64, n) -# Initialize lsrt -lsrt_initialize( data, control, status ) + # Initialize lsrt + lsrt_initialize(data, control, status) -status[] = 1 -control.print_level = 0 -lsrt_import_control( control, data, status ) + status[] = 1 + @reset control[].print_level = Cint(0) + lsrt_import_control(control, data, status) -for i = 1:m - u[i] = 1.0 # b = 1 -end + for i in 1:m + u[i] = 1.0 # b = 1 + end -# iteration loop to find the minimizer with A^T = (I:diag(1:n)) -while true # reverse-communication loop - lsrt_solve_problem( data, status, m, n, power, weight, x, u, v ) - if status[] == 0 # successful termination - break - elseif status[] < 0 # error exit - error("LSRT -- status = $(status[])") - elseif status[] == 2 # form u <- u + A * v - for i = 1:n - u[i] = u[i] + v[i] - u[n+i] = u[n+i] + i * v[i] - end - elseif status[] == 3 # form v <- v + A^T * u - for i = 1:n - v[i] = v[i] + u[i] + i * u[n+i] + # iteration loop to find the minimizer with A^T = (I:diag(1:n)) + terminated = false + while !terminated # reverse-communication loop + lsrt_solve_problem(data, status, m, n, power, weight, x, u, v) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # form u <- u + A * v + for i in 1:n + u[i] = u[i] + v[i] + u[n + i] = u[n + i] + (i + 1) * v[i] + end + elseif status[] == 3 # form v <- v + A^T * u + for i in 1:n + v[i] = v[i] + u[i] + (i + 1) * u[n + i] + end + elseif status[] == 4 # restart + for i in 1:m + u[i] = 1.0 + end + else + @printf(" the value %1i of status should not occur\n", + status) end - elseif status[] == 4 # restart - for i = 1:m - u[i] = 1.0 - end - else - @printf(" the value %1i of status should not occur\n", status) end -end -lsrt_information( data, inform, status ) -@printf("lsrt_solve_problem exit status = %i, f = %.2f\n", inform.status, inform.obj ) + lsrt_information(data, inform, status) + @printf("lsrt_solve_problem exit status = %i, f = %.2f\n", inform[].status, inform[].obj) -# Delete internal workspace -lsrt_terminate( data, control, inform ) + # Delete internal workspace + lsrt_terminate(data, control, inform) + + return 0 +end + +@testset "LSRT" begin + @test test_lsrt() == 0 +end diff --git a/GALAHAD.jl/test/test_lstr.jl b/GALAHAD.jl/test/test_lstr.jl index afec2375c2..2b422a8de0 100644 --- a/GALAHAD.jl/test/test_lstr.jl +++ b/GALAHAD.jl/test/test_lstr.jl @@ -2,72 +2,84 @@ # Simple code to test the Julia interface to LSTR using GALAHAD +using Test using Printf +using Accessors -# Derived types -data = [Ptr{Ptr{Cvoid}}()] -control = lstr_control_type{Float64}() -inform = lstr_inform_type{Float64}() +function test_lstr() + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{lstr_control_type{Float64}}() + inform = Ref{lstr_inform_type{Float64}}() -# Set problem data -n = 50 # dimensions -m = 2 * n + # Set problem data + n = 50 # dimensions + m = 2 * n -status = Ref{Cint}() -radius = Ref{Float64}() -x = zeros(Float64, n) -u = zeros(Float64, m) -v = zeros(Float64, n) + status = Ref{Cint}() + radius = Ref{Float64}() + x = zeros(Float64, n) + u = zeros(Float64, m) + v = zeros(Float64, n) -# Initialize lstr -lstr_initialize( data, control, status ) + # Initialize lstr + lstr_initialize(data, control, status) -# resolve with a smaller radius ? -for new_radius = 0:1 - if new_radius == 0 # original radius - radius[] = 1.0 - status[] = 1 - else # smaller radius - radius[] = 0.1 - status[] = 5 - end + # resolve with a smaller radius ? + for new_radius in 0:1 + if new_radius == 0 # original radius + radius[] = 1.0 + status[] = 1 + else # smaller radius + radius[] = 0.1 + status[] = 5 + end - control.print_level = 0 - lstr_import_control( control, data, status ) + @reset control[].print_level = Cint(0) + lstr_import_control(control, data, status) - for i = 1:m - u[i] = 1.0 # b = 1 - end - - # iteration loop to find the minimizer with A^T = (I:diag(1:n)) - while true # reverse-communication loop - lstr_solve_problem( data, status, m, n, radius, x, u, v ) + for i in 1:m + u[i] = 1.0 # b = 1 + end - if status[] == 0 # successful termination - break - elseif status[] < 0 # error exit - error("LSTR -- status = $(status[])") - elseif status[] == 2 # form u <- u + A * v - for i = 1:n - u[i] = u[i] + v[i] - u[n+i] = u[n+i] + i * v[i] + # iteration loop to find the minimizer with A^T = (I:diag(1:n)) + terminated = false + while !terminated # reverse-communication loop + lstr_solve_problem(data, status, m, n, radius[], x, u, v) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # form u <- u + A * v + for i in 1:n + u[i] = u[i] + v[i] + u[n + i] = u[n + i] + (i + 1) * v[i] + end + elseif status[] == 3 # form v <- v + A^T * u + for i in 1:n + v[i] = v[i] + u[i] + (i + 1) * u[n + i] + end + elseif status[] == 4 # restart + for i in 1:m + u[i] = 1.0 + end + else + @printf(" the value %1i of status should not occur\n", + status) end - elseif status[] == 3 # form v <- v + A^T * u - for i = 1:n - v[i] = v[i] + u[i] + i * u[n+i] - end - elseif status[] == 4 # restart - for i = 1:m - u[i] = 1.0 - end - else - @printf(" the value %1i of status should not occur\n", status) end + + lstr_information(data, inform, status) + @printf("%1i lstr_solve_problem exit status = %i, f = %.2f\n", new_radius, + inform[].status, inform[].r_norm) end - lstr_information( data, inform, status ) - @printf("%1i lstr_solve_problem exit status = %i, f = %.2f\n", new_radius, inform.status, inform.r_norm ) + # Delete internal workspace + lstr_terminate(data, control, inform) + + return 0 end -# Delete internal workspace -lstr_terminate( data, control, inform ) +@testset "LSTR" begin + @test test_lstr() == 0 +end diff --git a/GALAHAD.jl/test/test_psls.jl b/GALAHAD.jl/test/test_psls.jl index c576ed98a2..1a807a5fc4 100644 --- a/GALAHAD.jl/test/test_psls.jl +++ b/GALAHAD.jl/test/test_psls.jl @@ -2,88 +2,105 @@ # Simple code to test the Julia interface to PSLS using GALAHAD +using Test using Printf - -# Derived types -data = [Ptr{Ptr{Cvoid}}()] -control = psls_control_type{Float64}() -inform = psls_inform_type{Float64}() - -# Set problem data -n = 5 # dimension of A -ne = 7 # number of elements of A -dense_ne = n * ( n + 1 ) / 2 # number of elements of dense A - -row = Cint[1, 2, 2, 3, 3, 4, 5] # A indices values, NB lower triangle -col = Cint[1, 1, 5, 2, 3, 3, 5] -ptr = Cint[1, 2, 4, 6, 7, 8} -val = Float64[2.0, 3.0, 6.0, 4.0, 1.0, 5.0, 1.0] -dense = Float64[2.0, 3.0, 0.0, 0.0, 4.0, 1.0, 0.0, 0.0, 5.0, 0.0, 0.0, 6.0, 0.0, 0.0, 1.0] -st = ' ' -status = Ref{Cint}() -status_apply = Ref{Cint}() - -@printf(" Fortran sparse matrix indexing\n\n") -@printf(" basic tests of storage formats\n\n") - -for d = 1:3 - # Initialize PSLS - psls_initialize( data, control, status ) - control.preconditioner = 2 # band preconditioner - control.semi_bandwidth = 1 # semibandwidth - solver = "sils" - control.definite_linear_solver = (115, 105, 108, 115, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 0) - - # Set user-defined control options - control.f_indexing = true # fortran sparse matrix indexing - - # sparse co-ordinate storage - if d == 1 - global st = 'C' - - psls_import( control, data, status, n, - "coordinate", ne, row, col, Cint[] ) - - psls_form_preconditioner( data, status, ne, val ) - end - - # sparse by rows - if d == 2 - global st = 'R' - - psls_import( control, data, status, n, - "sparse_by_rows", ne, Cint[], col, ptr ) - - psls_form_preconditioner( data, status, ne, val ) - end - - # dense - if d == 3 - global st = 'D' - - psls_import( control, data, status, n, - "dense", ne, Cint[], Cint[], Cint[] ) - - psls_form_preconditioner( data, status, dense_ne, dense ) +using Accessors + +function test_psls() + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{psls_control_type{Float64}}() + inform = Ref{psls_inform_type{Float64}}() + + # Set problem data + n = 5 # dimension of A + ne = 7 # number of elements of A + dense_ne = n * (n + 1) / 2 # number of elements of dense A + + row = Cint[1, 2, 2, 3, 3, 4, 5] # A indices values, NB lower triangle + col = Cint[1, 1, 5, 2, 3, 3, 5] + ptr = Cint[1, 2, 4, 6, 7, 8] + val = Float64[2.0, 3.0, 6.0, 4.0, 1.0, 5.0, 1.0] + dense = Float64[2.0, 3.0, 0.0, 0.0, 4.0, 1.0, 0.0, + 0.0, 5.0, 0.0, 0.0, 6.0, 0.0, 0.0, 1.0] + st = ' ' + status = Ref{Cint}() + status_apply = Ref{Cint}() + + @printf(" Fortran sparse matrix indexing\n\n") + @printf(" basic tests of storage formats\n\n") + + for d in 1:3 + # Initialize PSLS + psls_initialize(data, control, status) + @reset control[].preconditioner = Cint(2) # band preconditioner + @reset control[].semi_bandwidth = Cint(1) # semibandwidth + @reset control[].definite_linear_solver = convert(NTuple{31,Int8}, + (115, 105, 108, 115, 32, 32, 32, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, 32, 32, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, 32, 32, 32, + 0)) + + # Set user-defined control options + @reset control[].f_indexing = true # fortran sparse matrix indexing + + # sparse co-ordinate storage + if d == 1 + st = 'C' + + psls_import(control, data, status, n, + "coordinate", ne, row, col, Cint[]) + + psls_form_preconditioner(data, status, ne, val) + end + + # sparse by rows + if d == 2 + st = 'R' + + psls_import(control, data, status, n, + "sparse_by_rows", ne, Cint[], col, ptr) + + psls_form_preconditioner(data, status, ne, val) + end + + # dense + if d == 3 + st = 'D' + + psls_import(control, data, status, n, + "dense", ne, Cint[], Cint[], Cint[]) + + psls_form_preconditioner(data, status, dense_ne, dense) + end + + # Set right-hand side b in x + x = Float64[8.0, 45.0, 31.0, 15.0, 17.0] # values + + if status == 0 + psls_information(data, inform, status) + psls_apply_preconditioner(data, status_apply, n, x) + else + status_apply[] = -1 + end + + @printf("%c storage: status from form factorize = %i apply = %i\n", + st, status[], status_apply[]) + + # @printf("x: ") + # for i = 1:n + # @printf("%f ", x[i]) + # end + + # Delete internal workspace + psls_terminate(data, control, inform) end - # Set right-hand side b in x - x = Float64[8.0, 45.0, 31.0, 15.0, 17.0] # values - - if status == 0 - psls_information( data, inform, status ) - psls_apply_preconditioner( data, status_apply, n, x ) - else - status_apply[] = -1 - end - - @printf("%c storage: status from form factorize = %i apply = %i\n", st, status, status_apply ) - - # @printf("x: ") - # for i = 1:n - # @printf("%f ", x[i]) - # end + return 0 +end - # Delete internal workspace - psls_terminate( data, control, inform ) +@testset "PSLS" begin + @test test_psls() == 0 end diff --git a/GALAHAD.jl/test/test_sbls.jl b/GALAHAD.jl/test/test_sbls.jl index 8a61339c26..f51e5a277b 100644 --- a/GALAHAD.jl/test/test_sbls.jl +++ b/GALAHAD.jl/test/test_sbls.jl @@ -2,184 +2,189 @@ # Simple code to test the Julia interface to SBLS using GALAHAD +using Test using Printf - -# Derived types -data = [Ptr{Ptr{Cvoid}}()] -control = sbls_control_type{Float64}() -inform = sbls_inform_type{Float64}() - -# Set problem data -n = 3 # dimension of H -m = 2 # dimension of C -H_ne = 4 # number of elements of H -A_ne = 3 # number of elements of A -C_ne = 3 # number of elements of C -H_dense_ne = 6 # number of elements of H -A_dense_ne = 6 # number of elements of A -C_dense_ne = 3 # number of elements of C -H_row = Cint[1, 2, 3, 3] # row indices, NB lower triangle -H_col = Cint[1, 2, 3, 1] -H_ptr = Cint[1, 2, 3, 5] -A_row = Cint[1, 1, 2] -A_col = Cint[1, 2, 3] -A_ptr = Cint[1, 3, 4] -C_row = [1, 2, 2] # row indices, NB lower triangle -C_col = [1, 1, 2] -C_ptr = [1, 2, 4] -H_val = Float64[1.0, 2.0, 3.0, 1.0] -A_val = Float64[2.0, 1.0, 1.0] -C_val = Float64[4.0, 1.0, 2.0] -H_dense = Float64[1.0, 0.0, 2.0, 1.0, 0.0, 3.0] -A_dense = Float64[2.0, 1.0, 0.0, 0.0, 0.0, 1.0] -C_dense = Float64[4.0, 1.0, 2.0] -H_diag = Float64[1.0, 1.0, 2.0] -C_diag = Float64[4.0, 2.0] -H_scid = Float64[2.0] -C_scid = Float64[2.0] - -st = ' ' -status = Ref{Cint}() - -@printf(" Fortran sparse matrix indexing\n\n") -@printf(" basic tests of storage formats\n\n") - -for d = 1:7 - # Initialize SBLS - sbls_initialize( data, control, status ) - control.preconditioner = 2 - control.factorization = 2 - control.get_norm_residual = true - - # Set user-defined control options - control.f_indexing = true # fortran sparse matrix indexing - - # sparse co-ordinate storage - if d == 1 - global st = 'C' - - sbls_import( control, data, status, n, m, - "coordinate", H_ne, H_row, H_col, Cint[], - "coordinate", A_ne, A_row, A_col, Cint[], - "coordinate", C_ne, C_row, C_col, Cint[] ) - - sbls_factorize_matrix( data, status, n, - H_ne, H_val, - A_ne, A_val, - C_ne, C_val, Cint[] ) - end - - # sparse by rows - if d == 2 - global st = 'R' - - sbls_import( control, data, status, n, m, - "sparse_by_rows", H_ne, Cint[], H_col, H_ptr, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr, - "sparse_by_rows", C_ne, Cint[], C_col, C_ptr ) - - sbls_factorize_matrix( data, status, n, - H_ne, H_val, - A_ne, A_val, - C_ne, C_val, Cint[] ) - end - - # dense - if d == 3 - global st = 'D' - - sbls_import( control, data, status, n, m, - "dense", H_ne, Cint[], Cint[], Cint[], - "dense", A_ne, Cint[], Cint[], Cint[], - "dense", C_ne, Cint[], Cint[], Cint[] ) - - sbls_factorize_matrix( data, status, n, - H_dense_ne, H_dense, - A_dense_ne, A_dense, - C_dense_ne, C_dense, - Cint[] ) - end - - # diagonal - if d == 4 - global st = 'L' - - sbls_import( control, data, status, n, m, - "diagonal", H_ne, Cint[], Cint[], Cint[], - "dense", A_ne, Cint[], Cint[], Cint[], - "diagonal", C_ne, Cint[], Cint[], Cint[] ) - - sbls_factorize_matrix( data, status, n, - n, H_diag, - A_dense_ne, A_dense, - m, C_diag, - Cint[] ) +using Accessors + +function test_sbls() + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{sbls_control_type{Float64}}() + inform = Ref{sbls_inform_type{Float64}}() + + # Set problem data + n = 3 # dimension of H + m = 2 # dimension of C + H_ne = 4 # number of elements of H + A_ne = 3 # number of elements of A + C_ne = 3 # number of elements of C + H_dense_ne = 6 # number of elements of H + A_dense_ne = 6 # number of elements of A + C_dense_ne = 3 # number of elements of C + H_row = Cint[1, 2, 3, 3] # row indices, NB lower triangle + H_col = Cint[1, 2, 3, 1] + H_ptr = Cint[1, 2, 3, 5] + A_row = Cint[1, 1, 2] + A_col = Cint[1, 2, 3] + A_ptr = Cint[1, 3, 4] + C_row = Cint[1, 2, 2] # row indices, NB lower triangle + C_col = Cint[1, 1, 2] + C_ptr = Cint[1, 2, 4] + H_val = Float64[1.0, 2.0, 3.0, 1.0] + A_val = Float64[2.0, 1.0, 1.0] + C_val = Float64[4.0, 1.0, 2.0] + H_dense = Float64[1.0, 0.0, 2.0, 1.0, 0.0, 3.0] + A_dense = Float64[2.0, 1.0, 0.0, 0.0, 0.0, 1.0] + C_dense = Float64[4.0, 1.0, 2.0] + H_diag = Float64[1.0, 1.0, 2.0] + C_diag = Float64[4.0, 2.0] + H_scid = Float64[2.0] + C_scid = Float64[2.0] + + st = ' ' + status = Ref{Cint}() + + @printf(" Fortran sparse matrix indexing\n\n") + @printf(" basic tests of storage formats\n\n") + + for d in 1:7 + + # Initialize SBLS + sbls_initialize(data, control, status) + @reset control[].preconditioner = Cint(2) + @reset control[].factorization = Cint(2) + @reset control[].get_norm_residual = true + + # Set user-defined control options + @reset control[].f_indexing = true # fortran sparse matrix indexing + + # sparse co-ordinate storage + if d == 1 + st = 'C' + sbls_import(control, data, status, n, m, + "coordinate", H_ne, H_row, H_col, Cint[], + "coordinate", A_ne, A_row, A_col, Cint[], + "coordinate", C_ne, C_row, C_col, Cint[]) + + sbls_factorize_matrix(data, status, n, + H_ne, H_val, + A_ne, A_val, + C_ne, C_val, Cint[]) + end + + # sparse by rows + if d == 2 + st = 'R' + sbls_import(control, data, status, n, m, + "sparse_by_rows", H_ne, Cint[], H_col, H_ptr, + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr, + "sparse_by_rows", C_ne, Cint[], C_col, C_ptr) + + sbls_factorize_matrix(data, status, n, + H_ne, H_val, + A_ne, A_val, + C_ne, C_val, Cint[]) + end + + # dense + if d == 3 + st = 'D' + sbls_import(control, data, status, n, m, + "dense", H_ne, Cint[], Cint[], Cint[], + "dense", A_ne, Cint[], Cint[], Cint[], + "dense", C_ne, Cint[], Cint[], Cint[]) + + sbls_factorize_matrix(data, status, n, + H_dense_ne, H_dense, + A_dense_ne, A_dense, + C_dense_ne, C_dense, + Cint[]) + end + + # diagonal + if d == 4 + st = 'L' + sbls_import(control, data, status, n, m, + "diagonal", H_ne, Cint[], Cint[], Cint[], + "dense", A_ne, Cint[], Cint[], Cint[], + "diagonal", C_ne, Cint[], Cint[], Cint[]) + + sbls_factorize_matrix(data, status, n, + n, H_diag, + A_dense_ne, A_dense, + m, C_diag, + Cint[]) + end + + # scaled identity + if d == 5 + st = 'S' + sbls_import(control, data, status, n, m, + "scaled_identity", H_ne, Cint[], Cint[], Cint[], + "dense", A_ne, Cint[], Cint[], Cint[], + "scaled_identity", C_ne, Cint[], Cint[], Cint[]) + + sbls_factorize_matrix(data, status, n, + 1, H_scid, + A_dense_ne, A_dense, + 1, C_scid, + Cint[]) + end + + # identity + if d == 6 + st = 'I' + sbls_import(control, data, status, n, m, + "identity", H_ne, Cint[], Cint[], Cint[], + "dense", A_ne, Cint[], Cint[], Cint[], + "identity", C_ne, Cint[], Cint[], Cint[]) + + sbls_factorize_matrix(data, status, n, + 0, H_val, + A_dense_ne, A_dense, + 0, C_val, Cint[]) + end + + # zero + if d == 7 + st = 'Z' + sbls_import(control, data, status, n, m, + "identity", H_ne, Cint[], Cint[], Cint[], + "dense", A_ne, Cint[], Cint[], Cint[], + "zero", C_ne, Cint[], Cint[], Cint[]) + + sbls_factorize_matrix(data, status, n, + 0, H_val, + A_dense_ne, A_dense, + 0, Cint[], Cint[]) + end + + # Set right-hand side (a, b) + sol = Float64[3.0, 2.0, 4.0, 2.0, 0.0] # values + + sbls_solve_system(data, status, n, m, sol) + + sbls_information(data, inform, status) + + if inform[].status == 0 + @printf("%c: residual = %9.1e status = %1i\n", + st, inform[].norm_residual, inform[].status) + else + @printf("%c: SBLS_solve exit status = %1i\n", st, inform[].status) + end + + # @printf("sol: ") + # for i = 1:n+m + # @printf("%f ", x[i]) + # end + + # Delete internal workspace + sbls_terminate(data, control, inform) end - # scaled identity - if d == 5 - global st = 'S' - - sbls_import( control, data, status, n, m, - "scaled_identity", H_ne, Cint[], Cint[], Cint[], - "dense", A_ne, Cint[], Cint[], Cint[], - "scaled_identity", C_ne, Cint[], Cint[], Cint[] ) - - sbls_factorize_matrix( data, status, n, - 1, H_scid, - A_dense_ne, A_dense, - 1, C_scid, - Cint[] ) - end - - # identity - if d == 6 - global st = 'I' - - sbls_import( control, data, status, n, m, - "identity", H_ne, Cint[], Cint[], Cint[], - "dense", A_ne, Cint[], Cint[], Cint[], - "identity", C_ne, Cint[], Cint[], Cint[] ) - - sbls_factorize_matrix( data, status, n, - 0, H_val, - A_dense_ne, A_dense, - 0, C_val, Cint[] ) - end - - # zero - if d == 7 - global st = 'Z' - - sbls_import( control, data, status, n, m, - "identity", H_ne, Cint[], Cint[], Cint[], - "dense", A_ne, Cint[], Cint[], Cint[], - "zero", C_ne, Cint[], Cint[], Cint[] ) - - sbls_factorize_matrix( data, status, n, - 0, H_val, - A_dense_ne, A_dense, - 0, Cint[], Cint[] ) - end - - # Set right-hand side ( a, b ) - sol = Float64[3.0, 2.0, 4.0, 2.0, 0.0] # values - - sbls_solve_system( data, status, n, m, sol ) - - sbls_information( data, inform, status ) - - if inform.status == 0 - @printf("%c: residual = %9.1e status = %1i\n", st, inform.norm_residual, inform.status) - else - @printf("%c: SBLS_solve exit status = %1i\n", st, inform.status) - end - - # @printf("sol: ") - # for i = 1:n+m - # @printf("%f ", x[i]) - # end + return 0 +end - # Delete internal workspace - sbls_terminate( data, control, inform ) +@testset "SBLS" begin + @test test_sbls() == 0 end diff --git a/GALAHAD.jl/test/test_sls.jl b/GALAHAD.jl/test/test_sls.jl index a3355b9a0d..d388505ae1 100644 --- a/GALAHAD.jl/test/test_sls.jl +++ b/GALAHAD.jl/test/test_sls.jl @@ -1,123 +1,162 @@ # test_sls.jl -# Full test SLS for the Julia interface +# Simple code to test the Julia interface to SLS using GALAHAD +using Test using Printf +using Accessors + +function test_sls() + maxabsarray(a) = maximum(abs.(a)) + + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{sls_control_type{Float64}}() + inform = Ref{sls_inform_type{Float64}}() + + # Set problem data + n = 5 # dimension of A + ne = 7 # number of entries of A + dense_ne = 15 # number of elements of A as a dense matrix + row = Cint[1, 2, 2, 3, 3, 4, 5] # row indices, NB lower triangle + col = Cint[1, 1, 5, 2, 3, 3, 5] # column indices + ptr = Cint[1, 2, 4, 6, 7, 8] # pointers to indices + val = Float64[2.0, 3.0, 6.0, 4.0, 1.0, 5.0, 1.0] # values + dense = Float64[2.0, 3.0, 0.0, 0.0, 4.0, 1.0, 0.0, + 0.0, 5.0, 0.0, 0.0, 6.0, 0.0, 0.0, 1.0] + rhs = Float64[8.0, 45.0, 31.0, 15.0, 17.0] + sol = Float64[1.0, 2.0, 3.0, 4.0, 5.0] + status = Ref{Cint}() + x = zeros(Float64, n) + error = zeros(Float64, n) + + norm_residual = Ref{Float64}() + good_x = eps(Float64)^(1 / 3) + + @printf(" Fortran sparse matrix indexing\n\n") + @printf(" basic tests of storage formats\n\n") + @printf(" storage RHS refine partial\n") + + for d in 1:3 + # Initialize SLS - use the sytr solver + sls_initialize("sytr", data, control, status) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing -# Function maxabsarray -maxabsarray(a) = maximum(abs.(a)) - -# Derived types -data = [Ptr{Ptr{Cvoid}}()] -control = sls_control_type{T}() -inform = sls_inform_type{T}() - -# Set problem data -n = 5 # dimension of A -ne = 7 # number of entries of A -dense_ne = 15 # number of elements of A as a dense matrix -row = Cint[0, 1, 1, 2, 2, 3, 4] # row indices, NB lower triangle -col = Cint[0, 0, 4, 1, 2, 2, 4] # column indices -ptr = Cint[0, 1, 3, 5, 6, 7] # pointers to indices -val = Float64[2.0, 3.0, 6.0, 4.0, 1.0, 5.0, 1.0] # values -dense = Float64[2.0, 3.0, 0.0, 0.0, 4.0, 1.0, 0.0, 0.0, 5.0, 0.0, 0.0, 6.0, 0.0, 0.0, 1.0] -rhs = Float64[8.0, 45.0, 31.0, 15.0, 17.0] -sol = Float64[1.0, 2.0, 3.0, 4.0, 5.0] - -x = zeros(Float64, n) -error = zeros(Float64, n) -good_x = eps(Float64)^(1/3) -status = Ref{Cint}() - -@printf(" C sparse matrix indexing\n\n") -@printf(" basic tests of storage formats\n\n") -@printf(" storage RHS refine partial\n") - -for d = 1:3 - # Initialize SLS - use the sytr solver - sls_initialize( "sytr", data, control, status ) - - # Set user-defined control options - control.f_indexing = false # C sparse matrix indexing - - # import matrix data and factorize - if d == 1 # sparse co-ordinate storage - @printf(" coordinate ") - sls_analyse_matrix( control, data, status, n, - "coordinate", ne, row, col, Cint[] ) - sls_factorize_matrix( data, status, ne, val ) - end - if d == 2 + if d == 1 + @printf(" coordinate ") + sls_analyse_matrix(control, data, status, n, + "coordinate", ne, row, col, Cint[]) + sls_factorize_matrix(data, status, ne, val) + end + # sparse by rows - @printf(" sparse by rows ") - sls_analyse_matrix( control, data, status, n, - "sparse_by_rows", ne, Cint[], col, ptr ) - sls_factorize_matrix( data, status, ne, val ) - end - if d == 3 + if d == 2 + @printf(" sparse by rows ") + sls_analyse_matrix(control, data, status, n, + "sparse_by_rows", ne, Cint[], col, ptr) + sls_factorize_matrix(data, status, ne, val) + end + # dense - @printf(" dense ") - sls_analyse_matrix( control, data, status, n, - "dense", ne, Cint[], Cint[], Cint[] ) - sls_factorize_matrix( data, status, dense_ne, dense ) - end + if d == 3 + @printf(" dense ") + sls_analyse_matrix(control, data, status, n, + "dense", ne, Cint[], Cint[], Cint[]) + sls_factorize_matrix(data, status, dense_ne, dense) + end - # Set right-hand side and solve the system - x .= rhs - sls_solve_system( data, status, n, x ) - sls_information( data, inform, status ) + # Set right-hand side and solve the system + for i in 1:n + x[i] = rhs[i] + end + + sls_solve_system(data, status, n, x) + sls_information(data, inform, status) + + if inform[].status == 0 + for i in 1:n + error[i] = x[i] - sol[i] + end + + norm_residual = maxabsarray(error) - if inform.status == 0 - error .= x .- sol - norm_residual = maxabsarray( error ) - if norm_residual < good_x - @printf(" ok ") + if norm_residual < good_x + @printf(" ok ") + else + @printf(" fail ") + end else - @printf(" fail ") + @printf(" SLS_solve exit status = %1i\n", inform[].status) end - else - @printf(" SLS_solve exit status = %1i\n", inform.status) - end - # resolve, this time using iterative refinement - control.max_iterative_refinements = 1 - sls_reset_control( control, data, status ) - x .= rhs - sls_solve_system( data, status, n, x ) - sls_information( data, inform, status ) - - if inform.status == 0 - error .= x .- sol - norm_residual = maxabsarray( error ) - if norm_residual < good_x - @printf(" ok ") + # @printf("sol: ") + # for i = 1:n + # @printf("%f ", x[i]) + # end + + # resolve, this time using iterative refinement + @reset control[].max_iterative_refinements = Cint(1) + sls_reset_control(control, data, status) + + for i in 1:n + x[i] = rhs[i] + end + + sls_solve_system(data, status, n, x) + sls_information(data, inform, status) + + if inform[].status == 0 + for i in 1:n + error[i] = x[i] - sol[i] + end + + norm_residual = maxabsarray(error) + + if norm_residual < good_x + @printf("ok ") + else + @printf(" fail ") + end else - @printf(" fail ") + @printf(" SLS_solve exit status = %1i\n", inform[].status) end - else - @printf(" SLS_solve exit status = %1i\n", inform.status) - end - # obtain the solution by part solves - x[i] .= rhs - sls_partial_solve_system( "L", data, status, n, x ) - sls_partial_solve_system( "D", data, status, n, x ) - sls_partial_solve_system( "U", data, status, n, x ) - sls_information( data, inform, status ) - - if inform.status == 0 - error .= x .- sol - norm_residual = maxabsarray( error ) - if norm_residual < good_x - @printf(" ok ") + # obtain the solution by part solves + for i in 1:n + x[i] = rhs[i] + end + + sls_partial_solve_system("L", data, status, n, x) + sls_partial_solve_system("D", data, status, n, x) + sls_partial_solve_system("U", data, status, n, x) + sls_information(data, inform, status) + + if inform[].status == 0 + for i in 1:n + error[i] = x[i] - sol[i] + end + + norm_residual = maxabsarray(error) + + if norm_residual < good_x + @printf("ok ") + else + @printf(" fail ") + end else - @printf(" fail ") + @printf(" SLS_solve exit status = %1i\n", inform[].status) end - else - @printf(" SLS_solve exit status = %1i\n", inform.status) + + # Delete internal workspace + sls_terminate(data, control, inform) end + + return 0 end -# Delete internal workspace -sls_terminate( data, control, inform ) +@testset "SLS" begin + @test test_sls() == 0 +end diff --git a/GALAHAD.jl/test/test_ugo.jl b/GALAHAD.jl/test/test_ugo.jl index 7ced442a49..1511878f7d 100644 --- a/GALAHAD.jl/test/test_ugo.jl +++ b/GALAHAD.jl/test/test_ugo.jl @@ -2,93 +2,107 @@ # Simple code to test the Julia interface to UGO using GALAHAD +using Test using Printf +using Accessors + +function test_ugo() + # Test problem objective + function objf(x::Float64) + a = 10.0 + res = x * x * cos(a * x) + return res + end -# Test problem objective -function objf(x) - a = 10.0 - res = x * x * cos( a*x ) - return Ref{Float64}(res) -end - -# Test problem first derivative -function gradf(x) - a = 10.0 - res = - a * x * x * sin( a*x ) + 2.0 * x * cos( a*x ) - return Ref{Float64}(res) -end - -# Test problem second derivative -function hessf(x) - a = 10.0 - res = - a * a* x * x * cos( a*x ) - 4.0 * a * x * sin( a*x ) + 2.0 * cos( a*x ) - return Ref{Float64}(res) -end - -# Derived types -data = [Ptr{Ptr{Cvoid}}()] -control = ugo_control_type{Float64}() -inform = ugo_inform_type{Float64}() - -# Initialize UGO -status = Ref{Cint}() -eval_status = Ref{Cint}() -ugo_initialize( data, control, status ) - -# Set user-defined control options -control.print_level = 1 - -# control.prefix = "'ugo: '" -control.prefix = (34, 39, 117, 103, 111, 58, 32, 39, 34, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 0) - -# Read options from specfile -specfile = "UGO.SPC" -ugo_read_specfile(control, specfile) - -# Test problem bounds -x_l = Ref{Float64}(-1.0) -x_u = Ref{Float64}(2.0) - -# Test problem objective, gradient, Hessian values -global x = Ref{Float64}(0.0) -global f = Ref{Float64}(0.0) -global g = Ref{Float64}(0.0) -global h = Ref{Float64}(0.0) - -# import problem data -ugo_import( control, data, status, x_l, x_u ) - -# Set for initial entry -status = Ref{Cint}(1) - -# Solve the problem: min f(x), x_l ≤ x ≤ x_u -while true + # Test problem first derivative + function gradf(x::Float64) + a = 10.0 + res = -a * x * x * sin(a * x) + 2.0 * x * cos(a * x) + return res + end - # Call UGO_solve - ugo_solve_reverse(data, status, eval_status, x, f, g, h ) + # Test problem second derivative + function hessf(x::Float64) + a = 10.0 + res = -a * a * x * x * cos(a * x) - 4.0 * a * x * sin(a * x) + 2.0 * cos(a * x) + return res + end - # Evaluate f(x) and its derivatives as required - if (status[] ≥ 2) # need objective - global f = objf(x[]) - if (status[] ≥ 3) # need first derivative - global g = gradf(x[]) - if (status[] ≥ 4) # need second derivative - global h = hessf(x[]) + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{ugo_control_type{Float64}}() + inform = Ref{ugo_inform_type{Float64}}() + + # Initialize UGO + status = Ref{Cint}() + eval_status = Ref{Cint}() + ugo_initialize(data, control, status) + + # Set user-defined control options + @reset control[].print_level = Cint(1) + + # control.prefix = "'ugo: '" + @reset control[].prefix = convert(NTuple{31,Int8}, + (34, 39, 117, 103, 111, 58, 32, 39, 34, 32, 32, 32, 32, + 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, + 32, 32, 32, 0)) + + # Read options from specfile + specfile = "UGO.SPC" + ugo_read_specfile(control, specfile) + + # Test problem bounds + x_l = Ref{Float64}(-1.0) + x_u = Ref{Float64}(2.0) + + # Test problem objective, gradient, Hessian values + x = Ref{Float64}(0.0) + f = Ref{Float64}(objf(x[])) + g = Ref{Float64}(gradf(x[])) + h = Ref{Float64}(hessf(x[])) + + # import problem data + ugo_import(control, data, status, x_l, x_u) + + # Set for initial entry + status[] = 1 + + # Solve the problem: min f(x), x_l ≤ x ≤ x_u + terminated = false + while !terminated + # Call UGO_solve + ugo_solve_reverse(data, status, eval_status, x, f, g, h) + + # Evaluate f(x) and its derivatives as required + if (status[] ≥ 2) # need objective + f[] = objf(x[]) + if (status[] ≥ 3) # need first derivative + g[] = gradf(x[]) + if (status[] ≥ 4) # need second derivative + h[] = hessf(x[]) + end end + else # the solution has been found (or an error has occured) + terminated = true end - else # the solution has been found (or an error has occured) - break end -end -# Record solution information -ugo_information( data, inform, status ) + # Record solution information + ugo_information(data, inform, status) + + if inform[].status == 0 + @printf("%i evaluations. Optimal objective value = %5.2f status = %1i\n", + inform[].f_eval, f[], inform[].status) + else + @printf("UGO_solve exit status = %1i\n", inform[].status) + end -if inform.status == 0 - @printf("%i evaluations. Optimal objective value = %5.2f status = %1i\n", inform.f_eval, f[], inform.status) -else - @printf("BGO_solve exit status = %1i\n", inform.status) + # Delete internal workspace + ugo_terminate(data, control, inform) + + return 0 end -# Delete internal workspace -ugo_terminate( data, control, inform ) +@testset "UGO" begin + @test test_ugo() == 0 +end diff --git a/GALAHAD.jl/test/test_wcp.jl b/GALAHAD.jl/test/test_wcp.jl index d0add0ddd1..b110a51069 100644 --- a/GALAHAD.jl/test/test_wcp.jl +++ b/GALAHAD.jl/test/test_wcp.jl @@ -2,107 +2,117 @@ # Simple code to test the Julia interface to WCP using GALAHAD +using Test using Printf +using Accessors + +function test_wcp() + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{wcp_control_type{Float64}}() + inform = Ref{wcp_inform_type{Float64}}() + + # Set problem data + n = 3 # dimension + m = 2 # number of general constraints + g = Float64[0.0, 2.0, 0.0] # linear term in the objective + A_ne = 4 # Jacobian elements + A_row = Cint[1, 1, 2, 2] # row indices + A_col = Cint[1, 2, 2, 3] # column indices + A_ptr = Cint[1, 3, 5] # row pointers + A_val = Float64[2.0, 1.0, 1.0, 1.0] # values + c_l = Float64[1.0, 2.0] # constraint lower bound + c_u = Float64[2.0, 2.0] # constraint upper bound + x_l = Float64[-1.0, -Inf, -Inf] # variable lower bound + x_u = Float64[1.0, Inf, 2.0] # variable upper bound + + # Set output storage + c = zeros(Float64, m) # constraint values + x_stat = zeros(Cint, n) # variable status + c_stat = zeros(Cint, m) # constraint status + st = ' ' + status = Ref{Cint}() + + @printf(" Fortran sparse matrix indexing\n\n") + @printf(" basic tests of wcp storage formats\n\n") + + for d in 1:3 + + # Initialize WCP + wcp_initialize(data, control, status) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + + # Start from 0 + x = Float64[0.0, 0.0, 0.0] + y_l = Float64[0.0, 0.0] + y_u = Float64[0.0, 0.0] + z_l = Float64[0.0, 0.0, 0.0] + z_u = Float64[0.0, 0.0, 0.0] -# Derived types -data = [Ptr{Ptr{Cvoid}}()] -control = wcp_control_type{Float64}() -inform = wcp_inform_type{Float64}() - -# Set problem data -n = 3 # dimension -m = 2 # number of general constraints -g = Float64[0.0, 2.0, 0.0] # linear term in the objective -A_ne = 4 # Jacobian elements -A_row = Cint[1, 1, 2, 2] # row indices -A_col = Cint[1, 2, 2, 3] # column indices -A_ptr = Cint[1, 3, 5] # row pointers -A_val = Float64[2.0, 1.0, 1.0, 1.0] # values -c_l = Float64[1.0, 2.0] # constraint lower bound -c_u = Float64[2.0, 2.0] # constraint upper bound -x_l = Float64[-1.0, -Inf, -Inf] # variable lower bound -x_u = Float64[1.0, Inf, 2.0] # variable upper bound - -# Set output storage -c = zeros(Float64, m) # constraint values -x_stat = zeros(Cint, n) # variable status -c_stat = zeros(Cint, m) # constraint status -st = ' ' -status = Ref{Cint}() - -@printf(" Fortran sparse matrix indexing\n\n") -@printf(" basic tests of wcp storage formats\n\n") - -for d = 1:3 - # Initialize WCP - wcp_initialize( data, control, status ) - - # Set user-defined control options - control.f_indexing = true # Fortran sparse matrix indexing - - # Start from 0 - x = Float64[0.0,0.0,0.0] - y_l = Float64[0.0,0.0] - y_u = Float64[0.0,0.0] - z_l = Float64[0.0,0.0,0.0] - z_u = Float64[0.0,0.0,0.0] - - if d == 1 # sparse co-ordinate storage - global st = 'C' - wcp_import( control, data, status, n, m, - "coordinate", A_ne, A_row, A_col, Cint[] ) + if d == 1 + st = 'C' + wcp_import(control, data, status, n, m, "coordinate", A_ne, A_row, A_col, Cint[]) - wcp_find_wcp( data, status, n, m, g, A_ne, A_val, - c_l, c_u, x_l, x_u, x, c, y_l, y_u, z_l, z_u, - x_stat, c_stat ) - end + wcp_find_wcp(data, status, n, m, g, A_ne, A_val, + c_l, c_u, x_l, x_u, x, c, y_l, y_u, z_l, z_u, + x_stat, c_stat) + end - if d == 2 # sparse by rows - global st = 'R' - wcp_import( control, data, status, n, m, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr ) + if d == 2 + st = 'R' + wcp_import(control, data, status, n, m, + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) - wcp_find_wcp( data, status, n, m, g, A_ne, A_val, - c_l, c_u, x_l, x_u, x, c, y_l, y_u, z_l, z_u, - x_stat, c_stat ) - end + wcp_find_wcp(data, status, n, m, g, A_ne, A_val, + c_l, c_u, x_l, x_u, x, c, y_l, y_u, z_l, z_u, + x_stat, c_stat) + end - if d == 3 # dense - global st = 'D' - A_dense_ne = 6 # number of elements of A - A_dense = Float64[2.0, 1.0, 0.0, 0.0, 1.0, 1.0] - - wcp_import( control, data, status, n, m, - "dense", A_dense_ne, Cint[], Cint[], Cint[] ) - - wcp_find_wcp( data, status, n, m, g, A_dense_ne, A_dense, - c_l, c_u, x_l, x_u, x, c, y_l, y_u, z_l, z_u, - x_stat, c_stat ) + if d == 3 + st = 'D' + A_dense_ne = 6 # number of elements of A + A_dense = Float64[2.0, 1.0, 0.0, 0.0, 1.0, 1.0] + + wcp_import(control, data, status, n, m, + "dense", A_dense_ne, Cint[], Cint[], Cint[]) + + wcp_find_wcp(data, status, n, m, g, A_dense_ne, A_dense, + c_l, c_u, x_l, x_u, x, c, y_l, y_u, z_l, z_u, + x_stat, c_stat) + end + + wcp_information(data, inform, status) + + if inform[].status == 0 + @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", st, + inform[].iter, inform[].obj, inform[].status) + else + @printf("%c: WCP_solve exit status = %1i\n", st, inform[].status) + end + + # @printf("x: ") + # for i = 1:n + # @printf("%f ", x[i]) + # end + # @printf("\n") + # @printf("gradient: ") + # for i = 1:n + # @printf("%f ", g[i]) + # end + # @printf("\n") + + # Delete internal workspace + wcp_terminate(data, control, inform) end - wcp_information( data, inform, status ) - - if inform.status == 0 - @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", - st, inform.iter, inform.obj, inform.status) - else - @printf("%c: WCP_solve exit status = %1i\n", st, inform.status) - end + return 0 end -# @printf("x: ") -# for i = 1:n -# @printf("%f ", x[i]) -# end -# @printf("\n") -# @printf("gradient: ") -# for i = 1:n -# @printf("%f ", g[i]) -# end -# @printf("\n") - -# Delete internal workspace -wcp_terminate( data, control, inform ) +@testset "WCP" begin + @test test_wcp() == 0 +end From 55329e60deab16435b602516666e72c732b2587e Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Mon, 22 Jan 2024 22:46:47 -0500 Subject: [PATCH 11/33] [GALAHAD.jl] More Julia tests... --- GALAHAD.jl/gen/examples.jl | 17 +- GALAHAD.jl/test/runtests.jl | 22 +- GALAHAD.jl/test/test_bllsb.jl | 255 +++++++++++------- GALAHAD.jl/test/test_ccqp.jl | 429 +++++++++++++++--------------- GALAHAD.jl/test/test_dps.jl | 220 +++++++++------- GALAHAD.jl/test/test_eqp.jl | 476 +++++++++++++++++++--------------- GALAHAD.jl/test/test_glrt.jl | 143 +++++----- GALAHAD.jl/test/test_gltr.jl | 139 +++++----- GALAHAD.jl/test/test_l2rt.jl | 108 ++++---- GALAHAD.jl/test/test_lhs.jl | 71 ++--- GALAHAD.jl/test/test_llst.jl | 377 ++++++++++++++++----------- GALAHAD.jl/test/test_lpa.jl | 206 ++++++++------- GALAHAD.jl/test/test_lpb.jl | 207 ++++++++------- 13 files changed, 1474 insertions(+), 1196 deletions(-) diff --git a/GALAHAD.jl/gen/examples.jl b/GALAHAD.jl/gen/examples.jl index 4d7a2d40ad..8f48eacff1 100644 --- a/GALAHAD.jl/gen/examples.jl +++ b/GALAHAD.jl/gen/examples.jl @@ -37,25 +37,29 @@ function examples(package::String, example::String) text = replace(text, "} #" => "] #") text = replace(text, "} #" => "] #") 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") + "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") text = replace(text, "real_wp_ $var[] = {" => "$var = Float64[") end for var in ("f", "power", "weight", "shift", "radius", "half_radius", "x_l", "x_u") text = replace(text, "real_wp_ $var =" => "$var =") end - for var in ("n", "ne", "m", "A_ne", "A_dense_ne", "H_ne", "H_dense_ne") + for var in ("n", "ne", "m", "A_ne", "A_dense_ne", "H_ne", "H_dense_ne", "C_dense_ne", "C_ne", "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") + 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") text = replace(text, "int $var[] = {" => "$var = Cint[") end - for val in ("3", "5", "6", "n") + for val in ("1", "3", "5", "6", "7", "n", "n+m") 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") 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") + for val in ("c", "g", "u", "v", "x", "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)") end @@ -100,6 +104,9 @@ function examples(package::String, example::String) text = replace(text, "# for i = 1:n @" => "# for i = 1:n\n# @") text = replace(text, "( " => "(") text = replace(text, " )" => ")") + text = replace(text, "switch(d)\n" => "") + text = replace(text, "for(i=0 i "for i = 1:n\n") + text = replace(text, "}\n" => "end\n") text = text * "end\n\n@testset \"" * uppercase(package) * "\" begin\n @test test_$package() == 0\nend\n" write(dst, text) (example == "") && clean_example(package) diff --git a/GALAHAD.jl/test/runtests.jl b/GALAHAD.jl/test/runtests.jl index 157665b3f0..f0bf722da9 100644 --- a/GALAHAD.jl/test/runtests.jl +++ b/GALAHAD.jl/test/runtests.jl @@ -6,33 +6,33 @@ include("test_structures.jl") # include("test_arc.jl") # include("test_bgo.jl") # include("test_blls.jl") -# include("test_bllsb.jl") +include("test_bllsb.jl") # include("test_bqp.jl") include("test_bqpb.jl") include("test_bsc.jl") -# include("test_ccqp.jl") +include("test_ccqp.jl") # include("test_clls.jl") include("test_convert.jl") # include("test_cqp.jl") # include("test_cro.jl") # include("test_dgo.jl") -# include("test_dps.jl") +include("test_dps.jl") # include("test_dqp.jl") -# include("test_eqp.jl") +include("test_eqp.jl") # include("test_fdc.jl") include("test_fit.jl") -# include("test_glrt.jl") +include("test_glrt.jl") include("test_gls.jl") -# include("test_gltr.jl") +include("test_gltr.jl") include("test_hash.jl") include("test_ir.jl") -# include("test_l2rt.jl") -# include("test_lhs.jl") +include("test_l2rt.jl") +include("test_lhs.jl") # include("test_llsr.jl") -# include("test_llst.jl") +## include("test_llst.jl") include("test_lms.jl") -# include("test_lpa.jl") -# include("test_lpb.jl") +include("test_lpa.jl") +include("test_lpb.jl") include("test_lsqp.jl") include("test_lsrt.jl") include("test_lstr.jl") diff --git a/GALAHAD.jl/test/test_bllsb.jl b/GALAHAD.jl/test/test_bllsb.jl index 3de6dc72b2..79c4b89ae7 100644 --- a/GALAHAD.jl/test/test_bllsb.jl +++ b/GALAHAD.jl/test/test_bllsb.jl @@ -2,105 +2,166 @@ # Simple code to test the Julia interface to BLLSB using GALAHAD +using Test using Printf - -# Derived types -data = [Ptr{Ptr{Cvoid}}()] -control = bllsb_control_type{Float64}() -inform = bllsb_inform_type{Float64}() - -# Set problem data -n = 3 # dimension -o = 4 # number of observations -Ao_ne = 7 # design matrix elements -Ao_row = Cint[1, 1, 2, 2, 3, 3, 4] # row indices -Ao_col = Cint[1, 2, 2, 1, 3, 2] # column indices -Ao_ptr_ne = o + 1 # row pointer length -Ao_ptr = Cint[1, 3, 5, 7, 8] # row pointers -Ao_val = Float64[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] # values -b = Float64[2.0, 2.0, 3.0, 1.0] # observations -x_l = Float64[-1.0, -Inf, -Inf] # variable lower bound -x_u = Float64[1.0, Inf, 2.0] # variable upper bound -sigma = 1.0 # regularization weight -w = Float64[1.0, 1.0, 1.0, 2.0] # values - -# Set output storage -x_stat = zeros(Cint, n) # variable status -st = ' ' -status = Ref{Cint}() - -@printf(" Fortran sparse matrix indexing\n\n") -@printf(" basic tests of bllsb storage formats\n\n") - -for d = 1:3 - - # Initialize BLLSB - bllsb_initialize( data, control, status ) - - # Set user-defined control options - control.f_indexing = true # Fortran sparse matrix indexing - - # Start from 0 - x = Float64[0.0,0.0,0.0] - z = Float64[0.0,0.0,0.0] - - # sparse co-ordinate storage - if d == 1 - global st = 'C' - - bllsb_import( control, data, status, n, o, - "coordinate", Ao_ne, Ao_row, Ao_col, 0, Cint[] ) - - bllsb_solve_blls( data, status, n, o, m, Ao_ne, Ao_val, b, sigma, - x_l, x_u, x, z, x_stat, w ) - end - - # sparse by rows - if d == 2 - global st = 'R' - - bllsb_import( control, data, status, n, o, - "sparse_by_rows", Ao_ne, Cint[], Ao_col, Ao_ptr_ne, Ao_ptr ) - - - bllsb_solve_blls( data, status, n, o, Ao_ne, Ao_val, b, sigma, - x_l, x_u, x, z, x_stat, w ) - end - - # dense - if d == 3 - global st = 'D' - - Ao_dense_ne = 12 # number of elements of Ao - Ao_dense = Float64[1.0, 1.0, 0.0, 0.0, 1.0, 1.0, - 1.0, 0.0, 1.0, 0.0, 1.0, 0.0] - - bllsb_import( control, data, status, n, o, - "dense", Ao_ne, Cint[], Cint[], 0, Cint[] ) - - bllsb_solve_blls( data, status, n, o, Ao_dense_ne, Ao_dense, b, sigma, - x_l, x_u, x, z, x_stat, w ) +using Accessors + +function test_bllsb() + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{bllsb_control_type{Float64}}() + inform = Ref{bllsb_inform_type{Float64}}() + + # Set problem data + n = 3 # dimension + o = 4 # number of observations + sigma = 1.0 # regularization weight + b = Float64[2.0, 2.0, 3.0, 1.0] # observations + x_l = Float64[-1.0, -Inf, -Inf] # variable lower bound + x_u = Float64[1.0, Inf, 2.0] # variable upper bound + w = Float64[1.0, 1.0, 1.0, 2.0] # weights + + # Set output storage + r = zeros(Float64, o) # residual values + x_stat = zeros(Cint, n) # variable status + st = "" + status = Ref{Cint}() + + @printf(" Fortran sparse matrix indexing\n\n") + @printf(" basic tests of bllsb storage formats\n\n") + + for d in 1:5 + # Initialize BLLSB + bllsb_initialize(data, control, status) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + @reset control[].symmetric_linear_solver = convert(NTuple{31,Int8}, + (112, 111, 116, 114, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 0)) + + @reset control[].fdc_control.symmetric_linear_solver = convert(NTuple{31,Int8}, + (112, 111, 116, 114, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 0)) + @reset control[].fdc_control.use_sls = true + + # Start from 0 + x = Float64[0.0, 0.0, 0.0] + y = Float64[0.0, 0.0] + z = Float64[0.0, 0.0, 0.0] + + # sparse co-ordinate storage + if d == 1 + st = "CO" + Ao_ne = 7 # objective Jacobian elements + Ao_row = Cint[1, 1, 2, 2, 3, 3, 4] # row indices + Ao_col = Cint[1, 2, 2, 3, 1, 3, 2] # column indices + Ao_val = Float64[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] # vals + + bllsb_import(control, data, status, n, o, + "coordinate", Ao_ne, Ao_row, Ao_col, 0, Cint[]) + + bllsb_solve_blls(data, status, n, o, Ao_ne, Ao_val, b, + sigma, x_l, x_u, x, r, z, x_stat, w) + end + + # sparse by rows + if d == 2 + st = "SR" + + Ao_ne = 7 # objective Jacobian elements + Ao_col = Cint[1, 2, 2, 3, 1, 3, 2] # column indices + Ao_ptr_ne = o + 1 # number of row pointers + Ao_ptr = Cint[1, 3, 5, 7, 8] # row pointers + Ao_val = Float64[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] # vals + + bllsb_import(control, data, status, n, o, + "sparse_by_rows", Ao_ne, Cint[], Ao_col, + Ao_ptr_ne, Ao_ptr) + + bllsb_solve_blls(data, status, n, o, Ao_ne, Ao_val, b, + sigma, x_l, x_u, x, r, z, x_stat, w) + end + + if d == 3 + st = "SC" + Ao_ne = 7 # objective Jacobian elements + Ao_row = Cint[1, 3, 1, 2, 4, 2, 3] # row indices + Ao_ptr_ne = n + 1 # number of column pointers + Ao_ptr = Cint[1, 3, 6, 8] # column pointers + Ao_val = Float64[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] # vals + + bllsb_import(control, data, status, n, o, + "sparse_by_columns", Ao_ne, Ao_row, Cint[], + Ao_ptr_ne, Ao_ptr) + + bllsb_solve_blls(data, status, n, o, Ao_ne, Ao_val, b, + sigma, x_l, x_u, x, r, z, x_stat, w) + end + + if d == 4 # dense by rows + st = "DR" + Ao_ne = 12 # objective Jacobian elements + Ao_dense = Float64[1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0] + + bllsb_import(control, data, status, n, o, + "dense", Ao_ne, Cint[], Cint[], 0, Cint[]) + + bllsb_solve_blls(data, status, n, o, Ao_ne, Ao_dense, b, + sigma, x_l, x_u, x, r, z, x_stat, w) + end + + if d == 5 # dense by cols + st = "DC" + Ao_ne = 12 # objective Jacobian elements + Ao_dense = Float64[1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0] + + bllsb_import(control, data, status, n, o, + "dense_by_columns", Ao_ne, Cint[], Cint[], 0, Cint[]) + + bllsb_solve_blls(data, status, n, o, Ao_ne, Ao_dense, b, + sigma, x_l, x_u, x, r, z, x_stat, w) + end + + bllsb_information(data, inform, status) + + if inform[].status == 0 + @printf("%s:%6i iterations. Optimal objective value = %5.2f status = %1i\n", st, + inform[].iter, inform[].obj, inform[].status) + else + @printf("%s: BLLSB_solve exit status = %1i\n", st, inform[].status) + end + + # @printf("x: ") + # for i = 1:n + # @printf("%f ", x[i]) + # end + # @printf("\n") + # @printf("gradient: ") + # for i = 1:n + # @printf("%f ", g[i]) + # end + # @printf("\n") + + # Delete internal workspace + bllsb_terminate(data, control, inform) end - bllsb_information( data, inform, status ) - - if inform.status == 0 - @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", st, inform.iter, inform.obj, inform.status) - else - @printf("%c: BLLSB_solve exit status = %1i\n", st, inform.status) - end + return 0 +end - # @printf("x: ") - # for i = 1:n - # @printf("%f ", x[i]) - # end - # @printf("\n") - # @printf("gradient: ") - # for i = 1:n - # @printf("%f ", g[i]) - # end - # @printf("\n") - - # Delete internal workspace - bllsb_terminate( data, control, inform ) +@testset "BLLSB" begin + @test test_bllsb() == 0 end diff --git a/GALAHAD.jl/test/test_ccqp.jl b/GALAHAD.jl/test/test_ccqp.jl index ed4498436e..fcac1f6091 100644 --- a/GALAHAD.jl/test/test_ccqp.jl +++ b/GALAHAD.jl/test/test_ccqp.jl @@ -2,222 +2,229 @@ # Simple code to test the Julia interface to CCQP using GALAHAD +using Test using Printf - -# Derived types -data = [Ptr{Ptr{Cvoid}}()] -control = ccqp_control_type{Float64}() -inform = ccqp_inform_type{Float64}() - -# Set problem data -n = 3 # dimension -m = 2 # number of general constraints -H_ne = 3 # Hesssian elements -H_row = Cint[1, 2, 3] # row indices, NB lower triangle -H_col = Cint[1, 2, 3] # column indices, NB lower triangle -H_ptr = Cint[1, 2, 3, 4] # row pointers -H_val = Float64[1.0, 1.0, 1.0] # values -g = Float64[0.0, 2.0, 0.0] # linear term in the objective -f = 1.0 # constant term in the objective -A_ne = 4 # Jacobian elements -A_row = Cint[1, 1, 2, 2] # row indices -A_col = Cint[1, 2, 2, 3] # column indices -A_ptr = Cint[1, 3, 5] # row pointers -A_val = Float64[2.0, 1.0, 1.0, 1.0] # values -c_l = Float64[1.0, 2.0] # constraint lower bound -c_u = Float64[2.0, 2.0] # constraint upper bound -x_l = Float64[-1.0, -Inf, -Inf] # variable lower bound -x_u = Float64[1.0, Inf, 2.0] # variable upper bound - -# Set output storage -c = zeros(Float64, m) # constraint values -x_stat = zeros(Cint, n) # variable status -c_stat = zeros(Cint, m) # constraint status -st = ' ' -status = Ref{Cint}() - -@printf(" Fortran sparse matrix indexing\n\n") -@printf(" basic tests of qp storage formats\n\n") - -for d = 1:7 - # Initialize CCQP - ccqp_initialize( data, control, status ) - - # Set user-defined control options - control.f_indexing = true # Fortran sparse matrix indexing - - # Start from 0 - x = Float64[0.0,0.0,0.0] - y = Float64[0.0,0.0] - z = Float64[0.0,0.0,0.0] - - # sparse co-ordinate storage - if d == 1 - global st = 'C' - - ccqp_import( control, data, status, n, m, - "coordinate", H_ne, H_row, H_col, Cint[], - "coordinate", A_ne, A_row, A_col, Cint[] ) - - ccqp_solve_qp( data, status, n, m, H_ne, H_val, g, f, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) - end - - # sparse by rows - if d == 2 - global st = 'R' - - ccqp_import( control, data, status, n, m, - "sparse_by_rows", H_ne, Cint[], H_col, H_ptr, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr ) - - ccqp_solve_qp( data, status, n, m, H_ne, H_val, g, f, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) - end - - # dense - if d == 3 - global st = 'D' - H_dense_ne = 6 # number of elements of H - A_dense_ne = 6 # number of elements of A - H_dense = Float64[1.0, 0.0, 1.0, 0.0, 0.0, 1.0] - A_dense = Float64[2.0, 1.0, 0.0, 0.0, 1.0, 1.0] - - ccqp_import( control, data, status, n, m, - "dense", H_ne, Cint[], Cint[], Cint[], - "dense", A_ne, Cint[], Cint[], Cint[] ) - - ccqp_solve_qp( data, status, n, m, H_dense_ne, H_dense, g, f, - A_dense_ne, A_dense, c_l, c_u, x_l, x_u, - x, c, y, z, x_stat, c_stat ) - end - - # diagonal - if d == 4 - global st = 'L' - - ccqp_import( control, data, status, n, m, - "diagonal", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr ) - - ccqp_solve_qp( data, status, n, m, H_ne, H_val, g, f, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) - end - - # scaled identity - if d == 5 - global st = 'S' - - ccqp_import( control, data, status, n, m, - "scaled_identity", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr ) - - ccqp_solve_qp( data, status, n, m, H_ne, H_val, g, f, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) +using Accessors + +function test_ccqp() + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{ccqp_control_type{Float64}}() + inform = Ref{ccqp_inform_type{Float64}}() + + # Set problem data + n = 3 # dimension + m = 2 # number of general constraints + H_ne = 3 # Hesssian elements + H_row = Cint[1, 2, 3] # row indices, NB lower triangle + H_col = Cint[1, 2, 3] # column indices, NB lower triangle + H_ptr = Cint[1, 2, 3, 4] # row pointers + H_val = Float64[1.0, 1.0, 1.0] # values + g = Float64[0.0, 2.0, 0.0] # linear term in the objective + f = 1.0 # constant term in the objective + A_ne = 4 # Jacobian elements + A_row = Cint[1, 1, 2, 2] # row indices + A_col = Cint[1, 2, 2, 3] # column indices + A_ptr = Cint[1, 3, 5] # row pointers + A_val = Float64[2.0, 1.0, 1.0, 1.0] # values + c_l = Float64[1.0, 2.0] # constraint lower bound + c_u = Float64[2.0, 2.0] # constraint upper bound + x_l = Float64[-1.0, -Inf, -Inf] # variable lower bound + x_u = Float64[1.0, Inf, 2.0] # variable upper bound + + # Set output storage + c = zeros(Float64, m) # constraint values + x_stat = zeros(Cint, n) # variable status + c_stat = zeros(Cint, m) # constraint status + st = ' ' + status = Ref{Cint}() + + @printf(" Fortran sparse matrix indexing\n\n") + @printf(" basic tests of qp storage formats\n\n") + + for d in 1:7 + # Initialize CCQP + ccqp_initialize(data, control, status) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + + # Start from 0 + x = Float64[0.0, 0.0, 0.0] + y = Float64[0.0, 0.0] + z = Float64[0.0, 0.0, 0.0] + + # sparse co-ordinate storage + if d == 1 + st = 'C' + ccqp_import(control, data, status, n, m, + "coordinate", H_ne, H_row, H_col, Cint[], + "coordinate", A_ne, A_row, A_col, Cint[]) + + ccqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + end + + # sparse by rows + if d == 2 + st = 'R' + ccqp_import(control, data, status, n, m, + "sparse_by_rows", H_ne, Cint[], H_col, H_ptr, + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + + ccqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + end + + # dense + if d == 3 + st = 'D' + H_dense_ne = 6 # number of elements of H + A_dense_ne = 6 # number of elements of A + H_dense = Float64[1.0, 0.0, 1.0, 0.0, 0.0, 1.0] + A_dense = Float64[2.0, 1.0, 0.0, 0.0, 1.0, 1.0] + + ccqp_import(control, data, status, n, m, + "dense", H_ne, Cint[], Cint[], Cint[], + "dense", A_ne, Cint[], Cint[], Cint[]) + + ccqp_solve_qp(data, status, n, m, H_dense_ne, H_dense, g, f, + A_dense_ne, A_dense, c_l, c_u, x_l, x_u, + x, c, y, z, x_stat, c_stat) + end + + # diagonal + if d == 4 + st = 'L' + ccqp_import(control, data, status, n, m, + "diagonal", H_ne, Cint[], Cint[], Cint[], + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + + ccqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + end + + # scaled identity + if d == 5 + st = 'S' + ccqp_import(control, data, status, n, m, + "scaled_identity", H_ne, Cint[], Cint[], Cint[], + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + + ccqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + end + + # identity + if d == 6 + st = 'I' + ccqp_import(control, data, status, n, m, + "identity", H_ne, Cint[], Cint[], Cint[], + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + + ccqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + end + + # zero + if d == 7 + st = 'Z' + ccqp_import(control, data, status, n, m, + "zero", H_ne, Cint[], Cint[], Cint[], + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + + ccqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + end + + ccqp_information(data, inform, status) + + if inform[].status == 0 + @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", + st, inform[].iter, inform[].obj, inform[].status) + else + @printf("%c: CCQP_solve exit status = %1i\n", st, inform[].status) + end + + # @printf("x: ") + # for i = 1:n + # @printf("%f ", x[i]) + # end + # @printf("\n") + # @printf("gradient: ") + # for i = 1:n + # @printf("%f ", g[i]) + # end + # @printf("\n") + + # Delete internal workspace + ccqp_terminate(data, control, inform) end - # identity - if d == 6 - global st = 'I' - - ccqp_import( control, data, status, n, m, - "identity", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr ) - - ccqp_solve_qp( data, status, n, m, H_ne, H_val, g, f, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) - end - - # zero - if d == 7 - global st = 'Z' - - ccqp_import( control, data, status, n, m, - "zero", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr ) - - ccqp_solve_qp( data, status, n, m, H_ne, H_val, g, f, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) + # test shifted least-distance interface + for d in 1:1 + + # Initialize CCQP + ccqp_initialize(data, control, status) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + + # Start from 0 + x = Float64[0.0, 0.0, 0.0] + y = Float64[0.0, 0.0] + z = Float64[0.0, 0.0, 0.0] + + # Set shifted least-distance data + + w = Float64[1.0, 1.0, 1.0] + x_0 = Float64[0.0, 0.0, 0.0] + + # sparse co-ordinate storage + if d == 1 + st = 'W' + ccqp_import(control, data, status, n, m, + "shifted_least_distance", H_ne, Cint[], Cint[], Cint[], + "coordinate", A_ne, A_row, A_col, Cint[]) + + ccqp_solve_sldqp(data, status, n, m, w, x_0, g, f, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + end + + ccqp_information(data, inform, status) + + if inform[].status == 0 + @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", st, + inform[].iter, inform[].obj, inform[].status) + else + @printf("%c: CCQP_solve exit status = %1i\n", st, inform[].status) + end + + # @printf("x: ") + # for i = 1:n + # @printf("%f ", x[i]) + # end + # @printf("\n") + # @printf("gradient: ") + # for i = 1:n + # @printf("%f ", g[i]) + # end + # @printf("\n") + + # Delete internal workspace + ccqp_terminate(data, control, inform) end - ccqp_information( data, inform, status ) - - if inform.status == 0 - @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", st, inform.iter, inform.obj, inform.status) - else - @printf("%c: CCQP_solve exit status = %1i\n", st, inform.status) - end + return 0 end -# @printf("x: ") -# for i = 1:n -# @printf("%f ", x[i]) -# end -# @printf("\n") -# @printf("gradient: ") -# for i = 1:n -# @printf("%f ", g[i]) -# end -# @printf("\n") - -# Delete internal workspace -ccqp_terminate( data, control, inform ) - -# test shifted least-distance interface -for d = 1:1 - # Initialize CCQP - ccqp_initialize( data, control, status ) - - # Set user-defined control options - control.f_indexing = true # Fortran sparse matrix indexing - - # Start from 0 - x = Float64[0.0,0.0,0.0] - y = Float64[0.0,0.0] - z = Float64[0.0,0.0,0.0] - - # Set shifted least-distance data - w = Float64[1.0,1.0,1.0] - x_0 = Float64[0.0,0.0,0.0] - - # sparse co-ordinate storage - if d == 1 - global st = 'W' - - ccqp_import( control, data, status, n, m, - "shifted_least_distance", H_ne, Cint[], Cint[], Cint[], - "coordinate", A_ne, A_row, A_col, Cint[] ) - - ccqp_solve_sldqp( data, status, n, m, w, x_0, g, f, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) - end - - ccqp_information( data, inform, status ) - - if inform.status == 0 - @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", st, inform.iter, inform.obj, inform.status) - else - @printf("%c: CCQP_solve exit status = %1i\n", st, inform.status) - end +@testset "CCQP" begin + @test test_ccqp() == 0 end - -# @printf("x: ") -# for i = 1:n -# @printf("%f ", x[i]) -# end -# @printf("\n") -# @printf("gradient: ") -# for i = 1:n -# @printf("%f ", g[i]) -# end -# @printf("\n") - -# Delete internal workspace -ccqp_terminate( data, control, inform ) diff --git a/GALAHAD.jl/test/test_dps.jl b/GALAHAD.jl/test/test_dps.jl index 3f34389954..1b0119d443 100644 --- a/GALAHAD.jl/test/test_dps.jl +++ b/GALAHAD.jl/test/test_dps.jl @@ -2,108 +2,128 @@ # Simple code to test the Julia interface to DPS using GALAHAD +using Test using Printf - -# Derived types -data = [Ptr{Ptr{Cvoid}}()] -control = dps_control_type{Float64}() -inform = dps_inform_type{Float64}() - -# Set problem data -n = 3 # dimension of H -m = 1 # dimension of A -H_ne = 4 # number of elements of H -H_dense_ne = 6 # number of elements of H -H_row = Cint[1, 2, 3, 3] # row indices, NB lower triangle -H_col = Cint[1, 2, 3, 1] -H_ptr = Cint[1, 2, 3, 5] -H_val = Float64[1.0, 2.0, 3.0, 4.0] -H_dense = Float64[1.0, 0.0, 2.0, 4.0, 0.0, 3.0] -f = 0.96 -radius = 1.0 -half_radius = 0.5 -c = Float64[0.0, 2.0, 0.0] - -st = ' ' -status = Ref{Cint}() -x = zeros(Float64, n) - -@printf(" Fortran sparse matrix indexing\n\n") -@printf(" basic tests of storage formats\n\n") - -for storage_type = 1:3 - # Initialize DPS - dps_initialize( data, control, status ) - - # Set user-defined control options - control.f_indexing = true # fortran sparse matrix indexing - solver = "sytr" - control.symmetric_linear_solver = (115, 121, 116, 114, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 0) - - # sparse co-ordinate storage - if storage_type == 1 - global st = 'C' - - # import the control parameters and structural data - dps_import( control, data, status, n, "coordinate", H_ne, H_row, H_col, Cint[] ) - - # solve the problem - dps_solve_tr_problem( data, status, n, H_ne, H_val, c, f, radius, x ) - end - - # sparse by rows - if storage_type == 2 - global st = 'R' - - # import the control parameters and structural data - dps_import( control, data, status, n, "sparse_by_rows", H_ne, Cint[], H_col, H_ptr ) - - dps_solve_tr_problem( data, status, n, H_ne, H_val, c, f, radius, x ) +using Accessors + +function test_dps() + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{dps_control_type{Float64}}() + inform = Ref{dps_inform_type{Float64}}() + + # Set problem data + n = 3 # dimension of H + m = 1 # dimension of A + H_ne = 4 # number of elements of H + H_dense_ne = 6 # number of elements of H + H_row = Cint[1, 2, 3, 3] # row indices, NB lower triangle + H_col = Cint[1, 2, 3, 1] + H_ptr = Cint[1, 2, 3, 5] + H_val = Float64[1.0, 2.0, 3.0, 4.0] + H_dense = Float64[1.0, 0.0, 2.0, 4.0, 0.0, 3.0] + f = 0.96 + radius = 1.0 + half_radius = 0.5 + c = Float64[0.0, 2.0, 0.0] + + st = ' ' + status = Ref{Cint}() + x = zeros(Float64, n) + + @printf(" Fortran sparse matrix indexing\n\n") + @printf(" basic tests of storage formats\n\n") + + for storage_type in 1:3 + # Initialize DPS + dps_initialize(data, control, status) + + # Set user-defined control options + @reset control[].f_indexing = true # fortran sparse matrix indexing + @reset control[].symmetric_linear_solver = convert(NTuple{31,Int8}, + (115, 121, 116, 114, 32, 32, 32, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, 32, 32, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, 32, 32, 32, + 0)) + + # sparse co-ordinate storage + if storage_type == 1 + st = 'C' + # import the control parameters and structural data + dps_import(control, data, status, n, + "coordinate", H_ne, H_row, H_col, Cint[]) + + # solve the problem + dps_solve_tr_problem(data, status, n, H_ne, H_val, + c, f, radius, x) + end + + # sparse by rows + if storage_type == 2 + st = 'R' + # import the control parameters and structural data + dps_import(control, data, status, n, + "sparse_by_rows", H_ne, Cint[], H_col, H_ptr) + + dps_solve_tr_problem(data, status, n, H_ne, H_val, + c, f, radius, x) + end + + # dense + if storage_type == 3 + st = 'D' + # import the control parameters and structural data + dps_import(control, data, status, n, + "dense", H_ne, Cint[], Cint[], Cint[]) + + dps_solve_tr_problem(data, status, n, H_dense_ne, H_dense, + c, f, radius, x) + end + + dps_information(data, inform, status) + @printf("format %c: DPS_solve_problem exit status = %1i, f = %.2f\n", + st, inform[].status, inform[].obj) + + # sparse co-ordinate storage + if storage_type == 1 + st = 'C' + # solve the problem + dps_resolve_tr_problem(data, status, n, + c, f, half_radius, x) + end + + # sparse by rows + if storage_type == 2 + st = 'R' + dps_resolve_tr_problem(data, status, n, + c, f, half_radius, x) + end + + # dense + if storage_type == 3 + st = 'D' + dps_resolve_tr_problem(data, status, n, + c, f, half_radius, x) + end + + dps_information(data, inform, status) + @printf("format %c: DPS_resolve_problem exit status = %1i, f = %.2f\n", + st, inform[].status, inform[].obj) + + # @printf("x: ") + # for i = 1:n+m + # @printf("%f ", x[i]) + # end + + # Delete internal workspace + dps_terminate(data, control, inform) end - # dense - if storage_type == 3 - global st = 'D' - - # import the control parameters and structural data - dps_import( control, data, status, n, "dense", H_ne, Cint[], Cint[], Cint[] ) - - dps_solve_tr_problem( data, status, n, H_dense_ne, H_dense, c, f, radius, x ) - end - - dps_information( data, inform, status ) - @printf("format %c: DPS_solve_problem exit status = %1i, f = %.2f\n", st, inform.status, inform.obj ) - - # sparse co-ordinate storage - if storage_type == 1 - global st = 'C' - - # solve the problem - dps_resolve_tr_problem( data, status, n, c, f, half_radius, x ) - end - - # sparse by rows - if storage_type == 2 - st = 'R' - - dps_resolve_tr_problem( data, status, n, c, f, half_radius, x ) - end - - # dense - if storage_type == 3 - st = 'D' - - dps_resolve_tr_problem( data, status, n, c, f, half_radius, x ) - end - - dps_information( data, inform, status ) - @printf("format %c: DPS_resolve_problem exit status = %1i, f = %.2f\n", st, inform.status, inform.obj ) - - # @printf("x: ") - # for i = 1:n+m - # @printf("%f ", x[i]) - # end + return 0 +end - # Delete internal workspace - dps_terminate( data, control, inform ) +@testset "DPS" begin + @test test_dps() == 0 end diff --git a/GALAHAD.jl/test/test_eqp.jl b/GALAHAD.jl/test/test_eqp.jl index c646d8a163..70e54818f3 100644 --- a/GALAHAD.jl/test/test_eqp.jl +++ b/GALAHAD.jl/test/test_eqp.jl @@ -2,223 +2,275 @@ # Simple code to test the Julia interface to EQP using GALAHAD +using Test using Printf - -# Derived types -data = [Ptr{Ptr{Cvoid}}()] -control = eqp_control_type{Float64}() -inform = eqp_inform_type{Float64}() - -# Set problem data -n = 3 # dimension -m = 2 # number of general constraints -H_ne = 3 # Hesssian elements -H_row = Cint[1, 2, 3] # row indices, NB lower triangle -H_col = Cint[1, 2, 3] # column indices, NB lower triangle -H_ptr = Cint[1, 2, 3, 4] # row pointers -H_val = Float64[1.0, 1.0, 1.0] # values -g = Float64[0.0, 2.0, 0.0] # linear term in the objective -f = 1.0 # constant term in the objective -A_ne = 4 # Jacobian elements -A_row = Cint[1, 1, 2, 2] # row indices -A_col = Cint[1, 2, 2, 3] # column indices -A_ptr = Cint[1, 3, 5] # row pointers -A_val = Float64[2.0, 1.0, 1.0, 1.0] # values -c = Float64[3.0, 0.0] # rhs of the constraints - -# Set output storage -x_stat = zeros(Cint, n) # variable status -c_stat = zeros(Cint, m) # constraint status -st = ' ' -status = Ref{Cint}() - -@printf(" Fortran sparse matrix indexing\n\n") -@printf(" basic tests of qp storage formats\n\n") - -for d = 1:6 - - # Initialize EQP - eqp_initialize( data, control, status ) - - # Set user-defined control options - control.f_indexing = true # Fortran sparse matrix indexing - control.fdc_control.use_sls = true - solver = "sytr" - control.fdc_control.symmetric_linear_solver = (115, 121, 116, 114, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 0) - control.sbls_control.symmetric_linear_solver = (115, 121, 116, 114, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 0) - control.sbls_control.definite_linear_solver = (115, 121, 116, 114, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 0) - - # Start from 0 - x = Float64[0.0,0.0,0.0] - y = Float64[0.0,0.0] - z = Float64[0.0,0.0,0.0] - - # sparse co-ordinate storage - if d == 1 - global st = 'C' - - eqp_import( control, data, status, n, m, - "coordinate", H_ne, H_row, H_col, Cint[], - "coordinate", A_ne, A_row, A_col, Cint[] ) - - eqp_solve_qp( data, status, n, m, H_ne, H_val, g, f, - A_ne, A_val, c, x, y ) - end - - # sparse by rows - if d == 2 - global st = 'R' - - eqp_import( control, data, status, n, m, - "sparse_by_rows", H_ne, Cint[], H_col, H_ptr, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr ) - - eqp_solve_qp( data, status, n, m, H_ne, H_val, g, f, - A_ne, A_val, c, x, y ) - end - - # dense - if d == 3 - global st = 'D' - - H_dense_ne = 6 # number of elements of H - A_dense_ne = 6 # number of elements of A - H_dense = [1.0, 0.0, 1.0, 0.0, 0.0, 1.0] - A_dense = Float64[2.0, 1.0, 0.0, 0.0, 1.0, 1.0] - - eqp_import( control, data, status, n, m, - "dense", H_ne, Cint[], Cint[], Cint[], - "dense", A_ne, Cint[], Cint[], Cint[] ) - - eqp_solve_qp( data, status, n, m, H_dense_ne, H_dense, g, f, - A_dense_ne, A_dense, c, x, y ) - end - - # diagonal - if d == 4 - global st = 'L' - - eqp_import( control, data, status, n, m, - "diagonal", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr ) - - eqp_solve_qp( data, status, n, m, H_ne, H_val, g, f, - A_ne, A_val, c, x, y ) - end - - # scaled identity - if d == 5 - global st = 'S' - - eqp_import( control, data, status, n, m, - "scaled_identity", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr ) - - eqp_solve_qp( data, status, n, m, H_ne, H_val, g, f, - A_ne, A_val, c, x, y ) - end - - # identity - if d == 6 - global st = 'I' - - eqp_import( control, data, status, n, m, - "identity", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr ) - - eqp_solve_qp( data, status, n, m, H_ne, H_val, g, f, - A_ne, A_val, c, x, y ) - end - - # zero - if d == 7 - global st = 'Z' - - eqp_import( control, data, status, n, m, - "zero", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr ) - - eqp_solve_qp( data, status, n, m, H_ne, H_val, g, f, - A_ne, A_val, c, x, y ) +using Accessors + +function test_eqp() + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{eqp_control_type{Float64}}() + inform = Ref{eqp_inform_type{Float64}}() + + # Set problem data + n = 3 # dimension + m = 2 # number of general constraints + H_ne = 3 # Hesssian elements + H_row = Cint[1, 2, 3] # row indices, NB lower triangle + H_col = Cint[1, 2, 3] # column indices, NB lower triangle + H_ptr = Cint[1, 2, 3, 4] # row pointers + H_val = Float64[1.0, 1.0, 1.0] # values + g = Float64[0.0, 2.0, 0.0] # linear term in the objective + f = 1.0 # constant term in the objective + A_ne = 4 # Jacobian elements + A_row = Cint[1, 1, 2, 2] # row indices + A_col = Cint[1, 2, 2, 3] # column indices + A_ptr = Cint[1, 3, 5] # row pointers + A_val = Float64[2.0, 1.0, 1.0, 1.0] # values + c = Float64[3.0, 0.0] # rhs of the constraints + + # Set output storage + x_stat = zeros(Cint, n) # variable status + c_stat = zeros(Cint, m) # constraint status + st = ' ' + status = Ref{Cint}() + + @printf(" Fortran sparse matrix indexing\n\n") + @printf(" basic tests of qp storage formats\n\n") + + for d in 1:6 + # Initialize EQP + eqp_initialize(data, control, status) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + @reset control[].fdc_control.use_sls = true + solver = "sytr" + @reset control[].fdc_control.symmetric_linear_solver = convert(NTuple{31,Int8}, + (115, 121, 116, 114, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 0)) + @reset control[].sbls_control.symmetric_linear_solver = convert(NTuple{31,Int8}, + (115, 121, 116, 114, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 0)) + @reset control[].sbls_control.definite_linear_solver = convert(NTuple{31,Int8}, + (115, 121, 116, 114, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 0)) + + # Start from 0 + x = Float64[0.0, 0.0, 0.0] + y = Float64[0.0, 0.0] + z = Float64[0.0, 0.0, 0.0] + + # sparse co-ordinate storage + if d == 1 + st = 'C' + eqp_import(control, data, status, n, m, + "coordinate", H_ne, H_row, H_col, Cint[], + "coordinate", A_ne, A_row, A_col, Cint[]) + + eqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, + A_ne, A_val, c, x, y) + end + + # sparse by rows + if d == 2 + st = 'R' + eqp_import(control, data, status, n, m, + "sparse_by_rows", H_ne, Cint[], H_col, H_ptr, + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + + eqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, + A_ne, A_val, c, x, y) + end + + # dense + if d == 3 + st = 'D' + H_dense_ne = 6 # number of elements of H + A_dense_ne = 6 # number of elements of A + H_dense = Float64[1.0, 0.0, 1.0, 0.0, 0.0, 1.0] + A_dense = Float64[2.0, 1.0, 0.0, 0.0, 1.0, 1.0] + + eqp_import(control, data, status, n, m, + "dense", H_ne, Cint[], Cint[], Cint[], + "dense", A_ne, Cint[], Cint[], Cint[]) + + eqp_solve_qp(data, status, n, m, H_dense_ne, H_dense, g, f, + A_dense_ne, A_dense, c, x, y) + end + + # diagonal + if d == 4 + st = 'L' + eqp_import(control, data, status, n, m, + "diagonal", H_ne, Cint[], Cint[], Cint[], + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + + eqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, + A_ne, A_val, c, x, y) + end + + # scaled identity + if d == 5 + st = 'S' + eqp_import(control, data, status, n, m, + "scaled_identity", H_ne, Cint[], Cint[], Cint[], + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + + eqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, + A_ne, A_val, c, x, y) + end + + # identity + if d == 6 + st = 'I' + eqp_import(control, data, status, n, m, + "identity", H_ne, Cint[], Cint[], Cint[], + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + + eqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, + A_ne, A_val, c, x, y) + end + + # zero + if d == 7 + st = 'Z' + eqp_import(control, data, status, n, m, + "zero", H_ne, Cint[], Cint[], Cint[], + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + + eqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, + A_ne, A_val, c, x, y) + end + + eqp_information(data, inform, status) + + if inform[].status == 0 + @printf("%c:%6i cg iterations. Optimal objective value = %5.2f status = %1i\n", + st, inform[].cg_iter, inform[].obj, inform[].status) + else + @printf("%c: EQP_solve exit status = %1i\n", st, inform[].status) + end + + # @printf("x: ") + # for i = 1:n + # @printf("%f ", x[i]) + # end + # @printf("\n") + # @printf("gradient: ") + # for i = 1:n + # @printf("%f ", g[i]) + # end + # @printf("\n") + + # Delete internal workspace + eqp_terminate(data, control, inform) end - eqp_information( data, inform, status ) - - if inform.status == 0 - @printf("%c:%6i cg iterations. Optimal objective value = %5.2f status = %1i\n", st, inform.cg_iter, inform.obj, inform.status) - else - @printf("%c: EQP_solve exit status = %1i\n", st, inform.status) + # test shifted least-distance interface + for d in 1:1 + + # Initialize EQP + eqp_initialize(data, control, status) + @reset control[].fdc_control.use_sls = true + solver = "sytr" + @reset control[].fdc_control.symmetric_linear_solver = convert(NTuple{31,Int8}, + (115, 121, 116, 114, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 0)) + @reset control[].sbls_control.symmetric_linear_solver = convert(NTuple{31,Int8}, + (115, 121, 116, 114, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 0)) + @reset control[].sbls_control.definite_linear_solver = convert(NTuple{31,Int8}, + (115, 121, 116, 114, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 0)) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + + # Start from 0 + x = Float64[0.0, 0.0, 0.0] + y = Float64[0.0, 0.0] + z = Float64[0.0, 0.0, 0.0] + + # Set shifted least-distance data + + w = Float64[1.0, 1.0, 1.0] + x_0 = Float64[0.0, 0.0, 0.0] + + # sparse co-ordinate storage + if d == 1 + st = 'W' + eqp_import(control, data, status, n, m, + "shifted_least_distance", H_ne, Cint[], Cint[], Cint[], + "coordinate", A_ne, A_row, A_col, Cint[]) + + eqp_solve_sldqp(data, status, n, m, w, x_0, g, f, + A_ne, A_val, c, x, y) + end + + eqp_information(data, inform, status) + + if inform[].status == 0 + @printf("%c:%6i cg iterations. Optimal objective value = %5.2f status = %1i\n", + st, inform[].cg_iter, inform[].obj, inform[].status) + else + @printf("%c: EQP_solve exit status = %1i\n", st, inform[].status) + end + + # @printf("x: ") + # for i = 1:n + # @printf("%f ", x[i]) + # end + # @printf("\n") + # @printf("gradient: ") + # for i = 1:n + # @printf("%f ", g[i]) + # end + # @printf("\n") + + # Delete internal workspace + eqp_terminate(data, control, inform) end - # @printf("x: ") - # for i = 1:n - # @printf("%f ", x[i]) - # end - # @printf("\n") - # @printf("gradient: ") - # for i = 1:n - # @printf("%f ", g[i]) - # end - # @printf("\n") - - # Delete internal workspace - eqp_terminate( data, control, inform ) + return 0 end -# test shifted least-distance interface -for d = 1:1 - - # Initialize EQP - eqp_initialize( data, control, status ) - control.fdc_control.use_sls = true - strcpy(control.fdc_control.symmetric_linear_solver, "sytr ") - strcpy(control.sbls_control.symmetric_linear_solver, "sytr ") - strcpy(control.sbls_control.definite_linear_solver, "sytr ") - - # Set user-defined control options - control.f_indexing = true # Fortran sparse matrix indexing - - # Start from 0 - x = Float64[0.0,0.0,0.0] - y = Float64[0.0,0.0] - z = Float64[0.0,0.0,0.0] - - # Set shifted least-distance data - - w = [1.0,1.0,1.0] - x_0 = [0.0,0.0,0.0] - - # sparse co-ordinate storage - if d == 1 - global st = 'W' - - eqp_import( control, data, status, n, m, - "shifted_least_distance", H_ne, Cint[], Cint[], Cint[], - "coordinate", A_ne, A_row, A_col, Cint[] ) - - eqp_solve_sldqp( data, status, n, m, w, x_0, g, f, - A_ne, A_val, c, x, y ) - end - - eqp_information( data, inform, status ) - - if inform.status == 0 - @printf("%c:%6i cg iterations. Optimal objective value = %5.2f status = %1i\n", st, inform.cg_iter, inform.obj, inform.status) - else - @printf("%c: EQP_solve exit status = %1i\n", st, inform.status) - end - - # @printf("x: ") - # for i = 1:n - # @printf("%f ", x[i]) - # end - # @printf("\n") - # @printf("gradient: ") - # for i = 1:n - # @printf("%f ", g[i]) - # end - # @printf("\n") - - # Delete internal workspace - eqp_terminate( data, control, inform ) +@testset "EQP" begin + @test test_eqp() == 0 end diff --git a/GALAHAD.jl/test/test_glrt.jl b/GALAHAD.jl/test/test_glrt.jl index 8774bbf08a..e8161e2734 100644 --- a/GALAHAD.jl/test/test_glrt.jl +++ b/GALAHAD.jl/test/test_glrt.jl @@ -2,84 +2,97 @@ # Simple code to test the Julia interface to GLRT using GALAHAD +using Test using Printf +using Accessors -# Derived types -data = [Ptr{Ptr{Cvoid}}()] -control = glrt_control_type{Float64}() -inform = glrt_inform_type{Float64}() +function test_glrt() + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{glrt_control_type{Float64}}() + inform = Ref{glrt_inform_type{Float64}}() -# Set problem data -n = 100 # dimension + # Set problem data + n = 100 # dimension -status = Ref{Cint}() -weight = 0 -power = 3.0 -x = zeros(Float64, n) -r = zeros(Float64, n) -vector = zeros(Float64, n) -h_vector = zeros(Float64, n) + status = Ref{Cint}() + weight = Ref{Float64}() + power = 3.0 + x = zeros(Float64, n) + r = zeros(Float64, n) + vector = zeros(Float64, n) + h_vector = zeros(Float64, n) -# Initialize glrt -glrt_initialize( data, control, status ) + # Initialize glrt + glrt_initialize(data, control, status) -# use a unit M ? -for unit_m = 0:1 - if unit_m == 0 - control.unitm = false - else - control.unitm = true - end - - glrt_import_control( control, data, status ) - - # resolve with a larger weight ? - for new_weight = 0:1 - if new_weight == 0 - global weight = 1.0 - status[] = 1 + # use a unit M ? + for unit_m in 0:1 + if unit_m == 0 + @reset control[].unitm = false else - global weight = 10.0 - status[] = 6 + @reset control[].unitm = true end - for i = 1:n - r[i] = 1.0 - end + glrt_import_control(control, data, status) - # iteration loop to find the minimizer - while true # reverse-communication loop - glrt_solve_problem( data, status, n, power, weight, x, r, vector ) - if status[] == 0 # successful termination - break - elseif status[] < 0 # error exit - error("GLRT -- status = $(status[])") - elseif status[] == 2 # form the preconditioned vector - for i = 1:n - vector[i] = vector[i] / 2.0 - end - elseif status[] == 3 # form the Hessian-vector product - h_vector[1] = 2.0 * vector[1] + vector[2] - for i =2:n-1 - h_vector[i] = vector[i-1] + 2.0 * vector[i] + vector[i+1] - end - h_vector[n] = vector[n-1] + 2.0 * vector[n] - for i = 1:n - vector[i] = h_vector[i] - end - elseif status[] == 4 # restart - for i = 1:n - r[i] = 1.0 - end + # resolve with a larger weight ? + for new_weight in 0:1 + if new_weight == 0 + weight[] = 1.0 + status[] = 1 else - @printf(" the value %1i of status should not occur\n", status) + weight[] = 10.0 + status[] = 6 end - end - glrt_information( data, inform, status ) - @printf("MR = %1i%1i glrt_solve_problem exit status = %i, f = %.2f\n", unit_m, new_weight, inform.status, inform.obj_regularized ) + for i in 1:n + r[i] = 1.0 + end + + # iteration loop to find the minimizer + terminated = false + while !terminated # reverse-communication loop + glrt_solve_problem(data, status, n, power, weight[], x, r, vector) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # form the preconditioned vector + for i in 1:n + vector[i] = vector[i] / 2.0 + end + elseif status[] == 3 # form the Hessian-vector product + h_vector[1] = 2.0 * vector[1] + vector[2] + for i in 2:(n - 1) + h_vector[i] = vector[i - 1] + 2.0 * vector[i] + vector[i + 1] + end + h_vector[n] = vector[n - 1] + 2.0 * vector[n] + for i in 1:n + vector[i] = h_vector[i] + end + elseif status[] == 4 # restart + for i in 1:n + r[i] = 1.0 + end + else + @printf(" the value %1i of status should not occur\n", status) + end + end + + glrt_information(data, inform, status) + @printf("MR = %1i%1i glrt_solve_problem exit status = %i, f = %.2f\n", unit_m, + new_weight, inform[].status, + inform[].obj_regularized) + end end + + # Delete internal workspace + glrt_terminate(data, control, inform) + + return 0 end -# Delete internal workspace -glrt_terminate( data, control, inform ) +@testset "GLRT" begin + @test test_glrt() == 0 +end diff --git a/GALAHAD.jl/test/test_gltr.jl b/GALAHAD.jl/test/test_gltr.jl index 4b278fd379..badff0a536 100644 --- a/GALAHAD.jl/test/test_gltr.jl +++ b/GALAHAD.jl/test/test_gltr.jl @@ -2,82 +2,95 @@ # Simple code to test the Julia interface to GLTR using GALAHAD +using Test using Printf +using Accessors -# Derived types -data = [Ptr{Ptr{Cvoid}}()] -control = gltr_control_type{Float64}() -inform = gltr_inform_type{Float64}() +function test_gltr() + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{gltr_control_type{Float64}}() + inform = Ref{gltr_inform_type{Float64}}() -# Set problem data -n = 100 # dimension + # Set problem data + n = 100 # dimension -status = Ref{Cint}() -radius = 0 -x = zeros(Float64, n) -r = zeros(Float64, n) -vector = zeros(Float64, n) -h_vector = zeros(Float64, n) + status = Ref{Cint}() + radius = Ref{Float64}() + x = zeros(Float64, n) + r = zeros(Float64, n) + vector = zeros(Float64, n) + h_vector = zeros(Float64, n) -# Initialize gltr -gltr_initialize( data, control, status ) + # Initialize gltr + gltr_initialize(data, control, status) -# use a unit M ? -for unit_m = 0:1 - if unit_m == 0 - control.unitm = false - else - control.unitm = true - end - gltr_import_control( control, data, status ) - - # resolve with a smaller radius ? - for new_radius = 0:1 - if new_radius == 0 - global radius = 1.0 - status[] = 1 + # use a unit M ? + for unit_m in 0:1 + if unit_m == 0 + @reset control[].unitm = false else - global radius = 0.1 - status[] = 4 + @reset control[].unitm = true end - for i = 1:n - r[i] = 1.0 - end + gltr_import_control(control, data, status) - # iteration loop to find the minimizer - while(true) # reverse-communication loop - gltr_solve_problem( data, status, n, radius, x, r, vector ) - if status[] == 0 # successful termination - break - elseif status[] < 0 # error exit - error("GLTR -- status = $(status[])") - elseif status[] == 2 # form the preconditioned vector - for i = 1:n - vector[i] = vector[i] / 2.0 - end - elseif status[] == 3 # form the Hessian-vector product - h_vector[1] = 2.0 * vector[1] + vector[2] - for i = 2:n-1 - h_vector[i] = vector[i-1] + 2.0 * vector[i] + vector[i+1] - end - h_vector[n] = vector[n-1] + 2.0 * vector[n] - for i = 1:n - vector[i] = h_vector[i] - end - elseif status[] == 5 # restart - for i = 1:n - r[i] = 1.0 - end + # resolve with a smaller radius ? + for new_radius in 0:1 + if new_radius == 0 + radius[] = 1.0 + status[] = 1 else - @printf(" the value %1i of status should not occur\n", status) + radius[] = 0.1 + status[] = 4 end - end - gltr_information( data, inform, status ) - @printf("MR = %1i%1i gltr_solve_problem exit status = %i, f = %.2f\n", unit_m, new_radius, inform.status, inform.obj ) + for i in 1:n + r[i] = 1.0 + end + + # iteration loop to find the minimizer + terminated = false + while !terminated # reverse-communication loop + gltr_solve_problem(data, status, n, radius[], x, r, vector) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # form the preconditioned vector + for i in 1:n + vector[i] = vector[i] / 2.0 + end + elseif status[] == 3 # form the Hessian-vector product + h_vector[1] = 2.0 * vector[1] + vector[2] + for i in 2:(n - 1) + h_vector[i] = vector[i - 1] + 2.0 * vector[i] + vector[i + 1] + end + h_vector[n] = vector[n - 1] + 2.0 * vector[n] + for i in 1:n + vector[i] = h_vector[i] + end + elseif status[] == 5 # restart + for i in 1:n + r[i] = 1.0 + end + else + @printf(" the value %1i of status should not occur\n", status) + end + end + + gltr_information(data, inform, status) + @printf("MR = %1i%1i gltr_solve_problem exit status = %i, f = %.2f\n", unit_m, + new_radius, inform[].status, inform[].obj) + end end + + # Delete internal workspace + gltr_terminate(data, control, inform) + + return 0 end -# Delete internal workspace -gltr_terminate( data, control, inform ) +@testset "GLTR" begin + @test test_gltr() == 0 +end diff --git a/GALAHAD.jl/test/test_l2rt.jl b/GALAHAD.jl/test/test_l2rt.jl index b53b7d188f..0131b9f36d 100644 --- a/GALAHAD.jl/test/test_l2rt.jl +++ b/GALAHAD.jl/test/test_l2rt.jl @@ -2,63 +2,75 @@ # Simple code to test the Julia interface to L2RT using GALAHAD +using Test using Printf +using Accessors -# Derived types -data = [Ptr{Ptr{Cvoid}}()] -control = l2rt_control_type{Float64}() -inform = l2rt_inform_type{Float64}() +function test_l2rt() + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{l2rt_control_type{Float64}}() + inform = Ref{l2rt_inform_type{Float64}}() -# Set problem data -n = 50 # dimensions -m = 2 * n + # Set problem data + n = 50 # dimensions + m = 2 * n -status = Ref{Cint}() -power = 3.0 -weight = 1.0 -shift = 1.0 -x = zeros(Float64, n) -u = zeros(Float64, m) -v = zeros(Float64, n) + status = Ref{Cint}() + power = 3.0 + weight = 1.0 + shift = 1.0 + x = zeros(Float64, n) + u = zeros(Float64, m) + v = zeros(Float64, n) -# Initialize l2rt -l2rt_initialize( data, control, status ) + # Initialize l2rt + l2rt_initialize(data, control, status) -status[] = 1 -control.print_level = 0 -l2rt_import_control( control, data, status ) + status[] = 1 + @reset control[].print_level = Cint(0) + l2rt_import_control(control, data, status) -for i = 1:m - u[i] = 1.0 # b = 1 -end + for i in 1:m + u[i] = 1.0 # b = 1 + end -# iteration loop to find the minimizer with A^T = (I:diag(1:n)) -while true # reverse-communication loop - l2rt_solve_problem( data, status, m, n, power, weight, shift, x, u, v ) - if status[] == 0 # successful termination - break - elseif status[] < 0 # error exit - error("L2RT -- status = $(status[])") - elseif status[] == 2 # form u <- u + A * v - for i = 1:n - u[i] = u[i] + v[i] - u[n+i] = u[n+i] + i * v[i] - end - elseif status[] == 3 # form v <- v + A^T * u - for i = 1:n - v[i] = v[i] + u[i] + i * u[n+i] + # iteration loop to find the minimizer with A^T = (I:diag(1:n)) + terminated = false + while !terminated # reverse-communication loop + l2rt_solve_problem(data, status, m, n, power, weight, shift, x, u, v) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # form u <- u + A * v + for i in 1:n + u[i] = u[i] + v[i] + u[n + i] = u[n+i] + i * v[i] + end + elseif status[] == 3 # form v <- v + A^T * u + for i in 1:n + v[i] = v[i] + u[i] + i * u[n+i] + end + elseif status[] == 4 # restart + for i in 1:m + u[i] = 1.0 + end + else + @printf(" the value %1i of status should not occur\n", status) end - elseif status[] == 4 # restart - for i = 1:m - u[i] = 1.0 - end - else - @printf(" the value %1i of status should not occur\n", status) end -end -l2rt_information( data, inform, status ) -@printf("l2rt_solve_problem exit status = %i, f = %.2f\n", inform.status, inform.obj ) + l2rt_information(data, inform, status) -# Delete internal workspace -l2rt_terminate( data, control, inform ) + @printf("l2rt_solve_problem exit status = %i, f = %.2f\n", inform[].status, inform[].obj) + + # Delete internal workspace + l2rt_terminate(data, control, inform) + + return 0 +end + +@testset "L2RT" begin + @test test_l2rt() == 0 +end diff --git a/GALAHAD.jl/test/test_lhs.jl b/GALAHAD.jl/test/test_lhs.jl index 611e1f7b19..cd8b7f8882 100644 --- a/GALAHAD.jl/test/test_lhs.jl +++ b/GALAHAD.jl/test/test_lhs.jl @@ -2,39 +2,50 @@ # Simple code to test the Julia interface to LHS using GALAHAD +using Test using Printf +using Accessors -# Derived types -data = [Ptr{Ptr{Cvoid}}()] -control = lhs_control_type() -inform = lhs_inform_type() - -# Initialize LHS -lhs_initialize(data, control, inform) - -# Parameters -n_dimen = 7 # dimension -n_points = 2 # points required -X = [zeros(Cint, n_points) for i=1:n_dimen] # points -seed = Ref{Cint}() - -# Set a random seed -lhs_get_seed(seed) - -# Generate points -lhs_ihs(n_dimen, n_points, seed, X, control, inform, data) -if inform.status == 0 # successful return - @printf("LHS successful\n") - for j = 1:n_points - @printf("Point %d = ", j) - for i = 1:n_dimen - @printf("%d ", X[i][j]) +function test_lhs() + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{lhs_control_type}() + inform = Ref{lhs_inform_type}() + + # Initialize LHS + lhs_initialize(data, control, inform) + + # Parameters + n_dimen = Cint(7) # dimension + n_points = Cint(2) # points required + X = [zeros(Cint, n_points) for i in 1:n_dimen] # points + seed = Ref{Cint}() + + # Set a random seed + lhs_get_seed(seed) + + # Generate points + lhs_ihs(n_dimen, n_points, seed, X, control, inform, data) + + if inform[].status == 0 # successful return + @printf("LHS successful\n") + for j in 1:n_points + @printf("Point %d = ", j) + for i in 1:n_dimen + @printf("%d ", X[i][j]) + @printf("\n") + end end + else # error returns + @printf("LHS exit status = %d \n", inform[].status) end - @printf("\n") -else # error returns - @printf("LHS exit status = %d \n", inform.status) + + # Delete internal workspace + lhs_terminate(data, control, inform) + + return 0 end -# Delete internal workspace -lhs_terminate(data, control, inform) +@testset "LHS" begin + @test test_lhs() == 0 +end diff --git a/GALAHAD.jl/test/test_llst.jl b/GALAHAD.jl/test/test_llst.jl index 1f914bdbc1..0d0d597c58 100644 --- a/GALAHAD.jl/test/test_llst.jl +++ b/GALAHAD.jl/test/test_llst.jl @@ -2,179 +2,244 @@ # Simple code to test the Julia interface to LLST using GALAHAD +using Test using Printf +using Accessors + +function test_llst() + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{llst_control_type{Float64}}() + inform = Ref{llst_inform_type{Float64}}() + + # Set problem data + # set dimensions + m = 100 + n = 2 * m + 1 + # A = (I : Diag(1:n) : e) + A_ne = 3 * m + A_row = zeros(Cint, A_ne) + A_col = zeros(Cint, A_ne) + A_ptr = zeros(Cint, m + 1) + A_val = zeros(Float64, A_ne) + + # store A in sparse formats + l = 1 + for i in 1:m + A_ptr[i] = l + A_row[l] = i + A_col[l] = i + A_val[l] = 1.0 + l = l + 1 + A_row[l] = i + A_col[l] = m + i + A_val[l] = i + l = l + 1 + A_row[l] = i + A_col[l] = n + A_val[l] = 1.0 + l = l + 1 + end + A_ptr[m] = l -# Derived types -data = [Ptr{Ptr{Cvoid}}()] -control = llst_control_type{Float64}() -inform = llst_inform_type{Float64}() - -# Set problem data -# set dimensions -m = 100 -n = 2*m+1 -# A = ( I : Diag(1:n) : e ) -A_ne = 3*m -A_row[A_ne] -A_col[A_ne] -A_ptr[m+1] -A_val[A_ne] - -# store A in sparse formats -l=0 -for( i=1 i <= m i++) - A_ptr[i-1] = l+1 - A_row[l] = i - A_col[l] = i - A_val[l] = 1.0 - l++ - A_row[l] = i - A_col[l] = m+i - A_val[l] = i - l++ - A_row[l] = i - A_col[l] = n - A_val[l] = 1.0 - l++ -] -A_ptr[m] = l+1 - -# store A in dense format -A_dense_ne = m * n -real_wp_ A_dense_val[A_dense_ne] -for( i=0 i < A_dense_ne i++) A_dense_val[i] = 0.0 -l=-1 -for( i=1 i <= m i++) - A_dense_val[l+i] = 1.0 - A_dense_val[l+m+i] = i - A_dense_val[l+n] = 1.0 - l=l+n -] - -# S = diag(1:n)**2 -S_ne = n -S_row[S_ne] -S_col[S_ne] -S_ptr[n+1] -S_val = zeros(Float64, S_ne) - -# store S in sparse formats -for i = 1:n - S_row[i] = i+1 - S_col[i] = i+1 - S_ptr[i] = i+1 - S_val[i] = (i+1)*(i+1) -end -S_ptr[n+1] = n+2 - -# store S in dense format -S_dense_ne = n*(n+1)/2 -S_dense_val = zeros(Float64, S_dense_ne) -l=-1 -for( i=1 i <= n i++) - S_dense_val[l+i] = i*i - l=l+i -] - -# b is a vector of ones -b = ones(Float64, m) # observations - -# trust-region radius is one -radius = 1.0 - -# Set output storage -x = zeros(Float64, n) # solution -st = ' ' -status = Ref{Cint}() - -@printf(" Fortran sparse matrix indexing\n\n") -@printf(" basic tests of problem storage formats\n\n") - -# loop over storage formats -for d = 1:4 - # Initialize LLST - llst_initialize( data, control, status ) - strcpy(control.definite_linear_solver, "potr ") - strcpy(control.sbls_control.symmetric_linear_solver, "sytr ") - strcpy(control.sbls_control.definite_linear_solver, "potr ") - # control.print_level = 1 - - # Set user-defined control options - control.f_indexing = true # Fortran sparse matrix indexing - - # use s or not (1 or 0) - for use_s = 0:1 - # sparse co-ordinate storage - if d == 1 - global st = 'C' - - llst_import( control, data, status, m, n, - "coordinate", A_ne, A_row, A_col, Cint[] ) - - if use_s == 0 - llst_solve_problem( data, status, m, n, radius, A_ne, A_val, b, x, 0, Cint[] ) - else - llst_import_scaling( control, data, status, n, "coordinate", S_ne, S_row, S_col, Cint[] ) - llst_solve_problem( data, status, m, n, radius, A_ne, A_val, b, x, S_ne, S_val ) - end - end + # store A in dense format + A_dense_ne = m * n + A_dense_val = zeros(Float64, A_dense_ne) + for i in 1:A_dense_ne + A_dense_val[i] = 0.0 + end + l = 0 + for i in 1:m + A_dense_val[l + i] = 1.0 + A_dense_val[l + m + i] = i + A_dense_val[l + n] = 1.0 + l = l + n + end - # sparse by rows - if d == 2 - global st = 'R' + # S = diag(1:n)**2 + S_ne = Cint(n) + S_row = zeros(Cint, S_ne) + S_col = zeros(Cint, S_ne) + S_ptr = zeros(Cint, n + 1) + S_val = zeros(Float64, S_ne) + + # store S in sparse formats + for i in 1:n + S_row[i] = i + S_col[i] = i + S_ptr[i] = i + S_val[i] = i * i + end + S_ptr[n] = n + 1 - llst_import( control, data, status, m, n, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr ) + # store S in dense format + S_dense_ne = div(n * (n + 1), 2) + S_dense_val = zeros(Float64, S_dense_ne) + for i in 1:S_dense_ne + S_dense_val[i] = 0.0 + end - if use_s == 0 - llst_solve_problem( data, status, m, n, radius, A_ne, A_val, b, x, 0, Cint[] ) - else - llst_import_scaling( control, data, status, n, "sparse_by_rows", S_ne, Cint[], S_col, S_ptr ) - llst_solve_problem( data, status, m, n, radius, A_ne, A_val, b, x, S_ne, S_val ) + l = 0 + for i in 1:n + S_dense_val[l + i] = i * i + l = l + i + end + + # b is a vector of ones + b = zeros(Float64, m) # observations + for i in 1:m + b[i] = 1.0 + end + + # trust-region radius is one + radius = 1.0 + + # Set output storage + x = zeros(Float64, n) # solution + st = ' ' + status = Ref{Cint}() + + @printf(" Fortran sparse matrix indexing\n\n") + @printf(" basic tests of problem storage formats\n\n") + + # loop over storage formats + for d in 1:4 + + # Initialize LLST + llst_initialize(data, control, status) + @reset control[].definite_linear_solver = convert(NTuple{31,Int8}, + (112, 111, 116, 114, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 0)) + @reset control[].sbls_control.symmetric_linear_solver = convert(NTuple{31,Int8}, + (115, 121, 116, 114, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 0)) + @reset control[].sbls_control.definite_linear_solver = convert(NTuple{31,Int8}, + (112, 111, 116, 114, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 0)) + # @reset control[].print_level = 1 + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + + # use s or not (1 or 0) + for use_s in 0:1 + # sparse co-ordinate storage + if d == 1 + st = 'C' + llst_import(control, data, status, m, n, + "coordinate", A_ne, A_row, A_col, Cint[]) + + if use_s == 0 + llst_solve_problem(data, status, m, n, radius, + A_ne, A_val, b, x, 0, Cint[]) + else + llst_import_scaling(control, data, status, n, + "coordinate", S_ne, S_row, + S_col, Cint[]) + + llst_solve_problem(data, status, m, n, radius, + A_ne, A_val, b, x, S_ne, S_val) + end end - end - # dense - if d == 3 - global st = 'D' + # sparse by rows + if d == 2 + st = 'R' + llst_import(control, data, status, m, n, + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + if use_s == 0 + llst_solve_problem(data, status, m, n, radius, + A_ne, A_val, b, x, 0, Cint[]) + else + llst_import_scaling(control, data, status, n, + "sparse_by_rows", S_ne, Cint[], + S_col, S_ptr) + + llst_solve_problem(data, status, m, n, radius, + A_ne, A_val, b, x, S_ne, S_val) + end + end - llst_import( control, data, status, m, n, "dense", A_dense_ne, Cint[], Cint[], Cint[] ) - if use_s == 0 - llst_solve_problem( data, status, m, n, radius, A_dense_ne, A_dense_val, b, x, 0, Cint[] ) - else - llst_import_scaling( control, data, status, n, "dense", S_dense_ne, Cint[], Cint[], Cint[] ) - llst_solve_problem( data, status, m, n, radius, A_dense_ne, A_dense_val, b, x, S_dense_ne, S_dense_val ) + # dense + if d == 3 + st = 'D' + llst_import(control, data, status, m, n, + "dense", A_dense_ne, Cint[], Cint[], Cint[]) + + if use_s == 0 + llst_solve_problem(data, status, m, n, radius, + A_dense_ne, A_dense_val, b, x, + 0, Cint[]) + else + llst_import_scaling(control, data, status, n, + "dense", S_dense_ne, + Cint[], Cint[], Cint[]) + + llst_solve_problem(data, status, m, n, radius, + A_dense_ne, A_dense_val, b, x, + S_dense_ne, S_dense_val) + end + end + + # diagonal + if d == 4 + st = 'I' + llst_import(control, data, status, m, n, + "coordinate", A_ne, A_row, A_col, Cint[]) + if use_s == 0 + llst_solve_problem(data, status, m, n, radius, + A_ne, A_val, b, x, 0, Cint[]) + else + llst_import_scaling(control, data, status, n, + "diagonal", S_ne, Cint[], Cint[], Cint[]) + + llst_solve_problem(data, status, m, n, radius, + A_ne, A_val, b, x, S_ne, S_val) + end end - end - # diagonal - if d == 4 - global st = 'I' + llst_information(data, inform, status) - llst_import( control, data, status, m, n, "coordinate", A_ne, A_row, A_col, Cint[] ) - if use_s == 0 - llst_solve_problem( data, status, m, n, radius, A_ne, A_val, b, x, 0, Cint[] ) + if inform[].status == 0 + @printf("storage type %c%1i: status = %1i, ||r|| = %5.2f\n", st, use_s, + inform[].status, inform[].r_norm) else - llst_import_scaling( control, data, status, n, "diagonal", S_ne, Cint[], Cint[], Cint[] ) - llst_solve_problem( data, status, m, n, radius, A_ne, A_val, b, x, S_ne, S_val ) + @printf("storage type %c%1i: LLST_solve exit status = %1i\n", st, use_s, + inform[].status) end end - llst_information( data, inform, status ) + # @printf("x: ") + # for i = 1:n + # @printf("%f ", x[i]) + # end + # @printf("\n") - if inform.status == 0 - @printf("storage type %c%1i: status = %1i, ||r|| = %5.2f\n", st, use_s, inform.status, inform.r_norm ) - else - @printf("storage type %c%1i: LLST_solve exit status = %1i\n", st, use_s, inform.status) - end + # Delete internal workspace + llst_terminate(data, control, inform) end - # @printf("x: ") - # for i = 1:n - # @printf("%f ", x[i]) - # end - # @printf("\n") + return 0 +end - # Delete internal workspace - llst_terminate( data, control, inform ) +@testset "LLST" begin + @test test_llst() == 0 end diff --git a/GALAHAD.jl/test/test_lpa.jl b/GALAHAD.jl/test/test_lpa.jl index 5da13813e0..93b012bc1f 100644 --- a/GALAHAD.jl/test/test_lpa.jl +++ b/GALAHAD.jl/test/test_lpa.jl @@ -2,107 +2,115 @@ # Simple code to test the Julia interface to LPA using GALAHAD +using Test using Printf - -# Derived types -data = [Ptr{Ptr{Cvoid}}()] -control = lpa_control_type{Float64}() -inform = lpa_inform_type{Float64}() - -# Set problem data -n = 3 # dimension -m = 2 # number of general constraints -g = Float64[0.0, 2.0, 0.0] # linear term in the objective -f = 1.0 # constant term in the objective -A_ne = 4 # Jacobian elements -A_row = Cint[1, 1, 2, 2] # row indices -A_col = Cint[1, 2, 2, 3] # column indices -A_ptr = Cint[1, 3, 5] # row pointers -A_val = Float64[2.0, 1.0, 1.0, 1.0] # values -c_l = Float64[1.0, 2.0] # constraint lower bound -c_u = Float64[2.0, 2.0] # constraint upper bound -x_l = Float64[-1.0, -Inf, -Inf] # variable lower bound -x_u = Float64[1.0, Inf, 2.0] # variable upper bound - -# Set output storage -c = zeros(Float64, m) # constraint values -x_stat = zeros(Cint, n) # variable status -c_stat = zeros(Cint, m) # constraint status -st = ' ' -status = Ref{Cint}() - -@printf(" Fortran sparse matrix indexing\n\n") -@printf(" basic tests of lp storage formats\n\n") - -for d = 1:3 - # Initialize LPA - lpa_initialize( data, control, status ) - - # Set user-defined control options - control.f_indexing = true # Fortran sparse matrix indexing - - # Start from 0 - x = Float64[0.0,0.0,0.0] - y = Float64[0.0,0.0] - z = Float64[0.0,0.0,0.0] - - # sparse co-ordinate storage - if d == 1 - global st = 'C' - - lpa_import( control, data, status, n, m, - "coordinate", A_ne, A_row, A_col, Cint[] ) - - lpa_solve_lp( data, status, n, m, g, f, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) - end - - # sparse by rows - if d == 2 - global st = 'R' - - lpa_import( control, data, status, n, m, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr ) - - lpa_solve_lp( data, status, n, m, g, f, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) - end - - # dense - if d == 3 - global st = 'D' - A_dense_ne = 6 # number of elements of A - A_dense = Float64[2.0, 1.0, 0.0, 0.0, 1.0, 1.0] - - lpa_import( control, data, status, n, m, - "dense", A_ne, Cint[], Cint[], Cint[] ) - - lpa_solve_lp( data, status, n, m, g, f, - A_dense_ne, A_dense, c_l, c_u, x_l, x_u, - x, c, y, z, x_stat, c_stat ) +using Accessors + +function test_lpa() + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{lpa_control_type{Float64}}() + inform = Ref{lpa_inform_type{Float64}}() + + # Set problem data + n = 3 # dimension + m = 2 # number of general constraints + g = Float64[0.0, 2.0, 0.0] # linear term in the objective + f = 1.0 # constant term in the objective + A_ne = 4 # Jacobian elements + A_row = Cint[1, 1, 2, 2] # row indices + A_col = Cint[1, 2, 2, 3] # column indices + A_ptr = Cint[1, 3, 5] # row pointers + A_val = Float64[2.0, 1.0, 1.0, 1.0] # values + c_l = Float64[1.0, 2.0] # constraint lower bound + c_u = Float64[2.0, 2.0] # constraint upper bound + x_l = Float64[-1.0, -Inf, -Inf] # variable lower bound + x_u = Float64[1.0, Inf, 2.0] # variable upper bound + + # Set output storage + c = zeros(Float64, m) # constraint values + x_stat = zeros(Cint, n) # variable status + c_stat = zeros(Cint, m) # constraint status + st = ' ' + status = Ref{Cint}() + + @printf(" Fortran sparse matrix indexing\n\n") + @printf(" basic tests of lp storage formats\n\n") + + for d in 1:3 + # Initialize LPA + lpa_initialize(data, control, status) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + + # Start from 0 + x = Float64[0.0, 0.0, 0.0] + y = Float64[0.0, 0.0] + z = Float64[0.0, 0.0, 0.0] + + # sparse co-ordinate storage + if d == 1 + st = 'C' + lpa_import(control, data, status, n, m, + "coordinate", A_ne, A_row, A_col, Cint[]) + + lpa_solve_lp(data, status, n, m, g, f, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + end + + # sparse by rows + if d == 2 + st = 'R' + lpa_import(control, data, status, n, m, + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + + lpa_solve_lp(data, status, n, m, g, f, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + end + + # dense + if d == 3 + st = 'D' + A_dense_ne = 6 # number of elements of A + A_dense = Float64[2.0, 1.0, 0.0, 0.0, 1.0, 1.0] + lpa_import(control, data, status, n, m, + "dense", A_ne, Cint[], Cint[], Cint[]) + + lpa_solve_lp(data, status, n, m, g, f, + A_dense_ne, A_dense, c_l, c_u, x_l, x_u, + x, c, y, z, x_stat, c_stat) + end + + lpa_information(data, inform, status) + + if inform[].status == 0 + @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", st, + inform[].iter, inform[].obj, inform[].status) + else + @printf("%c: LPA_solve exit status = %1i\n", st, inform[].status) + end + + # @printf("x: ") + # for i = 1:n + # @printf("%f ", x[i]) + # end + # @printf("\n") + # @printf("gradient: ") + # for i = 1:n + # @printf("%f ", g[i]) + # end + # @printf("\n") + + # Delete internal workspace + lpa_terminate(data, control, inform) end - lpa_information( data, inform, status ) - - if inform.status == 0 - @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", st, inform.iter, inform.obj, inform.status) - else - @printf("%c: LPA_solve exit status = %1i\n", st, inform.status) - end + return 0 end -# @printf("x: ") -# for i = 1:n -# @printf("%f ", x[i]) -# end -# @printf("\n") -# @printf("gradient: ") -# for i = 1:n -# @printf("%f ", g[i]) -# end -# @printf("\n") - -# Delete internal workspace -lpa_terminate( data, control, inform ) +@testset "LPA" begin + @test test_lpa() == 0 +end diff --git a/GALAHAD.jl/test/test_lpb.jl b/GALAHAD.jl/test/test_lpb.jl index e343b7977a..b4c48b80cc 100644 --- a/GALAHAD.jl/test/test_lpb.jl +++ b/GALAHAD.jl/test/test_lpb.jl @@ -2,107 +2,116 @@ # Simple code to test the Julia interface to LPB using GALAHAD +using Test using Printf - -# Derived types -data = [Ptr{Ptr{Cvoid}}()] -control = lpb_control_type{Float64}() -inform = lpb_inform_type{Float64}() - -# Set problem data -n = 3 # dimension -m = 2 # number of general constraints -g = Float64[0.0, 2.0, 0.0] # linear term in the objective -f = 1.0 # constant term in the objective -A_ne = 4 # Jacobian elements -A_row = Cint[1, 1, 2, 2] # row indices -A_col = Cint[1, 2, 2, 3] # column indices -A_ptr = Cint[1, 3, 5] # row pointers -A_val = Float64[2.0, 1.0, 1.0, 1.0] # values -c_l = Float64[1.0, 2.0] # constraint lower bound -c_u = Float64[2.0, 2.0] # constraint upper bound -x_l = Float64[-1.0, -Inf, -Inf] # variable lower bound -x_u = Float64[1.0, Inf, 2.0] # variable upper bound - -# Set output storage -c = zeros(Float64, m) # constraint values -x_stat = zeros(Cint, n) # variable status -c_stat = zeros(Cint, m) # constraint status -st = ' ' -status = Ref{Cint}() - -@printf(" Fortran sparse matrix indexing\n\n") -@printf(" basic tests of lp storage formats\n\n") - -for d = 1:3 - # Initialize LPB - lpb_initialize( data, control, status ) - - # Set user-defined control options - control.f_indexing = true # Fortran sparse matrix indexing - - # Start from 0 - x = Float64[0.0,0.0,0.0] - y = Float64[0.0,0.0] - z = Float64[0.0,0.0,0.0] - - # sparse co-ordinate storage - if d == 1 - global st = 'C' - - lpb_import( control, data, status, n, m, - "coordinate", A_ne, A_row, A_col, Cint[] ) - - lpb_solve_lp( data, status, n, m, g, f, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) - end - - # sparse by rows - if d == 2 - global st = 'R' - - lpb_import( control, data, status, n, m, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr ) - - lpb_solve_lp( data, status, n, m, g, f, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) - end - - # dense - if d == 3 - global st = 'D' - A_dense_ne = 6 # number of elements of A - A_dense = Float64[2.0, 1.0, 0.0, 0.0, 1.0, 1.0] - - lpb_import( control, data, status, n, m, - "dense", A_ne, Cint[], Cint[], Cint[] ) - - lpb_solve_lp( data, status, n, m, g, f, - A_dense_ne, A_dense, c_l, c_u, x_l, x_u, - x, c, y, z, x_stat, c_stat ) +using Accessors + +function test_lpb() + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{lpb_control_type{Float64}}() + inform = Ref{lpb_inform_type{Float64}}() + + # Set problem data + n = 3 # dimension + m = 2 # number of general constraints + g = Float64[0.0, 2.0, 0.0] # linear term in the objective + f = 1.0 # constant term in the objective + A_ne = 4 # Jacobian elements + A_row = Cint[1, 1, 2, 2] # row indices + A_col = Cint[1, 2, 2, 3] # column indices + A_ptr = Cint[1, 3, 5] # row pointers + A_val = Float64[2.0, 1.0, 1.0, 1.0] # values + c_l = Float64[1.0, 2.0] # constraint lower bound + c_u = Float64[2.0, 2.0] # constraint upper bound + x_l = Float64[-1.0, -Inf, -Inf] # variable lower bound + x_u = Float64[1.0, Inf, 2.0] # variable upper bound + + # Set output storage + c = zeros(Float64, m) # constraint values + x_stat = zeros(Cint, n) # variable status + c_stat = zeros(Cint, m) # constraint status + st = ' ' + status = Ref{Cint}() + + @printf(" Fortran sparse matrix indexing\n\n") + @printf(" basic tests of lp storage formats\n\n") + + for d in 1:3 + # Initialize LPB + lpb_initialize(data, control, status) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + + # Start from 0 + x = Float64[0.0, 0.0, 0.0] + y = Float64[0.0, 0.0] + z = Float64[0.0, 0.0, 0.0] + + # sparse co-ordinate storage + if d == 1 + st = 'C' + lpb_import(control, data, status, n, m, + "coordinate", A_ne, A_row, A_col, Cint[]) + + lpb_solve_lp(data, status, n, m, g, f, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + end + + # sparse by rows + if d == 2 + st = 'R' + lpb_import(control, data, status, n, m, + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + + lpb_solve_lp(data, status, n, m, g, f, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + end + + # dense + if d == 3 + st = 'D' + A_dense_ne = 6 # number of elements of A + A_dense = Float64[2.0, 1.0, 0.0, 0.0, 1.0, 1.0] + + lpb_import(control, data, status, n, m, + "dense", A_ne, Cint[], Cint[], Cint[]) + + lpb_solve_lp(data, status, n, m, g, f, + A_dense_ne, A_dense, c_l, c_u, x_l, x_u, + x, c, y, z, x_stat, c_stat) + end + + lpb_information(data, inform, status) + + if inform[].status == 0 + @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", + st, inform[].iter, inform[].obj, inform[].status) + else + @printf("%c: LPB_solve exit status = %1i\n", st, inform[].status) + end + + # @printf("x: ") + # for i = 1:n + # @printf("%f ", x[i]) + # end + # @printf("\n") + # @printf("gradient: ") + # for i = 1:n + # @printf("%f ", g[i]) + # end + # @printf("\n") + + # Delete internal workspace + lpb_terminate(data, control, inform) end - lpb_information( data, inform, status ) - - if inform.status == 0 - @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", st, inform.iter, inform.obj, inform.status) - else - @printf("%c: LPB_solve exit status = %1i\n", st, inform.status) - end + return 0 end -# @printf("x: ") -# for i = 1:n -# @printf("%f ", x[i]) -# end -# @printf("\n") -# @printf("gradient: ") -# for i = 1:n -# @printf("%f ", g[i]) -# end -# @printf("\n") - -# Delete internal workspace -lpb_terminate( data, control, inform ) +@testset "LPB" begin + @test test_lpb() == 0 +end From 4cbae350ae75a7ca0afac6c756e96c309e315558 Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Mon, 22 Jan 2024 23:22:01 -0500 Subject: [PATCH 12/33] [GALAHAD.jl] Don't test bqpb on Windows --- GALAHAD.jl/test/runtests.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/GALAHAD.jl/test/runtests.jl b/GALAHAD.jl/test/runtests.jl index f0bf722da9..749cfb6c19 100644 --- a/GALAHAD.jl/test/runtests.jl +++ b/GALAHAD.jl/test/runtests.jl @@ -8,7 +8,9 @@ include("test_structures.jl") # include("test_blls.jl") include("test_bllsb.jl") # include("test_bqp.jl") -include("test_bqpb.jl") +if !Sys.iswindows() + include("test_bqpb.jl") +end include("test_bsc.jl") include("test_ccqp.jl") # include("test_clls.jl") From cfb52e43c0fe17e58e076efe2ff4a0e9e9de35f6 Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Wed, 24 Jan 2024 14:57:20 -0500 Subject: [PATCH 13/33] [GALAHAD.jl] Test the pakages bllsb, clls and presolve --- GALAHAD.jl/gen/examples.jl | 10 +- GALAHAD.jl/test/runtests.jl | 8 +- GALAHAD.jl/test/test_bllsb.jl | 1 + GALAHAD.jl/test/test_clls.jl | 311 +++++++++++++++---------- GALAHAD.jl/test/test_presolve.jl | 375 +++++++++++++++++-------------- 5 files changed, 406 insertions(+), 299 deletions(-) diff --git a/GALAHAD.jl/gen/examples.jl b/GALAHAD.jl/gen/examples.jl index 8f48eacff1..fbaa3bab35 100644 --- a/GALAHAD.jl/gen/examples.jl +++ b/GALAHAD.jl/gen/examples.jl @@ -38,17 +38,18 @@ function examples(package::String, example::String) text = replace(text, "} #" => "] #") 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") + "C_dense", "H_diag", "C_diag", "H_scid", "C_scid", "Ao_val", "r") text = replace(text, "real_wp_ $var[] = {" => "$var = Float64[") end - for var in ("f", "power", "weight", "shift", "radius", "half_radius", "x_l", "x_u") + for var in ("f", "power", "weight", "shift", "radius", "half_radius", "x_l", "x_u", "sigma") 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") + 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") 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") + "C_row", "C_col", "C_ptr", "Ao_col", "Ao_ptr", "Ao_row") text = replace(text, "int $var[] = {" => "$var = Cint[") end for val in ("1", "3", "5", "6", "7", "n", "n+m") @@ -62,6 +63,7 @@ function examples(package::String, example::String) for val in ("c", "g", "u", "v", "x", "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, "int $val[n]" => "$val = zeros(Cint, n)") diff --git a/GALAHAD.jl/test/runtests.jl b/GALAHAD.jl/test/runtests.jl index 749cfb6c19..57f73d371b 100644 --- a/GALAHAD.jl/test/runtests.jl +++ b/GALAHAD.jl/test/runtests.jl @@ -8,12 +8,10 @@ include("test_structures.jl") # include("test_blls.jl") include("test_bllsb.jl") # include("test_bqp.jl") -if !Sys.iswindows() - include("test_bqpb.jl") -end +include("test_bqpb.jl") include("test_bsc.jl") include("test_ccqp.jl") -# include("test_clls.jl") +include("test_clls.jl") include("test_convert.jl") # include("test_cqp.jl") # include("test_cro.jl") @@ -39,7 +37,7 @@ include("test_lsqp.jl") include("test_lsrt.jl") include("test_lstr.jl") # include("test_nls.jl") -# include("test_presolve.jl") +include("test_presolve.jl") include("test_psls.jl") # include("test_qpa.jl") # include("test_qpb.jl") diff --git a/GALAHAD.jl/test/test_bllsb.jl b/GALAHAD.jl/test/test_bllsb.jl index 79c4b89ae7..8fe0ad5a09 100644 --- a/GALAHAD.jl/test/test_bllsb.jl +++ b/GALAHAD.jl/test/test_bllsb.jl @@ -95,6 +95,7 @@ function test_bllsb() sigma, x_l, x_u, x, r, z, x_stat, w) end + # sparse by columns if d == 3 st = "SC" Ao_ne = 7 # objective Jacobian elements diff --git a/GALAHAD.jl/test/test_clls.jl b/GALAHAD.jl/test/test_clls.jl index e23f3ba4fd..fbd39f59c3 100644 --- a/GALAHAD.jl/test/test_clls.jl +++ b/GALAHAD.jl/test/test_clls.jl @@ -2,124 +2,203 @@ # Simple code to test the Julia interface to CLLS using GALAHAD +using Test using Printf - -# Derived types -data = [Ptr{Ptr{Cvoid}}()] -control = clls_control_type{Float64}() -inform = clls_inform_type{Float64}() - -# Set problem data -n = 3 # dimension -o = 4 # number of observations -m = 2 # number of general constraints -Ao_ne = 7 # design matrix elements -Ao_row = Cint[1, 1, 2, 2, 3, 3, 4] # row indices -Ao_col = Cint[1, 2, 2, 1, 3, 2] # column indices -Ao_ptr_ne = o + 1 # row pointer length -Ao_ptr = Cint[1, 3, 5, 7, 8] # row pointers -Ao_val = Float64[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] # values -b = Float64[2.0, 2.0, 3.0, 1.0] # observations -A_ne = 4 # Jacobian elements -A_row = Cint[1, 1, 2, 2] # row indices -A_col = Cint[1, 2, 2, 3] # column indices -Ao_ptr_ne = m + 1 # row pointer length -A_ptr = Cint[1, 3, 5] # row pointers -A_val = Float64[2.0, 1.0, 1.0, 1.0] # values -c_l = Float64[1.0, 2.0] # constraint lower bound -c_u = Float64[2.0, 2.0] # constraint upper bound -x_l = Float64[-1.0, -Inf, -Inf] # variable lower bound -x_u = Float64[1.0, Inf, 2.0] # variable upper bound -sigma = 1.0 # regularization weight -w = Float64[1.0, 1.0, 1.0, 2.0] # values - -# Set output storage -c = zeros(Float64, m) # constraint values -x_stat = zeros(Cint, n) # variable status -c_stat = zeros(Cint, m) # constraint status -st = ' ' -status = Ref{Cint}() - -@printf(" Fortran sparse matrix indexing\n\n") -@printf(" basic tests of clls storage formats\n\n") - -for d = 1:3 - - # Initialize CLLS - clls_initialize( data, control, status ) - - # Set user-defined control options - control.f_indexing = true # Fortran sparse matrix indexing - - # Start from 0 - x = Float64[0.0,0.0,0.0] - y = Float64[0.0,0.0] - z = Float64[0.0,0.0,0.0] - - # sparse co-ordinate storage - if d == 1 - global st = 'C' - - clls_import( control, data, status, n, o, m, - "coordinate", Ao_ne, Ao_row, Ao_col, 0, Cint[], - "coordinate", A_ne, A_row, A_col, 0, Cint[] ) - - clls_solve_clls( data, status, n, o, m, Ao_ne, Ao_val, b, sigma, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat, w ) +using Accessors + +function test_clls() + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{clls_control_type{Float64}}() + inform = Ref{clls_inform_type{Float64}}() + + # Set problem data + n = 3 # dimension + o = 4 # number of observations + m = 2 # number of general constraints + sigma = 1.0 # regularization weight + b = Float64[2.0, 2.0, 3.0, 1.0] # observations + c_l = Float64[1.0, 2.0] # constraint lower bound + c_u = Float64[2.0, 2.0] # constraint upper bound + x_l = Float64[-1.0, -Inf, -Inf] # variable lower bound + x_u = Float64[1.0, Inf, 2.0] # variable upper bound + w = Float64[1.0, 1.0, 1.0, 2.0] # weights + + # Set output storage + r = zeros(Float64, o) # residual values + c = zeros(Float64, m) # constraint values + x_stat = zeros(Cint, n) # variable status + c_stat = zeros(Cint, m) # constraint status + st = "" + status = Ref{Cint}() + + @printf(" Fortran sparse matrix indexing\n\n") + @printf(" basic tests of clls storage formats\n\n") + + for d in 1:5 + # Initialize CLLS + clls_initialize(data, control, status) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + @reset control[].symmetric_linear_solver = convert(NTuple{31,Int8}, + (112, 111, 116, 114, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 0)) + + @reset control[].fdc_control.symmetric_linear_solver = convert(NTuple{31,Int8}, + (112, 111, 116, 114, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 32, + 32, 32, 32, 32, 32, 32, + 32, 0)) + @reset control[].fdc_control.use_sls = true + + # Start from 0 + x = Float64[0.0, 0.0, 0.0] + y = Float64[0.0, 0.0] + z = Float64[0.0, 0.0, 0.0] + + # sparse co-ordinate storage + if d == 1 + st = "CO" + Ao_ne = 7 # objective Jacobian elements + Ao_row = Cint[1, 1, 2, 2, 3, 3, 4] # row indices + Ao_col = Cint[1, 2, 2, 3, 1, 3, 2] # column indices + Ao_val = Float64[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] # vals + A_ne = 4 # constraint Jacobian elements + A_row = Cint[1, 1, 2, 2] # row indices + A_col = Cint[1, 2, 2, 3] # column indices + A_val = Float64[2.0, 1.0, 1.0, 1.0] # values + + clls_import(control, data, status, n, o, m, + "coordinate", Ao_ne, Ao_row, Ao_col, 0, Cint[], + "coordinate", A_ne, A_row, A_col, 0, Cint[]) + + clls_solve_clls(data, status, n, o, m, Ao_ne, Ao_val, b, + sigma, A_ne, A_val, c_l, c_u, x_l, x_u, + x, r, c, y, z, x_stat, c_stat, w) + end + + # sparse by rows + if d == 2 + st = "SR" + Ao_ne = 7 # objective Jacobian elements + Ao_col = Cint[1, 2, 2, 3, 1, 3, 2] # column indices + Ao_ptr_ne = o + 1 # number of row pointers + Ao_ptr = Cint[1, 3, 5, 7, 8] # row pointers + Ao_val = Float64[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] # vals + A_ne = 4 # constraint Jacobian elements + A_col = Cint[1, 2, 2, 3] # column indices + A_ptr_ne = m + 1 # number of row pointers + A_ptr = Cint[1, 3, 5] # row pointers + A_val = Float64[2.0, 1.0, 1.0, 1.0] # values + + clls_import(control, data, status, n, o, m, + "sparse_by_rows", Ao_ne, Cint[], Ao_col, + Ao_ptr_ne, Ao_ptr, + "sparse_by_rows", A_ne, Cint[], A_col, + A_ptr_ne, A_ptr) + + clls_solve_clls(data, status, n, o, m, Ao_ne, Ao_val, b, + sigma, A_ne, A_val, c_l, c_u, x_l, x_u, + x, r, c, y, z, x_stat, c_stat, w) + end + + # sparse by columns + if d == 3 + st = "SC" + Ao_ne = 7 # objective Jacobian elements + Ao_row = Cint[1, 3, 1, 2, 4, 2, 3] # row indices + Ao_ptr_ne = n + 1 # number of column pointers + Ao_ptr = Cint[1, 3, 6, 8] # column pointers + Ao_val = Float64[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] # vals + A_ne = 4 # constraint Jacobian elements + A_row = Cint[1, 1, 2, 2] # row indices + A_ptr_ne = n + 1 # number of column pointers + A_ptr = Cint[1, 2, 4, 5] # column pointers + A_val = Float64[2.0, 1.0, 1.0, 1.0] # values + + clls_import(control, data, status, n, o, m, + "sparse_by_columns", Ao_ne, Ao_row, Cint[], + Ao_ptr_ne, Ao_ptr, + "sparse_by_columns", A_ne, A_row, Cint[], + A_ptr_ne, A_ptr) + + clls_solve_clls(data, status, n, o, m, Ao_ne, Ao_val, b, + sigma, A_ne, A_val, c_l, c_u, x_l, x_u, + x, r, c, y, z, x_stat, c_stat, w) + end + + # dense by rows + if d == 4 + st = "DR" + Ao_ne = 12 # objective Jacobian elements + Ao_dense = Float64[1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0] + A_ne = 6 # constraint Jacobian elements + A_dense = Float64[2.0, 1.0, 0.0, 0.0, 1.0, 1.0] + + clls_import(control, data, status, n, o, m, + "dense", Ao_ne, Cint[], Cint[], 0, Cint[], + "dense", A_ne, Cint[], Cint[], 0, Cint[]) + + clls_solve_clls(data, status, n, o, m, Ao_ne, Ao_dense, b, + sigma, A_ne, A_dense, c_l, c_u, x_l, x_u, + x, r, c, y, z, x_stat, c_stat, w) + end + + # dense by cols + if d == 5 + st = "DC" + Ao_ne = 12 # objective Jacobian elements + Ao_dense = Float64[1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0] + A_ne = 6 # constraint Jacobian elements + A_dense = Float64[2.0, 0.0, 1.0, 1.0, 0.0, 1.0] + + clls_import(control, data, status, n, o, m, + "dense_by_columns", Ao_ne, Cint[], Cint[], 0, Cint[], + "dense_by_columns", A_ne, Cint[], Cint[], 0, Cint[]) + + clls_solve_clls(data, status, n, o, m, Ao_ne, Ao_dense, b, + sigma, A_ne, A_dense, c_l, c_u, x_l, x_u, + x, r, c, y, z, x_stat, c_stat, w) + end + + clls_information(data, inform, status) + + if inform[].status == 0 + @printf("%s:%6i iterations. Optimal objective value = %5.2f status = %1i\n", st, + inform[].iter, inform[].obj, inform[].status) + else + @printf("%s: CLLS_solve exit status = %1i\n", st, inform[].status) + end + + # @printf("x: ") + # for i = 1:n + # @printf("%f ", x[i]) + # end + # @printf("\n") + # @printf("gradient: ") + # for i = 1:n + # @printf("%f ", g[i]) + # end + # @printf("\n") + + # Delete internal workspace + clls_terminate(data, control, inform) end - # sparse by rows - if d == 2 - global st = 'R' - - clls_import( control, data, status, n, o, m, - "sparse_by_rows", Ao_ne, Cint[], Ao_col, Ao_ptr_ne, Ao_ptr, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr_ne, A_ptr ) - - clls_solve_clls( data, status, n, o, m, Ao_ne, Ao_val, b, sigma, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat, w ) - end - - # dense - if d == 3 - global st = 'D' - - Ao_dense_ne = 12 # number of elements of Ao - A_dense_ne = 6 # number of elements of A - Ao_dense = Float64[1.0, 1.0, 0.0, 0.0, 1.0, 1.0, - 1.0, 0.0, 1.0, 0.0, 1.0, 0.0] - A_dense = Float64[2.0, 1.0, 0.0, 0.0, 1.0, 1.0] - - clls_import( control, data, status, n, o, m, - "dense", Ao_ne, Cint[], Cint[], 0, Cint[], - "dense", A_ne, Cint[], Cint[], 0, Cint[] ) - - clls_solve_clls( data, status, n, o, m, Ao_dense_ne, Ao_dense, b, sigma, - A_dense_ne, A_dense, c_l, c_u, x_l, x_u, - x, c, y, z, x_stat, c_stat, w ) - end - - clls_information( data, inform, status ) - - if inform.status == 0 - @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", st, inform.iter, inform.obj, inform.status) - else - @printf("%c: CLLS_solve exit status = %1i\n", st, inform.status) - end + return 0 +end - # @printf("x: ") - # for i = 1:n - # @printf("%f ", x[i]) - # end - # @printf("\n") - # @printf("gradient: ") - # for i = 1:n - # @printf("%f ", g[i]) - # end - # @printf("\n") - - # Delete internal workspace - clls_terminate( data, control, inform ) +@testset "CLLS" begin + @test test_clls() == 0 end diff --git a/GALAHAD.jl/test/test_presolve.jl b/GALAHAD.jl/test/test_presolve.jl index 1caf4a68a5..44a0d08f61 100644 --- a/GALAHAD.jl/test/test_presolve.jl +++ b/GALAHAD.jl/test/test_presolve.jl @@ -2,182 +2,209 @@ # Simple code to test the Julia interface to PRESOLVE using GALAHAD +using Test using Printf - -# Derived types -data = [Ptr{Ptr{Cvoid}}()] -control = presolve_control_type{Float64}() -inform = presolve_inform_type{Float64}() - -# Set problem data -n = 6 # dimension -m = 5 # number of general constraints -H_ne = 1 # Hesssian elements -H_row = Cint[1] # row indices, NB lower triangle -H_col = Cint[1] # column indices, NB lower triangle -H_ptr = Cint[1, 2, 2, 2, 2, 2, 2] # row pointers -H_val = Float64[1.0] # values -g = Float64[1.0, 1.0, 1.0, 1.0, 1.0, 1.0] # linear term in the objective -f = 1.0 # constant term in the objective -A_ne = 8 # Jacobian elements -A_row = Cint[3, 3, 3, 4, 4, 5, 5, 5] # row indices -A_col = Cint[3, 4, 5, 3, 6, 4, 5, 6] # column indices -A_ptr = Cint[1, 1, 1, 4, 6, 9] # row pointers -A_val = Float64[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] # values -c_l = Float64[ 0.0, 0.0, 2.0, 1.0, 3.0] # constraint lower bound -c_u = Float64[1.0, 1.0, 3.0, 3.0, 3.0] # constraint upper bound -x_l = Float64[-3.0, 0.0, 0.0, 0.0, 0.0, 0.0] # variable lower bound -x_u = Float64[3.0, 1.0, 1.0, 1.0, 1.0, 1.0] # variable upper bound - -# Set output storage -st = ' ' -status = Ref{Cint}() - -@printf(" Fortran sparse matrix indexing\n\n") -@printf(" basic tests of qp storage formats\n\n") - -for d = 1:7 - # Initialize PRESOLVE - presolve_initialize( data, control, status ) - - # Set user-defined control options - control.f_indexing = true # Fortran sparse matrix indexing - - # sparse co-ordinate storage - if d == 1 - global st = 'C' - - presolve_import_problem( control, data, status, n, m, - "coordinate", H_ne, H_row, H_col, Cint[], H_val, g, f, - "coordinate", A_ne, A_row, A_col, Cint[], A_val, - c_l, c_u, x_l, x_u, n_trans, m_trans, H_ne_trans, A_ne_trans ) - end - - # sparse by rows - if d == 2 - global st = 'R' - - presolve_import_problem( control, data, status, n, m, - "sparse_by_rows", H_ne, Cint[], H_col, H_ptr, H_val, g, f, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr, A_val, - c_l, c_u, x_l, x_u, n_trans, m_trans, H_ne_trans, A_ne_trans ) - end - - # dense - if d == 3 - global st = 'D' - H_dense_ne = n*(n+1)/2 # number of elements of H - A_dense_ne = m*n # number of elements of A - H_dense = Float64[1.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.0, 0.0, 0.0, 0.0, 0.0] - A_dense = Float64[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, 1.0, 1.0, 1.0, 0.0, - 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, - 0.0, 0.0, 0.0, 1.0, 1.0, 1.0] - - presolve_import_problem( control, data, status, n, m, - "dense", H_dense_ne, Cint[], Cint[], Cint[], H_dense, g, f, - "dense", A_dense_ne, Cint[], Cint[], Cint[], A_dense, - c_l, c_u, x_l, x_u, n_trans, m_trans, H_ne_trans, A_ne_trans ) - end - - # diagonal - if d == 4 - global st = 'L' - - presolve_import_problem( control, data, status, n, m, - "diagonal", n, Cint[], Cint[], Cint[], H_val, g, f, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr, A_val, - c_l, c_u, x_l, x_u, n_trans, m_trans, H_ne_trans, A_ne_trans ) - end - - # scaled identity - if d == 5 - global st = 'S' - - presolve_import_problem( control, data, status, n, m, - "scaled_identity", 1, Cint[], Cint[], Cint[], H_val, g, f, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr, A_val, - c_l, c_u, x_l, x_u, n_trans, m_trans, H_ne_trans, A_ne_trans ) - end - - # identity - if d == 6 - global st = 'I' - - presolve_import_problem( control, data, status, n, m, - "identity", 0, Cint[], Cint[], Cint[], Cint[], g, f, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr, A_val, - c_l, c_u, x_l, x_u, n_trans, m_trans, H_ne_trans, A_ne_trans ) +using Accessors + +function test_presolve() + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{presolve_control_type{Float64}}() + inform = Ref{presolve_inform_type}() + + # Set problem data + n = 6 # dimension + m = 5 # number of general constraints + H_ne = 1 # Hesssian elements + H_row = Cint[1] # row indices, NB lower triangle + H_col = Cint[1] # column indices, NB lower triangle + H_ptr = Cint[1, 2, 2, 2, 2, 2, 2] # row pointers + H_val = Float64[1.0] # values + g = Float64[1.0, 1.0, 1.0, 1.0, 1.0, 1.0] # linear term in the objective + f = 1.0 # constant term in the objective + A_ne = 8 # Jacobian elements + A_row = Cint[3, 3, 3, 4, 4, 5, 5, 5] # row indices + A_col = Cint[3, 4, 5, 3, 6, 4, 5, 6] # column indices + A_ptr = Cint[1, 1, 1, 4, 6, 9] # row pointers + A_val = Float64[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] # values + c_l = Float64[0.0, 0.0, 2.0, 1.0, 3.0] # constraint lower bound + c_u = Float64[1.0, 1.0, 3.0, 3.0, 3.0] # constraint upper bound + x_l = Float64[-3.0, 0.0, 0.0, 0.0, 0.0, 0.0] # variable lower bound + x_u = Float64[3.0, 1.0, 1.0, 1.0, 1.0, 1.0] # variable upper bound + + # Set output storage + st = ' ' + status = Ref{Cint}() + + @printf(" Fortran sparse matrix indexing\n\n") + @printf(" basic tests of qp storage formats\n\n") + for d in 1:7 + n_trans = Ref{Cint}() + m_trans = Ref{Cint}() + H_ne_trans = Ref{Cint}() + A_ne_trans = Ref{Cint}() + + # Initialize PRESOLVE + presolve_initialize(data, control, status) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + + # sparse co-ordinate storage + if d == 1 + st = 'C' + presolve_import_problem(control, data, status, n, m, + "coordinate", H_ne, H_row, H_col, Cint[], H_val, g, f, + "coordinate", A_ne, A_row, A_col, Cint[], A_val, + c_l, c_u, x_l, x_u, + n_trans, m_trans, H_ne_trans, A_ne_trans) + end + + # sparse by rows + if d == 2 + st = 'R' + presolve_import_problem(control, data, status, n, m, + "sparse_by_rows", H_ne, Cint[], H_col, H_ptr, H_val, g, f, + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr, A_val, + c_l, c_u, x_l, x_u, + n_trans, m_trans, H_ne_trans, A_ne_trans) + end + + # dense + if d == 3 + st = 'D' + H_dense_ne = div(n * (n + 1), 2) # number of elements of H + A_dense_ne = m * n # number of elements of A + H_dense = Float64[1.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.0, 0.0, 0.0, 0.0, 0.0] + A_dense = Float64[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, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, + 0.0, 1.0, 1.0, 1.0] + presolve_import_problem(control, data, status, n, m, + "dense", H_dense_ne, Cint[], Cint[], Cint[], H_dense, g, + f, "dense", A_dense_ne, Cint[], Cint[], Cint[], A_dense, + c_l, c_u, x_l, x_u, + n_trans, m_trans, H_ne_trans, A_ne_trans) + end + + # diagonal + if d == 4 + st = 'L' + presolve_import_problem(control, data, status, n, m, + "diagonal", n, Cint[], Cint[], Cint[], H_val, g, f, + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr, A_val, + c_l, c_u, x_l, x_u, + n_trans, m_trans, H_ne_trans, A_ne_trans) + end + + # scaled identity + if d == 5 + st = 'S' + presolve_import_problem(control, data, status, n, m, + "scaled_identity", 1, Cint[], Cint[], Cint[], H_val, g, f, + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr, A_val, + c_l, c_u, x_l, x_u, + n_trans, m_trans, H_ne_trans, A_ne_trans) + end + + # identity + if d == 6 + st = 'I' + presolve_import_problem(control, data, status, n, m, + "identity", 0, Cint[], Cint[], Cint[], Cint[], g, f, + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr, A_val, + c_l, c_u, x_l, x_u, + n_trans, m_trans, H_ne_trans, A_ne_trans) + end + + # zero + if d == 7 + st = 'Z' + presolve_import_problem(control, data, status, n, m, + "zero", 0, Cint[], Cint[], Cint[], Cint[], g, f, + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr, A_val, + c_l, c_u, x_l, x_u, + n_trans, m_trans, H_ne_trans, A_ne_trans) + end + + # @printf("%c: n, m, h_ne, a_ne = %2i, %2i, %2i, %2i\n", st, n_trans, m_trans, H_ne_trans, A_ne_trans) + f_trans = Ref{Float64}() # transformed constant term in the objective + H_ptr_trans = zeros(Cint, n_trans[] + 1) # transformed Hessian row pointers + H_col_trans = zeros(Cint, H_ne_trans[]) # transformed Hessian column indices + H_val_trans = zeros(Float64, H_ne_trans[]) # transformed Hessian values + g_trans = zeros(Float64, n_trans[]) # transformed gradient + A_ptr_trans = zeros(Cint, m_trans[] + 1) # transformed Jacobian row pointers + A_col_trans = zeros(Cint, A_ne_trans[]) # transformed Jacobian column indices + A_val_trans = zeros(Float64, A_ne_trans[]) # transformed Jacobian values + x_l_trans = zeros(Float64, n_trans[]) # transformed lower variable bounds + x_u_trans = zeros(Float64, n_trans[]) # transformed upper variable bounds + c_l_trans = zeros(Float64, m_trans[]) # transformed lower constraint bounds + c_u_trans = zeros(Float64, m_trans[]) # transformed upper constraint bounds + y_l_trans = zeros(Float64, m_trans[]) # transformed lower multiplier bounds + y_u_trans = zeros(Float64, m_trans[]) # transformed upper multiplier bounds + z_l_trans = zeros(Float64, n_trans[]) # transformed lower dual variable bounds + z_u_trans = zeros(Float64, n_trans[]) # transformed upper dual variable bounds + + presolve_transform_problem(data, status, n_trans[], m_trans[], + H_ne_trans[], H_col_trans, H_ptr_trans, + H_val_trans, g_trans, f_trans, A_ne_trans[], + A_col_trans, A_ptr_trans, A_val_trans, + c_l_trans, c_u_trans, x_l_trans, x_u_trans, + y_l_trans, y_u_trans, z_l_trans, z_u_trans) + + x_trans = zeros(Float64, n_trans[]) # transformed variables + for i in 1:n_trans[] + x_trans[i] = 0.0 + end + c_trans = zeros(Float64, m_trans[]) # transformed constraints + for i in 1:n_trans[] + c_trans[i] = 0.0 + end + y_trans = zeros(Float64, m_trans[]) # transformed Lagrange multipliers + for i in 1:n_trans[] + y_trans[i] = 0.0 + end + z_trans = zeros(Float64, n_trans[]) # transformed dual variables + for i in 1:n_trans[] + z_trans[i] = 0.0 + end + + x = zeros(Float64, n) # primal variables + c = zeros(Float64, m) # constraint values + y = zeros(Float64, m) # Lagrange multipliers + z = zeros(Float64, n) # dual variables + + # @printf("%c: n_trans, m_trans, n, m = %2i, %2i, %2i, %2i\n", st, n_trans, m_trans, n, m) + presolve_restore_solution(data, status, n_trans[], m_trans[], + x_trans, c_trans, y_trans, z_trans, n, m, x, c, y, z) + + presolve_information(data, inform, status) + + if inform[].status == 0 + @printf("%c:%6i transformations, n, m = %2i, %2i, status = %1i\n", st, + inform[].nbr_transforms, n_trans[], m_trans[], inform[].status) + else + @printf("%c: PRESOLVE_solve exit status = %1i\n", st, inform[].status) + end + + # @printf("x: ") + # for i = 1:n + # @printf("%f ", x[i]) + # end + # @printf("\n") + # @printf("gradient: ") + # for i = 1:n + # @printf("%f ", g[i]) + # end + # @printf("\n") + + # Delete internal workspace + presolve_terminate(data, control, inform) end - # zero - if d == 7 - global st = 'Z' - - presolve_import_problem( control, data, status, n, m, - "zero", 0, Cint[], Cint[], Cint[], Cint[], g, f, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr, A_val, - c_l, c_u, x_l, x_u, n_trans, m_trans, H_ne_trans, A_ne_trans ) - end - - # @printf("%c: n, m, h_ne, a_ne = %2i, %2i, %2i, %2i\n", st, n_trans, m_trans, H_ne_trans, A_ne_trans) - f_trans = Ref{Float64}() # transformed constant term in the objective - H_ptr_trans = zeros(Cint, n_trans+1) # transformed Hessian row pointers - H_col_trans = zeros(Cint, H_ne_trans) # transformed Hessian column indices - H_val_trans = zeros(Float64, H_ne_trans) # transformed Hessian values - g_trans = zeros(Float64, n_trans) # transformed gradient - A_ptr_trans = zeros(Cint, m_trans+1) # transformed Jacobian row pointers - A_col_trans = zeros(Cint, A_ne_trans) # transformed Jacobian column indices - A_val_trans = zeros(Float64, A_ne_trans) # transformed Jacobian values - x_l_trans = zeros(Float64, n_trans) # transformed lower variable bounds - x_u_trans = zeros(Float64, n_trans) # transformed upper variable bounds - c_l_trans = zeros(Float64, m_trans) # transformed lower constraint bounds - c_u_trans = zeros(Float64, m_trans) # transformed upper constraint bounds - y_l_trans = zeros(Float64, m_trans) # transformed lower multiplier bounds - y_u_trans = zeros(Float64, m_trans) # transformed upper multiplier bounds - z_l_trans = zeros(Float64, n_trans) # transformed lower dual variable bounds - z_u_trans = zeros(Float64, n_trans) # transformed upper dual variable bounds - - presolve_transform_problem( data, status, n_trans, m_trans, - H_ne_trans, H_col_trans, H_ptr_trans, - H_val_trans, g_trans, f_trans, A_ne_trans, - A_col_trans, A_ptr_trans, A_val_trans, - c_l_trans, c_u_trans, x_l_trans, x_u_trans, - y_l_trans, y_u_trans, z_l_trans, z_u_trans ) - - x_trans = zeros(Float64, n_trans) # transformed variables - c_trans = zeros(Float64, m_trans) # transformed constraints - y_trans = zeros(Float64, m_trans) # transformed Lagrange multipliers - z_trans = zeros(Float64, n_trans) # transformed dual variables - - x = zeros(Float64, n) # primal variables - c = zeros(Float64, m) # constraint values - y = zeros(Float64, m) # Lagrange multipliers - z = zeros(Float64, n) # dual variables - - # @printf("%c: n_trans, m_trans, n, m = %2i, %2i, %2i, %2i\n", st, n_trans, m_trans, n, m ) - presolve_restore_solution( data, status, n_trans, m_trans, x_trans, c_trans, y_trans, z_trans, n, m, x, c, y, z ) - - presolve_information( data, inform, status ) - - if inform.status == 0 - @printf("%c:%6i transformations, n, m = %2i, %2i, status = %1i\n", st, inform.nbr_transforms, n_trans, m_trans, inform.status) - else - @printf("%c: PRESOLVE_solve exit status = %1i\n", st, inform.status) - end + return 0 +end - # @printf("x: ") - # for i = 1:n - # @printf("%f ", x[i]) - # end - # @printf("\n") - # @printf("gradient: ") - # for i = 1:n - # @printf("%f ", g[i]) - # end - # @printf("\n") - - # Delete internal workspace - presolve_terminate( data, control, inform ) +@testset "PRESOLVE" begin + @test test_presolve() == 0 end From ea461b29bab6a4351e30090704a65b0b944c69bd Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Tue, 6 Feb 2024 23:32:50 -0500 Subject: [PATCH 14/33] wip --- GALAHAD.jl/gen/README.md | 17 + GALAHAD.jl/gen/examples.jl | 17 +- GALAHAD.jl/test/runtests.jl | 18 +- GALAHAD.jl/test/test_bgo.jl | 687 +++++++++++++++++++++++++++++++++++ GALAHAD.jl/test/test_cqp.jl | 425 +++++++++++----------- GALAHAD.jl/test/test_cro.jl | 131 ++++--- GALAHAD.jl/test/test_llst.jl | 2 +- GALAHAD.jl/test/test_nls.jl | 620 +++++++++++++++++++++++++++++++ GALAHAD.jl/test/test_qpa.jl | 401 ++++++++++---------- GALAHAD.jl/test/test_qpb.jl | 328 ++++++++--------- GALAHAD.jl/test/test_rqs.jl | 252 +++++++++++++ GALAHAD.jl/test/test_slls.jl | 353 ++++++++++++++++++ GALAHAD.jl/test/test_trs.jl | 428 +++++++++++----------- GALAHAD.jl/test/test_tru.jl | 404 ++++++++++++++++++++ GALAHAD.jl/test/test_uls.jl | 291 ++++++++------- 15 files changed, 3392 insertions(+), 982 deletions(-) diff --git a/GALAHAD.jl/gen/README.md b/GALAHAD.jl/gen/README.md index 95bb08c081..2766aae9d2 100644 --- a/GALAHAD.jl/gen/README.md +++ b/GALAHAD.jl/gen/README.md @@ -108,3 +108,20 @@ include("wrappers/abcd.jl") Now, the Julia wrappers for the `abcd` package are accessible upon loading the Julia interface with `using GALAHAD`. + +# Tests + +The file `examples.jl` help to generate Julia tests based on the C tests of a GALAHAD package. +- Create symbolic link +- Explain "tf", "t" or "" +- Call clean_example(...) + +```julia +(name == "abcd") && examples("abcd", "tf") +``` + +To test the new package named `abcd`, insert the following line in `GALAHAD.jl/test/runtests.jl`: + +```julia +include("test_abcd.jl") +``` diff --git a/GALAHAD.jl/gen/examples.jl b/GALAHAD.jl/gen/examples.jl index fbaa3bab35..50a564cf01 100644 --- a/GALAHAD.jl/gen/examples.jl +++ b/GALAHAD.jl/gen/examples.jl @@ -38,25 +38,28 @@ function examples(package::String, example::String) text = replace(text, "} #" => "] #") 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") + "C_dense", "H_diag", "C_diag", "H_scid", "C_scid", "Ao_val", "r", "M_val", "M_dense", + "M_diag", "y", "W") text = replace(text, "real_wp_ $var[] = {" => "$var = Float64[") end - for var in ("f", "power", "weight", "shift", "radius", "half_radius", "x_l", "x_u", "sigma") + for var in ("f", "power", "weight", "shift", "radius", "half_radius", "x_l", "x_u", "sigma", "rho_g", "rho_b") 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") + "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, "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") + "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, "int $var[] = {" => "$var = Cint[") end for val in ("1", "3", "5", "6", "7", "n", "n+m") 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") + for index in ("unit_m", "new_radius", "a_is", "m_is") 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 @@ -109,6 +112,10 @@ function examples(package::String, example::String) text = replace(text, "switch(d)\n" => "") text = replace(text, "for(i=0 i "for i = 1:n\n") text = replace(text, "}\n" => "end\n") + for var in ("x", "u", "v", "hval", "g") + 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) (example == "") && clean_example(package) diff --git a/GALAHAD.jl/test/runtests.jl b/GALAHAD.jl/test/runtests.jl index 57f73d371b..4440d1e2eb 100644 --- a/GALAHAD.jl/test/runtests.jl +++ b/GALAHAD.jl/test/runtests.jl @@ -13,8 +13,8 @@ include("test_bsc.jl") include("test_ccqp.jl") include("test_clls.jl") include("test_convert.jl") -# include("test_cqp.jl") -# include("test_cro.jl") +include("test_cqp.jl") +include("test_cro.jl") # include("test_dgo.jl") include("test_dps.jl") # include("test_dqp.jl") @@ -36,11 +36,11 @@ include("test_lpb.jl") include("test_lsqp.jl") include("test_lsrt.jl") include("test_lstr.jl") -# include("test_nls.jl") +## include("test_nls.jl") include("test_presolve.jl") include("test_psls.jl") -# include("test_qpa.jl") -# include("test_qpb.jl") +include("test_qpa.jl") +include("test_qpb.jl") include("test_roots.jl") # include("test_rpd.jl") # include("test_rqs.jl") @@ -49,11 +49,11 @@ include("test_sbls.jl") include("test_sec.jl") include("test_sha.jl") include("test_sils.jl") -# include("test_slls.jl") +## include("test_slls.jl") include("test_sls.jl") # include("test_trb.jl") -# include("test_trs.jl") -# include("test_tru.jl") +## include("test_trs.jl") +## include("test_tru.jl") include("test_ugo.jl") -# include("test_uls.jl") +include("test_uls.jl") include("test_wcp.jl") diff --git a/GALAHAD.jl/test/test_bgo.jl b/GALAHAD.jl/test/test_bgo.jl index e69de29bb2..6b633b7be6 100644 --- a/GALAHAD.jl/test/test_bgo.jl +++ b/GALAHAD.jl/test/test_bgo.jl @@ -0,0 +1,687 @@ +/* bgot2.c */ +/* Full test for the BGO C interface using Fortran sparse matrix indexing */ + +#include +#include +#include "galahad_precision.h" +#include "galahad_cfunctions.h" +#include "galahad_bgo.h" + +# Custom userdata struct +struct userdata_type { + real_wp_ p + real_wp_ freq + real_wp_ mag +] + +# Function prototypes +int fun(int n, const real_wp_ x[], real_wp_ *f, const void *) +int grad(int n, const real_wp_ x[], real_wp_ g[], const void *) +int hess(int n, int ne, const real_wp_ x[], real_wp_ hval[], const void *) +int hess_dense(int n, int ne, const real_wp_ x[], real_wp_ hval[], +const void *) +int hessprod(int n, const real_wp_ x[], real_wp_ u[], const real_wp_ v[], + bool got_h, const void *) +int shessprod(int n, const real_wp_ x[], int nnz_v, const int index_nz_v[], + const real_wp_ v[], int *nnz_u, int index_nz_u[], real_wp_ u[], + bool got_h, const void *) +int prec(int n, const real_wp_ x[], real_wp_ u[], const real_wp_ v[], + const void *) +int fun_diag(int n, const real_wp_ x[], real_wp_ *f, const void *) +int grad_diag(int n, const real_wp_ x[], real_wp_ g[], const void *) +int hess_diag(int n, int ne, const real_wp_ x[], real_wp_ hval[], + const void *) +int hessprod_diag(int n, const real_wp_ x[], real_wp_ u[], const real_wp_ v[], + bool got_h, const void *) +int shessprod_diag(int n, const real_wp_ x[], int nnz_v, +const int index_nz_v[], +const real_wp_ v[], int *nnz_u, int index_nz_u[], +real_wp_ u[], bool got_h, const void *) + +# test_bgo.jl +# Simple code to test the Julia interface to BGO + +using GALAHAD +using Test +using Printf +using Accessors + +function test_bgo() +# Derived types +data = Ref{Ptr{Cvoid}}() +control = Ref{bgo_control_type{Float64}}() +inform = Ref{bgo_inform_type{Float64}}() + +# Set user data +struct userdata_type userdata +userdata.p = 4.0 +userdata.freq = 10 +userdata.mag = 1000 + +# Set problem data +n = 3 # dimension +ne = 5 # Hesssian elements +x_l = Float64[-10,-10,-10] +x_u = Float64[0.5,0.5,0.5] +H_row = Cint[1, 2, 3, 3, 3] # Hessian H +H_col = Cint[1, 2, 1, 2, 3] # NB lower triangle +H_ptr = Cint[1, 2, 3, 6] # row pointers + +# Set storage +g = zeros(Float64, n) # gradient +st = ' ' +status = Ref{Cint}() + +@printf(" Fortran sparse matrix indexing\n\n") + +@printf(" tests options for all-in-one storage format\n\n") + +for(int d=1 d <= 5 d++) + +# Initialize BGO +bgo_initialize(data, control, status) + +# Set user-defined control options +control[].f_indexing = true # Fortran sparse matrix indexing +control[].attempts_max = 10000 +control[].max_evals = 20000 +control[].sampling_strategy = 3 +control[].trb_control[].maxit = 100 +#control[].print_level = 1 + +# Start from 0 +x = Float64[0,0,0] + +switch(d) +# sparse co-ordinate storage +if d == 1 +st = 'C' +bgo_import(control, data, status, n, x_l, x_u, +"coordinate", ne, H_row, H_col, Cint[]) +bgo_solve_with_mat(data, userdata, status, n, x, g, +ne, fun, grad, hess, hessprod, prec) +end +# sparse by rows +if d == 2 +st = 'R' +bgo_import(control, data, status, n, x_l, x_u, +"sparse_by_rows", ne, Cint[], H_col, H_ptr) +bgo_solve_with_mat(data, userdata, status, n, x, g, +ne, fun, grad, hess, hessprod, prec) +end +# dense +if d == 3 +st = 'D' +bgo_import(control, data, status, n, x_l, x_u, +"dense", ne, Cint[], Cint[], Cint[]) +bgo_solve_with_mat(data, userdata, status, n, x, g, +ne, fun, grad, hess_dense, hessprod, prec) +end +# diagonal +if d == 4 +st = 'I' +bgo_import(control, data, status, n, x_l, x_u, +"diagonal", ne, Cint[], Cint[], Cint[]) +bgo_solve_with_mat(data, userdata, status, n, x, g, +ne, fun_diag, grad_diag, hess_diag, +hessprod_diag, prec) +end +case 5: # access by products +st = 'P' +bgo_import(control, data, status, n, x_l, x_u, +"absent", ne, Cint[], Cint[], Cint[]) +bgo_solve_without_mat(data, userdata, status, n, x, g, + fun, grad, hessprod, shessprod, prec) +end +] + +# Record solution information +bgo_information(data, inform, status) + +if inform[].status == 0 +@printf("%c:%6i evaluations. Optimal objective value = %5.2f" + " status = %1i\n", st, inform[].f_eval, inform[].obj, inform[].status) +else +@printf("%c: BGO_solve exit status = %1i\n", st, inform[].status) + +# @printf("x: ") +# for(int i = 0 i < n i++) @printf("%f ", x[i]) +# @printf("\n") +# @printf("gradient: ") +# for(int i = 0 i < n i++) @printf("%f ", g[i]) +# @printf("\n") + +# Delete internal workspace +bgo_terminate(data, control, inform) +@printf("\n tests reverse-communication options\n\n") + +# reverse-communication input/output +int eval_status, nnz_u, nnz_v +f = 0.0 +u = zeros(Float64, n), v[n] +index_nz_u = zeros(Cint, n), index_nz_v[n] +real_wp_ H_val[ne], H_dense[n*(n+1)/2], H_diag[n] + +for(int d=1 d <= 5 d++) + +# Initialize BGO +bgo_initialize(data, control, status) + +# Set user-defined control options +control[].f_indexing = true # Fortran sparse matrix indexing +control[].attempts_max = 10000 +control[].max_evals = 20000 +control[].sampling_strategy = 3 +control[].trb_control[].maxit = 100 +#control[].print_level = 1 + +# Start from 0 +x = Float64[0,0,0] + +switch(d) +# sparse co-ordinate storage +if d == 1 +st = 'C' +bgo_import(control, data, status, n, x_l, x_u, +"coordinate", ne, H_row, H_col, Cint[]) +while true # reverse-communication loop +bgo_solve_reverse_with_mat(data, status, eval_status, +n, x, f, g, ne, H_val, u, v) +if status == 0 # successful termination +end +}elseif status < 0) # error exit +end +}elseif status == 2) # evaluate f +eval_status = fun(n, x, f, userdata) +elseif status == 3) # evaluate g +eval_status = grad(n, x, g, userdata) +elseif status == 4) # evaluate H +eval_status = hess(n, ne, x, H_val, userdata) +elseif status == 5) # evaluate Hv product +eval_status = hessprod(n, x, u, v, false, userdata) +elseif status == 6) # evaluate the product with P +eval_status = prec(n, x, u, v, userdata) +elseif status == 23) # evaluate f and g +eval_status = fun(n, x, f, userdata) +eval_status = grad(n, x, g, userdata) +elseif status == 25) # evaluate f and Hv product +eval_status = fun(n, x, f, userdata) +eval_status = hessprod(n, x, u, v, false, userdata) +elseif status == 35) # evaluate g and Hv product +eval_status = grad(n, x, g, userdata) +eval_status = hessprod(n, x, u, v, false, userdata) +elseif status == 235) # evaluate f, g and Hv product +eval_status = fun(n, x, f, userdata) +eval_status = grad(n, x, g, userdata) +eval_status = hessprod(n, x, u, v, false, userdata) +else +@printf(" the value %1i of status should not occur\n", + status) +end +] +] +end +# sparse by rows +if d == 2 +st = 'R' +bgo_import(control, data, status, n, x_l, x_u, +"sparse_by_rows", ne, Cint[], H_col, H_ptr) +while true # reverse-communication loop +bgo_solve_reverse_with_mat(data, status, eval_status, +n, x, f, g, ne, H_val, u, v) +if status == 0 # successful termination +end +}elseif status < 0) # error exit +end +}elseif status == 2) # evaluate f +eval_status = fun(n, x, f, userdata) +elseif status == 3) # evaluate g +eval_status = grad(n, x, g, userdata) +elseif status == 4) # evaluate H +eval_status = hess(n, ne, x, H_val, userdata) +elseif status == 5) # evaluate Hv product +eval_status = hessprod(n, x, u, v, false, userdata) +elseif status == 6) # evaluate the product with P +eval_status = prec(n, x, u, v, userdata) +elseif status == 23) # evaluate f and g +eval_status = fun(n, x, f, userdata) +eval_status = grad(n, x, g, userdata) +elseif status == 25) # evaluate f and Hv product +eval_status = fun(n, x, f, userdata) +eval_status = hessprod(n, x, u, v, false, userdata) +elseif status == 35) # evaluate g and Hv product +eval_status = grad(n, x, g, userdata) +eval_status = hessprod(n, x, u, v, false, userdata) +elseif status == 235) # evaluate f, g and Hv product +eval_status = fun(n, x, f, userdata) +eval_status = grad(n, x, g, userdata) +eval_status = hessprod(n, x, u, v, false, userdata) +else +@printf(" the value %1i of status should not occur\n", + status) +end +] +] +end +# dense +if d == 3 +st = 'D' +bgo_import(control, data, status, n, x_l, x_u, +"dense", ne, Cint[], Cint[], Cint[]) +while true # reverse-communication loop +bgo_solve_reverse_with_mat(data, status, eval_status, +n, x, f, g, n*(n+1)/2, +H_dense, u, v) +if status == 0 # successful termination +end +}elseif status < 0) # error exit +end +}elseif status == 2) # evaluate f +eval_status = fun(n, x, f, userdata) +elseif status == 3) # evaluate g +eval_status = grad(n, x, g, userdata) +elseif status == 4) # evaluate H +eval_status = hess_dense(n, n*(n+1)/2, x, H_dense, + userdata) +elseif status == 5) # evaluate Hv product +eval_status = hessprod(n, x, u, v, false, userdata) +elseif status == 6) # evaluate the product with P +eval_status = prec(n, x, u, v, userdata) +elseif status == 23) # evaluate f and g +eval_status = fun(n, x, f, userdata) +eval_status = grad(n, x, g, userdata) +elseif status == 25) # evaluate f and Hv product +eval_status = fun(n, x, f, userdata) +eval_status = hessprod(n, x, u, v, false, userdata) +elseif status == 35) # evaluate g and Hv product +eval_status = grad(n, x, g, userdata) +eval_status = hessprod(n, x, u, v, false, userdata) +elseif status == 235) # evaluate f, g and Hv product +eval_status = fun(n, x, f, userdata) +eval_status = grad(n, x, g, userdata) +eval_status = hessprod(n, x, u, v, false, userdata) +else +@printf(" the value %1i of status should not occur\n", + status) +end +] +] +end +# diagonal +if d == 4 +st = 'I' +bgo_import(control, data, status, n, x_l, x_u, +"diagonal", ne, Cint[], Cint[], Cint[]) +while true # reverse-communication loop +bgo_solve_reverse_with_mat(data, status, eval_status, +n, x, f, g, n, H_diag, u, v) +if status == 0 # successful termination +end +}elseif status < 0) # error exit +end +}elseif status == 2) # evaluate f +eval_status = fun_diag(n, x, f, userdata) +elseif status == 3) # evaluate g +eval_status = grad_diag(n, x, g, userdata) +elseif status == 4) # evaluate H +eval_status = hess_diag(n, n, x, H_diag, userdata) +elseif status == 5) # evaluate Hv product +eval_status = hessprod_diag(n, x, u, v, false, + userdata) +elseif status == 6) # evaluate the product with P +eval_status = prec(n, x, u, v, userdata) +elseif status == 23) # evaluate f and g +eval_status = fun_diag(n, x, f, userdata) +eval_status = grad_diag(n, x, g, userdata) +elseif status == 25) # evaluate f and Hv product +eval_status = fun_diag(n, x, f, userdata) +eval_status = hessprod_diag(n, x, u, v, false, + userdata) +elseif status == 35) # evaluate g and Hv product +eval_status = grad_diag(n, x, g, userdata) +eval_status = hessprod_diag(n, x, u, v, false, + userdata) +elseif status == 235) # evaluate f, g and Hv product +eval_status = fun_diag(n, x, f, userdata) +eval_status = grad_diag(n, x, g, userdata) +eval_status = hessprod_diag(n, x, u, v, false, + userdata) +else +@printf(" the value %1i of status should not occur\n", + status) +end +] +] +end +case 5: # access by products +st = 'P' +bgo_import(control, data, status, n, x_l, x_u, +"absent", ne, Cint[], Cint[], Cint[]) +nnz_u = 0 +while true # reverse-communication loop +bgo_solve_reverse_without_mat(data, status, eval_status, + n, x, f, g, u, v, index_nz_v, + nnz_v, index_nz_u, nnz_u) +if status == 0 # successful termination +end +}elseif status < 0) # error exit +end +}elseif status == 2) # evaluate f +eval_status = fun(n, x, f, userdata) +elseif status == 3) # evaluate g +eval_status = grad(n, x, g, userdata) +elseif status == 5) # evaluate Hv product +eval_status = hessprod(n, x, u, v, false, userdata) +elseif status == 6) # evaluate the product with P +eval_status = prec(n, x, u, v, userdata) +elseif status == 7) # evaluate sparse Hess-vect product +eval_status = shessprod(n, x, nnz_v, index_nz_v, v, + nnz_u, index_nz_u, u, + false, userdata) +elseif status == 23) # evaluate f and g +eval_status = fun(n, x, f, userdata) +eval_status = grad(n, x, g, userdata) +elseif status == 25) # evaluate f and Hv product +eval_status = fun(n, x, f, userdata) +eval_status = hessprod(n, x, u, v, false, userdata) +elseif status == 35) # evaluate g and Hv product +eval_status = grad(n, x, g, userdata) +eval_status = hessprod(n, x, u, v, false, userdata) +elseif status == 235) # evaluate f, g and Hv product +eval_status = fun(n, x, f, userdata) +eval_status = grad(n, x, g, userdata) +eval_status = hessprod(n, x, u, v, false, userdata) +else +@printf(" the value %1i of status should not occur\n", + status) +end +] +] +end +] + +# Record solution information +bgo_information(data, inform, status) + +if inform[].status == 0 +@printf("%c:%6i evaluations. Optimal objective value = %5.2f" + " status = %1i\n", st, inform[].f_eval, inform[].obj, inform[].status) +else +@printf("%c: BGO_solve exit status = %1i\n", st, inform[].status) + +# @printf("x: ") +# for(int i = 0 i < n i++) @printf("%f ", x[i]) +# @printf("\n") +# @printf("gradient: ") +# for(int i = 0 i < n i++) @printf("%f ", g[i]) +# @printf("\n") + +# Delete internal workspace +bgo_terminate(data, control, inform) +] + +# Objective function +int fun(int n, + const real_wp_ x[], + real_wp_ *f, + const void *userdata) +struct userdata_type *myuserdata = (struct userdata_type *) userdata +real_wp_ p = myuserdata->p +real_wp_ freq = myuserdata->freq +real_wp_ mag = myuserdata->mag + +*f = pow(x[0] + x[2] + p, 2) + pow(x[1] + x[2], 2) + mag * cos(freq*x[0]) + + x[0] + x[1] + x[2] +return 0 +] + +# Gradient of the objective +int grad(int n, + const real_wp_ x[], + real_wp_ g[], + const void *userdata) +struct userdata_type *myuserdata = (struct userdata_type *) userdata +real_wp_ p = myuserdata->p +real_wp_ freq = myuserdata->freq +real_wp_ mag = myuserdata->mag + +g[0] = 2.0 * (x[0] + x[2] + p) - mag * freq * sin(freq*x[0]) + 1 +g[1] = 2.0 * (x[1] + x[2]) + 1 +g[2] = 2.0 * (x[0] + x[2] + p) + 2.0 * (x[1] + x[2]) + 1 +return 0 +] + +# Hessian of the objective +int hess(int n, + int ne, + const real_wp_ x[], + real_wp_ hval[], + const void *userdata) +struct userdata_type *myuserdata = (struct userdata_type *) userdata +real_wp_ freq = myuserdata->freq +real_wp_ mag = myuserdata->mag + +hval[0] = 2.0 - mag * freq * freq * cos(freq*x[0]) +hval[1] = 2.0 +hval[2] = 2.0 +hval[3] = 2.0 +hval[4] = 4.0 +return 0 +] + +# Dense Hessian +int hess_dense(int n, +int ne, +const real_wp_ x[], +real_wp_ hval[], +const void *userdata) +struct userdata_type *myuserdata = (struct userdata_type *) userdata +real_wp_ freq = myuserdata->freq +real_wp_ mag = myuserdata->mag + +hval[0] = 2.0 - mag * freq * freq * cos(freq*x[0]) +hval[1] = 0.0 +hval[2] = 2.0 +hval[3] = 2.0 +hval[4] = 2.0 +hval[5] = 4.0 +return 0 +] + +# Hessian-vector product +int hessprod(int n, + const real_wp_ x[], + real_wp_ u[], + const real_wp_ v[], + bool got_h, + const void *userdata) +struct userdata_type *myuserdata = (struct userdata_type *) userdata +real_wp_ freq = myuserdata->freq +real_wp_ mag = myuserdata->mag + +u[0] = u[0] + 2.0 * (v[0] + v[2]) + - mag * freq * freq * cos(freq*x[0]) * v[0] +u[1] = u[1] + 2.0 * (v[1] + v[2]) +u[2] = u[2] + 2.0 * (v[0] + v[1] + 2.0 * v[2]) +return 0 +] + +# Sparse Hessian-vector product +int shessprod(int n, + const real_wp_ x[], + int nnz_v, + const int index_nz_v[], + const real_wp_ v[], + int *nnz_u, + int index_nz_u[], + real_wp_ u[], + bool got_h, + const void *userdata) +struct userdata_type *myuserdata = (struct userdata_type *) userdata +real_wp_ freq = myuserdata->freq +real_wp_ mag = myuserdata->mag + +real_wp_ p[] = {0., 0., 0.] +bool used[] = {false, false, false] +for(int i = 0 i < nnz_v i++) +int j = index_nz_v[i] +switch(j) +case 1: +p[0] = p[0] + 2.0 * v[0] + - mag * freq * freq * cos(freq*x[0]) * v[0] +used[0] = true +p[2] = p[2] + 2.0 * v[0] +used[2] = true +end +case 2: +p[1] = p[1] + 2.0 * v[1] +used[1] = true +p[2] = p[2] + 2.0 * v[1] +used[2] = true +end +case 3: +p[0] = p[0] + 2.0 * v[2] +used[0] = true +p[1] = p[1] + 2.0 * v[2] +used[1] = true +p[2] = p[2] + 4.0 * v[2] +used[2] = true +end +] +] +*nnz_u = 0 +for(int j = 0 j < 3 j++) +if used[j]) +u[j] = p[j] +*nnz_u = *nnz_u + 1 +index_nz_u[*nnz_u-1] = j+1 +] +] +return 0 +] + +# Apply preconditioner +int prec(int n, + const real_wp_ x[], + real_wp_ u[], + const real_wp_ v[], + const void *userdata) + u[0] = 0.5 * v[0] + u[1] = 0.5 * v[1] + u[2] = 0.25 * v[2] + return 0 +] + +# Objective function +int fun_diag(int n, + const real_wp_ x[], + real_wp_ *f, + const void *userdata) +struct userdata_type *myuserdata = (struct userdata_type *) userdata +real_wp_ p = myuserdata->p +real_wp_ freq = myuserdata->freq +real_wp_ mag = myuserdata->mag + +*f = pow(x[2] + p, 2) + pow(x[1], 2) + mag * cos(freq*x[0]) + + x[0] + x[1] + x[2] +return 0 +] + +# Gradient of the objective +int grad_diag(int n, + const real_wp_ x[], + real_wp_ g[], + const void *userdata) +struct userdata_type *myuserdata = (struct userdata_type *) userdata +real_wp_ p = myuserdata->p +real_wp_ freq = myuserdata->freq +real_wp_ mag = myuserdata->mag + +g[0] = -mag * freq * sin(freq*x[0]) + 1 +g[1] = 2.0 * x[1] + 1 +g[2] = 2.0 * (x[2] + p) + 1 +return 0 +] + +# Hessian of the objective +int hess_diag(int n, + int ne, + const real_wp_ x[], + real_wp_ hval[], + const void *userdata) +struct userdata_type *myuserdata = (struct userdata_type *) userdata +real_wp_ freq = myuserdata->freq +real_wp_ mag = myuserdata->mag + +hval[0] = -mag * freq * freq * cos(freq*x[0]) +hval[1] = 2.0 +hval[2] = 2.0 +return 0 +] + +# Hessian-vector product +int hessprod_diag(int n, + const real_wp_ x[], + real_wp_ u[], + const real_wp_ v[], + bool got_h, + const void *userdata) +struct userdata_type *myuserdata = (struct userdata_type *) userdata +real_wp_ freq = myuserdata->freq +real_wp_ mag = myuserdata->mag + +u[0] = u[0] + -mag * freq * freq * cos(freq*x[0]) * v[0] +u[1] = u[1] + 2.0 * v[1] +u[2] = u[2] + 2.0 * v[2] +return 0 +] + +# Sparse Hessian-vector product +int shessprod_diag(int n, +const real_wp_ x[], +int nnz_v, +const int index_nz_v[], +const real_wp_ v[], +int *nnz_u, +int index_nz_u[], +real_wp_ u[], +bool got_h, +const void *userdata) +struct userdata_type *myuserdata = (struct userdata_type *) userdata +real_wp_ freq = myuserdata->freq +real_wp_ mag = myuserdata->mag + +real_wp_ p[] = {0., 0., 0.] +bool used[] = {false, false, false] +for(int i = 0 i < nnz_v i++) +int j = index_nz_v[i] +switch(j) +case 1: +p[0] = p[0] - mag * freq * freq * cos(freq*x[0]) * v[0] +used[0] = true +end +case 2: +p[1] = p[1] + 2.0 * v[1] +used[1] = true +end +case 3: +p[2] = p[2] + 2.0 * v[2] +used[2] = true +end +] +] +*nnz_u = 0 +for(int j = 0 j < 3 j++) +if used[j]) +u[j] = p[j] +*nnz_u = *nnz_u + 1 +index_nz_u[*nnz_u-1] = j+1 +] +] +return 0 +] +end + +@testset "BGO" begin + @test test_bgo() == 0 +end diff --git a/GALAHAD.jl/test/test_cqp.jl b/GALAHAD.jl/test/test_cqp.jl index 2bd6fe9914..215489b237 100644 --- a/GALAHAD.jl/test/test_cqp.jl +++ b/GALAHAD.jl/test/test_cqp.jl @@ -2,220 +2,227 @@ # Simple code to test the Julia interface to CQP using GALAHAD +using Test using Printf - -# Derived types -data = [Ptr{Ptr{Cvoid}}()] -control = cqp_control_type{Float64}() -inform = cqp_inform_type{Float64}() - -# Set problem data -n = 3 # dimension -m = 2 # number of general constraints -H_ne = 3 # Hesssian elements -H_row = Cint[1, 2, 3] # row indices, NB lower triangle -H_col = Cint[1, 2, 3] # column indices, NB lower triangle -H_ptr = Cint[1, 2, 3, 4] # row pointers -H_val = Float64[1.0, 1.0, 1.0] # values -g = Float64[0.0, 2.0, 0.0] # linear term in the objective -f = 1.0 # constant term in the objective -A_ne = 4 # Jacobian elements -A_row = Cint[1, 1, 2, 2] # row indices -A_col = Cint[1, 2, 2, 3] # column indices -A_ptr = Cint[1, 3, 5] # row pointers -A_val = Float64[2.0, 1.0, 1.0, 1.0] # values -c_l = Float64[1.0, 2.0] # constraint lower bound -c_u = Float64[2.0, 2.0] # constraint upper bound -x_l = Float64[-1.0, -Inf, -Inf] # variable lower bound -x_u = Float64[1.0, Inf, 2.0] # variable upper bound - -# Set output storage -c = zeros(Float64, m) # constraint values -x_stat = zeros(Cint, n) # variable status -c_stat = zeros(Cint, m) # constraint status -st = ' ' -status = Ref{Cint}() - -@printf(" Fortran sparse matrix indexing\n\n") -@printf(" basic tests of qp storage formats\n\n") - -for d = 1:7 - - # Initialize CQP - cqp_initialize( data, control, status ) - - # Set user-defined control options - control.f_indexing = true # Fortran sparse matrix indexing - - # Start from 0 - x = Float64[0.0,0.0,0.0] - y = Float64[0.0,0.0] - z = Float64[0.0,0.0,0.0] - - # sparse co-ordinate storage - if d == 1 - global st = 'C' - - cqp_import( control, data, status, n, m, - "coordinate", H_ne, H_row, H_col, Cint[], - "coordinate", A_ne, A_row, A_col, Cint[] ) - - cqp_solve_qp( data, status, n, m, H_ne, H_val, g, f, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) - end - - # sparse by rows - if d == 2 - global st = 'R' - - cqp_import( control, data, status, n, m, - "sparse_by_rows", H_ne, Cint[], H_col, H_ptr, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr ) - - cqp_solve_qp( data, status, n, m, H_ne, H_val, g, f, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) - end - - # dense - if d == 3 - global st = 'D' - - H_dense_ne = 6 # number of elements of H - A_dense_ne = 6 # number of elements of A - H_dense = Float64[1.0, 0.0, 1.0, 0.0, 0.0, 1.0] - A_dense = Float64[2.0, 1.0, 0.0, 0.0, 1.0, 1.0] - - cqp_import( control, data, status, n, m, - "dense", H_ne, Cint[], Cint[], Cint[], - "dense", A_ne, Cint[], Cint[], Cint[] ) - - cqp_solve_qp( data, status, n, m, H_dense_ne, H_dense, g, f, - A_dense_ne, A_dense, c_l, c_u, x_l, x_u, - x, c, y, z, x_stat, c_stat ) - end - - # diagonal - if d == 4 - global st = 'L' - - cqp_import( control, data, status, n, m, - "diagonal", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr ) - - cqp_solve_qp( data, status, n, m, H_ne, H_val, g, f, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) - end - - # scaled identity - if d == 5 - global st = 'S' - - cqp_import( control, data, status, n, m, - "scaled_identity", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr ) - - cqp_solve_qp( data, status, n, m, H_ne, H_val, g, f, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) +using Accessors + +function test_cqp() + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{cqp_control_type{Float64}}() + inform = Ref{cqp_inform_type{Float64}}() + + # Set problem data + n = 3 # dimension + m = 2 # number of general constraints + H_ne = 3 # Hesssian elements + H_row = Cint[1, 2, 3] # row indices, NB lower triangle + H_col = Cint[1, 2, 3] # column indices, NB lower triangle + H_ptr = Cint[1, 2, 3, 4] # row pointers + H_val = Float64[1.0, 1.0, 1.0] # values + g = Float64[0.0, 2.0, 0.0] # linear term in the objective + f = 1.0 # constant term in the objective + A_ne = 4 # Jacobian elements + A_row = Cint[1, 1, 2, 2] # row indices + A_col = Cint[1, 2, 2, 3] # column indices + A_ptr = Cint[1, 3, 5] # row pointers + A_val = Float64[2.0, 1.0, 1.0, 1.0] # values + c_l = Float64[1.0, 2.0] # constraint lower bound + c_u = Float64[2.0, 2.0] # constraint upper bound + x_l = Float64[-1.0, -Inf, -Inf] # variable lower bound + x_u = Float64[1.0, Inf, 2.0] # variable upper bound + + # Set output storage + c = zeros(Float64, m) # constraint values + x_stat = zeros(Cint, n) # variable status + c_stat = zeros(Cint, m) # constraint status + st = ' ' + status = Ref{Cint}() + + @printf(" Fortran sparse matrix indexing\n\n") + @printf(" basic tests of qp storage formats\n\n") + + for d in 1:7 + # Initialize CQP + cqp_initialize(data, control, status) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + + # Start from 0 + x = Float64[0.0, 0.0, 0.0] + y = Float64[0.0, 0.0] + z = Float64[0.0, 0.0, 0.0] + + # sparse co-ordinate storage + if d == 1 + st = 'C' + cqp_import(control, data, status, n, m, + "coordinate", H_ne, H_row, H_col, Cint[], + "coordinate", A_ne, A_row, A_col, Cint[]) + + cqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + end + + # sparse by rows + if d == 2 + st = 'R' + cqp_import(control, data, status, n, m, + "sparse_by_rows", H_ne, Cint[], H_col, H_ptr, + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + + cqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + end + # dense + if d == 3 + st = 'D' + H_dense_ne = 6 # number of elements of H + A_dense_ne = 6 # number of elements of A + H_dense = Float64[1.0, 0.0, 1.0, 0.0, 0.0, 1.0] + A_dense = Float64[2.0, 1.0, 0.0, 0.0, 1.0, 1.0] + + cqp_import(control, data, status, n, m, + "dense", H_ne, Cint[], Cint[], Cint[], + "dense", A_ne, Cint[], Cint[], Cint[]) + + cqp_solve_qp(data, status, n, m, H_dense_ne, H_dense, g, f, + A_dense_ne, A_dense, c_l, c_u, x_l, x_u, + x, c, y, z, x_stat, c_stat) + end + + # diagonal + if d == 4 + st = 'L' + cqp_import(control, data, status, n, m, + "diagonal", H_ne, Cint[], Cint[], Cint[], + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + + cqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + end + + # scaled identity + if d == 5 + st = 'S' + cqp_import(control, data, status, n, m, + "scaled_identity", H_ne, Cint[], Cint[], Cint[], + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + + cqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + end + + # identity + if d == 6 + st = 'I' + cqp_import(control, data, status, n, m, + "identity", H_ne, Cint[], Cint[], Cint[], + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + + cqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + end + + # zero + if d == 7 + st = 'Z' + cqp_import(control, data, status, n, m, + "zero", H_ne, Cint[], Cint[], Cint[], + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + + cqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + end + + cqp_information(data, inform, status) + + if inform[].status == 0 + @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", + st, inform[].iter, inform[].obj, inform[].status) + else + @printf("%c: CQP_solve exit status = %1i\n", st, inform[].status) + end + + # @printf("x: ") + # for i = 1:n + # @printf("%f ", x[i]) + # end + # @printf("\n") + # @printf("gradient: ") + # for i = 1:n + # @printf("%f ", g[i]) + # end + # @printf("\n") + + # Delete internal workspace + cqp_terminate(data, control, inform) end - # identity - if d == 6 - global st = 'I' - - cqp_import( control, data, status, n, m, - "identity", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr ) - - cqp_solve_qp( data, status, n, m, H_ne, H_val, g, f, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) - end - - # zero - if d == 7 - global st = 'Z' - - cqp_import( control, data, status, n, m, - "zero", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr ) - - cqp_solve_qp( data, status, n, m, H_ne, H_val, g, f, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) - end - - cqp_information( data, inform, status ) - - if inform.status == 0 - @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", st, inform.iter, inform.obj, inform.status) - else - @printf("%c: CQP_solve exit status = %1i\n", st, inform.status) + # test shifted least-distance interface + for d in 1:1 + # Initialize CQP + cqp_initialize(data, control, status) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + + # Start from 0 + x = Float64[0.0, 0.0, 0.0] + y = Float64[0.0, 0.0] + z = Float64[0.0, 0.0, 0.0] + + # Set shifted least-distance data + + w = Float64[1.0, 1.0, 1.0] + x_0 = Float64[0.0, 0.0, 0.0] + + # sparse co-ordinate storage + if d == 1 + st = 'W' + cqp_import(control, data, status, n, m, + "shifted_least_distance", H_ne, Cint[], Cint[], Cint[], + "coordinate", A_ne, A_row, A_col, Cint[]) + + cqp_solve_sldqp(data, status, n, m, w, x_0, g, f, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + end + + cqp_information(data, inform, status) + + if inform[].status == 0 + @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", + st, inform[].iter, inform[].obj, inform[].status) + else + @printf("%c: CQP_solve exit status = %1i\n", st, inform[].status) + end + + # @printf("x: ") + # for i = 1:n + # @printf("%f ", x[i]) + # end + # @printf("\n") + # @printf("gradient: ") + # for i = 1:n + # @printf("%f ", g[i]) + # end + # @printf("\n") + + # Delete internal workspace + cqp_terminate(data, control, inform) end - # @printf("x: ") - # for i = 1:n - # @printf("%f ", x[i]) - # end - # @printf("\n") - # @printf("gradient: ") - # for i = 1:n - # @printf("%f ", g[i]) - # end - # @printf("\n") - - # Delete internal workspace - cqp_terminate( data, control, inform ) + return 0 end -# test shifted least-distance interface -# Initialize CQP -cqp_initialize( data, control, status ) - -# Set user-defined control options -control.f_indexing = true # Fortran sparse matrix indexing - -# Start from 0 -x = Float64[0.0,0.0,0.0] -y = Float64[0.0,0.0] -z = Float64[0.0,0.0,0.0] - -# Set shifted least-distance data -w = Float64[1.0,1.0,1.0] -x_0 = Float64[0.0,0.0,0.0] - -# sparse co-ordinate storage -st = 'W' - -cqp_import( control, data, status, n, m, - "shifted_least_distance", H_ne, Cint[], Cint[], Cint[], - "coordinate", A_ne, A_row, A_col, Cint[] ) - -cqp_solve_sldqp( data, status, n, m, w, x_0, g, f, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) - -cqp_information( data, inform, status ) - -if inform.status == 0 - @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", st, inform.iter, inform.obj, inform.status) -else - @printf("%c: CQP_solve exit status = %1i\n", st, inform.status) +@testset "CQP" begin + @test test_cqp() == 0 end - -# @printf("x: ") -# for i = 1:n -# @printf("%f ", x[i]) -# end -# @printf("\n") -# @printf("gradient: ") -# for i = 1:n -# @printf("%f ", g[i]) -# end -# @printf("\n") - -# Delete internal workspace -cqp_terminate( data, control, inform ) diff --git a/GALAHAD.jl/test/test_cro.jl b/GALAHAD.jl/test/test_cro.jl index abac1efb8f..ad59c7e57e 100644 --- a/GALAHAD.jl/test/test_cro.jl +++ b/GALAHAD.jl/test/test_cro.jl @@ -2,65 +2,76 @@ # Simple code to test the Julia interface to CRO using GALAHAD +using Test using Printf +using Accessors -# Derived types -data = [Ptr{Ptr{Cvoid}}()] -control = cro_control_type{Float64}() -inform = cro_inform_type{Float64}() - -# Set problem dimensions -n = 11 # dimension -m = 3 # number of general constraints -m_equal = 1 # number of equality constraints - -# describe the objective function -H_ne = 21 -H_val = Float64[1.0,0.5,1.0,0.5,1.0,0.5,1.0,0.5,1.0,0.5,1.0,0.5,1.0,0.5,1.0,0.5,1.0,0.5,1.0,0.5,1.0] -H_col = Cint[1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11] -H_ptr = Cint[1,2,4,6,8,10,12,14,16,18,20,22] -g = Float64[0.5,-0.5,-1.0,-1.0,-1.0, -1.0,-1.0,-1.0,-1.0,-1.0,-0.5] - -# describe constraints -A_ne = 30 -A_val = Float64[1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0] -A_col = Cint[1,2,3,4,5,6,7,8,9,10,11,3,4,5,6,7,8,9,10,11,2,3,4,5,6,7,8,9,10,11] -A_ptr = Cint[1,12,21,31] -c_l = Float64[10.0,9.0,-Inf] -c_u = Float64[10.0,Inf,10.0] -x_l = Float64[0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0] -x_u = Float64[Inf,Inf,Inf,Inf,Inf,Inf,Inf,Inf,Inf,Inf,Inf] - -# provide optimal variables, Lagrange multipliers and dual variables -x = Float64[0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0, 1.0,1.0,1.0] -c = Float64[10.0,9.0,10.0] -y = Float64[-1.0,1.5,-2.0] -z = Float64[2.0,4.0,2.5,2.5,2.5,2.5,2.5,2.5,2.5,2.5,2.5] - -# provide interior-point constraint and variable status -c_stat = Cint[-1,-1,1] -x_stat = Cint[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1] - -# Set output storage -status = Ref{Cint}() - -@printf(" Fortran sparse matrix indexing\n\n") - -# Initialize CRO -cro_initialize( data, control, status ) - -# Set user-defined control options -control.f_indexing = true # Fortran sparse matrix indexing - -# crossover the solution -cro_crossover_solution( data, control, inform, - n, m, m_equal, - H_ne, H_val, H_col, H_ptr, - A_ne, A_val, A_col, A_ptr, - g, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) - -@printf(" CRO_crossover exit status = %1i\n", inform.status) - -# Delete internal workspace -cro_terminate( data, control, inform ) +function test_cro() + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{cro_control_type{Float64}}() + inform = Ref{cro_inform_type{Float64}}() + + # Set problem dimensions + n = 11 # dimension + m = 3 # number of general constraints + m_equal = 1 # number of equality constraints + + # describe the objective function + + H_ne = 21 + H_val = Float64[1.0, 0.5, 1.0, 0.5, 1.0, 0.5, 1.0, 0.5, 1.0, 0.5, 1.0, 0.5, 1.0, 0.5, 1.0, + 0.5, 1.0, 0.5, 1.0, 0.5, 1.0] + H_col = Cint[1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11] + H_ptr = Cint[1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22] + g = Float64[0.5, -0.5, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -0.5] + + # describe constraints + + A_ne = 30 + A_val = Float64[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] + A_col = Cint[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 3, 4, 5, 6, 7, 8, 9, 10, 11, 2, 3, 4, 5, + 6, 7, 8, 9, 10, 11] + A_ptr = Cint[1, 12, 21, 31] + c_l = Float64[10.0, 9.0, -Inf] + c_u = Float64[10.0, Inf, 10.0] + x_l = Float64[0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] + x_u = Float64[Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf] + + # provide optimal variables, Lagrange multipliers and dual variables + x = Float64[0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] + c = Float64[10.0, 9.0, 10.0] + y = Float64[-1.0, 1.5, -2.0] + z = Float64[2.0, 4.0, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5] + + # provide interior-point constraint and variable status + c_stat = Cint[-1, -1, 1] + x_stat = Cint[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1] + + # Set output storage + status = Ref{Cint}() + @printf(" Fortran sparse matrix indexing\n\n") + + # Initialize CRO + cro_initialize(data, control, status) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + + # crossover the solution + cro_crossover_solution(data, control, inform, n, m, m_equal, H_ne, H_val, H_col, H_ptr, + A_ne, A_val, A_col, A_ptr, g, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + + @printf(" CRO_crossover exit status = %1i\n", inform[].status) + + # Delete internal workspace + cro_terminate(data, control, inform) + + return 0 +end + +@testset "CRO" begin + @test test_cro() == 0 +end diff --git a/GALAHAD.jl/test/test_llst.jl b/GALAHAD.jl/test/test_llst.jl index 0d0d597c58..4e34d13ebe 100644 --- a/GALAHAD.jl/test/test_llst.jl +++ b/GALAHAD.jl/test/test_llst.jl @@ -134,7 +134,7 @@ function test_llst() 32, 32, 32, 32, 32, 32, 32, 32, 32, 0)) - # @reset control[].print_level = 1 + # @reset control[].print_level = Cint(1) # Set user-defined control options @reset control[].f_indexing = true # Fortran sparse matrix indexing diff --git a/GALAHAD.jl/test/test_nls.jl b/GALAHAD.jl/test/test_nls.jl index e69de29bb2..54cd373742 100644 --- a/GALAHAD.jl/test/test_nls.jl +++ b/GALAHAD.jl/test/test_nls.jl @@ -0,0 +1,620 @@ +# test_nls.jl +# Simple code to test the Julia interface to NLS + +using GALAHAD +using Test +using Printf +using Accessors + +# Custom userdata struct +struct userdata_type +p::Float64 +end + +function test_nls() + # compute the residuals + function res(n, m, x::Vector{Float64}, c::Vector{Float64}, userdata::userdata_type) + c[1] = pow(x[1], 2.0) + userdata.p + c[2] = x[1] + x[2]^(2.0) + c[3] = x[1] - x[2] + return 0 + end + + # compute the Jacobian + function jac(n, m, jne, x::Vector{Float64}, jval::Vector{Float64}, + userdata::userdata_type) + jval[1] = 2.0 * x[1] + jval[2] = 1.0 + jval[3] = 2.0 * x[2] + jval[4] = 1.0 + jval[5] = -1.0 + return 0 + end + + # compute the Hessian + function hess(n, m, hne, x::Vector{Float64}, y::Vector{Float64}, hval::Vector{Float64}, + userdata::userdata_type) + hval[1] = 2.0 * y[1] + hval[2] = 2.0 * y[2] + return 0 + end + + # compute Jacobian-vector products + function jacprod(n, m, x::Vector{Float64}, transpose::Bool, u::Vector{Float64}, + v::Vector{Float64}, got_j::Bool, userdata::userdata_type) + if transpose + u[1] = u[1] + 2.0 * x[1] * v[1] + v[2] + v[3] + u[2] = u[2] + 2.0 * x[2] * v[2] - v[3] + else + u[1] = u[1] + 2.0 * x[1] * v[1] + u[2] = u[2] + v[1] + 2.0 * x[2] * v[2] + u[3] = u[3] + v[1] - v[2] + end + return 0 + end + + # compute Hessian-vector products + function hessprod(n, m, x::Vector{Float64}, y::Vector{Float64}, u::Vector{Float64}, + v::Vector{Float64}, got_h::Bool, userdata::userdata_type) + u[1] = u[1] + 2.0 * y[1] * v[1] + u[2] = u[2] + 2.0 * y[2] * v[2] + return 0 + end + + # compute residual-Hessians-vector products + function rhessprods(n, m, pne, x::Vector{Float64}, v::Vector{Float64}, + pval::Vector{Float64}, got_h::Bool, userdata::userdata_type) + pval[1] = 2.0 * v[1] + pval[2] = 2.0 * v[2] + return 0 + end + + # # scale v + function scale(n, m, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, + userdata::userdata_type) + u[1] = v[1] + u[2] = v[2] + return 0 + end + + # compute the dense Jacobian + function jac_dense(n, m, jne, x::Vector{Float64}, jval::Vector{Float64}, + userdata::userdata_type) + jval[1] = 2.0 * x[1] + jval[2] = 0.0 + jval[3] = 1.0 + jval[4] = 2.0 * x[2] + jval[5] = 1.0 + jval[6] = -1.0 + return 0 + end + + # compute the dense Hessian + function hess_dense(n, m, hne, x::Vector{Float64}, y::Vector{Float64}, + hval::Vector{Float64}, userdata::userdata_type) + hval[1] = 2.0 * y[1] + hval[2] = 0.0 + hval[3] = 2.0 * y[2] + return 0 + end + + # compute dense residual-Hessians-vector products + function rhessprods_dense(n, m, pne, x::Vector{Float64}, v::Vector{Float64}, + pval::Vector{Float64}, got_h::Bool, userdata::userdata_type) + pval[1] = 2.0 * v[1] + pval[2] = 0.0 + pval[3] = 0.0 + pval[4] = 2.0 * v[2] + pval[5] = 0.0 + pval[6] = 0.0 + return 0 + end + + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{nls_control_type{Float64}}() + inform = Ref{nls_inform_type{Float64}}() + + # Set user data + userdata = userdata_type(1.0) + + # Set problem data + n = 2 # # variables + m = 3 # # residuals + j_ne = 5 # Jacobian elements + h_ne = 2 # Hesssian elements + p_ne = 2 # residual-Hessians-vector products elements + J_row = Cint[1, 2, 2, 3, 3] # Jacobian J + J_col = Cint[1, 1, 2, 1, 2] # + J_ptr = Cint[1, 2, 4, 6] # row pointers + H_row = Cint[1, 2] # Hessian H + H_col = Cint[1, 2] # NB lower triangle + H_ptr = Cint[1, 2, 3] # row pointers + P_row = Cint[1, 2] # residual-Hessians-vector product matrix + P_ptr = Cint[1, 2, 3, 3] # column pointers + + # Set storage + g = zeros(Float64, n) # gradient + c = zeros(Float64, m) # residual + y = zeros(Float64, m) # multipliers + W = Float64[1.0, 1.0, 1.0] # weights + st = ' ' + status = Ref{Cint}() + + @printf(" Fortran sparse matrix indexing\n\n") + @printf(" tests options for all-in-one storage format\n\n") + + for d in 1:5 + # Initialize NLS + nls_initialize(data, control, inform) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + # @reset control[].print_level = Cint(1) + @reset control[].jacobian_available = Cint(2) + @reset control[].hessian_available = Cint(2) + @reset control[].model = Cint(6) + x = Float64[1.5, 1.5] # starting point + W = Float64[1.0, 1.0, 1.0] # weights + + # sparse co-ordinate storage + if d == 1 + st = 'C' + nls_import(control, data, status, n, m, + "coordinate", j_ne, J_row, J_col, Cint[], + "coordinate", h_ne, H_row, H_col, Cint[], + "sparse_by_columns", p_ne, P_row, Cint[], P_ptr, W) + + nls_solve_with_mat(data, userdata, status, + n, m, x, c, g, res, j_ne, jac, + h_ne, hess, p_ne, rhessprods) + end + + # sparse by rows + if d == 2 + st = 'R' + nls_import(control, data, status, n, m, + "sparse_by_rows", j_ne, Cint[], J_col, J_ptr, + "sparse_by_rows", h_ne, Cint[], H_col, H_ptr, + "sparse_by_columns", p_ne, P_row, Cint[], P_ptr, W) + + nls_solve_with_mat(data, userdata, status, + n, m, x, c, g, res, j_ne, jac, + h_ne, hess, p_ne, rhessprods) + end + + # dense + if d == 3 + st = 'D' + nls_import(control, data, status, n, m, + "dense", j_ne, Cint[], Cint[], Cint[], + "dense", h_ne, Cint[], Cint[], Cint[], + "dense", p_ne, Cint[], Cint[], Cint[], W) + + nls_solve_with_mat(data, userdata, status, + n, m, x, c, g, res, j_ne, jac_dense, + h_ne, hess_dense, p_ne, rhessprods_dense) + end + + # diagonal + if d == 4 + st = 'I' + nls_import(control, data, status, n, m, + "sparse_by_rows", j_ne, Cint[], J_col, J_ptr, + "diagonal", h_ne, Cint[], Cint[], Cint[], + "sparse_by_columns", p_ne, P_row, Cint[], P_ptr, W) + + nls_solve_with_mat(data, userdata, status, + n, m, x, c, g, res, j_ne, jac, + h_ne, hess, p_ne, rhessprods) + end + + # access by products + if d == 5 + st = 'P' + nls_import(control, data, status, n, m, + "absent", j_ne, Cint[], Cint[], Cint[], + "absent", h_ne, Cint[], Cint[], Cint[], + "sparse_by_columns", p_ne, P_row, Cint[], P_ptr, W) + + nls_solve_without_mat(data, userdata, status, + n, m, x, c, g, res, jacprod, + hessprod, p_ne, rhessprods) + end + + nls_information(data, inform, status) + + if inform[].status == 0 + @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", + st, inform[].iter, inform[].obj, inform[].status) + else + @printf("%c: NLS_solve exit status = %1i\n", st, inform[].status) + end + + # Delete internal workspace + nls_terminate(data, control, inform) + end + + @printf("\n tests reverse-communication options\n\n") + # reverse-communication input/output + eval_status = Ref{Cint}() + u = zeros(Float64, max(m, n)) + v = zeros(Float64, max(m, n)) + J_val = zeros(Float64, j_ne) + J_dense = zeros(Float64, m * n) + H_val = zeros(Float64, h_ne) + H_dense = zeros(Float64, div(n * (n + 1), 2)) + H_diag = zeros(Float64, n) + P_val = zeros(Float64, p_ne) + P_dense = zeros(Float64, m * n) + got_j = false + got_h = false + + for d in 1:5 + # Initialize NLS + nls_initialize(data, control, inform) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + # @reset control[].print_level = Cint(1) + @reset control[].jacobian_available = 2 + @reset control[].hessian_available = 2 + @reset control[].model = 6 + x = Float64[1.5, 1.5] # starting point + W = Float64[1.0, 1.0, 1.0] # weights + + # sparse co-ordinate storage + if d == 1 + st = 'C' + nls_import(control, data, status, n, m, + "coordinate", j_ne, J_row, J_col, Cint[], + "coordinate", h_ne, H_row, H_col, Cint[], + "sparse_by_columns", p_ne, P_row, Cint[], P_ptr, W) + terminated = false + while !terminated # reverse-communication loop + nls_solve_reverse_with_mat(data, status, eval_status, + n, m, x, c, g, j_ne, J_val, y, + h_ne, H_val, v, p_ne, P_val) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # evaluate c + eval_status[] = res(n, m, x, c, userdata) + elseif status[] == 3 # evaluate J + eval_status[] = jac(n, m, j_ne, x, J_val, userdata) + elseif status[] == 4 # evaluate H + eval_status[] = hess(n, m, h_ne, x, y, H_val, userdata) + elseif status[] == 7 # evaluate P + eval_status[] = rhessprods(n, m, p_ne, x, v, P_val, got_h, userdata) + else + @printf(" the value %1i of status should not occur\n", status) + end + end + end + + # sparse by rows + if d == 2 + st = 'R' + nls_import(control, data, status, n, m, + "sparse_by_rows", j_ne, Cint[], J_col, J_ptr, + "sparse_by_rows", h_ne, Cint[], H_col, H_ptr, + "sparse_by_columns", p_ne, P_row, Cint[], P_ptr, W) + + terminated = false + while !terminated # reverse-communication loop + nls_solve_reverse_with_mat(data, status, eval_status, + n, m, x, c, g, j_ne, J_val, y, + h_ne, H_val, v, p_ne, P_val) + if status[] == 0 # successful termination + terminated[] = true + elseif status[] < 0 # error exit + terminated[] = true + elseif status[] == 2 # evaluate c + eval_status[] = res(n, m, x, c, userdata) + elseif status[] == 3 # evaluate J + eval_status[] = jac(n, m, j_ne, x, J_val, userdata) + elseif status[] == 4 # evaluate H + eval_status[] = hess(n, m, h_ne, x, y, H_val, userdata) + elseif status[] == 7 # evaluate P + eval_status[] = rhessprods(n, m, p_ne, x, v, P_val, got_h, userdata) + else + @printf(" the value %1i of status should not occur\n", status) + end + end + end + + # dense + if d == 3 + st = 'D' + nls_import(control, data, status, n, m, + "dense", j_ne, Cint[], Cint[], Cint[], + "dense", h_ne, Cint[], Cint[], Cint[], + "dense", p_ne, Cint[], Cint[], Cint[], W) + + terminated = false + while !terminated # reverse-communication loop + nls_solve_reverse_with_mat(data, status, eval_status, + n, m, x, c, g, m * n, J_dense, y, + n * (n + 1) / 2, H_dense, v, m * n, + P_dense) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # evaluate c + eval_status[] = res(n, m, x, c, userdata) + elseif status[] == 3 # evaluate J + eval_status[] = jac_dense(n, m, j_ne, x, J_dense, userdata) + elseif status[] == 4 # evaluate H + eval_status[] = hess_dense(n, m, h_ne, x, y, H_dense, userdata) + elseif status[] == 7 # evaluate P + eval_status[] = rhessprods_dense(n, m, p_ne, x, v, P_dense, got_h, userdata) + else + @printf(" the value %1i of status should not occur\n", status) + end + end + end + + # diagonal + if d == 4 + st = 'I' + nls_import(control, data, status, n, m, + "sparse_by_rows", j_ne, Cint[], J_col, J_ptr, + "diagonal", h_ne, Cint[], Cint[], Cint[], + "sparse_by_columns", p_ne, P_row, Cint[], P_ptr, W) + + terminated = false + while !terminated # reverse-communication loop + nls_solve_reverse_with_mat(data, status, eval_status, + n, m, x, c, g, j_ne, J_val, y, + n, H_diag, v, p_ne, P_val) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # evaluate c + eval_status[] = res(n, m, x, c, userdata) + elseif status[] == 3 # evaluate J + eval_status[] = jac(n, m, j_ne, x, J_val, userdata) + elseif status[] == 4 # evaluate H + eval_status[] = hess(n, m, h_ne, x, y, H_diag, userdata) + elseif status[] == 7 # evaluate P + eval_status[] = rhessprods(n, m, p_ne, x, v, P_val, got_h, userdata) + else + @printf(" the value %1i of status should not occur\n", status) + end + end + end + + # access by products + if d == 5 + st = 'P' + # @reset control[].print_level = Cint(1) + nls_import(control, data, status, n, m, + "absent", j_ne, Cint[], Cint[], Cint[], + "absent", h_ne, Cint[], Cint[], Cint[], + "sparse_by_columns", p_ne, P_row, Cint[], P_ptr, W) + + terminated = false + while !terminated # reverse-communication loop + nls_solve_reverse_without_mat(data, status, eval_status, + n, m, x, c, g, transpose, + u, v, y, p_ne, P_val) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # evaluate c + eval_status[] = res(n, m, x, c, userdata) + elseif status[] == 5 # evaluate u + J v or u + J'v + eval_status[] = jacprod(n, m, x, transpose, u, v, got_j, userdata) + elseif status[] == 6 # evaluate u + H v + eval_status[] = hessprod(n, m, x, y, u, v, got_h, userdata) + elseif status[] == 7 # evaluate P + eval_status[] = rhessprods(n, m, p_ne, x, v, P_val, got_h, userdata) + else + @printf(" the value %1i of status should not occur\n", status) + end + end + end + + nls_information(data, inform, status) + + if inform[].status == 0 + @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", + st, inform[].iter, inform[].obj, inform[].status) + else + @printf("%c: NLS_solve exit status = %1i\n", st, inform[].status) + end + + # Delete internal workspace + nls_terminate(data, control, inform) + end + + @printf("\n basic tests of models used, direct access\n\n") + for model in 3:8 + # Initialize NLS + nls_initialize(data, control, inform) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + # @reset control[].print_level = Cint(1) + @reset control[].jacobian_available = Cint(2) + @reset control[].hessian_available = Cint(2) + @reset control[].model = model + x = Float64[1.5, 1.5] # starting point + W = Float64[1.0, 1.0, 1.0] # weights + + nls_import(control, data, status, n, m, + "sparse_by_rows", j_ne, Cint[], J_col, J_ptr, + "sparse_by_rows", h_ne, Cint[], H_col, H_ptr, + "sparse_by_columns", p_ne, P_row, Cint[], P_ptr, W) + + nls_solve_with_mat(data, userdata, status, + n, m, x, c, g, res, j_ne, jac, + h_ne, hess, p_ne, rhessprods) + + nls_information(data, inform, status) + + if inform[].status == 0 + @printf(" %1i:%6i iterations. Optimal objective value = %5.2f status = %1i\n", + model, inform[].iter, inform[].obj, inform[].status) + else + @printf(" %i: NLS_solve exit status = %1i\n", model, inform[].status) + end + + # Delete internal workspace + nls_terminate(data, control, inform) + end + + @printf("\n basic tests of models used, access by products\n\n") + for model in 3:8 + # Initialize NLS + nls_initialize(data, control, inform) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + # @reset control[].print_level = Cint(1) + @reset control[].jacobian_available = Cint(2) + @reset control[].hessian_available = Cint(2) + @reset control[].model = model + x = Float64[1.5, 1.5] # starting point + W = Float64[1.0, 1.0, 1.0] # weights + + nls_import(control, data, status, n, m, + "absent", j_ne, Cint[], Cint[], Cint[], + "absent", h_ne, Cint[], Cint[], Cint[], + "sparse_by_columns", p_ne, P_row, Cint[], P_ptr, W) + + nls_solve_without_mat(data, userdata, status, + n, m, x, c, g, res, jacprod, + hessprod, p_ne, rhessprods) + + nls_information(data, inform, status) + + if inform[].status == 0 + @printf("P%1i:%6i iterations. Optimal objective value = %5.2f status = %1i\n", + model, inform[].iter, inform[].obj, inform[].status) + else + @printf("P%i: NLS_solve exit status = %1i\n", model, inform[].status) + end + + # Delete internal workspace + nls_terminate(data, control, inform) + end + + @printf("\n basic tests of models used, reverse access\n\n") + for model in 3:8 + # Initialize NLS + nls_initialize(data, control, inform) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + # @reset control[].print_level = Cint(1) + @reset control[].jacobian_available = Cint(2) + @reset control[].hessian_available = Cint(2) + @reset control[].model = model + x = Float64[1.5, 1.5] # starting point + W = Float64[1.0, 1.0, 1.0] # weights + + nls_import(control, data, status, n, m, + "sparse_by_rows", j_ne, Cint[], J_col, J_ptr, + "sparse_by_rows", h_ne, Cint[], H_col, H_ptr, + "sparse_by_columns", p_ne, P_row, Cint[], P_ptr, W) + + terminated = false + while !terminated # reverse-communication loop + nls_solve_reverse_with_mat(data, status, eval_status, + n, m, x, c, g, j_ne, J_val, y, + h_ne, H_val, v, p_ne, P_val) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # evaluate c + eval_status[] = res(n, m, x, c, userdata) + elseif status[] == 3 # evaluate J + eval_status[] = jac(n, m, j_ne, x, J_val, userdata) + elseif status[] == 4 # evaluate H + eval_status[] = hess(n, m, h_ne, x, y, H_val, userdata) + elseif status[] == 7 # evaluate P + eval_status[] = rhessprods(n, m, p_ne, x, v, P_val, got_h, userdata) + else + @printf(" the value %1i of status should not occur\n", status) + end + end + + nls_information(data, inform, status) + + if inform[].status == 0 + @printf("P%1i:%6i iterations. Optimal objective value = %5.2f status = %1i\n", + model, inform[].iter, inform[].obj, inform[].status) + else + @printf(" %i: NLS_solve exit status = %1i\n", model, inform[].status) + end + + # Delete internal workspace + nls_terminate(data, control, inform) + end + + @printf("\n basic tests of models used, reverse access by products\n\n") + for model in 3:8 + # Initialize NLS + nls_initialize(data, control, inform) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + # @reset control[].print_level = 1 + @reset control[].jacobian_available = Cint(2) + @reset control[].hessian_available = Cint(2) + @reset control[].model = model + x = Float64[1.5, 1.5] # starting point + W = Float64[1.0, 1.0, 1.0] # weights + + nls_import(control, data, status, n, m, + "absent", j_ne, Cint[], Cint[], Cint[], + "absent", h_ne, Cint[], Cint[], Cint[], + "sparse_by_columns", p_ne, P_row, Cint[], P_ptr, W) + + terminated = false + while !terminated # reverse-communication loop + nls_solve_reverse_without_mat(data, status, eval_status, + n, m, x, c, g, transpose, + u, v, y, p_ne, P_val) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # evaluate c + eval_status[] = res(n, m, x, c, userdata) + elseif status[] == 5 # evaluate u + J v or u + J'v + eval_status[] = jacprod(n, m, x, transpose, u, v, got_j, userdata) + elseif status[] == 6 # evaluate u + H v + eval_status[] = hessprod(n, m, x, y, u, v, got_h, userdata) + elseif status[] == 7 # evaluate P + eval_status[] = rhessprods(n, m, p_ne, x, v, P_val, got_h, userdata) + else + @printf(" the value %1i of status should not occur\n", status) + end + end + + nls_information(data, inform, status) + + if inform[].status == 0 + @printf("P%1i:%6i iterations. Optimal objective value = %5.2f status = %1i\n", + model, inform[].iter, inform[].obj, inform[].status) + else + @printf("P%i: NLS_solve exit status = %1i\n", model, inform[].status) + end + + # Delete internal workspace + nls_terminate(data, control, inform) + end + + return 0 +end + +@testset "NLS" begin + @test test_nls() == 0 +end diff --git a/GALAHAD.jl/test/test_qpa.jl b/GALAHAD.jl/test/test_qpa.jl index 746598f1a4..f5ae6ded15 100644 --- a/GALAHAD.jl/test/test_qpa.jl +++ b/GALAHAD.jl/test/test_qpa.jl @@ -2,224 +2,235 @@ # Simple code to test the Julia interface to QPA using GALAHAD +using Test using Printf - -# Derived types -data = [Ptr{Ptr{Cvoid}}()] -control = qpa_control_type{Float64}() -inform = qpa_inform_type{Float64}() - -# Set problem data -n = 3 # dimension -m = 2 # number of general constraints -H_ne = 3 # Hesssian elements -H_row = Cint[1, 2, 3] # row indices, NB lower triangle -H_col = Cint[1, 2, 3] # column indices, NB lower triangle -H_ptr = Cint[1, 2, 3, 4] # row pointers -H_val = Float64[1.0, 1.0, 1.0] # values -g = Float64[0.0, 2.0, 0.0] # linear term in the objective -f = 1.0 # constant term in the objective -rho_g = 0.1 # penalty paramter for general constraints -rho_b = 0.1 # penalty paramter for simple bound constraints -A_ne = 4 # Jacobian elements -A_row = Cint[1, 1, 2, 2] # row indices -A_col = Cint[1, 2, 2, 3] # column indices -A_ptr = Cint[1, 3, 5] # row pointers -A_val = Float64[2.0, 1.0, 1.0, 1.0] # values -c_l = Float64[1.0, 2.0] # constraint lower bound -c_u = Float64[2.0, 2.0] # constraint upper bound -x_l = Float64[-1.0, -Inf, -Inf] # variable lower bound -x_u = Float64[1.0, Inf, 2.0] # variable upper bound - -# Set output storage -c = zeros(Float64, m) # constraint values -x_stat = zeros(Cint, n) # variable status -c_stat = zeros(Cint, m) # constraint status -st = ' ' -status = Ref{Cint}() - -@printf(" Fortran sparse matrix indexing\n\n") -@printf(" basic tests of qp storage formats\n\n") - -for d = 1:7 - # Initialize QPA - qpa_initialize( data, control, status ) - - # Set user-defined control options - control.f_indexing = true # Fortran sparse matrix indexing - - # Start from 0 - x = Float64[0.0,0.0,0.0] - y = Float64[0.0,0.0] - z = Float64[0.0,0.0,0.0] - - # sparse co-ordinate storage - if d == 1 - global st = 'C' - - qpa_import( control, data, status, n, m, - "coordinate", H_ne, H_row, H_col, Cint[], - "coordinate", A_ne, A_row, A_col, Cint[] ) - - qpa_solve_qp( data, status, n, m, H_ne, H_val, g, f, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) +using Accessors + +function test_qpa() + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{qpa_control_type{Float64}}() + inform = Ref{qpa_inform_type{Float64}}() + + # Set problem data + n = 3 # dimension + m = 2 # number of general constraints + H_ne = 3 # Hesssian elements + H_row = Cint[1, 2, 3] # row indices, NB lower triangle + H_col = Cint[1, 2, 3] # column indices, NB lower triangle + H_ptr = Cint[1, 2, 3, 4] # row pointers + H_val = Float64[1.0, 1.0, 1.0] # values + g = Float64[0.0, 2.0, 0.0] # linear term in the objective + f = 1.0 # constant term in the objective + rho_g = 0.1 # penalty paramter for general constraints + rho_b = 0.1 # penalty paramter for simple bound constraints + A_ne = 4 # Jacobian elements + A_row = Cint[1, 1, 2, 2] # row indices + A_col = Cint[1, 2, 2, 3] # column indices + A_ptr = Cint[1, 3, 5] # row pointers + A_val = Float64[2.0, 1.0, 1.0, 1.0] # values + c_l = Float64[1.0, 2.0] # constraint lower bound + c_u = Float64[2.0, 2.0] # constraint upper bound + x_l = Float64[-1.0, -Inf, -Inf] # variable lower bound + x_u = Float64[1.0, Inf, 2.0] # variable upper bound + + # Set output storage + c = zeros(Float64, m) # constraint values + x_stat = zeros(Cint, n) # variable status + c_stat = zeros(Cint, m) # constraint status + st = ' ' + status = Ref{Cint}() + + @printf(" Fortran sparse matrix indexing\n\n") + @printf(" basic tests of qp storage formats\n\n") + + for d in 1:7 + # Initialize QPA + qpa_initialize(data, control, status) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + + # Start from 0 + x = Float64[0.0, 0.0, 0.0] + y = Float64[0.0, 0.0] + z = Float64[0.0, 0.0, 0.0] + + # sparse co-ordinate storage + if d == 1 + st = 'C' + qpa_import(control, data, status, n, m, + "coordinate", H_ne, H_row, H_col, Cint[], + "coordinate", A_ne, A_row, A_col, Cint[]) + + qpa_solve_qp(data, status, n, m, H_ne, H_val, g, f, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + end + + # sparse by rows + if d == 2 + st = 'R' + qpa_import(control, data, status, n, m, + "sparse_by_rows", H_ne, Cint[], H_col, H_ptr, + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + + qpa_solve_qp(data, status, n, m, H_ne, H_val, g, f, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + end + + # dense + if d == 3 + st = 'D' + H_dense_ne = 6 # number of elements of H + A_dense_ne = 6 # number of elements of A + H_dense = Float64[1.0, 0.0, 1.0, 0.0, 0.0, 1.0] + A_dense = Float64[2.0, 1.0, 0.0, 0.0, 1.0, 1.0] + + qpa_import(control, data, status, n, m, + "dense", H_ne, Cint[], Cint[], Cint[], + "dense", A_ne, Cint[], Cint[], Cint[]) + + qpa_solve_qp(data, status, n, m, H_dense_ne, H_dense, g, f, + A_dense_ne, A_dense, c_l, c_u, x_l, x_u, + x, c, y, z, x_stat, c_stat) + end + + # diagonal + if d == 4 + st = 'L' + qpa_import(control, data, status, n, m, + "diagonal", H_ne, Cint[], Cint[], Cint[], + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + + qpa_solve_qp(data, status, n, m, H_ne, H_val, g, f, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + end + + # scaled identity + if d == 5 + st = 'S' + qpa_import(control, data, status, n, m, + "scaled_identity", H_ne, Cint[], Cint[], Cint[], + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + + qpa_solve_qp(data, status, n, m, H_ne, H_val, g, f, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + end + + # identity + if d == 6 + st = 'I' + qpa_import(control, data, status, n, m, + "identity", H_ne, Cint[], Cint[], Cint[], + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + + qpa_solve_qp(data, status, n, m, H_ne, H_val, g, f, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + end + + # zero + if d == 7 + st = 'Z' + qpa_import(control, data, status, n, m, + "zero", H_ne, Cint[], Cint[], Cint[], + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + + qpa_solve_qp(data, status, n, m, H_ne, H_val, g, f, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + end + + qpa_information(data, inform, status) + + if inform[].status == 0 + @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", + st, inform[].iter, inform[].obj, inform[].status) + else + @printf("%c: QPA_solve exit status = %1i\n", st, inform[].status) + end + + # @printf("x: ") + # for i = 1:n + # @printf("%f ", x[i]) + # end + # @printf("\n") + # @printf("gradient: ") + # for i = 1:n + # @printf("%f ", g[i]) + # end + # @printf("\n") + + # Delete internal workspace + qpa_terminate(data, control, inform) end - # sparse by rows - if d == 2 - global st = 'R' - - qpa_import( control, data, status, n, m, - "sparse_by_rows", H_ne, Cint[], H_col, H_ptr, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr ) - - qpa_solve_qp( data, status, n, m, H_ne, H_val, g, f, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) - end - - # dense - if d == 3 - global st = 'D' - H_dense_ne = 6 # number of elements of H - A_dense_ne = 6 # number of elements of A - H_dense = Float64[1.0, 0.0, 1.0, 0.0, 0.0, 1.0] - A_dense = Float64[2.0, 1.0, 0.0, 0.0, 1.0, 1.0] - - qpa_import( control, data, status, n, m, - "dense", H_ne, Cint[], Cint[], Cint[], - "dense", A_ne, Cint[], Cint[], Cint[] ) - - qpa_solve_qp( data, status, n, m, H_dense_ne, H_dense, g, f, - A_dense_ne, A_dense, c_l, c_u, x_l, x_u, - x, c, y, z, x_stat, c_stat ) - end - - # diagonal - if d == 4 - global st = 'L' - - qpa_import( control, data, status, n, m, - "diagonal", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr ) - - qpa_solve_qp( data, status, n, m, H_ne, H_val, g, f, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) - end - - # scaled identity - if d == 5 - global st = 'S' - - qpa_import( control, data, status, n, m, - "scaled_identity", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr ) - - qpa_solve_qp( data, status, n, m, H_ne, H_val, g, f, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) - end - - # identity - if d == 6 - global st = 'I' - - qpa_import( control, data, status, n, m, - "identity", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr ) - - qpa_solve_qp( data, status, n, m, H_ne, H_val, g, f, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) - end - - # zero - if d == 7 - global st = 'Z' - - qpa_import( control, data, status, n, m, - "zero", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr ) - - qpa_solve_qp( data, status, n, m, H_ne, H_val, g, f, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) - end - - qpa_information( data, inform, status ) - - if inform.status == 0 - @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", st, inform.iter, inform.obj, inform.status) - else - @printf("%c: QPA_solve exit status = %1i\n", st, inform.status) - end - - # @printf("x: ") - # for i = 1:n - # @printf("%f ", x[i]) - # end - # @printf("\n") - # @printf("gradient: ") - # for i = 1:n - # @printf("%f ", g[i]) - # end - # @printf("\n") - - # Delete internal workspace - qpa_terminate( data, control, inform ) @printf("\n basic tests of l_1 qp storage formats\n\n") - - qpa_initialize( data, control, status ) + qpa_initialize(data, control, status) # Set user-defined control options - control.f_indexing = true # Fortran sparse matrix indexing + @reset control[].f_indexing = true # Fortran sparse matrix indexing # Start from 0 - x = Float64[0.0,0.0,0.0] - y = Float64[0.0,0.0] - z = Float64[0.0,0.0,0.0] + x = Float64[0.0, 0.0, 0.0] + y = Float64[0.0, 0.0] + z = Float64[0.0, 0.0, 0.0] # solve the l_1qp problem - qpa_import( control, data, status, n, m, - "coordinate", H_ne, H_row, H_col, Cint[], - "coordinate", A_ne, A_row, A_col, Cint[] ) + qpa_import(control, data, status, n, m, + "coordinate", H_ne, H_row, H_col, Cint[], + "coordinate", A_ne, A_row, A_col, Cint[]) - qpa_solve_l1qp( data, status, n, m, H_ne, H_val, g, f, rho_g, rho_b, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) + qpa_solve_l1qp(data, status, n, m, H_ne, H_val, g, f, rho_g, rho_b, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) - qpa_information( data, inform, status ) + qpa_information(data, inform, status) - if inform.status == 0 - @printf("%s %6i iterations. Optimal objective value = %5.2f status = %1i\n", "l1qp ", inform.iter, inform.obj, inform.status) + if inform[].status == 0 + @printf("%s %6i iterations. Optimal objective value = %5.2f status = %1i\n", + "l1qp ", inform[].iter, inform[].obj, inform[].status) else - @printf("%c: QPA_solve exit status = %1i\n", st, inform.status) + @printf("%c: QPA_solve exit status = %1i\n", st, inform[].status) end # Start from 0 - x .= 0.0 - y .= 0.0 - z .= 0.0 + for i in 1:n + x[i] = 0.0 + z[i] = 0.0 + end + for i in 1:m + y[i] = 0.0 + end # solve the bound constrained l_1qp problem - qpa_import( control, data, status, n, m, - "coordinate", H_ne, H_row, H_col, Cint[], - "coordinate", A_ne, A_row, A_col, Cint[] ) + qpa_import(control, data, status, n, m, + "coordinate", H_ne, H_row, H_col, Cint[], + "coordinate", A_ne, A_row, A_col, Cint[]) - qpa_solve_bcl1qp( data, status, n, m, H_ne, H_val, g, f, rho_g, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) + qpa_solve_bcl1qp(data, status, n, m, H_ne, H_val, g, f, rho_g, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) - qpa_information( data, inform, status ) + qpa_information(data, inform, status) - if inform.status == 0 - @printf("%s %6i iterations. Optimal objective value = %5.2f status = %1i\n", "bcl1qp", inform.iter, inform.obj, inform.status) + if inform[].status == 0 + @printf("%s %6i iterations. Optimal objective value = %5.2f status = %1i\n", + "bcl1qp", inform[].iter, inform[].obj, inform[].status) else - @printf("%c: QPA_solve exit status = %1i\n", st, inform.status) + @printf("%c: QPA_solve exit status = %1i\n", st, inform[].status) end # Delete internal workspace - qpa_terminate( data, control, inform ) -end \ No newline at end of file + qpa_terminate(data, control, inform) + + return 0 +end + +@testset "QPA" begin + @test test_qpa() == 0 +end diff --git a/GALAHAD.jl/test/test_qpb.jl b/GALAHAD.jl/test/test_qpb.jl index 5354c16aab..85c4c778b1 100644 --- a/GALAHAD.jl/test/test_qpb.jl +++ b/GALAHAD.jl/test/test_qpb.jl @@ -2,170 +2,174 @@ # Simple code to test the Julia interface to QPB using GALAHAD +using Test using Printf - -# Derived types -data = [Ptr{Ptr{Cvoid}}()] -control = qpb_control_type{Float64}() -inform = qpb_inform_type{Float64}() - -# Set problem data -n = 3 # dimension -m = 2 # number of general constraints -H_ne = 3 # Hesssian elements -H_row = Cint[1, 2, 3] # row indices, NB lower triangle -H_col = Cint[1, 2, 3] # column indices, NB lower triangle -H_ptr = Cint[1, 2, 3, 4] # row pointers -H_val = Float64[1.0, 1.0, 1.0] # values -g = Float64[0.0, 2.0, 0.0] # linear term in the objective -f = 1.0 # constant term in the objective -A_ne = 4 # Jacobian elements -A_row = Cint[1, 1, 2, 2] # row indices -A_col = Cint[1, 2, 2, 3] # column indices -A_ptr = Cint[1, 3, 5] # row pointers -A_val = Float64[2.0, 1.0, 1.0, 1.0] # values -c_l = Float64[1.0, 2.0] # constraint lower bound -c_u = Float64[2.0, 2.0] # constraint upper bound -x_l = Float64[-1.0, -Inf, -Inf] # variable lower bound -x_u = Float64[1.0, Inf, 2.0] # variable upper bound - -# Set output storage -c = zeros(Float64, m) # constraint values -x_stat = zeros(Cint, n) # variable status -c_stat = zeros(Cint, m) # constraint status -st = ' ' -status = Ref{Cint}() - -@printf(" Fortran sparse matrix indexing\n\n") -@printf(" basic tests of qp storage formats\n\n") - -for d = 1:7 - # Initialize QPB - qpb_initialize( data, control, status ) - - # Set user-defined control options - control.f_indexing = true # Fortran sparse matrix indexing - - # Start from 0 - x = Float64[0.0,0.0,0.0] - y = Float64[0.0,0.0] - z = Float64[0.0,0.0,0.0] - - # sparse co-ordinate storage - if d == 1 - global st = 'C' - - qpb_import( control, data, status, n, m, - "coordinate", H_ne, H_row, H_col, Cint[], - "coordinate", A_ne, A_row, A_col, Cint[] ) - - qpb_solve_qp( data, status, n, m, H_ne, H_val, g, f, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) - end - - # sparse by rows - if d == 2 - global st = 'R' - - qpb_import( control, data, status, n, m, - "sparse_by_rows", H_ne, Cint[], H_col, H_ptr, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr ) - - qpb_solve_qp( data, status, n, m, H_ne, H_val, g, f, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) +using Accessors + +function test_qpb() + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{qpb_control_type{Float64}}() + inform = Ref{qpb_inform_type{Float64}}() + + # Set problem data + n = 3 # dimension + m = 2 # number of general constraints + H_ne = 3 # Hesssian elements + H_row = Cint[1, 2, 3] # row indices, NB lower triangle + H_col = Cint[1, 2, 3] # column indices, NB lower triangle + H_ptr = Cint[1, 2, 3, 4] # row pointers + H_val = Float64[1.0, 1.0, 1.0] # values + g = Float64[0.0, 2.0, 0.0] # linear term in the objective + f = 1.0 # constant term in the objective + A_ne = 4 # Jacobian elements + A_row = Cint[1, 1, 2, 2] # row indices + A_col = Cint[1, 2, 2, 3] # column indices + A_ptr = Cint[1, 3, 5] # row pointers + A_val = Float64[2.0, 1.0, 1.0, 1.0] # values + c_l = Float64[1.0, 2.0] # constraint lower bound + c_u = Float64[2.0, 2.0] # constraint upper bound + x_l = Float64[-1.0, -Inf, -Inf] # variable lower bound + x_u = Float64[1.0, Inf, 2.0] # variable upper bound + + # Set output storage + c = zeros(Float64, m) # constraint values + x_stat = zeros(Cint, n) # variable status + c_stat = zeros(Cint, m) # constraint status + st = ' ' + status = Ref{Cint}() + + @printf(" Fortran sparse matrix indexing\n\n") + @printf(" basic tests of qp storage formats\n\n") + + for d in 1:7 + # Initialize QPB + qpb_initialize(data, control, status) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + + # Start from 0 + x = Float64[0.0, 0.0, 0.0] + y = Float64[0.0, 0.0] + z = Float64[0.0, 0.0, 0.0] + + # sparse co-ordinate storage + if d == 1 + st = 'C' + qpb_import(control, data, status, n, m, + "coordinate", H_ne, H_row, H_col, Cint[], + "coordinate", A_ne, A_row, A_col, Cint[]) + + qpb_solve_qp(data, status, n, m, H_ne, H_val, g, f, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + end + + # sparse by rows + if d == 2 + st = 'R' + qpb_import(control, data, status, n, m, + "sparse_by_rows", H_ne, Cint[], H_col, H_ptr, + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + + qpb_solve_qp(data, status, n, m, H_ne, H_val, g, f, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + end + + # dense + if d == 3 + st = 'D' + H_dense_ne = 6 # number of elements of H + A_dense_ne = 6 # number of elements of A + H_dense = Float64[1.0, 0.0, 1.0, 0.0, 0.0, 1.0] + A_dense = Float64[2.0, 1.0, 0.0, 0.0, 1.0, 1.0] + + qpb_import(control, data, status, n, m, + "dense", H_ne, Cint[], Cint[], Cint[], + "dense", A_ne, Cint[], Cint[], Cint[]) + + qpb_solve_qp(data, status, n, m, H_dense_ne, H_dense, g, f, + A_dense_ne, A_dense, c_l, c_u, x_l, x_u, + x, c, y, z, x_stat, c_stat) + end + + # diagonal + if d == 4 + st = 'L' + qpb_import(control, data, status, n, m, + "diagonal", H_ne, Cint[], Cint[], Cint[], + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + + qpb_solve_qp(data, status, n, m, H_ne, H_val, g, f, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + end + + # scaled identity + if d == 5 + st = 'S' + qpb_import(control, data, status, n, m, + "scaled_identity", H_ne, Cint[], Cint[], Cint[], + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + + qpb_solve_qp(data, status, n, m, H_ne, H_val, g, f, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + end + + # identity + if d == 6 + st = 'I' + qpb_import(control, data, status, n, m, + "identity", H_ne, Cint[], Cint[], Cint[], + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + + qpb_solve_qp(data, status, n, m, H_ne, H_val, g, f, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + end + + # zero + if d == 7 + st = 'Z' + qpb_import(control, data, status, n, m, + "zero", H_ne, Cint[], Cint[], Cint[], + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + + qpb_solve_qp(data, status, n, m, H_ne, H_val, g, f, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + end + + qpb_information(data, inform, status) + + if inform[].status == 0 + @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", + st, inform[].iter, inform[].obj, inform[].status) + else + @printf("%c: QPB_solve exit status = %1i\n", st, inform[].status) + end + + # @printf("x: ") + # for i = 1:n + # @printf("%f ", x[i]) + # end + # @printf("\n") + # @printf("gradient: ") + # for i = 1:n + # @printf("%f ", g[i]) + # end + # @printf("\n") + + # Delete internal workspace + qpb_terminate(data, control, inform) end - # dense - if d == 3 - global st = 'D' - - H_dense_ne = 6 # number of elements of H - A_dense_ne = 6 # number of elements of A - H_dense = Float64[1.0, 0.0, 1.0, 0.0, 0.0, 1.0] - A_dense = Float64[2.0, 1.0, 0.0, 0.0, 1.0, 1.0] - - qpb_import( control, data, status, n, m, - "dense", H_ne, Cint[], Cint[], Cint[], - "dense", A_ne, Cint[], Cint[], Cint[] ) - - qpb_solve_qp( data, status, n, m, H_dense_ne, H_dense, g, f, - A_dense_ne, A_dense, c_l, c_u, x_l, x_u, - x, c, y, z, x_stat, c_stat ) - end - - # diagonal - if d == 4 - global st = 'L' - - qpb_import( control, data, status, n, m, - "diagonal", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr ) - - qpb_solve_qp( data, status, n, m, H_ne, H_val, g, f, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) - end - - # scaled identity - if d == 5 - global st = 'S' - - qpb_import( control, data, status, n, m, - "scaled_identity", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr ) - - qpb_solve_qp( data, status, n, m, H_ne, H_val, g, f, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) - end - - # identity - if d == 6 - global st = 'I' - - qpb_import( control, data, status, n, m, - "identity", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr ) - - qpb_solve_qp( data, status, n, m, H_ne, H_val, g, f, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) - end - - # zero - if d == 7 - global st = 'Z' - - qpb_import( control, data, status, n, m, - "zero", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr ) - - qpb_solve_qp( data, status, n, m, H_ne, H_val, g, f, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) - end - - qpb_information( data, inform, status ) - - if inform.status == 0 - @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", st, inform.iter, inform.obj, inform.status) - else - @printf("%c: QPB_solve exit status = %1i\n", st, inform.status) - end + return 0 +end - # @printf("x: ") - # for i = 1:n - # @printf("%f ", x[i]) - # end - # @printf("\n") - # @printf("gradient: ") - # for i = 1:n - # @printf("%f ", g[i]) - # end - # @printf("\n") - - # Delete internal workspace - qpb_terminate( data, control, inform ) +@testset "QPB" begin + @test test_qpb() == 0 end diff --git a/GALAHAD.jl/test/test_rqs.jl b/GALAHAD.jl/test/test_rqs.jl index e69de29bb2..bfdce1875e 100644 --- a/GALAHAD.jl/test/test_rqs.jl +++ b/GALAHAD.jl/test/test_rqs.jl @@ -0,0 +1,252 @@ +/* rqstf.c */ +/* Full test for the RQS C interface using Fortran sparse matrix indexing */ + +#include +#include +#include +#include "galahad_precision.h" +#include "galahad_cfunctions.h" +#include "galahad_rqs.h" + +# test_rqs.jl +# Simple code to test the Julia interface to RQS + +using GALAHAD +using Test +using Printf +using Accessors + +function test_rqs() +# Derived types +data = Ref{Ptr{Cvoid}}() +control = Ref{rqs_control_type{Float64}}() +inform = Ref{rqs_inform_type{Float64}}() + +# Set problem data +n = 3 # dimension of H +m = 1 # dimension of A +H_ne = 4 # number of elements of H +M_ne = 3 # number of elements of M +A_ne = 3 # number of elements of A +H_dense_ne = 6 # number of elements of H +M_dense_ne = 6 # number of elements of M +H_row = Cint[1, 2, 3, 3] # row indices, NB lower triangle +H_col = Cint[1, 2, 3, 1] +H_ptr = Cint[1, 2, 3, 5] +M_row = Cint[1, 2, 3] # row indices, NB lower triangle +M_col = Cint[1, 2, 3] +M_ptr = Cint[1, 2, 3, 4] +A_row = Cint[1, 1, 1} +A_col = Cint[1, 2, 3] +A_ptr = Cint[1, 4] +H_val = Float64[1.0, 2.0, 3.0, 4.0] +M_val = Float64[1.0, 2.0, 1.0] +A_val = Float64[1.0, 1.0, 1.0] +H_dense = Float64[1.0, 0.0, 2.0, 4.0, 0.0, 3.0] +M_dense = Float64[1.0, 0.0, 2.0, 0.0, 0.0, 1.0] +H_diag = Float64[1.0, 0.0, 2.0] +M_diag = Float64[1.0, 2.0, 1.0] +f = 0.96 +power = 3.0 +weight = 1.0 +c = Float64[0.0, 2.0, 0.0] + +st = ' ' +status = Ref{Cint}() +x = zeros(Float64, n) +char ma[3] + +@printf(" Fortran sparse matrix indexing\n\n") + +@printf(" basic tests of storage formats\n\n") + +for a_is = 0:1 # add a linear constraint? + for m_is = 0:1 # include a scaling matrix? + +if (a_is == 1 m_is == 1) { + strcpy(ma, "MA") + +elseif (a_is == 1) { + strcpy(ma, "A ") + +elseif (m_is == 1) { + strcpy(ma, "M ") + +else { + strcpy(ma, " ") +for(int storage_type=1 storage_type <= 4 storage_type++) + + # Initialize RQS + rqs_initialize(data, control, status) + + # Set user-defined control options + control[].f_indexing = true # fortran sparse matrix indexing + + switch(storage_type) + # sparse co-ordinate storage +if d == 1 + st = 'C' + # import the control parameters and structural data + rqs_import(control, data, status, n, + "coordinate", H_ne, H_row, H_col, Cint[]) + if (m_is == 1) { +rqs_import_m(data, status, n, + "coordinate", M_ne, M_row, M_col, Cint[]) + ] + if (a_is == 1) { +rqs_import_a(data, status, m, + "coordinate", A_ne, A_row, A_col, Cint[]) + ] + # solve the problem + if (a_is == 1 m_is == 1) { +rqs_solve_problem(data, status, n, + power, weight, f, c, H_ne, H_val, x, + M_ne, M_val, m, A_ne, A_val, Cint[]) + ] + elseif (a_is == 1) { +rqs_solve_problem(data, status, n, + power, weight, f, c, H_ne, H_val, x, + 0, Cint[], m, A_ne, A_val, Cint[]) + ] + elseif (m_is == 1) { +rqs_solve_problem(data, status, n, + power, weight, f, c, H_ne, H_val, x, + M_ne, M_val, 0, 0, Cint[], Cint[]) + ] + else { +rqs_solve_problem(data, status, n, + power, weight, f, c, H_ne, H_val, x, + 0, Cint[], 0, 0, Cint[], Cint[]) + ] + end + @printf(" case %1i break\n", storage_type) + # sparse by rows +if d == 2 + st = 'R' + # import the control parameters and structural data + rqs_import(control, data, status, n, + "sparse_by_rows", H_ne, Cint[], H_col, H_ptr) + if (m_is == 1) { +rqs_import_m(data, status, n, + "sparse_by_rows", M_ne, Cint[], M_col, M_ptr) + ] + if (a_is == 1) { +rqs_import_a(data, status, m, + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + ] + # solve the problem + if (a_is == 1 m_is == 1) { +rqs_solve_problem(data, status, n, + power, weight, f, c, H_ne, H_val, x, + M_ne, M_val, m, A_ne, A_val, Cint[]) + ] + elseif (a_is == 1) { +rqs_solve_problem(data, status, n, + power, weight, f, c, H_ne, H_val, x, + 0, Cint[], m, A_ne, A_val, Cint[]) + ] + elseif (m_is == 1) { +rqs_solve_problem(data, status, n, + power, weight, f, c, H_ne, H_val, x, + M_ne, M_val, 0, 0, Cint[], Cint[]) + ] + else { +rqs_solve_problem(data, status, n, + power, weight, f, c, H_ne, H_val, x, + 0, Cint[], 0, 0, Cint[], Cint[]) + ] + end + # dense +if d == 3 + st = 'D' + # import the control parameters and structural data + rqs_import(control, data, status, n, + "dense", H_ne, Cint[], Cint[], Cint[]) + if (m_is == 1) { +rqs_import_m(data, status, n, + "dense", M_ne, Cint[], Cint[], Cint[]) + ] + if (a_is == 1) { +rqs_import_a(data, status, m, + "dense", A_ne, Cint[], Cint[], Cint[]) + ] + # solve the problem + if (a_is == 1 m_is == 1) { +rqs_solve_problem(data, status, n, power, weight, + f, c, H_dense_ne, H_dense, x, + M_dense_ne, M_dense, m, A_ne, A_val, + Cint[]) + ] + elseif (a_is == 1) { +rqs_solve_problem(data, status, n, power, weight, + f, c, H_dense_ne, H_dense, x, + 0, Cint[], m, A_ne, A_val, Cint[]) + ] + elseif (m_is == 1) { +rqs_solve_problem(data, status, n, power, weight, + f, c, H_dense_ne, H_dense, x, + M_dense_ne, M_dense, 0, 0, Cint[], Cint[]) + ] + else { +rqs_solve_problem(data, status, n, power, weight, + f, c, H_dense_ne, H_dense, x, + 0, Cint[], 0, 0, Cint[], Cint[]) + ] + end + # diagonal +if d == 4 + st = 'L' + # import the control parameters and structural data + rqs_import(control, data, status, n, + "diagonal", H_ne, Cint[], Cint[], Cint[]) + if (m_is == 1) { +rqs_import_m(data, status, n, + "diagonal", M_ne, Cint[], Cint[], Cint[]) + ] + if (a_is == 1) { +rqs_import_a(data, status, m, + "dense", A_ne, Cint[], Cint[], Cint[]) + ] + # solve the problem + if (a_is == 1 m_is == 1) { +rqs_solve_problem(data, status, n, + power, weight, f, c, n, H_diag, x, + n, M_diag, m, A_ne, A_val, Cint[]) + ] + elseif (a_is == 1) { +rqs_solve_problem(data, status, n, + power, weight, f, c, n, H_diag, x, + 0, Cint[], m, A_ne, A_val, Cint[]) + ] + elseif (m_is == 1) { +rqs_solve_problem(data, status, n, + power, weight, f, c, n, H_diag, x, + n, M_diag, 0, 0, Cint[], Cint[]) + ] + else { +rqs_solve_problem(data, status, n, + power, weight, f, c, n, H_diag, x, + 0, Cint[], 0, 0, Cint[], Cint[]) + ] + end + ] + + rqs_information(data, inform, status) + + @printf("format %c%s: RQS_solve_problem exit status = %1i, f = %.2f\n", + st, ma, inform[].status, inform[].obj_regularized) + # @printf("x: ") + # for(int i = 0 i < n+m i++) @printf("%f ", x[i]) + + # Delete internal workspace + rqs_terminate(data, control, inform) + ] +] + ] +] + +end + +@testset "RQS" begin + @test test_rqs() == 0 +end diff --git a/GALAHAD.jl/test/test_slls.jl b/GALAHAD.jl/test/test_slls.jl index e69de29bb2..647cc20c3e 100644 --- a/GALAHAD.jl/test/test_slls.jl +++ b/GALAHAD.jl/test/test_slls.jl @@ -0,0 +1,353 @@ +# test_slls.jl +# Simple code to test the Julia interface to SLLS + +using GALAHAD +using Test +using Printf +using Accessors + +# Custom userdata struct +struct userdata_type + scale::Float64 +end + +function test_slls() + # Apply preconditioner + function prec(n, var::Vector{Float64}, p::Vector{Float64}, userdata::userdata_type) + scale = userdata.scale + for i in 1:n + p[i] = scale * v[i] + end + return 0 + end + + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{slls_control_type{Float64}}() + inform = Ref{slls_inform_type{Float64}}() + + # Set user data + userdata = userdata_type(1.0) + + # Set problem data + n = 10 # dimension + o = n + 1 # number of residuals + Ao_ne = 2 * n # sparse Jacobian elements + Ao_dense_ne = o * n # dense Jacobian elements + # row-wise storage + Ao_row = zeros(Cint, Ao_ne) # row indices, + Ao_col = zeros(Cint, Ao_ne) # column indices + Ao_ptr_ne = o + 1 # row pointer length + Ao_ptr = zeros(Cint, Ao_ptr_ne) # row pointers + Ao_val = zeros(Float64, Ao_ne) # values + Ao_dense = zeros(Float64, Ao_dense_ne) # dense values + # column-wise storage + Ao_by_col_row = zeros(Cint, Ao_ne) # row indices, + Ao_by_col_ptr_ne = n + 1 # column pointer length + Ao_by_col_ptr = zeros(Cint, Ao_by_col_ptr_ne) # column pointers + Ao_by_col_val = zeros(Float64, Ao_ne) # values + Ao_by_col_dense = zeros(Float64, Ao_dense_ne) # dense values + b = zeros(Float64, o) # linear term in the objective + x = zeros(Float64, n) # variables + z = zeros(Float64, n) # dual variables + r = zeros(Float64, o) # residual + g = zeros(Float64, n) # gradient + + # Set output storage + x_stat = zeros(Cint, n) # variable status + st = "" + status = Ref{Cint}() + + # A = ( I ) and b = (i * e) + # (e^T) (n + 1) + + for i in 1:n + b[i] = i + end + b[n + 1] = n + 1 + + # A by rows + for i in 1:n + Ao_ptr[i] = i + Ao_row[i] = i + Ao_col[i] = i + Ao_val[i] = 1.0 + end + Ao_ptr[n + 1] = n + 1 + for i in 1:n + Ao_row[n + i] = o + Ao_col[n + i] = i + Ao_val[n + i] = 1.0 + end + Ao_ptr[o + 1] = Ao_ne + 1 + l = 0 + for i in 1:n + for j in 1:n + l = l + 1 + if i == j + Ao_dense[l] = 1.0 + else + Ao_dense[l] = 0.0 + end + end + end + for j in 1:n + l = l + 1 + Ao_dense[l] = 1.0 + end + + # # A by columns + l = 0 + for j in 1:n + l = l + 1 + Ao_by_col_ptr[j] = l + Ao_by_col_row[l] = j + Ao_by_col_val[l] = 1.0 + l = l + 1 + Ao_by_col_row[l] = o + Ao_by_col_val[l] = 1.0 + end + Ao_by_col_ptr[n + 1] = Ao_ne + l = 0 + for j in 1:n + for i in 1:n + l = l + 1 + if i == j + Ao_by_col_dense[l] = 1.0 + else + Ao_by_col_dense[l] = 0.0 + end + end + l = l + 1 + Ao_by_col_dense[l] = 1.0 + end + + @printf(" fortran sparse matrix indexing\n\n") + @printf(" basic tests of slls storage formats\n\n") + + for d in 1:5 + # Initialize SLLS + slls_initialize(data, control, status) + + # Set user-defined control options + @reset control[].f_indexing = true # fortran sparse matrix indexing + + # Start from 0 + for i in 1:n + x[i] = 0.0 + z[i] = 0.0 + end + + # sparse co-ordinate storage + if d == 1 + st = "CO" + slls_import(control, data, status, n, o, + "coordinate", Ao_ne, Ao_row, Ao_col, 0, Cint[]) + + slls_solve_given_a(data, userdata, status, n, o, Ao_ne, Ao_val, b, x, z, r, g, x_stat, + prec) + end + + # sparse by rows + if d == 2 + st = "SR" + slls_import(control, data, status, n, o, + "sparse_by_rows", Ao_ne, Cint[], Ao_col, + Ao_ptr_ne, Ao_ptr) + + slls_solve_given_a(data, userdata, status, n, o, Ao_ne, Ao_val, b, x, z, r, g, x_stat, + prec) + end + + # dense by rows + if d == 3 + st = "DR" + slls_import(control, data, status, n, o, + "dense_by_rows", Ao_dense_ne, + Cint[], Cint[], 0, Cint[]) + + slls_solve_given_a(data, userdata, status, n, o, + Ao_dense_ne, Ao_dense, b, + x, z, r, g, x_stat, prec) + end + + # sparse by columns + if d == 4 + st = "SC" + slls_import(control, data, status, n, o, + "sparse_by_columns", Ao_ne, Ao_by_col_row, + Cint[], Ao_by_col_ptr_ne, Ao_by_col_ptr) + + slls_solve_given_a(data, userdata, status, n, o, + Ao_ne, Ao_by_col_val, b, + x, z, r, g, x_stat, prec) + end + + # dense by columns + if d == 5 + st = "DC" + slls_import(control, data, status, n, o, + "dense_by_columns", Ao_dense_ne, + Cint[], Cint[], 0, Cint[]) + + slls_solve_given_a(data, userdata, status, n, o, Ao_dense_ne, Ao_by_col_dense, b, + x, z, r, g, x_stat, prec) + end + + slls_information(data, inform, status) + + if inform[].status == 0 + @printf("%s:%6i iterations. Optimal objective value = %5.2f status = %1i\n", + st, inform[].iter, inform[].obj, inform[].status) + else + @printf("%s: SLLS_solve exit status = %1i\n", st, inform[].status) + end + + # @printf("x: ") + # for i = 1:n + # @printf("%f ", x[i]) + # end + # @printf("\n") + # @printf("gradient: ") + # for i = 1:n + # @printf("%f ", g[i]) + # end + # @printf("\n") + + # Delete internal workspace + slls_terminate(data, control, inform) + end + + @printf("\n tests reverse-communication options\n\n") + # reverse-communication input/output + on = max(o, n) + eval_status = Ref{Cint}() + nz_v_start = Ref{Cint}() + nz_v_end = Ref{Cint}() + nz_p_end = Ref{Cint}() + nz_v = Vector(Cint, on) + nz_p = Vector(Cint, o) + mask = Vector(Cint, o) + v = Vector(Float64, on) + p = Vector(Float64, on) + + nz_p_end = 0 + + # Initialize SLLS + slls_initialize(data, control, status) + + # Set user-defined control options + @reset control[].f_indexing = true # fortran sparse matrix indexing + + # Start from 0 + for i in 1:n + x[i] = 0.0 + z[i] = 0.0 + end + + st = "RC" + for i in 1:o + mask[i] = 0 + end + + slls_import_without_a(control, data, status, n, o) + + terminated = false + while !terminated # reverse-communication loop + slls_solve_reverse_a_prod(data, status, eval_status, n, o, b, + x, z, r, g, x_stat, v, p, + nz_v, nz_v_start, nz_v_end, + nz_p, nz_p_end) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # evaluate p = Av + p[n + 1] = 0.0 + for i in 1:n + p[i] = v[i] + p[n + 1] = p[n + 1] + v[i] + end + elseif status[] == 3 # evaluate p = A^Tv + for i in 1:n + p[i] = v[i] + v[n + 1] + end + elseif status[] == 4 # evaluate p = Av for sparse v + p[n + 1] = 0.0 + for i in 1:n + p[i] = 0.0 + end + for l in nz_v_start:nz_v_end + i = nz_v[l] - 1 + p[i] = v[i] + p[n + 1] = p[n + 1] + v[i] + end + elseif status[] == 5 # evaluate p = sparse Av for sparse v + nz_p_end = 1 + for l in nz_v_start:nz_v_end + i = nz_v[l] - 1 + if mask[i] == 0 + mask[i] = 1 + nz_p[nz_p_end] = i + 1 + nz_p_end = nz_p_end + 1 + p[i] = v[i] + end + if mask[n] == 0 + mask[n] = 1 + nz_p[nz_p_end] = o + nz_p_end = nz_p_end + 1 + p[n] = v[i] + else + p[n] = p[n] + v[i] + end + end + for l in 1:nz_p_end + mask[nz_p[l]] = 0 + end + elseif status[] == 6 # evaluate p = sparse A^Tv + for l in nz_v_start:nz_v_end + i = nz_v[l] - 1 + p[i] = v[i] + v[n] + end + elseif status[] == 7 # evaluate p = P^{-}v + for i in 1:n + p[i] = userdata.scale * v[i] + end + else + @printf(" the value %1i of status should not occur\n", status) + end + + eval_status[] = 0 + end + + # Record solution information + slls_information(data, inform, status) + + # Print solution details + if inform[].status == 0 + @printf("%s:%6i iterations. Optimal objective value = %5.2f status = %1i\n", + st, inform[].iter, inform[].obj, inform[].status) + else + @printf("%s: SLLS_solve exit status = %1i\n", st, inform[].status) + end + + # @printf("x: ") + # for i = 1:n + # @printf("%f ", x[i]) + # end + # @printf("\n") + # @printf("gradient: ") + # for i = 1:n + # @printf("%f ", g[i]) + # end + # @printf("\n") + + # Delete internal workspace + slls_terminate(data, control, inform) + + return 0 +end + +@testset "SLLS" begin + @test test_slls() == 0 +end diff --git a/GALAHAD.jl/test/test_trs.jl b/GALAHAD.jl/test/test_trs.jl index f1c9130a46..48a5780a55 100644 --- a/GALAHAD.jl/test/test_trs.jl +++ b/GALAHAD.jl/test/test_trs.jl @@ -2,233 +2,239 @@ # Simple code to test the Julia interface to TRS using GALAHAD +using Test using Printf - -# Derived types -data = [Ptr{Ptr{Cvoid}}()] -control = trs_control_type{Float64}() -inform = trs_inform_type{Float64}() - -# Set problem data -n = 3 # dimension of H -m = 1 # dimension of A -H_ne = 4 # number of elements of H -M_ne = 3 # number of elements of M -A_ne = 3 # number of elements of A -H_dense_ne = 6 # number of elements of H -M_dense_ne = 6 # number of elements of M -H_row = Cint[1, 2, 3, 3] # row indices, NB lower triangle -H_col = Cint[1, 2, 3, 1] -H_ptr = Cint[1, 2, 3, 5] -M_row = Cint[1, 2, 3] # row indices, NB lower triangle -M_col = Cint[1, 2, 3] -M_ptr = Cint[1, 2, 3, 4] -A_row = Cint[1, 1, 1] -A_col = Cint[1, 2, 3] -A_ptr = Cint[1, 4] -H_val = Float64[1.0, 2.0, 3.0, 4.0] -M_val = Float64[1.0, 2.0, 1.0] -A_val = Float64[1.0, 1.0, 1.0] -H_dense = Float64[1.0, 0.0, 2.0, 4.0, 0.0, 3.0] -M_dense = Float64[1.0, 0.0, 2.0, 0.0, 0.0, 1.0] -H_diag = Float64[1.0, 0.0, 2.0] -M_diag = Float64[1.0, 2.0, 1.0] -f = 0.96 -radius = 1.0 -c = Float64[0.0, 2.0, 0.0] - -st = ' ' -status = Ref{Cint}() -x = zeros(Float64, n) -ma = NTuple{3, Cchar}((32, 32, 32)) - -@printf(" Fortran sparse matrix indexing\n\n") -@printf(" basic tests of storage formats\n\n") - -for a_is = 0:1 # add a linear constraint? - for m_is = 0:1 # include a scaling matrix? - - if (a_is == 1) && (m_is == 1) - strcpy(ma, "MA") - - elseif (a_is == 1) - strcpy(ma, "A ") - - elseif (m_is == 1) - strcpy(ma, "M ") - - else - strcpy(ma, " ") - end - - for storage_type = 1:4 - # Initialize TRS - trs_initialize( data, control, status ) - - # Set user-defined control options - control.f_indexing = true # fortran sparse matrix indexing - - # sparse co-ordinate storage - if d == 1 - global st = 'C' - - # import the control parameters and structural data - trs_import( control, data, status, n, - "coordinate", H_ne, H_row, H_col, Cint[] ) - - if m_is == 1 - trs_import_m( data, status, n, - "coordinate", M_ne, M_row, M_col, Cint[] ) - end - - if a_is == 1 - trs_import_a( data, status, m, - "coordinate", A_ne, A_row, A_col, Cint[] ) - end - - # solve the problem - if (a_is == 1) && (m_is == 1) - trs_solve_problem( data, status, n, - radius, f, c, H_ne, H_val, x, - M_ne, M_val, m, A_ne, A_val, Cint[] ) - elseif a_is == 1 - trs_solve_problem( data, status, n, - radius, f, c, H_ne, H_val, x, - 0, Cint[], m, A_ne, A_val, Cint[] ) - elseif m_is == 1 - trs_solve_problem( data, status, n, - radius, f, c, H_ne, H_val, x, - M_ne, M_val, 0, 0, Cint[], Cint[] ) - else - trs_solve_problem( data, status, n, - radius, f, c, H_ne, H_val, x, - 0, Cint[], 0, 0, Cint[], Cint[] ) - end - end - - # sparse by rows - if d == 2 - global st = 'R' - - # import the control parameters and structural data - trs_import( control, data, status, n, - "sparse_by_rows", H_ne, Cint[], H_col, H_ptr ) - - if m_is == 1 - trs_import_m( data, status, n, - "sparse_by_rows", M_ne, Cint[], M_col, M_ptr ) - end - - if a_is == 1 - trs_import_a( data, status, m, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr ) - end - - # solve the problem +using Accessors + +function test_trs() + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{trs_control_type{Float64}}() + inform = Ref{trs_inform_type{Float64}}() + + # Set problem data + n = 3 # dimension of H + m = 1 # dimension of A + H_ne = 4 # number of elements of H + M_ne = 3 # number of elements of M + A_ne = 3 # number of elements of A + H_dense_ne = 6 # number of elements of H + M_dense_ne = 6 # number of elements of M + H_row = Cint[1, 2, 3, 3] # row indices, NB lower triangle + H_col = Cint[1, 2, 3, 1] + H_ptr = Cint[1, 2, 3, 5] + M_row = Cint[1, 2, 3] # row indices, NB lower triangle + M_col = Cint[1, 2, 3] + M_ptr = Cint[1, 2, 3, 4] + A_row = Cint[1, 1, 1] + A_col = Cint[1, 2, 3] + A_ptr = Cint[1, 4] + H_val = Float64[1.0, 2.0, 3.0, 4.0] + M_val = Float64[1.0, 2.0, 1.0] + A_val = Float64[1.0, 1.0, 1.0] + H_dense = Float64[1.0, 0.0, 2.0, 4.0, 0.0, 3.0] + M_dense = Float64[1.0, 0.0, 2.0, 0.0, 0.0, 1.0] + H_diag = Float64[1.0, 0.0, 2.0] + M_diag = Float64[1.0, 2.0, 1.0] + f = 0.96 + radius = 1.0 + c = Float64[0.0, 2.0, 0.0] + + st = ' ' + status = Ref{Cint}() + x = zeros(Float64, n) + ma = "" + + @printf(" Fortran sparse matrix indexing\n\n") + @printf(" basic tests of storage formats\n\n") + + for a_is in 0:1 # add a linear constraint? + for m_is in 0:1 # include a scaling matrix? if (a_is == 1) && (m_is == 1) - trs_solve_problem( data, status, n, - radius, f, c, H_ne, H_val, x, - M_ne, M_val, m, A_ne, A_val, Cint[] ) + ma = "MA" elseif a_is == 1 - trs_solve_problem( data, status, n, - radius, f, c, H_ne, H_val, x, - 0, Cint[], m, A_ne, A_val, Cint[] ) + ma = "A " elseif m_is == 1 - trs_solve_problem( data, status, n, - radius, f, c, H_ne, H_val, x, - M_ne, M_val, 0, 0, Cint[], Cint[] ) + ma = "M " else - trs_solve_problem( data, status, n, - radius, f, c, H_ne, H_val, x, - 0, Cint[], 0, 0, Cint[], Cint[] ) + ma = " " end - end - - # dense - if d == 3 - global st = 'D' - - # import the control parameters and structural data - trs_import( control, data, status, n, - "dense", H_ne, Cint[], Cint[], Cint[] ) - if m_is == 1 - trs_import_m( data, status, n, - "dense", M_ne, Cint[], Cint[], Cint[] ) - end + for storage_type in 1:4 + # Initialize TRS + trs_initialize(data, control, status) + + # Set user-defined control options + @reset control[].f_indexing = true # fortran sparse matrix indexing + + # sparse co-ordinate storage + if storage_type == 1 + st = 'C' + # import the control parameters and structural data + trs_import(control, data, status, n, + "coordinate", H_ne, H_row, H_col, Cint[]) + + if m_is == 1 + trs_import_m(data, status, n, + "coordinate", M_ne, M_row, M_col, Cint[]) + end + + if a_is == 1 + trs_import_a(data, status, m, + "coordinate", A_ne, A_row, A_col, Cint[]) + end + + # solve the problem + if (a_is == 1) && (m_is == 1) + trs_solve_problem(data, status, n, + radius, f, c, H_ne, H_val, x, + M_ne, M_val, m, A_ne, A_val, Cint[]) + elseif a_is == 1 + trs_solve_problem(data, status, n, + radius, f, c, H_ne, H_val, x, + 0, Cint[], m, A_ne, A_val, Cint[]) + elseif m_is == 1 + trs_solve_problem(data, status, n, + radius, f, c, H_ne, H_val, x, + M_ne, M_val, 0, 0, Cint[], Cint[]) + else + trs_solve_problem(data, status, n, + radius, f, c, H_ne, H_val, x, + 0, Cint[], 0, 0, Cint[], Cint[]) + end + end - if a_is == 1 - trs_import_a( data, status, m, - "dense", A_ne, Cint[], Cint[], Cint[] ) - end + # sparse by rows + if storage_type == 2 + st = 'R' + # import the control parameters and structural data + trs_import(control, data, status, n, + "sparse_by_rows", H_ne, Cint[], H_col, H_ptr) + + if m_is == 1 + trs_import_m(data, status, n, + "sparse_by_rows", M_ne, Cint[], M_col, M_ptr) + end + + if a_is == 1 + trs_import_a(data, status, m, + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + end + + # solve the problem + if (a_is == 1) && (m_is == 1) + trs_solve_problem(data, status, n, + radius, f, c, H_ne, H_val, x, + M_ne, M_val, m, A_ne, A_val, Cint[]) + elseif a_is == 1 + trs_solve_problem(data, status, n, + radius, f, c, H_ne, H_val, x, + 0, Cint[], m, A_ne, A_val, Cint[]) + elseif m_is == 1 + trs_solve_problem(data, status, n, + radius, f, c, H_ne, H_val, x, + M_ne, M_val, 0, 0, Cint[], Cint[]) + else + trs_solve_problem(data, status, n, + radius, f, c, H_ne, H_val, x, + 0, Cint[], 0, 0, Cint[], Cint[]) + end + end - # solve the problem - if (a_is == 1) && (m_is == 1) - trs_solve_problem( data, status, n, - radius, f, c, H_dense_ne, H_dense, x, - M_dense_ne, M_dense, m, A_ne, A_val, Cint[] ) - elseif a_is == 1 - trs_solve_problem( data, status, n, - radius, f, c, H_dense_ne, H_dense, x, - 0, Cint[], m, A_ne, A_val, Cint[] ) - elseif m_is == 1 - trs_solve_problem( data, status, n, - radius, f, c, H_dense_ne, H_dense, x, - M_dense_ne, M_dense, 0, 0, Cint[], Cint[] ) - else - trs_solve_problem( data, status, n, - radius, f, c, H_dense_ne, H_dense, x, - 0, Cint[], 0, 0, Cint[], Cint[] ) - end - end + # dense + if storage_type == 3 + st = 'D' + # import the control parameters and structural data + trs_import(control, data, status, n, + "dense", H_ne, Cint[], Cint[], Cint[]) + + if m_is == 1 + trs_import_m(data, status, n, + "dense", M_ne, Cint[], Cint[], Cint[]) + end + + if a_is == 1 + trs_import_a(data, status, m, + "dense", A_ne, Cint[], Cint[], Cint[]) + end + + # solve the problem + if (a_is == 1) && (m_is == 1) + trs_solve_problem(data, status, n, + radius, f, c, H_dense_ne, H_dense, x, + M_dense_ne, M_dense, m, A_ne, A_val, + Cint[]) + elseif a_is == 1 + trs_solve_problem(data, status, n, + radius, f, c, H_dense_ne, H_dense, x, + 0, Cint[], m, A_ne, A_val, Cint[]) + elseif m_is == 1 + trs_solve_problem(data, status, n, + radius, f, c, H_dense_ne, H_dense, x, + M_dense_ne, M_dense, 0, 0, Cint[], Cint[]) + else + trs_solve_problem(data, status, n, + radius, f, c, H_dense_ne, H_dense, x, + 0, Cint[], 0, 0, Cint[], Cint[]) + end + end - # diagonal - if d == 4 - global st = 'L' + # diagonal + if storage_type == 4 + st = 'L' + # import the control parameters and structural data + trs_import(control, data, status, n, + "diagonal", H_ne, Cint[], Cint[], Cint[]) + + if m_is == 1 + trs_import_m(data, status, n, + "diagonal", M_ne, Cint[], Cint[], Cint[]) + end + + if a_is == 1 + trs_import_a(data, status, m, + "dense", A_ne, Cint[], Cint[], Cint[]) + end + + # solve the problem + if (a_is == 1) && (m_is == 1) + trs_solve_problem(data, status, n, + radius, f, c, n, H_diag, x, + n, M_diag, m, A_ne, A_val, Cint[]) + elseif a_is == 1 + trs_solve_problem(data, status, n, + radius, f, c, n, H_diag, x, + 0, Cint[], m, A_ne, A_val, Cint[]) + elseif m_is == 1 + trs_solve_problem(data, status, n, + radius, f, c, n, H_diag, x, + n, M_diag, 0, 0, Cint[], Cint[]) + else + trs_solve_problem(data, status, n, + radius, f, c, n, H_diag, x, + 0, Cint[], 0, 0, Cint[], Cint[]) + end + end - # import the control parameters and structural data - trs_import( control, data, status, n, - "diagonal", H_ne, Cint[], Cint[], Cint[] ) + trs_information(data, inform, status) - if m_is == 1 - trs_import_m( data, status, n, - "diagonal", M_ne, Cint[], Cint[], Cint[] ) - end + @printf("format %c%s: TRS_solve_problem exit status = %1i, f = %.2f\n", st, ma, + inform[].status, inform[].obj) - if a_is == 1 - trs_import_a( data, status, m, - "dense", A_ne, Cint[], Cint[], Cint[] ) - end + # @printf("x: ") + # for i = 1:n+m + # @printf("%f ", x[i]) + # end - # solve the problem - if (a_is == 1) && (m_is == 1) - trs_solve_problem( data, status, n, - radius, f, c, n, H_diag, x, - n, M_diag, m, A_ne, A_val, Cint[] ) - elseif a_is == 1 - trs_solve_problem( data, status, n, - radius, f, c, n, H_diag, x, - 0, Cint[], m, A_ne, A_val, Cint[] ) - elseif m_is == 1 - trs_solve_problem( data, status, n, - radius, f, c, n, H_diag, x, - n, M_diag, 0, 0, Cint[], Cint[] ) - else - trs_solve_problem( data, status, n, - radius, f, c, n, H_diag, x, - 0, Cint[], 0, 0, Cint[], Cint[] ) + # Delete internal workspace + trs_terminate(data, control, inform) end end + end - trs_information( data, inform, status ) - - @printf("format %c%s: TRS_solve_problem exit status = %1i, f = %.2f\n", st, ma, inform.status, inform.obj ) - # @printf("x: ") - # for i = 1:n+m - # @printf("%f ", x[i]) - # end + return 0 +end - # Delete internal workspace - trs_terminate( data, control, inform ) - end +@testset "TRS" begin + @test test_trs() == 0 end diff --git a/GALAHAD.jl/test/test_tru.jl b/GALAHAD.jl/test/test_tru.jl index e69de29bb2..45a4896ea8 100644 --- a/GALAHAD.jl/test/test_tru.jl +++ b/GALAHAD.jl/test/test_tru.jl @@ -0,0 +1,404 @@ +# test_tru.jl +# Simple code to test the Julia interface to TRU + +using GALAHAD +using Test +using Printf +using Accessors + +# Custom userdata struct +struct userdata_type + p::Float64 +end + +# Objective function +function fun(n, x::Vector{Float64}, f::Ref{Float64}, userdata::userdata_type) + p = userdata.p + f[] = (x[1] + x[3] + p)^2 + (x[2] + x[3])^2 + cos(x[1]) + return 0 +end + +# Gradient of the objective +function grad(n, x::Vector{Float64}, g::Vector{Float64}, userdata::userdata_type) + p = userdata.p + g[1] = 2.0 * (x[1] + x[3] + p) - sin(x[1]) + g[2] = 2.0 * (x[2] + x[3]) + g[3] = 2.0 * (x[1] + x[3] + p) + 2.0 * (x[2] + x[3]) + return 0 +end + +# Hessian of the objective +function hess(n, ne, x::Vector{Float64}, hval::Vector{Float64}, userdata::userdata_type) + hval[1] = 2.0 - cos(x[1]) + hval[2] = 2.0 + hval[3] = 2.0 + hval[4] = 2.0 + hval[5] = 4.0 + return 0 +end + +# Dense Hessian +function hess_dense(n, ne, x::Vector{Float64}, hval::Vector{Float64}, + userdata::userdata_type) + hval[1] = 2.0 - cos(x[1]) + hval[2] = 0.0 + hval[3] = 2.0 + hval[4] = 2.0 + hval[5] = 2.0 + hval[6] = 4.0 + return 0 +end + +# Hessian-vector product +function hessprod(n, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, + got_h::Bool, userdata::userdata_type) + u[1] = u[1] + 2.0 * (v[1] + v[3]) - cos(x[1]) * v[1] + u[2] = u[2] + 2.0 * (v[2] + v[3]) + u[3] = u[3] + 2.0 * (v[1] + v[2] + 2.0 * v[3]) + return 0 +end + +# Apply preconditioner +function prec(n, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, + userdata::userdata_type) + u[1] = 0.5 * v[1] + u[2] = 0.5 * v[2] + u[3] = 0.25 * v[3] + return 0 +end + +# Objective function +function fun_diag(n, x::Vector{Float64}, f::Ref{Float64}, userdata::userdata_type) + p = userdata.p + f[] = (x[3] + p)^2 + x[2]^2 + cos(x[1]) + return 0 +end + +# Gradient of the objective +function grad_diag(n, x::Vector{Float64}, g::Vector{Float64}, userdata::userdata_type) + p = userdata.p + g[1] = -sin(x[1]) + g[2] = 2.0 * x[2] + g[3] = 2.0 * (x[3] + p) + return 0 +end + +# Hessian of the objective +function hess_diag(n, ne, x::Vector{Float64}, hval::Vector{Float64}, + userdata::userdata_type) + hval[1] = -cos(x[1]) + hval[2] = 2.0 + hval[3] = 2.0 + return 0 +end + +# Hessian-vector product +function hessprod_diag(n, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, + got_h::Bool, userdata::userdata_type) + u[1] = u[1] + -cos(x[1]) * v[1] + u[2] = u[2] + 2.0 * v[2] + u[3] = u[3] + 2.0 * v[3] + return 0 +end + +function test_tru() + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{tru_control_type{Float64}}() + inform = Ref{tru_inform_type{Float64}}() + + # Set user data + userdata = userdata_type(4.0) + + # Set problem data + n = 3 # dimension + ne = 5 # Hesssian elements + H_row = Cint[1, 2, 3, 3, 3] # Hessian H + H_col = Cint[1, 2, 1, 2, 3] # NB lower triangle + H_ptr = Cint[1, 2, 3, 6] # row pointers + + # Set storage + g = zeros(Float64, n) # gradient + st = ' ' + status = Ref{Cint}() + + @printf(" Fortran sparse matrix indexing\n\n") + @printf(" tests options for all-in-one storage format\n\n") + + for d in 1:5 + # Initialize TRU + tru_initialize(data, control, status) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + # @reset control[].print_level = Cint(1) + + # Start from 1.5 + x = Float64[1.5, 1.5, 1.5] + + # sparse co-ordinate storage + if d == 1 + st = 'C' + tru_import(control, data, status, n, "coordinate", + ne, H_row, H_col, Cint[]) + + tru_solve_with_mat(data, userdata, status, + n, x, g, ne, fun, grad, hess, prec) + end + + # sparse by rows + if d == 2 + st = 'R' + tru_import(control, data, status, n, "sparse_by_rows", + ne, Cint[], H_col, H_ptr) + + tru_solve_with_mat(data, userdata, status, + n, x, g, ne, fun, grad, hess, prec) + end + + # dense + if d == 3 + st = 'D' + tru_import(control, data, status, n, "dense", + ne, Cint[], Cint[], Cint[]) + + tru_solve_with_mat(data, userdata, status, + n, x, g, ne, fun, grad, hess_dense, prec) + end + + # diagonal + if d == 4 + st = 'I' + tru_import(control, data, status, n, "diagonal", + ne, Cint[], Cint[], Cint[]) + + tru_solve_with_mat(data, userdata, status, n, x, g, + ne, fun_diag, grad_diag, hess_diag, prec) + end + + # access by products + if d == 5 + st = 'P' + tru_import(control, data, status, n, "absent", + ne, Cint[], Cint[], Cint[]) + + tru_solve_without_mat(data, userdata, status, + n, x, g, fun, grad, hessprod, prec) + end + + tru_information(data, inform, status) + + if inform[].status == 0 + @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", + st, inform[].iter, inform[].obj, inform[].status) + else + @printf("%c: TRU_solve exit status = %1i\n", st, inform[].status) + end + + # @printf("x: ") + # for i = 1:n + # @printf("%f ", x[i]) + # end + # @printf("\n") + # @printf("gradient: ") + # for i = 1:n + # @printf("%f ", g[i]) + # end + # @printf("\n") + + # Delete internal workspace + tru_terminate(data, control, inform) + end + + @printf("\n tests reverse-communication options\n\n") + # reverse-communication input/output + eval_status = Ref{Cint}() + f = 0.0 + u = zeros(Float64, n) + v = zeros(Float64, n) + index_nz_u = zeros(Cint, n) + index_nz_v = zeros(Cint, n) + H_val = zeros(Float64, ne) + H_dense = zeros(Float64, div(n * (n + 1), 2)) + H_diag = zeros(Float64, n) + + for d in 1:5 + # Initialize TRU + tru_initialize(data, control, status) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + # @reset control[].print_level = Cint(1) + # @reset control[].maxit = Cint(1) + + # Start from 1.5 + x = Float64[1.5, 1.5, 1.5] + + # sparse co-ordinate storage + if d == 1 + st = 'C' + tru_import(control, data, status, n, "coordinate", + ne, H_row, H_col, Cint[]) + + terminated = false + while !terminated # reverse-communication loop + tru_solve_reverse_with_mat(data, status, eval_status, + n, x, f, g, ne, H_val, u, v) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # evaluate f + eval_status[] = fun(n, x, f, userdata) + elseif status[] == 3 # evaluate g + eval_status[] = grad(n, x, g, userdata) + elseif status[] == 4 # evaluate H + eval_status[] = hess(n, ne, x, H_val, userdata) + elseif status[] == 6 # evaluate the product with P + eval_status[] = prec(n, x, u, v, userdata) + else + @printf(" the value %1i of status should not occur\n", status) + end + end + end + + # sparse by rows + if d == 2 + st = 'R' + tru_import(control, data, status, n, "sparse_by_rows", ne, + Cint[], H_col, H_ptr) + + terminated = false + while !terminated # reverse-communication loop + tru_solve_reverse_with_mat(data, status, eval_status, n, x, f, g, ne, H_val, u, v) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # evaluate f + eval_status[] = fun(n, x, f, userdata) + elseif status[] == 3 # evaluate g + eval_status[] = grad(n, x, g, userdata) + elseif status[] == 4 # evaluate H + eval_status[] = hess(n, ne, x, H_val, userdata) + elseif status[] == 6 # evaluate the product with P + eval_status[] = prec(n, x, u, v, userdata) + else + @printf(" the value %1i of status should not occur\n", status) + end + end + end + + # dense + if d == 3 + st = 'D' + tru_import(control, data, status, n, "dense", + ne, Cint[], Cint[], Cint[]) + + terminated = false + while !terminated # reverse-communication loop + tru_solve_reverse_with_mat(data, status, eval_status, + n, x, f, g, n * (n + 1) / 2, H_dense, u, v) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # evaluate f + eval_status[] = fun(n, x, f, userdata) + elseif status[] == 3 # evaluate g + eval_status[] = grad(n, x, g, userdata) + elseif status[] == 4 # evaluate H + eval_status[] = hess_dense(n, n * (n + 1) / 2, x, H_dense, userdata) + elseif status[] == 6 # evaluate the product with P + eval_status[] = prec(n, x, u, v, userdata) + else + @printf(" the value %1i of status should not occur\n", status) + end + end + end + + # diagonal + if d == 4 + st = 'I' + tru_import(control, data, status, n, "diagonal", + ne, Cint[], Cint[], Cint[]) + + terminated = false + while !terminated # reverse-communication loop + tru_solve_reverse_with_mat(data, status, eval_status, n, x, f, g, n, H_diag, u, v) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # evaluate f + eval_status[] = fun_diag(n, x, f, userdata) + elseif status[] == 3 # evaluate g + eval_status[] = grad_diag(n, x, g, userdata) + elseif status[] == 4 # evaluate H + eval_status[] = hess_diag(n, n, x, H_diag, userdata) + elseif status[] == 6 # evaluate the product with P + eval_status[] = prec(n, x, u, v, userdata) + else + @printf(" the value %1i of status should not occur\n", status) + end + end + end + + # access by products + if d == 5 + st = 'P' + tru_import(control, data, status, n, "absent", + ne, Cint[], Cint[], Cint[]) + + terminated = false + while !terminated # reverse-communication loop + tru_solve_reverse_without_mat(data, status, eval_status, + n, x, f, g, u, v) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # evaluate f + eval_status[] = fun(n, x, f, userdata) + elseif status[] == 3 # evaluate g + eval_status[] = grad(n, x, g, userdata) + elseif status[] == 5 # evaluate H + eval_status[] = hessprod(n, x, u, v, false, userdata) + elseif status[] == 6 # evaluate the product with P + eval_status[] = prec(n, x, u, v, userdata) + else + @printf(" the value %1i of status should not occur\n", status) + end + end + end + + tru_information(data, inform, status) + + if inform[].status == 0 + @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", st, + inform[].iter, inform[].obj, inform[].status) + else + @printf("%c: TRU_solve exit status = %1i\n", st, inform[].status) + end + + # @printf("x: ") + # for i = 1:n + # @printf("%f ", x[i]) + # end + # @printf("\n") + # @printf("gradient: ") + # for i = 1:n + # @printf("%f ", g[i]) + # end + # @printf("\n") + + # Delete internal workspace + tru_terminate(data, control, inform) + end + + return 0 +end + +@testset "TRU" begin + @test test_tru() == 0 +end diff --git a/GALAHAD.jl/test/test_uls.jl b/GALAHAD.jl/test/test_uls.jl index a262d4d58c..112e22811d 100644 --- a/GALAHAD.jl/test/test_uls.jl +++ b/GALAHAD.jl/test/test_uls.jl @@ -2,152 +2,183 @@ # Simple code to test the Julia interface to ULS using GALAHAD +using Test using Printf +using Accessors + +function test_uls() + maxabsarray(a) = maximum(abs.(a)) + + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{uls_control_type{Float64}}() + inform = Ref{uls_inform_type{Float64}}() + + # Set problem data + m = 5 # column dimension of A + n = 5 # column dimension of A + ne = 7 # number of entries of A + dense_ne = 25 # number of elements of A as a dense matrix + row = Cint[1, 2, 2, 3, 3, 4, 5] # row indices + col = Cint[1, 1, 5, 2, 3, 3, 4] # column indices + ptr = Cint[1, 2, 4, 6, 7, 8] # pointers to indices + val = Float64[2.0, 3.0, 6.0, 4.0, 1.0, 5.0, 1.0] # values + dense = Float64[2.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 6.0, 0.0, 4.0, 1.0, 0.0, 0.0, + 0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0] + rhs = Float64[2.0, 33.0, 11.0, 15.0, 4.0] + rhst = Float64[8.0, 12.0, 23.0, 5.0, 12.0] + sol = Float64[1.0, 2.0, 3.0, 4.0, 5.0] + status = Ref{Cint}() + x = zeros(Float64, n) + error = zeros(Float64, n) + good_x = eps(Float64)^(1 / 3) + + @printf(" Fortran sparse matrix indexing\n\n") + @printf(" basic tests of storage formats\n\n") + @printf(" storage RHS refine RHST refine\n") + + for d in 1:3 + # Initialize ULS - use the gls solver + uls_initialize("getr", data, control, status) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + + # sparse co-ordinate storage + if d == 1 + @printf(" coordinate ") + uls_factorize_matrix(control, data, status, m, n, + "coordinate", ne, val, row, col, Cint[]) + end -# Function maxabsarray -maxabsarray(a) = maximum(abs.(a)) - -# Derived types -data = [Ptr{Ptr{Cvoid}}()] -control = uls_control_type{Float64}() -inform = uls_inform_type{Float64}() - -# Set problem data -m = 5 # column dimension of A -n = 5 # column dimension of A -ne = 7 # number of entries of A -dense_ne = 25 # number of elements of A as a dense matrix -row = Cint[1, 2, 2, 3, 3, 4, 5] # row indices -col = Cint[1, 1, 5, 2, 3, 3, 4] # column indices -ptr = Cint[1, 2, 4, 6, 7, 8] # pointers to indices -val = Float64[2.0, 3.0, 6.0, 4.0, 1.0, 5.0, 1.0] # values -dense = Float64[2.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 6.0, - 0.0, 4.0, 1.0, 0.0, 0.0, 0.0, 0.0, 5.0, 0.0, 0.0, - 0.0, 0.0, 0.0, 1.0, 0.0] -rhs = Float64[2.0, 33.0, 11.0, 15.0, 4.0] -rhst = Float64[8.0, 12.0, 23.0, 5.0, 12.0] -sol = Float64[1.0, 2.0, 3.0, 4.0, 5.0] -x = zeros(Float64, n) -error = zeros(Float64, n) - -good_x = eps(Float64)^(1/3) - -@printf(" Fortran sparse matrix indexing\n\n") -@printf(" basic tests of storage formats\n\n") -@printf(" storage RHS refine RHST refine\n") - -for d = 1:3 - # Initialize ULS - use the gls solver - uls_initialize( "getr", data, control, status ) - - # Set user-defined control options - control.f_indexing = true # Fortran sparse matrix indexing - - # sparse co-ordinate storage - if d == 1 - @printf(" coordinate ") - uls_factorize_matrix( control, data, status, m, n, - "coordinate", ne, val, row, col, Cint[] ) - end + # sparse by rows + if d == 2 + @printf(" sparse by rows ") + uls_factorize_matrix(control, data, status, m, n, + "sparse_by_rows", ne, val, Cint[], col, ptr) + end - # sparse by rows - if d == 2 - @printf(" sparse by rows ") - uls_factorize_matrix( control, data, status, m, n, - "sparse_by_rows", ne, val, Cint[], col, ptr ) - end + # dense + if d == 3 + @printf(" dense ") + uls_factorize_matrix(control, data, status, m, n, + "dense", dense_ne, dense, Cint[], Cint[], Cint[]) + end - # dense - if d == 3 - @printf(" dense ") - uls_factorize_matrix( control, data, status, m, n, - "dense", dense_ne, dense, Cint[], Cint[], Cint[] ) - end + # Set right-hand side and solve the system A x = b + for i in 1:n + x[i] = rhs[i] + end - # Set right-hand side and solve the system Ax = b - x .= rhs - trans = false - uls_solve_system( data, status, m, n, x, trans ) - uls_information( data, inform, status ) - - if inform.status == 0 - error .= x .- sol - norm_residual = maxabsarray(error) - if norm_residual < good_x - @printf(" ok ") + trans = false + uls_solve_system(data, status, m, n, x, trans) + uls_information(data, inform, status) + + if inform[].status == 0 + for i in 1:n + error[i] = x[i] - sol[i] + end + norm_residual = maxabsarray(error) + if norm_residual < good_x + @printf(" ok ") + else + @printf(" fail ") + end else - @printf(" fail ") + @printf(" ULS_solve exit status = %1i\n", inform[].status) + end + + # @printf("sol: ") + # for i = 1:n + # @printf("%f ", x[i]) + # end + + # resolve, this time using iterative refinement + @reset control[].max_iterative_refinements = Cint(1) + uls_reset_control(control, data, status) + + for i in 1:n + x[i] = rhs[i] end - else - @printf(" ULS_solve exit status = %1i\n", inform.status) - end - # @printf("sol: ") - # for i = 1:n - # @printf("%f ", x[i]) - # end - - # resolve, this time using iterative refinement - control.max_iterative_refinements = 1 - uls_reset_control( control, data, status ) - x .= rhs - uls_solve_system( data, status, m, n, x, trans ) - uls_information( data, inform, status ) - - if inform.status == 0 - error .= x .- sol - norm_residual = maxabsarray(error) - if norm_residual < good_x - @printf("ok ") + uls_solve_system(data, status, m, n, x, trans) + uls_information(data, inform, status) + + if inform[].status == 0 + for i in 1:n + error[i] = x[i] - sol[i] + end + norm_residual = maxabsarray(error) + if norm_residual < good_x + @printf("ok ") + else + @printf(" fail ") + end else - @printf(" fail ") + @printf(" ULS_solve exit status = %1i\n", inform[].status) + end + + # Set right-hand side and solve the system A^T x = b + for i in 1:n + x[i] = rhst[i] end - else - @printf(" ULS_solve exit status = %1i\n", inform.status) - end - # Set right-hand side and solve the system Aᵀx = b - x .= rhst - trans = true - uls_solve_system( data, status, m, n, x, trans ) - uls_information( data, inform, status ) - - if inform.status == 0 - error .= x .- sol - norm_residual = maxabsarray(error) - if norm_residual < good_x - @printf(" ok ") + trans = true + uls_solve_system(data, status, m, n, x, trans) + uls_information(data, inform, status) + + if inform[].status == 0 + for i in 1:n + error[i] = x[i] - sol[i] + end + norm_residual = maxabsarray(error) + if norm_residual < good_x + @printf(" ok ") + else + @printf(" fail ") + end else - @printf(" fail ") + @printf(" ULS_solve exit status = %1i\n", inform[].status) end - else - @printf(" ULS_solve exit status = %1i\n", inform.status) - end - # @printf("sol: ") - # for i = 1:n - # @printf("%f ", x[i]) - # end - - # resolve, this time using iterative refinement - control.max_iterative_refinements = 1 - uls_reset_control( control, data, status ) - x .= rhst - uls_solve_system( data, status, m, n, x, trans ) - uls_information( data, inform, status ) - - if inform.status == 0 - error .= x .- sol - norm_residual = maxabsarray(error) - if norm_residual < good_x - @printf("ok ") + # @printf("sol: ") + # for i = 1:n + # @printf("%f ", x[i]) + # end + + # resolve, this time using iterative refinement + @reset control[].max_iterative_refinements = Cint(1) + + uls_reset_control(control, data, status) + for i in 1:n + x[i] = rhst[i] + end + + uls_solve_system(data, status, m, n, x, trans) + uls_information(data, inform, status) + + if inform[].status == 0 + for i in 1:n + error[i] = x[i] - sol[i] + end + norm_residual = maxabsarray(error) + if norm_residual < good_x + @printf("ok ") + else + @printf(" fail ") + end else - @printf(" fail ") + @printf(" ULS_solve exit status = %1i\n", inform[].status) end - else - @printf(" ULS_solve exit status = %1i\n", inform.status) + + # Delete internal workspace + uls_terminate(data, control, inform) + @printf("\n") end - # Delete internal workspace - uls_terminate( data, control, inform ) + return 0 +end + +@testset "ULS" begin + @test test_uls() == 0 end From 916ec6709be84ce7d8b18f7dc89ac4c522b264f8 Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Mon, 12 Feb 2024 00:30:25 -0500 Subject: [PATCH 15/33] Update the generator in Julia wrappers for the new C headers --- GALAHAD.jl/gen/examples.jl | 42 +++++++++++++++++++------------------- GALAHAD.jl/gen/rewriter.jl | 8 +++++--- GALAHAD.jl/gen/wrapper.jl | 2 +- include/ssids_rip.hxx | 14 ++++++------- 4 files changed, 34 insertions(+), 32 deletions(-) diff --git a/GALAHAD.jl/gen/examples.jl b/GALAHAD.jl/gen/examples.jl index 50a564cf01..5ae658cbf8 100644 --- a/GALAHAD.jl/gen/examples.jl +++ b/GALAHAD.jl/gen/examples.jl @@ -40,37 +40,37 @@ function examples(package::String, example::String) "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, "real_wp_ $var[] = {" => "$var = Float64[") + text = replace(text, "rpc_ $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, "real_wp_ $var =" => "$var =") + text = replace(text, "rpc_ $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, "int $var =" => "$var =") + text = replace(text, "ipc_ $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, "int $var[] = {" => "$var = Cint[") + text = replace(text, "ipc_ $var[] = {" => "$var = Cint[") end for val in ("1", "3", "5", "6", "7", "n", "n+m") - 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") + 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") end for index in ("unit_m", "new_radius", "a_is", "m_is") - 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") + 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") end for val in ("c", "g", "u", "v", "x", "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)") + 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)") end for val in ("x_stat", "c_stat", "index_nz_u", "index_nz_v", "depen") - text = replace(text, "int $val[n]" => "$val = zeros(Cint, n)") - text = replace(text, "int $val[m]" => "$val = zeros(Cint, m)") + text = replace(text, "ipc_ $val[n]" => "$val = zeros(Cint, n)") + text = replace(text, "ipc_ $val[m]" => "$val = zeros(Cint, m)") end text = replace(text, "if(" => "if ") @@ -81,9 +81,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, "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, "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, " ]" => "]") text = replace(text, "== 0)" => "== 0") text = replace(text, "case 1: # sparse co-ordinate storage" => "# sparse co-ordinate storage\nif d == 1") @@ -94,14 +94,14 @@ 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, "int maxabsarray(real_wp_ a[], int n, real_wp_ *maxabs)" => "maxabsarray(a) = maximum(abs.(a))") + text = replace(text, "ipc_ maxabsarray(rpc_ a[], ipc_ n, rpc_ *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( 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( 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, "constrastatus = Ref{Cint}()" => "constraint status") text = replace(text, "}#" => "] #") text = replace(text, "#for" => "# for") @@ -113,8 +113,8 @@ function examples(package::String, example::String) text = replace(text, "for(i=0 i "for i = 1:n\n") text = replace(text, "}\n" => "end\n") for var in ("x", "u", "v", "hval", "g") - text = replace(text, "const real_wp_ $var[]" => "var::Vector{Float64}") - text = replace(text, "real_wp_ $var[]" => "$var::Vector{Float64}") + text = replace(text, "const rpc_ $var[]" => "var::Vector{Float64}") + text = replace(text, "rpc_ $var[]" => "$var::Vector{Float64}") end text = text * "end\n\n@testset \"" * uppercase(package) * "\" begin\n @test test_$package() == 0\nend\n" write(dst, text) diff --git a/GALAHAD.jl/gen/rewriter.jl b/GALAHAD.jl/gen/rewriter.jl index 2330d480e6..6b9b4970d3 100644 --- a/GALAHAD.jl/gen/rewriter.jl +++ b/GALAHAD.jl/gen/rewriter.jl @@ -21,6 +21,8 @@ function rewrite!(path::String, name::String, optimized::Bool) structures = "# Structures for $name\n" text = read(path, String) if optimized + text = replace(text, "ipc_" => "Cint") + text = replace(text, "longc_" => "Int64") text = replace(text, "real_sp_" => "Float32") text = replace(text, "\n " => "\n ") @@ -59,8 +61,8 @@ function rewrite!(path::String, name::String, optimized::Bool) routine_single = replace(routine_single, "libgalahad_double" => "libgalahad_single") routine_single = replace(routine_single, ",\n" => ",\n ") - routine_single = replace(routine_single, "real_wp_" => "Float32") - routine_double = replace(routine_double, "real_wp_" => "Float64") + routine_single = replace(routine_single, "rpc_" => "Float32") + routine_double = replace(routine_double, "rpc_" => "Float64") routine_single = replace(routine_single, "spral_ssids_options" => "spral_ssids_options{Float32}") routine_double = replace(routine_double, "spral_ssids_options" => "spral_ssids_options{Float64}") @@ -84,7 +86,7 @@ function rewrite!(path::String, name::String, optimized::Bool) elseif contains(code, "struct ") structure = code * "end\n" structure_name = split(split(code, "struct ")[2], "\n")[1] - structure = replace(structure, "real_wp_" => "T") + structure = replace(structure, "rpc_" => "T") if structure_name ∉ nonparametric_structures structure = replace(structure, structure_name => structure_name * "{T}") structures = structures * "Ref{$(structure_name){Float32}}()\n" diff --git a/GALAHAD.jl/gen/wrapper.jl b/GALAHAD.jl/gen/wrapper.jl index e67e0ce362..6511100911 100644 --- a/GALAHAD.jl/gen/wrapper.jl +++ b/GALAHAD.jl/gen/wrapper.jl @@ -16,7 +16,7 @@ function wrapper(name::String, headers::Vector{String}, optimized::Bool; targets options["general"]["library_name"] = "libgalahad_double" # options["general"]["extract_c_comment_style"] = "doxygen" options["general"]["output_file_path"] = joinpath("..", "src", "wrappers", "$(name).jl") - optimized && (options["general"]["output_ignorelist"] = ["real_wp_", "real_sp_"]) + optimized && (options["general"]["output_ignorelist"] = ["real_wp_", "real_sp_", "rpc_", "ipc_"]) args = get_default_args() push!(args, "-I$include_dir") push!(args, "-DGALAHAD_DOUBLE") diff --git a/include/ssids_rip.hxx b/include/ssids_rip.hxx index 6856b96f72..42481c5468 100644 --- a/include/ssids_rip.hxx +++ b/include/ssids_rip.hxx @@ -10,21 +10,21 @@ /* real precision employed */ #ifdef SPRAL_SINGLE -#define rpc_ float +typedef float rpc_; #else -#define rpc_ double +typedef double rpc_; #endif /* integer storage employed */ #ifdef INTEGER_64 -#define ipc_ int64_t -#define uipc_ uint64_t +typedef int64_t ipc_; +typedef uint64_t uipc_; #else -#define ipc_ int -#define uipc_ unsigned int +typedef int ipc_; +typedef unsigned int uipc_; #endif /* generic storage */ -#define longc_ int64_t +typedef int64_t longc_; From 939e2d7c90250eea65c6a8d0900dc88a767c714d Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Mon, 12 Feb 2024 12:57:16 -0500 Subject: [PATCH 16/33] Add a function galahad_linear_solver --- GALAHAD.jl/src/GALAHAD.jl | 3 +++ GALAHAD.jl/src/utils.jl | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 GALAHAD.jl/src/utils.jl diff --git a/GALAHAD.jl/src/GALAHAD.jl b/GALAHAD.jl/src/GALAHAD.jl index dc753d4df9..31323fa2bf 100644 --- a/GALAHAD.jl/src/GALAHAD.jl +++ b/GALAHAD.jl/src/GALAHAD.jl @@ -11,6 +11,9 @@ else const GALAHAD_INSTALLATION = "YGGDRASIL" end +# Utils. +include("utils.jl") + # packages without dependencies. include("wrappers/bsc.jl") include("wrappers/convert.jl") diff --git a/GALAHAD.jl/src/utils.jl b/GALAHAD.jl/src/utils.jl new file mode 100644 index 0000000000..afb64e2635 --- /dev/null +++ b/GALAHAD.jl/src/utils.jl @@ -0,0 +1,16 @@ +export galahad_linear_solver + +function galahad_linear_solver(solver::String) + nchar = length(solver) + (nchar > 30) && error("The solver can't have more than 30 characters.") + + result = zeros(Int8, 31) + for i in 1:nchar + result[i] = Cchar(solver[i]) + end + for i in nchar+1:30 + result[i] = Char(' ') + end + + return ntuple(i -> result[i], 31) +end From 0a07832811693422069ae4b4be307653d5d257c2 Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Mon, 12 Feb 2024 12:57:47 -0500 Subject: [PATCH 17/33] More tests for the Julia interfaces --- GALAHAD.jl/gen/examples.jl | 57 +-- GALAHAD.jl/test/UGO.SPC | 0 GALAHAD.jl/test/runtests.jl | 12 +- GALAHAD.jl/test/test_blls.jl | 393 ++++++++++++++++---- GALAHAD.jl/test/test_bllsb.jl | 21 +- GALAHAD.jl/test/test_clls.jl | 21 +- GALAHAD.jl/test/test_dgo.jl | 670 ++++++++++++++++++++++++++++++++++ GALAHAD.jl/test/test_dps.jl | 10 +- GALAHAD.jl/test/test_dqp.jl | 406 ++++++++++---------- GALAHAD.jl/test/test_eqp.jl | 62 +--- GALAHAD.jl/test/test_fdc.jl | 96 ++--- GALAHAD.jl/test/test_llsr.jl | 219 +++++++++++ GALAHAD.jl/test/test_llst.jl | 30 +- GALAHAD.jl/test/test_nls.jl | 2 +- GALAHAD.jl/test/test_psls.jl | 8 +- GALAHAD.jl/test/test_rqs.jl | 455 +++++++++++------------ GALAHAD.jl/test/test_trb.jl | 510 ++++++++++++++++++++++++++ GALAHAD.jl/test/test_ugo.jl | 5 +- 18 files changed, 2257 insertions(+), 720 deletions(-) create mode 100644 GALAHAD.jl/test/UGO.SPC diff --git a/GALAHAD.jl/gen/examples.jl b/GALAHAD.jl/gen/examples.jl index 5ae658cbf8..b83aa14dfa 100644 --- a/GALAHAD.jl/gen/examples.jl +++ b/GALAHAD.jl/gen/examples.jl @@ -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, "&" => "") @@ -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}}()") @@ -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 ") @@ -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") @@ -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") @@ -113,8 +122,8 @@ function examples(package::String, example::String) text = replace(text, "for(i=0 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) diff --git a/GALAHAD.jl/test/UGO.SPC b/GALAHAD.jl/test/UGO.SPC new file mode 100644 index 0000000000..e69de29bb2 diff --git a/GALAHAD.jl/test/runtests.jl b/GALAHAD.jl/test/runtests.jl index 4440d1e2eb..e913ee6bbf 100644 --- a/GALAHAD.jl/test/runtests.jl +++ b/GALAHAD.jl/test/runtests.jl @@ -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") @@ -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") @@ -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") @@ -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") diff --git a/GALAHAD.jl/test/test_blls.jl b/GALAHAD.jl/test/test_blls.jl index dda558113a..0b5d8bc813 100644 --- a/GALAHAD.jl/test/test_blls.jl +++ b/GALAHAD.jl/test/test_blls.jl @@ -2,107 +2,362 @@ # Simple code to test the Julia interface to BLLS using GALAHAD +using Test using Printf +using Accessors -# Derived types -data = [Ptr{Ptr{Cvoid}}()] -control = blls_control_type{Float64}() -inform = blls_inform_type{Float64}() - -# Set problem data -n = 3 # dimension -o = 4 # number of observations -Ao_ne = 7 # design matrix elements -Ao_row = Cint[1, 1, 2, 2, 3, 3, 4] # row indices -Ao_col = Cint[1, 2, 2, 1, 3, 2] # column indices -Ao_ptr_ne = o + 1 # row pointer length -Ao_ptr = Cint[1, 3, 5, 7, 8] # row pointers -Ao_val = Float64[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] # values -b = Float64[2.0, 2.0, 3.0, 1.0] # observations -x_l = Float64[-1.0, -Inf, -Inf] # variable lower bound -x_u = Float64[1.0, Inf, 2.0] # variable upper bound -sigma = 1.0 # regularization weight -w = Float64[1.0, 1.0, 1.0, 2.0] # values - -# Set output storage -r = zeros(Float64, o) # residuals -g = zeros(Float64, n) # gradient -x_stat = zeros(Cint, n) # variable status -st = ' ' -status = Ref{Cint}() - -@printf(" Fortran sparse matrix indexing\n\n") -@printf(" basic tests of blls storage formats\n\n") - -for d = 1:3 +# Custom userdata struct +struct userdata_type + scale::Float64 +end - # Initialize BLLS - blls_initialize( data, control, status ) +function test_blls() + # Apply preconditioner + function prec(n::Int, var::Vector{Float64}, p::Vector{Float64}, userdata::userdata_type) + scale = userdata.scale + for i in 1:n + p[i] = scale * v[i] + end + return 0 + end - # Set user-defined control options - control.f_indexing = true # Fortran sparse matrix indexing + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{blls_control_type{Float64}}() + inform = Ref{blls_inform_type{Float64}}() - # Start from 0 - x = Float64[0.0,0.0,0.0] - z = Float64[0.0,0.0,0.0] + # Set user data + userdata = userdata_type(1.0) - # sparse co-ordinate storage - if d == 1 - global st = 'C' + # Set problem data + n = 10 # dimension + o = n + 1 # number of residuals + Ao_ne = 2 * n # sparse Jacobian elements + Ao_dense_ne = o * n # dense Jacobian elements + # row-wise storage + Ao_row = zeros(Cint, Ao_ne) # row indices, + Ao_col = zeros(Cint, Ao_ne) # column indices + Ao_ptr_ne = o + 1 # number of row pointers + Ao_ptr = zeros(Cint, Ao_ptr_ne) # row pointers + Ao_val = zeros(Float64, Ao_ne) # values + Ao_dense = zeros(Float64, Ao_dense_ne) # dense values + # column-wise storage + Ao_by_col_row = zeros(Cint, Ao_ne) # row indices, + Ao_by_col_ptr_ne = n + 1 # number of column pointers + Ao_by_col_ptr = zeros(Cint, Ao_by_col_ptr_ne) # column pointers + Ao_by_col_val = zeros(Float64, Ao_ne) # values + Ao_by_col_dense = zeros(Float64, Ao_dense_ne) # dense values + b = zeros(Float64, o) # linear term in the objective + x_l = zeros(Float64, n) # variable lower bound + x_u = zeros(Float64, n) # variable upper bound + x = zeros(Float64, n) # variables + z = zeros(Float64, n) # dual variables + r = zeros(Float64, o) # residual + g = zeros(Float64, n) # gradient + w = zeros(Float64, o) # weights - blls_import( control, data, status, n, o, - "coordinate", Ao_ne, Ao_row, Ao_col, 0, Cint[] ) + # Set output storage + x_stat = zeros(Cint, n) # variable status + st = ' ' + status = Ref{Cint}() - blls_solve_blls_given_a( data, status, n, o, m, Ao_ne, Ao_val, b, sigma, - x_l, x_u, x, z, r, g, x_stat, w, nothing ) + x_l[1] = -1.0 + for i in 2:n + x_l[i] = -Inf + end + x_u[1] = 1.0 + x_u[2] = Inf + for i in 3:n + x_u[i] = 2.0 end - # sparse by rows - if d == 2 - global st = 'R' + # A = ( I ) and b = (i * e) + # (e^T) (n + 1) - blls_import( control, data, status, n, o, - "sparse_by_rows", Ao_ne, Cint[], Ao_col, Ao_ptr_ne, Ao_ptr ) + for i in 1:n + b[i] = i + 1 + end + b[n + 1] = n + 1 + w[1] = 2.0 + w[2] = 1.0 + for i in 3:o + w[i] = 1.0 + end - blls_solve_blls_given_a( data, status, n, o, Ao_ne, Ao_val, b, sigma, - x_l, x_u, x, z, r, g, x_stat, w, nothing ) + # # A by rows + for i in 1:n + Ao_ptr[i] = i + 1 + Ao_row[i] = i + 1 + Ao_col[i] = i + 1 + Ao_val[i] = 1.0 + end + Ao_ptr[n + 1] = n + 1 + for i in 1:n + Ao_row[n + i] = o + Ao_col[n + i] = i + 1 + Ao_val[n + i] = 1.0 end + Ao_ptr[o] = Ao_ne + 1 + l = 0 + for i in 1:n + for j in 1:n + l = l + 1 + if i == j + Ao_dense[l] = 1.0 + else + Ao_dense[l] = 0.0 + end + end + end + for j in 1:n + l = l + 1 + Ao_dense[l] = 1.0 + end + + # # A by columns + l = 0 + for j in 1:n + l = l + 1 + Ao_by_col_ptr[j] = l + 1 + Ao_by_col_row[l] = j + 1 + Ao_by_col_val[l] = 1.0 + l = l + 1 + Ao_by_col_row[l] = o + Ao_by_col_val[l] = 1.0 + end + Ao_by_col_ptr[n + 1] = Ao_ne + 1 + l = 0 + for j in 1:n + for i in 1:n + l = l + 1 + if i == j + Ao_by_col_dense[l] = 1.0 + else + Ao_by_col_dense[l] = 0.0 + end + end + l = l + 1 + Ao_by_col_dense[l] = 1.0 + end + + @printf(" fortran sparse matrix indexing\n\n") + @printf(" basic tests of blls storage formats\n\n") + + for d in 1:5 + + # Initialize BLLS + blls_initialize(data, control, status) + + # Set user-defined control options + @reset control[].f_indexing = true # fortran sparse matrix indexing + + # Start from 0 + for i in 1:n + x[i] = 0.0 + z[i] = 0.0 + end + + # sparse co-ordinate storage + if d == 1 + st = "CO" + blls_import(control, data, status, n, o, + "coordinate", Ao_ne, Ao_row, Ao_col, 0, Cint[]) + + blls_solve_given_a(data, userdata, status, n, o, + Ao_ne, Ao_val, b, x_l, x_u, + x, z, r, g, x_stat, w, prec) + end + + # sparse by rows + if d == 2 + st = "SR" + blls_import(control, data, status, n, o, + "sparse_by_rows", Ao_ne, Cint[], Ao_col, + Ao_ptr_ne, Ao_ptr) + + blls_solve_given_a(data, userdata, status, n, o, + Ao_ne, Ao_val, b, x_l, x_u, + x, z, r, g, x_stat, w, prec) + end - # dense - if d == 3 - global st = 'D' + # dense by rows + if d == 3 + st = "DR" + blls_import(control, data, status, n, o, + "dense_by_rows", Ao_dense_ne, + Cint[], Cint[], 0, Cint[]) - Ao_dense_ne = 12 # number of elements of Ao - Ao_dense = Float64[1.0, 1.0, 0.0, 0.0, 1.0, 1.0, - 1.0, 0.0, 1.0, 0.0, 1.0, 0.0] + blls_solve_given_a(data, userdata, status, n, o, + Ao_dense_ne, Ao_dense, b, x_l, x_u, + x, z, r, g, x_stat, w, prec) + end - blls_import( control, data, status, n, o, - "dense", Ao_ne, Cint[], Cint[], 0, Cint[] ) + # sparse by columns + if d == 4 + st = "SC" + blls_import(control, data, status, n, o, + "sparse_by_columns", Ao_ne, Ao_by_col_row, + Cint[], Ao_by_col_ptr_ne, Ao_by_col_ptr) - blls_solve_blls_given_a( data, status, n, o, Ao_dense_ne, Ao_dense, b, - sigma, x_l, x_u, x, z, r, g, x_stat, w, nothing ) + blls_solve_given_a(data, userdata, status, n, o, + Ao_ne, Ao_by_col_val, b, x_l, x_u, + x, z, r, g, x_stat, w, prec) + end + + # dense by columns + if d == 5 + st = "DC" + blls_import(control, data, status, n, o, + "dense_by_columns", Ao_dense_ne, + Cint[], Cint[], 0, Cint[]) + + blls_solve_given_a(data, userdata, status, n, o, + Ao_dense_ne, Ao_by_col_dense, b, x_l, x_u, + x, z, r, g, x_stat, w, prec) + end + + blls_information(data, inform, status) + + if inform[].status == 0 + @printf("%s:%6i iterations. Optimal objective value = %5.2f status = %1i\n", + st, inform[].iter, inform[].obj, inform[].status) + else + @printf("%s: BLLS_solve exit status = %1i\n", st, inform[].status) + end + + # @printf("x: ") + # for i = 1:n + # @printf("%f ", x[i]) + # @printf("\n") + # @printf("gradient: ") + # for i = 1:n + # @printf("%f ", g[i]) + # @printf("\n") + + # Delete internal workspace + blls_terminate(data, control, inform) + @printf("\n tests reverse-communication options\n\n") + end + + # reverse-communication input/output + on = max(o, n) + # int eval_status, nz_v_start, nz_v_end, nz_p_end + # int nz_v[on], nz_p[o], mask[o] + # real_wp_ v[on], p[on] + + nz_p_end = 0 + + # Initialize BLLS + blls_initialize(data, control, status) + + # Set user-defined control options + @reset control[].f_indexing = true # fortran sparse matrix indexing + + # Start from 0 + for i in 1:n + x[i] = 0.0 + z[i] = 0.0 + end + + st = "RC" + for i in 1:o + mask[i] = 0 end + blls_import_without_a(control, data, status, n, o) - blls_information( data, inform, status ) + terminated = false + while !terminated # reverse-communication loop + blls_solve_reverse_a_prod(data, status, eval_status, n, o, b, + x_l, x_u, x, z, r, g, x_stat, v, p, + nz_v, nz_v_start, nz_v_end, + nz_p, nz_p_end, w) - if inform.status == 0 - @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", st, inform.iter, inform.obj, inform.status) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # evaluate p = Av + p[n + 1] = 0.0 + for i in 1:n + p[i] = v[i] + p[n + 1] = p[n + 1] + v[i] + end + elseif status[] == 3 # evaluate p = A^Tv + for i in 1:n + p[i] = v[i] + v[n + 1] + end + elseif status[] == 4 # evaluate p = Av for sparse v + p[n + 1] = 0.0 + for i in 1:n + p[i] = 0.0 + end + for l in (nz_v_start - 1):nz_v_end + i = nz_v[l] + p[i] = v[i] + p[n + 1] = p[n + 1] + v[i] + end + elseif status[] == 5 # evaluate p = sparse Av for sparse v + nz_p_end = 0 + for l in (nz_v_start - 1):nz_v_end + i = nz_v[l] - 1 + if mask[i] == 0 + mask[i] = 1 + nz_p[nz_p_end] = i + 1 + nz_p_end = nz_p_end + 1 + p[i] = v[i] + end + if mask[n + 1] == 0 + mask[n + 1] = 1 + nz_p[nz_p_end] = o + nz_p_end = nz_p_end + 1 + p[n + 1] = v[i] + else + p[n + 1] = p[n + 1] + v[i] + end + for l in 1:nz_p_end + mask[nz_p[l] - 1] = 0 + end + end + elseif status[] == 6 # evaluate p = sparse A^Tv + for l in (nz_v_start - 1):nz_v_end + i = nz_v[l] - 1 + p[i] = v[i] + v[n + 1] + end + elseif status[] == 7 # evaluate p = P^{-}v + for i in 1:n + p[i] = userdata.scale * v[i] + end + else + @printf(" the value %1i of status should not occur\n", status) + end + eval_status = 0 + end + + # Record solution information + blls_information(data, inform, status) + + # Print solution details + if inform[].status == 0 + @printf("%s:%6i iterations. Optimal objective value = %5.2f status = %1i\n", + st, inform[].iter, inform[].obj, inform[].status) else - @printf("%c: BLLS_solve exit status = %1i\n", st, inform.status) + @printf("%s: BLLS_solve exit status = %1i\n", st, inform[].status) end # @printf("x: ") # for i = 1:n # @printf("%f ", x[i]) - # end # @printf("\n") # @printf("gradient: ") # for i = 1:n # @printf("%f ", g[i]) - # end # @printf("\n") # Delete internal workspace - blls_terminate( data, control, inform ) + return blls_terminate(data, control, inform) +end + +@testset "BLLS" begin + @test test_blls() == 0 end diff --git a/GALAHAD.jl/test/test_bllsb.jl b/GALAHAD.jl/test/test_bllsb.jl index 8fe0ad5a09..3c251b9602 100644 --- a/GALAHAD.jl/test/test_bllsb.jl +++ b/GALAHAD.jl/test/test_bllsb.jl @@ -36,25 +36,8 @@ function test_bllsb() # Set user-defined control options @reset control[].f_indexing = true # Fortran sparse matrix indexing - @reset control[].symmetric_linear_solver = convert(NTuple{31,Int8}, - (112, 111, 116, 114, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 0)) - - @reset control[].fdc_control.symmetric_linear_solver = convert(NTuple{31,Int8}, - (112, 111, 116, 114, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 0)) + @reset control[].symmetric_linear_solver = galahad_linear_solver("potr") + @reset control[].fdc_control.symmetric_linear_solver = galahad_linear_solver("potr") @reset control[].fdc_control.use_sls = true # Start from 0 diff --git a/GALAHAD.jl/test/test_clls.jl b/GALAHAD.jl/test/test_clls.jl index fbd39f59c3..8bab23fcdf 100644 --- a/GALAHAD.jl/test/test_clls.jl +++ b/GALAHAD.jl/test/test_clls.jl @@ -41,25 +41,8 @@ function test_clls() # Set user-defined control options @reset control[].f_indexing = true # Fortran sparse matrix indexing - @reset control[].symmetric_linear_solver = convert(NTuple{31,Int8}, - (112, 111, 116, 114, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 0)) - - @reset control[].fdc_control.symmetric_linear_solver = convert(NTuple{31,Int8}, - (112, 111, 116, 114, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 0)) + @reset control[].symmetric_linear_solver = galahad_linear_solver("potr") + @reset control[].fdc_control.symmetric_linear_solver = galahad_linear_solver("potr") @reset control[].fdc_control.use_sls = true # Start from 0 diff --git a/GALAHAD.jl/test/test_dgo.jl b/GALAHAD.jl/test/test_dgo.jl index e69de29bb2..689eb7d1cc 100644 --- a/GALAHAD.jl/test/test_dgo.jl +++ b/GALAHAD.jl/test/test_dgo.jl @@ -0,0 +1,670 @@ +# test_dgo.jl +# Simple code to test the Julia interface to DGO + +using GALAHAD +using Test +using Printf +using Accessors + +# Custom userdata struct +struct userdata_type + p::Float64 + freq::Float64 + mag::Float64 +end + +function test_dgo() + + # Objective function + function fun(n::Int, var::Vector{Float64}, f::Ref{Float64}, userdata::userdata_type) + p = userdata.p + freq = userdata.freq + mag = userdata.mag + + f[] = (x[1] + x[3] + p)^2 + (x[2] + x[3])^2 + mag * cos(freq * x[1]) + x[1] + x[2] + + x[3] + return 0 + end + + # Gradient of the objective + function grad(n::Int, var::Vector{Float64}, g::Vector{Float64}, userdata::userdata_type) + p = userdata.p + freq = userdata.freq + mag = userdata.mag + + g[1] = 2.0 * (x[1] + x[3] + p) - mag * freq * sin(freq * x[1]) + 1 + g[2] = 2.0 * (x[2] + x[3]) + 1 + g[3] = 2.0 * (x[1] + x[3] + p) + 2.0 * (x[2] + x[3]) + 1 + return 0 + end + + # # Hessian of the objective + # int hess(int n, + # int ne, + # var::Vector{Float64}, + # hval::Vector{Float64}, + # const void *userdata) + # struct userdata_type *myuserdata = (struct userdata_type *) userdata + # real_wp_ freq = myuserdata->freq + # real_wp_ mag = myuserdata->mag + + # hval[0] = 2.0 - mag * freq * freq * cos(freq*x[0]) + # hval[1] = 2.0 + # hval[2] = 2.0 + # hval[3] = 2.0 + # hval[4] = 4.0 + # return 0 + # ] + + # # Dense Hessian + # int hess_dense(int n, + # int ne, + # var::Vector{Float64}, + # hval::Vector{Float64}, + # const void *userdata) + # struct userdata_type *myuserdata = (struct userdata_type *) userdata + # real_wp_ freq = myuserdata->freq + # real_wp_ mag = myuserdata->mag + + # hval[0] = 2.0 - mag * freq * freq * cos(freq*x[0]) + # hval[1] = 0.0 + # hval[2] = 2.0 + # hval[3] = 2.0 + # hval[4] = 2.0 + # hval[5] = 4.0 + # return 0 + # ] + + # # Hessian-vector product + # int hessprod(int n, + # var::Vector{Float64}, + # u::Vector{Float64}, + # var::Vector{Float64}, + # bool got_h, + # const void *userdata) + # struct userdata_type *myuserdata = (struct userdata_type *) userdata + # real_wp_ freq = myuserdata->freq + # real_wp_ mag = myuserdata->mag + + # u[0] = u[0] + 2.0 * (v[0] + v[2]) + # - mag * freq * freq * cos(freq*x[0]) * v[0] + # u[1] = u[1] + 2.0 * (v[1] + v[2]) + # u[2] = u[2] + 2.0 * (v[0] + v[1] + 2.0 * v[2]) + # return 0 + # ] + + # # Sparse Hessian-vector product + # int shessprod(int n, + # var::Vector{Float64}, + # int nnz_v, + # const int index_nz_v[], + # var::Vector{Float64}, + # int *nnz_u, + # int index_nz_u[], + # u::Vector{Float64}, + # bool got_h, + # const void *userdata) + # struct userdata_type *myuserdata = (struct userdata_type *) userdata + # real_wp_ freq = myuserdata->freq + # real_wp_ mag = myuserdata->mag + + # real_wp_ p[] = {0., 0., 0.] + # bool used[] = {false, false, false] + # for(int i = 0 i < nnz_v i++) + # int j = index_nz_v[i] + # switch(j) + # case 1: + # p[0] = p[0] + 2.0 * v[0] + # - mag * freq * freq * cos(freq*x[0]) * v[0] + # used[0] = true + # p[2] = p[2] + 2.0 * v[0] + # used[2] = true + # end + # case 2: + # p[1] = p[1] + 2.0 * v[1] + # used[1] = true + # p[2] = p[2] + 2.0 * v[1] + # used[2] = true + # end + # case 3: + # p[0] = p[0] + 2.0 * v[2] + # used[0] = true + # p[1] = p[1] + 2.0 * v[2] + # used[1] = true + # p[2] = p[2] + 4.0 * v[2] + # used[2] = true + # end + # ] + # ] + # *nnz_u = 0 + # for(int j = 0 j < 3 j++) + # if used[j]) + # u[j] = p[j] + # *nnz_u = *nnz_u + 1 + # index_nz_u[*nnz_u-1] = j+1 + # ] + # ] + # return 0 + # ] + + # # Apply preconditioner + # int prec(int n, + # var::Vector{Float64}, + # u::Vector{Float64}, + # var::Vector{Float64}, + # const void *userdata) + # u[0] = 0.5 * v[0] + # u[1] = 0.5 * v[1] + # u[2] = 0.25 * v[2] + # return 0 + # ] + + # # Objective function + # int fun_diag(int n, + # var::Vector{Float64}, + # real_wp_ *f, + # const void *userdata) + # struct userdata_type *myuserdata = (struct userdata_type *) userdata + # real_wp_ p = myuserdata->p + # real_wp_ freq = myuserdata->freq + # real_wp_ mag = myuserdata->mag + + # *f = pow(x[2] + p, 2) + pow(x[1], 2) + mag * cos(freq*x[0]) + # + x[0] + x[1] + x[2] + # return 0 + # ] + + # # Gradient of the objective + # int grad_diag(int n, + # var::Vector{Float64}, + # g::Vector{Float64}, + # const void *userdata) + # struct userdata_type *myuserdata = (struct userdata_type *) userdata + # real_wp_ p = myuserdata->p + # real_wp_ freq = myuserdata->freq + # real_wp_ mag = myuserdata->mag + + # g[0] = -mag * freq * sin(freq*x[0]) + 1 + # g[1] = 2.0 * x[1] + 1 + # g[2] = 2.0 * (x[2] + p) + 1 + # return 0 + # ] + + # # Hessian of the objective + # int hess_diag(int n, + # int ne, + # var::Vector{Float64}, + # hval::Vector{Float64}, + # const void *userdata) + # struct userdata_type *myuserdata = (struct userdata_type *) userdata + # real_wp_ freq = myuserdata->freq + # real_wp_ mag = myuserdata->mag + + # hval[0] = -mag * freq * freq * cos(freq*x[0]) + # hval[1] = 2.0 + # hval[2] = 2.0 + # return 0 + # ] + + # # Hessian-vector product + # int hessprod_diag(int n, + # var::Vector{Float64}, + # u::Vector{Float64}, + # var::Vector{Float64}, + # bool got_h, + # const void *userdata) + # struct userdata_type *myuserdata = (struct userdata_type *) userdata + # real_wp_ freq = myuserdata->freq + # real_wp_ mag = myuserdata->mag + + # u[0] = u[0] + -mag * freq * freq * cos(freq*x[0]) * v[0] + # u[1] = u[1] + 2.0 * v[1] + # u[2] = u[2] + 2.0 * v[2] + # return 0 + # ] + + # # Sparse Hessian-vector product + # int shessprod_diag(int n, + # var::Vector{Float64}, + # int nnz_v, + # const int index_nz_v[], + # var::Vector{Float64}, + # int *nnz_u, + # int index_nz_u[], + # u::Vector{Float64}, + # bool got_h, + # const void *userdata) + # struct userdata_type *myuserdata = (struct userdata_type *) userdata + # real_wp_ freq = myuserdata->freq + # real_wp_ mag = myuserdata->mag + + # real_wp_ p[] = {0., 0., 0.] + # bool used[] = {false, false, false] + # for(int i = 0 i < nnz_v i++) + # int j = index_nz_v[i] + # switch(j) + # case 1: + # p[0] = p[0] - mag * freq * freq * cos(freq*x[0]) * v[0] + # used[0] = true + # end + # case 2: + # p[1] = p[1] + 2.0 * v[1] + # used[1] = true + # end + # case 3: + # p[2] = p[2] + 2.0 * v[2] + # used[2] = true + # end + # ] + # ] + # *nnz_u = 0 + # for(int j = 0 j < 3 j++) + # if used[j]) + # u[j] = p[j] + # *nnz_u = *nnz_u + 1 + # index_nz_u[*nnz_u-1] = j+1 + # ] + # ] + # return 0 + # ] + # end + + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{dgo_control_type{Float64}}() + inform = Ref{dgo_inform_type{Float64}}() + + # Set user data + userdata = userdata_type(4.0, 10.0, 1000.0) + + # Set problem data + n = 3 # dimension + ne = 5 # Hesssian elements + x_l = Float64[-10, -10, -10] + x_u = Float64[0.5, 0.5, 0.5] + H_row = Cint[1, 2, 3, 3, 3] # Hessian H + H_col = Cint[1, 2, 1, 2, 3] # NB lower triangle + H_ptr = Cint[1, 2, 3, 6] # row pointers + + # Set storage + g = zeros(Float64, n) # gradient + st = ' ' + status = Ref{Cint}() + + @printf(" Fortran sparse matrix indexing\n\n") + @printf(" tests options for all-in-one storage format\n\n") + + for d in 1:5 + + # Initialize DGO + dgo_initialize(data, control, status) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + @reset control[].maxit = 2500 + # @reset control[].trb_control[].maxit = 100 + # @reset control[].print_level = 1 + + # Start from 0 + x = Float64[0, 0, 0] + + # sparse co-ordinate storage + if d == 1 + st = 'C' + dgo_import(control, data, status, n, x_l, x_u, + "coordinate", ne, H_row, H_col, Cint[]) + + dgo_solve_with_mat(data, userdata, status, n, x, g, + ne, fun, grad, hess, hessprod, prec) + end + + # sparse by rows + if d == 2 + st = 'R' + dgo_import(control, data, status, n, x_l, x_u, + "sparse_by_rows", ne, Cint[], H_col, H_ptr) + + dgo_solve_with_mat(data, userdata, status, n, x, g, + ne, fun, grad, hess, hessprod, prec) + end + + # dense + if d == 3 + st = 'D' + dgo_import(control, data, status, n, x_l, x_u, + "dense", ne, Cint[], Cint[], Cint[]) + + dgo_solve_with_mat(data, userdata, status, n, x, g, + ne, fun, grad, hess_dense, hessprod, prec) + end + + # diagonal + if d == 4 + st = 'I' + dgo_import(control, data, status, n, x_l, x_u, + "diagonal", ne, Cint[], Cint[], Cint[]) + + dgo_solve_with_mat(data, userdata, status, n, x, g, + ne, fun_diag, grad_diag, hess_diag, + hessprod_diag, prec) + end + + # access by products + if d == 5 + st = 'P' + dgo_import(control, data, status, n, x_l, x_u, + "absent", ne, Cint[], Cint[], Cint[]) + + dgo_solve_without_mat(data, userdata, status, n, x, g, + fun, grad, hessprod, shessprod, prec) + end + + # Record solution information + dgo_information(data, inform, status) + + if inform[].status[] == 0 + @printf("%c:%6i evaluations. Optimal objective value = %5.2f status = %1i\n", st, + inform[].f_eval, inform[].obj, inform[].status) + elseif inform[].status[] == -18 + @printf("%c:%6i evaluations. Best objective value = %5.2f status = %1i\n", st, + inform[].f_eval, inform[].obj, inform[].status) + else + @printf("%c: DGO_solve exit status = %1i\n", st, inform[].status) + end + + # @printf("x: ") + # for i in 1:n + # @printf("%f ", x[i]) + # end + # @printf("\n") + # @printf("gradient: ") + # for i in 1:n + # @printf("%f ", g[i]) + # end + # @printf("\n") + + # Delete internal workspace + dgo_terminate(data, control, inform) + end + + @printf("\n tests reverse-communication options\n\n") + + # reverse-communication input/output + eval_status = Ref{Cint}() + nnz_u = Ref{Cint}() + nnz_v = Ref{Cint}() + f = 0.0 + u = zeros(Float64, n) + v = zeros(Float64, n) + index_nz_u = zeros(Cint, n) + index_nz_v = zeros(Cint, n) + # real_wp_ H_val[ne], H_dense[n*(n+1)/2], H_diag[n] + + for d in 1:5 + # Initialize DGO + dgo_initialize(data, control, status) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + @reset control[].maxit = 2500 + # @reset control[].trb_control[].maxit = 100 + # @reset control[].print_level = 1 + + # Start from 0 + x = Float64[0.0, 0.0, 0.0] + + # sparse co-ordinate storage + if d == 1 + st = 'C' + dgo_import(control, data, status, n, x_l, x_u, "coordinate", ne, H_row, H_col, Cint[]) + + terminated = false + while !terminated # reverse-communication loop + dgo_solve_reverse_with_mat(data, status, eval_status, n, x, f, g, ne, H_val, u, v) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # evaluate f + eval_status = fun(n, x, f, userdata) + elseif status[] == 3 # evaluate g + eval_status = grad(n, x, g, userdata) + elseif status[] == 4 # evaluate H + eval_status = hess(n, ne, x, H_val, userdata) + elseif status[] == 5 # evaluate Hv product + eval_status = hessprod(n, x, u, v, false, userdata) + elseif status[] == 6 # evaluate the product with P + eval_status = prec(n, x, u, v, userdata) + elseif status[] == 23 # evaluate f and g + eval_status = fun(n, x, f, userdata) + eval_status = grad(n, x, g, userdata) + elseif status[] == 25 # evaluate f and Hv product + eval_status = fun(n, x, f, userdata) + eval_status = hessprod(n, x, u, v, false, userdata) + elseif status[] == 35 # evaluate g and Hv product + eval_status = grad(n, x, g, userdata) + eval_status = hessprod(n, x, u, v, false, userdata) + elseif status[] == 235 # evaluate f, g and Hv product + eval_status = fun(n, x, f, userdata) + eval_status = grad(n, x, g, userdata) + eval_status = hessprod(n, x, u, v, false, userdata) + else + @printf(" the value %1i of status should not occur\n", status) + end + end + end + + # sparse by rows + if d == 2 + st = 'R' + dgo_import(control, data, status, n, x_l, x_u, + "sparse_by_rows", ne, Cint[], H_col, H_ptr) + + terminated = false + while !terminated # reverse-communication loop + dgo_solve_reverse_with_mat(data, status, eval_status, + n, x, f, g, ne, H_val, u, v) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # evaluate f + eval_status = fun(n, x, f, userdata) + elseif status[] == 3 # evaluate g + eval_status = grad(n, x, g, userdata) + elseif status[] == 4 # evaluate H + eval_status = hess(n, ne, x, H_val, userdata) + elseif status[] == 5 # evaluate Hv product + eval_status = hessprod(n, x, u, v, false, userdata) + elseif status[] == 6 # evaluate the product with P + eval_status = prec(n, x, u, v, userdata) + elseif status[] == 23 # evaluate f and g + eval_status = fun(n, x, f, userdata) + eval_status = grad(n, x, g, userdata) + elseif status[] == 25 # evaluate f and Hv product + eval_status = fun(n, x, f, userdata) + eval_status = hessprod(n, x, u, v, false, userdata) + elseif status[] == 35 # evaluate g and Hv product + eval_status = grad(n, x, g, userdata) + eval_status = hessprod(n, x, u, v, false, userdata) + elseif status[] == 235 # evaluate f, g and Hv product + eval_status = fun(n, x, f, userdata) + eval_status = grad(n, x, g, userdata) + eval_status = hessprod(n, x, u, v, false, userdata) + else + @printf(" the value %1i of status should not occur\n", status) + end + end + end + + # dense + if d == 3 + st = 'D' + dgo_import(control, data, status, n, x_l, x_u, + "dense", ne, Cint[], Cint[], Cint[]) + + terminated = false + while !terminated # reverse-communication loop + dgo_solve_reverse_with_mat(data, status, eval_status, + n, x, f, g, n * (n + 1) / 2, + H_dense, u, v) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # evaluate f + eval_status = fun(n, x, f, userdata) + elseif status[] == 3 # evaluate g + eval_status = grad(n, x, g, userdata) + elseif status[] == 4 # evaluate H + eval_status = hess_dense(n, n * (n + 1) / 2, x, H_dense, + userdata) + elseif status[] == 5 # evaluate Hv product + eval_status = hessprod(n, x, u, v, false, userdata) + elseif status[] == 6 # evaluate the product with P + eval_status = prec(n, x, u, v, userdata) + elseif status[] == 23 # evaluate f and g + eval_status = fun(n, x, f, userdata) + eval_status = grad(n, x, g, userdata) + elseif status[] == 25 # evaluate f and Hv product + eval_status = fun(n, x, f, userdata) + eval_status = hessprod(n, x, u, v, false, userdata) + elseif status[] == 35 # evaluate g and Hv product + eval_status = grad(n, x, g, userdata) + eval_status = hessprod(n, x, u, v, false, userdata) + elseif status[] == 235 # evaluate f, g and Hv product + eval_status = fun(n, x, f, userdata) + eval_status = grad(n, x, g, userdata) + eval_status = hessprod(n, x, u, v, false, userdata) + else + @printf(" the value %1i of status should not occur\n", status) + end + end + end + + # diagonal + if d == 4 + st = 'I' + dgo_import(control, data, status, n, x_l, x_u, + "diagonal", ne, Cint[], Cint[], Cint[]) + + terminated = false + while !terminated # reverse-communication loop + dgo_solve_reverse_with_mat(data, status, eval_status, + n, x, f, g, n, H_diag, u, v) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # evaluate f + eval_status = fun_diag(n, x, f, userdata) + elseif status[] == 3 # evaluate g + eval_status = grad_diag(n, x, g, userdata) + elseif status[] == 4 # evaluate H + eval_status = hess_diag(n, n, x, H_diag, userdata) + elseif status[] == 5 # evaluate Hv product + eval_status = hessprod_diag(n, x, u, v, false, + userdata) + elseif status[] == 6 # evaluate the product with P + eval_status = prec(n, x, u, v, userdata) + elseif status[] == 23 # evaluate f and g + eval_status = fun_diag(n, x, f, userdata) + eval_status = grad_diag(n, x, g, userdata) + elseif status[] == 25 # evaluate f and Hv product + eval_status = fun_diag(n, x, f, userdata) + eval_status = hessprod_diag(n, x, u, v, false, + userdata) + elseif status[] == 35 # evaluate g and Hv product + eval_status = grad_diag(n, x, g, userdata) + eval_status = hessprod_diag(n, x, u, v, false, + userdata) + elseif status[] == 235 # evaluate f, g and Hv product + eval_status = fun_diag(n, x, f, userdata) + eval_status = grad_diag(n, x, g, userdata) + eval_status = hessprod_diag(n, x, u, v, false, + userdata) + else + @printf(" the value %1i of status should not occur\n", status) + end + end + end + + # access by products + if d == 5 + st = 'P' + dgo_import(control, data, status, n, x_l, x_u, + "absent", ne, Cint[], Cint[], Cint[]) + + nnz_u = 0 + terminated = false + while !terminated # reverse-communication loop + dgo_solve_reverse_without_mat(data, status, eval_status, + n, x, f, g, u, v, index_nz_v, + nnz_v, index_nz_u, nnz_u) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # evaluate f + eval_status = fun(n, x, f, userdata) + elseif status[] == 3 # evaluate g + eval_status = grad(n, x, g, userdata) + elseif status[] == 5 # evaluate Hv product + eval_status = hessprod(n, x, u, v, false, userdata) + elseif status[] == 6 # evaluate the product with P + eval_status = prec(n, x, u, v, userdata) + elseif status[] == 7 # evaluate sparse Hess-vect product + eval_status = shessprod(n, x, nnz_v, index_nz_v, v, + nnz_u, index_nz_u, u, + false, userdata) + elseif status[] == 23 # evaluate f and g + eval_status = fun(n, x, f, userdata) + eval_status = grad(n, x, g, userdata) + elseif status[] == 25 # evaluate f and Hv product + eval_status = fun(n, x, f, userdata) + eval_status = hessprod(n, x, u, v, false, userdata) + elseif status[] == 35 # evaluate g and Hv product + eval_status = grad(n, x, g, userdata) + eval_status = hessprod(n, x, u, v, false, userdata) + elseif status[] == 235 # evaluate f, g and Hv product + eval_status = fun(n, x, f, userdata) + eval_status = grad(n, x, g, userdata) + eval_status = hessprod(n, x, u, v, false, userdata) + else + @printf(" the value %1i of status should not occur\n", status) + end + end + end + + # Record solution information + dgo_information(data, inform, status) + + if inform[].status[] == 0 + @printf("%c:%6i evaluations. Optimal objective value = %5.2f status = %1i\n", st, + inform[].f_eval, inform[].obj, inform[].status) + elseif inform[].status[] == -18 + @printf("%c:%6i evaluations. Best objective value = %5.2f status = %1i\n", st, + inform[].f_eval, inform[].obj, inform[].status) + else + @printf("%c: DGO_solve exit status = %1i\n", st, inform[].status) + end + + # @printf("x: ") + # for i in 1:n + # @printf("%f ", x[i]) + # end + # @printf("\n") + # @printf("gradient: ") + # for i in 1:n + # @printf("%f ", g[i]) + # end + # @printf("\n") + + # Delete internal workspace + dgo_terminate(data, control, inform) + end +end + +@testset "DGO" begin + @test test_dgo() == 0 +end diff --git a/GALAHAD.jl/test/test_dps.jl b/GALAHAD.jl/test/test_dps.jl index 1b0119d443..f4cd8b6925 100644 --- a/GALAHAD.jl/test/test_dps.jl +++ b/GALAHAD.jl/test/test_dps.jl @@ -39,14 +39,8 @@ function test_dps() dps_initialize(data, control, status) # Set user-defined control options - @reset control[].f_indexing = true # fortran sparse matrix indexing - @reset control[].symmetric_linear_solver = convert(NTuple{31,Int8}, - (115, 121, 116, 114, 32, 32, 32, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, 32, 32, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, 32, 32, 32, - 0)) + @reset control[].f_indexing = true # fortran sparse matrix indexing + @reset control[].symmetric_linear_solver = galahad_linear_solver("sytr") # sparse co-ordinate storage if storage_type == 1 diff --git a/GALAHAD.jl/test/test_dqp.jl b/GALAHAD.jl/test/test_dqp.jl index 711d39e4ad..978239df7c 100644 --- a/GALAHAD.jl/test/test_dqp.jl +++ b/GALAHAD.jl/test/test_dqp.jl @@ -2,209 +2,217 @@ # Simple code to test the Julia interface to DQP using GALAHAD +using Test using Printf - -# Derived types -data = [Ptr{Ptr{Cvoid}}()] -control = dqp_control_type{Float64}() -inform = dqp_inform_type{Float64}() - -# Set problem data -n = 3 # dimension -m = 2 # number of general constraints -H_ne = 3 # Hesssian elements -H_row = Cint[1, 2, 3] # row indices, NB lower triangle -H_col = Cint[1, 2, 3] # column indices, NB lower triangle -H_ptr = Cint[1, 2, 3, 4] # row pointers -H_val = Float64[1.0, 1.0, 1.0] # values -g = Float64[0.0, 2.0, 0.0] # linear term in the objective -f = 1.0 # constant term in the objective -A_ne = 4 # Jacobian elements -A_row = Cint[1, 1, 2, 2] # row indices -A_col = Cint[1, 2, 2, 3] # column indices -A_ptr = Cint[1, 3, 5] # row pointers -A_val = Float64[2.0, 1.0, 1.0, 1.0] # values -c_l = Float64[1.0, 2.0] # constraint lower bound -c_u = Float64[2.0, 2.0] # constraint upper bound -x_l = Float64[-1.0, -Inf, -Inf] # variable lower bound -x_u = Float64[1.0, Inf, 2.0] # variable upper bound - -# Set output storage -c = zeros(Float64, m) # constraint values -x_stat = zeros(Cint, n) # variable status -c_stat = zeros(Cint, m) # constraint status -st = ' ' -status = Ref{Cint}() - -@printf(" Fortran sparse matrix indexing\n\n") -@printf(" basic tests of qp storage formats\n\n") - -for d = 1:6 - # Initialize DQP - dqp_initialize( data, control, status ) - - # Set user-defined control options - control.f_indexing = true # Fortran sparse matrix indexing - - # Start from 0 - x = Float64[0.0,0.0,0.0] - y = Float64[0.0,0.0] - z = Float64[0.0,0.0,0.0] - - # sparse co-ordinate storage - if d == 1 - global st = 'C' - - dqp_import( control, data, status, n, m, - "coordinate", H_ne, H_row, H_col, Cint[], - "coordinate", A_ne, A_row, A_col, Cint[] ) - - dqp_solve_qp( data, status, n, m, H_ne, H_val, g, f, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) - end - - # sparse by rows - if d == 2 - global st = 'R' - - dqp_import( control, data, status, n, m, - "sparse_by_rows", H_ne, Cint[], H_col, H_ptr, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr ) - - dqp_solve_qp( data, status, n, m, H_ne, H_val, g, f, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) - end - - # dense - if d == 3 - global st = 'D' - H_dense_ne = 6 # number of elements of H - A_dense_ne = 6 # number of elements of A - H_dense = Float64[1.0, 0.0, 1.0, 0.0, 0.0, 1.0] - A_dense = Float64[2.0, 1.0, 0.0, 0.0, 1.0, 1.0] - - dqp_import( control, data, status, n, m, - "dense", H_ne, Cint[], Cint[], Cint[], - "dense", A_ne, Cint[], Cint[], Cint[] ) - - dqp_solve_qp( data, status, n, m, H_dense_ne, H_dense, g, f, - A_dense_ne, A_dense, c_l, c_u, x_l, x_u, - x, c, y, z, x_stat, c_stat ) - end - - # diagonal - if d == 4 - global st = 'L' - - dqp_import( control, data, status, n, m, - "diagonal", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr ) - - dqp_solve_qp( data, status, n, m, H_ne, H_val, g, f, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) - end - - # scaled identity - if d == 5 - global st = 'S' - - dqp_import( control, data, status, n, m, - "scaled_identity", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr ) - - dqp_solve_qp( data, status, n, m, H_ne, H_val, g, f, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) - end - - # identity - if d == 6 - global st = 'I' - - dqp_import( control, data, status, n, m, - "identity", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr ) - - dqp_solve_qp( data, status, n, m, H_ne, H_val, g, f, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) +using Accessors + +function test_dqp() + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{dqp_control_type{Float64}}() + inform = Ref{dqp_inform_type{Float64}}() + + # Set problem data + n = 3 # dimension + m = 2 # number of general constraints + H_ne = 3 # Hesssian elements + H_row = Cint[1, 2, 3] # row indices, NB lower triangle + H_col = Cint[1, 2, 3] # column indices, NB lower triangle + H_ptr = Cint[1, 2, 3, 4] # row pointers + H_val = Float64[1.0, 1.0, 1.0] # values + g = Float64[0.0, 2.0, 0.0] # linear term in the objective + f = 1.0 # constant term in the objective + A_ne = 4 # Jacobian elements + A_row = Cint[1, 1, 2, 2] # row indices + A_col = Cint[1, 2, 2, 3] # column indices + A_ptr = Cint[1, 3, 5] # row pointers + A_val = Float64[2.0, 1.0, 1.0, 1.0] # values + c_l = Float64[1.0, 2.0] # constraint lower bound + c_u = Float64[2.0, 2.0] # constraint upper bound + x_l = Float64[-1.0, -Inf, -Inf] # variable lower bound + x_u = Float64[1.0, Inf, 2.0] # variable upper bound + + # Set output storage + c = zeros(Float64, m) # constraint values + x_stat = zeros(Cint, n) # variable status + c_stat = zeros(Cint, m) # constraint status + st = ' ' + status = Ref{Cint}() + + @printf(" Fortran sparse matrix indexing\n\n") + @printf(" basic tests of qp storage formats\n\n") + + for d in 1:6 + + # Initialize DQP + dqp_initialize(data, control, status) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + + # Start from 0 + x = Float64[0.0, 0.0, 0.0] + y = Float64[0.0, 0.0] + z = Float64[0.0, 0.0, 0.0] + + # sparse co-ordinate storage + if d == 1 + st = 'C' + dqp_import(control, data, status, n, m, + "coordinate", H_ne, H_row, H_col, Cint[], + "coordinate", A_ne, A_row, A_col, Cint[]) + + dqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + end + + # sparse by rows + if d == 2 + st = 'R' + dqp_import(control, data, status, n, m, + "sparse_by_rows", H_ne, Cint[], H_col, H_ptr, + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + + dqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + end + + # dense + if d == 3 + st = 'D' + H_dense_ne = 6 # number of elements of H + A_dense_ne = 6 # number of elements of A + H_dense = Float64[1.0, 0.0, 1.0, 0.0, 0.0, 1.0] + A_dense = Float64[2.0, 1.0, 0.0, 0.0, 1.0, 1.0] + + dqp_import(control, data, status, n, m, + "dense", H_ne, Cint[], Cint[], Cint[], + "dense", A_ne, Cint[], Cint[], Cint[]) + + dqp_solve_qp(data, status, n, m, H_dense_ne, H_dense, g, f, + A_dense_ne, A_dense, c_l, c_u, x_l, x_u, + x, c, y, z, x_stat, c_stat) + end + + # diagonal + if d == 4 + st = 'L' + dqp_import(control, data, status, n, m, + "diagonal", H_ne, Cint[], Cint[], Cint[], + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + + dqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + end + + # scaled identity + if d == 5 + st = 'S' + dqp_import(control, data, status, n, m, + "scaled_identity", H_ne, Cint[], Cint[], Cint[], + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + + dqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + end + + # identity + if d == 6 + st = 'I' + dqp_import(control, data, status, n, m, + "identity", H_ne, Cint[], Cint[], Cint[], + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + + dqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + end + + dqp_information(data, inform, status) + + if inform[].status == 0 + @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", st, + inform[].iter, inform[].obj, inform[].status) + else + @printf("%c: DQP_solve exit status = %1i\n", st, inform[].status) + end + + # @printf("x: ") + # for i = 1:n + # @printf("%f ", x[i]) + # end + # @printf("\n") + # @printf("gradient: ") + # for i = 1:n + # @printf("%f ", g[i]) + # end + # @printf("\n") + + # Delete internal workspace + dqp_terminate(data, control, inform) end - dqp_information( data, inform, status ) - - if inform.status == 0 - @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", st, inform.iter, inform.obj, inform.status) - else - @printf("%c: DQP_solve exit status = %1i\n", st, inform.status) + # test shifted least-distance interface + for d in 1:1 + + # Initialize DQP + dqp_initialize(data, control, status) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + + # Start from 0 + x = Float64[0.0, 0.0, 0.0] + y = Float64[0.0, 0.0] + z = Float64[0.0, 0.0, 0.0] + + # Set shifted least-distance data + + w = Float64[1.0, 1.0, 1.0] + x_0 = Float64[0.0, 0.0, 0.0] + + # sparse co-ordinate storage + if d == 1 + st = 'W' + dqp_import(control, data, status, n, m, + "shifted_least_distance", H_ne, Cint[], Cint[], Cint[], + "coordinate", A_ne, A_row, A_col, Cint[]) + + dqp_solve_sldqp(data, status, n, m, w, x_0, g, f, + A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, + x_stat, c_stat) + end + + dqp_information(data, inform, status) + + if inform[].status == 0 + @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", st, + inform[].iter, inform[].obj, inform[].status) + else + @printf("%c: DQP_solve exit status = %1i\n", st, inform[].status) + end + + # @printf("x: ") + # for i = 1:n + # @printf("%f ", x[i]) + # end + # @printf("\n") + # @printf("gradient: ") + # for i = 1:n + # @printf("%f ", g[i]) + # end + # @printf("\n") + + # Delete internal workspace + dqp_terminate(data, control, inform) end - - # @printf("x: ") - # for i = 1:n - # @printf("%f ", x[i]) - # end - # @printf("\n") - # @printf("gradient: ") - # for i = 1:n - # @printf("%f ", g[i]) - # end - # @printf("\n") - - # Delete internal workspace - dqp_terminate( data, control, inform ) + return 0 end -# test shifted least-distance interface -for d = 1:1 - # Initialize DQP - dqp_initialize( data, control, status ) - - # Set user-defined control options - control.f_indexing = true # Fortran sparse matrix indexing - - # Start from 0 - x = Float64[0.0,0.0,0.0] - y = Float64[0.0,0.0] - z = Float64[0.0,0.0,0.0] - - # Set shifted least-distance data - w = Float64[1.0,1.0,1.0] - x_0 = Float64[0.0,0.0,0.0] - - # sparse co-ordinate storage - if d == 1 - global st = 'W' - - dqp_import( control, data, status, n, m, - "shifted_least_distance", H_ne, Cint[], Cint[], Cint[], - "coordinate", A_ne, A_row, A_col, Cint[] ) - - dqp_solve_sldqp( data, status, n, m, w, x_0, g, f, - A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, - x_stat, c_stat ) - end - - dqp_information( data, inform, status ) - - if inform.status == 0 - @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", st, inform.iter, inform.obj, inform.status) - else - @printf("%c: DQP_solve exit status = %1i\n", st, inform.status) - end - - # @printf("x: ") - # for i = 1:n - # @printf("%f ", x[i]) - # end - # @printf("\n") - # @printf("gradient: ") - # for i = 1:n - # @printf("%f ", g[i]) - # end - # @printf("\n") - - # Delete internal workspace - dqp_terminate( data, control, inform ) +@testset "DQP" begin + @test test_dqp() == 0 end diff --git a/GALAHAD.jl/test/test_eqp.jl b/GALAHAD.jl/test/test_eqp.jl index 70e54818f3..3c2c79fe21 100644 --- a/GALAHAD.jl/test/test_eqp.jl +++ b/GALAHAD.jl/test/test_eqp.jl @@ -45,34 +45,9 @@ function test_eqp() # Set user-defined control options @reset control[].f_indexing = true # Fortran sparse matrix indexing @reset control[].fdc_control.use_sls = true - solver = "sytr" - @reset control[].fdc_control.symmetric_linear_solver = convert(NTuple{31,Int8}, - (115, 121, 116, 114, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 0)) - @reset control[].sbls_control.symmetric_linear_solver = convert(NTuple{31,Int8}, - (115, 121, 116, 114, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 0)) - @reset control[].sbls_control.definite_linear_solver = convert(NTuple{31,Int8}, - (115, 121, 116, 114, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 0)) + @reset control[].fdc_control.symmetric_linear_solver = galahad_linear_solver("sytr") + @reset control[].sbls_control.symmetric_linear_solver = galahad_linear_solver("sytr") + @reset control[].sbls_control.definite_linear_solver = galahad_linear_solver("sytr") # Start from 0 x = Float64[0.0, 0.0, 0.0] @@ -191,34 +166,9 @@ function test_eqp() # Initialize EQP eqp_initialize(data, control, status) @reset control[].fdc_control.use_sls = true - solver = "sytr" - @reset control[].fdc_control.symmetric_linear_solver = convert(NTuple{31,Int8}, - (115, 121, 116, 114, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 0)) - @reset control[].sbls_control.symmetric_linear_solver = convert(NTuple{31,Int8}, - (115, 121, 116, 114, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 0)) - @reset control[].sbls_control.definite_linear_solver = convert(NTuple{31,Int8}, - (115, 121, 116, 114, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 0)) + @reset control[].fdc_control.symmetric_linear_solver = galahad_linear_solver("sytr") + @reset control[].sbls_control.symmetric_linear_solver = galahad_linear_solver("sytr") + @reset control[].sbls_control.definite_linear_solver = galahad_linear_solver("sytr") # Set user-defined control options @reset control[].f_indexing = true # Fortran sparse matrix indexing diff --git a/GALAHAD.jl/test/test_fdc.jl b/GALAHAD.jl/test/test_fdc.jl index ade26ca225..91570e6c57 100644 --- a/GALAHAD.jl/test/test_fdc.jl +++ b/GALAHAD.jl/test/test_fdc.jl @@ -2,53 +2,61 @@ # Simple code to test the Julia interface to FDC using GALAHAD +using Test using Printf - -# Derived types -data = [Ptr{Ptr{Cvoid}}()] -control = fdc_control_type{Float64}() -inform = fdc_inform_type{Float64}() - -# Set problem data -m = 3 # number of rows -n = 4 # number of columns -A_ne = 10 # number of nonzeros -A_col = Cint[1, 2, 3, 4, 1, 2, 3, 4, 2, 4] # column indices -A_ptr = Cint[1, 5, 9, 11] # row pointers -A_val = Float64[1.0, 2.0, 3.0, 4.0, 2.0, -4.0, 6.0, -8.0, 5.0, 10.0] -b = Float64[5.0, 10.0, 0.0] - -# Set output storage -depen = zeros(Cint, m) # dependencies, if any -n_depen = Ref{Cint}() -status = Ref{Cint}() - -@printf(" Fortran sparse matrix indexing\n") - -# Initialize FDC -fdc_initialize( data, control, status ) - -# Set user-defined control options -control.f_indexing = true # Fortran sparse matrix indexing - -# Start from 0 -fdc_find_dependent_rows( control, data, inform, status, m, n, A_ne, - A_col, A_ptr, A_val, b, n_depen, depen ) - -if status == 0 - if n_depen == 0 - @printf("FDC_find_dependent - no dependent rows, status = %i\n", status) +using Accessors + +function test_fdc() + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{fdc_control_type{Float64}}() + inform = Ref{fdc_inform_type{Float64}}() + + # Set problem data + m = 3 # number of rows + n = 4 # number of columns + A_ne = 10 # number of nonzeros + A_col = Cint[1, 2, 3, 4, 1, 2, 3, 4, 2, 4] # column indices + A_ptr = Cint[1, 5, 9, 11] # row pointers + A_val = Float64[1.0, 2.0, 3.0, 4.0, 2.0, -4.0, 6.0, -8.0, 5.0, 10.0] + b = Float64[5.0, 10.0, 0.0] + + # Set output storage + depen = zeros(Cint, m) # dependencies, if any + n_depen = Ref{Cint}() + status = Ref{Cint}() + + @printf(" Fortran sparse matrix indexing\n") + + # Initialize FDC + fdc_initialize(data, control, status) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + + # Start from 0 + fdc_find_dependent_rows(control, data, inform, status, m, n, A_ne, A_col, A_ptr, A_val, b, + n_depen, depen) + + if status[] == 0 + if n_depen == 0 + @printf("FDC_find_dependent - no dependent rows, status = %i\n", status[]) + else + @printf("FDC_find_dependent - dependent rows(s):") + for i in 1:n_depen + @printf(" %i", depen[i]) + end + @printf(", status = %i\n", status[]) + end else - @printf("FDC_find_dependent - dependent rows(s):" ) + @printf("FDC_find_dependent - exit status = %1i\n", status[]) end - for i = 1:n_depen - @printf(" %i", depen[i]) - end - @printf(", status = %i\n", status) -else - @printf("FDC_find_dependent - exit status = %1i\n", status) + # Delete internal workspace + fdc_terminate(data, control, inform) + return 0 end -# Delete internal workspace -fdc_terminate( data, control, inform ) +@testset "FDC" begin + @test test_fdc() == 0 +end diff --git a/GALAHAD.jl/test/test_llsr.jl b/GALAHAD.jl/test/test_llsr.jl index e69de29bb2..09fdc0f450 100644 --- a/GALAHAD.jl/test/test_llsr.jl +++ b/GALAHAD.jl/test/test_llsr.jl @@ -0,0 +1,219 @@ +# test_llsr.jl +# Simple code to test the Julia interface to LLSR + +using GALAHAD +using Test +using Printf +using Accessors + +function test_llsr() + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{llsr_control_type{Float64}}() + inform = Ref{llsr_inform_type{Float64}}() + + # Set problem data + # set dimensions + m = 100 + n = 2 * m + 1 + + # # A = (I : Diag(1:n) : e) + A_ne = 3 * m + A_row = zeros(Cint, A_ne) + A_col = zeros(Cint, A_ne) + A_ptr = zeros(Cint, m + 1) + A_val = zeros(Float64, A_ne) + + # store A in sparse formats + l = 1 + for i in 1:m + A_ptr[i] = l + 1 + A_row[l] = i + A_col[l] = i + A_val[l] = 1.0 + l = l + 1 + A_row[l] = i + A_col[l] = m + i + A_val[l] = i + l = l + 1 + A_row[l] = i + A_col[l] = n + A_val[l] = 1.0 + l = l + 1 + end + A_ptr[m + 1] = l + 1 + + # store A in dense format + A_dense_ne = m * n + A_dense_val = zeros(Float64, A_dense_ne) + for i in 1:A_dense_ne + A_dense_val[i] = 0.0 + end + l = 0 + for i in 1:m + A_dense_val[l + i] = 1.0 + A_dense_val[l + m + i] = i + A_dense_val[l + n] = 1.0 + l = l + n + end + + # S = diag(1:n)**2 + S_ne = n + S_row = zeros(Cint, S_ne) + S_col = zeros(Cint, S_ne) + S_ptr = zeros(Cint, n + 1) + S_val = zeros(Float64, S_ne) + + # store S in sparse formats + for i in 1:n + S_row[i] = i + S_col[i] = i + S_ptr[i] = i + S_val[i] = i * i + end + S_ptr[n + 1] = n + 1 + + # store S in dense format + S_dense_ne = div(n * (n + 1), 2) + S_dense_val = zeros(Float64, S_dense_ne) + for i in 1:S_dense_ne + S_dense_val[i] = 0.0 + end + l = 0 + for i in 1:n + S_dense_val[l + i] = i * i + l = l + i + end + + # b is a vector of ones + b = ones(Float64, m) # observations + + # cubic regularization, weight is one + power = 3.0 + weight = 1.0 + + # Set output storage + x = zeros(Float64, n) # solution + st = ' ' + status = Ref{Cint}() + + @printf(" Fortran sparse matrix indexing\n\n") + @printf(" basic tests of problem storage formats\n\n") + + # loop over storage formats + for d in 1:4 + + # Initialize LLSR + llsr_initialize(data, control, status) + @reset control[].definite_linear_solver = galahad_linear_solver("potr") + @reset control[].sbls_control.symmetric_linear_solver = galahad_linear_solver("sytr") + @reset control[].sbls_control.definite_linear_solver = galahad_linear_solver("potr") + # @reset control[].print_level = 1 + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + + # use s or not (1 or 0) + for use_s in 0:1 + + # sparse co-ordinate storage + if d == 1 + st = 'C' + llsr_import(control, data, status, m, n, + "coordinate", A_ne, A_row, A_col, Cint[]) + + if use_s == 0 + llsr_solve_problem(data, status, m, n, power, weight, + A_ne, A_val, b, x, 0, Cint[]) + else + llsr_import_scaling(control, data, status, n, + "coordinate", S_ne, S_row, + S_col, Cint[]) + + llsr_solve_problem(data, status, m, n, power, weight, + A_ne, A_val, b, x, S_ne, S_val) + end + end + + # sparse by rows + if d == 2 + st = 'R' + llsr_import(control, data, status, m, n, + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + + if use_s == 0 + llsr_solve_problem(data, status, m, n, power, weight, + A_ne, A_val, b, x, 0, Cint[]) + else + llsr_import_scaling(control, data, status, n, + "sparse_by_rows", S_ne, Cint[], + S_col, S_ptr) + + llsr_solve_problem(data, status, m, n, power, weight, + A_ne, A_val, b, x, S_ne, S_val) + end + end + + # dense + if d == 3 + st = 'D' + llsr_import(control, data, status, m, n, + "dense", A_dense_ne, Cint[], Cint[], Cint[]) + if use_s == 0 + llsr_solve_problem(data, status, m, n, power, weight, + A_dense_ne, A_dense_val, b, x, + 0, Cint[]) + else + llsr_import_scaling(control, data, status, n, + "dense", S_dense_ne, + Cint[], Cint[], Cint[]) + + llsr_solve_problem(data, status, m, n, power, weight, + A_dense_ne, A_dense_val, b, x, + S_dense_ne, S_dense_val) + end + end + + # diagonal + if d == 4 + st = 'I' + llsr_import(control, data, status, m, n, + "coordinate", A_ne, A_row, A_col, Cint[]) + if use_s == 0 + llsr_solve_problem(data, status, m, n, power, weight, + A_ne, A_val, b, x, 0, Cint[]) + else + llsr_import_scaling(control, data, status, n, + "diagonal", S_ne, Cint[], Cint[], Cint[]) + + llsr_solve_problem(data, status, m, n, power, weight, + A_ne, A_val, b, x, S_ne, S_val) + end + end + + llsr_information(data, inform, status) + + if inform[].status == 0 + @printf("storage type %c%1i: status = %1i, ||r|| = %5.2f\n", st, use_s, + inform[].status, inform[].r_norm) + else + @printf("storage type %c%1i: LLSR_solve exit status = %1i\n", st, use_s, + inform[].status) + end + end + + # @printf("x: ") + # for i = 1:n + # @printf("%f ", x[i]) + # end + # @printf("\n") + + # Delete internal workspace + llsr_terminate(data, control, inform) + end + return 0 +end + +@testset "LLSR" begin + @test test_llsr() == 0 +end diff --git a/GALAHAD.jl/test/test_llst.jl b/GALAHAD.jl/test/test_llst.jl index 4e34d13ebe..1ecc37c8ca 100644 --- a/GALAHAD.jl/test/test_llst.jl +++ b/GALAHAD.jl/test/test_llst.jl @@ -107,33 +107,9 @@ function test_llst() # Initialize LLST llst_initialize(data, control, status) - @reset control[].definite_linear_solver = convert(NTuple{31,Int8}, - (112, 111, 116, 114, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 0)) - @reset control[].sbls_control.symmetric_linear_solver = convert(NTuple{31,Int8}, - (115, 121, 116, 114, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 0)) - @reset control[].sbls_control.definite_linear_solver = convert(NTuple{31,Int8}, - (112, 111, 116, 114, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, - 32, 0)) + @reset control[].definite_linear_solver = galahad_linear_solver("potr") + @reset control[].sbls_control.symmetric_linear_solver = galahad_linear_solver("potr") + @reset control[].sbls_control.definite_linear_solver = galahad_linear_solver("potr") # @reset control[].print_level = Cint(1) # Set user-defined control options diff --git a/GALAHAD.jl/test/test_nls.jl b/GALAHAD.jl/test/test_nls.jl index 54cd373742..2e6e7e2796 100644 --- a/GALAHAD.jl/test/test_nls.jl +++ b/GALAHAD.jl/test/test_nls.jl @@ -8,7 +8,7 @@ using Accessors # Custom userdata struct struct userdata_type -p::Float64 + p::Float64 end function test_nls() diff --git a/GALAHAD.jl/test/test_psls.jl b/GALAHAD.jl/test/test_psls.jl index 1a807a5fc4..0324e0daa2 100644 --- a/GALAHAD.jl/test/test_psls.jl +++ b/GALAHAD.jl/test/test_psls.jl @@ -35,13 +35,7 @@ function test_psls() psls_initialize(data, control, status) @reset control[].preconditioner = Cint(2) # band preconditioner @reset control[].semi_bandwidth = Cint(1) # semibandwidth - @reset control[].definite_linear_solver = convert(NTuple{31,Int8}, - (115, 105, 108, 115, 32, 32, 32, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, 32, 32, 32, - 32, 32, - 32, 32, 32, 32, 32, 32, 32, 32, 32, - 0)) + @reset control[].definite_linear_solver = galahad_linear_solver("sils") # Set user-defined control options @reset control[].f_indexing = true # fortran sparse matrix indexing diff --git a/GALAHAD.jl/test/test_rqs.jl b/GALAHAD.jl/test/test_rqs.jl index bfdce1875e..10a02e9b94 100644 --- a/GALAHAD.jl/test/test_rqs.jl +++ b/GALAHAD.jl/test/test_rqs.jl @@ -1,13 +1,3 @@ -/* rqstf.c */ -/* Full test for the RQS C interface using Fortran sparse matrix indexing */ - -#include -#include -#include -#include "galahad_precision.h" -#include "galahad_cfunctions.h" -#include "galahad_rqs.h" - # test_rqs.jl # Simple code to test the Julia interface to RQS @@ -17,234 +7,225 @@ using Printf using Accessors function test_rqs() -# Derived types -data = Ref{Ptr{Cvoid}}() -control = Ref{rqs_control_type{Float64}}() -inform = Ref{rqs_inform_type{Float64}}() - -# Set problem data -n = 3 # dimension of H -m = 1 # dimension of A -H_ne = 4 # number of elements of H -M_ne = 3 # number of elements of M -A_ne = 3 # number of elements of A -H_dense_ne = 6 # number of elements of H -M_dense_ne = 6 # number of elements of M -H_row = Cint[1, 2, 3, 3] # row indices, NB lower triangle -H_col = Cint[1, 2, 3, 1] -H_ptr = Cint[1, 2, 3, 5] -M_row = Cint[1, 2, 3] # row indices, NB lower triangle -M_col = Cint[1, 2, 3] -M_ptr = Cint[1, 2, 3, 4] -A_row = Cint[1, 1, 1} -A_col = Cint[1, 2, 3] -A_ptr = Cint[1, 4] -H_val = Float64[1.0, 2.0, 3.0, 4.0] -M_val = Float64[1.0, 2.0, 1.0] -A_val = Float64[1.0, 1.0, 1.0] -H_dense = Float64[1.0, 0.0, 2.0, 4.0, 0.0, 3.0] -M_dense = Float64[1.0, 0.0, 2.0, 0.0, 0.0, 1.0] -H_diag = Float64[1.0, 0.0, 2.0] -M_diag = Float64[1.0, 2.0, 1.0] -f = 0.96 -power = 3.0 -weight = 1.0 -c = Float64[0.0, 2.0, 0.0] - -st = ' ' -status = Ref{Cint}() -x = zeros(Float64, n) -char ma[3] - -@printf(" Fortran sparse matrix indexing\n\n") - -@printf(" basic tests of storage formats\n\n") - -for a_is = 0:1 # add a linear constraint? - for m_is = 0:1 # include a scaling matrix? - -if (a_is == 1 m_is == 1) { - strcpy(ma, "MA") - -elseif (a_is == 1) { - strcpy(ma, "A ") - -elseif (m_is == 1) { - strcpy(ma, "M ") - -else { - strcpy(ma, " ") -for(int storage_type=1 storage_type <= 4 storage_type++) - - # Initialize RQS - rqs_initialize(data, control, status) - - # Set user-defined control options - control[].f_indexing = true # fortran sparse matrix indexing - - switch(storage_type) - # sparse co-ordinate storage -if d == 1 - st = 'C' - # import the control parameters and structural data - rqs_import(control, data, status, n, - "coordinate", H_ne, H_row, H_col, Cint[]) - if (m_is == 1) { -rqs_import_m(data, status, n, - "coordinate", M_ne, M_row, M_col, Cint[]) - ] - if (a_is == 1) { -rqs_import_a(data, status, m, - "coordinate", A_ne, A_row, A_col, Cint[]) - ] - # solve the problem - if (a_is == 1 m_is == 1) { -rqs_solve_problem(data, status, n, - power, weight, f, c, H_ne, H_val, x, - M_ne, M_val, m, A_ne, A_val, Cint[]) - ] - elseif (a_is == 1) { -rqs_solve_problem(data, status, n, - power, weight, f, c, H_ne, H_val, x, - 0, Cint[], m, A_ne, A_val, Cint[]) - ] - elseif (m_is == 1) { -rqs_solve_problem(data, status, n, - power, weight, f, c, H_ne, H_val, x, - M_ne, M_val, 0, 0, Cint[], Cint[]) - ] - else { -rqs_solve_problem(data, status, n, - power, weight, f, c, H_ne, H_val, x, - 0, Cint[], 0, 0, Cint[], Cint[]) - ] - end - @printf(" case %1i break\n", storage_type) - # sparse by rows -if d == 2 - st = 'R' - # import the control parameters and structural data - rqs_import(control, data, status, n, - "sparse_by_rows", H_ne, Cint[], H_col, H_ptr) - if (m_is == 1) { -rqs_import_m(data, status, n, - "sparse_by_rows", M_ne, Cint[], M_col, M_ptr) - ] - if (a_is == 1) { -rqs_import_a(data, status, m, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) - ] - # solve the problem - if (a_is == 1 m_is == 1) { -rqs_solve_problem(data, status, n, - power, weight, f, c, H_ne, H_val, x, - M_ne, M_val, m, A_ne, A_val, Cint[]) - ] - elseif (a_is == 1) { -rqs_solve_problem(data, status, n, - power, weight, f, c, H_ne, H_val, x, - 0, Cint[], m, A_ne, A_val, Cint[]) - ] - elseif (m_is == 1) { -rqs_solve_problem(data, status, n, - power, weight, f, c, H_ne, H_val, x, - M_ne, M_val, 0, 0, Cint[], Cint[]) - ] - else { -rqs_solve_problem(data, status, n, - power, weight, f, c, H_ne, H_val, x, - 0, Cint[], 0, 0, Cint[], Cint[]) - ] - end - # dense -if d == 3 - st = 'D' - # import the control parameters and structural data - rqs_import(control, data, status, n, - "dense", H_ne, Cint[], Cint[], Cint[]) - if (m_is == 1) { -rqs_import_m(data, status, n, - "dense", M_ne, Cint[], Cint[], Cint[]) - ] - if (a_is == 1) { -rqs_import_a(data, status, m, - "dense", A_ne, Cint[], Cint[], Cint[]) - ] - # solve the problem - if (a_is == 1 m_is == 1) { -rqs_solve_problem(data, status, n, power, weight, - f, c, H_dense_ne, H_dense, x, - M_dense_ne, M_dense, m, A_ne, A_val, - Cint[]) - ] - elseif (a_is == 1) { -rqs_solve_problem(data, status, n, power, weight, - f, c, H_dense_ne, H_dense, x, - 0, Cint[], m, A_ne, A_val, Cint[]) - ] - elseif (m_is == 1) { -rqs_solve_problem(data, status, n, power, weight, - f, c, H_dense_ne, H_dense, x, - M_dense_ne, M_dense, 0, 0, Cint[], Cint[]) - ] - else { -rqs_solve_problem(data, status, n, power, weight, - f, c, H_dense_ne, H_dense, x, - 0, Cint[], 0, 0, Cint[], Cint[]) - ] - end - # diagonal -if d == 4 - st = 'L' - # import the control parameters and structural data - rqs_import(control, data, status, n, - "diagonal", H_ne, Cint[], Cint[], Cint[]) - if (m_is == 1) { -rqs_import_m(data, status, n, - "diagonal", M_ne, Cint[], Cint[], Cint[]) - ] - if (a_is == 1) { -rqs_import_a(data, status, m, - "dense", A_ne, Cint[], Cint[], Cint[]) - ] - # solve the problem - if (a_is == 1 m_is == 1) { -rqs_solve_problem(data, status, n, - power, weight, f, c, n, H_diag, x, - n, M_diag, m, A_ne, A_val, Cint[]) - ] - elseif (a_is == 1) { -rqs_solve_problem(data, status, n, - power, weight, f, c, n, H_diag, x, - 0, Cint[], m, A_ne, A_val, Cint[]) - ] - elseif (m_is == 1) { -rqs_solve_problem(data, status, n, - power, weight, f, c, n, H_diag, x, - n, M_diag, 0, 0, Cint[], Cint[]) - ] - else { -rqs_solve_problem(data, status, n, - power, weight, f, c, n, H_diag, x, - 0, Cint[], 0, 0, Cint[], Cint[]) - ] + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{rqs_control_type{Float64}}() + inform = Ref{rqs_inform_type{Float64}}() + + # Set problem data + n = 3 # dimension of H + m = 1 # dimension of A + H_ne = 4 # number of elements of H + M_ne = 3 # number of elements of M + A_ne = 3 # number of elements of A + H_dense_ne = 6 # number of elements of H + M_dense_ne = 6 # number of elements of M + H_row = Cint[1, 2, 3, 3] # row indices, NB lower triangle + H_col = Cint[1, 2, 3, 1] + H_ptr = Cint[1, 2, 3, 5] + M_row = Cint[1, 2, 3] # row indices, NB lower triangle + M_col = Cint[1, 2, 3] + M_ptr = Cint[1, 2, 3, 4] + A_row = Cint[1, 1, 1] + A_col = Cint[1, 2, 3] + A_ptr = Cint[1, 4] + H_val = Float64[1.0, 2.0, 3.0, 4.0] + M_val = Float64[1.0, 2.0, 1.0] + A_val = Float64[1.0, 1.0, 1.0] + H_dense = Float64[1.0, 0.0, 2.0, 4.0, 0.0, 3.0] + M_dense = Float64[1.0, 0.0, 2.0, 0.0, 0.0, 1.0] + H_diag = Float64[1.0, 0.0, 2.0] + M_diag = Float64[1.0, 2.0, 1.0] + f = 0.96 + power = 3.0 + weight = 1.0 + c = Float64[0.0, 2.0, 0.0] + + st = ' ' + status = Ref{Cint}() + x = zeros(Float64, n) + + @printf(" Fortran sparse matrix indexing\n\n") + @printf(" basic tests of storage formats\n\n") + + for a_is in 0:1 # add a linear constraint? + for m_is in 0:1 # include a scaling matrix? + if (a_is == 1) && (m_is == 1) + ma = "MA" + elseif a_is == 1 + ma = "A" + elseif m_is == 1 + ma = "M" + else + ma = "" + end + + for storage_type in 1:4 + + # Initialize RQS + rqs_initialize(data, control, status) + + # Set user-defined control options + @reset control[].f_indexing = true # fortran sparse matrix indexing + + # sparse co-ordinate storage + if storage_type == 1 + st = 'C' + # import the control parameters and structural data + rqs_import(control, data, status, n, + "coordinate", H_ne, H_row, H_col, Cint[]) + if m_is == 1 + rqs_import_m(data, status, n, + "coordinate", M_ne, M_row, M_col, Cint[]) + end + if a_is == 1 + rqs_import_a(data, status, m, + "coordinate", A_ne, A_row, A_col, Cint[]) + end + + # solve the problem + if (a_is == 1) && (m_is == 1) + rqs_solve_problem(data, status, n, + power, weight, f, c, H_ne, H_val, x, + M_ne, M_val, m, A_ne, A_val, Cint[]) + elseif a_is == 1 + rqs_solve_problem(data, status, n, + power, weight, f, c, H_ne, H_val, x, + 0, Cint[], m, A_ne, A_val, Cint[]) + elseif m_is == 1 + rqs_solve_problem(data, status, n, + power, weight, f, c, H_ne, H_val, x, + M_ne, M_val, 0, 0, Cint[], Cint[]) + else + rqs_solve_problem(data, status, n, + power, weight, f, c, H_ne, H_val, x, + 0, Cint[], 0, 0, Cint[], Cint[]) + end + end + + # sparse by rows + if storage_type == 2 + st = 'R' + # import the control parameters and structural data + rqs_import(control, data, status, n, + "sparse_by_rows", H_ne, Cint[], H_col, H_ptr) + if m_is == 1 + rqs_import_m(data, status, n, + "sparse_by_rows", M_ne, Cint[], M_col, M_ptr) + end + if a_is == 1 + rqs_import_a(data, status, m, + "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + end + + # solve the problem + if (a_is == 1) && (m_is == 1) + rqs_solve_problem(data, status, n, + power, weight, f, c, H_ne, H_val, x, + M_ne, M_val, m, A_ne, A_val, Cint[]) + elseif a_is == 1 + rqs_solve_problem(data, status, n, + power, weight, f, c, H_ne, H_val, x, + 0, Cint[], m, A_ne, A_val, Cint[]) + elseif m_is == 1 + rqs_solve_problem(data, status, n, + power, weight, f, c, H_ne, H_val, x, + M_ne, M_val, 0, 0, Cint[], Cint[]) + else + rqs_solve_problem(data, status, n, + power, weight, f, c, H_ne, H_val, x, + 0, Cint[], 0, 0, Cint[], Cint[]) + end + end + + # dense + if storage_type == 3 + st = 'D' + # import the control parameters and structural data + rqs_import(control, data, status, n, + "dense", H_ne, Cint[], Cint[], Cint[]) + if m_is == 1 + rqs_import_m(data, status, n, + "dense", M_ne, Cint[], Cint[], Cint[]) + end + + if a_is == 1 + rqs_import_a(data, status, m, + "dense", A_ne, Cint[], Cint[], Cint[]) + end + + # solve the problem + if (a_is == 1) && (m_is == 1) + rqs_solve_problem(data, status, n, power, weight, + f, c, H_dense_ne, H_dense, x, + M_dense_ne, M_dense, m, A_ne, A_val, + Cint[]) + elseif a_is == 1 + rqs_solve_problem(data, status, n, power, weight, + f, c, H_dense_ne, H_dense, x, + 0, Cint[], m, A_ne, A_val, Cint[]) + elseif m_is == 1 + rqs_solve_problem(data, status, n, power, weight, + f, c, H_dense_ne, H_dense, x, + M_dense_ne, M_dense, 0, 0, Cint[], Cint[]) + else + rqs_solve_problem(data, status, n, power, weight, + f, c, H_dense_ne, H_dense, x, + 0, Cint[], 0, 0, Cint[], Cint[]) + end + end + + # diagonal + if storage_type == 4 + st = 'L' + # import the control parameters and structural data + rqs_import(control, data, status, n, + "diagonal", H_ne, Cint[], Cint[], Cint[]) + if m_is == 1 + rqs_import_m(data, status, n, + "diagonal", M_ne, Cint[], Cint[], Cint[]) + end + if a_is == 1 + rqs_import_a(data, status, m, + "dense", A_ne, Cint[], Cint[], Cint[]) + end + + # solve the problem + if (a_is == 1) && (m_is == 1) + rqs_solve_problem(data, status, n, + power, weight, f, c, n, H_diag, x, + n, M_diag, m, A_ne, A_val, Cint[]) + elseif a_is == 1 + rqs_solve_problem(data, status, n, + power, weight, f, c, n, H_diag, x, + 0, Cint[], m, A_ne, A_val, Cint[]) + elseif m_is == 1 + rqs_solve_problem(data, status, n, + power, weight, f, c, n, H_diag, x, + n, M_diag, 0, 0, Cint[], Cint[]) + else + rqs_solve_problem(data, status, n, + power, weight, f, c, n, H_diag, x, + 0, Cint[], 0, 0, Cint[], Cint[]) + end + end + + rqs_information(data, inform, status) + + @printf("format %c%s: RQS_solve_problem exit status = %1i, f = %.2f\n", st, ma, + inform[].status, inform[].obj_regularized) + + # @printf("x: ") + # for(int i = 0 i < n+m i++) + # @printf("%f ", x[i]) + # end + + # Delete internal workspace + rqs_terminate(data, control, inform) + end + end end - ] - - rqs_information(data, inform, status) - - @printf("format %c%s: RQS_solve_problem exit status = %1i, f = %.2f\n", - st, ma, inform[].status, inform[].obj_regularized) - # @printf("x: ") - # for(int i = 0 i < n+m i++) @printf("%f ", x[i]) - - # Delete internal workspace - rqs_terminate(data, control, inform) - ] -] - ] -] - + return 0 end @testset "RQS" begin diff --git a/GALAHAD.jl/test/test_trb.jl b/GALAHAD.jl/test/test_trb.jl index e69de29bb2..c78a988f86 100644 --- a/GALAHAD.jl/test/test_trb.jl +++ b/GALAHAD.jl/test/test_trb.jl @@ -0,0 +1,510 @@ +/* trbtf.c */ +/* Full test for the TRB C interface using Fortran sparse matrix indexing */ + +#include +#include +#include "galahad_precision.h" +#include "galahad_cfunctions.h" +#include "galahad_trb.h" + +# Custom userdata struct +struct userdata_type { + real_wp_ p +] + +# Function prototypes +int fun(int n, var::Vector{Float64}, real_wp_ *f, const void *) +int grad(int n, var::Vector{Float64}, g::Vector{Float64}, const void *) +int hess(int n, int ne, var::Vector{Float64}, hval::Vector{Float64}, const void *) +int hess_dense(int n, int ne, var::Vector{Float64}, hval::Vector{Float64}, + const void *) +int hessprod(int n, var::Vector{Float64}, u::Vector{Float64}, var::Vector{Float64}, + bool got_h, const void *) +int shessprod(int n, var::Vector{Float64}, int nnz_v, const int index_nz_v[], +var::Vector{Float64}, int *nnz_u, int index_nz_u[], +u::Vector{Float64}, bool got_h, const void *) +int prec(int n, var::Vector{Float64}, u::Vector{Float64}, var::Vector{Float64}, + const void *) +int fun_diag(int n, var::Vector{Float64}, real_wp_ *f, const void *) +int grad_diag(int n, var::Vector{Float64}, g::Vector{Float64}, const void *) +int hess_diag(int n, int ne, var::Vector{Float64}, hval::Vector{Float64}, +const void *) +int hessprod_diag(int n, var::Vector{Float64}, u::Vector{Float64}, +var::Vector{Float64}, bool got_h, const void *) +int shessprod_diag(int n, var::Vector{Float64}, int nnz_v, +const int index_nz_v[], +var::Vector{Float64}, int *nnz_u, int index_nz_u[], +u::Vector{Float64}, bool got_h, const void *) + +# test_trb.jl +# Simple code to test the Julia interface to TRB + +using GALAHAD +using Test +using Printf +using Accessors + +function test_trb() +# Derived types +data = Ref{Ptr{Cvoid}}() +control = Ref{trb_control_type{Float64}}() +inform = Ref{trb_inform_type{Float64}}() + +# Set user data +struct userdata_type userdata +userdata.p = 4.0 + +# Set problem data +n = 3 # dimension +ne = 5 # Hesssian elements +x_l = Float64[-10,-10,-10] +x_u = Float64[0.5,0.5,0.5] +H_row = Cint[1, 2, 3, 3, 3] # Hessian H +H_col = Cint[1, 2, 1, 2, 3] # NB lower triangle +H_ptr = Cint[1, 2, 3, 6] # row pointers + +# Set storage +g = zeros(Float64, n) # gradient +st = ' ' = ' ' +status = Ref{Cint}() + +@printf(" Fortran sparse matrix indexing\n\n") + +@printf(" tests options for all-in-one storage format\n\n") + +for d = 1:5 + +# Initialize TRB +trb_initialize(data, control, status) + +# Set user-defined control options +control[].f_indexing = true # Fortran sparse matrix indexing +#control[].print_level = 1 + +# Start from 1.5 +x = Float64[1.5,1.5,1.5] + +# sparse co-ordinate storage +if d == 1 +st = 'C' +trb_import(control, data, status, n, x_l, x_u, +"coordinate", ne, H_row, H_col, Cint[]) +trb_solve_with_mat(data, userdata, status, n, x, g, ne, +fun, grad, hess, prec) +end +# sparse by rows +if d == 2 +st = 'R' +trb_import(control, data, status, n, x_l, x_u, +"sparse_by_rows", ne, Cint[], H_col, H_ptr) +trb_solve_with_mat(data, userdata, status, n, x, g, ne, +fun, grad, hess, prec) +end +# dense +if d == 3 +st = 'D' +trb_import(control, data, status, n, x_l, x_u, +"dense", ne, Cint[], Cint[], Cint[]) +trb_solve_with_mat(data, userdata, status, n, x, g, ne, +fun, grad, hess_dense, prec) +end +# diagonal +if d == 4 +st = 'I' +trb_import(control, data, status, n, x_l, x_u, +"diagonal", ne, Cint[], Cint[], Cint[]) +trb_solve_with_mat (data, userdata, status, n, x, g, ne, +fun_diag, grad_diag, hess_diag, prec) +end +case 5: # access by products +st = 'P' +trb_import(control, data, status, n, x_l, x_u, +"absent", ne, Cint[], Cint[], Cint[]) +trb_solve_without_mat(data, userdata, status, n, x, g, + fun, grad, hessprod, shessprod, prec) +end +] +# Record solution information +trb_information(data, inform, status) + +# Print solution details +if inform[].status == 0 +@printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", + st, inform[].iter, inform[].obj, inform[].status) +else +@printf("%c: TRB_solve exit status = %1i\n", st, inform[].status) + +# @printf("x: ") +# for i = 1:n +# @printf("%f ", x[i]) +# @printf("\n") +# @printf("gradient: ") +# for i = 1:n +# @printf("%f ", g[i]) +# @printf("\n") + +# Delete internal workspace +trb_terminate(data, control, inform) +@printf("\n tests reverse-communication options\n\n") + +# reverse-communication input/output +int eval_status, nnz_v +int nnz_u +f = 0.0 +u = zeros(Float64, n), v[n] +index_nz_u = zeros(Cint, n), index_nz_v[n] +real_wp_ H_val[ne], H_dense[n*(n+1)/2], H_diag[n] +for d = 1:5 + +# Initialize TRB +trb_initialize(data, control, status) + +# Set user-defined control options +control[].f_indexing = true # Fortran sparse matrix indexing +#control[].print_level = 1 + +# Start from 1.5 +x = Float64[1.5,1.5,1.5] + +# sparse co-ordinate storage +if d == 1 +st = 'C' +trb_import(control, data, status, n, x_l, x_u, +"coordinate", ne, H_row, H_col, Cint[]) +while true # reverse-communication loop +trb_solve_reverse_with_mat(data, status, eval_status, +n, x, f, g, ne, H_val, u, v) +if status == 0 # successful termination +end +elseif status < 0) # error exit +end +elseif status == 2) # evaluate f +eval_status = fun(n, x, f, userdata) +elseif status == 3) # evaluate g +eval_status = grad(n, x, g, userdata) +elseif status == 4) # evaluate H +eval_status = hess(n, ne, x, H_val, userdata) +elseif status == 6) # evaluate the product with P +eval_status = prec(n, x, u, v, userdata) +else +@printf(" the value %1i of status should not occur\n", status) +end +] +] +end +# sparse by rows +if d == 2 +st = 'R' +trb_import(control, data, status, n, x_l, x_u, +"sparse_by_rows", ne, Cint[], H_col, H_ptr) +while true # reverse-communication loop +trb_solve_reverse_with_mat(data, status, eval_status, +n, x, f, g, ne, H_val, u, v) +if status == 0 # successful termination +end +elseif status < 0) # error exit +end +elseif status == 2) # evaluate f +eval_status = fun(n, x, f, userdata) +elseif status == 3) # evaluate g +eval_status = grad(n, x, g, userdata) +elseif status == 4) # evaluate H +eval_status = hess(n, ne, x, H_val, userdata) +elseif status == 6) # evaluate the product with P +eval_status = prec(n, x, u, v, userdata) +else +@printf(" the value %1i of status should not occur\n", status) +end +] +] +end +# dense +if d == 3 +st = 'D' +trb_import(control, data, status, n, x_l, x_u, +"dense", ne, Cint[], Cint[], Cint[]) +while true # reverse-communication loop +trb_solve_reverse_with_mat(data, status, eval_status, +n, x, f, g, n*(n+1)/2, H_dense, +u, v) +if status == 0 # successful termination +end +elseif status < 0) # error exit +end +elseif status == 2) # evaluate f +eval_status = fun(n, x, f, userdata) +elseif status == 3) # evaluate g +eval_status = grad(n, x, g, userdata) +elseif status == 4) # evaluate H +eval_status = hess_dense(n, n*(n+1)/2, x, H_dense, + userdata) +elseif status == 6) # evaluate the product with P +eval_status = prec(n, x, u, v, userdata) +else +@printf(" the value %1i of status should not occur\n", status) +end +] +] +end +# diagonal +if d == 4 +st = 'I' +trb_import(control, data, status, n, x_l, x_u, +"diagonal", ne, Cint[], Cint[], Cint[]) +while true # reverse-communication loop +trb_solve_reverse_with_mat(data, status, eval_status, +n, x, f, g, n, H_diag, u, v) +if status == 0 # successful termination +end +elseif status < 0) # error exit +end +elseif status == 2) # evaluate f +eval_status = fun_diag(n, x, f, userdata) +elseif status == 3) # evaluate g +eval_status = grad_diag(n, x, g, userdata) +elseif status == 4) # evaluate H +eval_status = hess_diag(n, n, x, H_diag, userdata) +elseif status == 6) # evaluate the product with P +eval_status = prec(n, x, u, v, userdata) +else +@printf(" the value %1i of status should not occur\n", status) +end +] +] +end +case 5: # access by products +st = 'P' +trb_import(control, data, status, n, x_l, x_u, +"absent", ne, Cint[], Cint[], Cint[]) +nnz_u = 0 +while true # reverse-communication loop +trb_solve_reverse_without_mat(data, status, eval_status, + n, x, f, g, u, v, index_nz_v, + nnz_v, index_nz_u, nnz_u) +if status == 0 # successful termination +end +elseif status < 0) # error exit +end +elseif status == 2) # evaluate f +eval_status = fun(n, x, f, userdata) +elseif status == 3) # evaluate g +eval_status = grad(n, x, g, userdata) +elseif status == 5) # evaluate H +eval_status = hessprod(n, x, u, v, false, userdata) +elseif status == 6) # evaluate the product with P +eval_status = prec(n, x, u, v, userdata) +elseif status == 7) # evaluate sparse Hessian-vect prod +eval_status = shessprod(n, x, nnz_v, index_nz_v, v, + nnz_u, index_nz_u, u, + false, userdata) +else +@printf(" the value %1i of status should not occur\n", status) +end +] +] +end +] + +# Record solution information +trb_information(data, inform, status) + +# Print solution details +if inform[].status == 0 +@printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", + st, inform[].iter, inform[].obj, inform[].status) +else +@printf("%c: TRB_solve exit status = %1i\n", st, inform[].status) + +# @printf("x: ") +# for i = 1:n +# @printf("%f ", x[i]) +# @printf("\n") +# @printf("gradient: ") +# for i = 1:n +# @printf("%f ", g[i]) +# @printf("\n") + +# Delete internal workspace +trb_terminate(data, control, inform) +] + +# Objective function +int fun(int n, var::Vector{Float64}, real_wp_ *f, const void *userdata) +struct userdata_type *myuserdata = (struct userdata_type *) userdata +real_wp_ p = myuserdata->p + +*f = pow(x[0] + x[2] + p, 2) + pow(x[1] + x[2], 2) + cos(x[0]) +return 0 +] + +# Gradient of the objective +int grad(int n, var::Vector{Float64}, g::Vector{Float64}, const void *userdata) +struct userdata_type *myuserdata = (struct userdata_type *) userdata +real_wp_ p = myuserdata->p + +g[0] = 2.0 * (x[0] + x[2] + p) - sin(x[0]) +g[1] = 2.0 * (x[1] + x[2]) +g[2] = 2.0 * (x[0] + x[2] + p) + 2.0 * (x[1] + x[2]) +return 0 +] + +# Hessian of the objective +int hess(int n, int ne, var::Vector{Float64}, hval::Vector{Float64}, + const void *userdata) +hval[0] = 2.0 - cos(x[0]) +hval[1] = 2.0 +hval[2] = 2.0 +hval[3] = 2.0 +hval[4] = 4.0 +return 0 +] + +# Dense Hessian +int hess_dense(int n, int ne, var::Vector{Float64}, hval::Vector{Float64}, +const void *userdata) +hval[0] = 2.0 - cos(x[0]) +hval[1] = 0.0 +hval[2] = 2.0 +hval[3] = 2.0 +hval[4] = 2.0 +hval[5] = 4.0 +return 0 +] + +# Hessian-vector product +int hessprod(int n, var::Vector{Float64}, u::Vector{Float64}, var::Vector{Float64}, + bool got_h, const void *userdata) +u[0] = u[0] + 2.0 * (v[0] + v[2]) - cos(x[0]) * v[0] +u[1] = u[1] + 2.0 * (v[1] + v[2]) +u[2] = u[2] + 2.0 * (v[0] + v[1] + 2.0 * v[2]) +return 0 +] + +# Sparse Hessian-vector product +int shessprod(int n, var::Vector{Float64}, int nnz_v, const int index_nz_v[], + var::Vector{Float64}, int *nnz_u, int index_nz_u[], u::Vector{Float64}, + bool got_h, const void *userdata) +real_wp_ p[] = {0., 0., 0.] +bool used[] = {false, false, false] +for(int i = 0 i < nnz_v i++) +int j = index_nz_v[i] +switch(j) +case 1: +p[0] = p[0] + 2.0 * v[0] - cos(x[0]) * v[0] +used[0] = true +p[2] = p[2] + 2.0 * v[0] +used[2] = true +end +case 2: +p[1] = p[1] + 2.0 * v[1] +used[1] = true +p[2] = p[2] + 2.0 * v[1] +used[2] = true +end +case 3: +p[0] = p[0] + 2.0 * v[2] +used[0] = true +p[1] = p[1] + 2.0 * v[2] +used[1] = true +p[2] = p[2] + 4.0 * v[2] +used[2] = true +end +] +] +*nnz_u = 0 +for(int j = 0 j < 3 j++) +if used[j]) +u[j] = p[j] +*nnz_u = *nnz_u + 1 +index_nz_u[*nnz_u-1] = j+1 +] +] +return 0 +] + +# Apply preconditioner +int prec(int n, var::Vector{Float64}, u::Vector{Float64}, var::Vector{Float64}, + const void *userdata) + u[0] = 0.5 * v[0] + u[1] = 0.5 * v[1] + u[2] = 0.25 * v[2] + return 0 +] + + # Objective function +int fun_diag(int n, var::Vector{Float64}, real_wp_ *f, const void *userdata) +struct userdata_type *myuserdata = (struct userdata_type *) userdata +real_wp_ p = myuserdata->p + +*f = pow(x[2] + p, 2) + pow(x[1], 2) + cos(x[0]) +return 0 +] + +# Gradient of the objective +int grad_diag(int n, var::Vector{Float64}, g::Vector{Float64}, const void *userdata) +struct userdata_type *myuserdata = (struct userdata_type *) userdata +real_wp_ p = myuserdata->p + +g[0] = -sin(x[0]) +g[1] = 2.0 * x[1] +g[2] = 2.0 * (x[2] + p) +return 0 +] + +# Hessian of the objective +int hess_diag(int n, int ne, var::Vector{Float64}, hval::Vector{Float64}, + const void *userdata) +hval[0] = -cos(x[0]) +hval[1] = 2.0 +hval[2] = 2.0 +return 0 +] + +# Hessian-vector product +int hessprod_diag(int n, var::Vector{Float64}, u::Vector{Float64}, var::Vector{Float64}, + bool got_h, const void *userdata) +u[0] = u[0] + - cos(x[0]) * v[0] +u[1] = u[1] + 2.0 * v[1] +u[2] = u[2] + 2.0 * v[2] +return 0 +] + +# Sparse Hessian-vector product +int shessprod_diag(int n, var::Vector{Float64}, int nnz_v, +const int index_nz_v[], +var::Vector{Float64}, int *nnz_u, int index_nz_u[], +u::Vector{Float64}, bool got_h, const void *userdata) +real_wp_ p[] = {0., 0., 0.] +bool used[] = {false, false, false] +for(int i = 0 i < nnz_v i++) +int j = index_nz_v[i] +switch(j) +case 0: +p[0] = p[0] - cos(x[0]) * v[0] +used[0] = true +end +case 1: +p[1] = p[1] + 2.0 * v[1] +used[1] = true +end +case 2: +p[2] = p[2] + 2.0 * v[2] +used[2] = true +end +] +] +*nnz_u = 0 +for(int j = 0 j < 3 j++) +if used[j]) +u[j] = p[j] +*nnz_u = *nnz_u + 1 +index_nz_u[*nnz_u-1] = j+1 +] +] +return 0 +] +end + +@testset "TRB" begin + @test test_trb() == 0 +end diff --git a/GALAHAD.jl/test/test_ugo.jl b/GALAHAD.jl/test/test_ugo.jl index 1511878f7d..cc10243021 100644 --- a/GALAHAD.jl/test/test_ugo.jl +++ b/GALAHAD.jl/test/test_ugo.jl @@ -42,10 +42,7 @@ function test_ugo() @reset control[].print_level = Cint(1) # control.prefix = "'ugo: '" - @reset control[].prefix = convert(NTuple{31,Int8}, - (34, 39, 117, 103, 111, 58, 32, 39, 34, 32, 32, 32, 32, - 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, - 32, 32, 32, 0)) + @reset control[].prefix = galahad_linear_solver("'ugo: '") # Read options from specfile specfile = "UGO.SPC" From fe09a21f940c41fc7358d2d980815ffb92ad9f6b Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Mon, 12 Feb 2024 16:14:23 -0500 Subject: [PATCH 18/33] Add OpenBLAS32_jll as a dependency of GALAHAD.jl --- GALAHAD.jl/Project.toml | 3 ++- GALAHAD.jl/src/GALAHAD.jl | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/GALAHAD.jl/Project.toml b/GALAHAD.jl/Project.toml index 2ffa4d8cc8..3429ebd2e3 100644 --- a/GALAHAD.jl/Project.toml +++ b/GALAHAD.jl/Project.toml @@ -6,14 +6,15 @@ version = "0.1.0" [deps] GALAHAD_jll = "1621ace8-c1f0-5e32-a05d-ca786afa56c2" Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb" +OpenBLAS32_jll = "656ef2d0-ae68-5445-9ca0-591084a874a2" [compat] julia = "1.9" [extras] +Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697" Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" -Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697" [targets] test = ["Test", "Printf", "Accessors"] diff --git a/GALAHAD.jl/src/GALAHAD.jl b/GALAHAD.jl/src/GALAHAD.jl index 31323fa2bf..3dfbabadfe 100644 --- a/GALAHAD.jl/src/GALAHAD.jl +++ b/GALAHAD.jl/src/GALAHAD.jl @@ -7,10 +7,20 @@ if haskey(ENV, "JULIA_GALAHAD_LIBRARY_PATH") const libgalahad_double = joinpath(ENV["JULIA_GALAHAD_LIBRARY_PATH"], "libgalahad_double.$dlext") const GALAHAD_INSTALLATION = "CUSTOM" else + using OpenBLAS32_jll using GALAHAD_jll const GALAHAD_INSTALLATION = "YGGDRASIL" end +function __init__() + if GALAHAD_INSTALLATION == "YGGDRASIL" + config = LinearAlgebra.BLAS.lbt_get_config() + if !any(lib -> lib.interface == :lp64, config.loaded_libs) + LinearAlgebra.BLAS.lbt_forward(OpenBLAS32_jll.libopenblas_path) + end + end +end + # Utils. include("utils.jl") From 54c96cdccf484f6bae47d5ee54034fb3a4089aa9 Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Mon, 12 Feb 2024 16:16:02 -0500 Subject: [PATCH 19/33] Update Project.tml --- GALAHAD.jl/Project.toml | 1 + GALAHAD.jl/src/GALAHAD.jl | 1 + 2 files changed, 2 insertions(+) diff --git a/GALAHAD.jl/Project.toml b/GALAHAD.jl/Project.toml index 3429ebd2e3..094a70a99e 100644 --- a/GALAHAD.jl/Project.toml +++ b/GALAHAD.jl/Project.toml @@ -6,6 +6,7 @@ version = "0.1.0" [deps] GALAHAD_jll = "1621ace8-c1f0-5e32-a05d-ca786afa56c2" Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb" +LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" OpenBLAS32_jll = "656ef2d0-ae68-5445-9ca0-591084a874a2" [compat] diff --git a/GALAHAD.jl/src/GALAHAD.jl b/GALAHAD.jl/src/GALAHAD.jl index 3dfbabadfe..3c9b0c0ad5 100644 --- a/GALAHAD.jl/src/GALAHAD.jl +++ b/GALAHAD.jl/src/GALAHAD.jl @@ -1,6 +1,7 @@ module GALAHAD using Libdl +using LinearAlgebra if haskey(ENV, "JULIA_GALAHAD_LIBRARY_PATH") const libgalahad_single = joinpath(ENV["JULIA_GALAHAD_LIBRARY_PATH"], "libgalahad_single.$dlext") From 3e3d601819ccc32430d35aa90dcfcff3159ddf9c Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Tue, 13 Feb 2024 00:06:33 -0500 Subject: [PATCH 20/33] Try to debug test_llsr.jl with CI --- GALAHAD.jl/gen/examples.jl | 2 +- GALAHAD.jl/src/utils.jl | 2 +- GALAHAD.jl/test/test_llsr.jl | 34 ++++++++++++---------------- GALAHAD.jl/test/test_llst.jl | 44 ++++++++++++++---------------------- src/bqp/C/bqptf.c | 4 +--- 5 files changed, 34 insertions(+), 52 deletions(-) diff --git a/GALAHAD.jl/gen/examples.jl b/GALAHAD.jl/gen/examples.jl index b83aa14dfa..e2861e1542 100644 --- a/GALAHAD.jl/gen/examples.jl +++ b/GALAHAD.jl/gen/examples.jl @@ -84,7 +84,7 @@ function examples(package::String, example::String) text = replace(text, ")\n}" => ")\n") text = replace(text, "\n\n\n" => "\n") text = replace(text, "}\n" => "]\n") - text = replace(text, "NULL" => "Cint[]") + text = replace(text, "NULL" => "C_NULL") text = replace(text, "char st" => "st = ' '") text = replace(text, "int status" => "status = Ref{Cint}()") text = replace(text, "int n_depen" => "n_depen = Ref{Cint}()") diff --git a/GALAHAD.jl/src/utils.jl b/GALAHAD.jl/src/utils.jl index afb64e2635..05cee5fcf8 100644 --- a/GALAHAD.jl/src/utils.jl +++ b/GALAHAD.jl/src/utils.jl @@ -9,7 +9,7 @@ function galahad_linear_solver(solver::String) result[i] = Cchar(solver[i]) end for i in nchar+1:30 - result[i] = Char(' ') + result[i] = Cchar(' ') end return ntuple(i -> result[i], 31) diff --git a/GALAHAD.jl/test/test_llsr.jl b/GALAHAD.jl/test/test_llsr.jl index 09fdc0f450..65461d383d 100644 --- a/GALAHAD.jl/test/test_llsr.jl +++ b/GALAHAD.jl/test/test_llsr.jl @@ -27,7 +27,7 @@ function test_llsr() # store A in sparse formats l = 1 for i in 1:m - A_ptr[i] = l + 1 + A_ptr[i] = l A_row[l] = i A_col[l] = i A_val[l] = 1.0 @@ -41,14 +41,11 @@ function test_llsr() A_val[l] = 1.0 l = l + 1 end - A_ptr[m + 1] = l + 1 + A_ptr[m + 1] = l # store A in dense format A_dense_ne = m * n A_dense_val = zeros(Float64, A_dense_ne) - for i in 1:A_dense_ne - A_dense_val[i] = 0.0 - end l = 0 for i in 1:m A_dense_val[l + i] = 1.0 @@ -76,9 +73,6 @@ function test_llsr() # store S in dense format S_dense_ne = div(n * (n + 1), 2) S_dense_val = zeros(Float64, S_dense_ne) - for i in 1:S_dense_ne - S_dense_val[i] = 0.0 - end l = 0 for i in 1:n S_dense_val[l + i] = i * i @@ -120,15 +114,15 @@ function test_llsr() if d == 1 st = 'C' llsr_import(control, data, status, m, n, - "coordinate", A_ne, A_row, A_col, Cint[]) + "coordinate", A_ne, A_row, A_col, C_NULL) if use_s == 0 llsr_solve_problem(data, status, m, n, power, weight, - A_ne, A_val, b, x, 0, Cint[]) + A_ne, A_val, b, x, 0, C_NULL) else llsr_import_scaling(control, data, status, n, "coordinate", S_ne, S_row, - S_col, Cint[]) + S_col, C_NULL) llsr_solve_problem(data, status, m, n, power, weight, A_ne, A_val, b, x, S_ne, S_val) @@ -139,14 +133,14 @@ function test_llsr() if d == 2 st = 'R' llsr_import(control, data, status, m, n, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) if use_s == 0 llsr_solve_problem(data, status, m, n, power, weight, - A_ne, A_val, b, x, 0, Cint[]) + A_ne, A_val, b, x, 0, C_NULL) else llsr_import_scaling(control, data, status, n, - "sparse_by_rows", S_ne, Cint[], + "sparse_by_rows", S_ne, C_NULL, S_col, S_ptr) llsr_solve_problem(data, status, m, n, power, weight, @@ -158,15 +152,15 @@ function test_llsr() if d == 3 st = 'D' llsr_import(control, data, status, m, n, - "dense", A_dense_ne, Cint[], Cint[], Cint[]) + "dense", A_dense_ne, C_NULL, C_NULL, C_NULL) if use_s == 0 llsr_solve_problem(data, status, m, n, power, weight, A_dense_ne, A_dense_val, b, x, - 0, Cint[]) + 0, C_NULL) else llsr_import_scaling(control, data, status, n, "dense", S_dense_ne, - Cint[], Cint[], Cint[]) + C_NULL, C_NULL, C_NULL) llsr_solve_problem(data, status, m, n, power, weight, A_dense_ne, A_dense_val, b, x, @@ -178,13 +172,13 @@ function test_llsr() if d == 4 st = 'I' llsr_import(control, data, status, m, n, - "coordinate", A_ne, A_row, A_col, Cint[]) + "coordinate", A_ne, A_row, A_col, C_NULL) if use_s == 0 llsr_solve_problem(data, status, m, n, power, weight, - A_ne, A_val, b, x, 0, Cint[]) + A_ne, A_val, b, x, 0, C_NULL) else llsr_import_scaling(control, data, status, n, - "diagonal", S_ne, Cint[], Cint[], Cint[]) + "diagonal", S_ne, C_NULL, C_NULL, C_NULL) llsr_solve_problem(data, status, m, n, power, weight, A_ne, A_val, b, x, S_ne, S_val) diff --git a/GALAHAD.jl/test/test_llst.jl b/GALAHAD.jl/test/test_llst.jl index 1ecc37c8ca..2c9291acc0 100644 --- a/GALAHAD.jl/test/test_llst.jl +++ b/GALAHAD.jl/test/test_llst.jl @@ -40,14 +40,11 @@ function test_llst() A_val[l] = 1.0 l = l + 1 end - A_ptr[m] = l + A_ptr[m+1] = l # store A in dense format A_dense_ne = m * n A_dense_val = zeros(Float64, A_dense_ne) - for i in 1:A_dense_ne - A_dense_val[i] = 0.0 - end l = 0 for i in 1:m A_dense_val[l + i] = 1.0 @@ -57,7 +54,7 @@ function test_llst() end # S = diag(1:n)**2 - S_ne = Cint(n) + S_ne = n S_row = zeros(Cint, S_ne) S_col = zeros(Cint, S_ne) S_ptr = zeros(Cint, n + 1) @@ -70,15 +67,11 @@ function test_llst() S_ptr[i] = i S_val[i] = i * i end - S_ptr[n] = n + 1 + S_ptr[n+1] = n + 1 # store S in dense format S_dense_ne = div(n * (n + 1), 2) S_dense_val = zeros(Float64, S_dense_ne) - for i in 1:S_dense_ne - S_dense_val[i] = 0.0 - end - l = 0 for i in 1:n S_dense_val[l + i] = i * i @@ -86,10 +79,7 @@ function test_llst() end # b is a vector of ones - b = zeros(Float64, m) # observations - for i in 1:m - b[i] = 1.0 - end + b = ones(Float64, m) # observations # trust-region radius is one radius = 1.0 @@ -108,7 +98,7 @@ function test_llst() # Initialize LLST llst_initialize(data, control, status) @reset control[].definite_linear_solver = galahad_linear_solver("potr") - @reset control[].sbls_control.symmetric_linear_solver = galahad_linear_solver("potr") + @reset control[].sbls_control.symmetric_linear_solver = galahad_linear_solver("sytr") @reset control[].sbls_control.definite_linear_solver = galahad_linear_solver("potr") # @reset control[].print_level = Cint(1) @@ -121,15 +111,15 @@ function test_llst() if d == 1 st = 'C' llst_import(control, data, status, m, n, - "coordinate", A_ne, A_row, A_col, Cint[]) + "coordinate", A_ne, A_row, A_col, C_NULL) if use_s == 0 llst_solve_problem(data, status, m, n, radius, - A_ne, A_val, b, x, 0, Cint[]) + A_ne, A_val, b, x, 0, C_NULL) else llst_import_scaling(control, data, status, n, "coordinate", S_ne, S_row, - S_col, Cint[]) + S_col, C_NULL) llst_solve_problem(data, status, m, n, radius, A_ne, A_val, b, x, S_ne, S_val) @@ -140,13 +130,13 @@ function test_llst() if d == 2 st = 'R' llst_import(control, data, status, m, n, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) if use_s == 0 llst_solve_problem(data, status, m, n, radius, - A_ne, A_val, b, x, 0, Cint[]) + A_ne, A_val, b, x, 0, C_NULL) else llst_import_scaling(control, data, status, n, - "sparse_by_rows", S_ne, Cint[], + "sparse_by_rows", S_ne, C_NULL, S_col, S_ptr) llst_solve_problem(data, status, m, n, radius, @@ -158,16 +148,16 @@ function test_llst() if d == 3 st = 'D' llst_import(control, data, status, m, n, - "dense", A_dense_ne, Cint[], Cint[], Cint[]) + "dense", A_dense_ne, C_NULL, C_NULL, C_NULL) if use_s == 0 llst_solve_problem(data, status, m, n, radius, A_dense_ne, A_dense_val, b, x, - 0, Cint[]) + 0, C_NULL) else llst_import_scaling(control, data, status, n, "dense", S_dense_ne, - Cint[], Cint[], Cint[]) + C_NULL, C_NULL, C_NULL) llst_solve_problem(data, status, m, n, radius, A_dense_ne, A_dense_val, b, x, @@ -179,13 +169,13 @@ function test_llst() if d == 4 st = 'I' llst_import(control, data, status, m, n, - "coordinate", A_ne, A_row, A_col, Cint[]) + "coordinate", A_ne, A_row, A_col, C_NULL) if use_s == 0 llst_solve_problem(data, status, m, n, radius, - A_ne, A_val, b, x, 0, Cint[]) + A_ne, A_val, b, x, 0, C_NULL) else llst_import_scaling(control, data, status, n, - "diagonal", S_ne, Cint[], Cint[], Cint[]) + "diagonal", S_ne, C_NULL, C_NULL, C_NULL) llst_solve_problem(data, status, m, n, radius, A_ne, A_val, b, x, S_ne, S_val) diff --git a/src/bqp/C/bqptf.c b/src/bqp/C/bqptf.c index 4c42911d6e..7d338ee919 100644 --- a/src/bqp/C/bqptf.c +++ b/src/bqp/C/bqptf.c @@ -216,10 +216,8 @@ int main(void) { mask[i+1] = 1; nz_prod[nz_prod_end] = i + 1; nz_prod_end = nz_prod_end + 1; - prod[i+1] = prod[i+1] + v[i]; - }else{ - prod[i+1] = prod[i+1] + v[i]; } + prod[i+1] = prod[i+1] + v[i]; } } for( ipc_ l = 0; l < nz_prod_end; l++) mask[nz_prod[l]] = 0; From a7fb27a9daf77045c7dc3dd2ac71c78bcee09134 Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Tue, 13 Feb 2024 00:46:05 -0500 Subject: [PATCH 21/33] debug llsr --- GALAHAD.jl/test/runtests.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/GALAHAD.jl/test/runtests.jl b/GALAHAD.jl/test/runtests.jl index e913ee6bbf..91bc39c581 100644 --- a/GALAHAD.jl/test/runtests.jl +++ b/GALAHAD.jl/test/runtests.jl @@ -3,11 +3,11 @@ using GALAHAD @info("GALAHAD_INSTALLATION : $(GALAHAD.GALAHAD_INSTALLATION)") include("test_structures.jl") -# include("test_arc.jl") -# include("test_bgo.jl") +## include("test_arc.jl") +## include("test_bgo.jl") ## include("test_blls.jl") include("test_bllsb.jl") -# include("test_bqp.jl") +## include("test_bqp.jl") include("test_bqpb.jl") include("test_bsc.jl") include("test_ccqp.jl") @@ -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") # bug ## include("test_llst.jl") include("test_lms.jl") include("test_lpa.jl") @@ -42,7 +42,7 @@ include("test_psls.jl") include("test_qpa.jl") include("test_qpb.jl") include("test_roots.jl") -# include("test_rpd.jl") +include("test_rpd.jl") ## include("test_rqs.jl") include("test_sbls.jl") ## include("test_scu.jl") From cb34dadb8275b7c8250f794f343e28c9f03d8700 Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Tue, 13 Feb 2024 01:28:10 -0500 Subject: [PATCH 22/33] debug llst --- GALAHAD.jl/test/test_llst.jl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/GALAHAD.jl/test/test_llst.jl b/GALAHAD.jl/test/test_llst.jl index 2c9291acc0..c16ba6915b 100644 --- a/GALAHAD.jl/test/test_llst.jl +++ b/GALAHAD.jl/test/test_llst.jl @@ -6,7 +6,7 @@ using Test using Printf using Accessors -function test_llst() +#function test_llst() # Derived types data = Ref{Ptr{Cvoid}}() control = Ref{llst_control_type{Float64}}() @@ -203,9 +203,9 @@ function test_llst() llst_terminate(data, control, inform) end - return 0 -end +# return 0 +# end -@testset "LLST" begin - @test test_llst() == 0 -end +# @testset "LLST" begin +# @test test_llst() == 0 +# end From 781f77d32fd3f6b5d27c8331519e6d08bbe6035c Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Tue, 13 Feb 2024 01:32:29 -0500 Subject: [PATCH 23/33] debug llst --- GALAHAD.jl/test/test_llst.jl | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/GALAHAD.jl/test/test_llst.jl b/GALAHAD.jl/test/test_llst.jl index c16ba6915b..bdff9cb419 100644 --- a/GALAHAD.jl/test/test_llst.jl +++ b/GALAHAD.jl/test/test_llst.jl @@ -9,7 +9,7 @@ using Accessors #function test_llst() # Derived types data = Ref{Ptr{Cvoid}}() - control = Ref{llst_control_type{Float64}}() + global control = Ref{llst_control_type{Float64}}() inform = Ref{llst_inform_type{Float64}}() # Set problem data @@ -24,33 +24,33 @@ using Accessors A_val = zeros(Float64, A_ne) # store A in sparse formats - l = 1 + global l = 1 for i in 1:m A_ptr[i] = l A_row[l] = i A_col[l] = i A_val[l] = 1.0 - l = l + 1 + global l = l + 1 A_row[l] = i A_col[l] = m + i A_val[l] = i - l = l + 1 + global l = l + 1 A_row[l] = i A_col[l] = n A_val[l] = 1.0 - l = l + 1 + global l = l + 1 end A_ptr[m+1] = l # store A in dense format A_dense_ne = m * n A_dense_val = zeros(Float64, A_dense_ne) - l = 0 + global l = 0 for i in 1:m A_dense_val[l + i] = 1.0 A_dense_val[l + m + i] = i A_dense_val[l + n] = 1.0 - l = l + n + global l = l + n end # S = diag(1:n)**2 @@ -72,10 +72,10 @@ using Accessors # store S in dense format S_dense_ne = div(n * (n + 1), 2) S_dense_val = zeros(Float64, S_dense_ne) - l = 0 + global l = 0 for i in 1:n S_dense_val[l + i] = i * i - l = l + i + global l = l + i end # b is a vector of ones @@ -86,7 +86,7 @@ using Accessors # Set output storage x = zeros(Float64, n) # solution - st = ' ' + global st = ' ' status = Ref{Cint}() @printf(" Fortran sparse matrix indexing\n\n") @@ -97,9 +97,9 @@ using Accessors # Initialize LLST llst_initialize(data, control, status) - @reset control[].definite_linear_solver = galahad_linear_solver("potr") - @reset control[].sbls_control.symmetric_linear_solver = galahad_linear_solver("sytr") - @reset control[].sbls_control.definite_linear_solver = galahad_linear_solver("potr") + global @reset control[].definite_linear_solver = galahad_linear_solver("potr") + global @reset control[].sbls_control.symmetric_linear_solver = galahad_linear_solver("sytr") + global @reset control[].sbls_control.definite_linear_solver = galahad_linear_solver("potr") # @reset control[].print_level = Cint(1) # Set user-defined control options @@ -109,7 +109,7 @@ using Accessors for use_s in 0:1 # sparse co-ordinate storage if d == 1 - st = 'C' + global st = 'C' llst_import(control, data, status, m, n, "coordinate", A_ne, A_row, A_col, C_NULL) @@ -128,7 +128,7 @@ using Accessors # sparse by rows if d == 2 - st = 'R' + global st = 'R' llst_import(control, data, status, m, n, "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) if use_s == 0 @@ -146,7 +146,7 @@ using Accessors # dense if d == 3 - st = 'D' + global st = 'D' llst_import(control, data, status, m, n, "dense", A_dense_ne, C_NULL, C_NULL, C_NULL) @@ -167,7 +167,7 @@ using Accessors # diagonal if d == 4 - st = 'I' + global st = 'I' llst_import(control, data, status, m, n, "coordinate", A_ne, A_row, A_col, C_NULL) if use_s == 0 From 15b211575196c6853f0a1b9e3bef9ec99673cfe4 Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Tue, 13 Feb 2024 01:33:05 -0500 Subject: [PATCH 24/33] Add a Julia test for all GALAHAD packages --- GALAHAD.jl/test/test_arc.jl | 675 +++++++++---------- GALAHAD.jl/test/test_bgo.jl | 1220 +++++++++++++++------------------- GALAHAD.jl/test/test_bqp.jl | 295 ++++++++ GALAHAD.jl/test/test_bqpb.jl | 16 +- GALAHAD.jl/test/test_nls.jl | 4 +- GALAHAD.jl/test/test_rpd.jl | 129 ++++ GALAHAD.jl/test/test_slls.jl | 69 +- GALAHAD.jl/test/test_trb.jl | 980 ++++++++++++++------------- GALAHAD.jl/test/test_trs.jl | 56 +- GALAHAD.jl/test/test_tru.jl | 13 +- 10 files changed, 1877 insertions(+), 1580 deletions(-) diff --git a/GALAHAD.jl/test/test_arc.jl b/GALAHAD.jl/test/test_arc.jl index 6849fbaad1..cadec2508a 100644 --- a/GALAHAD.jl/test/test_arc.jl +++ b/GALAHAD.jl/test/test_arc.jl @@ -2,393 +2,400 @@ # Simple code to test the Julia interface to ARC using GALAHAD +using Test using Printf +using Accessors -# Objective function -function fun(n, x, f, userdata) - p = userdata.p - f[] = (x[1] + x[3] + p)^2) + (x[2] + x[3])^2) + cos(x[1]) - return 0 -end - -# Gradient of the objective -function grad(n, x, g, userdata) - p = userdata.p - g[1] = 2.0 * ( x[1] + x[3] + p ) - sin(x[1]) - g[2] = 2.0 * ( x[2] + x[3] ) - g[3] = 2.0 * ( x[1] + x[3] + p ) + 2.0 * ( x[2] + x[3] ) - return 0 -end - -# Hessian of the objective -function hess(n, ne, x, hval, userdata) - hval[1] = 2.0 - cos(x[1]) - hval[2] = 2.0 - hval[3] = 2.0 - hval[4] = 2.0 - hval[5] = 4.0 - return 0 -end - -# Dense Hessian -function hess_dense(n, ne, x, hval, userdata) - hval[1] = 2.0 - cos(x[1]) - hval[2] = 0.0 - hval[3] = 2.0 - hval[4] = 2.0 - hval[5] = 2.0 - hval[6] = 4.0 - return 0 -end - -# Hessian-vector product -function hessprod(n, x, u, v, got_h, userdata) - u[1] = u[1] + 2.0 * ( v[1] + v[3] ) - cos(x[1]) * v[1] - u[2] = u[2] + 2.0 * ( v[2] + v[3] ) - u[3] = u[3] + 2.0 * ( v[1] + v[2] + 2.0 * v[3] ) - return 0 -end - -# Apply preconditioner -function prec(n, x, u, v, userdata) - u[1] = 0.5 * v[1] - u[2] = 0.5 * v[2] - u[3] = 0.25 * v[3] - return 0 -end - - # Objective function -function fun_diag(n, x, f, userdata) - p = userdata.p - f[] = (x[3] + p)^2 + x[2]^2 + cos(x[1]) - return 0 +# Custom userdata struct +struct userdata_type + p::Float64 end -# Gradient of the objective -function grad_diag(n, x, g, userdata) - p = userdata.p - g[1] = - sin(x[1]) - g[2] = 2.0 * x[2] - g[3] = 2.0 * ( x[3] + p ) - return 0 -end +function test_arc() + # Objective function + function fun(n, x, f, userdata) + p = userdata.p + f[] = (x[1] + x[3] + p)^2 + (x[2] + x[3])^2 + cos(x[1]) + return 0 + end -# Hessian of the objective -function hess_diag(n, ne, x, hval, userdata) - hval[1] = - cos(x[1]) - hval[2] = 2.0 - hval[3] = 2.0 - return 0 -end + # Gradient of the objective + function grad(n, x, g, userdata) + p = userdata.p + g[1] = 2.0 * (x[1] + x[3] + p) - sin(x[1]) + g[2] = 2.0 * (x[2] + x[3]) + g[3] = 2.0 * (x[1] + x[3] + p) + 2.0 * (x[2] + x[3]) + return 0 + end -# Hessian-vector product -function hessprod_diag(n, x, u, v, got_h, userdata) - u[1] = u[1] + - cos(x[1]) * v[1] - u[2] = u[2] + 2.0 * v[2] - u[3] = u[3] + 2.0 * v[3] - return 0 -end + # Hessian of the objective + function hess(n, ne, x, hval, userdata) + hval[1] = 2.0 - cos(x[1]) + hval[2] = 2.0 + hval[3] = 2.0 + hval[4] = 2.0 + hval[5] = 4.0 + return 0 + end -# Derived types -data = [Ptr{Ptr{Cvoid}}()] -control = arc_control_type{Float64}() -inform = arc_inform_type{Float64}() + # Dense Hessian + function hess_dense(n, ne, x, hval, userdata) + hval[1] = 2.0 - cos(x[1]) + hval[2] = 0.0 + hval[3] = 2.0 + hval[4] = 2.0 + hval[5] = 2.0 + hval[6] = 4.0 + return 0 + end -# Set user data -mutable struct userdata_type - p::Float64 -end + # Hessian-vector product + function hessprod(n, x, u, v, got_h, userdata) + u[1] = u[1] + 2.0 * (v[1] + v[3]) - cos(x[1]) * v[1] + u[2] = u[2] + 2.0 * (v[2] + v[3]) + u[3] = u[3] + 2.0 * (v[1] + v[2] + 2.0 * v[3]) + return 0 + end -userdata = userdata_type(4.0) + # Apply preconditioner + function prec(n, x, u, v, userdata) + u[1] = 0.5 * v[1] + u[2] = 0.5 * v[2] + u[3] = 0.25 * v[3] + return 0 + end -# Set problem data -n = 3 # dimension -ne = 5 # Hesssian elements -H_row = Cint[1, 2, 3, 3, 3] # Hessian H -H_col = Cint[1, 2, 1, 2, 3] # NB lower triangle -H_ptr = Cint[1, 2, 3, 6] # row pointers + # Objective function + function fun_diag(n, x, f, userdata) + p = userdata.p + f[] = (x[3] + p)^2 + x[2]^2 + cos(x[1]) + return 0 + end -# Set storage -g = zeros(Float64, n) # gradient -st = ' ' -status = Ref{Cint}() + # Gradient of the objective + function grad_diag(n, x, g, userdata) + p = userdata.p + g[1] = -sin(x[1]) + g[2] = 2.0 * x[2] + g[3] = 2.0 * (x[3] + p) + return 0 + end -@printf(" Fortran sparse matrix indexing\n\n") -@printf(" tests options for all-in-one storage format\n\n") + # Hessian of the objective + function hess_diag(n, ne, x, hval, userdata) + hval[1] = -cos(x[1]) + hval[2] = 2.0 + hval[3] = 2.0 + return 0 + end -for d = 1:5 + # Hessian-vector product + function hessprod_diag(n, x, u, v, got_h, userdata) + u[1] = u[1] + -cos(x[1]) * v[1] + u[2] = u[2] + 2.0 * v[2] + u[3] = u[3] + 2.0 * v[3] + return 0 + end - # Initialize ARC - arc_initialize( data, control, status ) + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{arc_control_type{Float64}}() + inform = Ref{arc_inform_type{Float64}}() - # Set user-defined control options - control.f_indexing = true # Fortran sparse matrix indexing + # Set user data + userdata = userdata_type(4.0) - # control.print_level = 1 + # Set problem data + n = 3 # dimension + ne = 5 # Hesssian elements + H_row = Cint[1, 2, 3, 3, 3] # Hessian H + H_col = Cint[1, 2, 1, 2, 3] # NB lower triangle + H_ptr = Cint[1, 2, 3, 6] # row pointers - # Start from 1.5 - x = Float64[1.5,1.5,1.5] + # Set storage + g = zeros(Float64, n) # gradient + st = ' ' + status = Ref{Cint}() - # sparse co-ordinate storage - if d == 1 - global st = 'C' + @printf(" Fortran sparse matrix indexing\n\n") + @printf(" tests options for all-in-one storage format\n\n") - arc_import( control, data, status, n, "coordinate", - ne, H_row, H_col, Cint[] ) + for d in 1:5 - arc_solve_with_mat( data, userdata, status, - n, x, g, ne, fun, grad, hess, prec ) - end + # Initialize ARC + arc_initialize(data, control, status) - # sparse by rows - if d == 2 + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + # @reset control[].print_level = 1 - global st = 'R' + # Start from 1.5 + x = Float64[1.5, 1.5, 1.5] - arc_import( control, data, status, n, "sparse_by_rows", - ne, Cint[], H_col, H_ptr) + # sparse co-ordinate storage + if d == 1 + st = 'C' + arc_import(control, data, status, n, "coordinate", + ne, H_row, H_col, C_NULL) - arc_solve_with_mat( data, userdata, status, - n, x, g, ne, fun, grad, hess, prec ) - end + arc_solve_with_mat(data, userdata, status, + n, x, g, ne, fun, grad, hess, prec) + end - # dense - if d == 3 - global st = 'D' + # sparse by rows + if d == 2 + st = 'R' + arc_import(control, data, status, n, "sparse_by_rows", + ne, C_NULL, H_col, H_ptr) - arc_import( control, data, status, n, "dense", - ne, Cint[], Cint[], Cint[] ) + arc_solve_with_mat(data, userdata, status, + n, x, g, ne, fun, grad, hess, prec) + end - arc_solve_with_mat( data, userdata, status, - n, x, g, ne, fun, grad, hess_dense, prec ) - end + # dense + if d == 3 + st = 'D' + arc_import(control, data, status, n, "dense", + ne, C_NULL, C_NULL, C_NULL) - # diagonal - if d == 4 - global st = 'I' + arc_solve_with_mat(data, userdata, status, + n, x, g, ne, fun, grad, hess_dense, prec) + end - arc_import( control, data, status, n, "diagonal", - ne, Cint[], Cint[], Cint[] ) + # diagonal + if d == 4 + st = 'I' + arc_import(control, data, status, n, "diagonal", + ne, C_NULL, C_NULL, C_NULL) - arc_solve_with_mat( data, userdata, status, n, x, g, - ne, fun_diag, grad_diag, hess_diag, prec) - end + arc_solve_with_mat(data, userdata, status, n, x, g, + ne, fun_diag, grad_diag, hess_diag, prec) + end - # access by products - if d == 5 - global st = 'P' + # access by products + if d == 5 + st = 'P' + arc_import(control, data, status, n, "absent", + ne, C_NULL, C_NULL, C_NULL) - arc_import( control, data, status, n, "absent", - ne, Cint[], Cint[], Cint[] ) + arc_solve_without_mat(data, userdata, status, + n, x, g, fun, grad, hessprod, prec) + end - arc_solve_without_mat( data, userdata, status, - n, x, g, fun, grad, hessprod, prec ) - end + arc_information(data, inform, status) - arc_information( data, inform, status) + if inform[].status[] == 0 + @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", st, + inform[].iter, inform[].obj, inform[].status) + else + @printf("%c: ARC_solve exit status = %1i\n", st, inform[].status) + end - if inform.status == 0 - @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", st, inform.iter, inform.obj, inform.status) - else - @printf("%c: ARC_solve exit status = %1i\n", st, inform.status) + # @printf("x: ") + # for i = 1:n + # @printf("%f ", x[i]) + # end + # @printf("\n") + # @printf("gradient: ") + # for i = 1:n + # @printf("%f ", g[i]) + # end + # @printf("\n") + + # Delete internal workspace + arc_terminate(data, control, inform) end - # @printf("x: ") - # for i = 1:n - # @printf("%f ", x[i]) - # end - # @printf("\n") - # @printf("gradient: ") - # for i = 1:n - # @printf("%f ", g[i]) - # end - # @printf("\n") - - # Delete internal workspace - arc_terminate( data, control, inform ) @printf("\n tests reverse-communication options\n\n") -end -# reverse-communication input/output -eval_status = Ref{Cint}() -f = 0.0 -u = zeros(Float64, n) -v = zeros(Float64, n) -index_nz_u = zeros(Cint, n) -index_nz_v = zeros(Cint, n) -H_val = zeros(Float64, ne) -H_dense = zeros(Float64, n*(n+1)/2) -H_diag = zeros(Float64, n) - -for d = 1:5 - - # Initialize ARC - arc_initialize( data, control, status ) - - # Set user-defined control options - control.f_indexing = true # Fortran sparse matrix indexing - #control.print_level = 1 - - # Start from 1.5 - x = Float64[1.5,1.5,1.5] - - # sparse co-ordinate storage - if d == 1 - global st = 'C' - - arc_import( control, data, status, n, "coordinate", - ne, H_row, H_col, Cint[] ) - - while true # reverse-communication loop - arc_solve_reverse_with_mat( data, status, eval_status, - n, x, f, g, ne, H_val, u, v ) - if status[] == 0 # successful termination - break - elseif status[] < 0 # error exit - error("ARC -- status = $(status[])") - elseif status[] == 2 # evaluate f - eval_status = fun( n, x, f, userdata ) - elseif status[] == 3 # evaluate g - eval_status = grad( n, x, g, userdata ) - elseif status[] == 4 # evaluate H - eval_status = hess( n, ne, x, H_val, userdata ) - elseif status[] == 6 # evaluate the product with P - eval_status = prec( n, x, u, v, userdata ) - else - @printf(" the value %1i of status should not occur\n", status) + # reverse-communication input/output + eval_status = Ref{Cint}() + f = 0.0 + u = zeros(Float64, n) + v = zeros(Float64, n) + H_val = zeros(Float64, ne) + H_dense = zeros(Float64, div(n * (n + 1), 2)) + H_diag = zeros(Float64, n) + + for d in 1:5 + + # Initialize ARC + arc_initialize(data, control, status) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + # @reset control[].print_level = 1 + + # Start from 1.5 + x = Float64[1.5, 1.5, 1.5] + + # sparse co-ordinate storage + if d == 1 + st = 'C' + arc_import(control, data, status, n, "coordinate", + ne, H_row, H_col, C_NULL) + + terminated = false + while !terminated # reverse-communication loop + arc_solve_reverse_with_mat(data, status, eval_status, n, x, f, g, ne, H_val, u, v) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # evaluate f + eval_status = fun(n, x, f, userdata) + elseif status[] == 3 # evaluate g + eval_status = grad(n, x, g, userdata) + elseif status[] == 4 # evaluate H + eval_status = hess(n, ne, x, H_val, userdata) + elseif status[] == 6 # evaluate the product with P + eval_status = prec(n, x, u, v, userdata) + else + @printf(" the value %1i of status should not occur\n", status) + end end - end + end - # sparse by rows - if d == 2 - global st = 'R' - - arc_import( control, data, status, n, "sparse_by_rows", ne, - Cint[], H_col, H_ptr) - - while true # reverse-communication loop - arc_solve_reverse_with_mat( data, status, eval_status, - n, x, f, g, ne, H_val, u, v ) - if status[] == 0 # successful termination - break - elseif status[] < 0 # error exit - error("ARC -- status = $(status[])") - elseif status[] == 2 # evaluate f - eval_status = fun( n, x, f, userdata ) - elseif status[] == 3 # evaluate g - eval_status = grad( n, x, g, userdata ) - elseif status[] == 4 # evaluate H - eval_status = hess( n, ne, x, H_val, userdata ) - elseif status[] == 6 # evaluate the product with P - eval_status = prec( n, x, u, v, userdata ) - else - @printf(" the value %1i of status should not occur\n", status) + # sparse by rows + if d == 2 + st = 'R' + arc_import(control, data, status, n, "sparse_by_rows", ne, + C_NULL, H_col, H_ptr) + + terminated = false + while !terminated # reverse-communication loop + arc_solve_reverse_with_mat(data, status, eval_status, + n, x, f, g, ne, H_val, u, v) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # evaluate f + eval_status = fun(n, x, f, userdata) + elseif status[] == 3 # evaluate g + eval_status = grad(n, x, g, userdata) + elseif status[] == 4 # evaluate H + eval_status = hess(n, ne, x, H_val, userdata) + elseif status[] == 6 # evaluate the product with P + eval_status = prec(n, x, u, v, userdata) + else + @printf(" the value %1i of status should not occur\n", status) + end end - end + end - # dense - if d == 3 - global st = 'D' - - arc_import( control, data, status, n, "dense", - ne, Cint[], Cint[], Cint[] ) - - while true # reverse-communication loop - arc_solve_reverse_with_mat( data, status, eval_status, - n, x, f, g, n*(n+1)/2, H_dense, u, v ) - if status[] == 0 # successful termination - break - elseif status[] < 0 # error exit - error("ARC -- status = $(status[])") - elseif status[] == 2 # evaluate f - eval_status = fun( n, x, f, userdata ) - elseif status[] == 3 # evaluate g - eval_status = grad( n, x, g, userdata ) - elseif status[] == 4 # evaluate H - eval_status = hess_dense( n, n*(n+1)/2, x, H_dense, userdata ) - elseif status[] == 6 # evaluate the product with P - eval_status = prec( n, x, u, v, userdata ) - else - @printf(" the value %1i of status should not occur\n", status) + # dense + if d == 3 + st = 'D' + arc_import(control, data, status, n, "dense", + ne, C_NULL, C_NULL, C_NULL) + + terminated = false + while !terminated # reverse-communication loop + arc_solve_reverse_with_mat(data, status, eval_status, + n, x, f, g, n * (n + 1) / 2, H_dense, u, v) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # evaluate f + eval_status = fun(n, x, f, userdata) + elseif status[] == 3 # evaluate g + eval_status = grad(n, x, g, userdata) + elseif status[] == 4 # evaluate H + eval_status = hess_dense(n, n * (n + 1) / 2, x, H_dense, + userdata) + elseif status[] == 6 # evaluate the product with P + eval_status = prec(n, x, u, v, userdata) + else + @printf(" the value %1i of status should not occur\n", + status) + end end end - end - # diagonal - if d == 4 - global st = 'I' - - arc_import( control, data, status, n, "diagonal", - ne, Cint[], Cint[], Cint[] ) - - while true # reverse-communication loop - arc_solve_reverse_with_mat( data, status, eval_status, - n, x, f, g, n, H_diag, u, v ) - if status[] == 0 # successful termination - break - elseif status[] < 0 # error exit - error("ARC -- status = $(status[])") - elseif status[] == 2 # evaluate f - eval_status = fun_diag( n, x, f, userdata ) - elseif status[] == 3 # evaluate g - eval_status = grad_diag( n, x, g, userdata ) - elseif status[] == 4 # evaluate H - eval_status = hess_diag( n, n, x, H_diag, userdata ) - elseif status[] == 6 # evaluate the product with P - eval_status = prec( n, x, u, v, userdata ) - else - @printf(" the value %1i of status should not occur\n", status) + # diagonal + if d == 4 + st = 'I' + arc_import(control, data, status, n, "diagonal", + ne, C_NULL, C_NULL, C_NULL) + + terminated = false + while !terminated # reverse-communication loop + arc_solve_reverse_with_mat(data, status, eval_status, + n, x, f, g, n, H_diag, u, v) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # evaluate f + eval_status = fun_diag(n, x, f, userdata) + elseif status[] == 3 # evaluate g + eval_status = grad_diag(n, x, g, userdata) + elseif status[] == 4 # evaluate H + eval_status = hess_diag(n, n, x, H_diag, userdata) + elseif status[] == 6 # evaluate the product with P + eval_status = prec(n, x, u, v, userdata) + else + @printf(" the value %1i of status should not occur\n", status) + end end end - end - # access by products - if d == 5 - global st = 'P' - - arc_import( control, data, status, n, "absent", - ne, Cint[], Cint[], Cint[] ) - - while true # reverse-communication loop - arc_solve_reverse_without_mat( data, status, eval_status, - n, x, f, g, u, v ) - if status[] == 0 # successful termination - break - elseif status[] < 0 # error exit - error("ARC -- status = $(status[])") - elseif status[] == 2 # evaluate f - eval_status = fun( n, x, f, userdata ) - elseif status[] == 3 # evaluate g - eval_status = grad( n, x, g, userdata ) - elseif status[] == 5 # evaluate H - eval_status = hessprod( n, x, u, v, false, userdata ) - elseif status[] == 6 # evaluate the product with P - eval_status = prec( n, x, u, v, userdata ) - else - @printf(" the value %1i of status should not occur\n", status) + # access by products + if d == 5 + st = 'P' + arc_import(control, data, status, n, "absent", + ne, C_NULL, C_NULL, C_NULL) + + terminated = false + while !terminated # reverse-communication loop + arc_solve_reverse_without_mat(data, status, eval_status, + n, x, f, g, u, v) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # evaluate f + eval_status = fun(n, x, f, userdata) + elseif status[] == 3 # evaluate g + eval_status = grad(n, x, g, userdata) + elseif status[] == 5 # evaluate H + eval_status = hessprod(n, x, u, v, false, userdata) + elseif status[] == 6 # evaluate the product with P + eval_status = prec(n, x, u, v, userdata) + else + @printf(" the value %1i of status should not occur\n", status) + end end end - end - arc_information( data, inform, status ) + arc_information(data, inform, status) - if inform.status == 0 - @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", st, inform.iter, inform.obj, inform.status) - else - @printf("%c: ARC_solve exit status = %1i\n", st, inform.status) + if inform[].status[] == 0 + @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", st, + inform[].iter, inform[].obj, inform[].status) + else + @printf("%c: ARC_solve exit status = %1i\n", st, inform[].status) + end + + # @printf("x: ") + # for i = 1:n + # @printf("%f ", x[i]) + # end + # @printf("\n") + # @printf("gradient: ") + # for i = 1:n + # @printf("%f ", g[i]) + # end + # @printf("\n") + + # Delete internal workspace + arc_terminate(data, control, inform) end + return 0 +end - # @printf("x: ") - # for i = 1:n - # @printf("%f ", x[i]) - # end - # @printf("\n") - # @printf("gradient: ") - # for i = 1:n - # @printf("%f ", g[i]) - # end - # @printf("\n") - - # Delete internal workspace - arc_terminate( data, control, inform ) +@testset "ARC" begin + @test test_arc() == 0 end diff --git a/GALAHAD.jl/test/test_bgo.jl b/GALAHAD.jl/test/test_bgo.jl index 6b633b7be6..0afd53b9a8 100644 --- a/GALAHAD.jl/test/test_bgo.jl +++ b/GALAHAD.jl/test/test_bgo.jl @@ -1,43 +1,3 @@ -/* bgot2.c */ -/* Full test for the BGO C interface using Fortran sparse matrix indexing */ - -#include -#include -#include "galahad_precision.h" -#include "galahad_cfunctions.h" -#include "galahad_bgo.h" - -# Custom userdata struct -struct userdata_type { - real_wp_ p - real_wp_ freq - real_wp_ mag -] - -# Function prototypes -int fun(int n, const real_wp_ x[], real_wp_ *f, const void *) -int grad(int n, const real_wp_ x[], real_wp_ g[], const void *) -int hess(int n, int ne, const real_wp_ x[], real_wp_ hval[], const void *) -int hess_dense(int n, int ne, const real_wp_ x[], real_wp_ hval[], -const void *) -int hessprod(int n, const real_wp_ x[], real_wp_ u[], const real_wp_ v[], - bool got_h, const void *) -int shessprod(int n, const real_wp_ x[], int nnz_v, const int index_nz_v[], - const real_wp_ v[], int *nnz_u, int index_nz_u[], real_wp_ u[], - bool got_h, const void *) -int prec(int n, const real_wp_ x[], real_wp_ u[], const real_wp_ v[], - const void *) -int fun_diag(int n, const real_wp_ x[], real_wp_ *f, const void *) -int grad_diag(int n, const real_wp_ x[], real_wp_ g[], const void *) -int hess_diag(int n, int ne, const real_wp_ x[], real_wp_ hval[], - const void *) -int hessprod_diag(int n, const real_wp_ x[], real_wp_ u[], const real_wp_ v[], - bool got_h, const void *) -int shessprod_diag(int n, const real_wp_ x[], int nnz_v, -const int index_nz_v[], -const real_wp_ v[], int *nnz_u, int index_nz_u[], -real_wp_ u[], bool got_h, const void *) - # test_bgo.jl # Simple code to test the Julia interface to BGO @@ -46,640 +6,554 @@ using Test using Printf using Accessors -function test_bgo() -# Derived types -data = Ref{Ptr{Cvoid}}() -control = Ref{bgo_control_type{Float64}}() -inform = Ref{bgo_inform_type{Float64}}() - -# Set user data -struct userdata_type userdata -userdata.p = 4.0 -userdata.freq = 10 -userdata.mag = 1000 - -# Set problem data -n = 3 # dimension -ne = 5 # Hesssian elements -x_l = Float64[-10,-10,-10] -x_u = Float64[0.5,0.5,0.5] -H_row = Cint[1, 2, 3, 3, 3] # Hessian H -H_col = Cint[1, 2, 1, 2, 3] # NB lower triangle -H_ptr = Cint[1, 2, 3, 6] # row pointers - -# Set storage -g = zeros(Float64, n) # gradient -st = ' ' -status = Ref{Cint}() - -@printf(" Fortran sparse matrix indexing\n\n") - -@printf(" tests options for all-in-one storage format\n\n") - -for(int d=1 d <= 5 d++) - -# Initialize BGO -bgo_initialize(data, control, status) - -# Set user-defined control options -control[].f_indexing = true # Fortran sparse matrix indexing -control[].attempts_max = 10000 -control[].max_evals = 20000 -control[].sampling_strategy = 3 -control[].trb_control[].maxit = 100 -#control[].print_level = 1 - -# Start from 0 -x = Float64[0,0,0] - -switch(d) -# sparse co-ordinate storage -if d == 1 -st = 'C' -bgo_import(control, data, status, n, x_l, x_u, -"coordinate", ne, H_row, H_col, Cint[]) -bgo_solve_with_mat(data, userdata, status, n, x, g, -ne, fun, grad, hess, hessprod, prec) -end -# sparse by rows -if d == 2 -st = 'R' -bgo_import(control, data, status, n, x_l, x_u, -"sparse_by_rows", ne, Cint[], H_col, H_ptr) -bgo_solve_with_mat(data, userdata, status, n, x, g, -ne, fun, grad, hess, hessprod, prec) -end -# dense -if d == 3 -st = 'D' -bgo_import(control, data, status, n, x_l, x_u, -"dense", ne, Cint[], Cint[], Cint[]) -bgo_solve_with_mat(data, userdata, status, n, x, g, -ne, fun, grad, hess_dense, hessprod, prec) -end -# diagonal -if d == 4 -st = 'I' -bgo_import(control, data, status, n, x_l, x_u, -"diagonal", ne, Cint[], Cint[], Cint[]) -bgo_solve_with_mat(data, userdata, status, n, x, g, -ne, fun_diag, grad_diag, hess_diag, -hessprod_diag, prec) -end -case 5: # access by products -st = 'P' -bgo_import(control, data, status, n, x_l, x_u, -"absent", ne, Cint[], Cint[], Cint[]) -bgo_solve_without_mat(data, userdata, status, n, x, g, - fun, grad, hessprod, shessprod, prec) -end -] - -# Record solution information -bgo_information(data, inform, status) - -if inform[].status == 0 -@printf("%c:%6i evaluations. Optimal objective value = %5.2f" - " status = %1i\n", st, inform[].f_eval, inform[].obj, inform[].status) -else -@printf("%c: BGO_solve exit status = %1i\n", st, inform[].status) - -# @printf("x: ") -# for(int i = 0 i < n i++) @printf("%f ", x[i]) -# @printf("\n") -# @printf("gradient: ") -# for(int i = 0 i < n i++) @printf("%f ", g[i]) -# @printf("\n") - -# Delete internal workspace -bgo_terminate(data, control, inform) -@printf("\n tests reverse-communication options\n\n") - -# reverse-communication input/output -int eval_status, nnz_u, nnz_v -f = 0.0 -u = zeros(Float64, n), v[n] -index_nz_u = zeros(Cint, n), index_nz_v[n] -real_wp_ H_val[ne], H_dense[n*(n+1)/2], H_diag[n] - -for(int d=1 d <= 5 d++) - -# Initialize BGO -bgo_initialize(data, control, status) - -# Set user-defined control options -control[].f_indexing = true # Fortran sparse matrix indexing -control[].attempts_max = 10000 -control[].max_evals = 20000 -control[].sampling_strategy = 3 -control[].trb_control[].maxit = 100 -#control[].print_level = 1 - -# Start from 0 -x = Float64[0,0,0] - -switch(d) -# sparse co-ordinate storage -if d == 1 -st = 'C' -bgo_import(control, data, status, n, x_l, x_u, -"coordinate", ne, H_row, H_col, Cint[]) -while true # reverse-communication loop -bgo_solve_reverse_with_mat(data, status, eval_status, -n, x, f, g, ne, H_val, u, v) -if status == 0 # successful termination -end -}elseif status < 0) # error exit -end -}elseif status == 2) # evaluate f -eval_status = fun(n, x, f, userdata) -elseif status == 3) # evaluate g -eval_status = grad(n, x, g, userdata) -elseif status == 4) # evaluate H -eval_status = hess(n, ne, x, H_val, userdata) -elseif status == 5) # evaluate Hv product -eval_status = hessprod(n, x, u, v, false, userdata) -elseif status == 6) # evaluate the product with P -eval_status = prec(n, x, u, v, userdata) -elseif status == 23) # evaluate f and g -eval_status = fun(n, x, f, userdata) -eval_status = grad(n, x, g, userdata) -elseif status == 25) # evaluate f and Hv product -eval_status = fun(n, x, f, userdata) -eval_status = hessprod(n, x, u, v, false, userdata) -elseif status == 35) # evaluate g and Hv product -eval_status = grad(n, x, g, userdata) -eval_status = hessprod(n, x, u, v, false, userdata) -elseif status == 235) # evaluate f, g and Hv product -eval_status = fun(n, x, f, userdata) -eval_status = grad(n, x, g, userdata) -eval_status = hessprod(n, x, u, v, false, userdata) -else -@printf(" the value %1i of status should not occur\n", - status) -end -] -] -end -# sparse by rows -if d == 2 -st = 'R' -bgo_import(control, data, status, n, x_l, x_u, -"sparse_by_rows", ne, Cint[], H_col, H_ptr) -while true # reverse-communication loop -bgo_solve_reverse_with_mat(data, status, eval_status, -n, x, f, g, ne, H_val, u, v) -if status == 0 # successful termination -end -}elseif status < 0) # error exit -end -}elseif status == 2) # evaluate f -eval_status = fun(n, x, f, userdata) -elseif status == 3) # evaluate g -eval_status = grad(n, x, g, userdata) -elseif status == 4) # evaluate H -eval_status = hess(n, ne, x, H_val, userdata) -elseif status == 5) # evaluate Hv product -eval_status = hessprod(n, x, u, v, false, userdata) -elseif status == 6) # evaluate the product with P -eval_status = prec(n, x, u, v, userdata) -elseif status == 23) # evaluate f and g -eval_status = fun(n, x, f, userdata) -eval_status = grad(n, x, g, userdata) -elseif status == 25) # evaluate f and Hv product -eval_status = fun(n, x, f, userdata) -eval_status = hessprod(n, x, u, v, false, userdata) -elseif status == 35) # evaluate g and Hv product -eval_status = grad(n, x, g, userdata) -eval_status = hessprod(n, x, u, v, false, userdata) -elseif status == 235) # evaluate f, g and Hv product -eval_status = fun(n, x, f, userdata) -eval_status = grad(n, x, g, userdata) -eval_status = hessprod(n, x, u, v, false, userdata) -else -@printf(" the value %1i of status should not occur\n", - status) -end -] -] -end -# dense -if d == 3 -st = 'D' -bgo_import(control, data, status, n, x_l, x_u, -"dense", ne, Cint[], Cint[], Cint[]) -while true # reverse-communication loop -bgo_solve_reverse_with_mat(data, status, eval_status, -n, x, f, g, n*(n+1)/2, -H_dense, u, v) -if status == 0 # successful termination -end -}elseif status < 0) # error exit -end -}elseif status == 2) # evaluate f -eval_status = fun(n, x, f, userdata) -elseif status == 3) # evaluate g -eval_status = grad(n, x, g, userdata) -elseif status == 4) # evaluate H -eval_status = hess_dense(n, n*(n+1)/2, x, H_dense, - userdata) -elseif status == 5) # evaluate Hv product -eval_status = hessprod(n, x, u, v, false, userdata) -elseif status == 6) # evaluate the product with P -eval_status = prec(n, x, u, v, userdata) -elseif status == 23) # evaluate f and g -eval_status = fun(n, x, f, userdata) -eval_status = grad(n, x, g, userdata) -elseif status == 25) # evaluate f and Hv product -eval_status = fun(n, x, f, userdata) -eval_status = hessprod(n, x, u, v, false, userdata) -elseif status == 35) # evaluate g and Hv product -eval_status = grad(n, x, g, userdata) -eval_status = hessprod(n, x, u, v, false, userdata) -elseif status == 235) # evaluate f, g and Hv product -eval_status = fun(n, x, f, userdata) -eval_status = grad(n, x, g, userdata) -eval_status = hessprod(n, x, u, v, false, userdata) -else -@printf(" the value %1i of status should not occur\n", - status) -end -] -] -end -# diagonal -if d == 4 -st = 'I' -bgo_import(control, data, status, n, x_l, x_u, -"diagonal", ne, Cint[], Cint[], Cint[]) -while true # reverse-communication loop -bgo_solve_reverse_with_mat(data, status, eval_status, -n, x, f, g, n, H_diag, u, v) -if status == 0 # successful termination -end -}elseif status < 0) # error exit -end -}elseif status == 2) # evaluate f -eval_status = fun_diag(n, x, f, userdata) -elseif status == 3) # evaluate g -eval_status = grad_diag(n, x, g, userdata) -elseif status == 4) # evaluate H -eval_status = hess_diag(n, n, x, H_diag, userdata) -elseif status == 5) # evaluate Hv product -eval_status = hessprod_diag(n, x, u, v, false, - userdata) -elseif status == 6) # evaluate the product with P -eval_status = prec(n, x, u, v, userdata) -elseif status == 23) # evaluate f and g -eval_status = fun_diag(n, x, f, userdata) -eval_status = grad_diag(n, x, g, userdata) -elseif status == 25) # evaluate f and Hv product -eval_status = fun_diag(n, x, f, userdata) -eval_status = hessprod_diag(n, x, u, v, false, - userdata) -elseif status == 35) # evaluate g and Hv product -eval_status = grad_diag(n, x, g, userdata) -eval_status = hessprod_diag(n, x, u, v, false, - userdata) -elseif status == 235) # evaluate f, g and Hv product -eval_status = fun_diag(n, x, f, userdata) -eval_status = grad_diag(n, x, g, userdata) -eval_status = hessprod_diag(n, x, u, v, false, - userdata) -else -@printf(" the value %1i of status should not occur\n", - status) -end -] -] -end -case 5: # access by products -st = 'P' -bgo_import(control, data, status, n, x_l, x_u, -"absent", ne, Cint[], Cint[], Cint[]) -nnz_u = 0 -while true # reverse-communication loop -bgo_solve_reverse_without_mat(data, status, eval_status, - n, x, f, g, u, v, index_nz_v, - nnz_v, index_nz_u, nnz_u) -if status == 0 # successful termination -end -}elseif status < 0) # error exit -end -}elseif status == 2) # evaluate f -eval_status = fun(n, x, f, userdata) -elseif status == 3) # evaluate g -eval_status = grad(n, x, g, userdata) -elseif status == 5) # evaluate Hv product -eval_status = hessprod(n, x, u, v, false, userdata) -elseif status == 6) # evaluate the product with P -eval_status = prec(n, x, u, v, userdata) -elseif status == 7) # evaluate sparse Hess-vect product -eval_status = shessprod(n, x, nnz_v, index_nz_v, v, - nnz_u, index_nz_u, u, - false, userdata) -elseif status == 23) # evaluate f and g -eval_status = fun(n, x, f, userdata) -eval_status = grad(n, x, g, userdata) -elseif status == 25) # evaluate f and Hv product -eval_status = fun(n, x, f, userdata) -eval_status = hessprod(n, x, u, v, false, userdata) -elseif status == 35) # evaluate g and Hv product -eval_status = grad(n, x, g, userdata) -eval_status = hessprod(n, x, u, v, false, userdata) -elseif status == 235) # evaluate f, g and Hv product -eval_status = fun(n, x, f, userdata) -eval_status = grad(n, x, g, userdata) -eval_status = hessprod(n, x, u, v, false, userdata) -else -@printf(" the value %1i of status should not occur\n", - status) -end -] -] -end -] - -# Record solution information -bgo_information(data, inform, status) - -if inform[].status == 0 -@printf("%c:%6i evaluations. Optimal objective value = %5.2f" - " status = %1i\n", st, inform[].f_eval, inform[].obj, inform[].status) -else -@printf("%c: BGO_solve exit status = %1i\n", st, inform[].status) - -# @printf("x: ") -# for(int i = 0 i < n i++) @printf("%f ", x[i]) -# @printf("\n") -# @printf("gradient: ") -# for(int i = 0 i < n i++) @printf("%f ", g[i]) -# @printf("\n") - -# Delete internal workspace -bgo_terminate(data, control, inform) -] - -# Objective function -int fun(int n, - const real_wp_ x[], - real_wp_ *f, - const void *userdata) -struct userdata_type *myuserdata = (struct userdata_type *) userdata -real_wp_ p = myuserdata->p -real_wp_ freq = myuserdata->freq -real_wp_ mag = myuserdata->mag - -*f = pow(x[0] + x[2] + p, 2) + pow(x[1] + x[2], 2) + mag * cos(freq*x[0]) - + x[0] + x[1] + x[2] -return 0 -] - -# Gradient of the objective -int grad(int n, - const real_wp_ x[], - real_wp_ g[], - const void *userdata) -struct userdata_type *myuserdata = (struct userdata_type *) userdata -real_wp_ p = myuserdata->p -real_wp_ freq = myuserdata->freq -real_wp_ mag = myuserdata->mag - -g[0] = 2.0 * (x[0] + x[2] + p) - mag * freq * sin(freq*x[0]) + 1 -g[1] = 2.0 * (x[1] + x[2]) + 1 -g[2] = 2.0 * (x[0] + x[2] + p) + 2.0 * (x[1] + x[2]) + 1 -return 0 -] - -# Hessian of the objective -int hess(int n, - int ne, - const real_wp_ x[], - real_wp_ hval[], - const void *userdata) -struct userdata_type *myuserdata = (struct userdata_type *) userdata -real_wp_ freq = myuserdata->freq -real_wp_ mag = myuserdata->mag - -hval[0] = 2.0 - mag * freq * freq * cos(freq*x[0]) -hval[1] = 2.0 -hval[2] = 2.0 -hval[3] = 2.0 -hval[4] = 4.0 -return 0 -] - -# Dense Hessian -int hess_dense(int n, -int ne, -const real_wp_ x[], -real_wp_ hval[], -const void *userdata) -struct userdata_type *myuserdata = (struct userdata_type *) userdata -real_wp_ freq = myuserdata->freq -real_wp_ mag = myuserdata->mag - -hval[0] = 2.0 - mag * freq * freq * cos(freq*x[0]) -hval[1] = 0.0 -hval[2] = 2.0 -hval[3] = 2.0 -hval[4] = 2.0 -hval[5] = 4.0 -return 0 -] - -# Hessian-vector product -int hessprod(int n, - const real_wp_ x[], - real_wp_ u[], - const real_wp_ v[], - bool got_h, - const void *userdata) -struct userdata_type *myuserdata = (struct userdata_type *) userdata -real_wp_ freq = myuserdata->freq -real_wp_ mag = myuserdata->mag - -u[0] = u[0] + 2.0 * (v[0] + v[2]) - - mag * freq * freq * cos(freq*x[0]) * v[0] -u[1] = u[1] + 2.0 * (v[1] + v[2]) -u[2] = u[2] + 2.0 * (v[0] + v[1] + 2.0 * v[2]) -return 0 -] - -# Sparse Hessian-vector product -int shessprod(int n, - const real_wp_ x[], - int nnz_v, - const int index_nz_v[], - const real_wp_ v[], - int *nnz_u, - int index_nz_u[], - real_wp_ u[], - bool got_h, - const void *userdata) -struct userdata_type *myuserdata = (struct userdata_type *) userdata -real_wp_ freq = myuserdata->freq -real_wp_ mag = myuserdata->mag - -real_wp_ p[] = {0., 0., 0.] -bool used[] = {false, false, false] -for(int i = 0 i < nnz_v i++) -int j = index_nz_v[i] -switch(j) -case 1: -p[0] = p[0] + 2.0 * v[0] - - mag * freq * freq * cos(freq*x[0]) * v[0] -used[0] = true -p[2] = p[2] + 2.0 * v[0] -used[2] = true -end -case 2: -p[1] = p[1] + 2.0 * v[1] -used[1] = true -p[2] = p[2] + 2.0 * v[1] -used[2] = true -end -case 3: -p[0] = p[0] + 2.0 * v[2] -used[0] = true -p[1] = p[1] + 2.0 * v[2] -used[1] = true -p[2] = p[2] + 4.0 * v[2] -used[2] = true -end -] -] -*nnz_u = 0 -for(int j = 0 j < 3 j++) -if used[j]) -u[j] = p[j] -*nnz_u = *nnz_u + 1 -index_nz_u[*nnz_u-1] = j+1 -] -] -return 0 -] - -# Apply preconditioner -int prec(int n, - const real_wp_ x[], - real_wp_ u[], - const real_wp_ v[], - const void *userdata) - u[0] = 0.5 * v[0] - u[1] = 0.5 * v[1] - u[2] = 0.25 * v[2] - return 0 -] - -# Objective function -int fun_diag(int n, - const real_wp_ x[], - real_wp_ *f, - const void *userdata) -struct userdata_type *myuserdata = (struct userdata_type *) userdata -real_wp_ p = myuserdata->p -real_wp_ freq = myuserdata->freq -real_wp_ mag = myuserdata->mag - -*f = pow(x[2] + p, 2) + pow(x[1], 2) + mag * cos(freq*x[0]) - + x[0] + x[1] + x[2] -return 0 -] - -# Gradient of the objective -int grad_diag(int n, - const real_wp_ x[], - real_wp_ g[], - const void *userdata) -struct userdata_type *myuserdata = (struct userdata_type *) userdata -real_wp_ p = myuserdata->p -real_wp_ freq = myuserdata->freq -real_wp_ mag = myuserdata->mag - -g[0] = -mag * freq * sin(freq*x[0]) + 1 -g[1] = 2.0 * x[1] + 1 -g[2] = 2.0 * (x[2] + p) + 1 -return 0 -] - -# Hessian of the objective -int hess_diag(int n, - int ne, - const real_wp_ x[], - real_wp_ hval[], - const void *userdata) -struct userdata_type *myuserdata = (struct userdata_type *) userdata -real_wp_ freq = myuserdata->freq -real_wp_ mag = myuserdata->mag - -hval[0] = -mag * freq * freq * cos(freq*x[0]) -hval[1] = 2.0 -hval[2] = 2.0 -return 0 -] - -# Hessian-vector product -int hessprod_diag(int n, - const real_wp_ x[], - real_wp_ u[], - const real_wp_ v[], - bool got_h, - const void *userdata) -struct userdata_type *myuserdata = (struct userdata_type *) userdata -real_wp_ freq = myuserdata->freq -real_wp_ mag = myuserdata->mag - -u[0] = u[0] + -mag * freq * freq * cos(freq*x[0]) * v[0] -u[1] = u[1] + 2.0 * v[1] -u[2] = u[2] + 2.0 * v[2] -return 0 -] - -# Sparse Hessian-vector product -int shessprod_diag(int n, -const real_wp_ x[], -int nnz_v, -const int index_nz_v[], -const real_wp_ v[], -int *nnz_u, -int index_nz_u[], -real_wp_ u[], -bool got_h, -const void *userdata) -struct userdata_type *myuserdata = (struct userdata_type *) userdata -real_wp_ freq = myuserdata->freq -real_wp_ mag = myuserdata->mag - -real_wp_ p[] = {0., 0., 0.] -bool used[] = {false, false, false] -for(int i = 0 i < nnz_v i++) -int j = index_nz_v[i] -switch(j) -case 1: -p[0] = p[0] - mag * freq * freq * cos(freq*x[0]) * v[0] -used[0] = true -end -case 2: -p[1] = p[1] + 2.0 * v[1] -used[1] = true -end -case 3: -p[2] = p[2] + 2.0 * v[2] -used[2] = true +# Custom userdata struct +struct userdata_type + p::Float64 + freq::Float64 + mag::Float64 end -] -] -*nnz_u = 0 -for(int j = 0 j < 3 j++) -if used[j]) -u[j] = p[j] -*nnz_u = *nnz_u + 1 -index_nz_u[*nnz_u-1] = j+1 -] -] -return 0 -] + +function test_bgo() + + # # Objective function + # function fun(n::Int, var::Vector{Float64}, f::Ptr{Float64}, userdata::Ptr{Cvoid}) + # p = myuserdata.p + # freq = myuserdata.freq + # mag = myuserdata.mag + + # f_val = (var[1] + var[3] + p)^2 + (var[2] + var[3])^2 + mag * cos(freq * var[1]) + sum(var) + # unsafe_store!(f, f_val) + # return 0 + # end + + # # Gradient of the objective + # function grad(n::Int, var::Vector{Float64}, g::Vector{Float64}, userdata::Ptr{Cvoid}) + # struct Cuserdata_type + # p::Float64 + # freq::Float64 + # mag::Float64 + # end + # myuserdata = unsafe_load(Cuserdata_type, userdata) + # p = myuserdata.p + # freq = myuserdata.freq + # mag = myuserdata.mag + + # g[1] = 2.0 * (var[1] + var[3] + p) - mag * freq * sin(freq * var[1]) + 1.0 + # g[2] = 2.0 * (var[2] + var[3]) + 1.0 + # g[3] = 2.0 * (var[1] + var[3] + p) + 2.0 * (var[2] + var[3]) + 1.0 + # return 0 + # end + + # # Hessian of the objective + # function hess(n::Int, ne::Int, var::Vector{Float64}, hval::Vector{Float64}, userdata::Ptr{Cvoid}) + # struct Cuserdata_type + # p::Float64 + # freq::Float64 + # mag::Float64 + # end + # myuserdata = unsafe_load(Cuserdata_type, userdata) + # freq = myuserdata.freq + # mag = myuserdata.mag + + # hval[1] = 2.0 - mag * freq^2 * cos(freq * var[1]) + # hval[2] = 2.0 + # hval[3] = 2.0 + # hval[4] = 4.0 + # return 0 + # end + + # # Dense Hessian + # function hess_dense(n::Int, ne::Int, var::Vector{Float64}, hval::Vector{Float64}, userdata::Ptr{Cvoid}) + # struct Cuserdata_type + # p::Float64 + # freq::Float64 + # mag::Float64 + # end + # myuserdata = unsafe_load(Cuserdata_type, userdata) + # freq = myuserdata.freq + # mag = myuserdata.mag + + # hval[1] = 2.0 - mag * freq^2 * cos(freq * var[1]) + # hval[2] = 0.0 + # hval[3] = 2.0 + # hval[4] = 2.0 + # hval[5] = 4.0 + # return 0 + # end + + # # Hessian-vector product + # function hessprod(n::Int, var::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, got_h::Bool, userdata::Ptr{Cvoid}) + # struct Cuserdata_type + # p::Float64 + # freq::Float64 + # mag::Float64 + # end + # myuserdata = unsafe_load(Cuserdata_type, userdata) + # freq = myuserdata.freq + # mag = myuserdata.mag + + # u[1] = u[1] + 2.0 * (v[1] + v[3]) - mag * freq^2 * cos(freq * var[1]) * v[1] + # u[2] = u[2] + 2.0 * (v[2] + v[3]) + # u[3] = u[3] + 2.0 * (v[1] + v[2] + 2.0 * v[3]) + # return 0 + # end + + # # Sparse Hessian-vector product + # function shessprod(n::Int, var::Vector{Float64}, nnz_v::Int, index_nz_v::Vector{Int}, v::Vector{Float64}, + # nnz_u::Ptr{Int}, index_nz_u::Vector{Int}, u::Vector{Float64}, got_h::Bool, userdata::Ptr{Cvoid}) + # struct Cuserdata_type + # p::Float64 + # freq::Float64 + # mag::Float64 + # end + # myuserdata = unsafe_load(Cuserdata_type, userdata) + # freq = myuserdata.freq + # mag = myuserdata.mag + + # p = zeros(3) + # used = [false, false, false] + # for i in 1:nnz_v + # j = index_nz_v[i] + # if j == 1 + # p[1] += 2.0 * v[1] - mag * freq^2 * cos(freq * var[1]) * v[1] + # used[1] = true + # p[3] += 2.0 * v[1] + # used[3] = true + # elseif j == 2 + # p[2] += 2.0 * v[2] + # used[2] = true + # p[3] += 2.0 * v[2] + # used[3] = true + # elseif j == 3 + # p[1] += 2.0 * v[3] + # used[1] = true + # p[2] += 2.0 * v[3] + # used[2] = true + # p[3] += 4.0 * v[3] + # used[3] = true + # end + # end + + # nnz = 0 + # for j in 1:3 + # if used[j] + # u[j] = p[j] + # nnz += 1 + # index_nz_u[nnz] = j + # end + # end + # unsafe_store!(nnz_u, nnz) + # return 0 + # end + + # # Apply preconditioner + # function prec(n::Int, var::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, userdata::Ptr{Cvoid}) + # u[1] = 0.5 * v[1] + # u[2] = 0.5 * v[2] + # u[3] = 0.25 * v[3] + # return 0 + # end + + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{bgo_control_type{Float64}}() + inform = Ref{bgo_inform_type{Float64}}() + + # Set user data + userdata = userdata_type(4.0, 10, 1000) + + # Set problem data + n = 3 # dimension + ne = 5 # Hesssian elements + x_l = Float64[-10, -10, -10] + x_u = Float64[0.5, 0.5, 0.5] + H_row = Cint[1, 2, 3, 3, 3] # Hessian H + H_col = Cint[1, 2, 1, 2, 3] # NB lower triangle + H_ptr = Cint[1, 2, 3, 6] # row pointers + + # Set storage + g = zeros(Float64, n) # gradient + st = ' ' + status = Ref{Cint}() + + @printf(" Fortran sparse matrix indexing\n\n") + @printf(" tests options for all-in-one storage format\n\n") + + for d in 1:5 + + # Initialize BGO + bgo_initialize(data, control, status) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + @reset control[].attempts_max = 10000 + @reset control[].max_evals = 20000 + @reset control[].sampling_strategy = 3 + @reset control[].trb_control.maxit = 100 + # @reset control[].print_level = 1 + + # Start from 0 + x = Float64[0.0, 0.0, 0.0] + + # sparse co-ordinate storage + if d == 1 + st = 'C' + bgo_import(control, data, status, n, x_l, x_u, + "coordinate", ne, H_row, H_col, C_NULL) + + bgo_solve_with_mat(data, userdata, status, n, x, g, + ne, fun, grad, hess, hessprod, prec) + end + + # sparse by rows + if d == 2 + st = 'R' + bgo_import(control, data, status, n, x_l, x_u, + "sparse_by_rows", ne, C_NULL, H_col, H_ptr) + + bgo_solve_with_mat(data, userdata, status, n, x, g, + ne, fun, grad, hess, hessprod, prec) + end + + # dense + if d == 3 + st = 'D' + bgo_import(control, data, status, n, x_l, x_u, + "dense", ne, C_NULL, C_NULL, C_NULL) + + bgo_solve_with_mat(data, userdata, status, n, x, g, + ne, fun, grad, hess_dense, hessprod, prec) + end + + # diagonal + if d == 4 + st = 'I' + bgo_import(control, data, status, n, x_l, x_u, + "diagonal", ne, C_NULL, C_NULL, C_NULL) + + bgo_solve_with_mat(data, userdata, status, n, x, g, + ne, fun_diag, grad_diag, hess_diag, + hessprod_diag, prec) + end + + # access by products + if d == 5 + st = 'P' + bgo_import(control, data, status, n, x_l, x_u, + "absent", ne, C_NULL, C_NULL, C_NULL) + + bgo_solve_without_mat(data, userdata, status, n, x, g, + fun, grad, hessprod, shessprod, prec) + end + + # Record solution information + bgo_information(data, inform, status) + + if inform[].status == 0 + @printf("%c:%6i evaluations. Optimal objective value = %5.2f status = %1i\n", st, + inform[].f_eval, inform[].obj, inform[].status) + else + @printf("%c: BGO_solve exit status = %1i\n", st, inform[].status) + end + + # @printf("x: ") + # for i in 1:n + # @printf("%f ", x[i]) + # end + # @printf("\n") + # @printf("gradient: ") + # for i in 1:n + # @printf("%f ", g[i]) + # end + # @printf("\n") + + # Delete internal workspace + bgo_terminate(data, control, inform) + end + + @printf("\n tests reverse-communication options\n\n") + + # reverse-communication input/output + eval_status = Ref{Cint}() + nnz_u = Ref{Cint}() + nnz_v = Ref{Cint}() + f = Ref{Float64}(0.0) + u = zeros(Float64, n) + v = zeros(Float64, n) + index_nz_u = zeros(Cint, n) + index_nz_v = zeros(Cint, n) + H_val = zeros(Float64, ne) + H_dense = zeros(Float64, div(n * (n + 1), 2)) + H_diag = zeros(Float64, n) + + for d in 1:5 + + # Initialize BGO + bgo_initialize(data, control, status) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + @reset control[].attempts_max = 10000 + @reset control[].max_evals = 20000 + @reset control[].sampling_strategy = 3 + @reset control[].trb_control.maxit = 100 + # @reset control[].print_level = 1 + + # Start from 0 + x = Float64[0.0, 0.0, 0.0] + + # sparse co-ordinate storage + if d == 1 + st = 'C' + bgo_import(control, data, status, n, x_l, x_u, + "coordinate", ne, H_row, H_col, C_NULL) + + terminated = false + while !terminated # reverse-communication loop + bgo_solve_reverse_with_mat(data, status, eval_status, + n, x, f, g, ne, H_val, u, v) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # evaluate f + eval_status = fun(n, x, f, userdata) + elseif status[] == 3 # evaluate g + eval_status = grad(n, x, g, userdata) + elseif status[] == 4 # evaluate H + eval_status = hess(n, ne, x, H_val, userdata) + elseif status[] == 5 # evaluate Hv product + eval_status = hessprod(n, x, u, v, false, userdata) + elseif status[] == 6 # evaluate the product with P + eval_status = prec(n, x, u, v, userdata) + elseif status[] == 23 # evaluate f and g + eval_status = fun(n, x, f, userdata) + eval_status = grad(n, x, g, userdata) + elseif status[] == 25 # evaluate f and Hv product + eval_status = fun(n, x, f, userdata) + eval_status = hessprod(n, x, u, v, false, userdata) + elseif status[] == 35 # evaluate g and Hv product + eval_status = grad(n, x, g, userdata) + eval_status = hessprod(n, x, u, v, false, userdata) + elseif status[] == 235 # evaluate f, g and Hv product + eval_status = fun(n, x, f, userdata) + eval_status = grad(n, x, g, userdata) + eval_status = hessprod(n, x, u, v, false, userdata) + else + @printf(" the value %1i of status should not occur\n", + status) + end + end + end + + # sparse by rows + if d == 2 + st = 'R' + bgo_import(control, data, status, n, x_l, x_u, + "sparse_by_rows", ne, C_NULL, H_col, H_ptr) + + terminated = false + while !terminated # reverse-communication loop + bgo_solve_reverse_with_mat(data, status, eval_status, + n, x, f, g, ne, H_val, u, v) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # evaluate f + eval_status = fun(n, x, f, userdata) + elseif status[] == 3 # evaluate g + eval_status = grad(n, x, g, userdata) + elseif status[] == 4 # evaluate H + eval_status = hess(n, ne, x, H_val, userdata) + elseif status[] == 5 # evaluate Hv product + eval_status = hessprod(n, x, u, v, false, userdata) + elseif status[] == 6 # evaluate the product with P + eval_status = prec(n, x, u, v, userdata) + elseif status[] == 23 # evaluate f and g + eval_status = fun(n, x, f, userdata) + eval_status = grad(n, x, g, userdata) + elseif status[] == 25 # evaluate f and Hv product + eval_status = fun(n, x, f, userdata) + eval_status = hessprod(n, x, u, v, false, userdata) + elseif status[] == 35 # evaluate g and Hv product + eval_status = grad(n, x, g, userdata) + eval_status = hessprod(n, x, u, v, false, userdata) + elseif status[] == 235 # evaluate f, g and Hv product + eval_status = fun(n, x, f, userdata) + eval_status = grad(n, x, g, userdata) + eval_status = hessprod(n, x, u, v, false, userdata) + else + @printf(" the value %1i of status should not occur\n", status) + end + end + end + + # dense + if d == 3 + st = 'D' + bgo_import(control, data, status, n, x_l, x_u, + "dense", ne, C_NULL, C_NULL, C_NULL) + + terminated = false + while !terminated # reverse-communication loop + bgo_solve_reverse_with_mat(data, status, eval_status, + n, x, f, g, n * (n + 1) / 2, + H_dense, u, v) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # evaluate f + eval_status = fun(n, x, f, userdata) + elseif status[] == 3 # evaluate g + eval_status = grad(n, x, g, userdata) + elseif status[] == 4 # evaluate H + eval_status = hess_dense(n, n * (n + 1) / 2, x, H_dense, + userdata) + elseif status[] == 5 # evaluate Hv product + eval_status = hessprod(n, x, u, v, false, userdata) + elseif status[] == 6 # evaluate the product with P + eval_status = prec(n, x, u, v, userdata) + elseif status[] == 23 # evaluate f and g + eval_status = fun(n, x, f, userdata) + eval_status = grad(n, x, g, userdata) + elseif status[] == 25 # evaluate f and Hv product + eval_status = fun(n, x, f, userdata) + eval_status = hessprod(n, x, u, v, false, userdata) + elseif status[] == 35 # evaluate g and Hv product + eval_status = grad(n, x, g, userdata) + eval_status = hessprod(n, x, u, v, false, userdata) + elseif status[] == 235 # evaluate f, g and Hv product + eval_status = fun(n, x, f, userdata) + eval_status = grad(n, x, g, userdata) + eval_status = hessprod(n, x, u, v, false, userdata) + else + @printf(" the value %1i of status should not occur\n", status) + end + end + end + + # diagonal + if d == 4 + st = 'I' + bgo_import(control, data, status, n, x_l, x_u, + "diagonal", ne, C_NULL, C_NULL, C_NULL) + + terminated = false + while !terminated # reverse-communication loop + bgo_solve_reverse_with_mat(data, status, eval_status, + n, x, f, g, n, H_diag, u, v) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # evaluate f + eval_status = fun_diag(n, x, f, userdata) + elseif status[] == 3 # evaluate g + eval_status = grad_diag(n, x, g, userdata) + elseif status[] == 4 # evaluate H + eval_status = hess_diag(n, n, x, H_diag, userdata) + elseif status[] == 5 # evaluate Hv product + eval_status = hessprod_diag(n, x, u, v, false, + userdata) + elseif status[] == 6 # evaluate the product with P + eval_status = prec(n, x, u, v, userdata) + elseif status[] == 23 # evaluate f and g + eval_status = fun_diag(n, x, f, userdata) + eval_status = grad_diag(n, x, g, userdata) + elseif status[] == 25 # evaluate f and Hv product + eval_status = fun_diag(n, x, f, userdata) + eval_status = hessprod_diag(n, x, u, v, false, + userdata) + elseif status[] == 35 # evaluate g and Hv product + eval_status = grad_diag(n, x, g, userdata) + eval_status = hessprod_diag(n, x, u, v, false, + userdata) + elseif status[] == 235 # evaluate f, g and Hv product + eval_status = fun_diag(n, x, f, userdata) + eval_status = grad_diag(n, x, g, userdata) + eval_status = hessprod_diag(n, x, u, v, false, + userdata) + else + @printf(" the value %1i of status should not occur\n", status) + end + end + end + + # access by products + if d == 5 + st = 'P' + bgo_import(control, data, status, n, x_l, x_u, + "absent", ne, C_NULL, C_NULL, C_NULL) + nnz_u = 0 + + terminated = false + while !terminated # reverse-communication loop + bgo_solve_reverse_without_mat(data, status, eval_status, + n, x, f, g, u, v, index_nz_v, + nnz_v, index_nz_u, nnz_u) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # evaluate f + eval_status = fun(n, x, f, userdata) + elseif status[] == 3 # evaluate g + eval_status = grad(n, x, g, userdata) + elseif status[] == 5 # evaluate Hv product + eval_status = hessprod(n, x, u, v, false, userdata) + elseif status[] == 6 # evaluate the product with P + eval_status = prec(n, x, u, v, userdata) + elseif status[] == 7 # evaluate sparse Hess-vect product + eval_status = shessprod(n, x, nnz_v, index_nz_v, v, + nnz_u, index_nz_u, u, + false, userdata) + elseif status[] == 23 # evaluate f and g + eval_status = fun(n, x, f, userdata) + eval_status = grad(n, x, g, userdata) + elseif status[] == 25 # evaluate f and Hv product + eval_status = fun(n, x, f, userdata) + eval_status = hessprod(n, x, u, v, false, userdata) + elseif status[] == 35 # evaluate g and Hv product + eval_status = grad(n, x, g, userdata) + eval_status = hessprod(n, x, u, v, false, userdata) + elseif status[] == 235 # evaluate f, g and Hv product + eval_status = fun(n, x, f, userdata) + eval_status = grad(n, x, g, userdata) + eval_status = hessprod(n, x, u, v, false, userdata) + else + @printf(" the value %1i of status should not occur\n", + status) + end + end + end + + # Record solution information + bgo_information(data, inform, status) + + if inform[].status == 0 + @printf("%c:%6i evaluations. Optimal objective value = %5.2f status = %1i\n", st, + inform[].f_eval, inform[].obj, inform[].status) + else + @printf("%c: BGO_solve exit status = %1i\n", st, inform[].status) + end + + # @printf("x: ") + # for i in 1:n + # @printf("%f ", x[i]) + # end + # @printf("\n") + # @printf("gradient: ") + # for i in 1:n + # @printf("%f ", g[i]) + # end + # @printf("\n") + + # Delete internal workspace + bgo_terminate(data, control, inform) + end + return 0 end @testset "BGO" begin diff --git a/GALAHAD.jl/test/test_bqp.jl b/GALAHAD.jl/test/test_bqp.jl index e69de29bb2..503dd0dc66 100644 --- a/GALAHAD.jl/test/test_bqp.jl +++ b/GALAHAD.jl/test/test_bqp.jl @@ -0,0 +1,295 @@ +# test_bqp.jl +# Simple code to test the Julia interface to BQP + +using GALAHAD +using Test +using Printf +using Accessors + +function test_bqp() + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{bqp_control_type{Float64}}() + inform = Ref{bqp_inform_type{Float64}}() + + # Set problem data + n = 10 # dimension + H_ne = 2 * n - 1 # Hesssian elements, NB lower triangle + H_dense_ne = div(n * (n + 1), 2) # dense Hessian elements + H_row = zeros(Cint, H_ne) # row indices, + H_col = zeros(Cint, H_ne) # column indices + H_ptr = zeros(Cint, n + 1) # row pointers + H_val = zeros(Float64, H_ne) # values + H_dense = zeros(Float64, H_dense_ne) # dense values + H_diag = zeros(Float64, n) # diagonal values + g = zeros(Float64, n) # linear term in the objective + f = 1.0 # constant term in the objective + x_l = zeros(Float64, n) # variable lower bound + x_u = zeros(Float64, n) # variable upper bound + x = zeros(Float64, n) # variables + z = zeros(Float64, n) # dual variables + + # Set output storage + x_stat = zeros(Cint, n) # variable status + st = ' ' + status = Ref{Cint}() + + g[1] = 2.0 + for i in 2:n + g[i] = 0.0 + end + x_l[1] = -1.0 + for i in 2:n + x_l[i] = -Inf + end + x_u[1] = 1.0 + x_u[2] = Inf + for i in 3:n + x_u[i] = 2.0 + end + + # H = tridiag(2,1), H_dense = diag(2) + l = 1 + H_ptr[1] = l + H_row[l] = 1 + H_col[l] = 1 + H_val[l] = 2.0 + for i in 2:n + l = l + 1 + H_ptr[i] = l + H_row[l] = i + H_col[l] = i - 1 + H_val[l] = 1.0 + l = l + 1 + H_row[l] = i + H_col[l] = i + H_val[l] = 2.0 + end + H_ptr[n + 1] = l + 1 + + l = 0 + for i in 1:n + H_diag[i] = 2.0 + for j in 1:i + l = l + 1 + if j < i - 1 + H_dense[l] = 0.0 + elseif j == i - 1 + H_dense[l] = 1.0 + else + H_dense[l] = 2.0 + end + end + end + + @printf(" fortran sparse matrix indexing\n\n") + @printf(" basic tests of bqp storage formats\n\n") + + for d in 1:4 + + # Initialize BQP + bqp_initialize(data, control, status) + + # Set user-defined control options + @reset control[].f_indexing = true # fortran sparse matrix indexing + + # Start from 0 + for i in 1:n + x[i] = 0.0 + z[i] = 0.0 + end + + # sparse co-ordinate storage + if d == 1 + st = 'C' + bqp_import(control, data, status, n, + "coordinate", H_ne, H_row, H_col, Cint[]) + + bqp_solve_given_h(data, status, n, H_ne, H_val, g, f, + x_l, x_u, x, z, x_stat) + end + + # sparse by rows + if d == 2 + st = 'R' + bqp_import(control, data, status, n, + "sparse_by_rows", H_ne, Cint[], H_col, H_ptr) + + bqp_solve_given_h(data, status, n, H_ne, H_val, g, f, + x_l, x_u, x, z, x_stat) + end + + # dense + if d == 3 + st = 'D' + bqp_import(control, data, status, n, + "dense", H_dense_ne, Cint[], Cint[], Cint[]) + + bqp_solve_given_h(data, status, n, H_dense_ne, H_dense, + g, f, x_l, x_u, x, z, x_stat) + end + + # diagonal + if d == 4 + st = 'L' + bqp_import(control, data, status, n, + "diagonal", H_ne, Cint[], Cint[], Cint[]) + + bqp_solve_given_h(data, status, n, n, H_diag, g, f, + x_l, x_u, x, z, x_stat) + end + + bqp_information(data, inform, status) + + if inform[].status == 0 + @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", st, + inform[].iter, inform[].obj, inform[].status) + else + @printf("%c: BQP_solve exit status = %1i\n", st, inform[].status) + end + + # @printf("x: ") + # for i = 1:n + # @printf("%f ", x[i]) + # end + # @printf("\n") + # @printf("gradient: ") + # for i = 1:n + # @printf("%f ", g[i]) + # end + # @printf("\n") + + # Delete internal workspace + bqp_terminate(data, control, inform) + end + + @printf("\n tests reverse-communication options\n\n") + + # reverse-communication input/output + nz_v_start = Ref{Cint}() + nz_v_end = Ref{Cint}() + nz_prod_end = Ref{Cint}() + nz_v = zeros(Cint, n) + nz_prod = zeros(Cint, n) + mask = zeros(Cint, n) + v = zeros(Float64, n) + prod = zeros(Float64, n) + + nz_prod_end = 0 + + # Initialize BQP + bqp_initialize(data, control, status) + # @reset control[].print_level = 1 + + # Set user-defined control options + @reset control[].f_indexing = true # fortran sparse matrix indexing + + # Start from 0 + for i in 1:n + x[i] = 0.0 + z[i] = 0.0 + end + + st = 'I' + for i in 1:n + mask[i] = 0 + end + bqp_import_without_h(control, data, status, n) + + terminated = false + while !terminated # reverse-communication loop + bqp_solve_reverse_h_prod(data, status, n, g, f, x_l, x_u, x, z, x_stat, v, prod, nz_v, + nz_v_start, nz_v_end, nz_prod, nz_prod_end) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # evaluate Hv + prod[1] = 2.0 * v[1] + v[2] + for i in 2:(n - 1) + prod[i] = 2.0 * v[i] + v[i - 1] + v[i + 1] + end + prod[n] = 2.0 * v[n] + v[n - 1] + elseif status[] == 3 # evaluate Hv for sparse v + for i in 1:n + prod[i] = 0.0 + end + for l in nz_v_start[]+1:nz_v_end[] + i = nz_v[l] - 1 + if i > 1 + prod[i - 1] = prod[i - 1] + v[i] + end + prod[i] = prod[i] + 2.0 * v[i] + if i < n + prod[i + 1] = prod[i + 1] + v[i] + end + end + elseif status[] == 4 # evaluate sarse Hv for sparse v + nz_prod_end = 1 + for l in nz_v_start[]:nz_v_end[] + i = nz_v[l] - 1 + if i > 1 + if mask[i - 1] == 0 + mask[i - 1] = 1 + nz_prod[nz_prod_end] = i - 1 + nz_prod_end = nz_prod_end + 1 + prod[i - 1] = v[i] + else + prod[i - 1] = prod[i - 1] + v[i] + end + end + if mask[i] == 0 + mask[i] = 1 + nz_prod[nz_prod_end] = i + nz_prod_end = nz_prod_end + 1 + prod[i] = 2.0 * v[i] + else + prod[i] = prod[i] + 2.0 * v[i] + end + if i < n + if mask[i + 1] == 0 + mask[i + 1] = 1 + nz_prod[nz_prod_end] = i + 1 + nz_prod_end = nz_prod_end + 1 + end + prod[i + 1] = prod[i + 1] + v[i] + end + for l in 1:nz_prod_end + mask[nz_prod[l]] = 0 + end + end + else + @printf(" the value %1i of status should not occur\n", status[]) + end + end + + # Record solution information + bqp_information(data, inform, status) + + # Print solution details + if inform[].status == 0 + @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", st, + inform[].iter, inform[].obj, inform[].status) + else + @printf("%c: BQP_solve exit status = %1i\n", st, inform[].status) + end + + # @printf("x: ") + # for i = 1:n + # @printf("%f ", x[i]) + # end + # @printf("\n") + # @printf("gradient: ") + # for i = 1:n + # @printf("%f ", g[i]) + # end + # @printf("\n") + + # Delete internal workspace + bqp_terminate(data, control, inform) + return 0 +end + +@testset "BQP" begin + @test test_bqp() == 0 +end diff --git a/GALAHAD.jl/test/test_bqpb.jl b/GALAHAD.jl/test/test_bqpb.jl index 83280ac803..0bb0334bc7 100644 --- a/GALAHAD.jl/test/test_bqpb.jl +++ b/GALAHAD.jl/test/test_bqpb.jl @@ -49,7 +49,7 @@ function test_bqpb() if d == 1 st = 'C' bqpb_import(control, data, status, n, - "coordinate", H_ne, H_row, H_col, Cint[]) + "coordinate", H_ne, H_row, H_col, C_NULL) bqpb_solve_qp(data, status, n, H_ne, H_val, g, f, x_l, x_u, x, z, x_stat) @@ -59,7 +59,7 @@ function test_bqpb() if d == 2 st = 'R' bqpb_import(control, data, status, n, - "sparse_by_rows", H_ne, Cint[], H_col, H_ptr) + "sparse_by_rows", H_ne, C_NULL, H_col, H_ptr) bqpb_solve_qp(data, status, n, H_ne, H_val, g, f, x_l, x_u, x, z, x_stat) @@ -71,7 +71,7 @@ function test_bqpb() H_dense_ne = 6 # number of elements of H H_dense = Float64[1.0, 0.0, 1.0, 0.0, 0.0, 1.0] bqpb_import(control, data, status, n, - "dense", H_ne, Cint[], Cint[], Cint[]) + "dense", H_ne, C_NULL, C_NULL, C_NULL) bqpb_solve_qp(data, status, n, H_dense_ne, H_dense, g, f, x_l, x_u, x, z, x_stat) @@ -81,7 +81,7 @@ function test_bqpb() if d == 4 st = 'L' bqpb_import(control, data, status, n, - "diagonal", H_ne, Cint[], Cint[], Cint[]) + "diagonal", H_ne, C_NULL, C_NULL, C_NULL) bqpb_solve_qp(data, status, n, H_ne, H_val, g, f, x_l, x_u, x, z, x_stat) @@ -91,7 +91,7 @@ function test_bqpb() if d == 5 st = 'S' bqpb_import(control, data, status, n, - "scaled_identity", H_ne, Cint[], Cint[], Cint[]) + "scaled_identity", H_ne, C_NULL, C_NULL, C_NULL) bqpb_solve_qp(data, status, n, H_ne, H_val, g, f, x_l, x_u, x, z, x_stat) @@ -101,7 +101,7 @@ function test_bqpb() if d == 6 st = 'I' bqpb_import(control, data, status, n, - "identity", H_ne, Cint[], Cint[], Cint[]) + "identity", H_ne, C_NULL, C_NULL, C_NULL) bqpb_solve_qp(data, status, n, H_ne, H_val, g, f, x_l, x_u, x, z, x_stat) @@ -111,7 +111,7 @@ function test_bqpb() if d == 7 st = 'Z' bqpb_import(control, data, status, n, - "zero", H_ne, Cint[], Cint[], Cint[]) + "zero", H_ne, C_NULL, C_NULL, C_NULL) bqpb_solve_qp(data, status, n, H_ne, H_val, g, f, x_l, x_u, x, z, x_stat) @@ -163,7 +163,7 @@ function test_bqpb() if d == 1 st = 'W' bqpb_import(control, data, status, n, - "shifted_least_distance", H_ne, Cint[], Cint[], Cint[]) + "shifted_least_distance", H_ne, C_NULL, C_NULL, C_NULL) bqpb_solve_sldqp(data, status, n, w, x_0, g, f, x_l, x_u, x, z, x_stat) diff --git a/GALAHAD.jl/test/test_nls.jl b/GALAHAD.jl/test/test_nls.jl index 2e6e7e2796..d07bced435 100644 --- a/GALAHAD.jl/test/test_nls.jl +++ b/GALAHAD.jl/test/test_nls.jl @@ -14,8 +14,8 @@ end function test_nls() # compute the residuals function res(n, m, x::Vector{Float64}, c::Vector{Float64}, userdata::userdata_type) - c[1] = pow(x[1], 2.0) + userdata.p - c[2] = x[1] + x[2]^(2.0) + c[1] = x[1]^2 + userdata.p + c[2] = x[1] + x[2]^2 c[3] = x[1] - x[2] return 0 end diff --git a/GALAHAD.jl/test/test_rpd.jl b/GALAHAD.jl/test/test_rpd.jl index e69de29bb2..57de6289a5 100644 --- a/GALAHAD.jl/test/test_rpd.jl +++ b/GALAHAD.jl/test/test_rpd.jl @@ -0,0 +1,129 @@ +# test_rpd.jl +# Simple code to test the Julia interface to RPD + +using GALAHAD +using Test +using Printf +using Accessors + +function test_rpd() + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{rpd_control_type}() + inform = Ref{rpd_inform_type}() + + # extend the qplib_file string to include the actual position of the + # provided ALLINIT.qplib example file provided as part GALAHAD + qplib_file = joinpath(ENV["GALAHAD"], "examples", "ALLINIT.qplib") + qplib_file_len = length(qplib_file) + + status = Ref{Cint}() + n = Ref{Cint}() + m = Ref{Cint}() + h_ne = Ref{Cint}() + a_ne = Ref{Cint}() + h_c_ne = Ref{Cint}() + p_type = Vector{Cchar}(undef, 4) + + @printf(" Fortran sparse matrix indexing\n\n") + @printf(" basic tests of storage formats\n\n") + + # Initialize RPD */ + rpd_initialize(data, control, status) + + # Set user-defined control options */ + @reset control[].f_indexing = true # fortran sparse matrix indexing + + # Recover vital statistics from the QPLIB file + rpd_get_stats(qplib_file, qplib_file_len, control, data, status, p_type, n, m, h_ne, a_ne, + h_c_ne) + @printf(" QPLIB file is of type %s\n", mapreduce(x -> Char(x), *, p_type)) + @printf(" n = %i, m = %i, h_ne = %i, a_ne = %i, h_c_ne = %i\n", n[], m[], h_ne[], a_ne[], + h_c_ne[]) + + # Recover g + g = zeros(Float64, n[]) + rpd_get_g(data, status, n[], g) + @printf(" g = %.1f %.1f %.1f %.1f %.1f\n", g[1], g[2], g[3], g[4], g[5]) + + # Recover f + f = Ref{Float64}() + rpd_get_f(data, status, f) + @printf(" f = %.1f\n", f[]) + + # Recover xlu + x_l = zeros(Float64, n[]) + x_u = zeros(Float64, n[]) + rpd_get_xlu(data, status, n[], x_l, x_u) + @printf(" x_l = %.1f %.1f %.1f %.1f %.1f\n", x_l[1], x_l[2], x_l[3], x_l[4], x_l[5]) + @printf(" x_u = %.1f %.1f %.1f %.1f %.1f\n", x_u[1], x_u[2], x_u[3], x_u[4], x_u[5]) + + # Recover clu + c_l = zeros(Float64, m[]) + c_u = zeros(Float64, m[]) + rpd_get_clu(data, status, m[], c_l, c_u) + @printf(" c_l = %.1f %.1f\n", c_l[1], c_l[2]) + @printf(" c_u = %.1f %.1f\n", c_u[1], c_u[2]) + + # Recover H + h_row = zeros(Cint, h_ne[]) + h_col = zeros(Cint, h_ne[]) + h_val = zeros(Float64, h_ne[]) + rpd_get_h(data, status, h_ne[], h_row, h_col, h_val) + @printf(" h_row, h_col, h_val =\n") + for i in 1:h_ne[] + @printf(" %i %i %.1f\n", h_row[i], h_col[i], h_val[i]) + end + + # Recover A + a_row = zeros(Cint, a_ne[]) + a_col = zeros(Cint, a_ne[]) + a_val = zeros(Float64, a_ne[]) + rpd_get_a(data, status, a_ne[], a_row, a_col, a_val) + @printf(" a_row, a_col, a_val =\n") + for i in 1:a_ne[] + @printf(" %i %i %.1f\n", a_row[i], a_col[i], a_val[i]) + end + + # Recover H_c + h_c_ptr = zeros(Cint, h_c_ne[]) + h_c_row = zeros(Cint, h_c_ne[]) + h_c_col = zeros(Cint, h_c_ne[]) + h_c_val = zeros(Float64, h_c_ne[]) + rpd_get_h_c(data, status, h_c_ne[], h_c_ptr, h_c_row, h_c_col, h_c_val) + @printf(" h_c_row, h_c_col, h_c_val =\n") + for i in 1:h_c_ne[] + @printf(" %i %i %i %.1f\n", h_c_ptr[i], h_c_row[i], h_c_col[i], h_c_val[i]) + end + + # Recover x_type + x_type = zeros(Cint, n[]) + rpd_get_x_type(data, status, n[], x_type) + @printf(" x_type = %i %i %i %i %i\n", x_type[1], x_type[2], x_type[3], x_type[4], + x_type[5]) + + # Recover x + x = zeros(Float64, n[]) + rpd_get_x(data, status, n[], x) + @printf(" x = %.1f %.1f %.1f %.1f %.1f\n", x[1], x[2], x[3], x[4], x[5]) + + # Recover y + y = zeros(Float64, m[]) + rpd_get_y(data, status, m[], y) + @printf(" y = %.1f %.1f\n", y[1], y[2]) + + # Recover z + z = zeros(Float64, n[]) + rpd_get_z(data, status, n[], z) + @printf(" z = %.1f %.1f %.1f %.1f %.1f\n", z[1], z[2], z[3], z[4], z[5]) + + # Delete internal workspace + rpd_terminate(data, control, inform) + return 0 +end + +@testset "RPD" begin + if haskey(ENV, "GALAHAD") + @test test_rpd() == 0 + end +end diff --git a/GALAHAD.jl/test/test_slls.jl b/GALAHAD.jl/test/test_slls.jl index 647cc20c3e..7c80d72de2 100644 --- a/GALAHAD.jl/test/test_slls.jl +++ b/GALAHAD.jl/test/test_slls.jl @@ -7,19 +7,21 @@ using Printf using Accessors # Custom userdata struct -struct userdata_type +mutable struct userdata_type scale::Float64 end -function test_slls() - # Apply preconditioner - function prec(n, var::Vector{Float64}, p::Vector{Float64}, userdata::userdata_type) - scale = userdata.scale - for i in 1:n - p[i] = scale * v[i] - end - return 0 +# Apply preconditioner +function prec(n::Int, var::Vector{Float64}, p::Vector{Float64}, userdata::userdata_type) + scale = userdata.scale + for i in 1:n + p[i] = scale * v[i] end + return 0 +end + +function test_slls() + pointer_prec = @cfunction(prec, Int, (Int, Vector{Float64}, Vector{Float64}, userdata_type)) # Derived types data = Ref{Ptr{Cvoid}}() @@ -28,6 +30,7 @@ function test_slls() # Set user data userdata = userdata_type(1.0) + pointer_userdata = pointer_from_objref(userdata) # Set problem data n = 10 # dimension @@ -142,21 +145,21 @@ function test_slls() if d == 1 st = "CO" slls_import(control, data, status, n, o, - "coordinate", Ao_ne, Ao_row, Ao_col, 0, Cint[]) + "coordinate", Ao_ne, Ao_row, Ao_col, 0, C_NULL) - slls_solve_given_a(data, userdata, status, n, o, Ao_ne, Ao_val, b, x, z, r, g, x_stat, - prec) + slls_solve_given_a(data, pointer_userdata, status, n, o, Ao_ne, Ao_val, b, x, z, r, g, + x_stat, pointer_prec) end # sparse by rows if d == 2 st = "SR" slls_import(control, data, status, n, o, - "sparse_by_rows", Ao_ne, Cint[], Ao_col, + "sparse_by_rows", Ao_ne, C_NULL, Ao_col, Ao_ptr_ne, Ao_ptr) - slls_solve_given_a(data, userdata, status, n, o, Ao_ne, Ao_val, b, x, z, r, g, x_stat, - prec) + slls_solve_given_a(data, pointer_userdata, status, n, o, Ao_ne, Ao_val, b, x, z, r, g, + x_stat, pointer_prec) end # dense by rows @@ -164,11 +167,11 @@ function test_slls() st = "DR" slls_import(control, data, status, n, o, "dense_by_rows", Ao_dense_ne, - Cint[], Cint[], 0, Cint[]) + C_NULL, C_NULL, 0, C_NULL) - slls_solve_given_a(data, userdata, status, n, o, + slls_solve_given_a(data, pointer_userdata, status, n, o, Ao_dense_ne, Ao_dense, b, - x, z, r, g, x_stat, prec) + x, z, r, g, x_stat, pointer_prec) end # sparse by columns @@ -176,11 +179,11 @@ function test_slls() st = "SC" slls_import(control, data, status, n, o, "sparse_by_columns", Ao_ne, Ao_by_col_row, - Cint[], Ao_by_col_ptr_ne, Ao_by_col_ptr) + C_NULL, Ao_by_col_ptr_ne, Ao_by_col_ptr) - slls_solve_given_a(data, userdata, status, n, o, + slls_solve_given_a(data, pointer_userdata, status, n, o, Ao_ne, Ao_by_col_val, b, - x, z, r, g, x_stat, prec) + x, z, r, g, x_stat, pointer_prec) end # dense by columns @@ -188,10 +191,10 @@ function test_slls() st = "DC" slls_import(control, data, status, n, o, "dense_by_columns", Ao_dense_ne, - Cint[], Cint[], 0, Cint[]) + C_NULL, C_NULL, 0, C_NULL) - slls_solve_given_a(data, userdata, status, n, o, Ao_dense_ne, Ao_by_col_dense, b, - x, z, r, g, x_stat, prec) + slls_solve_given_a(data, pointer_userdata, status, n, o, Ao_dense_ne, Ao_by_col_dense, b, + x, z, r, g, x_stat, pointer_prec) end slls_information(data, inform, status) @@ -225,11 +228,11 @@ function test_slls() nz_v_start = Ref{Cint}() nz_v_end = Ref{Cint}() nz_p_end = Ref{Cint}() - nz_v = Vector(Cint, on) - nz_p = Vector(Cint, o) - mask = Vector(Cint, o) - v = Vector(Float64, on) - p = Vector(Float64, on) + nz_v = zeros(Cint, on) + nz_p = zeros(Cint, o) + mask = zeros(Cint, o) + v = zeros(Float64, on) + p = zeros(Float64, on) nz_p_end = 0 @@ -277,15 +280,15 @@ function test_slls() for i in 1:n p[i] = 0.0 end - for l in nz_v_start:nz_v_end - i = nz_v[l] - 1 + for l in nz_v_start[]:nz_v_end[] + i = nz_v[l] p[i] = v[i] p[n + 1] = p[n + 1] + v[i] end elseif status[] == 5 # evaluate p = sparse Av for sparse v nz_p_end = 1 - for l in nz_v_start:nz_v_end - i = nz_v[l] - 1 + for l in nz_v_start[]:nz_v_end[] + i = nz_v[l] if mask[i] == 0 mask[i] = 1 nz_p[nz_p_end] = i + 1 diff --git a/GALAHAD.jl/test/test_trb.jl b/GALAHAD.jl/test/test_trb.jl index c78a988f86..69537dc725 100644 --- a/GALAHAD.jl/test/test_trb.jl +++ b/GALAHAD.jl/test/test_trb.jl @@ -1,41 +1,3 @@ -/* trbtf.c */ -/* Full test for the TRB C interface using Fortran sparse matrix indexing */ - -#include -#include -#include "galahad_precision.h" -#include "galahad_cfunctions.h" -#include "galahad_trb.h" - -# Custom userdata struct -struct userdata_type { - real_wp_ p -] - -# Function prototypes -int fun(int n, var::Vector{Float64}, real_wp_ *f, const void *) -int grad(int n, var::Vector{Float64}, g::Vector{Float64}, const void *) -int hess(int n, int ne, var::Vector{Float64}, hval::Vector{Float64}, const void *) -int hess_dense(int n, int ne, var::Vector{Float64}, hval::Vector{Float64}, - const void *) -int hessprod(int n, var::Vector{Float64}, u::Vector{Float64}, var::Vector{Float64}, - bool got_h, const void *) -int shessprod(int n, var::Vector{Float64}, int nnz_v, const int index_nz_v[], -var::Vector{Float64}, int *nnz_u, int index_nz_u[], -u::Vector{Float64}, bool got_h, const void *) -int prec(int n, var::Vector{Float64}, u::Vector{Float64}, var::Vector{Float64}, - const void *) -int fun_diag(int n, var::Vector{Float64}, real_wp_ *f, const void *) -int grad_diag(int n, var::Vector{Float64}, g::Vector{Float64}, const void *) -int hess_diag(int n, int ne, var::Vector{Float64}, hval::Vector{Float64}, -const void *) -int hessprod_diag(int n, var::Vector{Float64}, u::Vector{Float64}, -var::Vector{Float64}, bool got_h, const void *) -int shessprod_diag(int n, var::Vector{Float64}, int nnz_v, -const int index_nz_v[], -var::Vector{Float64}, int *nnz_u, int index_nz_u[], -u::Vector{Float64}, bool got_h, const void *) - # test_trb.jl # Simple code to test the Julia interface to TRB @@ -44,465 +6,491 @@ using Test using Printf using Accessors -function test_trb() -# Derived types -data = Ref{Ptr{Cvoid}}() -control = Ref{trb_control_type{Float64}}() -inform = Ref{trb_inform_type{Float64}}() - -# Set user data -struct userdata_type userdata -userdata.p = 4.0 - -# Set problem data -n = 3 # dimension -ne = 5 # Hesssian elements -x_l = Float64[-10,-10,-10] -x_u = Float64[0.5,0.5,0.5] -H_row = Cint[1, 2, 3, 3, 3] # Hessian H -H_col = Cint[1, 2, 1, 2, 3] # NB lower triangle -H_ptr = Cint[1, 2, 3, 6] # row pointers - -# Set storage -g = zeros(Float64, n) # gradient -st = ' ' = ' ' -status = Ref{Cint}() - -@printf(" Fortran sparse matrix indexing\n\n") - -@printf(" tests options for all-in-one storage format\n\n") - -for d = 1:5 - -# Initialize TRB -trb_initialize(data, control, status) - -# Set user-defined control options -control[].f_indexing = true # Fortran sparse matrix indexing -#control[].print_level = 1 - -# Start from 1.5 -x = Float64[1.5,1.5,1.5] - -# sparse co-ordinate storage -if d == 1 -st = 'C' -trb_import(control, data, status, n, x_l, x_u, -"coordinate", ne, H_row, H_col, Cint[]) -trb_solve_with_mat(data, userdata, status, n, x, g, ne, -fun, grad, hess, prec) -end -# sparse by rows -if d == 2 -st = 'R' -trb_import(control, data, status, n, x_l, x_u, -"sparse_by_rows", ne, Cint[], H_col, H_ptr) -trb_solve_with_mat(data, userdata, status, n, x, g, ne, -fun, grad, hess, prec) -end -# dense -if d == 3 -st = 'D' -trb_import(control, data, status, n, x_l, x_u, -"dense", ne, Cint[], Cint[], Cint[]) -trb_solve_with_mat(data, userdata, status, n, x, g, ne, -fun, grad, hess_dense, prec) -end -# diagonal -if d == 4 -st = 'I' -trb_import(control, data, status, n, x_l, x_u, -"diagonal", ne, Cint[], Cint[], Cint[]) -trb_solve_with_mat (data, userdata, status, n, x, g, ne, -fun_diag, grad_diag, hess_diag, prec) -end -case 5: # access by products -st = 'P' -trb_import(control, data, status, n, x_l, x_u, -"absent", ne, Cint[], Cint[], Cint[]) -trb_solve_without_mat(data, userdata, status, n, x, g, - fun, grad, hessprod, shessprod, prec) -end -] -# Record solution information -trb_information(data, inform, status) - -# Print solution details -if inform[].status == 0 -@printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", - st, inform[].iter, inform[].obj, inform[].status) -else -@printf("%c: TRB_solve exit status = %1i\n", st, inform[].status) - -# @printf("x: ") -# for i = 1:n -# @printf("%f ", x[i]) -# @printf("\n") -# @printf("gradient: ") -# for i = 1:n -# @printf("%f ", g[i]) -# @printf("\n") - -# Delete internal workspace -trb_terminate(data, control, inform) -@printf("\n tests reverse-communication options\n\n") - -# reverse-communication input/output -int eval_status, nnz_v -int nnz_u -f = 0.0 -u = zeros(Float64, n), v[n] -index_nz_u = zeros(Cint, n), index_nz_v[n] -real_wp_ H_val[ne], H_dense[n*(n+1)/2], H_diag[n] -for d = 1:5 - -# Initialize TRB -trb_initialize(data, control, status) - -# Set user-defined control options -control[].f_indexing = true # Fortran sparse matrix indexing -#control[].print_level = 1 - -# Start from 1.5 -x = Float64[1.5,1.5,1.5] - -# sparse co-ordinate storage -if d == 1 -st = 'C' -trb_import(control, data, status, n, x_l, x_u, -"coordinate", ne, H_row, H_col, Cint[]) -while true # reverse-communication loop -trb_solve_reverse_with_mat(data, status, eval_status, -n, x, f, g, ne, H_val, u, v) -if status == 0 # successful termination -end -elseif status < 0) # error exit -end -elseif status == 2) # evaluate f -eval_status = fun(n, x, f, userdata) -elseif status == 3) # evaluate g -eval_status = grad(n, x, g, userdata) -elseif status == 4) # evaluate H -eval_status = hess(n, ne, x, H_val, userdata) -elseif status == 6) # evaluate the product with P -eval_status = prec(n, x, u, v, userdata) -else -@printf(" the value %1i of status should not occur\n", status) -end -] -] -end -# sparse by rows -if d == 2 -st = 'R' -trb_import(control, data, status, n, x_l, x_u, -"sparse_by_rows", ne, Cint[], H_col, H_ptr) -while true # reverse-communication loop -trb_solve_reverse_with_mat(data, status, eval_status, -n, x, f, g, ne, H_val, u, v) -if status == 0 # successful termination -end -elseif status < 0) # error exit -end -elseif status == 2) # evaluate f -eval_status = fun(n, x, f, userdata) -elseif status == 3) # evaluate g -eval_status = grad(n, x, g, userdata) -elseif status == 4) # evaluate H -eval_status = hess(n, ne, x, H_val, userdata) -elseif status == 6) # evaluate the product with P -eval_status = prec(n, x, u, v, userdata) -else -@printf(" the value %1i of status should not occur\n", status) -end -] -] -end -# dense -if d == 3 -st = 'D' -trb_import(control, data, status, n, x_l, x_u, -"dense", ne, Cint[], Cint[], Cint[]) -while true # reverse-communication loop -trb_solve_reverse_with_mat(data, status, eval_status, -n, x, f, g, n*(n+1)/2, H_dense, -u, v) -if status == 0 # successful termination -end -elseif status < 0) # error exit -end -elseif status == 2) # evaluate f -eval_status = fun(n, x, f, userdata) -elseif status == 3) # evaluate g -eval_status = grad(n, x, g, userdata) -elseif status == 4) # evaluate H -eval_status = hess_dense(n, n*(n+1)/2, x, H_dense, - userdata) -elseif status == 6) # evaluate the product with P -eval_status = prec(n, x, u, v, userdata) -else -@printf(" the value %1i of status should not occur\n", status) -end -] -] -end -# diagonal -if d == 4 -st = 'I' -trb_import(control, data, status, n, x_l, x_u, -"diagonal", ne, Cint[], Cint[], Cint[]) -while true # reverse-communication loop -trb_solve_reverse_with_mat(data, status, eval_status, -n, x, f, g, n, H_diag, u, v) -if status == 0 # successful termination -end -elseif status < 0) # error exit -end -elseif status == 2) # evaluate f -eval_status = fun_diag(n, x, f, userdata) -elseif status == 3) # evaluate g -eval_status = grad_diag(n, x, g, userdata) -elseif status == 4) # evaluate H -eval_status = hess_diag(n, n, x, H_diag, userdata) -elseif status == 6) # evaluate the product with P -eval_status = prec(n, x, u, v, userdata) -else -@printf(" the value %1i of status should not occur\n", status) -end -] -] -end -case 5: # access by products -st = 'P' -trb_import(control, data, status, n, x_l, x_u, -"absent", ne, Cint[], Cint[], Cint[]) -nnz_u = 0 -while true # reverse-communication loop -trb_solve_reverse_without_mat(data, status, eval_status, - n, x, f, g, u, v, index_nz_v, - nnz_v, index_nz_u, nnz_u) -if status == 0 # successful termination -end -elseif status < 0) # error exit -end -elseif status == 2) # evaluate f -eval_status = fun(n, x, f, userdata) -elseif status == 3) # evaluate g -eval_status = grad(n, x, g, userdata) -elseif status == 5) # evaluate H -eval_status = hessprod(n, x, u, v, false, userdata) -elseif status == 6) # evaluate the product with P -eval_status = prec(n, x, u, v, userdata) -elseif status == 7) # evaluate sparse Hessian-vect prod -eval_status = shessprod(n, x, nnz_v, index_nz_v, v, - nnz_u, index_nz_u, u, - false, userdata) -else -@printf(" the value %1i of status should not occur\n", status) -end -] -] -end -] - -# Record solution information -trb_information(data, inform, status) - -# Print solution details -if inform[].status == 0 -@printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", - st, inform[].iter, inform[].obj, inform[].status) -else -@printf("%c: TRB_solve exit status = %1i\n", st, inform[].status) - -# @printf("x: ") -# for i = 1:n -# @printf("%f ", x[i]) -# @printf("\n") -# @printf("gradient: ") -# for i = 1:n -# @printf("%f ", g[i]) -# @printf("\n") - -# Delete internal workspace -trb_terminate(data, control, inform) -] - -# Objective function -int fun(int n, var::Vector{Float64}, real_wp_ *f, const void *userdata) -struct userdata_type *myuserdata = (struct userdata_type *) userdata -real_wp_ p = myuserdata->p - -*f = pow(x[0] + x[2] + p, 2) + pow(x[1] + x[2], 2) + cos(x[0]) -return 0 -] - -# Gradient of the objective -int grad(int n, var::Vector{Float64}, g::Vector{Float64}, const void *userdata) -struct userdata_type *myuserdata = (struct userdata_type *) userdata -real_wp_ p = myuserdata->p - -g[0] = 2.0 * (x[0] + x[2] + p) - sin(x[0]) -g[1] = 2.0 * (x[1] + x[2]) -g[2] = 2.0 * (x[0] + x[2] + p) + 2.0 * (x[1] + x[2]) -return 0 -] - -# Hessian of the objective -int hess(int n, int ne, var::Vector{Float64}, hval::Vector{Float64}, - const void *userdata) -hval[0] = 2.0 - cos(x[0]) -hval[1] = 2.0 -hval[2] = 2.0 -hval[3] = 2.0 -hval[4] = 4.0 -return 0 -] - -# Dense Hessian -int hess_dense(int n, int ne, var::Vector{Float64}, hval::Vector{Float64}, -const void *userdata) -hval[0] = 2.0 - cos(x[0]) -hval[1] = 0.0 -hval[2] = 2.0 -hval[3] = 2.0 -hval[4] = 2.0 -hval[5] = 4.0 -return 0 -] - -# Hessian-vector product -int hessprod(int n, var::Vector{Float64}, u::Vector{Float64}, var::Vector{Float64}, - bool got_h, const void *userdata) -u[0] = u[0] + 2.0 * (v[0] + v[2]) - cos(x[0]) * v[0] -u[1] = u[1] + 2.0 * (v[1] + v[2]) -u[2] = u[2] + 2.0 * (v[0] + v[1] + 2.0 * v[2]) -return 0 -] - -# Sparse Hessian-vector product -int shessprod(int n, var::Vector{Float64}, int nnz_v, const int index_nz_v[], - var::Vector{Float64}, int *nnz_u, int index_nz_u[], u::Vector{Float64}, - bool got_h, const void *userdata) -real_wp_ p[] = {0., 0., 0.] -bool used[] = {false, false, false] -for(int i = 0 i < nnz_v i++) -int j = index_nz_v[i] -switch(j) -case 1: -p[0] = p[0] + 2.0 * v[0] - cos(x[0]) * v[0] -used[0] = true -p[2] = p[2] + 2.0 * v[0] -used[2] = true -end -case 2: -p[1] = p[1] + 2.0 * v[1] -used[1] = true -p[2] = p[2] + 2.0 * v[1] -used[2] = true -end -case 3: -p[0] = p[0] + 2.0 * v[2] -used[0] = true -p[1] = p[1] + 2.0 * v[2] -used[1] = true -p[2] = p[2] + 4.0 * v[2] -used[2] = true -end -] -] -*nnz_u = 0 -for(int j = 0 j < 3 j++) -if used[j]) -u[j] = p[j] -*nnz_u = *nnz_u + 1 -index_nz_u[*nnz_u-1] = j+1 -] -] -return 0 -] - -# Apply preconditioner -int prec(int n, var::Vector{Float64}, u::Vector{Float64}, var::Vector{Float64}, - const void *userdata) - u[0] = 0.5 * v[0] - u[1] = 0.5 * v[1] - u[2] = 0.25 * v[2] - return 0 -] - - # Objective function -int fun_diag(int n, var::Vector{Float64}, real_wp_ *f, const void *userdata) -struct userdata_type *myuserdata = (struct userdata_type *) userdata -real_wp_ p = myuserdata->p - -*f = pow(x[2] + p, 2) + pow(x[1], 2) + cos(x[0]) -return 0 -] - -# Gradient of the objective -int grad_diag(int n, var::Vector{Float64}, g::Vector{Float64}, const void *userdata) -struct userdata_type *myuserdata = (struct userdata_type *) userdata -real_wp_ p = myuserdata->p - -g[0] = -sin(x[0]) -g[1] = 2.0 * x[1] -g[2] = 2.0 * (x[2] + p) -return 0 -] - -# Hessian of the objective -int hess_diag(int n, int ne, var::Vector{Float64}, hval::Vector{Float64}, - const void *userdata) -hval[0] = -cos(x[0]) -hval[1] = 2.0 -hval[2] = 2.0 -return 0 -] - -# Hessian-vector product -int hessprod_diag(int n, var::Vector{Float64}, u::Vector{Float64}, var::Vector{Float64}, - bool got_h, const void *userdata) -u[0] = u[0] + - cos(x[0]) * v[0] -u[1] = u[1] + 2.0 * v[1] -u[2] = u[2] + 2.0 * v[2] -return 0 -] - -# Sparse Hessian-vector product -int shessprod_diag(int n, var::Vector{Float64}, int nnz_v, -const int index_nz_v[], -var::Vector{Float64}, int *nnz_u, int index_nz_u[], -u::Vector{Float64}, bool got_h, const void *userdata) -real_wp_ p[] = {0., 0., 0.] -bool used[] = {false, false, false] -for(int i = 0 i < nnz_v i++) -int j = index_nz_v[i] -switch(j) -case 0: -p[0] = p[0] - cos(x[0]) * v[0] -used[0] = true -end -case 1: -p[1] = p[1] + 2.0 * v[1] -used[1] = true -end -case 2: -p[2] = p[2] + 2.0 * v[2] -used[2] = true +# Custom userdata struct +struct userdata_type + p::Float64 end -] -] -*nnz_u = 0 -for(int j = 0 j < 3 j++) -if used[j]) -u[j] = p[j] -*nnz_u = *nnz_u + 1 -index_nz_u[*nnz_u-1] = j+1 -] -] -return 0 -] + +function test_trb() + # Objective function + function fun(n::Int, var::Vector{Float64}, f::Ref{Float64}, userdata::userdata_type) + p = userdata.p + f[] = (x[1] + x[3] + p)^2 + (x[2] + x[3])^2 + cos(x[1]) + return 0 + end + + # # Gradient of the objective + # int grad(n::Int, var::Vector{Float64}, g::Vector{Float64}, userdata::userdata_type) + # struct userdata_type *myuserdata = (struct userdata_type *) userdata + # real_wp_ p = myuserdata->p + + # g[0] = 2.0 * (x[0] + x[2] + p) - sin(x[0]) + # g[1] = 2.0 * (x[1] + x[2]) + # g[2] = 2.0 * (x[0] + x[2] + p) + 2.0 * (x[1] + x[2]) + # return 0 + # ] + + # # Hessian of the objective + # int hess(n::Int, n::Inte, var::Vector{Float64}, hval::Vector{Float64}, + # userdata::userdata_type) + # hval[0] = 2.0 - cos(x[0]) + # hval[1] = 2.0 + # hval[2] = 2.0 + # hval[3] = 2.0 + # hval[4] = 4.0 + # return 0 + # ] + + # # Dense Hessian + # int hess_dense(n::Int, n::Inte, var::Vector{Float64}, hval::Vector{Float64}, + # userdata::userdata_type) + # hval[0] = 2.0 - cos(x[0]) + # hval[1] = 0.0 + # hval[2] = 2.0 + # hval[3] = 2.0 + # hval[4] = 2.0 + # hval[5] = 4.0 + # return 0 + # ] + + # # Hessian-vector product + # int hessprod(n::Int, var::Vector{Float64}, u::Vector{Float64}, var::Vector{Float64}, + # bool got_h, userdata::userdata_type) + # u[0] = u[0] + 2.0 * (v[0] + v[2]) - cos(x[0]) * v[0] + # u[1] = u[1] + 2.0 * (v[1] + v[2]) + # u[2] = u[2] + 2.0 * (v[0] + v[1] + 2.0 * v[2]) + # return 0 + # ] + + # # Sparse Hessian-vector product + # int shessprod(n::Int, var::Vector{Float64}, n::Intnz_v, const int index_nz_v[], + # var::Vector{Float64}, int *nnz_u, int index_nz_u[], u::Vector{Float64}, + # bool got_h, userdata::userdata_type) + # real_wp_ p[] = {0., 0., 0.] + # bool used[] = {false, false, false] + # for(int i = 0 i < nnz_v i++) + # int j = index_nz_v[i] + # switch(j) + # case 1: + # p[0] = p[0] + 2.0 * v[0] - cos(x[0]) * v[0] + # used[0] = true + # p[2] = p[2] + 2.0 * v[0] + # used[2] = true + # end + # case 2: + # p[1] = p[1] + 2.0 * v[1] + # used[1] = true + # p[2] = p[2] + 2.0 * v[1] + # used[2] = true + # end + # case 3: + # p[0] = p[0] + 2.0 * v[2] + # used[0] = true + # p[1] = p[1] + 2.0 * v[2] + # used[1] = true + # p[2] = p[2] + 4.0 * v[2] + # used[2] = true + # end + # ] + # ] + # *nnz_u = 0 + # for(int j = 0 j < 3 j++) + # if used[j]) + # u[j] = p[j] + # *nnz_u = *nnz_u + 1 + # index_nz_u[*nnz_u-1] = j+1 + # ] + # ] + # return 0 + # ] + + # # Apply preconditioner + # int prec(n::Int, var::Vector{Float64}, u::Vector{Float64}, var::Vector{Float64}, + # userdata::userdata_type) + # u[0] = 0.5 * v[0] + # u[1] = 0.5 * v[1] + # u[2] = 0.25 * v[2] + # return 0 + # ] + + # # Objective function + # int fun_diag(n::Int, var::Vector{Float64}, real_wp_ *f, userdata::userdata_type) + # struct userdata_type *myuserdata = (struct userdata_type *) userdata + # real_wp_ p = myuserdata->p + + # *f = pow(x[2] + p, 2) + pow(x[1], 2) + cos(x[0]) + # return 0 + # ] + + # # Gradient of the objective + # int grad_diag(n::Int, var::Vector{Float64}, g::Vector{Float64}, userdata::userdata_type) + # struct userdata_type *myuserdata = (struct userdata_type *) userdata + # real_wp_ p = myuserdata->p + + # g[0] = -sin(x[0]) + # g[1] = 2.0 * x[1] + # g[2] = 2.0 * (x[2] + p) + # return 0 + # ] + + # # Hessian of the objective + # int hess_diag(n::Int, n::Inte, var::Vector{Float64}, hval::Vector{Float64}, + # userdata::userdata_type) + # hval[0] = -cos(x[0]) + # hval[1] = 2.0 + # hval[2] = 2.0 + # return 0 + # ] + + # # Hessian-vector product + # int hessprod_diag(n::Int, var::Vector{Float64}, u::Vector{Float64}, var::Vector{Float64}, + # bool got_h, userdata::userdata_type) + # u[0] = u[0] + - cos(x[0]) * v[0] + # u[1] = u[1] + 2.0 * v[1] + # u[2] = u[2] + 2.0 * v[2] + # return 0 + # ] + + # # Sparse Hessian-vector product + # int shessprod_diag(n::Int, var::Vector{Float64}, n::Intnz_v, + # const int index_nz_v[], + # var::Vector{Float64}, int *nnz_u, int index_nz_u[], + # u::Vector{Float64}, bool got_h, userdata::userdata_type) + # real_wp_ p[] = {0., 0., 0.] + # bool used[] = {false, false, false] + # for(int i = 0 i < nnz_v i++) + # int j = index_nz_v[i] + # switch(j) + # case 0: + # p[0] = p[0] - cos(x[0]) * v[0] + # used[0] = true + # end + # case 1: + # p[1] = p[1] + 2.0 * v[1] + # used[1] = true + # end + # case 2: + # p[2] = p[2] + 2.0 * v[2] + # used[2] = true + # end + # ] + # ] + # *nnz_u = 0 + # for(int j = 0 j < 3 j++) + # if used[j]) + # u[j] = p[j] + # *nnz_u = *nnz_u + 1 + # index_nz_u[*nnz_u-1] = j+1 + # ] + # ] + # return 0 + # ] + # end + + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{trb_control_type{Float64}}() + inform = Ref{trb_inform_type{Float64}}() + + # Set user data + userdata = userdata_type(4.0) + + # Set problem data + n = 3 # dimension + ne = 5 # Hesssian elements + x_l = Float64[-10, -10, -10] + x_u = Float64[0.5, 0.5, 0.5] + H_row = Cint[1, 2, 3, 3, 3] # Hessian H + H_col = Cint[1, 2, 1, 2, 3] # NB lower triangle + H_ptr = Cint[1, 2, 3, 6] # row pointers + + # Set storage + g = zeros(Float64, n) # gradient + st = ' ' + status = Ref{Cint}() + + @printf(" Fortran sparse matrix indexing\n\n") + @printf(" tests options for all-in-one storage format\n\n") + + for d in 1:5 + + # Initialize TRB + trb_initialize(data, control, status) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + # @reset control[].print_level = 1 + + # Start from 1.5 + x = Float64[1.5, 1.5, 1.5] + + # sparse co-ordinate storage + if d == 1 + st = 'C' + trb_import(control, data, status, n, x_l, x_u, + "coordinate", ne, H_row, H_col, Cint[]) + + trb_solve_with_mat(data, userdata, status, n, x, g, ne, + fun, grad, hess, prec) + end + + # sparse by rows + if d == 2 + st = 'R' + trb_import(control, data, status, n, x_l, x_u, + "sparse_by_rows", ne, Cint[], H_col, H_ptr) + + trb_solve_with_mat(data, userdata, status, n, x, g, ne, + fun, grad, hess, prec) + end + + # dense + if d == 3 + st = 'D' + trb_import(control, data, status, n, x_l, x_u, + "dense", ne, Cint[], Cint[], Cint[]) + + trb_solve_with_mat(data, userdata, status, n, x, g, ne, + fun, grad, hess_dense, prec) + end + + # diagonal + if d == 4 + st = 'I' + trb_import(control, data, status, n, x_l, x_u, + "diagonal", ne, Cint[], Cint[], Cint[]) + + trb_solve_with_mat(data, userdata, status, n, x, g, ne, + fun_diag, grad_diag, hess_diag, prec) + end + + # access by products + if d == 5 + st = 'P' + trb_import(control, data, status, n, x_l, x_u, + "absent", ne, Cint[], Cint[], Cint[]) + + trb_solve_without_mat(data, userdata, status, n, x, g, + fun, grad, hessprod, shessprod, prec) + end + + # Record solution information + trb_information(data, inform, status) + + # Print solution details + if inform[].status == 0 + @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", st, + inform[].iter, inform[].obj, inform[].status) + else + @printf("%c: TRB_solve exit status = %1i\n", st, inform[].status) + end + + # @printf("x: ") + # for i = 1:n + # @printf("%f ", x[i]) + # end + # @printf("\n") + # @printf("gradient: ") + # for i = 1:n + # @printf("%f ", g[i]) + # end + # @printf("\n") + + # Delete internal workspace + trb_terminate(data, control, inform) + end + + @printf("\n tests reverse-communication options\n\n") + + # reverse-communication input/output + eval_status = Ref{Cint}() + nnz_v = Ref{Cint}() + nnz_u = Ref{Cint}() + f = 0.0 + u = zeros(Float64, n) + v = zeros(Float64, n) + index_nz_u = zeros(Cint, n) + index_nz_v = zeros(Cint, n) + H_val = zeros(Float64, ne) + H_dense = zeros(Float64, div(n * (n + 1), 2)) + H_diag = zeros(Float64, n) + + for d in 1:5 + + # Initialize TRB + trb_initialize(data, control, status) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + # @reset control[].print_level = 1 + + # Start from 1.5 + x = Float64[1.5, 1.5, 1.5] + + # sparse co-ordinate storage + if d == 1 + st = 'C' + trb_import(control, data, status, n, x_l, x_u, "coordinate", ne, H_row, H_col, Cint[]) + + terminated = false + while !terminated # reverse-communication loop + trb_solve_reverse_with_mat(data, status, eval_status, n, x, f, g, ne, H_val, u, v) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # evaluate f + eval_status = fun(n, x, f, userdata) + elseif status[] == 3 # evaluate g + eval_status = grad(n, x, g, userdata) + elseif status[] == 4 # evaluate H + eval_status = hess(n, ne, x, H_val, userdata) + elseif status[] == 6 # evaluate the product with P + eval_status = prec(n, x, u, v, userdata) + else + @printf(" the value %1i of status should not occur\n", status) + end + end + end + + # sparse by rows + if d == 2 + st = 'R' + trb_import(control, data, status, n, x_l, x_u, "sparse_by_rows", ne, Cint[], H_col, + H_ptr) + + terminated = false + while !terminated # reverse-communication loop + trb_solve_reverse_with_mat(data, status, eval_status, n, x, f, g, ne, H_val, u, v) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # evaluate f + eval_status = fun(n, x, f, userdata) + elseif status[] == 3 # evaluate g + eval_status = grad(n, x, g, userdata) + elseif status[] == 4 # evaluate H + eval_status = hess(n, ne, x, H_val, userdata) + elseif status[] == 6 # evaluate the product with P + eval_status = prec(n, x, u, v, userdata) + else + @printf(" the value %1i of status should not occur\n", status) + end + end + end + + # dense + if d == 3 + st = 'D' + trb_import(control, data, status, n, x_l, x_u, + "dense", ne, Cint[], Cint[], Cint[]) + + terminated = false + while !terminated # reverse-communication loop + trb_solve_reverse_with_mat(data, status, eval_status, n, x, f, g, n * (n + 1) / 2, + H_dense, u, v) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # evaluate f + eval_status = fun(n, x, f, userdata) + elseif status[] == 3 # evaluate g + eval_status = grad(n, x, g, userdata) + elseif status[] == 4 # evaluate H + eval_status = hess_dense(n, div(n * (n + 1), 2), x, H_dense, userdata) + elseif status[] == 6 # evaluate the product with P + eval_status = prec(n, x, u, v, userdata) + else + @printf(" the value %1i of status should not occur\n", status) + end + end + end + + # diagonal + if d == 4 + st = 'I' + trb_import(control, data, status, n, x_l, x_u, "diagonal", ne, Cint[], Cint[], Cint[]) + + terminated = false + while !terminated # reverse-communication loop + trb_solve_reverse_with_mat(data, status, eval_status, n, x, f, g, n, H_diag, u, v) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # evaluate f + eval_status = fun_diag(n, x, f, userdata) + elseif status[] == 3 # evaluate g + eval_status = grad_diag(n, x, g, userdata) + elseif status[] == 4 # evaluate H + eval_status = hess_diag(n, n, x, H_diag, userdata) + elseif status[] == 6 # evaluate the product with P + eval_status = prec(n, x, u, v, userdata) + else + @printf(" the value %1i of status should not occur\n", status) + end + end + end + + # access by products + if d == 5 + st = 'P' + trb_import(control, data, status, n, x_l, x_u, "absent", ne, Cint[], Cint[], Cint[]) + nnz_u = 0 + + terminated = false + while !terminated # reverse-communication loop + trb_solve_reverse_without_mat(data, status, eval_status, n, x, f, g, u, v, + index_nz_v, nnz_v, index_nz_u, nnz_u) + if status[] == 0 # successful termination + terminated = true + elseif status[] < 0 # error exit + terminated = true + elseif status[] == 2 # evaluate f + eval_status = fun(n, x, f, userdata) + elseif status[] == 3 # evaluate g + eval_status = grad(n, x, g, userdata) + elseif status[] == 5 # evaluate H + eval_status = hessprod(n, x, u, v, false, userdata) + elseif status[] == 6 # evaluate the product with P + eval_status = prec(n, x, u, v, userdata) + elseif status[] == 7 # evaluate sparse Hessian-vect prod + eval_status = shessprod(n, x, nnz_v, index_nz_v, v, nnz_u, index_nz_u, u, false, + userdata) + else + @printf(" the value %1i of status should not occur\n", status) + end + end + end + + # Record solution information + trb_information(data, inform, status) + + # Print solution details + if inform[].status[] == 0 + @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", st, + inform[].iter, inform[].obj, inform[].status) + else + @printf("%c: TRB_solve exit status = %1i\n", st, inform[].status) + end + + # @printf("x: ") + # for i = 1:n + # @printf("%f ", x[i]) + # end + # @printf("\n") + # @printf("gradient: ") + # for i = 1:n + # @printf("%f ", g[i]) + # end + # @printf("\n") + + # Delete internal workspace + trb_terminate(data, control, inform) + end + return 0 end @testset "TRB" begin diff --git a/GALAHAD.jl/test/test_trs.jl b/GALAHAD.jl/test/test_trs.jl index 48a5780a55..7081f39a7f 100644 --- a/GALAHAD.jl/test/test_trs.jl +++ b/GALAHAD.jl/test/test_trs.jl @@ -72,35 +72,35 @@ function test_trs() st = 'C' # import the control parameters and structural data trs_import(control, data, status, n, - "coordinate", H_ne, H_row, H_col, Cint[]) + "coordinate", H_ne, H_row, H_col, C_NULL) if m_is == 1 trs_import_m(data, status, n, - "coordinate", M_ne, M_row, M_col, Cint[]) + "coordinate", M_ne, M_row, M_col, C_NULL) end if a_is == 1 trs_import_a(data, status, m, - "coordinate", A_ne, A_row, A_col, Cint[]) + "coordinate", A_ne, A_row, A_col, C_NULL) end # solve the problem if (a_is == 1) && (m_is == 1) trs_solve_problem(data, status, n, radius, f, c, H_ne, H_val, x, - M_ne, M_val, m, A_ne, A_val, Cint[]) + M_ne, M_val, m, A_ne, A_val, C_NULL) elseif a_is == 1 trs_solve_problem(data, status, n, radius, f, c, H_ne, H_val, x, - 0, Cint[], m, A_ne, A_val, Cint[]) + 0, C_NULL, m, A_ne, A_val, C_NULL) elseif m_is == 1 trs_solve_problem(data, status, n, radius, f, c, H_ne, H_val, x, - M_ne, M_val, 0, 0, Cint[], Cint[]) + M_ne, M_val, 0, 0, C_NULL, C_NULL) else trs_solve_problem(data, status, n, radius, f, c, H_ne, H_val, x, - 0, Cint[], 0, 0, Cint[], Cint[]) + 0, C_NULL, 0, 0, C_NULL, C_NULL) end end @@ -109,35 +109,35 @@ function test_trs() st = 'R' # import the control parameters and structural data trs_import(control, data, status, n, - "sparse_by_rows", H_ne, Cint[], H_col, H_ptr) + "sparse_by_rows", H_ne, C_NULL, H_col, H_ptr) if m_is == 1 trs_import_m(data, status, n, - "sparse_by_rows", M_ne, Cint[], M_col, M_ptr) + "sparse_by_rows", M_ne, C_NULL, M_col, M_ptr) end if a_is == 1 trs_import_a(data, status, m, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) end # solve the problem if (a_is == 1) && (m_is == 1) trs_solve_problem(data, status, n, radius, f, c, H_ne, H_val, x, - M_ne, M_val, m, A_ne, A_val, Cint[]) + M_ne, M_val, m, A_ne, A_val, C_NULL) elseif a_is == 1 trs_solve_problem(data, status, n, radius, f, c, H_ne, H_val, x, - 0, Cint[], m, A_ne, A_val, Cint[]) + 0, C_NULL, m, A_ne, A_val, C_NULL) elseif m_is == 1 trs_solve_problem(data, status, n, radius, f, c, H_ne, H_val, x, - M_ne, M_val, 0, 0, Cint[], Cint[]) + M_ne, M_val, 0, 0, C_NULL, C_NULL) else trs_solve_problem(data, status, n, radius, f, c, H_ne, H_val, x, - 0, Cint[], 0, 0, Cint[], Cint[]) + 0, C_NULL, 0, 0, C_NULL, C_NULL) end end @@ -146,16 +146,16 @@ function test_trs() st = 'D' # import the control parameters and structural data trs_import(control, data, status, n, - "dense", H_ne, Cint[], Cint[], Cint[]) + "dense", H_ne, C_NULL, C_NULL, C_NULL) if m_is == 1 trs_import_m(data, status, n, - "dense", M_ne, Cint[], Cint[], Cint[]) + "dense", M_ne, C_NULL, C_NULL, C_NULL) end if a_is == 1 trs_import_a(data, status, m, - "dense", A_ne, Cint[], Cint[], Cint[]) + "dense", A_ne, C_NULL, C_NULL, C_NULL) end # solve the problem @@ -163,19 +163,19 @@ function test_trs() trs_solve_problem(data, status, n, radius, f, c, H_dense_ne, H_dense, x, M_dense_ne, M_dense, m, A_ne, A_val, - Cint[]) + C_NULL) elseif a_is == 1 trs_solve_problem(data, status, n, radius, f, c, H_dense_ne, H_dense, x, - 0, Cint[], m, A_ne, A_val, Cint[]) + 0, C_NULL, m, A_ne, A_val, C_NULL) elseif m_is == 1 trs_solve_problem(data, status, n, radius, f, c, H_dense_ne, H_dense, x, - M_dense_ne, M_dense, 0, 0, Cint[], Cint[]) + M_dense_ne, M_dense, 0, 0, C_NULL, C_NULL) else trs_solve_problem(data, status, n, radius, f, c, H_dense_ne, H_dense, x, - 0, Cint[], 0, 0, Cint[], Cint[]) + 0, C_NULL, 0, 0, C_NULL, C_NULL) end end @@ -184,35 +184,35 @@ function test_trs() st = 'L' # import the control parameters and structural data trs_import(control, data, status, n, - "diagonal", H_ne, Cint[], Cint[], Cint[]) + "diagonal", H_ne, C_NULL, C_NULL, C_NULL) if m_is == 1 trs_import_m(data, status, n, - "diagonal", M_ne, Cint[], Cint[], Cint[]) + "diagonal", M_ne, C_NULL, C_NULL, C_NULL) end if a_is == 1 trs_import_a(data, status, m, - "dense", A_ne, Cint[], Cint[], Cint[]) + "dense", A_ne, C_NULL, C_NULL, C_NULL) end # solve the problem if (a_is == 1) && (m_is == 1) trs_solve_problem(data, status, n, radius, f, c, n, H_diag, x, - n, M_diag, m, A_ne, A_val, Cint[]) + n, M_diag, m, A_ne, A_val, C_NULL) elseif a_is == 1 trs_solve_problem(data, status, n, radius, f, c, n, H_diag, x, - 0, Cint[], m, A_ne, A_val, Cint[]) + 0, C_NULL, m, A_ne, A_val, C_NULL) elseif m_is == 1 trs_solve_problem(data, status, n, radius, f, c, n, H_diag, x, - n, M_diag, 0, 0, Cint[], Cint[]) + n, M_diag, 0, 0, C_NULL, C_NULL) else trs_solve_problem(data, status, n, radius, f, c, n, H_diag, x, - 0, Cint[], 0, 0, Cint[], Cint[]) + 0, C_NULL, 0, 0, C_NULL, C_NULL) end end diff --git a/GALAHAD.jl/test/test_tru.jl b/GALAHAD.jl/test/test_tru.jl index 45a4896ea8..85b1ac6ac0 100644 --- a/GALAHAD.jl/test/test_tru.jl +++ b/GALAHAD.jl/test/test_tru.jl @@ -7,7 +7,7 @@ using Printf using Accessors # Custom userdata struct -struct userdata_type +mutable struct userdata_type p::Float64 end @@ -109,6 +109,7 @@ function test_tru() # Set user data userdata = userdata_type(4.0) + pointer_userdata = pointer_from_objref(userdata) # Set problem data n = 3 # dimension @@ -142,7 +143,7 @@ function test_tru() tru_import(control, data, status, n, "coordinate", ne, H_row, H_col, Cint[]) - tru_solve_with_mat(data, userdata, status, + tru_solve_with_mat(data, pointer_userdata, status, n, x, g, ne, fun, grad, hess, prec) end @@ -152,7 +153,7 @@ function test_tru() tru_import(control, data, status, n, "sparse_by_rows", ne, Cint[], H_col, H_ptr) - tru_solve_with_mat(data, userdata, status, + tru_solve_with_mat(data, pointer_userdata, status, n, x, g, ne, fun, grad, hess, prec) end @@ -162,7 +163,7 @@ function test_tru() tru_import(control, data, status, n, "dense", ne, Cint[], Cint[], Cint[]) - tru_solve_with_mat(data, userdata, status, + tru_solve_with_mat(data, pointer_userdata, status, n, x, g, ne, fun, grad, hess_dense, prec) end @@ -172,7 +173,7 @@ function test_tru() tru_import(control, data, status, n, "diagonal", ne, Cint[], Cint[], Cint[]) - tru_solve_with_mat(data, userdata, status, n, x, g, + tru_solve_with_mat(data, pointer_userdata, status, n, x, g, ne, fun_diag, grad_diag, hess_diag, prec) end @@ -182,7 +183,7 @@ function test_tru() tru_import(control, data, status, n, "absent", ne, Cint[], Cint[], Cint[]) - tru_solve_without_mat(data, userdata, status, + tru_solve_without_mat(data, pointer_userdata, status, n, x, g, fun, grad, hessprod, prec) end From 4af566939db0341d22593c4fa8b1e6eb3a8e8a79 Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Tue, 13 Feb 2024 02:09:48 -0500 Subject: [PATCH 25/33] wip --- GALAHAD.jl/test/runtests.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GALAHAD.jl/test/runtests.jl b/GALAHAD.jl/test/runtests.jl index 91bc39c581..a5f3fa5016 100644 --- a/GALAHAD.jl/test/runtests.jl +++ b/GALAHAD.jl/test/runtests.jl @@ -28,8 +28,8 @@ include("test_hash.jl") include("test_ir.jl") include("test_l2rt.jl") include("test_lhs.jl") -include("test_llsr.jl") # bug -## include("test_llst.jl") +## include("test_llsr.jl") # bug +include("test_llst.jl") # bug include("test_lms.jl") include("test_lpa.jl") include("test_lpb.jl") From 4d2e98d92287b9e74e1b28fb9a7db54e0938f563 Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Tue, 13 Feb 2024 12:55:51 -0500 Subject: [PATCH 26/33] Fix the structures of some packages --- GALAHAD.jl/gen/rewriter.jl | 4 ++++ GALAHAD.jl/src/wrappers/llsr.jl | 2 +- GALAHAD.jl/src/wrappers/llst.jl | 2 +- GALAHAD.jl/src/wrappers/rqs.jl | 2 +- GALAHAD.jl/src/wrappers/trs.jl | 2 +- 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/GALAHAD.jl/gen/rewriter.jl b/GALAHAD.jl/gen/rewriter.jl index 6b9b4970d3..5e1e0253f4 100644 --- a/GALAHAD.jl/gen/rewriter.jl +++ b/GALAHAD.jl/gen/rewriter.jl @@ -49,6 +49,10 @@ function rewrite!(path::String, name::String, optimized::Bool) end end + for type in ("llst_history_type", "llsr_history_type", "rqs_history_type", "trs_history_type") + text = replace(text, "$type}" => "$type{T}}") + end + blocks = split(text, "end\n") text = "" for (index, code) in enumerate(blocks) diff --git a/GALAHAD.jl/src/wrappers/llsr.jl b/GALAHAD.jl/src/wrappers/llsr.jl index cadc36f4eb..1c9176c009 100644 --- a/GALAHAD.jl/src/wrappers/llsr.jl +++ b/GALAHAD.jl/src/wrappers/llsr.jl @@ -58,7 +58,7 @@ struct llsr_inform_type{T} multiplier::T bad_alloc::NTuple{81,Cchar} time::llsr_time_type{T} - history::NTuple{100,llsr_history_type} + history::NTuple{100,llsr_history_type{T}} sbls_inform::sbls_inform_type{T} sls_inform::sls_inform_type{T} ir_inform::ir_inform_type{T} diff --git a/GALAHAD.jl/src/wrappers/llst.jl b/GALAHAD.jl/src/wrappers/llst.jl index d928d78f9d..f66d16395f 100644 --- a/GALAHAD.jl/src/wrappers/llst.jl +++ b/GALAHAD.jl/src/wrappers/llst.jl @@ -59,7 +59,7 @@ struct llst_inform_type{T} multiplier::T bad_alloc::NTuple{81,Cchar} time::llst_time_type{T} - history::NTuple{100,llst_history_type} + history::NTuple{100,llst_history_type{T}} sbls_inform::sbls_inform_type{T} sls_inform::sls_inform_type{T} ir_inform::ir_inform_type{T} diff --git a/GALAHAD.jl/src/wrappers/rqs.jl b/GALAHAD.jl/src/wrappers/rqs.jl index 050d3c91a6..6993e1ae25 100644 --- a/GALAHAD.jl/src/wrappers/rqs.jl +++ b/GALAHAD.jl/src/wrappers/rqs.jl @@ -71,7 +71,7 @@ struct rqs_inform_type{T} hard_case::Bool bad_alloc::NTuple{81,Cchar} time::rqs_time_type{T} - history::NTuple{100,rqs_history_type} + history::NTuple{100,rqs_history_type{T}} sls_inform::sls_inform_type{T} ir_inform::ir_inform_type{T} end diff --git a/GALAHAD.jl/src/wrappers/trs.jl b/GALAHAD.jl/src/wrappers/trs.jl index bee2a30964..8c139ee1e0 100644 --- a/GALAHAD.jl/src/wrappers/trs.jl +++ b/GALAHAD.jl/src/wrappers/trs.jl @@ -73,7 +73,7 @@ struct trs_inform_type{T} hard_case::Bool bad_alloc::NTuple{81,Cchar} time::trs_time_type{T} - history::NTuple{100,trs_history_type} + history::NTuple{100,trs_history_type{T}} sls_inform::sls_inform_type{T} ir_inform::ir_inform_type{T} end From 7576cba12c5ccb971adda71ea8c7b03256f663c8 Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Tue, 13 Feb 2024 12:56:10 -0500 Subject: [PATCH 27/33] More working tests! --- GALAHAD.jl/test/runtests.jl | 18 +- GALAHAD.jl/test/test_arc.jl | 148 +++--------- GALAHAD.jl/test/test_bgo.jl | 371 +++++++++++------------------ GALAHAD.jl/test/test_blls.jl | 99 ++++---- GALAHAD.jl/test/test_bqp.jl | 20 +- GALAHAD.jl/test/test_nls.jl | 262 ++++----------------- GALAHAD.jl/test/test_rqs.jl | 60 +++-- GALAHAD.jl/test/test_slls.jl | 8 +- GALAHAD.jl/test/test_trb.jl | 442 ++++++++++++++--------------------- GALAHAD.jl/test/test_tru.jl | 142 ++--------- 10 files changed, 511 insertions(+), 1059 deletions(-) diff --git a/GALAHAD.jl/test/runtests.jl b/GALAHAD.jl/test/runtests.jl index a5f3fa5016..bef02dd0b7 100644 --- a/GALAHAD.jl/test/runtests.jl +++ b/GALAHAD.jl/test/runtests.jl @@ -3,11 +3,11 @@ using GALAHAD @info("GALAHAD_INSTALLATION : $(GALAHAD.GALAHAD_INSTALLATION)") include("test_structures.jl") -## include("test_arc.jl") +include("test_arc.jl") ## include("test_bgo.jl") ## include("test_blls.jl") include("test_bllsb.jl") -## include("test_bqp.jl") +include("test_bqp.jl") include("test_bqpb.jl") include("test_bsc.jl") include("test_ccqp.jl") @@ -28,22 +28,22 @@ include("test_hash.jl") include("test_ir.jl") include("test_l2rt.jl") include("test_lhs.jl") -## include("test_llsr.jl") # bug -include("test_llst.jl") # bug +include("test_llsr.jl") +include("test_llst.jl") include("test_lms.jl") include("test_lpa.jl") include("test_lpb.jl") include("test_lsqp.jl") include("test_lsrt.jl") include("test_lstr.jl") -## include("test_nls.jl") +include("test_nls.jl") include("test_presolve.jl") include("test_psls.jl") 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") @@ -51,9 +51,9 @@ include("test_sha.jl") include("test_sils.jl") ## include("test_slls.jl") include("test_sls.jl") -# include("test_trb.jl") -## include("test_trs.jl") -## include("test_tru.jl") +## include("test_trb.jl") +include("test_trs.jl") +include("test_tru.jl") include("test_ugo.jl") include("test_uls.jl") include("test_wcp.jl") diff --git a/GALAHAD.jl/test/test_arc.jl b/GALAHAD.jl/test/test_arc.jl index cadec2508a..a8460c654e 100644 --- a/GALAHAD.jl/test/test_arc.jl +++ b/GALAHAD.jl/test/test_arc.jl @@ -118,99 +118,11 @@ function test_arc() status = Ref{Cint}() @printf(" Fortran sparse matrix indexing\n\n") - @printf(" tests options for all-in-one storage format\n\n") - - for d in 1:5 - - # Initialize ARC - arc_initialize(data, control, status) - - # Set user-defined control options - @reset control[].f_indexing = true # Fortran sparse matrix indexing - # @reset control[].print_level = 1 - - # Start from 1.5 - x = Float64[1.5, 1.5, 1.5] - - # sparse co-ordinate storage - if d == 1 - st = 'C' - arc_import(control, data, status, n, "coordinate", - ne, H_row, H_col, C_NULL) - - arc_solve_with_mat(data, userdata, status, - n, x, g, ne, fun, grad, hess, prec) - end - - # sparse by rows - if d == 2 - st = 'R' - arc_import(control, data, status, n, "sparse_by_rows", - ne, C_NULL, H_col, H_ptr) - - arc_solve_with_mat(data, userdata, status, - n, x, g, ne, fun, grad, hess, prec) - end - - # dense - if d == 3 - st = 'D' - arc_import(control, data, status, n, "dense", - ne, C_NULL, C_NULL, C_NULL) - - arc_solve_with_mat(data, userdata, status, - n, x, g, ne, fun, grad, hess_dense, prec) - end - - # diagonal - if d == 4 - st = 'I' - arc_import(control, data, status, n, "diagonal", - ne, C_NULL, C_NULL, C_NULL) - - arc_solve_with_mat(data, userdata, status, n, x, g, - ne, fun_diag, grad_diag, hess_diag, prec) - end - - # access by products - if d == 5 - st = 'P' - arc_import(control, data, status, n, "absent", - ne, C_NULL, C_NULL, C_NULL) - - arc_solve_without_mat(data, userdata, status, - n, x, g, fun, grad, hessprod, prec) - end - - arc_information(data, inform, status) - - if inform[].status[] == 0 - @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", st, - inform[].iter, inform[].obj, inform[].status) - else - @printf("%c: ARC_solve exit status = %1i\n", st, inform[].status) - end - - # @printf("x: ") - # for i = 1:n - # @printf("%f ", x[i]) - # end - # @printf("\n") - # @printf("gradient: ") - # for i = 1:n - # @printf("%f ", g[i]) - # end - # @printf("\n") - - # Delete internal workspace - arc_terminate(data, control, inform) - end - - @printf("\n tests reverse-communication options\n\n") + @printf(" tests reverse-communication options\n\n") # reverse-communication input/output eval_status = Ref{Cint}() - f = 0.0 + f = Ref{Float64}(0.0) u = zeros(Float64, n) v = zeros(Float64, n) H_val = zeros(Float64, ne) @@ -224,7 +136,7 @@ function test_arc() # Set user-defined control options @reset control[].f_indexing = true # Fortran sparse matrix indexing - # @reset control[].print_level = 1 + # @reset control[].print_level = Cint(1) # Start from 1.5 x = Float64[1.5, 1.5, 1.5] @@ -237,19 +149,19 @@ function test_arc() terminated = false while !terminated # reverse-communication loop - arc_solve_reverse_with_mat(data, status, eval_status, n, x, f, g, ne, H_val, u, v) + arc_solve_reverse_with_mat(data, status, eval_status, n, x, f[], g, ne, H_val, u, v) if status[] == 0 # successful termination terminated = true elseif status[] < 0 # error exit terminated = true elseif status[] == 2 # evaluate f - eval_status = fun(n, x, f, userdata) + eval_status[] = fun(n, x, f, userdata) elseif status[] == 3 # evaluate g - eval_status = grad(n, x, g, userdata) + eval_status[] = grad(n, x, g, userdata) elseif status[] == 4 # evaluate H - eval_status = hess(n, ne, x, H_val, userdata) + eval_status[] = hess(n, ne, x, H_val, userdata) elseif status[] == 6 # evaluate the product with P - eval_status = prec(n, x, u, v, userdata) + eval_status[] = prec(n, x, u, v, userdata) else @printf(" the value %1i of status should not occur\n", status) end @@ -265,19 +177,19 @@ function test_arc() terminated = false while !terminated # reverse-communication loop arc_solve_reverse_with_mat(data, status, eval_status, - n, x, f, g, ne, H_val, u, v) + n, x, f[], g, ne, H_val, u, v) if status[] == 0 # successful termination terminated = true elseif status[] < 0 # error exit terminated = true elseif status[] == 2 # evaluate f - eval_status = fun(n, x, f, userdata) + eval_status[] = fun(n, x, f, userdata) elseif status[] == 3 # evaluate g - eval_status = grad(n, x, g, userdata) + eval_status[] = grad(n, x, g, userdata) elseif status[] == 4 # evaluate H - eval_status = hess(n, ne, x, H_val, userdata) + eval_status[] = hess(n, ne, x, H_val, userdata) elseif status[] == 6 # evaluate the product with P - eval_status = prec(n, x, u, v, userdata) + eval_status[] = prec(n, x, u, v, userdata) else @printf(" the value %1i of status should not occur\n", status) end @@ -293,23 +205,21 @@ function test_arc() terminated = false while !terminated # reverse-communication loop arc_solve_reverse_with_mat(data, status, eval_status, - n, x, f, g, n * (n + 1) / 2, H_dense, u, v) + n, x, f[], g, div(n*(n + 1), 2), H_dense, u, v) if status[] == 0 # successful termination terminated = true elseif status[] < 0 # error exit terminated = true elseif status[] == 2 # evaluate f - eval_status = fun(n, x, f, userdata) + eval_status[] = fun(n, x, f, userdata) elseif status[] == 3 # evaluate g - eval_status = grad(n, x, g, userdata) + eval_status[] = grad(n, x, g, userdata) elseif status[] == 4 # evaluate H - eval_status = hess_dense(n, n * (n + 1) / 2, x, H_dense, - userdata) + eval_status[] = hess_dense(n, div(n*(n + 1), 2), x, H_dense, userdata) elseif status[] == 6 # evaluate the product with P - eval_status = prec(n, x, u, v, userdata) + eval_status[] = prec(n, x, u, v, userdata) else - @printf(" the value %1i of status should not occur\n", - status) + @printf(" the value %1i of status should not occur\n", status) end end end @@ -323,19 +233,19 @@ function test_arc() terminated = false while !terminated # reverse-communication loop arc_solve_reverse_with_mat(data, status, eval_status, - n, x, f, g, n, H_diag, u, v) + n, x, f[], g, n, H_diag, u, v) if status[] == 0 # successful termination terminated = true elseif status[] < 0 # error exit terminated = true elseif status[] == 2 # evaluate f - eval_status = fun_diag(n, x, f, userdata) + eval_status[] = fun_diag(n, x, f, userdata) elseif status[] == 3 # evaluate g - eval_status = grad_diag(n, x, g, userdata) + eval_status[] = grad_diag(n, x, g, userdata) elseif status[] == 4 # evaluate H - eval_status = hess_diag(n, n, x, H_diag, userdata) + eval_status[] = hess_diag(n, n, x, H_diag, userdata) elseif status[] == 6 # evaluate the product with P - eval_status = prec(n, x, u, v, userdata) + eval_status[] = prec(n, x, u, v, userdata) else @printf(" the value %1i of status should not occur\n", status) end @@ -351,19 +261,19 @@ function test_arc() terminated = false while !terminated # reverse-communication loop arc_solve_reverse_without_mat(data, status, eval_status, - n, x, f, g, u, v) + n, x, f[], g, u, v) if status[] == 0 # successful termination terminated = true elseif status[] < 0 # error exit terminated = true elseif status[] == 2 # evaluate f - eval_status = fun(n, x, f, userdata) + eval_status[] = fun(n, x, f, userdata) elseif status[] == 3 # evaluate g - eval_status = grad(n, x, g, userdata) + eval_status[] = grad(n, x, g, userdata) elseif status[] == 5 # evaluate H - eval_status = hessprod(n, x, u, v, false, userdata) + eval_status[] = hessprod(n, x, u, v, false, userdata) elseif status[] == 6 # evaluate the product with P - eval_status = prec(n, x, u, v, userdata) + eval_status[] = prec(n, x, u, v, userdata) else @printf(" the value %1i of status should not occur\n", status) end diff --git a/GALAHAD.jl/test/test_bgo.jl b/GALAHAD.jl/test/test_bgo.jl index 0afd53b9a8..9d8c053201 100644 --- a/GALAHAD.jl/test/test_bgo.jl +++ b/GALAHAD.jl/test/test_bgo.jl @@ -15,144 +15,143 @@ end function test_bgo() - # # Objective function - # function fun(n::Int, var::Vector{Float64}, f::Ptr{Float64}, userdata::Ptr{Cvoid}) - # p = myuserdata.p - # freq = myuserdata.freq - # mag = myuserdata.mag - - # f_val = (var[1] + var[3] + p)^2 + (var[2] + var[3])^2 + mag * cos(freq * var[1]) + sum(var) - # unsafe_store!(f, f_val) - # return 0 - # end - - # # Gradient of the objective - # function grad(n::Int, var::Vector{Float64}, g::Vector{Float64}, userdata::Ptr{Cvoid}) - # struct Cuserdata_type - # p::Float64 - # freq::Float64 - # mag::Float64 - # end - # myuserdata = unsafe_load(Cuserdata_type, userdata) - # p = myuserdata.p - # freq = myuserdata.freq - # mag = myuserdata.mag - - # g[1] = 2.0 * (var[1] + var[3] + p) - mag * freq * sin(freq * var[1]) + 1.0 - # g[2] = 2.0 * (var[2] + var[3]) + 1.0 - # g[3] = 2.0 * (var[1] + var[3] + p) + 2.0 * (var[2] + var[3]) + 1.0 - # return 0 - # end - - # # Hessian of the objective - # function hess(n::Int, ne::Int, var::Vector{Float64}, hval::Vector{Float64}, userdata::Ptr{Cvoid}) - # struct Cuserdata_type - # p::Float64 - # freq::Float64 - # mag::Float64 - # end - # myuserdata = unsafe_load(Cuserdata_type, userdata) - # freq = myuserdata.freq - # mag = myuserdata.mag - - # hval[1] = 2.0 - mag * freq^2 * cos(freq * var[1]) - # hval[2] = 2.0 - # hval[3] = 2.0 - # hval[4] = 4.0 - # return 0 - # end - - # # Dense Hessian - # function hess_dense(n::Int, ne::Int, var::Vector{Float64}, hval::Vector{Float64}, userdata::Ptr{Cvoid}) - # struct Cuserdata_type - # p::Float64 - # freq::Float64 - # mag::Float64 - # end - # myuserdata = unsafe_load(Cuserdata_type, userdata) - # freq = myuserdata.freq - # mag = myuserdata.mag - - # hval[1] = 2.0 - mag * freq^2 * cos(freq * var[1]) - # hval[2] = 0.0 - # hval[3] = 2.0 - # hval[4] = 2.0 - # hval[5] = 4.0 - # return 0 - # end - - # # Hessian-vector product - # function hessprod(n::Int, var::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, got_h::Bool, userdata::Ptr{Cvoid}) - # struct Cuserdata_type - # p::Float64 - # freq::Float64 - # mag::Float64 - # end - # myuserdata = unsafe_load(Cuserdata_type, userdata) - # freq = myuserdata.freq - # mag = myuserdata.mag - - # u[1] = u[1] + 2.0 * (v[1] + v[3]) - mag * freq^2 * cos(freq * var[1]) * v[1] - # u[2] = u[2] + 2.0 * (v[2] + v[3]) - # u[3] = u[3] + 2.0 * (v[1] + v[2] + 2.0 * v[3]) - # return 0 - # end - - # # Sparse Hessian-vector product - # function shessprod(n::Int, var::Vector{Float64}, nnz_v::Int, index_nz_v::Vector{Int}, v::Vector{Float64}, - # nnz_u::Ptr{Int}, index_nz_u::Vector{Int}, u::Vector{Float64}, got_h::Bool, userdata::Ptr{Cvoid}) - # struct Cuserdata_type - # p::Float64 - # freq::Float64 - # mag::Float64 - # end - # myuserdata = unsafe_load(Cuserdata_type, userdata) - # freq = myuserdata.freq - # mag = myuserdata.mag - - # p = zeros(3) - # used = [false, false, false] - # for i in 1:nnz_v - # j = index_nz_v[i] - # if j == 1 - # p[1] += 2.0 * v[1] - mag * freq^2 * cos(freq * var[1]) * v[1] - # used[1] = true - # p[3] += 2.0 * v[1] - # used[3] = true - # elseif j == 2 - # p[2] += 2.0 * v[2] - # used[2] = true - # p[3] += 2.0 * v[2] - # used[3] = true - # elseif j == 3 - # p[1] += 2.0 * v[3] - # used[1] = true - # p[2] += 2.0 * v[3] - # used[2] = true - # p[3] += 4.0 * v[3] - # used[3] = true - # end - # end - - # nnz = 0 - # for j in 1:3 - # if used[j] - # u[j] = p[j] - # nnz += 1 - # index_nz_u[nnz] = j - # end - # end - # unsafe_store!(nnz_u, nnz) - # return 0 - # end - - # # Apply preconditioner - # function prec(n::Int, var::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, userdata::Ptr{Cvoid}) - # u[1] = 0.5 * v[1] - # u[2] = 0.5 * v[2] - # u[3] = 0.25 * v[3] - # return 0 - # end + # Objective function + function fun(n::Int, x::Vector{Float64}, f::Ref{Float64}, userdata::userdata_type) + p = userdata.p + freq = userdata.freq + mag = userdata.mag + + f[] = (x[1] + x[3] + p)^2 + (x[2] + x[3])^2 + mag * cos(freq * x[1]) + sum(x) + return 0 + end + + # Gradient of the objective + function grad(n::Int, var::Vector{Float64}, g::Vector{Float64}, userdata::userdata_type) + struct Cuserdata_type + p::Float64 + freq::Float64 + mag::Float64 + end + myuserdata = unsafe_load(Cuserdata_type, userdata) + p = myuserdata.p + freq = myuserdata.freq + mag = myuserdata.mag + + g[1] = 2.0 * (var[1] + var[3] + p) - mag * freq * sin(freq * var[1]) + 1.0 + g[2] = 2.0 * (var[2] + var[3]) + 1.0 + g[3] = 2.0 * (var[1] + var[3] + p) + 2.0 * (var[2] + var[3]) + 1.0 + return 0 + end + + # Hessian of the objective + function hess(n::Int, ne::Int, var::Vector{Float64}, hval::Vector{Float64}, userdata::userdata_type) + struct Cuserdata_type + p::Float64 + freq::Float64 + mag::Float64 + end + myuserdata = unsafe_load(Cuserdata_type, userdata) + freq = myuserdata.freq + mag = myuserdata.mag + + hval[1] = 2.0 - mag * freq^2 * cos(freq * var[1]) + hval[2] = 2.0 + hval[3] = 2.0 + hval[4] = 4.0 + return 0 + end + + # Dense Hessian + function hess_dense(n::Int, ne::Int, var::Vector{Float64}, hval::Vector{Float64}, userdata::userdata_type) + struct Cuserdata_type + p::Float64 + freq::Float64 + mag::Float64 + end + myuserdata = unsafe_load(Cuserdata_type, userdata) + freq = myuserdata.freq + mag = myuserdata.mag + + hval[1] = 2.0 - mag * freq^2 * cos(freq * var[1]) + hval[2] = 0.0 + hval[3] = 2.0 + hval[4] = 2.0 + hval[5] = 4.0 + return 0 + end + + # Hessian-vector product + function hessprod(n::Int, var::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, got_h::Bool, userdata::userdata_type) + struct Cuserdata_type + p::Float64 + freq::Float64 + mag::Float64 + end + myuserdata = unsafe_load(Cuserdata_type, userdata) + freq = myuserdata.freq + mag = myuserdata.mag + + u[1] = u[1] + 2.0 * (v[1] + v[3]) - mag * freq^2 * cos(freq * var[1]) * v[1] + u[2] = u[2] + 2.0 * (v[2] + v[3]) + u[3] = u[3] + 2.0 * (v[1] + v[2] + 2.0 * v[3]) + return 0 + end + + # Sparse Hessian-vector product + function shessprod(n::Int, var::Vector{Float64}, nnz_v::Int, index_nz_v::Vector{Int}, v::Vector{Float64}, + nnz_u::Ptr{Int}, index_nz_u::Vector{Int}, u::Vector{Float64}, got_h::Bool, userdata::userdata_type) + struct Cuserdata_type + p::Float64 + freq::Float64 + mag::Float64 + end + myuserdata = unsafe_load(Cuserdata_type, userdata) + freq = myuserdata.freq + mag = myuserdata.mag + + p = zeros(3) + used = [false, false, false] + for i in 1:nnz_v + j = index_nz_v[i] + if j == 1 + p[1] += 2.0 * v[1] - mag * freq^2 * cos(freq * var[1]) * v[1] + used[1] = true + p[3] += 2.0 * v[1] + used[3] = true + elseif j == 2 + p[2] += 2.0 * v[2] + used[2] = true + p[3] += 2.0 * v[2] + used[3] = true + elseif j == 3 + p[1] += 2.0 * v[3] + used[1] = true + p[2] += 2.0 * v[3] + used[2] = true + p[3] += 4.0 * v[3] + used[3] = true + end + end + + nnz = 0 + for j in 1:3 + if used[j] + u[j] = p[j] + nnz += 1 + index_nz_u[nnz] = j + end + end + unsafe_store!(nnz_u, nnz) + return 0 + end + + # Apply preconditioner + function prec(n::Int, var::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, userdata::userdata_type) + u[1] = 0.5 * v[1] + u[2] = 0.5 * v[2] + u[3] = 0.25 * v[3] + return 0 + end # Derived types data = Ref{Ptr{Cvoid}}() @@ -177,101 +176,7 @@ function test_bgo() status = Ref{Cint}() @printf(" Fortran sparse matrix indexing\n\n") - @printf(" tests options for all-in-one storage format\n\n") - - for d in 1:5 - - # Initialize BGO - bgo_initialize(data, control, status) - - # Set user-defined control options - @reset control[].f_indexing = true # Fortran sparse matrix indexing - @reset control[].attempts_max = 10000 - @reset control[].max_evals = 20000 - @reset control[].sampling_strategy = 3 - @reset control[].trb_control.maxit = 100 - # @reset control[].print_level = 1 - - # Start from 0 - x = Float64[0.0, 0.0, 0.0] - - # sparse co-ordinate storage - if d == 1 - st = 'C' - bgo_import(control, data, status, n, x_l, x_u, - "coordinate", ne, H_row, H_col, C_NULL) - - bgo_solve_with_mat(data, userdata, status, n, x, g, - ne, fun, grad, hess, hessprod, prec) - end - - # sparse by rows - if d == 2 - st = 'R' - bgo_import(control, data, status, n, x_l, x_u, - "sparse_by_rows", ne, C_NULL, H_col, H_ptr) - - bgo_solve_with_mat(data, userdata, status, n, x, g, - ne, fun, grad, hess, hessprod, prec) - end - - # dense - if d == 3 - st = 'D' - bgo_import(control, data, status, n, x_l, x_u, - "dense", ne, C_NULL, C_NULL, C_NULL) - - bgo_solve_with_mat(data, userdata, status, n, x, g, - ne, fun, grad, hess_dense, hessprod, prec) - end - - # diagonal - if d == 4 - st = 'I' - bgo_import(control, data, status, n, x_l, x_u, - "diagonal", ne, C_NULL, C_NULL, C_NULL) - - bgo_solve_with_mat(data, userdata, status, n, x, g, - ne, fun_diag, grad_diag, hess_diag, - hessprod_diag, prec) - end - - # access by products - if d == 5 - st = 'P' - bgo_import(control, data, status, n, x_l, x_u, - "absent", ne, C_NULL, C_NULL, C_NULL) - - bgo_solve_without_mat(data, userdata, status, n, x, g, - fun, grad, hessprod, shessprod, prec) - end - - # Record solution information - bgo_information(data, inform, status) - - if inform[].status == 0 - @printf("%c:%6i evaluations. Optimal objective value = %5.2f status = %1i\n", st, - inform[].f_eval, inform[].obj, inform[].status) - else - @printf("%c: BGO_solve exit status = %1i\n", st, inform[].status) - end - - # @printf("x: ") - # for i in 1:n - # @printf("%f ", x[i]) - # end - # @printf("\n") - # @printf("gradient: ") - # for i in 1:n - # @printf("%f ", g[i]) - # end - # @printf("\n") - - # Delete internal workspace - bgo_terminate(data, control, inform) - end - - @printf("\n tests reverse-communication options\n\n") + @printf(" tests reverse-communication options\n\n") # reverse-communication input/output eval_status = Ref{Cint}() diff --git a/GALAHAD.jl/test/test_blls.jl b/GALAHAD.jl/test/test_blls.jl index 0b5d8bc813..cca6b8244e 100644 --- a/GALAHAD.jl/test/test_blls.jl +++ b/GALAHAD.jl/test/test_blls.jl @@ -7,20 +7,20 @@ using Printf using Accessors # Custom userdata struct -struct userdata_type +mutable struct userdata_type scale::Float64 end -function test_blls() - # Apply preconditioner - function prec(n::Int, var::Vector{Float64}, p::Vector{Float64}, userdata::userdata_type) - scale = userdata.scale - for i in 1:n - p[i] = scale * v[i] - end - return 0 +# Apply preconditioner +function prec(n::Int, x::Vector{Float64}, p::Vector{Float64}, userdata::userdata_type) + scale = userdata.scale + for i in 1:n + p[i] = scale * x[i] end + return 0 +end +function test_blls() # Derived types data = Ref{Ptr{Cvoid}}() control = Ref{blls_control_type{Float64}}() @@ -28,6 +28,10 @@ function test_blls() # Set user data userdata = userdata_type(1.0) + pointer_userdata = pointer_from_objref(userdata) + + # Pointer to call prec + pointer_prec = @cfunction(prec, Int, (Int, Vector{Float64}, Vector{Float64}, userdata_type)) # Set problem data n = 10 # dimension @@ -75,7 +79,7 @@ function test_blls() # (e^T) (n + 1) for i in 1:n - b[i] = i + 1 + b[i] = i end b[n + 1] = n + 1 @@ -87,18 +91,18 @@ function test_blls() # # A by rows for i in 1:n - Ao_ptr[i] = i + 1 - Ao_row[i] = i + 1 - Ao_col[i] = i + 1 + Ao_ptr[i] = i + Ao_row[i] = i + Ao_col[i] = i Ao_val[i] = 1.0 end Ao_ptr[n + 1] = n + 1 for i in 1:n Ao_row[n + i] = o - Ao_col[n + i] = i + 1 + Ao_col[n + i] = i Ao_val[n + i] = 1.0 end - Ao_ptr[o] = Ao_ne + 1 + Ao_ptr[o + 1] = Ao_ne + 1 l = 0 for i in 1:n for j in 1:n @@ -119,8 +123,8 @@ function test_blls() l = 0 for j in 1:n l = l + 1 - Ao_by_col_ptr[j] = l + 1 - Ao_by_col_row[l] = j + 1 + Ao_by_col_ptr[j] = l + Ao_by_col_row[l] = j Ao_by_col_val[l] = 1.0 l = l + 1 Ao_by_col_row[l] = o @@ -162,23 +166,23 @@ function test_blls() if d == 1 st = "CO" blls_import(control, data, status, n, o, - "coordinate", Ao_ne, Ao_row, Ao_col, 0, Cint[]) + "coordinate", Ao_ne, Ao_row, Ao_col, 0, C_NULL) - blls_solve_given_a(data, userdata, status, n, o, + blls_solve_given_a(data, pointer_userdata, status, n, o, Ao_ne, Ao_val, b, x_l, x_u, - x, z, r, g, x_stat, w, prec) + x, z, r, g, x_stat, w, pointer_prec) end # sparse by rows if d == 2 st = "SR" blls_import(control, data, status, n, o, - "sparse_by_rows", Ao_ne, Cint[], Ao_col, + "sparse_by_rows", Ao_ne, C_NULL, Ao_col, Ao_ptr_ne, Ao_ptr) - blls_solve_given_a(data, userdata, status, n, o, + blls_solve_given_a(data, pointer_userdata, status, n, o, Ao_ne, Ao_val, b, x_l, x_u, - x, z, r, g, x_stat, w, prec) + x, z, r, g, x_stat, w, pointer_prec) end # dense by rows @@ -186,11 +190,11 @@ function test_blls() st = "DR" blls_import(control, data, status, n, o, "dense_by_rows", Ao_dense_ne, - Cint[], Cint[], 0, Cint[]) + C_NULL, C_NULL, 0, C_NULL) - blls_solve_given_a(data, userdata, status, n, o, + blls_solve_given_a(data, pointer_userdata, status, n, o, Ao_dense_ne, Ao_dense, b, x_l, x_u, - x, z, r, g, x_stat, w, prec) + x, z, r, g, x_stat, w, pointer_prec) end # sparse by columns @@ -198,11 +202,11 @@ function test_blls() st = "SC" blls_import(control, data, status, n, o, "sparse_by_columns", Ao_ne, Ao_by_col_row, - Cint[], Ao_by_col_ptr_ne, Ao_by_col_ptr) + C_NULL, Ao_by_col_ptr_ne, Ao_by_col_ptr) - blls_solve_given_a(data, userdata, status, n, o, + blls_solve_given_a(data, pointer_userdata, status, n, o, Ao_ne, Ao_by_col_val, b, x_l, x_u, - x, z, r, g, x_stat, w, prec) + x, z, r, g, x_stat, w, pointer_prec) end # dense by columns @@ -210,11 +214,11 @@ function test_blls() st = "DC" blls_import(control, data, status, n, o, "dense_by_columns", Ao_dense_ne, - Cint[], Cint[], 0, Cint[]) + C_NULL, C_NULL, 0, C_NULL) - blls_solve_given_a(data, userdata, status, n, o, + blls_solve_given_a(data, pointer_userdata, status, n, o, Ao_dense_ne, Ao_by_col_dense, b, x_l, x_u, - x, z, r, g, x_stat, w, prec) + x, z, r, g, x_stat, w, pointer_prec) end blls_information(data, inform, status) @@ -242,11 +246,16 @@ function test_blls() # reverse-communication input/output on = max(o, n) - # int eval_status, nz_v_start, nz_v_end, nz_p_end - # int nz_v[on], nz_p[o], mask[o] - # real_wp_ v[on], p[on] + eval_status = Ref{Cint}() + nz_v_start = Ref{Cint}() + nz_v_end = Ref{Cint}() + nz_v = zeros(Cint, on) + nz_p = zeros(Cint, o) + mask = zeros(Cint, o) + v = zeros(Float64, on) + p = zeros(Float64, on) - nz_p_end = 0 + nz_p_end = 1 # Initialize BLLS blls_initialize(data, control, status) @@ -260,7 +269,7 @@ function test_blls() z[i] = 0.0 end - st = "RC" + st = "RZ" for i in 1:o mask[i] = 0 end @@ -292,15 +301,15 @@ function test_blls() for i in 1:n p[i] = 0.0 end - for l in (nz_v_start - 1):nz_v_end + for l in nz_v_start[]:nz_v_end[] i = nz_v[l] p[i] = v[i] p[n + 1] = p[n + 1] + v[i] end elseif status[] == 5 # evaluate p = sparse Av for sparse v - nz_p_end = 0 - for l in (nz_v_start - 1):nz_v_end - i = nz_v[l] - 1 + nz_p_end = 1 + for l in nz_v_start[]:nz_v_end[] + i = nz_v[l] if mask[i] == 0 mask[i] = 1 nz_p[nz_p_end] = i + 1 @@ -316,12 +325,12 @@ function test_blls() p[n + 1] = p[n + 1] + v[i] end for l in 1:nz_p_end - mask[nz_p[l] - 1] = 0 + mask[nz_p[l]] = 0 # <-- Nick I need your help here end end elseif status[] == 6 # evaluate p = sparse A^Tv - for l in (nz_v_start - 1):nz_v_end - i = nz_v[l] - 1 + for l in nz_v_start[]:nz_v_end[] + i = nz_v[l] p[i] = v[i] + v[n + 1] end elseif status[] == 7 # evaluate p = P^{-}v @@ -331,7 +340,7 @@ function test_blls() else @printf(" the value %1i of status should not occur\n", status) end - eval_status = 0 + eval_status[] = 0 end # Record solution information diff --git a/GALAHAD.jl/test/test_bqp.jl b/GALAHAD.jl/test/test_bqp.jl index 503dd0dc66..f724161f2a 100644 --- a/GALAHAD.jl/test/test_bqp.jl +++ b/GALAHAD.jl/test/test_bqp.jl @@ -103,7 +103,7 @@ function test_bqp() if d == 1 st = 'C' bqp_import(control, data, status, n, - "coordinate", H_ne, H_row, H_col, Cint[]) + "coordinate", H_ne, H_row, H_col, C_NULL) bqp_solve_given_h(data, status, n, H_ne, H_val, g, f, x_l, x_u, x, z, x_stat) @@ -113,7 +113,7 @@ function test_bqp() if d == 2 st = 'R' bqp_import(control, data, status, n, - "sparse_by_rows", H_ne, Cint[], H_col, H_ptr) + "sparse_by_rows", H_ne, C_NULL, H_col, H_ptr) bqp_solve_given_h(data, status, n, H_ne, H_val, g, f, x_l, x_u, x, z, x_stat) @@ -123,7 +123,7 @@ function test_bqp() if d == 3 st = 'D' bqp_import(control, data, status, n, - "dense", H_dense_ne, Cint[], Cint[], Cint[]) + "dense", H_dense_ne, C_NULL, C_NULL, C_NULL) bqp_solve_given_h(data, status, n, H_dense_ne, H_dense, g, f, x_l, x_u, x, z, x_stat) @@ -133,7 +133,7 @@ function test_bqp() if d == 4 st = 'L' bqp_import(control, data, status, n, - "diagonal", H_ne, Cint[], Cint[], Cint[]) + "diagonal", H_ne, C_NULL, C_NULL, C_NULL) bqp_solve_given_h(data, status, n, n, H_diag, g, f, x_l, x_u, x, z, x_stat) @@ -168,14 +168,13 @@ function test_bqp() # reverse-communication input/output nz_v_start = Ref{Cint}() nz_v_end = Ref{Cint}() - nz_prod_end = Ref{Cint}() nz_v = zeros(Cint, n) nz_prod = zeros(Cint, n) mask = zeros(Cint, n) v = zeros(Float64, n) prod = zeros(Float64, n) - nz_prod_end = 0 + nz_prod_end = 1 # Initialize BQP bqp_initialize(data, control, status) @@ -200,13 +199,14 @@ function test_bqp() while !terminated # reverse-communication loop bqp_solve_reverse_h_prod(data, status, n, g, f, x_l, x_u, x, z, x_stat, v, prod, nz_v, nz_v_start, nz_v_end, nz_prod, nz_prod_end) + if status[] == 0 # successful termination terminated = true elseif status[] < 0 # error exit terminated = true elseif status[] == 2 # evaluate Hv prod[1] = 2.0 * v[1] + v[2] - for i in 2:(n - 1) + for i in 2:n-1 prod[i] = 2.0 * v[i] + v[i - 1] + v[i + 1] end prod[n] = 2.0 * v[n] + v[n - 1] @@ -214,8 +214,8 @@ function test_bqp() for i in 1:n prod[i] = 0.0 end - for l in nz_v_start[]+1:nz_v_end[] - i = nz_v[l] - 1 + for l in nz_v_start[]:nz_v_end[] + i = nz_v[l] if i > 1 prod[i - 1] = prod[i - 1] + v[i] end @@ -227,7 +227,7 @@ function test_bqp() elseif status[] == 4 # evaluate sarse Hv for sparse v nz_prod_end = 1 for l in nz_v_start[]:nz_v_end[] - i = nz_v[l] - 1 + i = nz_v[l] if i > 1 if mask[i - 1] == 0 mask[i - 1] = 1 diff --git a/GALAHAD.jl/test/test_nls.jl b/GALAHAD.jl/test/test_nls.jl index d07bced435..81e8008e2d 100644 --- a/GALAHAD.jl/test/test_nls.jl +++ b/GALAHAD.jl/test/test_nls.jl @@ -13,7 +13,7 @@ end function test_nls() # compute the residuals - function res(n, m, x::Vector{Float64}, c::Vector{Float64}, userdata::userdata_type) + function res(n::Int, m::Int, x::Vector{Float64}, c::Vector{Float64}, userdata::userdata_type) c[1] = x[1]^2 + userdata.p c[2] = x[1] + x[2]^2 c[3] = x[1] - x[2] @@ -21,8 +21,7 @@ function test_nls() end # compute the Jacobian - function jac(n, m, jne, x::Vector{Float64}, jval::Vector{Float64}, - userdata::userdata_type) + function jac(n::Int, m::Int, jne::Int, x::Vector{Float64}, jval::Vector{Float64}, userdata::userdata_type) jval[1] = 2.0 * x[1] jval[2] = 1.0 jval[3] = 2.0 * x[2] @@ -32,17 +31,15 @@ function test_nls() end # compute the Hessian - function hess(n, m, hne, x::Vector{Float64}, y::Vector{Float64}, hval::Vector{Float64}, - userdata::userdata_type) + function hess(n::Int, m::Int, hne::Int, x::Vector{Float64}, y::Vector{Float64}, hval::Vector{Float64}, userdata::userdata_type) hval[1] = 2.0 * y[1] hval[2] = 2.0 * y[2] return 0 end # compute Jacobian-vector products - function jacprod(n, m, x::Vector{Float64}, transpose::Bool, u::Vector{Float64}, - v::Vector{Float64}, got_j::Bool, userdata::userdata_type) - if transpose + function jacprod(n::Int, m::Int, x::Vector{Float64}, trans::Bool, u::Vector{Float64}, v::Vector{Float64}, got_j::Bool, userdata::userdata_type) + if trans u[1] = u[1] + 2.0 * x[1] * v[1] + v[2] + v[3] u[2] = u[2] + 2.0 * x[2] * v[2] - v[3] else @@ -54,32 +51,28 @@ function test_nls() end # compute Hessian-vector products - function hessprod(n, m, x::Vector{Float64}, y::Vector{Float64}, u::Vector{Float64}, - v::Vector{Float64}, got_h::Bool, userdata::userdata_type) + function hessprod(n::Int, m::Int, x::Vector{Float64}, y::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, got_h::Bool, userdata::userdata_type) u[1] = u[1] + 2.0 * y[1] * v[1] u[2] = u[2] + 2.0 * y[2] * v[2] return 0 end # compute residual-Hessians-vector products - function rhessprods(n, m, pne, x::Vector{Float64}, v::Vector{Float64}, - pval::Vector{Float64}, got_h::Bool, userdata::userdata_type) + function rhessprods(n::Int, m::Int, pne::Int, x::Vector{Float64}, v::Vector{Float64}, pval::Vector{Float64}, got_h::Bool, userdata::userdata_type) pval[1] = 2.0 * v[1] pval[2] = 2.0 * v[2] return 0 end # # scale v - function scale(n, m, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, - userdata::userdata_type) + function scale(n::Int, m::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, userdata::userdata_type) u[1] = v[1] u[2] = v[2] return 0 end # compute the dense Jacobian - function jac_dense(n, m, jne, x::Vector{Float64}, jval::Vector{Float64}, - userdata::userdata_type) + function jac_dense(n::Int, m::Int, jne::Int, x::Vector{Float64}, jval::Vector{Float64}, userdata::userdata_type) jval[1] = 2.0 * x[1] jval[2] = 0.0 jval[3] = 1.0 @@ -90,8 +83,7 @@ function test_nls() end # compute the dense Hessian - function hess_dense(n, m, hne, x::Vector{Float64}, y::Vector{Float64}, - hval::Vector{Float64}, userdata::userdata_type) + function hess_dense(n::Int, m::Int, hne::Int, x::Vector{Float64}, y::Vector{Float64}, hval::Vector{Float64}, userdata::userdata_type) hval[1] = 2.0 * y[1] hval[2] = 0.0 hval[3] = 2.0 * y[2] @@ -99,8 +91,7 @@ function test_nls() end # compute dense residual-Hessians-vector products - function rhessprods_dense(n, m, pne, x::Vector{Float64}, v::Vector{Float64}, - pval::Vector{Float64}, got_h::Bool, userdata::userdata_type) + function rhessprods_dense(n::Int, m::Int, pne::Int, x::Vector{Float64}, v::Vector{Float64}, pval::Vector{Float64}, got_h::Bool, userdata::userdata_type) pval[1] = 2.0 * v[1] pval[2] = 0.0 pval[3] = 0.0 @@ -142,100 +133,8 @@ function test_nls() status = Ref{Cint}() @printf(" Fortran sparse matrix indexing\n\n") - @printf(" tests options for all-in-one storage format\n\n") + @printf(" tests reverse-communication options\n\n") - for d in 1:5 - # Initialize NLS - nls_initialize(data, control, inform) - - # Set user-defined control options - @reset control[].f_indexing = true # Fortran sparse matrix indexing - # @reset control[].print_level = Cint(1) - @reset control[].jacobian_available = Cint(2) - @reset control[].hessian_available = Cint(2) - @reset control[].model = Cint(6) - x = Float64[1.5, 1.5] # starting point - W = Float64[1.0, 1.0, 1.0] # weights - - # sparse co-ordinate storage - if d == 1 - st = 'C' - nls_import(control, data, status, n, m, - "coordinate", j_ne, J_row, J_col, Cint[], - "coordinate", h_ne, H_row, H_col, Cint[], - "sparse_by_columns", p_ne, P_row, Cint[], P_ptr, W) - - nls_solve_with_mat(data, userdata, status, - n, m, x, c, g, res, j_ne, jac, - h_ne, hess, p_ne, rhessprods) - end - - # sparse by rows - if d == 2 - st = 'R' - nls_import(control, data, status, n, m, - "sparse_by_rows", j_ne, Cint[], J_col, J_ptr, - "sparse_by_rows", h_ne, Cint[], H_col, H_ptr, - "sparse_by_columns", p_ne, P_row, Cint[], P_ptr, W) - - nls_solve_with_mat(data, userdata, status, - n, m, x, c, g, res, j_ne, jac, - h_ne, hess, p_ne, rhessprods) - end - - # dense - if d == 3 - st = 'D' - nls_import(control, data, status, n, m, - "dense", j_ne, Cint[], Cint[], Cint[], - "dense", h_ne, Cint[], Cint[], Cint[], - "dense", p_ne, Cint[], Cint[], Cint[], W) - - nls_solve_with_mat(data, userdata, status, - n, m, x, c, g, res, j_ne, jac_dense, - h_ne, hess_dense, p_ne, rhessprods_dense) - end - - # diagonal - if d == 4 - st = 'I' - nls_import(control, data, status, n, m, - "sparse_by_rows", j_ne, Cint[], J_col, J_ptr, - "diagonal", h_ne, Cint[], Cint[], Cint[], - "sparse_by_columns", p_ne, P_row, Cint[], P_ptr, W) - - nls_solve_with_mat(data, userdata, status, - n, m, x, c, g, res, j_ne, jac, - h_ne, hess, p_ne, rhessprods) - end - - # access by products - if d == 5 - st = 'P' - nls_import(control, data, status, n, m, - "absent", j_ne, Cint[], Cint[], Cint[], - "absent", h_ne, Cint[], Cint[], Cint[], - "sparse_by_columns", p_ne, P_row, Cint[], P_ptr, W) - - nls_solve_without_mat(data, userdata, status, - n, m, x, c, g, res, jacprod, - hessprod, p_ne, rhessprods) - end - - nls_information(data, inform, status) - - if inform[].status == 0 - @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", - st, inform[].iter, inform[].obj, inform[].status) - else - @printf("%c: NLS_solve exit status = %1i\n", st, inform[].status) - end - - # Delete internal workspace - nls_terminate(data, control, inform) - end - - @printf("\n tests reverse-communication options\n\n") # reverse-communication input/output eval_status = Ref{Cint}() u = zeros(Float64, max(m, n)) @@ -247,6 +146,7 @@ function test_nls() H_diag = zeros(Float64, n) P_val = zeros(Float64, p_ne) P_dense = zeros(Float64, m * n) + trans = Ref{Bool}() got_j = false got_h = false @@ -257,9 +157,9 @@ function test_nls() # Set user-defined control options @reset control[].f_indexing = true # Fortran sparse matrix indexing # @reset control[].print_level = Cint(1) - @reset control[].jacobian_available = 2 - @reset control[].hessian_available = 2 - @reset control[].model = 6 + @reset control[].jacobian_available = Cint(2) + @reset control[].hessian_available = Cint(2) + @reset control[].model = Cint(6) x = Float64[1.5, 1.5] # starting point W = Float64[1.0, 1.0, 1.0] # weights @@ -267,9 +167,9 @@ function test_nls() if d == 1 st = 'C' nls_import(control, data, status, n, m, - "coordinate", j_ne, J_row, J_col, Cint[], - "coordinate", h_ne, H_row, H_col, Cint[], - "sparse_by_columns", p_ne, P_row, Cint[], P_ptr, W) + "coordinate", j_ne, J_row, J_col, C_NULL, + "coordinate", h_ne, H_row, H_col, C_NULL, + "sparse_by_columns", p_ne, P_row, C_NULL, P_ptr, W) terminated = false while !terminated # reverse-communication loop nls_solve_reverse_with_mat(data, status, eval_status, @@ -297,9 +197,9 @@ function test_nls() if d == 2 st = 'R' nls_import(control, data, status, n, m, - "sparse_by_rows", j_ne, Cint[], J_col, J_ptr, - "sparse_by_rows", h_ne, Cint[], H_col, H_ptr, - "sparse_by_columns", p_ne, P_row, Cint[], P_ptr, W) + "sparse_by_rows", j_ne, C_NULL, J_col, J_ptr, + "sparse_by_rows", h_ne, C_NULL, H_col, H_ptr, + "sparse_by_columns", p_ne, P_row, C_NULL, P_ptr, W) terminated = false while !terminated # reverse-communication loop @@ -307,9 +207,9 @@ function test_nls() n, m, x, c, g, j_ne, J_val, y, h_ne, H_val, v, p_ne, P_val) if status[] == 0 # successful termination - terminated[] = true + terminated = true elseif status[] < 0 # error exit - terminated[] = true + terminated = true elseif status[] == 2 # evaluate c eval_status[] = res(n, m, x, c, userdata) elseif status[] == 3 # evaluate J @@ -328,9 +228,9 @@ function test_nls() if d == 3 st = 'D' nls_import(control, data, status, n, m, - "dense", j_ne, Cint[], Cint[], Cint[], - "dense", h_ne, Cint[], Cint[], Cint[], - "dense", p_ne, Cint[], Cint[], Cint[], W) + "dense", j_ne, C_NULL, C_NULL, C_NULL, + "dense", h_ne, C_NULL, C_NULL, C_NULL, + "dense", p_ne, C_NULL, C_NULL, C_NULL, W) terminated = false while !terminated # reverse-communication loop @@ -360,9 +260,9 @@ function test_nls() if d == 4 st = 'I' nls_import(control, data, status, n, m, - "sparse_by_rows", j_ne, Cint[], J_col, J_ptr, - "diagonal", h_ne, Cint[], Cint[], Cint[], - "sparse_by_columns", p_ne, P_row, Cint[], P_ptr, W) + "sparse_by_rows", j_ne, C_NULL, J_col, J_ptr, + "diagonal", h_ne, C_NULL, C_NULL, C_NULL, + "sparse_by_columns", p_ne, P_row, C_NULL, P_ptr, W) terminated = false while !terminated # reverse-communication loop @@ -392,14 +292,14 @@ function test_nls() st = 'P' # @reset control[].print_level = Cint(1) nls_import(control, data, status, n, m, - "absent", j_ne, Cint[], Cint[], Cint[], - "absent", h_ne, Cint[], Cint[], Cint[], - "sparse_by_columns", p_ne, P_row, Cint[], P_ptr, W) + "absent", j_ne, C_NULL, C_NULL, C_NULL, + "absent", h_ne, C_NULL, C_NULL, C_NULL, + "sparse_by_columns", p_ne, P_row, C_NULL, P_ptr, W) terminated = false while !terminated # reverse-communication loop nls_solve_reverse_without_mat(data, status, eval_status, - n, m, x, c, g, transpose, + n, m, x, c, g, trans, u, v, y, p_ne, P_val) if status[] == 0 # successful termination terminated = true @@ -408,7 +308,7 @@ function test_nls() elseif status[] == 2 # evaluate c eval_status[] = res(n, m, x, c, userdata) elseif status[] == 5 # evaluate u + J v or u + J'v - eval_status[] = jacprod(n, m, x, transpose, u, v, got_j, userdata) + eval_status[] = jacprod(n, m, x, trans[], u, v, got_j, userdata) elseif status[] == 6 # evaluate u + H v eval_status[] = hessprod(n, m, x, y, u, v, got_h, userdata) elseif status[] == 7 # evaluate P @@ -432,78 +332,6 @@ function test_nls() nls_terminate(data, control, inform) end - @printf("\n basic tests of models used, direct access\n\n") - for model in 3:8 - # Initialize NLS - nls_initialize(data, control, inform) - - # Set user-defined control options - @reset control[].f_indexing = true # Fortran sparse matrix indexing - # @reset control[].print_level = Cint(1) - @reset control[].jacobian_available = Cint(2) - @reset control[].hessian_available = Cint(2) - @reset control[].model = model - x = Float64[1.5, 1.5] # starting point - W = Float64[1.0, 1.0, 1.0] # weights - - nls_import(control, data, status, n, m, - "sparse_by_rows", j_ne, Cint[], J_col, J_ptr, - "sparse_by_rows", h_ne, Cint[], H_col, H_ptr, - "sparse_by_columns", p_ne, P_row, Cint[], P_ptr, W) - - nls_solve_with_mat(data, userdata, status, - n, m, x, c, g, res, j_ne, jac, - h_ne, hess, p_ne, rhessprods) - - nls_information(data, inform, status) - - if inform[].status == 0 - @printf(" %1i:%6i iterations. Optimal objective value = %5.2f status = %1i\n", - model, inform[].iter, inform[].obj, inform[].status) - else - @printf(" %i: NLS_solve exit status = %1i\n", model, inform[].status) - end - - # Delete internal workspace - nls_terminate(data, control, inform) - end - - @printf("\n basic tests of models used, access by products\n\n") - for model in 3:8 - # Initialize NLS - nls_initialize(data, control, inform) - - # Set user-defined control options - @reset control[].f_indexing = true # Fortran sparse matrix indexing - # @reset control[].print_level = Cint(1) - @reset control[].jacobian_available = Cint(2) - @reset control[].hessian_available = Cint(2) - @reset control[].model = model - x = Float64[1.5, 1.5] # starting point - W = Float64[1.0, 1.0, 1.0] # weights - - nls_import(control, data, status, n, m, - "absent", j_ne, Cint[], Cint[], Cint[], - "absent", h_ne, Cint[], Cint[], Cint[], - "sparse_by_columns", p_ne, P_row, Cint[], P_ptr, W) - - nls_solve_without_mat(data, userdata, status, - n, m, x, c, g, res, jacprod, - hessprod, p_ne, rhessprods) - - nls_information(data, inform, status) - - if inform[].status == 0 - @printf("P%1i:%6i iterations. Optimal objective value = %5.2f status = %1i\n", - model, inform[].iter, inform[].obj, inform[].status) - else - @printf("P%i: NLS_solve exit status = %1i\n", model, inform[].status) - end - - # Delete internal workspace - nls_terminate(data, control, inform) - end - @printf("\n basic tests of models used, reverse access\n\n") for model in 3:8 # Initialize NLS @@ -514,14 +342,14 @@ function test_nls() # @reset control[].print_level = Cint(1) @reset control[].jacobian_available = Cint(2) @reset control[].hessian_available = Cint(2) - @reset control[].model = model + @reset control[].model = Cint(model) x = Float64[1.5, 1.5] # starting point W = Float64[1.0, 1.0, 1.0] # weights nls_import(control, data, status, n, m, - "sparse_by_rows", j_ne, Cint[], J_col, J_ptr, - "sparse_by_rows", h_ne, Cint[], H_col, H_ptr, - "sparse_by_columns", p_ne, P_row, Cint[], P_ptr, W) + "sparse_by_rows", j_ne, C_NULL, J_col, J_ptr, + "sparse_by_rows", h_ne, C_NULL, H_col, H_ptr, + "sparse_by_columns", p_ne, P_row, C_NULL, P_ptr, W) terminated = false while !terminated # reverse-communication loop @@ -568,19 +396,19 @@ function test_nls() # @reset control[].print_level = 1 @reset control[].jacobian_available = Cint(2) @reset control[].hessian_available = Cint(2) - @reset control[].model = model + @reset control[].model = Cint(model) x = Float64[1.5, 1.5] # starting point W = Float64[1.0, 1.0, 1.0] # weights nls_import(control, data, status, n, m, - "absent", j_ne, Cint[], Cint[], Cint[], - "absent", h_ne, Cint[], Cint[], Cint[], - "sparse_by_columns", p_ne, P_row, Cint[], P_ptr, W) + "absent", j_ne, C_NULL, C_NULL, C_NULL, + "absent", h_ne, C_NULL, C_NULL, C_NULL, + "sparse_by_columns", p_ne, P_row, C_NULL, P_ptr, W) terminated = false while !terminated # reverse-communication loop nls_solve_reverse_without_mat(data, status, eval_status, - n, m, x, c, g, transpose, + n, m, x, c, g, trans, u, v, y, p_ne, P_val) if status[] == 0 # successful termination terminated = true @@ -589,7 +417,7 @@ function test_nls() elseif status[] == 2 # evaluate c eval_status[] = res(n, m, x, c, userdata) elseif status[] == 5 # evaluate u + J v or u + J'v - eval_status[] = jacprod(n, m, x, transpose, u, v, got_j, userdata) + eval_status[] = jacprod(n, m, x, trans[], u, v, got_j, userdata) elseif status[] == 6 # evaluate u + H v eval_status[] = hessprod(n, m, x, y, u, v, got_h, userdata) elseif status[] == 7 # evaluate P diff --git a/GALAHAD.jl/test/test_rqs.jl b/GALAHAD.jl/test/test_rqs.jl index 10a02e9b94..9546856a66 100644 --- a/GALAHAD.jl/test/test_rqs.jl +++ b/GALAHAD.jl/test/test_rqs.jl @@ -61,7 +61,6 @@ function test_rqs() end for storage_type in 1:4 - # Initialize RQS rqs_initialize(data, control, status) @@ -73,33 +72,33 @@ function test_rqs() st = 'C' # import the control parameters and structural data rqs_import(control, data, status, n, - "coordinate", H_ne, H_row, H_col, Cint[]) + "coordinate", H_ne, H_row, H_col, C_NULL) if m_is == 1 rqs_import_m(data, status, n, - "coordinate", M_ne, M_row, M_col, Cint[]) + "coordinate", M_ne, M_row, M_col, C_NULL) end if a_is == 1 rqs_import_a(data, status, m, - "coordinate", A_ne, A_row, A_col, Cint[]) + "coordinate", A_ne, A_row, A_col, C_NULL) end # solve the problem if (a_is == 1) && (m_is == 1) rqs_solve_problem(data, status, n, power, weight, f, c, H_ne, H_val, x, - M_ne, M_val, m, A_ne, A_val, Cint[]) + M_ne, M_val, m, A_ne, A_val, C_NULL) elseif a_is == 1 rqs_solve_problem(data, status, n, power, weight, f, c, H_ne, H_val, x, - 0, Cint[], m, A_ne, A_val, Cint[]) + 0, C_NULL, m, A_ne, A_val, C_NULL) elseif m_is == 1 rqs_solve_problem(data, status, n, power, weight, f, c, H_ne, H_val, x, - M_ne, M_val, 0, 0, Cint[], Cint[]) + M_ne, M_val, 0, 0, C_NULL, C_NULL) else rqs_solve_problem(data, status, n, power, weight, f, c, H_ne, H_val, x, - 0, Cint[], 0, 0, Cint[], Cint[]) + 0, C_NULL, 0, 0, C_NULL, C_NULL) end end @@ -108,33 +107,33 @@ function test_rqs() st = 'R' # import the control parameters and structural data rqs_import(control, data, status, n, - "sparse_by_rows", H_ne, Cint[], H_col, H_ptr) + "sparse_by_rows", H_ne, C_NULL, H_col, H_ptr) if m_is == 1 rqs_import_m(data, status, n, - "sparse_by_rows", M_ne, Cint[], M_col, M_ptr) + "sparse_by_rows", M_ne, C_NULL, M_col, M_ptr) end if a_is == 1 rqs_import_a(data, status, m, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) end # solve the problem if (a_is == 1) && (m_is == 1) rqs_solve_problem(data, status, n, power, weight, f, c, H_ne, H_val, x, - M_ne, M_val, m, A_ne, A_val, Cint[]) + M_ne, M_val, m, A_ne, A_val, C_NULL) elseif a_is == 1 rqs_solve_problem(data, status, n, power, weight, f, c, H_ne, H_val, x, - 0, Cint[], m, A_ne, A_val, Cint[]) + 0, C_NULL, m, A_ne, A_val, C_NULL) elseif m_is == 1 rqs_solve_problem(data, status, n, power, weight, f, c, H_ne, H_val, x, - M_ne, M_val, 0, 0, Cint[], Cint[]) + M_ne, M_val, 0, 0, C_NULL, C_NULL) else rqs_solve_problem(data, status, n, power, weight, f, c, H_ne, H_val, x, - 0, Cint[], 0, 0, Cint[], Cint[]) + 0, C_NULL, 0, 0, C_NULL, C_NULL) end end @@ -143,15 +142,14 @@ function test_rqs() st = 'D' # import the control parameters and structural data rqs_import(control, data, status, n, - "dense", H_ne, Cint[], Cint[], Cint[]) + "dense", H_ne, C_NULL, C_NULL, C_NULL) if m_is == 1 rqs_import_m(data, status, n, - "dense", M_ne, Cint[], Cint[], Cint[]) + "dense", M_ne, C_NULL, C_NULL, C_NULL) end - if a_is == 1 rqs_import_a(data, status, m, - "dense", A_ne, Cint[], Cint[], Cint[]) + "dense", A_ne, C_NULL, C_NULL, C_NULL) end # solve the problem @@ -159,19 +157,19 @@ function test_rqs() rqs_solve_problem(data, status, n, power, weight, f, c, H_dense_ne, H_dense, x, M_dense_ne, M_dense, m, A_ne, A_val, - Cint[]) + C_NULL) elseif a_is == 1 rqs_solve_problem(data, status, n, power, weight, f, c, H_dense_ne, H_dense, x, - 0, Cint[], m, A_ne, A_val, Cint[]) + 0, C_NULL, m, A_ne, A_val, C_NULL) elseif m_is == 1 rqs_solve_problem(data, status, n, power, weight, f, c, H_dense_ne, H_dense, x, - M_dense_ne, M_dense, 0, 0, Cint[], Cint[]) + M_dense_ne, M_dense, 0, 0, C_NULL, C_NULL) else rqs_solve_problem(data, status, n, power, weight, f, c, H_dense_ne, H_dense, x, - 0, Cint[], 0, 0, Cint[], Cint[]) + 0, C_NULL, 0, 0, C_NULL, C_NULL) end end @@ -180,33 +178,33 @@ function test_rqs() st = 'L' # import the control parameters and structural data rqs_import(control, data, status, n, - "diagonal", H_ne, Cint[], Cint[], Cint[]) + "diagonal", H_ne, C_NULL, C_NULL, C_NULL) if m_is == 1 rqs_import_m(data, status, n, - "diagonal", M_ne, Cint[], Cint[], Cint[]) + "diagonal", M_ne, C_NULL, C_NULL, C_NULL) end if a_is == 1 rqs_import_a(data, status, m, - "dense", A_ne, Cint[], Cint[], Cint[]) + "dense", A_ne, C_NULL, C_NULL, C_NULL) end # solve the problem if (a_is == 1) && (m_is == 1) rqs_solve_problem(data, status, n, power, weight, f, c, n, H_diag, x, - n, M_diag, m, A_ne, A_val, Cint[]) + n, M_diag, m, A_ne, A_val, C_NULL) elseif a_is == 1 rqs_solve_problem(data, status, n, power, weight, f, c, n, H_diag, x, - 0, Cint[], m, A_ne, A_val, Cint[]) + 0, C_NULL, m, A_ne, A_val, C_NULL) elseif m_is == 1 rqs_solve_problem(data, status, n, power, weight, f, c, n, H_diag, x, - n, M_diag, 0, 0, Cint[], Cint[]) + n, M_diag, 0, 0, C_NULL, C_NULL) else rqs_solve_problem(data, status, n, power, weight, f, c, n, H_diag, x, - 0, Cint[], 0, 0, Cint[], Cint[]) + 0, C_NULL, 0, 0, C_NULL, C_NULL) end end @@ -216,7 +214,7 @@ function test_rqs() inform[].status, inform[].obj_regularized) # @printf("x: ") - # for(int i = 0 i < n+m i++) + # for i in 1:n+m # @printf("%f ", x[i]) # end diff --git a/GALAHAD.jl/test/test_slls.jl b/GALAHAD.jl/test/test_slls.jl index 7c80d72de2..86109a3cb9 100644 --- a/GALAHAD.jl/test/test_slls.jl +++ b/GALAHAD.jl/test/test_slls.jl @@ -21,7 +21,6 @@ function prec(n::Int, var::Vector{Float64}, p::Vector{Float64}, userdata::userda end function test_slls() - pointer_prec = @cfunction(prec, Int, (Int, Vector{Float64}, Vector{Float64}, userdata_type)) # Derived types data = Ref{Ptr{Cvoid}}() @@ -32,6 +31,9 @@ function test_slls() userdata = userdata_type(1.0) pointer_userdata = pointer_from_objref(userdata) + # Pointer to call prec + pointer_prec = @cfunction(prec, Int, (Int, Vector{Float64}, Vector{Float64}, userdata_type)) + # Set problem data n = 10 # dimension o = n + 1 # number of residuals @@ -308,8 +310,8 @@ function test_slls() mask[nz_p[l]] = 0 end elseif status[] == 6 # evaluate p = sparse A^Tv - for l in nz_v_start:nz_v_end - i = nz_v[l] - 1 + for l in nz_v_start[]:nz_v_end[] + i = nz_v[l] p[i] = v[i] + v[n] end elseif status[] == 7 # evaluate p = P^{-}v diff --git a/GALAHAD.jl/test/test_trb.jl b/GALAHAD.jl/test/test_trb.jl index 69537dc725..3e0f4a74b1 100644 --- a/GALAHAD.jl/test/test_trb.jl +++ b/GALAHAD.jl/test/test_trb.jl @@ -19,173 +19,163 @@ function test_trb() return 0 end - # # Gradient of the objective - # int grad(n::Int, var::Vector{Float64}, g::Vector{Float64}, userdata::userdata_type) - # struct userdata_type *myuserdata = (struct userdata_type *) userdata - # real_wp_ p = myuserdata->p - - # g[0] = 2.0 * (x[0] + x[2] + p) - sin(x[0]) - # g[1] = 2.0 * (x[1] + x[2]) - # g[2] = 2.0 * (x[0] + x[2] + p) + 2.0 * (x[1] + x[2]) - # return 0 - # ] - - # # Hessian of the objective - # int hess(n::Int, n::Inte, var::Vector{Float64}, hval::Vector{Float64}, - # userdata::userdata_type) - # hval[0] = 2.0 - cos(x[0]) - # hval[1] = 2.0 - # hval[2] = 2.0 - # hval[3] = 2.0 - # hval[4] = 4.0 - # return 0 - # ] - - # # Dense Hessian - # int hess_dense(n::Int, n::Inte, var::Vector{Float64}, hval::Vector{Float64}, - # userdata::userdata_type) - # hval[0] = 2.0 - cos(x[0]) - # hval[1] = 0.0 - # hval[2] = 2.0 - # hval[3] = 2.0 - # hval[4] = 2.0 - # hval[5] = 4.0 - # return 0 - # ] - - # # Hessian-vector product - # int hessprod(n::Int, var::Vector{Float64}, u::Vector{Float64}, var::Vector{Float64}, - # bool got_h, userdata::userdata_type) - # u[0] = u[0] + 2.0 * (v[0] + v[2]) - cos(x[0]) * v[0] - # u[1] = u[1] + 2.0 * (v[1] + v[2]) - # u[2] = u[2] + 2.0 * (v[0] + v[1] + 2.0 * v[2]) - # return 0 - # ] - - # # Sparse Hessian-vector product - # int shessprod(n::Int, var::Vector{Float64}, n::Intnz_v, const int index_nz_v[], - # var::Vector{Float64}, int *nnz_u, int index_nz_u[], u::Vector{Float64}, - # bool got_h, userdata::userdata_type) - # real_wp_ p[] = {0., 0., 0.] - # bool used[] = {false, false, false] - # for(int i = 0 i < nnz_v i++) - # int j = index_nz_v[i] - # switch(j) - # case 1: - # p[0] = p[0] + 2.0 * v[0] - cos(x[0]) * v[0] - # used[0] = true - # p[2] = p[2] + 2.0 * v[0] - # used[2] = true - # end - # case 2: - # p[1] = p[1] + 2.0 * v[1] - # used[1] = true - # p[2] = p[2] + 2.0 * v[1] - # used[2] = true - # end - # case 3: - # p[0] = p[0] + 2.0 * v[2] - # used[0] = true - # p[1] = p[1] + 2.0 * v[2] - # used[1] = true - # p[2] = p[2] + 4.0 * v[2] - # used[2] = true - # end - # ] - # ] - # *nnz_u = 0 - # for(int j = 0 j < 3 j++) - # if used[j]) - # u[j] = p[j] - # *nnz_u = *nnz_u + 1 - # index_nz_u[*nnz_u-1] = j+1 - # ] - # ] - # return 0 - # ] - - # # Apply preconditioner - # int prec(n::Int, var::Vector{Float64}, u::Vector{Float64}, var::Vector{Float64}, - # userdata::userdata_type) - # u[0] = 0.5 * v[0] - # u[1] = 0.5 * v[1] - # u[2] = 0.25 * v[2] - # return 0 - # ] - - # # Objective function - # int fun_diag(n::Int, var::Vector{Float64}, real_wp_ *f, userdata::userdata_type) - # struct userdata_type *myuserdata = (struct userdata_type *) userdata - # real_wp_ p = myuserdata->p - - # *f = pow(x[2] + p, 2) + pow(x[1], 2) + cos(x[0]) - # return 0 - # ] - - # # Gradient of the objective - # int grad_diag(n::Int, var::Vector{Float64}, g::Vector{Float64}, userdata::userdata_type) - # struct userdata_type *myuserdata = (struct userdata_type *) userdata - # real_wp_ p = myuserdata->p - - # g[0] = -sin(x[0]) - # g[1] = 2.0 * x[1] - # g[2] = 2.0 * (x[2] + p) - # return 0 - # ] - - # # Hessian of the objective - # int hess_diag(n::Int, n::Inte, var::Vector{Float64}, hval::Vector{Float64}, - # userdata::userdata_type) - # hval[0] = -cos(x[0]) - # hval[1] = 2.0 - # hval[2] = 2.0 - # return 0 - # ] - - # # Hessian-vector product - # int hessprod_diag(n::Int, var::Vector{Float64}, u::Vector{Float64}, var::Vector{Float64}, - # bool got_h, userdata::userdata_type) - # u[0] = u[0] + - cos(x[0]) * v[0] - # u[1] = u[1] + 2.0 * v[1] - # u[2] = u[2] + 2.0 * v[2] - # return 0 - # ] - - # # Sparse Hessian-vector product - # int shessprod_diag(n::Int, var::Vector{Float64}, n::Intnz_v, - # const int index_nz_v[], - # var::Vector{Float64}, int *nnz_u, int index_nz_u[], - # u::Vector{Float64}, bool got_h, userdata::userdata_type) - # real_wp_ p[] = {0., 0., 0.] - # bool used[] = {false, false, false] - # for(int i = 0 i < nnz_v i++) - # int j = index_nz_v[i] - # switch(j) - # case 0: - # p[0] = p[0] - cos(x[0]) * v[0] - # used[0] = true - # end - # case 1: - # p[1] = p[1] + 2.0 * v[1] - # used[1] = true - # end - # case 2: - # p[2] = p[2] + 2.0 * v[2] - # used[2] = true - # end - # ] - # ] - # *nnz_u = 0 - # for(int j = 0 j < 3 j++) - # if used[j]) - # u[j] = p[j] - # *nnz_u = *nnz_u + 1 - # index_nz_u[*nnz_u-1] = j+1 - # ] - # ] - # return 0 - # ] - # end + # Gradient of the objective + function grad(n::Int, var::Vector{Float64}, g::Vector{Float64}, userdata::userdata_type) + p = userdata.p + g[1] = 2.0 * (x[1] + x[3] + p) - sin(x[1]) + g[2] = 2.0 * (x[2] + x[3]) + g[3] = 2.0 * (x[1] + x[3] + p) + 2.0 * (x[2] + x[3]) + return 0 + end + + # Hessian of the objective + function hess(n::Int, n::Int, var::Vector{Float64}, hval::Vector{Float64}, userdata::userdata_type) + p = userdata.p + hval[1] = 2.0 - cos(x[1]) + hval[2] = 2.0 + hval[3] = 2.0 + hval[4] = 2.0 + hval[5] = 4.0 + return 0 + end + + # Dense Hessian + function hess_dense(n::Int, n::Int, var::Vector{Float64}, hval::Vector{Float64}, userdata::userdata_type) + p = userdata.p + hval[1] = 2.0 - cos(x[1]) + hval[2] = 0.0 + hval[3] = 2.0 + hval[4] = 2.0 + hval[5] = 2.0 + hval[6] = 4.0 + return 0 + end + + # Hessian-vector product + function hessprod(n::Int, var::Vector{Float64}, u::Vector{Float64}, var::Vector{Float64}, got_h::Bool, userdata::userdata_type) + p = userdata.p + u[1] = u[1] + 2.0 * (v[1] + v[3]) - cos(x[1]) * v[1] + u[2] = u[2] + 2.0 * (v[2] + v[3]) + u[3] = u[3] + 2.0 * (v[1] + v[2] + 2.0 * v[3]) + return 0 + end + + # Sparse Hessian-vector product + function shessprod(n::Int, var::Vector{Float64}, nnz_v::Int, index_nz_v::Vector{Int}, v::Vector{Float64}, nnz_u::Ref{Int}, index_nz_u::Vector{Int}, u::Vector{Float64}, got_h::Bool, userdata::userdata_type) + p = zeros(Float64, 3) + used = falses(3) + for i in 1:nnz_v + j = index_nz_v[i] + if j == 1 + p[1] += 2.0 * v[i] - cos(var[1]) * v[i] + used[1] = true + p[3] += 2.0 * v[i] + used[3] = true + elseif j == 2 + p[2] += 2.0 * v[i] + used[2] = true + p[3] += 2.0 * v[i] + used[3] = true + elseif j == 3 + p[1] += 2.0 * v[i] + used[1] = true + p[2] += 2.0 * v[i] + used[2] = true + p[3] += 4.0 * v[i] + used[3] = true + end + end + + nnz_u[] = 0 + for j in 1:3 + if used[j] + u[j] = p[j] + nnz_u[] += 1 + index_nz_u[nnz_u[]] = j + end + end + return 0 + end + + # Apply preconditioner + function prec(n::Int, var::Vector{Float64}, u::Vector{Float64}, var::Vector{Float64}, userdata::userdata_type) + p = userdata.p + u[1] = 0.5 * v[1] + u[2] = 0.5 * v[2] + u[3] = 0.25 * v[3] + return 0 + end + + # Objective function + function fun_diag(n::Int, var::Vector{Float64}, f::Ref{Float64}, userdata::userdata_type) + p = userdata.p + f[] = (x[2] + p)^2 + x[1]^2 + cos(x[1]) + return 0 + end + + # Gradient of the objective + function grad_diag(n::Int, var::Vector{Float64}, g::Vector{Float64}, userdata::userdata_type) + p = userdata.p + g[1] = -sin(x[1]) + g[2] = 2.0 * x[2] + g[3] = 2.0 * (x[3] + p) + return 0 + end + + # Hessian of the objective + function hess_diag(n::Int, n::Int, var::Vector{Float64}, hval::Vector{Float64}, userdata::userdata_type) + p = userdata.p + hval[1] = -cos(x[1]) + hval[3] = 2.0 + hval[3] = 2.0 + return 0 + end + + # Hessian-vector product + function hessprod_diag(n::Int, var::Vector{Float64}, u::Vector{Float64}, var::Vector{Float64}, got_h::Bool, userdata::userdata_type) + p = userdata.p + u[1] = u[1] + - cos(x[1]) * v[1] + u[2] = u[2] + 2.0 * v[2] + u[3] = u[3] + 2.0 * v[3] + return 0 + end + + # Produit matrice-vecteur Hesseien creux + function shessprod_diag(n::Int, var::Vector{Float64}, nnz_v::Int, index_nz_v::Vector{Int}, u::Vector{Float64}, got_h::Bool, userdata::userdata_type) + p = zeros(3) + used = falses(3) + for i in 1:nnz_v + j = index_nz_v[i] + if j == 1 + p[1] += 2.0 * v[0] + p[3] += 2.0 * v[0] + used[1] = true + used[3] = true + elseif j == 2 + p[2] += 2.0 * v[1] + p[3] += 2.0 * v[1] + used[2] = true + used[3] = true + elseif j == 3 + p[1] += 2.0 * v[2] + p[2] += 2.0 * v[2] + p[3] += 4.0 * v[2] + used[1] = true + used[2] = true + used[3] = true + end + end + + nnz_u = 0 + for j in 1:3 + if used[j] + u[j] = p[j] + nnz_u += 1 + index_nz_u[nnz_u] = j + end + end + return 0 + end # Derived types data = Ref{Ptr{Cvoid}}() @@ -210,103 +200,13 @@ function test_trb() status = Ref{Cint}() @printf(" Fortran sparse matrix indexing\n\n") - @printf(" tests options for all-in-one storage format\n\n") - - for d in 1:5 - - # Initialize TRB - trb_initialize(data, control, status) - - # Set user-defined control options - @reset control[].f_indexing = true # Fortran sparse matrix indexing - # @reset control[].print_level = 1 - - # Start from 1.5 - x = Float64[1.5, 1.5, 1.5] - - # sparse co-ordinate storage - if d == 1 - st = 'C' - trb_import(control, data, status, n, x_l, x_u, - "coordinate", ne, H_row, H_col, Cint[]) - - trb_solve_with_mat(data, userdata, status, n, x, g, ne, - fun, grad, hess, prec) - end - - # sparse by rows - if d == 2 - st = 'R' - trb_import(control, data, status, n, x_l, x_u, - "sparse_by_rows", ne, Cint[], H_col, H_ptr) - - trb_solve_with_mat(data, userdata, status, n, x, g, ne, - fun, grad, hess, prec) - end - - # dense - if d == 3 - st = 'D' - trb_import(control, data, status, n, x_l, x_u, - "dense", ne, Cint[], Cint[], Cint[]) - - trb_solve_with_mat(data, userdata, status, n, x, g, ne, - fun, grad, hess_dense, prec) - end - - # diagonal - if d == 4 - st = 'I' - trb_import(control, data, status, n, x_l, x_u, - "diagonal", ne, Cint[], Cint[], Cint[]) - - trb_solve_with_mat(data, userdata, status, n, x, g, ne, - fun_diag, grad_diag, hess_diag, prec) - end - - # access by products - if d == 5 - st = 'P' - trb_import(control, data, status, n, x_l, x_u, - "absent", ne, Cint[], Cint[], Cint[]) - - trb_solve_without_mat(data, userdata, status, n, x, g, - fun, grad, hessprod, shessprod, prec) - end - - # Record solution information - trb_information(data, inform, status) - - # Print solution details - if inform[].status == 0 - @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", st, - inform[].iter, inform[].obj, inform[].status) - else - @printf("%c: TRB_solve exit status = %1i\n", st, inform[].status) - end - - # @printf("x: ") - # for i = 1:n - # @printf("%f ", x[i]) - # end - # @printf("\n") - # @printf("gradient: ") - # for i = 1:n - # @printf("%f ", g[i]) - # end - # @printf("\n") - - # Delete internal workspace - trb_terminate(data, control, inform) - end - - @printf("\n tests reverse-communication options\n\n") + @printf(" tests reverse-communication options\n\n") # reverse-communication input/output eval_status = Ref{Cint}() nnz_v = Ref{Cint}() nnz_u = Ref{Cint}() - f = 0.0 + f = Ref{Float64}(0.0) u = zeros(Float64, n) v = zeros(Float64, n) index_nz_u = zeros(Cint, n) @@ -316,7 +216,6 @@ function test_trb() H_diag = zeros(Float64, n) for d in 1:5 - # Initialize TRB trb_initialize(data, control, status) @@ -330,11 +229,11 @@ function test_trb() # sparse co-ordinate storage if d == 1 st = 'C' - trb_import(control, data, status, n, x_l, x_u, "coordinate", ne, H_row, H_col, Cint[]) + trb_import(control, data, status, n, x_l, x_u, "coordinate", ne, H_row, H_col, C_NULL) terminated = false while !terminated # reverse-communication loop - trb_solve_reverse_with_mat(data, status, eval_status, n, x, f, g, ne, H_val, u, v) + trb_solve_reverse_with_mat(data, status, eval_status, n, x, f[], g, ne, H_val, u, v) if status[] == 0 # successful termination terminated = true elseif status[] < 0 # error exit @@ -356,12 +255,11 @@ function test_trb() # sparse by rows if d == 2 st = 'R' - trb_import(control, data, status, n, x_l, x_u, "sparse_by_rows", ne, Cint[], H_col, - H_ptr) + trb_import(control, data, status, n, x_l, x_u, "sparse_by_rows", ne, C_NULL, H_col, H_ptr) terminated = false while !terminated # reverse-communication loop - trb_solve_reverse_with_mat(data, status, eval_status, n, x, f, g, ne, H_val, u, v) + trb_solve_reverse_with_mat(data, status, eval_status, n, x, f[], g, ne, H_val, u, v) if status[] == 0 # successful termination terminated = true elseif status[] < 0 # error exit @@ -384,12 +282,11 @@ function test_trb() if d == 3 st = 'D' trb_import(control, data, status, n, x_l, x_u, - "dense", ne, Cint[], Cint[], Cint[]) + "dense", ne, C_NULL, C_NULL, C_NULL) terminated = false while !terminated # reverse-communication loop - trb_solve_reverse_with_mat(data, status, eval_status, n, x, f, g, n * (n + 1) / 2, - H_dense, u, v) + trb_solve_reverse_with_mat(data, status, eval_status, n, x, f[], g, div(n*(n + 1), 2), H_dense, u, v) if status[] == 0 # successful termination terminated = true elseif status[] < 0 # error exit @@ -411,11 +308,11 @@ function test_trb() # diagonal if d == 4 st = 'I' - trb_import(control, data, status, n, x_l, x_u, "diagonal", ne, Cint[], Cint[], Cint[]) + trb_import(control, data, status, n, x_l, x_u, "diagonal", ne, C_NULL, C_NULL, C_NULL) terminated = false while !terminated # reverse-communication loop - trb_solve_reverse_with_mat(data, status, eval_status, n, x, f, g, n, H_diag, u, v) + trb_solve_reverse_with_mat(data, status, eval_status, n, x, f[], g, n, H_diag, u, v) if status[] == 0 # successful termination terminated = true elseif status[] < 0 # error exit @@ -437,13 +334,12 @@ function test_trb() # access by products if d == 5 st = 'P' - trb_import(control, data, status, n, x_l, x_u, "absent", ne, Cint[], Cint[], Cint[]) + trb_import(control, data, status, n, x_l, x_u, "absent", ne, C_NULL, C_NULL, C_NULL) nnz_u = 0 terminated = false while !terminated # reverse-communication loop - trb_solve_reverse_without_mat(data, status, eval_status, n, x, f, g, u, v, - index_nz_v, nnz_v, index_nz_u, nnz_u) + trb_solve_reverse_without_mat(data, status, eval_status, n, x, f[], g, u, v, index_nz_v, nnz_v, index_nz_u, nnz_u) if status[] == 0 # successful termination terminated = true elseif status[] < 0 # error exit diff --git a/GALAHAD.jl/test/test_tru.jl b/GALAHAD.jl/test/test_tru.jl index 85b1ac6ac0..cb11943beb 100644 --- a/GALAHAD.jl/test/test_tru.jl +++ b/GALAHAD.jl/test/test_tru.jl @@ -12,14 +12,14 @@ mutable struct userdata_type end # Objective function -function fun(n, x::Vector{Float64}, f::Ref{Float64}, userdata::userdata_type) +function fun(n::Int, x::Vector{Float64}, f::Ref{Float64}, userdata::userdata_type) p = userdata.p f[] = (x[1] + x[3] + p)^2 + (x[2] + x[3])^2 + cos(x[1]) return 0 end # Gradient of the objective -function grad(n, x::Vector{Float64}, g::Vector{Float64}, userdata::userdata_type) +function grad(n::Int, x::Vector{Float64}, g::Vector{Float64}, userdata::userdata_type) p = userdata.p g[1] = 2.0 * (x[1] + x[3] + p) - sin(x[1]) g[2] = 2.0 * (x[2] + x[3]) @@ -28,7 +28,7 @@ function grad(n, x::Vector{Float64}, g::Vector{Float64}, userdata::userdata_type end # Hessian of the objective -function hess(n, ne, x::Vector{Float64}, hval::Vector{Float64}, userdata::userdata_type) +function hess(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, userdata::userdata_type) hval[1] = 2.0 - cos(x[1]) hval[2] = 2.0 hval[3] = 2.0 @@ -38,8 +38,7 @@ function hess(n, ne, x::Vector{Float64}, hval::Vector{Float64}, userdata::userda end # Dense Hessian -function hess_dense(n, ne, x::Vector{Float64}, hval::Vector{Float64}, - userdata::userdata_type) +function hess_dense(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, userdata::userdata_type) hval[1] = 2.0 - cos(x[1]) hval[2] = 0.0 hval[3] = 2.0 @@ -50,8 +49,7 @@ function hess_dense(n, ne, x::Vector{Float64}, hval::Vector{Float64}, end # Hessian-vector product -function hessprod(n, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, - got_h::Bool, userdata::userdata_type) +function hessprod(n::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, got_h::Bool, userdata::userdata_type) u[1] = u[1] + 2.0 * (v[1] + v[3]) - cos(x[1]) * v[1] u[2] = u[2] + 2.0 * (v[2] + v[3]) u[3] = u[3] + 2.0 * (v[1] + v[2] + 2.0 * v[3]) @@ -59,8 +57,7 @@ function hessprod(n, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, end # Apply preconditioner -function prec(n, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, - userdata::userdata_type) +function prec(n::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, userdata::userdata_type) u[1] = 0.5 * v[1] u[2] = 0.5 * v[2] u[3] = 0.25 * v[3] @@ -68,14 +65,14 @@ function prec(n, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, end # Objective function -function fun_diag(n, x::Vector{Float64}, f::Ref{Float64}, userdata::userdata_type) +function fun_diag(n::Int, x::Vector{Float64}, f::Ref{Float64}, userdata::userdata_type) p = userdata.p f[] = (x[3] + p)^2 + x[2]^2 + cos(x[1]) return 0 end # Gradient of the objective -function grad_diag(n, x::Vector{Float64}, g::Vector{Float64}, userdata::userdata_type) +function grad_diag(n::Int, x::Vector{Float64}, g::Vector{Float64}, userdata::userdata_type) p = userdata.p g[1] = -sin(x[1]) g[2] = 2.0 * x[2] @@ -84,8 +81,7 @@ function grad_diag(n, x::Vector{Float64}, g::Vector{Float64}, userdata::userdata end # Hessian of the objective -function hess_diag(n, ne, x::Vector{Float64}, hval::Vector{Float64}, - userdata::userdata_type) +function hess_diag(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, userdata::userdata_type) hval[1] = -cos(x[1]) hval[2] = 2.0 hval[3] = 2.0 @@ -93,8 +89,7 @@ function hess_diag(n, ne, x::Vector{Float64}, hval::Vector{Float64}, end # Hessian-vector product -function hessprod_diag(n, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, - got_h::Bool, userdata::userdata_type) +function hessprod_diag(n::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, got_h::Bool, userdata::userdata_type) u[1] = u[1] + -cos(x[1]) * v[1] u[2] = u[2] + 2.0 * v[2] u[3] = u[3] + 2.0 * v[3] @@ -109,7 +104,6 @@ function test_tru() # Set user data userdata = userdata_type(4.0) - pointer_userdata = pointer_from_objref(userdata) # Set problem data n = 3 # dimension @@ -124,97 +118,11 @@ function test_tru() status = Ref{Cint}() @printf(" Fortran sparse matrix indexing\n\n") - @printf(" tests options for all-in-one storage format\n\n") + @printf(" tests reverse-communication options\n\n") - for d in 1:5 - # Initialize TRU - tru_initialize(data, control, status) - - # Set user-defined control options - @reset control[].f_indexing = true # Fortran sparse matrix indexing - # @reset control[].print_level = Cint(1) - - # Start from 1.5 - x = Float64[1.5, 1.5, 1.5] - - # sparse co-ordinate storage - if d == 1 - st = 'C' - tru_import(control, data, status, n, "coordinate", - ne, H_row, H_col, Cint[]) - - tru_solve_with_mat(data, pointer_userdata, status, - n, x, g, ne, fun, grad, hess, prec) - end - - # sparse by rows - if d == 2 - st = 'R' - tru_import(control, data, status, n, "sparse_by_rows", - ne, Cint[], H_col, H_ptr) - - tru_solve_with_mat(data, pointer_userdata, status, - n, x, g, ne, fun, grad, hess, prec) - end - - # dense - if d == 3 - st = 'D' - tru_import(control, data, status, n, "dense", - ne, Cint[], Cint[], Cint[]) - - tru_solve_with_mat(data, pointer_userdata, status, - n, x, g, ne, fun, grad, hess_dense, prec) - end - - # diagonal - if d == 4 - st = 'I' - tru_import(control, data, status, n, "diagonal", - ne, Cint[], Cint[], Cint[]) - - tru_solve_with_mat(data, pointer_userdata, status, n, x, g, - ne, fun_diag, grad_diag, hess_diag, prec) - end - - # access by products - if d == 5 - st = 'P' - tru_import(control, data, status, n, "absent", - ne, Cint[], Cint[], Cint[]) - - tru_solve_without_mat(data, pointer_userdata, status, - n, x, g, fun, grad, hessprod, prec) - end - - tru_information(data, inform, status) - - if inform[].status == 0 - @printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", - st, inform[].iter, inform[].obj, inform[].status) - else - @printf("%c: TRU_solve exit status = %1i\n", st, inform[].status) - end - - # @printf("x: ") - # for i = 1:n - # @printf("%f ", x[i]) - # end - # @printf("\n") - # @printf("gradient: ") - # for i = 1:n - # @printf("%f ", g[i]) - # end - # @printf("\n") - - # Delete internal workspace - tru_terminate(data, control, inform) - end - - @printf("\n tests reverse-communication options\n\n") # reverse-communication input/output eval_status = Ref{Cint}() - f = 0.0 + f = Ref{Float64}(0.0) u = zeros(Float64, n) v = zeros(Float64, n) index_nz_u = zeros(Cint, n) @@ -239,12 +147,11 @@ function test_tru() if d == 1 st = 'C' tru_import(control, data, status, n, "coordinate", - ne, H_row, H_col, Cint[]) + ne, H_row, H_col, C_NULL) terminated = false while !terminated # reverse-communication loop - tru_solve_reverse_with_mat(data, status, eval_status, - n, x, f, g, ne, H_val, u, v) + tru_solve_reverse_with_mat(data, status, eval_status, n, x, f[], g, ne, H_val, u, v) if status[] == 0 # successful termination terminated = true elseif status[] < 0 # error exit @@ -267,11 +174,11 @@ function test_tru() if d == 2 st = 'R' tru_import(control, data, status, n, "sparse_by_rows", ne, - Cint[], H_col, H_ptr) + C_NULL, H_col, H_ptr) terminated = false while !terminated # reverse-communication loop - tru_solve_reverse_with_mat(data, status, eval_status, n, x, f, g, ne, H_val, u, v) + tru_solve_reverse_with_mat(data, status, eval_status, n, x, f[], g, ne, H_val, u, v) if status[] == 0 # successful termination terminated = true elseif status[] < 0 # error exit @@ -294,12 +201,11 @@ function test_tru() if d == 3 st = 'D' tru_import(control, data, status, n, "dense", - ne, Cint[], Cint[], Cint[]) + ne, C_NULL, C_NULL, C_NULL) terminated = false while !terminated # reverse-communication loop - tru_solve_reverse_with_mat(data, status, eval_status, - n, x, f, g, n * (n + 1) / 2, H_dense, u, v) + tru_solve_reverse_with_mat(data, status, eval_status, n, x, f[], g, div(n*(n + 1), 2), H_dense, u, v) if status[] == 0 # successful termination terminated = true elseif status[] < 0 # error exit @@ -309,7 +215,7 @@ function test_tru() elseif status[] == 3 # evaluate g eval_status[] = grad(n, x, g, userdata) elseif status[] == 4 # evaluate H - eval_status[] = hess_dense(n, n * (n + 1) / 2, x, H_dense, userdata) + eval_status[] = hess_dense(n, div(n*(n + 1), 2), x, H_dense, userdata) elseif status[] == 6 # evaluate the product with P eval_status[] = prec(n, x, u, v, userdata) else @@ -321,12 +227,11 @@ function test_tru() # diagonal if d == 4 st = 'I' - tru_import(control, data, status, n, "diagonal", - ne, Cint[], Cint[], Cint[]) + tru_import(control, data, status, n, "diagonal", ne, C_NULL, C_NULL, C_NULL) terminated = false while !terminated # reverse-communication loop - tru_solve_reverse_with_mat(data, status, eval_status, n, x, f, g, n, H_diag, u, v) + tru_solve_reverse_with_mat(data, status, eval_status, n, x, f[], g, n, H_diag, u, v) if status[] == 0 # successful termination terminated = true elseif status[] < 0 # error exit @@ -349,12 +254,11 @@ function test_tru() if d == 5 st = 'P' tru_import(control, data, status, n, "absent", - ne, Cint[], Cint[], Cint[]) + ne, C_NULL, C_NULL, C_NULL) terminated = false while !terminated # reverse-communication loop - tru_solve_reverse_without_mat(data, status, eval_status, - n, x, f, g, u, v) + tru_solve_reverse_without_mat(data, status, eval_status, n, x, f[], g, u, v) if status[] == 0 # successful termination terminated = true elseif status[] < 0 # error exit From dfdc9e77ffcbf7acce873a9f434043b7f3b72f84 Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Tue, 13 Feb 2024 13:51:13 -0500 Subject: [PATCH 28/33] Clean examples --- GALAHAD.jl/test/test_arc.jl | 4 +- GALAHAD.jl/test/test_bgo.jl | 218 ++++++++++--------- GALAHAD.jl/test/test_blls.jl | 3 +- GALAHAD.jl/test/test_bllsb.jl | 10 +- GALAHAD.jl/test/test_bqp.jl | 2 +- GALAHAD.jl/test/test_ccqp.jl | 32 +-- GALAHAD.jl/test/test_clls.jl | 20 +- GALAHAD.jl/test/test_cqp.jl | 32 +-- GALAHAD.jl/test/test_dgo.jl | 20 +- GALAHAD.jl/test/test_dps.jl | 6 +- GALAHAD.jl/test/test_dqp.jl | 28 +-- GALAHAD.jl/test/test_eqp.jl | 32 +-- GALAHAD.jl/test/test_l2rt.jl | 4 +- GALAHAD.jl/test/test_llst.jl | 362 +++++++++++++++---------------- GALAHAD.jl/test/test_lpa.jl | 6 +- GALAHAD.jl/test/test_lpb.jl | 6 +- GALAHAD.jl/test/test_lsqp.jl | 6 +- GALAHAD.jl/test/test_nls.jl | 32 ++- GALAHAD.jl/test/test_presolve.jl | 28 +-- GALAHAD.jl/test/test_psls.jl | 6 +- GALAHAD.jl/test/test_qpa.jl | 36 +-- GALAHAD.jl/test/test_qpb.jl | 28 +-- GALAHAD.jl/test/test_sbls.jl | 56 ++--- GALAHAD.jl/test/test_slls.jl | 6 +- GALAHAD.jl/test/test_sls.jl | 6 +- GALAHAD.jl/test/test_trb.jl | 39 ++-- GALAHAD.jl/test/test_tru.jl | 23 +- GALAHAD.jl/test/test_uls.jl | 6 +- GALAHAD.jl/test/test_wcp.jl | 6 +- 29 files changed, 552 insertions(+), 511 deletions(-) diff --git a/GALAHAD.jl/test/test_arc.jl b/GALAHAD.jl/test/test_arc.jl index a8460c654e..38677f939d 100644 --- a/GALAHAD.jl/test/test_arc.jl +++ b/GALAHAD.jl/test/test_arc.jl @@ -205,7 +205,7 @@ function test_arc() terminated = false while !terminated # reverse-communication loop arc_solve_reverse_with_mat(data, status, eval_status, - n, x, f[], g, div(n*(n + 1), 2), H_dense, u, v) + n, x, f[], g, div(n * (n + 1), 2), H_dense, u, v) if status[] == 0 # successful termination terminated = true elseif status[] < 0 # error exit @@ -215,7 +215,7 @@ function test_arc() elseif status[] == 3 # evaluate g eval_status[] = grad(n, x, g, userdata) elseif status[] == 4 # evaluate H - eval_status[] = hess_dense(n, div(n*(n + 1), 2), x, H_dense, userdata) + eval_status[] = hess_dense(n, div(n * (n + 1), 2), x, H_dense, userdata) elseif status[] == 6 # evaluate the product with P eval_status[] = prec(n, x, u, v, userdata) else diff --git a/GALAHAD.jl/test/test_bgo.jl b/GALAHAD.jl/test/test_bgo.jl index 9d8c053201..c1bd07fa05 100644 --- a/GALAHAD.jl/test/test_bgo.jl +++ b/GALAHAD.jl/test/test_bgo.jl @@ -27,130 +27,136 @@ function test_bgo() # Gradient of the objective function grad(n::Int, var::Vector{Float64}, g::Vector{Float64}, userdata::userdata_type) - struct Cuserdata_type - p::Float64 - freq::Float64 - mag::Float64 - end - myuserdata = unsafe_load(Cuserdata_type, userdata) - p = myuserdata.p - freq = myuserdata.freq - mag = myuserdata.mag - - g[1] = 2.0 * (var[1] + var[3] + p) - mag * freq * sin(freq * var[1]) + 1.0 - g[2] = 2.0 * (var[2] + var[3]) + 1.0 - g[3] = 2.0 * (var[1] + var[3] + p) + 2.0 * (var[2] + var[3]) + 1.0 - return 0 + struct Cuserdata_type + p::Float64 + freq::Float64 + mag::Float64 + end + myuserdata = unsafe_load(Cuserdata_type, userdata) + p = myuserdata.p + freq = myuserdata.freq + mag = myuserdata.mag + + g[1] = 2.0 * (var[1] + var[3] + p) - mag * freq * sin(freq * var[1]) + 1.0 + g[2] = 2.0 * (var[2] + var[3]) + 1.0 + g[3] = 2.0 * (var[1] + var[3] + p) + 2.0 * (var[2] + var[3]) + 1.0 + return 0 end # Hessian of the objective - function hess(n::Int, ne::Int, var::Vector{Float64}, hval::Vector{Float64}, userdata::userdata_type) - struct Cuserdata_type - p::Float64 - freq::Float64 - mag::Float64 - end - myuserdata = unsafe_load(Cuserdata_type, userdata) - freq = myuserdata.freq - mag = myuserdata.mag - - hval[1] = 2.0 - mag * freq^2 * cos(freq * var[1]) - hval[2] = 2.0 - hval[3] = 2.0 - hval[4] = 4.0 - return 0 + function hess(n::Int, ne::Int, var::Vector{Float64}, hval::Vector{Float64}, + userdata::userdata_type) + struct Cuserdata_type + p::Float64 + freq::Float64 + mag::Float64 + end + myuserdata = unsafe_load(Cuserdata_type, userdata) + freq = myuserdata.freq + mag = myuserdata.mag + + hval[1] = 2.0 - mag * freq^2 * cos(freq * var[1]) + hval[2] = 2.0 + hval[3] = 2.0 + hval[4] = 4.0 + return 0 end # Dense Hessian - function hess_dense(n::Int, ne::Int, var::Vector{Float64}, hval::Vector{Float64}, userdata::userdata_type) - struct Cuserdata_type - p::Float64 - freq::Float64 - mag::Float64 - end - myuserdata = unsafe_load(Cuserdata_type, userdata) - freq = myuserdata.freq - mag = myuserdata.mag - - hval[1] = 2.0 - mag * freq^2 * cos(freq * var[1]) - hval[2] = 0.0 - hval[3] = 2.0 - hval[4] = 2.0 - hval[5] = 4.0 - return 0 + function hess_dense(n::Int, ne::Int, var::Vector{Float64}, hval::Vector{Float64}, + userdata::userdata_type) + struct Cuserdata_type + p::Float64 + freq::Float64 + mag::Float64 + end + myuserdata = unsafe_load(Cuserdata_type, userdata) + freq = myuserdata.freq + mag = myuserdata.mag + + hval[1] = 2.0 - mag * freq^2 * cos(freq * var[1]) + hval[2] = 0.0 + hval[3] = 2.0 + hval[4] = 2.0 + hval[5] = 4.0 + return 0 end # Hessian-vector product - function hessprod(n::Int, var::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, got_h::Bool, userdata::userdata_type) - struct Cuserdata_type - p::Float64 - freq::Float64 - mag::Float64 - end - myuserdata = unsafe_load(Cuserdata_type, userdata) - freq = myuserdata.freq - mag = myuserdata.mag - - u[1] = u[1] + 2.0 * (v[1] + v[3]) - mag * freq^2 * cos(freq * var[1]) * v[1] - u[2] = u[2] + 2.0 * (v[2] + v[3]) - u[3] = u[3] + 2.0 * (v[1] + v[2] + 2.0 * v[3]) - return 0 + function hessprod(n::Int, var::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, + got_h::Bool, userdata::userdata_type) + struct Cuserdata_type + p::Float64 + freq::Float64 + mag::Float64 + end + myuserdata = unsafe_load(Cuserdata_type, userdata) + freq = myuserdata.freq + mag = myuserdata.mag + + u[1] = u[1] + 2.0 * (v[1] + v[3]) - mag * freq^2 * cos(freq * var[1]) * v[1] + u[2] = u[2] + 2.0 * (v[2] + v[3]) + u[3] = u[3] + 2.0 * (v[1] + v[2] + 2.0 * v[3]) + return 0 end # Sparse Hessian-vector product - function shessprod(n::Int, var::Vector{Float64}, nnz_v::Int, index_nz_v::Vector{Int}, v::Vector{Float64}, - nnz_u::Ptr{Int}, index_nz_u::Vector{Int}, u::Vector{Float64}, got_h::Bool, userdata::userdata_type) - struct Cuserdata_type - p::Float64 - freq::Float64 - mag::Float64 - end - myuserdata = unsafe_load(Cuserdata_type, userdata) - freq = myuserdata.freq - mag = myuserdata.mag - - p = zeros(3) - used = [false, false, false] - for i in 1:nnz_v - j = index_nz_v[i] - if j == 1 - p[1] += 2.0 * v[1] - mag * freq^2 * cos(freq * var[1]) * v[1] - used[1] = true - p[3] += 2.0 * v[1] - used[3] = true - elseif j == 2 - p[2] += 2.0 * v[2] - used[2] = true - p[3] += 2.0 * v[2] - used[3] = true - elseif j == 3 - p[1] += 2.0 * v[3] - used[1] = true - p[2] += 2.0 * v[3] - used[2] = true - p[3] += 4.0 * v[3] - used[3] = true - end + function shessprod(n::Int, var::Vector{Float64}, nnz_v::Int, index_nz_v::Vector{Int}, + v::Vector{Float64}, + nnz_u::Ptr{Int}, index_nz_u::Vector{Int}, u::Vector{Float64}, + got_h::Bool, userdata::userdata_type) + struct Cuserdata_type + p::Float64 + freq::Float64 + mag::Float64 + end + myuserdata = unsafe_load(Cuserdata_type, userdata) + freq = myuserdata.freq + mag = myuserdata.mag + + p = zeros(3) + used = [false, false, false] + for i in 1:nnz_v + j = index_nz_v[i] + if j == 1 + p[1] += 2.0 * v[1] - mag * freq^2 * cos(freq * var[1]) * v[1] + used[1] = true + p[3] += 2.0 * v[1] + used[3] = true + elseif j == 2 + p[2] += 2.0 * v[2] + used[2] = true + p[3] += 2.0 * v[2] + used[3] = true + elseif j == 3 + p[1] += 2.0 * v[3] + used[1] = true + p[2] += 2.0 * v[3] + used[2] = true + p[3] += 4.0 * v[3] + used[3] = true end + end - nnz = 0 - for j in 1:3 - if used[j] - u[j] = p[j] - nnz += 1 - index_nz_u[nnz] = j - end + nnz = 0 + for j in 1:3 + if used[j] + u[j] = p[j] + nnz += 1 + index_nz_u[nnz] = j end - unsafe_store!(nnz_u, nnz) - return 0 + end + unsafe_store!(nnz_u, nnz) + return 0 end # Apply preconditioner - function prec(n::Int, var::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, userdata::userdata_type) - u[1] = 0.5 * v[1] - u[2] = 0.5 * v[2] - u[3] = 0.25 * v[3] - return 0 + function prec(n::Int, var::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, + userdata::userdata_type) + u[1] = 0.5 * v[1] + u[2] = 0.5 * v[2] + u[3] = 0.25 * v[3] + return 0 end # Derived types diff --git a/GALAHAD.jl/test/test_blls.jl b/GALAHAD.jl/test/test_blls.jl index cca6b8244e..98feca3e10 100644 --- a/GALAHAD.jl/test/test_blls.jl +++ b/GALAHAD.jl/test/test_blls.jl @@ -31,7 +31,8 @@ function test_blls() pointer_userdata = pointer_from_objref(userdata) # Pointer to call prec - pointer_prec = @cfunction(prec, Int, (Int, Vector{Float64}, Vector{Float64}, userdata_type)) + pointer_prec = @cfunction(prec, Int, + (Int, Vector{Float64}, Vector{Float64}, userdata_type)) # Set problem data n = 10 # dimension diff --git a/GALAHAD.jl/test/test_bllsb.jl b/GALAHAD.jl/test/test_bllsb.jl index 3c251b9602..64ccd65af1 100644 --- a/GALAHAD.jl/test/test_bllsb.jl +++ b/GALAHAD.jl/test/test_bllsb.jl @@ -54,7 +54,7 @@ function test_bllsb() Ao_val = Float64[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] # vals bllsb_import(control, data, status, n, o, - "coordinate", Ao_ne, Ao_row, Ao_col, 0, Cint[]) + "coordinate", Ao_ne, Ao_row, Ao_col, 0, C_NULL) bllsb_solve_blls(data, status, n, o, Ao_ne, Ao_val, b, sigma, x_l, x_u, x, r, z, x_stat, w) @@ -71,7 +71,7 @@ function test_bllsb() Ao_val = Float64[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] # vals bllsb_import(control, data, status, n, o, - "sparse_by_rows", Ao_ne, Cint[], Ao_col, + "sparse_by_rows", Ao_ne, C_NULL, Ao_col, Ao_ptr_ne, Ao_ptr) bllsb_solve_blls(data, status, n, o, Ao_ne, Ao_val, b, @@ -88,7 +88,7 @@ function test_bllsb() Ao_val = Float64[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] # vals bllsb_import(control, data, status, n, o, - "sparse_by_columns", Ao_ne, Ao_row, Cint[], + "sparse_by_columns", Ao_ne, Ao_row, C_NULL, Ao_ptr_ne, Ao_ptr) bllsb_solve_blls(data, status, n, o, Ao_ne, Ao_val, b, @@ -101,7 +101,7 @@ function test_bllsb() Ao_dense = Float64[1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0] bllsb_import(control, data, status, n, o, - "dense", Ao_ne, Cint[], Cint[], 0, Cint[]) + "dense", Ao_ne, C_NULL, C_NULL, 0, C_NULL) bllsb_solve_blls(data, status, n, o, Ao_ne, Ao_dense, b, sigma, x_l, x_u, x, r, z, x_stat, w) @@ -113,7 +113,7 @@ function test_bllsb() Ao_dense = Float64[1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0] bllsb_import(control, data, status, n, o, - "dense_by_columns", Ao_ne, Cint[], Cint[], 0, Cint[]) + "dense_by_columns", Ao_ne, C_NULL, C_NULL, 0, C_NULL) bllsb_solve_blls(data, status, n, o, Ao_ne, Ao_dense, b, sigma, x_l, x_u, x, r, z, x_stat, w) diff --git a/GALAHAD.jl/test/test_bqp.jl b/GALAHAD.jl/test/test_bqp.jl index f724161f2a..1cabc40ac9 100644 --- a/GALAHAD.jl/test/test_bqp.jl +++ b/GALAHAD.jl/test/test_bqp.jl @@ -206,7 +206,7 @@ function test_bqp() terminated = true elseif status[] == 2 # evaluate Hv prod[1] = 2.0 * v[1] + v[2] - for i in 2:n-1 + for i in 2:(n - 1) prod[i] = 2.0 * v[i] + v[i - 1] + v[i + 1] end prod[n] = 2.0 * v[n] + v[n - 1] diff --git a/GALAHAD.jl/test/test_ccqp.jl b/GALAHAD.jl/test/test_ccqp.jl index fcac1f6091..006257888a 100644 --- a/GALAHAD.jl/test/test_ccqp.jl +++ b/GALAHAD.jl/test/test_ccqp.jl @@ -58,8 +58,8 @@ function test_ccqp() if d == 1 st = 'C' ccqp_import(control, data, status, n, m, - "coordinate", H_ne, H_row, H_col, Cint[], - "coordinate", A_ne, A_row, A_col, Cint[]) + "coordinate", H_ne, H_row, H_col, C_NULL, + "coordinate", A_ne, A_row, A_col, C_NULL) ccqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, @@ -70,8 +70,8 @@ function test_ccqp() if d == 2 st = 'R' ccqp_import(control, data, status, n, m, - "sparse_by_rows", H_ne, Cint[], H_col, H_ptr, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + "sparse_by_rows", H_ne, C_NULL, H_col, H_ptr, + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) ccqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, @@ -87,8 +87,8 @@ function test_ccqp() A_dense = Float64[2.0, 1.0, 0.0, 0.0, 1.0, 1.0] ccqp_import(control, data, status, n, m, - "dense", H_ne, Cint[], Cint[], Cint[], - "dense", A_ne, Cint[], Cint[], Cint[]) + "dense", H_ne, C_NULL, C_NULL, C_NULL, + "dense", A_ne, C_NULL, C_NULL, C_NULL) ccqp_solve_qp(data, status, n, m, H_dense_ne, H_dense, g, f, A_dense_ne, A_dense, c_l, c_u, x_l, x_u, @@ -99,8 +99,8 @@ function test_ccqp() if d == 4 st = 'L' ccqp_import(control, data, status, n, m, - "diagonal", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + "diagonal", H_ne, C_NULL, C_NULL, C_NULL, + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) ccqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, @@ -111,8 +111,8 @@ function test_ccqp() if d == 5 st = 'S' ccqp_import(control, data, status, n, m, - "scaled_identity", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + "scaled_identity", H_ne, C_NULL, C_NULL, C_NULL, + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) ccqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, @@ -123,8 +123,8 @@ function test_ccqp() if d == 6 st = 'I' ccqp_import(control, data, status, n, m, - "identity", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + "identity", H_ne, C_NULL, C_NULL, C_NULL, + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) ccqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, @@ -135,8 +135,8 @@ function test_ccqp() if d == 7 st = 'Z' ccqp_import(control, data, status, n, m, - "zero", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + "zero", H_ne, C_NULL, C_NULL, C_NULL, + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) ccqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, @@ -190,8 +190,8 @@ function test_ccqp() if d == 1 st = 'W' ccqp_import(control, data, status, n, m, - "shifted_least_distance", H_ne, Cint[], Cint[], Cint[], - "coordinate", A_ne, A_row, A_col, Cint[]) + "shifted_least_distance", H_ne, C_NULL, C_NULL, C_NULL, + "coordinate", A_ne, A_row, A_col, C_NULL) ccqp_solve_sldqp(data, status, n, m, w, x_0, g, f, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, diff --git a/GALAHAD.jl/test/test_clls.jl b/GALAHAD.jl/test/test_clls.jl index 8bab23fcdf..f5dc6fc4a8 100644 --- a/GALAHAD.jl/test/test_clls.jl +++ b/GALAHAD.jl/test/test_clls.jl @@ -63,8 +63,8 @@ function test_clls() A_val = Float64[2.0, 1.0, 1.0, 1.0] # values clls_import(control, data, status, n, o, m, - "coordinate", Ao_ne, Ao_row, Ao_col, 0, Cint[], - "coordinate", A_ne, A_row, A_col, 0, Cint[]) + "coordinate", Ao_ne, Ao_row, Ao_col, 0, C_NULL, + "coordinate", A_ne, A_row, A_col, 0, C_NULL) clls_solve_clls(data, status, n, o, m, Ao_ne, Ao_val, b, sigma, A_ne, A_val, c_l, c_u, x_l, x_u, @@ -86,9 +86,9 @@ function test_clls() A_val = Float64[2.0, 1.0, 1.0, 1.0] # values clls_import(control, data, status, n, o, m, - "sparse_by_rows", Ao_ne, Cint[], Ao_col, + "sparse_by_rows", Ao_ne, C_NULL, Ao_col, Ao_ptr_ne, Ao_ptr, - "sparse_by_rows", A_ne, Cint[], A_col, + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr_ne, A_ptr) clls_solve_clls(data, status, n, o, m, Ao_ne, Ao_val, b, @@ -111,9 +111,9 @@ function test_clls() A_val = Float64[2.0, 1.0, 1.0, 1.0] # values clls_import(control, data, status, n, o, m, - "sparse_by_columns", Ao_ne, Ao_row, Cint[], + "sparse_by_columns", Ao_ne, Ao_row, C_NULL, Ao_ptr_ne, Ao_ptr, - "sparse_by_columns", A_ne, A_row, Cint[], + "sparse_by_columns", A_ne, A_row, C_NULL, A_ptr_ne, A_ptr) clls_solve_clls(data, status, n, o, m, Ao_ne, Ao_val, b, @@ -130,8 +130,8 @@ function test_clls() A_dense = Float64[2.0, 1.0, 0.0, 0.0, 1.0, 1.0] clls_import(control, data, status, n, o, m, - "dense", Ao_ne, Cint[], Cint[], 0, Cint[], - "dense", A_ne, Cint[], Cint[], 0, Cint[]) + "dense", Ao_ne, C_NULL, C_NULL, 0, C_NULL, + "dense", A_ne, C_NULL, C_NULL, 0, C_NULL) clls_solve_clls(data, status, n, o, m, Ao_ne, Ao_dense, b, sigma, A_ne, A_dense, c_l, c_u, x_l, x_u, @@ -147,8 +147,8 @@ function test_clls() A_dense = Float64[2.0, 0.0, 1.0, 1.0, 0.0, 1.0] clls_import(control, data, status, n, o, m, - "dense_by_columns", Ao_ne, Cint[], Cint[], 0, Cint[], - "dense_by_columns", A_ne, Cint[], Cint[], 0, Cint[]) + "dense_by_columns", Ao_ne, C_NULL, C_NULL, 0, C_NULL, + "dense_by_columns", A_ne, C_NULL, C_NULL, 0, C_NULL) clls_solve_clls(data, status, n, o, m, Ao_ne, Ao_dense, b, sigma, A_ne, A_dense, c_l, c_u, x_l, x_u, diff --git a/GALAHAD.jl/test/test_cqp.jl b/GALAHAD.jl/test/test_cqp.jl index 215489b237..59431b8585 100644 --- a/GALAHAD.jl/test/test_cqp.jl +++ b/GALAHAD.jl/test/test_cqp.jl @@ -58,8 +58,8 @@ function test_cqp() if d == 1 st = 'C' cqp_import(control, data, status, n, m, - "coordinate", H_ne, H_row, H_col, Cint[], - "coordinate", A_ne, A_row, A_col, Cint[]) + "coordinate", H_ne, H_row, H_col, C_NULL, + "coordinate", A_ne, A_row, A_col, C_NULL) cqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, @@ -70,8 +70,8 @@ function test_cqp() if d == 2 st = 'R' cqp_import(control, data, status, n, m, - "sparse_by_rows", H_ne, Cint[], H_col, H_ptr, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + "sparse_by_rows", H_ne, C_NULL, H_col, H_ptr, + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) cqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, @@ -86,8 +86,8 @@ function test_cqp() A_dense = Float64[2.0, 1.0, 0.0, 0.0, 1.0, 1.0] cqp_import(control, data, status, n, m, - "dense", H_ne, Cint[], Cint[], Cint[], - "dense", A_ne, Cint[], Cint[], Cint[]) + "dense", H_ne, C_NULL, C_NULL, C_NULL, + "dense", A_ne, C_NULL, C_NULL, C_NULL) cqp_solve_qp(data, status, n, m, H_dense_ne, H_dense, g, f, A_dense_ne, A_dense, c_l, c_u, x_l, x_u, @@ -98,8 +98,8 @@ function test_cqp() if d == 4 st = 'L' cqp_import(control, data, status, n, m, - "diagonal", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + "diagonal", H_ne, C_NULL, C_NULL, C_NULL, + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) cqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, @@ -110,8 +110,8 @@ function test_cqp() if d == 5 st = 'S' cqp_import(control, data, status, n, m, - "scaled_identity", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + "scaled_identity", H_ne, C_NULL, C_NULL, C_NULL, + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) cqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, @@ -122,8 +122,8 @@ function test_cqp() if d == 6 st = 'I' cqp_import(control, data, status, n, m, - "identity", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + "identity", H_ne, C_NULL, C_NULL, C_NULL, + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) cqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, @@ -134,8 +134,8 @@ function test_cqp() if d == 7 st = 'Z' cqp_import(control, data, status, n, m, - "zero", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + "zero", H_ne, C_NULL, C_NULL, C_NULL, + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) cqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, @@ -188,8 +188,8 @@ function test_cqp() if d == 1 st = 'W' cqp_import(control, data, status, n, m, - "shifted_least_distance", H_ne, Cint[], Cint[], Cint[], - "coordinate", A_ne, A_row, A_col, Cint[]) + "shifted_least_distance", H_ne, C_NULL, C_NULL, C_NULL, + "coordinate", A_ne, A_row, A_col, C_NULL) cqp_solve_sldqp(data, status, n, m, w, x_0, g, f, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, diff --git a/GALAHAD.jl/test/test_dgo.jl b/GALAHAD.jl/test/test_dgo.jl index 689eb7d1cc..b2c167968e 100644 --- a/GALAHAD.jl/test/test_dgo.jl +++ b/GALAHAD.jl/test/test_dgo.jl @@ -312,7 +312,7 @@ function test_dgo() if d == 1 st = 'C' dgo_import(control, data, status, n, x_l, x_u, - "coordinate", ne, H_row, H_col, Cint[]) + "coordinate", ne, H_row, H_col, C_NULL) dgo_solve_with_mat(data, userdata, status, n, x, g, ne, fun, grad, hess, hessprod, prec) @@ -322,7 +322,7 @@ function test_dgo() if d == 2 st = 'R' dgo_import(control, data, status, n, x_l, x_u, - "sparse_by_rows", ne, Cint[], H_col, H_ptr) + "sparse_by_rows", ne, C_NULL, H_col, H_ptr) dgo_solve_with_mat(data, userdata, status, n, x, g, ne, fun, grad, hess, hessprod, prec) @@ -332,7 +332,7 @@ function test_dgo() if d == 3 st = 'D' dgo_import(control, data, status, n, x_l, x_u, - "dense", ne, Cint[], Cint[], Cint[]) + "dense", ne, C_NULL, C_NULL, C_NULL) dgo_solve_with_mat(data, userdata, status, n, x, g, ne, fun, grad, hess_dense, hessprod, prec) @@ -342,7 +342,7 @@ function test_dgo() if d == 4 st = 'I' dgo_import(control, data, status, n, x_l, x_u, - "diagonal", ne, Cint[], Cint[], Cint[]) + "diagonal", ne, C_NULL, C_NULL, C_NULL) dgo_solve_with_mat(data, userdata, status, n, x, g, ne, fun_diag, grad_diag, hess_diag, @@ -353,7 +353,7 @@ function test_dgo() if d == 5 st = 'P' dgo_import(control, data, status, n, x_l, x_u, - "absent", ne, Cint[], Cint[], Cint[]) + "absent", ne, C_NULL, C_NULL, C_NULL) dgo_solve_without_mat(data, userdata, status, n, x, g, fun, grad, hessprod, shessprod, prec) @@ -416,7 +416,7 @@ function test_dgo() # sparse co-ordinate storage if d == 1 st = 'C' - dgo_import(control, data, status, n, x_l, x_u, "coordinate", ne, H_row, H_col, Cint[]) + dgo_import(control, data, status, n, x_l, x_u, "coordinate", ne, H_row, H_col, C_NULL) terminated = false while !terminated # reverse-communication loop @@ -458,7 +458,7 @@ function test_dgo() if d == 2 st = 'R' dgo_import(control, data, status, n, x_l, x_u, - "sparse_by_rows", ne, Cint[], H_col, H_ptr) + "sparse_by_rows", ne, C_NULL, H_col, H_ptr) terminated = false while !terminated # reverse-communication loop @@ -501,7 +501,7 @@ function test_dgo() if d == 3 st = 'D' dgo_import(control, data, status, n, x_l, x_u, - "dense", ne, Cint[], Cint[], Cint[]) + "dense", ne, C_NULL, C_NULL, C_NULL) terminated = false while !terminated # reverse-communication loop @@ -546,7 +546,7 @@ function test_dgo() if d == 4 st = 'I' dgo_import(control, data, status, n, x_l, x_u, - "diagonal", ne, Cint[], Cint[], Cint[]) + "diagonal", ne, C_NULL, C_NULL, C_NULL) terminated = false while !terminated # reverse-communication loop @@ -593,7 +593,7 @@ function test_dgo() if d == 5 st = 'P' dgo_import(control, data, status, n, x_l, x_u, - "absent", ne, Cint[], Cint[], Cint[]) + "absent", ne, C_NULL, C_NULL, C_NULL) nnz_u = 0 terminated = false diff --git a/GALAHAD.jl/test/test_dps.jl b/GALAHAD.jl/test/test_dps.jl index f4cd8b6925..ec513995da 100644 --- a/GALAHAD.jl/test/test_dps.jl +++ b/GALAHAD.jl/test/test_dps.jl @@ -47,7 +47,7 @@ function test_dps() st = 'C' # import the control parameters and structural data dps_import(control, data, status, n, - "coordinate", H_ne, H_row, H_col, Cint[]) + "coordinate", H_ne, H_row, H_col, C_NULL) # solve the problem dps_solve_tr_problem(data, status, n, H_ne, H_val, @@ -59,7 +59,7 @@ function test_dps() st = 'R' # import the control parameters and structural data dps_import(control, data, status, n, - "sparse_by_rows", H_ne, Cint[], H_col, H_ptr) + "sparse_by_rows", H_ne, C_NULL, H_col, H_ptr) dps_solve_tr_problem(data, status, n, H_ne, H_val, c, f, radius, x) @@ -70,7 +70,7 @@ function test_dps() st = 'D' # import the control parameters and structural data dps_import(control, data, status, n, - "dense", H_ne, Cint[], Cint[], Cint[]) + "dense", H_ne, C_NULL, C_NULL, C_NULL) dps_solve_tr_problem(data, status, n, H_dense_ne, H_dense, c, f, radius, x) diff --git a/GALAHAD.jl/test/test_dqp.jl b/GALAHAD.jl/test/test_dqp.jl index 978239df7c..527bb3c0b7 100644 --- a/GALAHAD.jl/test/test_dqp.jl +++ b/GALAHAD.jl/test/test_dqp.jl @@ -59,8 +59,8 @@ function test_dqp() if d == 1 st = 'C' dqp_import(control, data, status, n, m, - "coordinate", H_ne, H_row, H_col, Cint[], - "coordinate", A_ne, A_row, A_col, Cint[]) + "coordinate", H_ne, H_row, H_col, C_NULL, + "coordinate", A_ne, A_row, A_col, C_NULL) dqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, @@ -71,8 +71,8 @@ function test_dqp() if d == 2 st = 'R' dqp_import(control, data, status, n, m, - "sparse_by_rows", H_ne, Cint[], H_col, H_ptr, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + "sparse_by_rows", H_ne, C_NULL, H_col, H_ptr, + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) dqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, @@ -88,8 +88,8 @@ function test_dqp() A_dense = Float64[2.0, 1.0, 0.0, 0.0, 1.0, 1.0] dqp_import(control, data, status, n, m, - "dense", H_ne, Cint[], Cint[], Cint[], - "dense", A_ne, Cint[], Cint[], Cint[]) + "dense", H_ne, C_NULL, C_NULL, C_NULL, + "dense", A_ne, C_NULL, C_NULL, C_NULL) dqp_solve_qp(data, status, n, m, H_dense_ne, H_dense, g, f, A_dense_ne, A_dense, c_l, c_u, x_l, x_u, @@ -100,8 +100,8 @@ function test_dqp() if d == 4 st = 'L' dqp_import(control, data, status, n, m, - "diagonal", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + "diagonal", H_ne, C_NULL, C_NULL, C_NULL, + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) dqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, @@ -112,8 +112,8 @@ function test_dqp() if d == 5 st = 'S' dqp_import(control, data, status, n, m, - "scaled_identity", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + "scaled_identity", H_ne, C_NULL, C_NULL, C_NULL, + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) dqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, @@ -124,8 +124,8 @@ function test_dqp() if d == 6 st = 'I' dqp_import(control, data, status, n, m, - "identity", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + "identity", H_ne, C_NULL, C_NULL, C_NULL, + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) dqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, @@ -179,8 +179,8 @@ function test_dqp() if d == 1 st = 'W' dqp_import(control, data, status, n, m, - "shifted_least_distance", H_ne, Cint[], Cint[], Cint[], - "coordinate", A_ne, A_row, A_col, Cint[]) + "shifted_least_distance", H_ne, C_NULL, C_NULL, C_NULL, + "coordinate", A_ne, A_row, A_col, C_NULL) dqp_solve_sldqp(data, status, n, m, w, x_0, g, f, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, diff --git a/GALAHAD.jl/test/test_eqp.jl b/GALAHAD.jl/test/test_eqp.jl index 3c2c79fe21..ca20c156c8 100644 --- a/GALAHAD.jl/test/test_eqp.jl +++ b/GALAHAD.jl/test/test_eqp.jl @@ -58,8 +58,8 @@ function test_eqp() if d == 1 st = 'C' eqp_import(control, data, status, n, m, - "coordinate", H_ne, H_row, H_col, Cint[], - "coordinate", A_ne, A_row, A_col, Cint[]) + "coordinate", H_ne, H_row, H_col, C_NULL, + "coordinate", A_ne, A_row, A_col, C_NULL) eqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, A_ne, A_val, c, x, y) @@ -69,8 +69,8 @@ function test_eqp() if d == 2 st = 'R' eqp_import(control, data, status, n, m, - "sparse_by_rows", H_ne, Cint[], H_col, H_ptr, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + "sparse_by_rows", H_ne, C_NULL, H_col, H_ptr, + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) eqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, A_ne, A_val, c, x, y) @@ -85,8 +85,8 @@ function test_eqp() A_dense = Float64[2.0, 1.0, 0.0, 0.0, 1.0, 1.0] eqp_import(control, data, status, n, m, - "dense", H_ne, Cint[], Cint[], Cint[], - "dense", A_ne, Cint[], Cint[], Cint[]) + "dense", H_ne, C_NULL, C_NULL, C_NULL, + "dense", A_ne, C_NULL, C_NULL, C_NULL) eqp_solve_qp(data, status, n, m, H_dense_ne, H_dense, g, f, A_dense_ne, A_dense, c, x, y) @@ -96,8 +96,8 @@ function test_eqp() if d == 4 st = 'L' eqp_import(control, data, status, n, m, - "diagonal", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + "diagonal", H_ne, C_NULL, C_NULL, C_NULL, + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) eqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, A_ne, A_val, c, x, y) @@ -107,8 +107,8 @@ function test_eqp() if d == 5 st = 'S' eqp_import(control, data, status, n, m, - "scaled_identity", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + "scaled_identity", H_ne, C_NULL, C_NULL, C_NULL, + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) eqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, A_ne, A_val, c, x, y) @@ -118,8 +118,8 @@ function test_eqp() if d == 6 st = 'I' eqp_import(control, data, status, n, m, - "identity", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + "identity", H_ne, C_NULL, C_NULL, C_NULL, + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) eqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, A_ne, A_val, c, x, y) @@ -129,8 +129,8 @@ function test_eqp() if d == 7 st = 'Z' eqp_import(control, data, status, n, m, - "zero", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + "zero", H_ne, C_NULL, C_NULL, C_NULL, + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) eqp_solve_qp(data, status, n, m, H_ne, H_val, g, f, A_ne, A_val, c, x, y) @@ -187,8 +187,8 @@ function test_eqp() if d == 1 st = 'W' eqp_import(control, data, status, n, m, - "shifted_least_distance", H_ne, Cint[], Cint[], Cint[], - "coordinate", A_ne, A_row, A_col, Cint[]) + "shifted_least_distance", H_ne, C_NULL, C_NULL, C_NULL, + "coordinate", A_ne, A_row, A_col, C_NULL) eqp_solve_sldqp(data, status, n, m, w, x_0, g, f, A_ne, A_val, c, x, y) diff --git a/GALAHAD.jl/test/test_l2rt.jl b/GALAHAD.jl/test/test_l2rt.jl index 0131b9f36d..a17b188994 100644 --- a/GALAHAD.jl/test/test_l2rt.jl +++ b/GALAHAD.jl/test/test_l2rt.jl @@ -46,11 +46,11 @@ function test_l2rt() elseif status[] == 2 # form u <- u + A * v for i in 1:n u[i] = u[i] + v[i] - u[n + i] = u[n+i] + i * v[i] + u[n + i] = u[n + i] + i * v[i] end elseif status[] == 3 # form v <- v + A^T * u for i in 1:n - v[i] = v[i] + u[i] + i * u[n+i] + v[i] = v[i] + u[i] + i * u[n + i] end elseif status[] == 4 # restart for i in 1:m diff --git a/GALAHAD.jl/test/test_llst.jl b/GALAHAD.jl/test/test_llst.jl index bdff9cb419..dee68a0b55 100644 --- a/GALAHAD.jl/test/test_llst.jl +++ b/GALAHAD.jl/test/test_llst.jl @@ -7,202 +7,202 @@ using Printf using Accessors #function test_llst() - # Derived types - data = Ref{Ptr{Cvoid}}() - global control = Ref{llst_control_type{Float64}}() - inform = Ref{llst_inform_type{Float64}}() - - # Set problem data - # set dimensions - m = 100 - n = 2 * m + 1 - # A = (I : Diag(1:n) : e) - A_ne = 3 * m - A_row = zeros(Cint, A_ne) - A_col = zeros(Cint, A_ne) - A_ptr = zeros(Cint, m + 1) - A_val = zeros(Float64, A_ne) - - # store A in sparse formats - global l = 1 - for i in 1:m - A_ptr[i] = l - A_row[l] = i - A_col[l] = i - A_val[l] = 1.0 - global l = l + 1 - A_row[l] = i - A_col[l] = m + i - A_val[l] = i - global l = l + 1 - A_row[l] = i - A_col[l] = n - A_val[l] = 1.0 - global l = l + 1 - end - A_ptr[m+1] = l - - # store A in dense format - A_dense_ne = m * n - A_dense_val = zeros(Float64, A_dense_ne) - global l = 0 - for i in 1:m - A_dense_val[l + i] = 1.0 - A_dense_val[l + m + i] = i - A_dense_val[l + n] = 1.0 - global l = l + n - end - - # S = diag(1:n)**2 - S_ne = n - S_row = zeros(Cint, S_ne) - S_col = zeros(Cint, S_ne) - S_ptr = zeros(Cint, n + 1) - S_val = zeros(Float64, S_ne) - - # store S in sparse formats - for i in 1:n - S_row[i] = i - S_col[i] = i - S_ptr[i] = i - S_val[i] = i * i - end - S_ptr[n+1] = n + 1 - - # store S in dense format - S_dense_ne = div(n * (n + 1), 2) - S_dense_val = zeros(Float64, S_dense_ne) - global l = 0 - for i in 1:n - S_dense_val[l + i] = i * i - global l = l + i - end +# Derived types +data = Ref{Ptr{Cvoid}}() +global control = Ref{llst_control_type{Float64}}() +inform = Ref{llst_inform_type{Float64}}() + +# Set problem data +# set dimensions +m = 100 +n = 2 * m + 1 +# A = (I : Diag(1:n) : e) +A_ne = 3 * m +A_row = zeros(Cint, A_ne) +A_col = zeros(Cint, A_ne) +A_ptr = zeros(Cint, m + 1) +A_val = zeros(Float64, A_ne) + +# store A in sparse formats +global l = 1 +for i in 1:m + A_ptr[i] = l + A_row[l] = i + A_col[l] = i + A_val[l] = 1.0 + global l = l + 1 + A_row[l] = i + A_col[l] = m + i + A_val[l] = i + global l = l + 1 + A_row[l] = i + A_col[l] = n + A_val[l] = 1.0 + global l = l + 1 +end +A_ptr[m + 1] = l + +# store A in dense format +A_dense_ne = m * n +A_dense_val = zeros(Float64, A_dense_ne) +global l = 0 +for i in 1:m + A_dense_val[l + i] = 1.0 + A_dense_val[l + m + i] = i + A_dense_val[l + n] = 1.0 + global l = l + n +end + +# S = diag(1:n)**2 +S_ne = n +S_row = zeros(Cint, S_ne) +S_col = zeros(Cint, S_ne) +S_ptr = zeros(Cint, n + 1) +S_val = zeros(Float64, S_ne) + +# store S in sparse formats +for i in 1:n + S_row[i] = i + S_col[i] = i + S_ptr[i] = i + S_val[i] = i * i +end +S_ptr[n + 1] = n + 1 + +# store S in dense format +S_dense_ne = div(n * (n + 1), 2) +S_dense_val = zeros(Float64, S_dense_ne) +global l = 0 +for i in 1:n + S_dense_val[l + i] = i * i + global l = l + i +end + +# b is a vector of ones +b = ones(Float64, m) # observations + +# trust-region radius is one +radius = 1.0 + +# Set output storage +x = zeros(Float64, n) # solution +global st = ' ' +status = Ref{Cint}() + +@printf(" Fortran sparse matrix indexing\n\n") +@printf(" basic tests of problem storage formats\n\n") + +# loop over storage formats +for d in 1:4 + + # Initialize LLST + llst_initialize(data, control, status) + global @reset control[].definite_linear_solver = galahad_linear_solver("potr") + global @reset control[].sbls_control.symmetric_linear_solver = galahad_linear_solver("sytr") + global @reset control[].sbls_control.definite_linear_solver = galahad_linear_solver("potr") + # @reset control[].print_level = Cint(1) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + + # use s or not (1 or 0) + for use_s in 0:1 + # sparse co-ordinate storage + if d == 1 + global st = 'C' + llst_import(control, data, status, m, n, + "coordinate", A_ne, A_row, A_col, C_NULL) + + if use_s == 0 + llst_solve_problem(data, status, m, n, radius, + A_ne, A_val, b, x, 0, C_NULL) + else + llst_import_scaling(control, data, status, n, + "coordinate", S_ne, S_row, + S_col, C_NULL) - # b is a vector of ones - b = ones(Float64, m) # observations - - # trust-region radius is one - radius = 1.0 - - # Set output storage - x = zeros(Float64, n) # solution - global st = ' ' - status = Ref{Cint}() - - @printf(" Fortran sparse matrix indexing\n\n") - @printf(" basic tests of problem storage formats\n\n") - - # loop over storage formats - for d in 1:4 - - # Initialize LLST - llst_initialize(data, control, status) - global @reset control[].definite_linear_solver = galahad_linear_solver("potr") - global @reset control[].sbls_control.symmetric_linear_solver = galahad_linear_solver("sytr") - global @reset control[].sbls_control.definite_linear_solver = galahad_linear_solver("potr") - # @reset control[].print_level = Cint(1) - - # Set user-defined control options - @reset control[].f_indexing = true # Fortran sparse matrix indexing - - # use s or not (1 or 0) - for use_s in 0:1 - # sparse co-ordinate storage - if d == 1 - global st = 'C' - llst_import(control, data, status, m, n, - "coordinate", A_ne, A_row, A_col, C_NULL) - - if use_s == 0 - llst_solve_problem(data, status, m, n, radius, - A_ne, A_val, b, x, 0, C_NULL) - else - llst_import_scaling(control, data, status, n, - "coordinate", S_ne, S_row, - S_col, C_NULL) - - llst_solve_problem(data, status, m, n, radius, - A_ne, A_val, b, x, S_ne, S_val) - end + llst_solve_problem(data, status, m, n, radius, + A_ne, A_val, b, x, S_ne, S_val) end + end - # sparse by rows - if d == 2 - global st = 'R' - llst_import(control, data, status, m, n, - "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) - if use_s == 0 - llst_solve_problem(data, status, m, n, radius, - A_ne, A_val, b, x, 0, C_NULL) - else - llst_import_scaling(control, data, status, n, - "sparse_by_rows", S_ne, C_NULL, - S_col, S_ptr) - - llst_solve_problem(data, status, m, n, radius, - A_ne, A_val, b, x, S_ne, S_val) - end - end + # sparse by rows + if d == 2 + global st = 'R' + llst_import(control, data, status, m, n, + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) + if use_s == 0 + llst_solve_problem(data, status, m, n, radius, + A_ne, A_val, b, x, 0, C_NULL) + else + llst_import_scaling(control, data, status, n, + "sparse_by_rows", S_ne, C_NULL, + S_col, S_ptr) - # dense - if d == 3 - global st = 'D' - llst_import(control, data, status, m, n, - "dense", A_dense_ne, C_NULL, C_NULL, C_NULL) - - if use_s == 0 - llst_solve_problem(data, status, m, n, radius, - A_dense_ne, A_dense_val, b, x, - 0, C_NULL) - else - llst_import_scaling(control, data, status, n, - "dense", S_dense_ne, - C_NULL, C_NULL, C_NULL) - - llst_solve_problem(data, status, m, n, radius, - A_dense_ne, A_dense_val, b, x, - S_dense_ne, S_dense_val) - end + llst_solve_problem(data, status, m, n, radius, + A_ne, A_val, b, x, S_ne, S_val) end + end - # diagonal - if d == 4 - global st = 'I' - llst_import(control, data, status, m, n, - "coordinate", A_ne, A_row, A_col, C_NULL) - if use_s == 0 - llst_solve_problem(data, status, m, n, radius, - A_ne, A_val, b, x, 0, C_NULL) - else - llst_import_scaling(control, data, status, n, - "diagonal", S_ne, C_NULL, C_NULL, C_NULL) - - llst_solve_problem(data, status, m, n, radius, - A_ne, A_val, b, x, S_ne, S_val) - end - end + # dense + if d == 3 + global st = 'D' + llst_import(control, data, status, m, n, + "dense", A_dense_ne, C_NULL, C_NULL, C_NULL) + + if use_s == 0 + llst_solve_problem(data, status, m, n, radius, + A_dense_ne, A_dense_val, b, x, + 0, C_NULL) + else + llst_import_scaling(control, data, status, n, + "dense", S_dense_ne, + C_NULL, C_NULL, C_NULL) - llst_information(data, inform, status) + llst_solve_problem(data, status, m, n, radius, + A_dense_ne, A_dense_val, b, x, + S_dense_ne, S_dense_val) + end + end - if inform[].status == 0 - @printf("storage type %c%1i: status = %1i, ||r|| = %5.2f\n", st, use_s, - inform[].status, inform[].r_norm) + # diagonal + if d == 4 + global st = 'I' + llst_import(control, data, status, m, n, + "coordinate", A_ne, A_row, A_col, C_NULL) + if use_s == 0 + llst_solve_problem(data, status, m, n, radius, + A_ne, A_val, b, x, 0, C_NULL) else - @printf("storage type %c%1i: LLST_solve exit status = %1i\n", st, use_s, - inform[].status) + llst_import_scaling(control, data, status, n, + "diagonal", S_ne, C_NULL, C_NULL, C_NULL) + + llst_solve_problem(data, status, m, n, radius, + A_ne, A_val, b, x, S_ne, S_val) end end - # @printf("x: ") - # for i = 1:n - # @printf("%f ", x[i]) - # end - # @printf("\n") + llst_information(data, inform, status) - # Delete internal workspace - llst_terminate(data, control, inform) + if inform[].status == 0 + @printf("storage type %c%1i: status = %1i, ||r|| = %5.2f\n", st, use_s, + inform[].status, inform[].r_norm) + else + @printf("storage type %c%1i: LLST_solve exit status = %1i\n", st, use_s, + inform[].status) + end end + # @printf("x: ") + # for i = 1:n + # @printf("%f ", x[i]) + # end + # @printf("\n") + + # Delete internal workspace + llst_terminate(data, control, inform) +end + # return 0 # end diff --git a/GALAHAD.jl/test/test_lpa.jl b/GALAHAD.jl/test/test_lpa.jl index 93b012bc1f..59a26efd86 100644 --- a/GALAHAD.jl/test/test_lpa.jl +++ b/GALAHAD.jl/test/test_lpa.jl @@ -53,7 +53,7 @@ function test_lpa() if d == 1 st = 'C' lpa_import(control, data, status, n, m, - "coordinate", A_ne, A_row, A_col, Cint[]) + "coordinate", A_ne, A_row, A_col, C_NULL) lpa_solve_lp(data, status, n, m, g, f, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, @@ -64,7 +64,7 @@ function test_lpa() if d == 2 st = 'R' lpa_import(control, data, status, n, m, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) lpa_solve_lp(data, status, n, m, g, f, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, @@ -77,7 +77,7 @@ function test_lpa() A_dense_ne = 6 # number of elements of A A_dense = Float64[2.0, 1.0, 0.0, 0.0, 1.0, 1.0] lpa_import(control, data, status, n, m, - "dense", A_ne, Cint[], Cint[], Cint[]) + "dense", A_ne, C_NULL, C_NULL, C_NULL) lpa_solve_lp(data, status, n, m, g, f, A_dense_ne, A_dense, c_l, c_u, x_l, x_u, diff --git a/GALAHAD.jl/test/test_lpb.jl b/GALAHAD.jl/test/test_lpb.jl index b4c48b80cc..352747e504 100644 --- a/GALAHAD.jl/test/test_lpb.jl +++ b/GALAHAD.jl/test/test_lpb.jl @@ -53,7 +53,7 @@ function test_lpb() if d == 1 st = 'C' lpb_import(control, data, status, n, m, - "coordinate", A_ne, A_row, A_col, Cint[]) + "coordinate", A_ne, A_row, A_col, C_NULL) lpb_solve_lp(data, status, n, m, g, f, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, @@ -64,7 +64,7 @@ function test_lpb() if d == 2 st = 'R' lpb_import(control, data, status, n, m, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) lpb_solve_lp(data, status, n, m, g, f, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, @@ -78,7 +78,7 @@ function test_lpb() A_dense = Float64[2.0, 1.0, 0.0, 0.0, 1.0, 1.0] lpb_import(control, data, status, n, m, - "dense", A_ne, Cint[], Cint[], Cint[]) + "dense", A_ne, C_NULL, C_NULL, C_NULL) lpb_solve_lp(data, status, n, m, g, f, A_dense_ne, A_dense, c_l, c_u, x_l, x_u, diff --git a/GALAHAD.jl/test/test_lsqp.jl b/GALAHAD.jl/test/test_lsqp.jl index 2c8b6b3cd0..080f347c81 100644 --- a/GALAHAD.jl/test/test_lsqp.jl +++ b/GALAHAD.jl/test/test_lsqp.jl @@ -55,7 +55,7 @@ function test_lsqp() if d == 1 st = 'C' lsqp_import(control, data, status, n, m, - "coordinate", A_ne, A_row, A_col, Cint[]) + "coordinate", A_ne, A_row, A_col, C_NULL) lsqp_solve_qp(data, status, n, m, w, x_0, g, f, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, @@ -66,7 +66,7 @@ function test_lsqp() if d == 2 st = 'R' lsqp_import(control, data, status, n, m, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) lsqp_solve_qp(data, status, n, m, w, x_0, g, f, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, @@ -80,7 +80,7 @@ function test_lsqp() A_dense = Float64[2.0, 1.0, 0.0, 0.0, 1.0, 1.0] lsqp_import(control, data, status, n, m, - "dense", A_dense_ne, Cint[], Cint[], Cint[]) + "dense", A_dense_ne, C_NULL, C_NULL, C_NULL) lsqp_solve_qp(data, status, n, m, w, x_0, g, f, A_dense_ne, A_dense, c_l, c_u, x_l, x_u, diff --git a/GALAHAD.jl/test/test_nls.jl b/GALAHAD.jl/test/test_nls.jl index 81e8008e2d..bf4a9a0135 100644 --- a/GALAHAD.jl/test/test_nls.jl +++ b/GALAHAD.jl/test/test_nls.jl @@ -13,7 +13,8 @@ end function test_nls() # compute the residuals - function res(n::Int, m::Int, x::Vector{Float64}, c::Vector{Float64}, userdata::userdata_type) + function res(n::Int, m::Int, x::Vector{Float64}, c::Vector{Float64}, + userdata::userdata_type) c[1] = x[1]^2 + userdata.p c[2] = x[1] + x[2]^2 c[3] = x[1] - x[2] @@ -21,7 +22,8 @@ function test_nls() end # compute the Jacobian - function jac(n::Int, m::Int, jne::Int, x::Vector{Float64}, jval::Vector{Float64}, userdata::userdata_type) + function jac(n::Int, m::Int, jne::Int, x::Vector{Float64}, jval::Vector{Float64}, + userdata::userdata_type) jval[1] = 2.0 * x[1] jval[2] = 1.0 jval[3] = 2.0 * x[2] @@ -31,14 +33,16 @@ function test_nls() end # compute the Hessian - function hess(n::Int, m::Int, hne::Int, x::Vector{Float64}, y::Vector{Float64}, hval::Vector{Float64}, userdata::userdata_type) + function hess(n::Int, m::Int, hne::Int, x::Vector{Float64}, y::Vector{Float64}, + hval::Vector{Float64}, userdata::userdata_type) hval[1] = 2.0 * y[1] hval[2] = 2.0 * y[2] return 0 end # compute Jacobian-vector products - function jacprod(n::Int, m::Int, x::Vector{Float64}, trans::Bool, u::Vector{Float64}, v::Vector{Float64}, got_j::Bool, userdata::userdata_type) + function jacprod(n::Int, m::Int, x::Vector{Float64}, trans::Bool, u::Vector{Float64}, + v::Vector{Float64}, got_j::Bool, userdata::userdata_type) if trans u[1] = u[1] + 2.0 * x[1] * v[1] + v[2] + v[3] u[2] = u[2] + 2.0 * x[2] * v[2] - v[3] @@ -51,28 +55,33 @@ function test_nls() end # compute Hessian-vector products - function hessprod(n::Int, m::Int, x::Vector{Float64}, y::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, got_h::Bool, userdata::userdata_type) + function hessprod(n::Int, m::Int, x::Vector{Float64}, y::Vector{Float64}, + u::Vector{Float64}, v::Vector{Float64}, got_h::Bool, + userdata::userdata_type) u[1] = u[1] + 2.0 * y[1] * v[1] u[2] = u[2] + 2.0 * y[2] * v[2] return 0 end # compute residual-Hessians-vector products - function rhessprods(n::Int, m::Int, pne::Int, x::Vector{Float64}, v::Vector{Float64}, pval::Vector{Float64}, got_h::Bool, userdata::userdata_type) + function rhessprods(n::Int, m::Int, pne::Int, x::Vector{Float64}, v::Vector{Float64}, + pval::Vector{Float64}, got_h::Bool, userdata::userdata_type) pval[1] = 2.0 * v[1] pval[2] = 2.0 * v[2] return 0 end # # scale v - function scale(n::Int, m::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, userdata::userdata_type) + function scale(n::Int, m::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, + userdata::userdata_type) u[1] = v[1] u[2] = v[2] return 0 end # compute the dense Jacobian - function jac_dense(n::Int, m::Int, jne::Int, x::Vector{Float64}, jval::Vector{Float64}, userdata::userdata_type) + function jac_dense(n::Int, m::Int, jne::Int, x::Vector{Float64}, jval::Vector{Float64}, + userdata::userdata_type) jval[1] = 2.0 * x[1] jval[2] = 0.0 jval[3] = 1.0 @@ -83,7 +92,8 @@ function test_nls() end # compute the dense Hessian - function hess_dense(n::Int, m::Int, hne::Int, x::Vector{Float64}, y::Vector{Float64}, hval::Vector{Float64}, userdata::userdata_type) + function hess_dense(n::Int, m::Int, hne::Int, x::Vector{Float64}, y::Vector{Float64}, + hval::Vector{Float64}, userdata::userdata_type) hval[1] = 2.0 * y[1] hval[2] = 0.0 hval[3] = 2.0 * y[2] @@ -91,7 +101,9 @@ function test_nls() end # compute dense residual-Hessians-vector products - function rhessprods_dense(n::Int, m::Int, pne::Int, x::Vector{Float64}, v::Vector{Float64}, pval::Vector{Float64}, got_h::Bool, userdata::userdata_type) + function rhessprods_dense(n::Int, m::Int, pne::Int, x::Vector{Float64}, + v::Vector{Float64}, pval::Vector{Float64}, got_h::Bool, + userdata::userdata_type) pval[1] = 2.0 * v[1] pval[2] = 0.0 pval[3] = 0.0 diff --git a/GALAHAD.jl/test/test_presolve.jl b/GALAHAD.jl/test/test_presolve.jl index 44a0d08f61..44fe31749b 100644 --- a/GALAHAD.jl/test/test_presolve.jl +++ b/GALAHAD.jl/test/test_presolve.jl @@ -54,8 +54,8 @@ function test_presolve() if d == 1 st = 'C' presolve_import_problem(control, data, status, n, m, - "coordinate", H_ne, H_row, H_col, Cint[], H_val, g, f, - "coordinate", A_ne, A_row, A_col, Cint[], A_val, + "coordinate", H_ne, H_row, H_col, C_NULL, H_val, g, f, + "coordinate", A_ne, A_row, A_col, C_NULL, A_val, c_l, c_u, x_l, x_u, n_trans, m_trans, H_ne_trans, A_ne_trans) end @@ -64,8 +64,8 @@ function test_presolve() if d == 2 st = 'R' presolve_import_problem(control, data, status, n, m, - "sparse_by_rows", H_ne, Cint[], H_col, H_ptr, H_val, g, f, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr, A_val, + "sparse_by_rows", H_ne, C_NULL, H_col, H_ptr, H_val, g, f, + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr, A_val, c_l, c_u, x_l, x_u, n_trans, m_trans, H_ne_trans, A_ne_trans) end @@ -81,8 +81,8 @@ function test_presolve() 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0] presolve_import_problem(control, data, status, n, m, - "dense", H_dense_ne, Cint[], Cint[], Cint[], H_dense, g, - f, "dense", A_dense_ne, Cint[], Cint[], Cint[], A_dense, + "dense", H_dense_ne, C_NULL, C_NULL, C_NULL, H_dense, g, + f, "dense", A_dense_ne, C_NULL, C_NULL, C_NULL, A_dense, c_l, c_u, x_l, x_u, n_trans, m_trans, H_ne_trans, A_ne_trans) end @@ -91,8 +91,8 @@ function test_presolve() if d == 4 st = 'L' presolve_import_problem(control, data, status, n, m, - "diagonal", n, Cint[], Cint[], Cint[], H_val, g, f, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr, A_val, + "diagonal", n, C_NULL, C_NULL, C_NULL, H_val, g, f, + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr, A_val, c_l, c_u, x_l, x_u, n_trans, m_trans, H_ne_trans, A_ne_trans) end @@ -101,8 +101,8 @@ function test_presolve() if d == 5 st = 'S' presolve_import_problem(control, data, status, n, m, - "scaled_identity", 1, Cint[], Cint[], Cint[], H_val, g, f, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr, A_val, + "scaled_identity", 1, C_NULL, C_NULL, C_NULL, H_val, g, f, + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr, A_val, c_l, c_u, x_l, x_u, n_trans, m_trans, H_ne_trans, A_ne_trans) end @@ -111,8 +111,8 @@ function test_presolve() if d == 6 st = 'I' presolve_import_problem(control, data, status, n, m, - "identity", 0, Cint[], Cint[], Cint[], Cint[], g, f, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr, A_val, + "identity", 0, C_NULL, C_NULL, C_NULL, C_NULL, g, f, + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr, A_val, c_l, c_u, x_l, x_u, n_trans, m_trans, H_ne_trans, A_ne_trans) end @@ -121,8 +121,8 @@ function test_presolve() if d == 7 st = 'Z' presolve_import_problem(control, data, status, n, m, - "zero", 0, Cint[], Cint[], Cint[], Cint[], g, f, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr, A_val, + "zero", 0, C_NULL, C_NULL, C_NULL, C_NULL, g, f, + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr, A_val, c_l, c_u, x_l, x_u, n_trans, m_trans, H_ne_trans, A_ne_trans) end diff --git a/GALAHAD.jl/test/test_psls.jl b/GALAHAD.jl/test/test_psls.jl index 0324e0daa2..909159e44f 100644 --- a/GALAHAD.jl/test/test_psls.jl +++ b/GALAHAD.jl/test/test_psls.jl @@ -45,7 +45,7 @@ function test_psls() st = 'C' psls_import(control, data, status, n, - "coordinate", ne, row, col, Cint[]) + "coordinate", ne, row, col, C_NULL) psls_form_preconditioner(data, status, ne, val) end @@ -55,7 +55,7 @@ function test_psls() st = 'R' psls_import(control, data, status, n, - "sparse_by_rows", ne, Cint[], col, ptr) + "sparse_by_rows", ne, C_NULL, col, ptr) psls_form_preconditioner(data, status, ne, val) end @@ -65,7 +65,7 @@ function test_psls() st = 'D' psls_import(control, data, status, n, - "dense", ne, Cint[], Cint[], Cint[]) + "dense", ne, C_NULL, C_NULL, C_NULL) psls_form_preconditioner(data, status, dense_ne, dense) end diff --git a/GALAHAD.jl/test/test_qpa.jl b/GALAHAD.jl/test/test_qpa.jl index f5ae6ded15..3dda1dc05a 100644 --- a/GALAHAD.jl/test/test_qpa.jl +++ b/GALAHAD.jl/test/test_qpa.jl @@ -60,8 +60,8 @@ function test_qpa() if d == 1 st = 'C' qpa_import(control, data, status, n, m, - "coordinate", H_ne, H_row, H_col, Cint[], - "coordinate", A_ne, A_row, A_col, Cint[]) + "coordinate", H_ne, H_row, H_col, C_NULL, + "coordinate", A_ne, A_row, A_col, C_NULL) qpa_solve_qp(data, status, n, m, H_ne, H_val, g, f, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, @@ -72,8 +72,8 @@ function test_qpa() if d == 2 st = 'R' qpa_import(control, data, status, n, m, - "sparse_by_rows", H_ne, Cint[], H_col, H_ptr, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + "sparse_by_rows", H_ne, C_NULL, H_col, H_ptr, + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) qpa_solve_qp(data, status, n, m, H_ne, H_val, g, f, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, @@ -89,8 +89,8 @@ function test_qpa() A_dense = Float64[2.0, 1.0, 0.0, 0.0, 1.0, 1.0] qpa_import(control, data, status, n, m, - "dense", H_ne, Cint[], Cint[], Cint[], - "dense", A_ne, Cint[], Cint[], Cint[]) + "dense", H_ne, C_NULL, C_NULL, C_NULL, + "dense", A_ne, C_NULL, C_NULL, C_NULL) qpa_solve_qp(data, status, n, m, H_dense_ne, H_dense, g, f, A_dense_ne, A_dense, c_l, c_u, x_l, x_u, @@ -101,8 +101,8 @@ function test_qpa() if d == 4 st = 'L' qpa_import(control, data, status, n, m, - "diagonal", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + "diagonal", H_ne, C_NULL, C_NULL, C_NULL, + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) qpa_solve_qp(data, status, n, m, H_ne, H_val, g, f, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, @@ -113,8 +113,8 @@ function test_qpa() if d == 5 st = 'S' qpa_import(control, data, status, n, m, - "scaled_identity", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + "scaled_identity", H_ne, C_NULL, C_NULL, C_NULL, + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) qpa_solve_qp(data, status, n, m, H_ne, H_val, g, f, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, @@ -125,8 +125,8 @@ function test_qpa() if d == 6 st = 'I' qpa_import(control, data, status, n, m, - "identity", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + "identity", H_ne, C_NULL, C_NULL, C_NULL, + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) qpa_solve_qp(data, status, n, m, H_ne, H_val, g, f, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, @@ -137,8 +137,8 @@ function test_qpa() if d == 7 st = 'Z' qpa_import(control, data, status, n, m, - "zero", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + "zero", H_ne, C_NULL, C_NULL, C_NULL, + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) qpa_solve_qp(data, status, n, m, H_ne, H_val, g, f, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, @@ -182,8 +182,8 @@ function test_qpa() # solve the l_1qp problem qpa_import(control, data, status, n, m, - "coordinate", H_ne, H_row, H_col, Cint[], - "coordinate", A_ne, A_row, A_col, Cint[]) + "coordinate", H_ne, H_row, H_col, C_NULL, + "coordinate", A_ne, A_row, A_col, C_NULL) qpa_solve_l1qp(data, status, n, m, H_ne, H_val, g, f, rho_g, rho_b, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, @@ -209,8 +209,8 @@ function test_qpa() # solve the bound constrained l_1qp problem qpa_import(control, data, status, n, m, - "coordinate", H_ne, H_row, H_col, Cint[], - "coordinate", A_ne, A_row, A_col, Cint[]) + "coordinate", H_ne, H_row, H_col, C_NULL, + "coordinate", A_ne, A_row, A_col, C_NULL) qpa_solve_bcl1qp(data, status, n, m, H_ne, H_val, g, f, rho_g, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, diff --git a/GALAHAD.jl/test/test_qpb.jl b/GALAHAD.jl/test/test_qpb.jl index 85c4c778b1..e99a4480ea 100644 --- a/GALAHAD.jl/test/test_qpb.jl +++ b/GALAHAD.jl/test/test_qpb.jl @@ -58,8 +58,8 @@ function test_qpb() if d == 1 st = 'C' qpb_import(control, data, status, n, m, - "coordinate", H_ne, H_row, H_col, Cint[], - "coordinate", A_ne, A_row, A_col, Cint[]) + "coordinate", H_ne, H_row, H_col, C_NULL, + "coordinate", A_ne, A_row, A_col, C_NULL) qpb_solve_qp(data, status, n, m, H_ne, H_val, g, f, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, @@ -70,8 +70,8 @@ function test_qpb() if d == 2 st = 'R' qpb_import(control, data, status, n, m, - "sparse_by_rows", H_ne, Cint[], H_col, H_ptr, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + "sparse_by_rows", H_ne, C_NULL, H_col, H_ptr, + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) qpb_solve_qp(data, status, n, m, H_ne, H_val, g, f, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, @@ -87,8 +87,8 @@ function test_qpb() A_dense = Float64[2.0, 1.0, 0.0, 0.0, 1.0, 1.0] qpb_import(control, data, status, n, m, - "dense", H_ne, Cint[], Cint[], Cint[], - "dense", A_ne, Cint[], Cint[], Cint[]) + "dense", H_ne, C_NULL, C_NULL, C_NULL, + "dense", A_ne, C_NULL, C_NULL, C_NULL) qpb_solve_qp(data, status, n, m, H_dense_ne, H_dense, g, f, A_dense_ne, A_dense, c_l, c_u, x_l, x_u, @@ -99,8 +99,8 @@ function test_qpb() if d == 4 st = 'L' qpb_import(control, data, status, n, m, - "diagonal", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + "diagonal", H_ne, C_NULL, C_NULL, C_NULL, + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) qpb_solve_qp(data, status, n, m, H_ne, H_val, g, f, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, @@ -111,8 +111,8 @@ function test_qpb() if d == 5 st = 'S' qpb_import(control, data, status, n, m, - "scaled_identity", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + "scaled_identity", H_ne, C_NULL, C_NULL, C_NULL, + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) qpb_solve_qp(data, status, n, m, H_ne, H_val, g, f, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, @@ -123,8 +123,8 @@ function test_qpb() if d == 6 st = 'I' qpb_import(control, data, status, n, m, - "identity", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + "identity", H_ne, C_NULL, C_NULL, C_NULL, + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) qpb_solve_qp(data, status, n, m, H_ne, H_val, g, f, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, @@ -135,8 +135,8 @@ function test_qpb() if d == 7 st = 'Z' qpb_import(control, data, status, n, m, - "zero", H_ne, Cint[], Cint[], Cint[], - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + "zero", H_ne, C_NULL, C_NULL, C_NULL, + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) qpb_solve_qp(data, status, n, m, H_ne, H_val, g, f, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z, diff --git a/GALAHAD.jl/test/test_sbls.jl b/GALAHAD.jl/test/test_sbls.jl index f51e5a277b..d8cae6e274 100644 --- a/GALAHAD.jl/test/test_sbls.jl +++ b/GALAHAD.jl/test/test_sbls.jl @@ -62,101 +62,101 @@ function test_sbls() if d == 1 st = 'C' sbls_import(control, data, status, n, m, - "coordinate", H_ne, H_row, H_col, Cint[], - "coordinate", A_ne, A_row, A_col, Cint[], - "coordinate", C_ne, C_row, C_col, Cint[]) + "coordinate", H_ne, H_row, H_col, C_NULL, + "coordinate", A_ne, A_row, A_col, C_NULL, + "coordinate", C_ne, C_row, C_col, C_NULL) sbls_factorize_matrix(data, status, n, H_ne, H_val, A_ne, A_val, - C_ne, C_val, Cint[]) + C_ne, C_val, C_NULL) end # sparse by rows if d == 2 st = 'R' sbls_import(control, data, status, n, m, - "sparse_by_rows", H_ne, Cint[], H_col, H_ptr, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr, - "sparse_by_rows", C_ne, Cint[], C_col, C_ptr) + "sparse_by_rows", H_ne, C_NULL, H_col, H_ptr, + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr, + "sparse_by_rows", C_ne, C_NULL, C_col, C_ptr) sbls_factorize_matrix(data, status, n, H_ne, H_val, A_ne, A_val, - C_ne, C_val, Cint[]) + C_ne, C_val, C_NULL) end # dense if d == 3 st = 'D' sbls_import(control, data, status, n, m, - "dense", H_ne, Cint[], Cint[], Cint[], - "dense", A_ne, Cint[], Cint[], Cint[], - "dense", C_ne, Cint[], Cint[], Cint[]) + "dense", H_ne, C_NULL, C_NULL, C_NULL, + "dense", A_ne, C_NULL, C_NULL, C_NULL, + "dense", C_ne, C_NULL, C_NULL, C_NULL) sbls_factorize_matrix(data, status, n, H_dense_ne, H_dense, A_dense_ne, A_dense, C_dense_ne, C_dense, - Cint[]) + C_NULL) end # diagonal if d == 4 st = 'L' sbls_import(control, data, status, n, m, - "diagonal", H_ne, Cint[], Cint[], Cint[], - "dense", A_ne, Cint[], Cint[], Cint[], - "diagonal", C_ne, Cint[], Cint[], Cint[]) + "diagonal", H_ne, C_NULL, C_NULL, C_NULL, + "dense", A_ne, C_NULL, C_NULL, C_NULL, + "diagonal", C_ne, C_NULL, C_NULL, C_NULL) sbls_factorize_matrix(data, status, n, n, H_diag, A_dense_ne, A_dense, m, C_diag, - Cint[]) + C_NULL) end # scaled identity if d == 5 st = 'S' sbls_import(control, data, status, n, m, - "scaled_identity", H_ne, Cint[], Cint[], Cint[], - "dense", A_ne, Cint[], Cint[], Cint[], - "scaled_identity", C_ne, Cint[], Cint[], Cint[]) + "scaled_identity", H_ne, C_NULL, C_NULL, C_NULL, + "dense", A_ne, C_NULL, C_NULL, C_NULL, + "scaled_identity", C_ne, C_NULL, C_NULL, C_NULL) sbls_factorize_matrix(data, status, n, 1, H_scid, A_dense_ne, A_dense, 1, C_scid, - Cint[]) + C_NULL) end # identity if d == 6 st = 'I' sbls_import(control, data, status, n, m, - "identity", H_ne, Cint[], Cint[], Cint[], - "dense", A_ne, Cint[], Cint[], Cint[], - "identity", C_ne, Cint[], Cint[], Cint[]) + "identity", H_ne, C_NULL, C_NULL, C_NULL, + "dense", A_ne, C_NULL, C_NULL, C_NULL, + "identity", C_ne, C_NULL, C_NULL, C_NULL) sbls_factorize_matrix(data, status, n, 0, H_val, A_dense_ne, A_dense, - 0, C_val, Cint[]) + 0, C_val, C_NULL) end # zero if d == 7 st = 'Z' sbls_import(control, data, status, n, m, - "identity", H_ne, Cint[], Cint[], Cint[], - "dense", A_ne, Cint[], Cint[], Cint[], - "zero", C_ne, Cint[], Cint[], Cint[]) + "identity", H_ne, C_NULL, C_NULL, C_NULL, + "dense", A_ne, C_NULL, C_NULL, C_NULL, + "zero", C_ne, C_NULL, C_NULL, C_NULL) sbls_factorize_matrix(data, status, n, 0, H_val, A_dense_ne, A_dense, - 0, Cint[], Cint[]) + 0, C_NULL, C_NULL) end # Set right-hand side (a, b) diff --git a/GALAHAD.jl/test/test_slls.jl b/GALAHAD.jl/test/test_slls.jl index 86109a3cb9..5426e028f8 100644 --- a/GALAHAD.jl/test/test_slls.jl +++ b/GALAHAD.jl/test/test_slls.jl @@ -32,7 +32,8 @@ function test_slls() pointer_userdata = pointer_from_objref(userdata) # Pointer to call prec - pointer_prec = @cfunction(prec, Int, (Int, Vector{Float64}, Vector{Float64}, userdata_type)) + pointer_prec = @cfunction(prec, Int, + (Int, Vector{Float64}, Vector{Float64}, userdata_type)) # Set problem data n = 10 # dimension @@ -195,7 +196,8 @@ function test_slls() "dense_by_columns", Ao_dense_ne, C_NULL, C_NULL, 0, C_NULL) - slls_solve_given_a(data, pointer_userdata, status, n, o, Ao_dense_ne, Ao_by_col_dense, b, + slls_solve_given_a(data, pointer_userdata, status, n, o, Ao_dense_ne, Ao_by_col_dense, + b, x, z, r, g, x_stat, pointer_prec) end diff --git a/GALAHAD.jl/test/test_sls.jl b/GALAHAD.jl/test/test_sls.jl index d388505ae1..dc3a948e87 100644 --- a/GALAHAD.jl/test/test_sls.jl +++ b/GALAHAD.jl/test/test_sls.jl @@ -48,7 +48,7 @@ function test_sls() if d == 1 @printf(" coordinate ") sls_analyse_matrix(control, data, status, n, - "coordinate", ne, row, col, Cint[]) + "coordinate", ne, row, col, C_NULL) sls_factorize_matrix(data, status, ne, val) end @@ -56,7 +56,7 @@ function test_sls() if d == 2 @printf(" sparse by rows ") sls_analyse_matrix(control, data, status, n, - "sparse_by_rows", ne, Cint[], col, ptr) + "sparse_by_rows", ne, C_NULL, col, ptr) sls_factorize_matrix(data, status, ne, val) end @@ -64,7 +64,7 @@ function test_sls() if d == 3 @printf(" dense ") sls_analyse_matrix(control, data, status, n, - "dense", ne, Cint[], Cint[], Cint[]) + "dense", ne, C_NULL, C_NULL, C_NULL) sls_factorize_matrix(data, status, dense_ne, dense) end diff --git a/GALAHAD.jl/test/test_trb.jl b/GALAHAD.jl/test/test_trb.jl index 3e0f4a74b1..393e727da7 100644 --- a/GALAHAD.jl/test/test_trb.jl +++ b/GALAHAD.jl/test/test_trb.jl @@ -29,7 +29,8 @@ function test_trb() end # Hessian of the objective - function hess(n::Int, n::Int, var::Vector{Float64}, hval::Vector{Float64}, userdata::userdata_type) + function hess(n::Int, n::Int, var::Vector{Float64}, hval::Vector{Float64}, + userdata::userdata_type) p = userdata.p hval[1] = 2.0 - cos(x[1]) hval[2] = 2.0 @@ -40,7 +41,8 @@ function test_trb() end # Dense Hessian - function hess_dense(n::Int, n::Int, var::Vector{Float64}, hval::Vector{Float64}, userdata::userdata_type) + function hess_dense(n::Int, n::Int, var::Vector{Float64}, hval::Vector{Float64}, + userdata::userdata_type) p = userdata.p hval[1] = 2.0 - cos(x[1]) hval[2] = 0.0 @@ -52,7 +54,8 @@ function test_trb() end # Hessian-vector product - function hessprod(n::Int, var::Vector{Float64}, u::Vector{Float64}, var::Vector{Float64}, got_h::Bool, userdata::userdata_type) + function hessprod(n::Int, var::Vector{Float64}, u::Vector{Float64}, var::Vector{Float64}, + got_h::Bool, userdata::userdata_type) p = userdata.p u[1] = u[1] + 2.0 * (v[1] + v[3]) - cos(x[1]) * v[1] u[2] = u[2] + 2.0 * (v[2] + v[3]) @@ -61,7 +64,9 @@ function test_trb() end # Sparse Hessian-vector product - function shessprod(n::Int, var::Vector{Float64}, nnz_v::Int, index_nz_v::Vector{Int}, v::Vector{Float64}, nnz_u::Ref{Int}, index_nz_u::Vector{Int}, u::Vector{Float64}, got_h::Bool, userdata::userdata_type) + function shessprod(n::Int, var::Vector{Float64}, nnz_v::Int, index_nz_v::Vector{Int}, + v::Vector{Float64}, nnz_u::Ref{Int}, index_nz_u::Vector{Int}, + u::Vector{Float64}, got_h::Bool, userdata::userdata_type) p = zeros(Float64, 3) used = falses(3) for i in 1:nnz_v @@ -98,7 +103,8 @@ function test_trb() end # Apply preconditioner - function prec(n::Int, var::Vector{Float64}, u::Vector{Float64}, var::Vector{Float64}, userdata::userdata_type) + function prec(n::Int, var::Vector{Float64}, u::Vector{Float64}, var::Vector{Float64}, + userdata::userdata_type) p = userdata.p u[1] = 0.5 * v[1] u[2] = 0.5 * v[2] @@ -114,7 +120,8 @@ function test_trb() end # Gradient of the objective - function grad_diag(n::Int, var::Vector{Float64}, g::Vector{Float64}, userdata::userdata_type) + function grad_diag(n::Int, var::Vector{Float64}, g::Vector{Float64}, + userdata::userdata_type) p = userdata.p g[1] = -sin(x[1]) g[2] = 2.0 * x[2] @@ -123,7 +130,8 @@ function test_trb() end # Hessian of the objective - function hess_diag(n::Int, n::Int, var::Vector{Float64}, hval::Vector{Float64}, userdata::userdata_type) + function hess_diag(n::Int, n::Int, var::Vector{Float64}, hval::Vector{Float64}, + userdata::userdata_type) p = userdata.p hval[1] = -cos(x[1]) hval[3] = 2.0 @@ -132,16 +140,18 @@ function test_trb() end # Hessian-vector product - function hessprod_diag(n::Int, var::Vector{Float64}, u::Vector{Float64}, var::Vector{Float64}, got_h::Bool, userdata::userdata_type) + function hessprod_diag(n::Int, var::Vector{Float64}, u::Vector{Float64}, + var::Vector{Float64}, got_h::Bool, userdata::userdata_type) p = userdata.p - u[1] = u[1] + - cos(x[1]) * v[1] + u[1] = u[1] + -cos(x[1]) * v[1] u[2] = u[2] + 2.0 * v[2] u[3] = u[3] + 2.0 * v[3] return 0 end # Produit matrice-vecteur Hesseien creux - function shessprod_diag(n::Int, var::Vector{Float64}, nnz_v::Int, index_nz_v::Vector{Int}, u::Vector{Float64}, got_h::Bool, userdata::userdata_type) + function shessprod_diag(n::Int, var::Vector{Float64}, nnz_v::Int, index_nz_v::Vector{Int}, + u::Vector{Float64}, got_h::Bool, userdata::userdata_type) p = zeros(3) used = falses(3) for i in 1:nnz_v @@ -255,7 +265,8 @@ function test_trb() # sparse by rows if d == 2 st = 'R' - trb_import(control, data, status, n, x_l, x_u, "sparse_by_rows", ne, C_NULL, H_col, H_ptr) + trb_import(control, data, status, n, x_l, x_u, "sparse_by_rows", ne, C_NULL, H_col, + H_ptr) terminated = false while !terminated # reverse-communication loop @@ -286,7 +297,8 @@ function test_trb() terminated = false while !terminated # reverse-communication loop - trb_solve_reverse_with_mat(data, status, eval_status, n, x, f[], g, div(n*(n + 1), 2), H_dense, u, v) + trb_solve_reverse_with_mat(data, status, eval_status, n, x, f[], g, + div(n * (n + 1), 2), H_dense, u, v) if status[] == 0 # successful termination terminated = true elseif status[] < 0 # error exit @@ -339,7 +351,8 @@ function test_trb() terminated = false while !terminated # reverse-communication loop - trb_solve_reverse_without_mat(data, status, eval_status, n, x, f[], g, u, v, index_nz_v, nnz_v, index_nz_u, nnz_u) + trb_solve_reverse_without_mat(data, status, eval_status, n, x, f[], g, u, v, + index_nz_v, nnz_v, index_nz_u, nnz_u) if status[] == 0 # successful termination terminated = true elseif status[] < 0 # error exit diff --git a/GALAHAD.jl/test/test_tru.jl b/GALAHAD.jl/test/test_tru.jl index cb11943beb..53e8eff48d 100644 --- a/GALAHAD.jl/test/test_tru.jl +++ b/GALAHAD.jl/test/test_tru.jl @@ -28,7 +28,8 @@ function grad(n::Int, x::Vector{Float64}, g::Vector{Float64}, userdata::userdata end # Hessian of the objective -function hess(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, userdata::userdata_type) +function hess(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, + userdata::userdata_type) hval[1] = 2.0 - cos(x[1]) hval[2] = 2.0 hval[3] = 2.0 @@ -38,7 +39,8 @@ function hess(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, userda end # Dense Hessian -function hess_dense(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, userdata::userdata_type) +function hess_dense(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, + userdata::userdata_type) hval[1] = 2.0 - cos(x[1]) hval[2] = 0.0 hval[3] = 2.0 @@ -49,7 +51,8 @@ function hess_dense(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, end # Hessian-vector product -function hessprod(n::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, got_h::Bool, userdata::userdata_type) +function hessprod(n::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, + got_h::Bool, userdata::userdata_type) u[1] = u[1] + 2.0 * (v[1] + v[3]) - cos(x[1]) * v[1] u[2] = u[2] + 2.0 * (v[2] + v[3]) u[3] = u[3] + 2.0 * (v[1] + v[2] + 2.0 * v[3]) @@ -57,7 +60,8 @@ function hessprod(n::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Floa end # Apply preconditioner -function prec(n::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, userdata::userdata_type) +function prec(n::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, + userdata::userdata_type) u[1] = 0.5 * v[1] u[2] = 0.5 * v[2] u[3] = 0.25 * v[3] @@ -81,7 +85,8 @@ function grad_diag(n::Int, x::Vector{Float64}, g::Vector{Float64}, userdata::use end # Hessian of the objective -function hess_diag(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, userdata::userdata_type) +function hess_diag(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, + userdata::userdata_type) hval[1] = -cos(x[1]) hval[2] = 2.0 hval[3] = 2.0 @@ -89,7 +94,8 @@ function hess_diag(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, u end # Hessian-vector product -function hessprod_diag(n::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, got_h::Bool, userdata::userdata_type) +function hessprod_diag(n::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, + got_h::Bool, userdata::userdata_type) u[1] = u[1] + -cos(x[1]) * v[1] u[2] = u[2] + 2.0 * v[2] u[3] = u[3] + 2.0 * v[3] @@ -205,7 +211,8 @@ function test_tru() terminated = false while !terminated # reverse-communication loop - tru_solve_reverse_with_mat(data, status, eval_status, n, x, f[], g, div(n*(n + 1), 2), H_dense, u, v) + tru_solve_reverse_with_mat(data, status, eval_status, n, x, f[], g, + div(n * (n + 1), 2), H_dense, u, v) if status[] == 0 # successful termination terminated = true elseif status[] < 0 # error exit @@ -215,7 +222,7 @@ function test_tru() elseif status[] == 3 # evaluate g eval_status[] = grad(n, x, g, userdata) elseif status[] == 4 # evaluate H - eval_status[] = hess_dense(n, div(n*(n + 1), 2), x, H_dense, userdata) + eval_status[] = hess_dense(n, div(n * (n + 1), 2), x, H_dense, userdata) elseif status[] == 6 # evaluate the product with P eval_status[] = prec(n, x, u, v, userdata) else diff --git a/GALAHAD.jl/test/test_uls.jl b/GALAHAD.jl/test/test_uls.jl index 112e22811d..2811223321 100644 --- a/GALAHAD.jl/test/test_uls.jl +++ b/GALAHAD.jl/test/test_uls.jl @@ -48,21 +48,21 @@ function test_uls() if d == 1 @printf(" coordinate ") uls_factorize_matrix(control, data, status, m, n, - "coordinate", ne, val, row, col, Cint[]) + "coordinate", ne, val, row, col, C_NULL) end # sparse by rows if d == 2 @printf(" sparse by rows ") uls_factorize_matrix(control, data, status, m, n, - "sparse_by_rows", ne, val, Cint[], col, ptr) + "sparse_by_rows", ne, val, C_NULL, col, ptr) end # dense if d == 3 @printf(" dense ") uls_factorize_matrix(control, data, status, m, n, - "dense", dense_ne, dense, Cint[], Cint[], Cint[]) + "dense", dense_ne, dense, C_NULL, C_NULL, C_NULL) end # Set right-hand side and solve the system A x = b diff --git a/GALAHAD.jl/test/test_wcp.jl b/GALAHAD.jl/test/test_wcp.jl index b110a51069..64d0b8fce5 100644 --- a/GALAHAD.jl/test/test_wcp.jl +++ b/GALAHAD.jl/test/test_wcp.jl @@ -54,7 +54,7 @@ function test_wcp() # sparse co-ordinate storage if d == 1 st = 'C' - wcp_import(control, data, status, n, m, "coordinate", A_ne, A_row, A_col, Cint[]) + wcp_import(control, data, status, n, m, "coordinate", A_ne, A_row, A_col, C_NULL) wcp_find_wcp(data, status, n, m, g, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y_l, y_u, z_l, z_u, @@ -65,7 +65,7 @@ function test_wcp() if d == 2 st = 'R' wcp_import(control, data, status, n, m, - "sparse_by_rows", A_ne, Cint[], A_col, A_ptr) + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) wcp_find_wcp(data, status, n, m, g, A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y_l, y_u, z_l, z_u, @@ -79,7 +79,7 @@ function test_wcp() A_dense = Float64[2.0, 1.0, 0.0, 0.0, 1.0, 1.0] wcp_import(control, data, status, n, m, - "dense", A_dense_ne, Cint[], Cint[], Cint[]) + "dense", A_dense_ne, C_NULL, C_NULL, C_NULL) wcp_find_wcp(data, status, n, m, g, A_dense_ne, A_dense, c_l, c_u, x_l, x_u, x, c, y_l, y_u, z_l, z_u, From 5db7de8e6b2864b6fb27b03417066d310e7f3211 Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Tue, 13 Feb 2024 13:53:24 -0500 Subject: [PATCH 29/33] Clean examples --- GALAHAD.jl/test/test_llst.jl | 370 +++++++++++++++++------------------ 1 file changed, 185 insertions(+), 185 deletions(-) diff --git a/GALAHAD.jl/test/test_llst.jl b/GALAHAD.jl/test/test_llst.jl index dee68a0b55..6fb373c3c6 100644 --- a/GALAHAD.jl/test/test_llst.jl +++ b/GALAHAD.jl/test/test_llst.jl @@ -6,206 +6,206 @@ using Test using Printf using Accessors -#function test_llst() -# Derived types -data = Ref{Ptr{Cvoid}}() -global control = Ref{llst_control_type{Float64}}() -inform = Ref{llst_inform_type{Float64}}() - -# Set problem data -# set dimensions -m = 100 -n = 2 * m + 1 -# A = (I : Diag(1:n) : e) -A_ne = 3 * m -A_row = zeros(Cint, A_ne) -A_col = zeros(Cint, A_ne) -A_ptr = zeros(Cint, m + 1) -A_val = zeros(Float64, A_ne) - -# store A in sparse formats -global l = 1 -for i in 1:m - A_ptr[i] = l - A_row[l] = i - A_col[l] = i - A_val[l] = 1.0 - global l = l + 1 - A_row[l] = i - A_col[l] = m + i - A_val[l] = i - global l = l + 1 - A_row[l] = i - A_col[l] = n - A_val[l] = 1.0 - global l = l + 1 -end -A_ptr[m + 1] = l - -# store A in dense format -A_dense_ne = m * n -A_dense_val = zeros(Float64, A_dense_ne) -global l = 0 -for i in 1:m - A_dense_val[l + i] = 1.0 - A_dense_val[l + m + i] = i - A_dense_val[l + n] = 1.0 - global l = l + n -end - -# S = diag(1:n)**2 -S_ne = n -S_row = zeros(Cint, S_ne) -S_col = zeros(Cint, S_ne) -S_ptr = zeros(Cint, n + 1) -S_val = zeros(Float64, S_ne) - -# store S in sparse formats -for i in 1:n - S_row[i] = i - S_col[i] = i - S_ptr[i] = i - S_val[i] = i * i -end -S_ptr[n + 1] = n + 1 - -# store S in dense format -S_dense_ne = div(n * (n + 1), 2) -S_dense_val = zeros(Float64, S_dense_ne) -global l = 0 -for i in 1:n - S_dense_val[l + i] = i * i - global l = l + i -end - -# b is a vector of ones -b = ones(Float64, m) # observations - -# trust-region radius is one -radius = 1.0 - -# Set output storage -x = zeros(Float64, n) # solution -global st = ' ' -status = Ref{Cint}() - -@printf(" Fortran sparse matrix indexing\n\n") -@printf(" basic tests of problem storage formats\n\n") - -# loop over storage formats -for d in 1:4 - - # Initialize LLST - llst_initialize(data, control, status) - global @reset control[].definite_linear_solver = galahad_linear_solver("potr") - global @reset control[].sbls_control.symmetric_linear_solver = galahad_linear_solver("sytr") - global @reset control[].sbls_control.definite_linear_solver = galahad_linear_solver("potr") - # @reset control[].print_level = Cint(1) - - # Set user-defined control options - @reset control[].f_indexing = true # Fortran sparse matrix indexing - - # use s or not (1 or 0) - for use_s in 0:1 - # sparse co-ordinate storage - if d == 1 - global st = 'C' - llst_import(control, data, status, m, n, - "coordinate", A_ne, A_row, A_col, C_NULL) +function test_llst() + # Derived types + data = Ref{Ptr{Cvoid}}() + control = Ref{llst_control_type{Float64}}() + inform = Ref{llst_inform_type{Float64}}() + + # Set problem data + # set dimensions + m = 100 + n = 2 * m + 1 + # A = (I : Diag(1:n) : e) + A_ne = 3 * m + A_row = zeros(Cint, A_ne) + A_col = zeros(Cint, A_ne) + A_ptr = zeros(Cint, m + 1) + A_val = zeros(Float64, A_ne) + + # store A in sparse formats + l = 1 + for i in 1:m + A_ptr[i] = l + A_row[l] = i + A_col[l] = i + A_val[l] = 1.0 + l = l + 1 + A_row[l] = i + A_col[l] = m + i + A_val[l] = i + l = l + 1 + A_row[l] = i + A_col[l] = n + A_val[l] = 1.0 + l = l + 1 + end + A_ptr[m + 1] = l + + # store A in dense format + A_dense_ne = m * n + A_dense_val = zeros(Float64, A_dense_ne) + l = 0 + for i in 1:m + A_dense_val[l + i] = 1.0 + A_dense_val[l + m + i] = i + A_dense_val[l + n] = 1.0 + l = l + n + end - if use_s == 0 - llst_solve_problem(data, status, m, n, radius, - A_ne, A_val, b, x, 0, C_NULL) - else - llst_import_scaling(control, data, status, n, - "coordinate", S_ne, S_row, - S_col, C_NULL) + # S = diag(1:n)**2 + S_ne = n + S_row = zeros(Cint, S_ne) + S_col = zeros(Cint, S_ne) + S_ptr = zeros(Cint, n + 1) + S_val = zeros(Float64, S_ne) + + # store S in sparse formats + for i in 1:n + S_row[i] = i + S_col[i] = i + S_ptr[i] = i + S_val[i] = i * i + end + S_ptr[n + 1] = n + 1 + + # store S in dense format + S_dense_ne = div(n * (n + 1), 2) + S_dense_val = zeros(Float64, S_dense_ne) + l = 0 + for i in 1:n + S_dense_val[l + i] = i * i + l = l + i + end - llst_solve_problem(data, status, m, n, radius, - A_ne, A_val, b, x, S_ne, S_val) + # b is a vector of ones + b = ones(Float64, m) # observations + + # trust-region radius is one + radius = 1.0 + + # Set output storage + x = zeros(Float64, n) # solution + st = ' ' + status = Ref{Cint}() + + @printf(" Fortran sparse matrix indexing\n\n") + @printf(" basic tests of problem storage formats\n\n") + + # loop over storage formats + for d in 1:4 + + # Initialize LLST + llst_initialize(data, control, status) + @reset control[].definite_linear_solver = galahad_linear_solver("potr") + @reset control[].sbls_control.symmetric_linear_solver = galahad_linear_solver("sytr") + @reset control[].sbls_control.definite_linear_solver = galahad_linear_solver("potr") + # @reset control[].print_level = Cint(1) + + # Set user-defined control options + @reset control[].f_indexing = true # Fortran sparse matrix indexing + + # use s or not (1 or 0) + for use_s in 0:1 + # sparse co-ordinate storage + if d == 1 + st = 'C' + llst_import(control, data, status, m, n, + "coordinate", A_ne, A_row, A_col, C_NULL) + + if use_s == 0 + llst_solve_problem(data, status, m, n, radius, + A_ne, A_val, b, x, 0, C_NULL) + else + llst_import_scaling(control, data, status, n, + "coordinate", S_ne, S_row, + S_col, C_NULL) + + llst_solve_problem(data, status, m, n, radius, + A_ne, A_val, b, x, S_ne, S_val) + end end - end - - # sparse by rows - if d == 2 - global st = 'R' - llst_import(control, data, status, m, n, - "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) - if use_s == 0 - llst_solve_problem(data, status, m, n, radius, - A_ne, A_val, b, x, 0, C_NULL) - else - llst_import_scaling(control, data, status, n, - "sparse_by_rows", S_ne, C_NULL, - S_col, S_ptr) - llst_solve_problem(data, status, m, n, radius, - A_ne, A_val, b, x, S_ne, S_val) + # sparse by rows + if d == 2 + st = 'R' + llst_import(control, data, status, m, n, + "sparse_by_rows", A_ne, C_NULL, A_col, A_ptr) + if use_s == 0 + llst_solve_problem(data, status, m, n, radius, + A_ne, A_val, b, x, 0, C_NULL) + else + llst_import_scaling(control, data, status, n, + "sparse_by_rows", S_ne, C_NULL, + S_col, S_ptr) + + llst_solve_problem(data, status, m, n, radius, + A_ne, A_val, b, x, S_ne, S_val) + end end - end - # dense - if d == 3 - global st = 'D' - llst_import(control, data, status, m, n, - "dense", A_dense_ne, C_NULL, C_NULL, C_NULL) - - if use_s == 0 - llst_solve_problem(data, status, m, n, radius, - A_dense_ne, A_dense_val, b, x, - 0, C_NULL) - else - llst_import_scaling(control, data, status, n, - "dense", S_dense_ne, - C_NULL, C_NULL, C_NULL) + # dense + if d == 3 + st = 'D' + llst_import(control, data, status, m, n, + "dense", A_dense_ne, C_NULL, C_NULL, C_NULL) + + if use_s == 0 + llst_solve_problem(data, status, m, n, radius, + A_dense_ne, A_dense_val, b, x, + 0, C_NULL) + else + llst_import_scaling(control, data, status, n, + "dense", S_dense_ne, + C_NULL, C_NULL, C_NULL) + + llst_solve_problem(data, status, m, n, radius, + A_dense_ne, A_dense_val, b, x, + S_dense_ne, S_dense_val) + end + end - llst_solve_problem(data, status, m, n, radius, - A_dense_ne, A_dense_val, b, x, - S_dense_ne, S_dense_val) + # diagonal + if d == 4 + st = 'I' + llst_import(control, data, status, m, n, + "coordinate", A_ne, A_row, A_col, C_NULL) + if use_s == 0 + llst_solve_problem(data, status, m, n, radius, + A_ne, A_val, b, x, 0, C_NULL) + else + llst_import_scaling(control, data, status, n, + "diagonal", S_ne, C_NULL, C_NULL, C_NULL) + + llst_solve_problem(data, status, m, n, radius, + A_ne, A_val, b, x, S_ne, S_val) + end end - end - # diagonal - if d == 4 - global st = 'I' - llst_import(control, data, status, m, n, - "coordinate", A_ne, A_row, A_col, C_NULL) - if use_s == 0 - llst_solve_problem(data, status, m, n, radius, - A_ne, A_val, b, x, 0, C_NULL) - else - llst_import_scaling(control, data, status, n, - "diagonal", S_ne, C_NULL, C_NULL, C_NULL) + llst_information(data, inform, status) - llst_solve_problem(data, status, m, n, radius, - A_ne, A_val, b, x, S_ne, S_val) + if inform[].status == 0 + @printf("storage type %c%1i: status = %1i, ||r|| = %5.2f\n", st, use_s, + inform[].status, inform[].r_norm) + else + @printf("storage type %c%1i: LLST_solve exit status = %1i\n", st, use_s, + inform[].status) end end - llst_information(data, inform, status) + # @printf("x: ") + # for i = 1:n + # @printf("%f ", x[i]) + # end + # @printf("\n") - if inform[].status == 0 - @printf("storage type %c%1i: status = %1i, ||r|| = %5.2f\n", st, use_s, - inform[].status, inform[].r_norm) - else - @printf("storage type %c%1i: LLST_solve exit status = %1i\n", st, use_s, - inform[].status) - end + # Delete internal workspace + llst_terminate(data, control, inform) end - # @printf("x: ") - # for i = 1:n - # @printf("%f ", x[i]) - # end - # @printf("\n") - - # Delete internal workspace - llst_terminate(data, control, inform) + return 0 end -# return 0 -# end - -# @testset "LLST" begin -# @test test_llst() == 0 -# end +@testset "LLST" begin + @test test_llst() == 0 +end From 95a992fba750f479b450b352034ae0b840162504 Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Tue, 13 Feb 2024 15:27:57 -0500 Subject: [PATCH 30/33] Fix test_bgo.jl --- GALAHAD.jl/test/runtests.jl | 2 +- GALAHAD.jl/test/test_bgo.jl | 370 ++++++++++++++++++++---------------- 2 files changed, 207 insertions(+), 165 deletions(-) diff --git a/GALAHAD.jl/test/runtests.jl b/GALAHAD.jl/test/runtests.jl index bef02dd0b7..d8ec58c181 100644 --- a/GALAHAD.jl/test/runtests.jl +++ b/GALAHAD.jl/test/runtests.jl @@ -4,7 +4,7 @@ using GALAHAD include("test_structures.jl") include("test_arc.jl") -## include("test_bgo.jl") +include("test_bgo.jl") ## include("test_blls.jl") include("test_bllsb.jl") include("test_bqp.jl") diff --git a/GALAHAD.jl/test/test_bgo.jl b/GALAHAD.jl/test/test_bgo.jl index c1bd07fa05..532fcebacc 100644 --- a/GALAHAD.jl/test/test_bgo.jl +++ b/GALAHAD.jl/test/test_bgo.jl @@ -20,42 +20,28 @@ function test_bgo() p = userdata.p freq = userdata.freq mag = userdata.mag - f[] = (x[1] + x[3] + p)^2 + (x[2] + x[3])^2 + mag * cos(freq * x[1]) + sum(x) return 0 end # Gradient of the objective - function grad(n::Int, var::Vector{Float64}, g::Vector{Float64}, userdata::userdata_type) - struct Cuserdata_type - p::Float64 - freq::Float64 - mag::Float64 - end - myuserdata = unsafe_load(Cuserdata_type, userdata) - p = myuserdata.p - freq = myuserdata.freq - mag = myuserdata.mag - - g[1] = 2.0 * (var[1] + var[3] + p) - mag * freq * sin(freq * var[1]) + 1.0 - g[2] = 2.0 * (var[2] + var[3]) + 1.0 - g[3] = 2.0 * (var[1] + var[3] + p) + 2.0 * (var[2] + var[3]) + 1.0 + function grad(n::Int, x::Vector{Float64}, g::Vector{Float64}, userdata::userdata_type) + p = userdata.p + freq = userdata.freq + mag = userdata.mag + g[1] = 2.0 * (x[1] + x[3] + p) - mag * freq * sin(freq * x[1]) + 1.0 + g[2] = 2.0 * (x[2] + x[3]) + 1.0 + g[3] = 2.0 * (x[1] + x[3] + p) + 2.0 * (x[2] + x[3]) + 1.0 return 0 end # Hessian of the objective - function hess(n::Int, ne::Int, var::Vector{Float64}, hval::Vector{Float64}, + function hess(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, userdata::userdata_type) - struct Cuserdata_type - p::Float64 - freq::Float64 - mag::Float64 - end - myuserdata = unsafe_load(Cuserdata_type, userdata) - freq = myuserdata.freq - mag = myuserdata.mag - - hval[1] = 2.0 - mag * freq^2 * cos(freq * var[1]) + p = userdata.p + freq = userdata.freq + mag = userdata.mag + hval[1] = 2.0 - mag * freq^2 * cos(freq * x[1]) hval[2] = 2.0 hval[3] = 2.0 hval[4] = 4.0 @@ -63,18 +49,12 @@ function test_bgo() end # Dense Hessian - function hess_dense(n::Int, ne::Int, var::Vector{Float64}, hval::Vector{Float64}, + function hess_dense(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, userdata::userdata_type) - struct Cuserdata_type - p::Float64 - freq::Float64 - mag::Float64 - end - myuserdata = unsafe_load(Cuserdata_type, userdata) - freq = myuserdata.freq - mag = myuserdata.mag - - hval[1] = 2.0 - mag * freq^2 * cos(freq * var[1]) + p = userdata.p + freq = userdata.freq + mag = userdata.mag + hval[1] = 2.0 - mag * freq^2 * cos(freq * x[1]) hval[2] = 0.0 hval[3] = 2.0 hval[4] = 2.0 @@ -83,75 +63,61 @@ function test_bgo() end # Hessian-vector product - function hessprod(n::Int, var::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, + function hessprod(n::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, got_h::Bool, userdata::userdata_type) - struct Cuserdata_type - p::Float64 - freq::Float64 - mag::Float64 - end - myuserdata = unsafe_load(Cuserdata_type, userdata) - freq = myuserdata.freq - mag = myuserdata.mag - - u[1] = u[1] + 2.0 * (v[1] + v[3]) - mag * freq^2 * cos(freq * var[1]) * v[1] + p = userdata.p + freq = userdata.freq + mag = userdata.mag + u[1] = u[1] + 2.0 * (v[1] + v[3]) - mag * freq^2 * cos(freq * x[1]) * v[1] u[2] = u[2] + 2.0 * (v[2] + v[3]) u[3] = u[3] + 2.0 * (v[1] + v[2] + 2.0 * v[3]) return 0 end # Sparse Hessian-vector product - function shessprod(n::Int, var::Vector{Float64}, nnz_v::Int, index_nz_v::Vector{Int}, - v::Vector{Float64}, - nnz_u::Ptr{Int}, index_nz_u::Vector{Int}, u::Vector{Float64}, - got_h::Bool, userdata::userdata_type) - struct Cuserdata_type - p::Float64 - freq::Float64 - mag::Float64 - end - myuserdata = unsafe_load(Cuserdata_type, userdata) - freq = myuserdata.freq - mag = myuserdata.mag - - p = zeros(3) - used = [false, false, false] + function shessprod(n::Int, x::Vector{Float64}, nnz_v::Cint, index_nz_v::Vector{Cint}, + v::Vector{Float64}, nnz_u::Ref{Cint}, index_nz_u::Vector{Cint}, + u::Vector{Float64}, got_h::Bool, userdata::userdata_type) + p = userdata.p + freq = userdata.freq + mag = userdata.mag + p = zeros(Float64, 3) + used = falses(3) for i in 1:nnz_v j = index_nz_v[i] if j == 1 - p[1] += 2.0 * v[1] - mag * freq^2 * cos(freq * var[1]) * v[1] + p[1] = p[1] + 2.0 * v[1] - mag * freq^2 * cos(freq * x[1]) * v[1] used[1] = true - p[3] += 2.0 * v[1] + p[3] = p[3] + 2.0 * v[1] used[3] = true elseif j == 2 - p[2] += 2.0 * v[2] + p[2] = p[2] + 2.0 * v[2] used[2] = true - p[3] += 2.0 * v[2] + p[3] = p[3] + 2.0 * v[2] used[3] = true elseif j == 3 - p[1] += 2.0 * v[3] + p[1] = p[1] + 2.0 * v[3] used[1] = true - p[2] += 2.0 * v[3] + p[2] = p[2] + 2.0 * v[3] used[2] = true - p[3] += 4.0 * v[3] + p[3] = p[3] + 4.0 * v[3] used[3] = true end end - nnz = 0 + nnz_u[] = 0 for j in 1:3 if used[j] u[j] = p[j] - nnz += 1 - index_nz_u[nnz] = j + nnz_u[] += 1 + index_nz_u[nnz_u[]] = j end end - unsafe_store!(nnz_u, nnz) return 0 end # Apply preconditioner - function prec(n::Int, var::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, + function prec(n::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, userdata::userdata_type) u[1] = 0.5 * v[1] u[2] = 0.5 * v[2] @@ -159,6 +125,84 @@ function test_bgo() return 0 end + # Objective function + function fun_diag(n::Int, x::Vector{Float64}, f::Ref{Float64}, userdata) + p = userdata.p + freq = userdata.freq + mag = userdata.mag + + f[] = (x[3] + p)^2 + x[2]^2 + mag * cos(freq * x[1]) + sum(x) + return 0 + end + + # Gradient of the objective + function grad_diag(n::Int, x::Vector{Float64}, g::Vector{Float64}, userdata) + p = userdata.p + freq = userdata.freq + mag = userdata.mag + + g[1] = -mag * freq * sin(freq * x[1]) + 1 + g[2] = 2.0 * x[2] + 1 + g[3] = 2.0 * (x[3] + p) + 1 + return 0 + end + + # Hessian of the objective + function hess_diag(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, userdata) + freq = userdata.freq + mag = userdata.mag + + hval[1] = -mag * freq^2 * cos(freq * x[1]) + hval[2] = 2.0 + hval[3] = 2.0 + return 0 + end + + # Hessian-vector product + function hessprod_diag(n::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, + got_h::Bool, userdata) + freq = userdata.freq + mag = userdata.mag + + u[1] += -mag * freq^2 * cos(freq * x[1]) * v[1] + u[2] += 2.0 * v[2] + u[3] += 2.0 * v[3] + return 0 + end + + # Sparse Hessian-vector product + function shessprod_diag(n::Int, x::Vector{Float64}, nnz_v::Cint, index_nz_v::Vector{Cint}, + v::Vector{Float64}, nnz_u::Ref{Cint}, index_nz_u::Vector{Cint}, + u::Vector{Float64}, got_h::Bool, userdata) + freq = userdata.freq + mag = userdata.mag + + p = zeros(3) + used = falses(3) + for i in 1:nnz_v + j = index_nz_v[i] + if j == 1 + p[1] -= mag * freq^2 * cos(freq * x[1]) * v[1] + used[1] = true + elseif j == 2 + p[2] += 2.0 * v[2] + used[2] = true + elseif j == 3 + p[3] += 2.0 * v[3] + used[3] = true + end + end + nnz_u[] = 0 + for j in 1:3 + if used[j] + u[j] = p[j] + nnz_u[] += 1 + index_nz_u[nnz_u[]] = j + end + end + return 0 + end + # Derived types data = Ref{Ptr{Cvoid}}() control = Ref{bgo_control_type{Float64}}() @@ -204,11 +248,11 @@ function test_bgo() # Set user-defined control options @reset control[].f_indexing = true # Fortran sparse matrix indexing - @reset control[].attempts_max = 10000 - @reset control[].max_evals = 20000 - @reset control[].sampling_strategy = 3 - @reset control[].trb_control.maxit = 100 - # @reset control[].print_level = 1 + @reset control[].attempts_max = Cint(10000) + @reset control[].max_evals = Cint(20000) + @reset control[].sampling_strategy = Cint(3) + @reset control[].trb_control.maxit = Cint(100) + # @reset control[].print_level = CInt(1) # Start from 0 x = Float64[0.0, 0.0, 0.0] @@ -222,34 +266,34 @@ function test_bgo() terminated = false while !terminated # reverse-communication loop bgo_solve_reverse_with_mat(data, status, eval_status, - n, x, f, g, ne, H_val, u, v) + n, x, f[], g, ne, H_val, u, v) if status[] == 0 # successful termination terminated = true elseif status[] < 0 # error exit terminated = true elseif status[] == 2 # evaluate f - eval_status = fun(n, x, f, userdata) + eval_status[] = fun(n, x, f, userdata) elseif status[] == 3 # evaluate g - eval_status = grad(n, x, g, userdata) + eval_status[] = grad(n, x, g, userdata) elseif status[] == 4 # evaluate H - eval_status = hess(n, ne, x, H_val, userdata) + eval_status[] = hess(n, ne, x, H_val, userdata) elseif status[] == 5 # evaluate Hv product - eval_status = hessprod(n, x, u, v, false, userdata) + eval_status[] = hessprod(n, x, u, v, false, userdata) elseif status[] == 6 # evaluate the product with P - eval_status = prec(n, x, u, v, userdata) + eval_status[] = prec(n, x, u, v, userdata) elseif status[] == 23 # evaluate f and g - eval_status = fun(n, x, f, userdata) - eval_status = grad(n, x, g, userdata) + eval_status[] = fun(n, x, f, userdata) + eval_status[] = grad(n, x, g, userdata) elseif status[] == 25 # evaluate f and Hv product - eval_status = fun(n, x, f, userdata) - eval_status = hessprod(n, x, u, v, false, userdata) + eval_status[] = fun(n, x, f, userdata) + eval_status[] = hessprod(n, x, u, v, false, userdata) elseif status[] == 35 # evaluate g and Hv product - eval_status = grad(n, x, g, userdata) - eval_status = hessprod(n, x, u, v, false, userdata) + eval_status[] = grad(n, x, g, userdata) + eval_status[] = hessprod(n, x, u, v, false, userdata) elseif status[] == 235 # evaluate f, g and Hv product - eval_status = fun(n, x, f, userdata) - eval_status = grad(n, x, g, userdata) - eval_status = hessprod(n, x, u, v, false, userdata) + eval_status[] = fun(n, x, f, userdata) + eval_status[] = grad(n, x, g, userdata) + eval_status[] = hessprod(n, x, u, v, false, userdata) else @printf(" the value %1i of status should not occur\n", status) @@ -266,34 +310,34 @@ function test_bgo() terminated = false while !terminated # reverse-communication loop bgo_solve_reverse_with_mat(data, status, eval_status, - n, x, f, g, ne, H_val, u, v) + n, x, f[], g, ne, H_val, u, v) if status[] == 0 # successful termination terminated = true elseif status[] < 0 # error exit terminated = true elseif status[] == 2 # evaluate f - eval_status = fun(n, x, f, userdata) + eval_status[] = fun(n, x, f, userdata) elseif status[] == 3 # evaluate g - eval_status = grad(n, x, g, userdata) + eval_status[] = grad(n, x, g, userdata) elseif status[] == 4 # evaluate H - eval_status = hess(n, ne, x, H_val, userdata) + eval_status[] = hess(n, ne, x, H_val, userdata) elseif status[] == 5 # evaluate Hv product - eval_status = hessprod(n, x, u, v, false, userdata) + eval_status[] = hessprod(n, x, u, v, false, userdata) elseif status[] == 6 # evaluate the product with P - eval_status = prec(n, x, u, v, userdata) + eval_status[] = prec(n, x, u, v, userdata) elseif status[] == 23 # evaluate f and g - eval_status = fun(n, x, f, userdata) - eval_status = grad(n, x, g, userdata) + eval_status[] = fun(n, x, f, userdata) + eval_status[] = grad(n, x, g, userdata) elseif status[] == 25 # evaluate f and Hv product - eval_status = fun(n, x, f, userdata) - eval_status = hessprod(n, x, u, v, false, userdata) + eval_status[] = fun(n, x, f, userdata) + eval_status[] = hessprod(n, x, u, v, false, userdata) elseif status[] == 35 # evaluate g and Hv product - eval_status = grad(n, x, g, userdata) - eval_status = hessprod(n, x, u, v, false, userdata) + eval_status[] = grad(n, x, g, userdata) + eval_status[] = hessprod(n, x, u, v, false, userdata) elseif status[] == 235 # evaluate f, g and Hv product - eval_status = fun(n, x, f, userdata) - eval_status = grad(n, x, g, userdata) - eval_status = hessprod(n, x, u, v, false, userdata) + eval_status[] = fun(n, x, f, userdata) + eval_status[] = grad(n, x, g, userdata) + eval_status[] = hessprod(n, x, u, v, false, userdata) else @printf(" the value %1i of status should not occur\n", status) end @@ -309,36 +353,35 @@ function test_bgo() terminated = false while !terminated # reverse-communication loop bgo_solve_reverse_with_mat(data, status, eval_status, - n, x, f, g, n * (n + 1) / 2, + n, x, f[], g, div(n * (n + 1), 2), H_dense, u, v) if status[] == 0 # successful termination terminated = true elseif status[] < 0 # error exit terminated = true elseif status[] == 2 # evaluate f - eval_status = fun(n, x, f, userdata) + eval_status[] = fun(n, x, f, userdata) elseif status[] == 3 # evaluate g - eval_status = grad(n, x, g, userdata) + eval_status[] = grad(n, x, g, userdata) elseif status[] == 4 # evaluate H - eval_status = hess_dense(n, n * (n + 1) / 2, x, H_dense, - userdata) + eval_status[] = hess_dense(n, div(n * (n + 1), 2), x, H_dense, userdata) elseif status[] == 5 # evaluate Hv product - eval_status = hessprod(n, x, u, v, false, userdata) + eval_status[] = hessprod(n, x, u, v, false, userdata) elseif status[] == 6 # evaluate the product with P - eval_status = prec(n, x, u, v, userdata) + eval_status[] = prec(n, x, u, v, userdata) elseif status[] == 23 # evaluate f and g - eval_status = fun(n, x, f, userdata) - eval_status = grad(n, x, g, userdata) + eval_status[] = fun(n, x, f, userdata) + eval_status[] = grad(n, x, g, userdata) elseif status[] == 25 # evaluate f and Hv product - eval_status = fun(n, x, f, userdata) - eval_status = hessprod(n, x, u, v, false, userdata) + eval_status[] = fun(n, x, f, userdata) + eval_status[] = hessprod(n, x, u, v, false, userdata) elseif status[] == 35 # evaluate g and Hv product - eval_status = grad(n, x, g, userdata) - eval_status = hessprod(n, x, u, v, false, userdata) + eval_status[] = grad(n, x, g, userdata) + eval_status[] = hessprod(n, x, u, v, false, userdata) elseif status[] == 235 # evaluate f, g and Hv product - eval_status = fun(n, x, f, userdata) - eval_status = grad(n, x, g, userdata) - eval_status = hessprod(n, x, u, v, false, userdata) + eval_status[] = fun(n, x, f, userdata) + eval_status[] = grad(n, x, g, userdata) + eval_status[] = hessprod(n, x, u, v, false, userdata) else @printf(" the value %1i of status should not occur\n", status) end @@ -354,38 +397,37 @@ function test_bgo() terminated = false while !terminated # reverse-communication loop bgo_solve_reverse_with_mat(data, status, eval_status, - n, x, f, g, n, H_diag, u, v) + n, x, f[], g, n, H_diag, u, v) if status[] == 0 # successful termination terminated = true elseif status[] < 0 # error exit terminated = true elseif status[] == 2 # evaluate f - eval_status = fun_diag(n, x, f, userdata) + eval_status[] = fun_diag(n, x, f, userdata) elseif status[] == 3 # evaluate g - eval_status = grad_diag(n, x, g, userdata) + eval_status[] = grad_diag(n, x, g, userdata) elseif status[] == 4 # evaluate H - eval_status = hess_diag(n, n, x, H_diag, userdata) + eval_status[] = hess_diag(n, n, x, H_diag, userdata) elseif status[] == 5 # evaluate Hv product - eval_status = hessprod_diag(n, x, u, v, false, - userdata) + eval_status[] = hessprod_diag(n, x, u, v, false, userdata) elseif status[] == 6 # evaluate the product with P - eval_status = prec(n, x, u, v, userdata) + eval_status[] = prec(n, x, u, v, userdata) elseif status[] == 23 # evaluate f and g - eval_status = fun_diag(n, x, f, userdata) - eval_status = grad_diag(n, x, g, userdata) + eval_status[] = fun_diag(n, x, f, userdata) + eval_status[] = grad_diag(n, x, g, userdata) elseif status[] == 25 # evaluate f and Hv product - eval_status = fun_diag(n, x, f, userdata) - eval_status = hessprod_diag(n, x, u, v, false, - userdata) + eval_status[] = fun_diag(n, x, f, userdata) + eval_status[] = hessprod_diag(n, x, u, v, false, + userdata) elseif status[] == 35 # evaluate g and Hv product - eval_status = grad_diag(n, x, g, userdata) - eval_status = hessprod_diag(n, x, u, v, false, - userdata) + eval_status[] = grad_diag(n, x, g, userdata) + eval_status[] = hessprod_diag(n, x, u, v, false, + userdata) elseif status[] == 235 # evaluate f, g and Hv product - eval_status = fun_diag(n, x, f, userdata) - eval_status = grad_diag(n, x, g, userdata) - eval_status = hessprod_diag(n, x, u, v, false, - userdata) + eval_status[] = fun_diag(n, x, f, userdata) + eval_status[] = grad_diag(n, x, g, userdata) + eval_status[] = hessprod_diag(n, x, u, v, false, + userdata) else @printf(" the value %1i of status should not occur\n", status) end @@ -397,42 +439,42 @@ function test_bgo() st = 'P' bgo_import(control, data, status, n, x_l, x_u, "absent", ne, C_NULL, C_NULL, C_NULL) - nnz_u = 0 + nnz_u = Ref{Cint}(0) terminated = false while !terminated # reverse-communication loop bgo_solve_reverse_without_mat(data, status, eval_status, - n, x, f, g, u, v, index_nz_v, - nnz_v, index_nz_u, nnz_u) + n, x, f[], g, u, v, index_nz_v, + nnz_v, index_nz_u, nnz_u[]) if status[] == 0 # successful termination terminated = true elseif status[] < 0 # error exit terminated = true elseif status[] == 2 # evaluate f - eval_status = fun(n, x, f, userdata) + eval_status[] = fun(n, x, f, userdata) elseif status[] == 3 # evaluate g - eval_status = grad(n, x, g, userdata) + eval_status[] = grad(n, x, g, userdata) elseif status[] == 5 # evaluate Hv product - eval_status = hessprod(n, x, u, v, false, userdata) + eval_status[] = hessprod(n, x, u, v, false, userdata) elseif status[] == 6 # evaluate the product with P - eval_status = prec(n, x, u, v, userdata) + eval_status[] = prec(n, x, u, v, userdata) elseif status[] == 7 # evaluate sparse Hess-vect product - eval_status = shessprod(n, x, nnz_v, index_nz_v, v, - nnz_u, index_nz_u, u, - false, userdata) + eval_status[] = shessprod(n, x, nnz_v[], index_nz_v, v, + nnz_u, index_nz_u, u, + false, userdata) elseif status[] == 23 # evaluate f and g - eval_status = fun(n, x, f, userdata) - eval_status = grad(n, x, g, userdata) + eval_status[] = fun(n, x, f, userdata) + eval_status[] = grad(n, x, g, userdata) elseif status[] == 25 # evaluate f and Hv product - eval_status = fun(n, x, f, userdata) - eval_status = hessprod(n, x, u, v, false, userdata) + eval_status[] = fun(n, x, f, userdata) + eval_status[] = hessprod(n, x, u, v, false, userdata) elseif status[] == 35 # evaluate g and Hv product - eval_status = grad(n, x, g, userdata) - eval_status = hessprod(n, x, u, v, false, userdata) + eval_status[] = grad(n, x, g, userdata) + eval_status[] = hessprod(n, x, u, v, false, userdata) elseif status[] == 235 # evaluate f, g and Hv product - eval_status = fun(n, x, f, userdata) - eval_status = grad(n, x, g, userdata) - eval_status = hessprod(n, x, u, v, false, userdata) + eval_status[] = fun(n, x, f, userdata) + eval_status[] = grad(n, x, g, userdata) + eval_status[] = hessprod(n, x, u, v, false, userdata) else @printf(" the value %1i of status should not occur\n", status) From 0671e036d9ce6a27c0bcf06205739c85a0a3e2cc Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Tue, 13 Feb 2024 17:01:21 -0500 Subject: [PATCH 31/33] Last examples --- GALAHAD.jl/test/runtests.jl | 4 +- GALAHAD.jl/test/test_dgo.jl | 685 ++++++++++++++--------------------- GALAHAD.jl/test/test_slls.jl | 5 +- GALAHAD.jl/test/test_trb.jl | 129 +++---- src/trb/C/trbtf.c | 6 +- 5 files changed, 330 insertions(+), 499 deletions(-) diff --git a/GALAHAD.jl/test/runtests.jl b/GALAHAD.jl/test/runtests.jl index d8ec58c181..46e038508c 100644 --- a/GALAHAD.jl/test/runtests.jl +++ b/GALAHAD.jl/test/runtests.jl @@ -15,7 +15,7 @@ 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_eqp.jl") @@ -51,7 +51,7 @@ include("test_sha.jl") include("test_sils.jl") ## include("test_slls.jl") include("test_sls.jl") -## include("test_trb.jl") +include("test_trb.jl") include("test_trs.jl") include("test_tru.jl") include("test_ugo.jl") diff --git a/GALAHAD.jl/test/test_dgo.jl b/GALAHAD.jl/test/test_dgo.jl index b2c167968e..9ec4881d7d 100644 --- a/GALAHAD.jl/test/test_dgo.jl +++ b/GALAHAD.jl/test/test_dgo.jl @@ -16,258 +16,192 @@ end function test_dgo() # Objective function - function fun(n::Int, var::Vector{Float64}, f::Ref{Float64}, userdata::userdata_type) + function fun(n::Int, x::Vector{Float64}, f::Ref{Float64}, userdata::userdata_type) p = userdata.p freq = userdata.freq mag = userdata.mag + f[] = (x[1] + x[3] + p)^2 + (x[2] + x[3])^2 + mag * cos(freq * x[1]) + x[1] + x[2] + x[3] + return 0 + end - f[] = (x[1] + x[3] + p)^2 + (x[2] + x[3])^2 + mag * cos(freq * x[1]) + x[1] + x[2] + - x[3] + # Gradient of the objective + function grad(n::Int, x::Vector{Float64}, g::Vector{Float64}, userdata::userdata_type) + p = userdata.p + freq = userdata.freq + mag = userdata.mag + g[1] = 2.0 * (x[1] + x[3] + p) - mag * freq * sin(freq * x[1]) + 1.0 + g[2] = 2.0 * (x[2] + x[3]) + 1.0 + g[3] = 2.0 * (x[1] + x[3] + p) + 2.0 * (x[2] + x[3]) + 1.0 + return 0 + end + + # Hessian of the objective + function hess(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, + userdata::userdata_type) + p = userdata.p + freq = userdata.freq + mag = userdata.mag + hval[1] = 2.0 - mag * freq^2 * cos(freq * x[1]) + hval[2] = 2.0 + hval[3] = 2.0 + hval[4] = 4.0 + return 0 + end + + # Dense Hessian + function hess_dense(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, + userdata::userdata_type) + p = userdata.p + freq = userdata.freq + mag = userdata.mag + hval[1] = 2.0 - mag * freq^2 * cos(freq * x[1]) + hval[2] = 0.0 + hval[3] = 2.0 + hval[4] = 2.0 + hval[5] = 4.0 + return 0 + end + + # Hessian-vector product + function hessprod(n::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, + got_h::Bool, userdata::userdata_type) + p = userdata.p + freq = userdata.freq + mag = userdata.mag + u[1] = u[1] + 2.0 * (v[1] + v[3]) - mag * freq^2 * cos(freq * x[1]) * v[1] + u[2] = u[2] + 2.0 * (v[2] + v[3]) + u[3] = u[3] + 2.0 * (v[1] + v[2] + 2.0 * v[3]) + return 0 + end + + # Sparse Hessian-vector product + function shessprod(n::Int, x::Vector{Float64}, nnz_v::Cint, index_nz_v::Vector{Cint}, + v::Vector{Float64}, nnz_u::Ref{Cint}, index_nz_u::Vector{Cint}, + u::Vector{Float64}, got_h::Bool, userdata::userdata_type) + p = userdata.p + freq = userdata.freq + mag = userdata.mag + p = zeros(Float64, 3) + used = falses(3) + for i in 1:nnz_v + j = index_nz_v[i] + if j == 1 + p[1] = p[1] + 2.0 * v[1] - mag * freq^2 * cos(freq * x[1]) * v[1] + used[1] = true + p[3] = p[3] + 2.0 * v[1] + used[3] = true + elseif j == 2 + p[2] = p[2] + 2.0 * v[2] + used[2] = true + p[3] = p[3] + 2.0 * v[2] + used[3] = true + elseif j == 3 + p[1] = p[1] + 2.0 * v[3] + used[1] = true + p[2] = p[2] + 2.0 * v[3] + used[2] = true + p[3] = p[3] + 4.0 * v[3] + used[3] = true + end + end + + nnz_u[] = 0 + for j in 1:3 + if used[j] + u[j] = p[j] + nnz_u[] += 1 + index_nz_u[nnz_u[]] = j + end + end + return 0 + end + + # Apply preconditioner + function prec(n::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, + userdata::userdata_type) + u[1] = 0.5 * v[1] + u[2] = 0.5 * v[2] + u[3] = 0.25 * v[3] + return 0 + end + + # Objective function + function fun_diag(n::Int, x::Vector{Float64}, f::Ref{Float64}, userdata) + p = userdata.p + freq = userdata.freq + mag = userdata.mag + + f[] = (x[3] + p)^2 + x[2]^2 + mag * cos(freq * x[1]) + sum(x) return 0 end # Gradient of the objective - function grad(n::Int, var::Vector{Float64}, g::Vector{Float64}, userdata::userdata_type) + function grad_diag(n::Int, x::Vector{Float64}, g::Vector{Float64}, userdata) p = userdata.p freq = userdata.freq mag = userdata.mag - g[1] = 2.0 * (x[1] + x[3] + p) - mag * freq * sin(freq * x[1]) + 1 - g[2] = 2.0 * (x[2] + x[3]) + 1 - g[3] = 2.0 * (x[1] + x[3] + p) + 2.0 * (x[2] + x[3]) + 1 + g[1] = -mag * freq * sin(freq * x[1]) + 1 + g[2] = 2.0 * x[2] + 1 + g[3] = 2.0 * (x[3] + p) + 1 + return 0 + end + + # Hessian of the objective + function hess_diag(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, userdata) + freq = userdata.freq + mag = userdata.mag + + hval[1] = -mag * freq^2 * cos(freq * x[1]) + hval[2] = 2.0 + hval[3] = 2.0 + return 0 + end + + # Hessian-vector product + function hessprod_diag(n::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, + got_h::Bool, userdata) + freq = userdata.freq + mag = userdata.mag + + u[1] += -mag * freq^2 * cos(freq * x[1]) * v[1] + u[2] += 2.0 * v[2] + u[3] += 2.0 * v[3] return 0 end - # # Hessian of the objective - # int hess(int n, - # int ne, - # var::Vector{Float64}, - # hval::Vector{Float64}, - # const void *userdata) - # struct userdata_type *myuserdata = (struct userdata_type *) userdata - # real_wp_ freq = myuserdata->freq - # real_wp_ mag = myuserdata->mag - - # hval[0] = 2.0 - mag * freq * freq * cos(freq*x[0]) - # hval[1] = 2.0 - # hval[2] = 2.0 - # hval[3] = 2.0 - # hval[4] = 4.0 - # return 0 - # ] - - # # Dense Hessian - # int hess_dense(int n, - # int ne, - # var::Vector{Float64}, - # hval::Vector{Float64}, - # const void *userdata) - # struct userdata_type *myuserdata = (struct userdata_type *) userdata - # real_wp_ freq = myuserdata->freq - # real_wp_ mag = myuserdata->mag - - # hval[0] = 2.0 - mag * freq * freq * cos(freq*x[0]) - # hval[1] = 0.0 - # hval[2] = 2.0 - # hval[3] = 2.0 - # hval[4] = 2.0 - # hval[5] = 4.0 - # return 0 - # ] - - # # Hessian-vector product - # int hessprod(int n, - # var::Vector{Float64}, - # u::Vector{Float64}, - # var::Vector{Float64}, - # bool got_h, - # const void *userdata) - # struct userdata_type *myuserdata = (struct userdata_type *) userdata - # real_wp_ freq = myuserdata->freq - # real_wp_ mag = myuserdata->mag - - # u[0] = u[0] + 2.0 * (v[0] + v[2]) - # - mag * freq * freq * cos(freq*x[0]) * v[0] - # u[1] = u[1] + 2.0 * (v[1] + v[2]) - # u[2] = u[2] + 2.0 * (v[0] + v[1] + 2.0 * v[2]) - # return 0 - # ] - - # # Sparse Hessian-vector product - # int shessprod(int n, - # var::Vector{Float64}, - # int nnz_v, - # const int index_nz_v[], - # var::Vector{Float64}, - # int *nnz_u, - # int index_nz_u[], - # u::Vector{Float64}, - # bool got_h, - # const void *userdata) - # struct userdata_type *myuserdata = (struct userdata_type *) userdata - # real_wp_ freq = myuserdata->freq - # real_wp_ mag = myuserdata->mag - - # real_wp_ p[] = {0., 0., 0.] - # bool used[] = {false, false, false] - # for(int i = 0 i < nnz_v i++) - # int j = index_nz_v[i] - # switch(j) - # case 1: - # p[0] = p[0] + 2.0 * v[0] - # - mag * freq * freq * cos(freq*x[0]) * v[0] - # used[0] = true - # p[2] = p[2] + 2.0 * v[0] - # used[2] = true - # end - # case 2: - # p[1] = p[1] + 2.0 * v[1] - # used[1] = true - # p[2] = p[2] + 2.0 * v[1] - # used[2] = true - # end - # case 3: - # p[0] = p[0] + 2.0 * v[2] - # used[0] = true - # p[1] = p[1] + 2.0 * v[2] - # used[1] = true - # p[2] = p[2] + 4.0 * v[2] - # used[2] = true - # end - # ] - # ] - # *nnz_u = 0 - # for(int j = 0 j < 3 j++) - # if used[j]) - # u[j] = p[j] - # *nnz_u = *nnz_u + 1 - # index_nz_u[*nnz_u-1] = j+1 - # ] - # ] - # return 0 - # ] - - # # Apply preconditioner - # int prec(int n, - # var::Vector{Float64}, - # u::Vector{Float64}, - # var::Vector{Float64}, - # const void *userdata) - # u[0] = 0.5 * v[0] - # u[1] = 0.5 * v[1] - # u[2] = 0.25 * v[2] - # return 0 - # ] - - # # Objective function - # int fun_diag(int n, - # var::Vector{Float64}, - # real_wp_ *f, - # const void *userdata) - # struct userdata_type *myuserdata = (struct userdata_type *) userdata - # real_wp_ p = myuserdata->p - # real_wp_ freq = myuserdata->freq - # real_wp_ mag = myuserdata->mag - - # *f = pow(x[2] + p, 2) + pow(x[1], 2) + mag * cos(freq*x[0]) - # + x[0] + x[1] + x[2] - # return 0 - # ] - - # # Gradient of the objective - # int grad_diag(int n, - # var::Vector{Float64}, - # g::Vector{Float64}, - # const void *userdata) - # struct userdata_type *myuserdata = (struct userdata_type *) userdata - # real_wp_ p = myuserdata->p - # real_wp_ freq = myuserdata->freq - # real_wp_ mag = myuserdata->mag - - # g[0] = -mag * freq * sin(freq*x[0]) + 1 - # g[1] = 2.0 * x[1] + 1 - # g[2] = 2.0 * (x[2] + p) + 1 - # return 0 - # ] - - # # Hessian of the objective - # int hess_diag(int n, - # int ne, - # var::Vector{Float64}, - # hval::Vector{Float64}, - # const void *userdata) - # struct userdata_type *myuserdata = (struct userdata_type *) userdata - # real_wp_ freq = myuserdata->freq - # real_wp_ mag = myuserdata->mag - - # hval[0] = -mag * freq * freq * cos(freq*x[0]) - # hval[1] = 2.0 - # hval[2] = 2.0 - # return 0 - # ] - - # # Hessian-vector product - # int hessprod_diag(int n, - # var::Vector{Float64}, - # u::Vector{Float64}, - # var::Vector{Float64}, - # bool got_h, - # const void *userdata) - # struct userdata_type *myuserdata = (struct userdata_type *) userdata - # real_wp_ freq = myuserdata->freq - # real_wp_ mag = myuserdata->mag - - # u[0] = u[0] + -mag * freq * freq * cos(freq*x[0]) * v[0] - # u[1] = u[1] + 2.0 * v[1] - # u[2] = u[2] + 2.0 * v[2] - # return 0 - # ] - - # # Sparse Hessian-vector product - # int shessprod_diag(int n, - # var::Vector{Float64}, - # int nnz_v, - # const int index_nz_v[], - # var::Vector{Float64}, - # int *nnz_u, - # int index_nz_u[], - # u::Vector{Float64}, - # bool got_h, - # const void *userdata) - # struct userdata_type *myuserdata = (struct userdata_type *) userdata - # real_wp_ freq = myuserdata->freq - # real_wp_ mag = myuserdata->mag - - # real_wp_ p[] = {0., 0., 0.] - # bool used[] = {false, false, false] - # for(int i = 0 i < nnz_v i++) - # int j = index_nz_v[i] - # switch(j) - # case 1: - # p[0] = p[0] - mag * freq * freq * cos(freq*x[0]) * v[0] - # used[0] = true - # end - # case 2: - # p[1] = p[1] + 2.0 * v[1] - # used[1] = true - # end - # case 3: - # p[2] = p[2] + 2.0 * v[2] - # used[2] = true - # end - # ] - # ] - # *nnz_u = 0 - # for(int j = 0 j < 3 j++) - # if used[j]) - # u[j] = p[j] - # *nnz_u = *nnz_u + 1 - # index_nz_u[*nnz_u-1] = j+1 - # ] - # ] - # return 0 - # ] - # end + # Sparse Hessian-vector product + function shessprod_diag(n::Int, x::Vector{Float64}, nnz_v::Cint, index_nz_v::Vector{Cint}, + v::Vector{Float64}, nnz_u::Ref{Cint}, index_nz_u::Vector{Cint}, + u::Vector{Float64}, got_h::Bool, userdata) + freq = userdata.freq + mag = userdata.mag + + p = zeros(3) + used = falses(3) + for i in 1:nnz_v + j = index_nz_v[i] + if j == 1 + p[1] -= mag * freq^2 * cos(freq * x[1]) * v[1] + used[1] = true + elseif j == 2 + p[2] += 2.0 * v[2] + used[2] = true + elseif j == 3 + p[3] += 2.0 * v[3] + used[3] = true + end + end + nnz_u[] = 0 + for j in 1:3 + if used[j] + u[j] = p[j] + nnz_u[] += 1 + index_nz_u[nnz_u[]] = j + end + end + return 0 + end # Derived types data = Ref{Ptr{Cvoid}}() @@ -292,113 +226,20 @@ function test_dgo() status = Ref{Cint}() @printf(" Fortran sparse matrix indexing\n\n") - @printf(" tests options for all-in-one storage format\n\n") - - for d in 1:5 - - # Initialize DGO - dgo_initialize(data, control, status) - - # Set user-defined control options - @reset control[].f_indexing = true # Fortran sparse matrix indexing - @reset control[].maxit = 2500 - # @reset control[].trb_control[].maxit = 100 - # @reset control[].print_level = 1 - - # Start from 0 - x = Float64[0, 0, 0] - - # sparse co-ordinate storage - if d == 1 - st = 'C' - dgo_import(control, data, status, n, x_l, x_u, - "coordinate", ne, H_row, H_col, C_NULL) - - dgo_solve_with_mat(data, userdata, status, n, x, g, - ne, fun, grad, hess, hessprod, prec) - end - - # sparse by rows - if d == 2 - st = 'R' - dgo_import(control, data, status, n, x_l, x_u, - "sparse_by_rows", ne, C_NULL, H_col, H_ptr) - - dgo_solve_with_mat(data, userdata, status, n, x, g, - ne, fun, grad, hess, hessprod, prec) - end - - # dense - if d == 3 - st = 'D' - dgo_import(control, data, status, n, x_l, x_u, - "dense", ne, C_NULL, C_NULL, C_NULL) - - dgo_solve_with_mat(data, userdata, status, n, x, g, - ne, fun, grad, hess_dense, hessprod, prec) - end - - # diagonal - if d == 4 - st = 'I' - dgo_import(control, data, status, n, x_l, x_u, - "diagonal", ne, C_NULL, C_NULL, C_NULL) - - dgo_solve_with_mat(data, userdata, status, n, x, g, - ne, fun_diag, grad_diag, hess_diag, - hessprod_diag, prec) - end - - # access by products - if d == 5 - st = 'P' - dgo_import(control, data, status, n, x_l, x_u, - "absent", ne, C_NULL, C_NULL, C_NULL) - - dgo_solve_without_mat(data, userdata, status, n, x, g, - fun, grad, hessprod, shessprod, prec) - end - - # Record solution information - dgo_information(data, inform, status) - - if inform[].status[] == 0 - @printf("%c:%6i evaluations. Optimal objective value = %5.2f status = %1i\n", st, - inform[].f_eval, inform[].obj, inform[].status) - elseif inform[].status[] == -18 - @printf("%c:%6i evaluations. Best objective value = %5.2f status = %1i\n", st, - inform[].f_eval, inform[].obj, inform[].status) - else - @printf("%c: DGO_solve exit status = %1i\n", st, inform[].status) - end - - # @printf("x: ") - # for i in 1:n - # @printf("%f ", x[i]) - # end - # @printf("\n") - # @printf("gradient: ") - # for i in 1:n - # @printf("%f ", g[i]) - # end - # @printf("\n") - - # Delete internal workspace - dgo_terminate(data, control, inform) - end - - @printf("\n tests reverse-communication options\n\n") + @printf(" tests reverse-communication options\n\n") # reverse-communication input/output eval_status = Ref{Cint}() nnz_u = Ref{Cint}() nnz_v = Ref{Cint}() - f = 0.0 + f = Ref{Float64}(0.0) u = zeros(Float64, n) v = zeros(Float64, n) index_nz_u = zeros(Cint, n) index_nz_v = zeros(Cint, n) - # real_wp_ H_val[ne], H_dense[n*(n+1)/2], H_diag[n] + H_val = zeros(Float64, ne) + H_dense = zeros(Float64, div(n * (n + 1), 2)) + H_diag = zeros(Float64, n) for d in 1:5 # Initialize DGO @@ -406,9 +247,9 @@ function test_dgo() # Set user-defined control options @reset control[].f_indexing = true # Fortran sparse matrix indexing - @reset control[].maxit = 2500 - # @reset control[].trb_control[].maxit = 100 - # @reset control[].print_level = 1 + @reset control[].maxit = Cint(2500) + # @reset control[].trb_control[].maxit = Cint(100) + # @reset control[].print_level = Cint(1) # Start from 0 x = Float64[0.0, 0.0, 0.0] @@ -420,34 +261,34 @@ function test_dgo() terminated = false while !terminated # reverse-communication loop - dgo_solve_reverse_with_mat(data, status, eval_status, n, x, f, g, ne, H_val, u, v) + dgo_solve_reverse_with_mat(data, status, eval_status, n, x, f[], g, ne, H_val, u, v) if status[] == 0 # successful termination terminated = true elseif status[] < 0 # error exit terminated = true elseif status[] == 2 # evaluate f - eval_status = fun(n, x, f, userdata) + eval_status[] = fun(n, x, f, userdata) elseif status[] == 3 # evaluate g - eval_status = grad(n, x, g, userdata) + eval_status[] = grad(n, x, g, userdata) elseif status[] == 4 # evaluate H - eval_status = hess(n, ne, x, H_val, userdata) + eval_status[] = hess(n, ne, x, H_val, userdata) elseif status[] == 5 # evaluate Hv product - eval_status = hessprod(n, x, u, v, false, userdata) + eval_status[] = hessprod(n, x, u, v, false, userdata) elseif status[] == 6 # evaluate the product with P - eval_status = prec(n, x, u, v, userdata) + eval_status[] = prec(n, x, u, v, userdata) elseif status[] == 23 # evaluate f and g - eval_status = fun(n, x, f, userdata) - eval_status = grad(n, x, g, userdata) + eval_status[] = fun(n, x, f, userdata) + eval_status[] = grad(n, x, g, userdata) elseif status[] == 25 # evaluate f and Hv product - eval_status = fun(n, x, f, userdata) - eval_status = hessprod(n, x, u, v, false, userdata) + eval_status[] = fun(n, x, f, userdata) + eval_status[] = hessprod(n, x, u, v, false, userdata) elseif status[] == 35 # evaluate g and Hv product - eval_status = grad(n, x, g, userdata) - eval_status = hessprod(n, x, u, v, false, userdata) + eval_status[] = grad(n, x, g, userdata) + eval_status[] = hessprod(n, x, u, v, false, userdata) elseif status[] == 235 # evaluate f, g and Hv product - eval_status = fun(n, x, f, userdata) - eval_status = grad(n, x, g, userdata) - eval_status = hessprod(n, x, u, v, false, userdata) + eval_status[] = fun(n, x, f, userdata) + eval_status[] = grad(n, x, g, userdata) + eval_status[] = hessprod(n, x, u, v, false, userdata) else @printf(" the value %1i of status should not occur\n", status) end @@ -463,34 +304,34 @@ function test_dgo() terminated = false while !terminated # reverse-communication loop dgo_solve_reverse_with_mat(data, status, eval_status, - n, x, f, g, ne, H_val, u, v) + n, x, f[], g, ne, H_val, u, v) if status[] == 0 # successful termination terminated = true elseif status[] < 0 # error exit terminated = true elseif status[] == 2 # evaluate f - eval_status = fun(n, x, f, userdata) + eval_status[] = fun(n, x, f, userdata) elseif status[] == 3 # evaluate g - eval_status = grad(n, x, g, userdata) + eval_status[] = grad(n, x, g, userdata) elseif status[] == 4 # evaluate H - eval_status = hess(n, ne, x, H_val, userdata) + eval_status[] = hess(n, ne, x, H_val, userdata) elseif status[] == 5 # evaluate Hv product - eval_status = hessprod(n, x, u, v, false, userdata) + eval_status[] = hessprod(n, x, u, v, false, userdata) elseif status[] == 6 # evaluate the product with P - eval_status = prec(n, x, u, v, userdata) + eval_status[] = prec(n, x, u, v, userdata) elseif status[] == 23 # evaluate f and g - eval_status = fun(n, x, f, userdata) - eval_status = grad(n, x, g, userdata) + eval_status[] = fun(n, x, f, userdata) + eval_status[] = grad(n, x, g, userdata) elseif status[] == 25 # evaluate f and Hv product - eval_status = fun(n, x, f, userdata) - eval_status = hessprod(n, x, u, v, false, userdata) + eval_status[] = fun(n, x, f, userdata) + eval_status[] = hessprod(n, x, u, v, false, userdata) elseif status[] == 35 # evaluate g and Hv product - eval_status = grad(n, x, g, userdata) - eval_status = hessprod(n, x, u, v, false, userdata) + eval_status[] = grad(n, x, g, userdata) + eval_status[] = hessprod(n, x, u, v, false, userdata) elseif status[] == 235 # evaluate f, g and Hv product - eval_status = fun(n, x, f, userdata) - eval_status = grad(n, x, g, userdata) - eval_status = hessprod(n, x, u, v, false, userdata) + eval_status[] = fun(n, x, f, userdata) + eval_status[] = grad(n, x, g, userdata) + eval_status[] = hessprod(n, x, u, v, false, userdata) else @printf(" the value %1i of status should not occur\n", status) end @@ -506,36 +347,35 @@ function test_dgo() terminated = false while !terminated # reverse-communication loop dgo_solve_reverse_with_mat(data, status, eval_status, - n, x, f, g, n * (n + 1) / 2, + n, x, f[], g, div(n * (n + 1), 2), H_dense, u, v) if status[] == 0 # successful termination terminated = true elseif status[] < 0 # error exit terminated = true elseif status[] == 2 # evaluate f - eval_status = fun(n, x, f, userdata) + eval_status[] = fun(n, x, f, userdata) elseif status[] == 3 # evaluate g - eval_status = grad(n, x, g, userdata) + eval_status[] = grad(n, x, g, userdata) elseif status[] == 4 # evaluate H - eval_status = hess_dense(n, n * (n + 1) / 2, x, H_dense, - userdata) + eval_status[] = hess_dense(n, div(n * (n + 1), 2), x, H_dense, userdata) elseif status[] == 5 # evaluate Hv product - eval_status = hessprod(n, x, u, v, false, userdata) + eval_status[] = hessprod(n, x, u, v, false, userdata) elseif status[] == 6 # evaluate the product with P - eval_status = prec(n, x, u, v, userdata) + eval_status[] = prec(n, x, u, v, userdata) elseif status[] == 23 # evaluate f and g - eval_status = fun(n, x, f, userdata) - eval_status = grad(n, x, g, userdata) + eval_status[] = fun(n, x, f, userdata) + eval_status[] = grad(n, x, g, userdata) elseif status[] == 25 # evaluate f and Hv product - eval_status = fun(n, x, f, userdata) - eval_status = hessprod(n, x, u, v, false, userdata) + eval_status[] = fun(n, x, f, userdata) + eval_status[] = hessprod(n, x, u, v, false, userdata) elseif status[] == 35 # evaluate g and Hv product - eval_status = grad(n, x, g, userdata) - eval_status = hessprod(n, x, u, v, false, userdata) + eval_status[] = grad(n, x, g, userdata) + eval_status[] = hessprod(n, x, u, v, false, userdata) elseif status[] == 235 # evaluate f, g and Hv product - eval_status = fun(n, x, f, userdata) - eval_status = grad(n, x, g, userdata) - eval_status = hessprod(n, x, u, v, false, userdata) + eval_status[] = fun(n, x, f, userdata) + eval_status[] = grad(n, x, g, userdata) + eval_status[] = hessprod(n, x, u, v, false, userdata) else @printf(" the value %1i of status should not occur\n", status) end @@ -551,38 +391,38 @@ function test_dgo() terminated = false while !terminated # reverse-communication loop dgo_solve_reverse_with_mat(data, status, eval_status, - n, x, f, g, n, H_diag, u, v) + n, x, f[], g, n, H_diag, u, v) if status[] == 0 # successful termination terminated = true elseif status[] < 0 # error exit terminated = true elseif status[] == 2 # evaluate f - eval_status = fun_diag(n, x, f, userdata) + eval_status[] = fun_diag(n, x, f, userdata) elseif status[] == 3 # evaluate g - eval_status = grad_diag(n, x, g, userdata) + eval_status[] = grad_diag(n, x, g, userdata) elseif status[] == 4 # evaluate H - eval_status = hess_diag(n, n, x, H_diag, userdata) + eval_status[] = hess_diag(n, n, x, H_diag, userdata) elseif status[] == 5 # evaluate Hv product - eval_status = hessprod_diag(n, x, u, v, false, - userdata) + eval_status[] = hessprod_diag(n, x, u, v, false, + userdata) elseif status[] == 6 # evaluate the product with P - eval_status = prec(n, x, u, v, userdata) + eval_status[] = prec(n, x, u, v, userdata) elseif status[] == 23 # evaluate f and g - eval_status = fun_diag(n, x, f, userdata) - eval_status = grad_diag(n, x, g, userdata) + eval_status[] = fun_diag(n, x, f, userdata) + eval_status[] = grad_diag(n, x, g, userdata) elseif status[] == 25 # evaluate f and Hv product - eval_status = fun_diag(n, x, f, userdata) - eval_status = hessprod_diag(n, x, u, v, false, - userdata) + eval_status[] = fun_diag(n, x, f, userdata) + eval_status[] = hessprod_diag(n, x, u, v, false, + userdata) elseif status[] == 35 # evaluate g and Hv product - eval_status = grad_diag(n, x, g, userdata) - eval_status = hessprod_diag(n, x, u, v, false, - userdata) + eval_status[] = grad_diag(n, x, g, userdata) + eval_status[] = hessprod_diag(n, x, u, v, false, + userdata) elseif status[] == 235 # evaluate f, g and Hv product - eval_status = fun_diag(n, x, f, userdata) - eval_status = grad_diag(n, x, g, userdata) - eval_status = hessprod_diag(n, x, u, v, false, - userdata) + eval_status[] = fun_diag(n, x, f, userdata) + eval_status[] = grad_diag(n, x, g, userdata) + eval_status[] = hessprod_diag(n, x, u, v, false, + userdata) else @printf(" the value %1i of status should not occur\n", status) end @@ -595,41 +435,41 @@ function test_dgo() dgo_import(control, data, status, n, x_l, x_u, "absent", ne, C_NULL, C_NULL, C_NULL) - nnz_u = 0 + nnz_u = Ref{Cint}(0) terminated = false while !terminated # reverse-communication loop dgo_solve_reverse_without_mat(data, status, eval_status, - n, x, f, g, u, v, index_nz_v, - nnz_v, index_nz_u, nnz_u) + n, x, f[], g, u, v, index_nz_v, + nnz_v, index_nz_u, nnz_u[]) if status[] == 0 # successful termination terminated = true elseif status[] < 0 # error exit terminated = true elseif status[] == 2 # evaluate f - eval_status = fun(n, x, f, userdata) + eval_status[] = fun(n, x, f, userdata) elseif status[] == 3 # evaluate g - eval_status = grad(n, x, g, userdata) + eval_status[] = grad(n, x, g, userdata) elseif status[] == 5 # evaluate Hv product - eval_status = hessprod(n, x, u, v, false, userdata) + eval_status[] = hessprod(n, x, u, v, false, userdata) elseif status[] == 6 # evaluate the product with P - eval_status = prec(n, x, u, v, userdata) + eval_status[] = prec(n, x, u, v, userdata) elseif status[] == 7 # evaluate sparse Hess-vect product - eval_status = shessprod(n, x, nnz_v, index_nz_v, v, - nnz_u, index_nz_u, u, - false, userdata) + eval_status[] = shessprod(n, x, nnz_v[], index_nz_v, v, + nnz_u, index_nz_u, u, + false, userdata) elseif status[] == 23 # evaluate f and g - eval_status = fun(n, x, f, userdata) - eval_status = grad(n, x, g, userdata) + eval_status[] = fun(n, x, f, userdata) + eval_status[] = grad(n, x, g, userdata) elseif status[] == 25 # evaluate f and Hv product - eval_status = fun(n, x, f, userdata) - eval_status = hessprod(n, x, u, v, false, userdata) + eval_status[] = fun(n, x, f, userdata) + eval_status[] = hessprod(n, x, u, v, false, userdata) elseif status[] == 35 # evaluate g and Hv product - eval_status = grad(n, x, g, userdata) - eval_status = hessprod(n, x, u, v, false, userdata) + eval_status[] = grad(n, x, g, userdata) + eval_status[] = hessprod(n, x, u, v, false, userdata) elseif status[] == 235 # evaluate f, g and Hv product - eval_status = fun(n, x, f, userdata) - eval_status = grad(n, x, g, userdata) - eval_status = hessprod(n, x, u, v, false, userdata) + eval_status[] = fun(n, x, f, userdata) + eval_status[] = grad(n, x, g, userdata) + eval_status[] = hessprod(n, x, u, v, false, userdata) else @printf(" the value %1i of status should not occur\n", status) end @@ -663,6 +503,7 @@ function test_dgo() # Delete internal workspace dgo_terminate(data, control, inform) end + return 0 end @testset "DGO" begin diff --git a/GALAHAD.jl/test/test_slls.jl b/GALAHAD.jl/test/test_slls.jl index 5426e028f8..47ff9b2f1a 100644 --- a/GALAHAD.jl/test/test_slls.jl +++ b/GALAHAD.jl/test/test_slls.jl @@ -12,10 +12,11 @@ mutable struct userdata_type end # Apply preconditioner -function prec(n::Int, var::Vector{Float64}, p::Vector{Float64}, userdata::userdata_type) +function prec(n::Int, x::Vector{Float64}, p::Vector{Float64}, userdata::userdata_type) scale = userdata.scale for i in 1:n - p[i] = scale * v[i] + p[i] = scale * x[i] + println(bob) end return 0 end diff --git a/GALAHAD.jl/test/test_trb.jl b/GALAHAD.jl/test/test_trb.jl index 393e727da7..26b1c9384c 100644 --- a/GALAHAD.jl/test/test_trb.jl +++ b/GALAHAD.jl/test/test_trb.jl @@ -13,14 +13,14 @@ end function test_trb() # Objective function - function fun(n::Int, var::Vector{Float64}, f::Ref{Float64}, userdata::userdata_type) + function fun(n::Int, x::Vector{Float64}, f::Ref{Float64}, userdata::userdata_type) p = userdata.p f[] = (x[1] + x[3] + p)^2 + (x[2] + x[3])^2 + cos(x[1]) return 0 end # Gradient of the objective - function grad(n::Int, var::Vector{Float64}, g::Vector{Float64}, userdata::userdata_type) + function grad(n::Int, x::Vector{Float64}, g::Vector{Float64}, userdata::userdata_type) p = userdata.p g[1] = 2.0 * (x[1] + x[3] + p) - sin(x[1]) g[2] = 2.0 * (x[2] + x[3]) @@ -29,9 +29,8 @@ function test_trb() end # Hessian of the objective - function hess(n::Int, n::Int, var::Vector{Float64}, hval::Vector{Float64}, + function hess(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, userdata::userdata_type) - p = userdata.p hval[1] = 2.0 - cos(x[1]) hval[2] = 2.0 hval[3] = 2.0 @@ -41,9 +40,8 @@ function test_trb() end # Dense Hessian - function hess_dense(n::Int, n::Int, var::Vector{Float64}, hval::Vector{Float64}, + function hess_dense(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, userdata::userdata_type) - p = userdata.p hval[1] = 2.0 - cos(x[1]) hval[2] = 0.0 hval[3] = 2.0 @@ -54,9 +52,8 @@ function test_trb() end # Hessian-vector product - function hessprod(n::Int, var::Vector{Float64}, u::Vector{Float64}, var::Vector{Float64}, + function hessprod(n::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, got_h::Bool, userdata::userdata_type) - p = userdata.p u[1] = u[1] + 2.0 * (v[1] + v[3]) - cos(x[1]) * v[1] u[2] = u[2] + 2.0 * (v[2] + v[3]) u[3] = u[3] + 2.0 * (v[1] + v[2] + 2.0 * v[3]) @@ -64,29 +61,29 @@ function test_trb() end # Sparse Hessian-vector product - function shessprod(n::Int, var::Vector{Float64}, nnz_v::Int, index_nz_v::Vector{Int}, - v::Vector{Float64}, nnz_u::Ref{Int}, index_nz_u::Vector{Int}, + function shessprod(n::Int, x::Vector{Float64}, nnz_v::Cint, index_nz_v::Vector{Cint}, + v::Vector{Float64}, nnz_u::Ref{Cint}, index_nz_u::Vector{Cint}, u::Vector{Float64}, got_h::Bool, userdata::userdata_type) p = zeros(Float64, 3) used = falses(3) for i in 1:nnz_v j = index_nz_v[i] if j == 1 - p[1] += 2.0 * v[i] - cos(var[1]) * v[i] + p[1] = p[1] + 2.0 * v[1] - cos(x[1]) * v[1] used[1] = true - p[3] += 2.0 * v[i] + p[3] = p[3] + 2.0 * v[1] used[3] = true elseif j == 2 - p[2] += 2.0 * v[i] + p[2] = p[2] + 2.0 * v[2] used[2] = true - p[3] += 2.0 * v[i] + p[3] = p[3] + 2.0 * v[2] used[3] = true elseif j == 3 - p[1] += 2.0 * v[i] + p[1] = p[1] + 2.0 * v[3] used[1] = true - p[2] += 2.0 * v[i] + p[2] = p[2] + 2.0 * v[3] used[2] = true - p[3] += 4.0 * v[i] + p[3] = p[3] + 4.0 * v[3] used[3] = true end end @@ -103,9 +100,8 @@ function test_trb() end # Apply preconditioner - function prec(n::Int, var::Vector{Float64}, u::Vector{Float64}, var::Vector{Float64}, + function prec(n::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, userdata::userdata_type) - p = userdata.p u[1] = 0.5 * v[1] u[2] = 0.5 * v[2] u[3] = 0.25 * v[3] @@ -113,14 +109,14 @@ function test_trb() end # Objective function - function fun_diag(n::Int, var::Vector{Float64}, f::Ref{Float64}, userdata::userdata_type) + function fun_diag(n::Int, x::Vector{Float64}, f::Ref{Float64}, userdata::userdata_type) p = userdata.p - f[] = (x[2] + p)^2 + x[1]^2 + cos(x[1]) + f[] = (x[3] + p)^2 + x[2]^2 + cos(x[1]) return 0 end # Gradient of the objective - function grad_diag(n::Int, var::Vector{Float64}, g::Vector{Float64}, + function grad_diag(n::Int, x::Vector{Float64}, g::Vector{Float64}, userdata::userdata_type) p = userdata.p g[1] = -sin(x[1]) @@ -130,58 +126,50 @@ function test_trb() end # Hessian of the objective - function hess_diag(n::Int, n::Int, var::Vector{Float64}, hval::Vector{Float64}, + function hess_diag(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, userdata::userdata_type) - p = userdata.p hval[1] = -cos(x[1]) - hval[3] = 2.0 + hval[2] = 2.0 hval[3] = 2.0 return 0 end # Hessian-vector product - function hessprod_diag(n::Int, var::Vector{Float64}, u::Vector{Float64}, - var::Vector{Float64}, got_h::Bool, userdata::userdata_type) - p = userdata.p + function hessprod_diag(n::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, + got_h::Bool, userdata::userdata_type) u[1] = u[1] + -cos(x[1]) * v[1] u[2] = u[2] + 2.0 * v[2] u[3] = u[3] + 2.0 * v[3] return 0 end - # Produit matrice-vecteur Hesseien creux - function shessprod_diag(n::Int, var::Vector{Float64}, nnz_v::Int, index_nz_v::Vector{Int}, - u::Vector{Float64}, got_h::Bool, userdata::userdata_type) - p = zeros(3) + # Sparse Hessian-vector product + function shessprod_diag(n::Int, x::Vector{Float64}, nnz_v::Cint, + index_nz_v::Vector{Cint}, v::Vector{Float64}, nnz_u::Ref{Cint}, + index_nz_u::Vector{Cint}, u::Vector{Float64}, got_h::Bool, + userdata::userdata_type) + p = zeros(Float64, 3) used = falses(3) for i in 1:nnz_v j = index_nz_v[i] if j == 1 - p[1] += 2.0 * v[0] - p[3] += 2.0 * v[0] + p[1] = p[1] - cos(x[1]) * v[1] used[1] = true - used[3] = true elseif j == 2 - p[2] += 2.0 * v[1] - p[3] += 2.0 * v[1] + p[2] = p[2] + 2.0 * v[2] used[2] = true - used[3] = true elseif j == 3 - p[1] += 2.0 * v[2] - p[2] += 2.0 * v[2] - p[3] += 4.0 * v[2] - used[1] = true - used[2] = true + p[3] = p[3] + 2.0 * v[3] used[3] = true end end - nnz_u = 0 + nnz_u[] = 0 for j in 1:3 if used[j] u[j] = p[j] - nnz_u += 1 - index_nz_u[nnz_u] = j + nnz_u[] += 1 + index_nz_u[nnz_u[]] = j end end return 0 @@ -249,13 +237,13 @@ function test_trb() elseif status[] < 0 # error exit terminated = true elseif status[] == 2 # evaluate f - eval_status = fun(n, x, f, userdata) + eval_status[] = fun(n, x, f, userdata) elseif status[] == 3 # evaluate g - eval_status = grad(n, x, g, userdata) + eval_status[] = grad(n, x, g, userdata) elseif status[] == 4 # evaluate H - eval_status = hess(n, ne, x, H_val, userdata) + eval_status[] = hess(n, ne, x, H_val, userdata) elseif status[] == 6 # evaluate the product with P - eval_status = prec(n, x, u, v, userdata) + eval_status[] = prec(n, x, u, v, userdata) else @printf(" the value %1i of status should not occur\n", status) end @@ -276,13 +264,13 @@ function test_trb() elseif status[] < 0 # error exit terminated = true elseif status[] == 2 # evaluate f - eval_status = fun(n, x, f, userdata) + eval_status[] = fun(n, x, f, userdata) elseif status[] == 3 # evaluate g - eval_status = grad(n, x, g, userdata) + eval_status[] = grad(n, x, g, userdata) elseif status[] == 4 # evaluate H - eval_status = hess(n, ne, x, H_val, userdata) + eval_status[] = hess(n, ne, x, H_val, userdata) elseif status[] == 6 # evaluate the product with P - eval_status = prec(n, x, u, v, userdata) + eval_status[] = prec(n, x, u, v, userdata) else @printf(" the value %1i of status should not occur\n", status) end @@ -304,13 +292,13 @@ function test_trb() elseif status[] < 0 # error exit terminated = true elseif status[] == 2 # evaluate f - eval_status = fun(n, x, f, userdata) + eval_status[] = fun(n, x, f, userdata) elseif status[] == 3 # evaluate g - eval_status = grad(n, x, g, userdata) + eval_status[] = grad(n, x, g, userdata) elseif status[] == 4 # evaluate H - eval_status = hess_dense(n, div(n * (n + 1), 2), x, H_dense, userdata) + eval_status[] = hess_dense(n, div(n * (n + 1), 2), x, H_dense, userdata) elseif status[] == 6 # evaluate the product with P - eval_status = prec(n, x, u, v, userdata) + eval_status[] = prec(n, x, u, v, userdata) else @printf(" the value %1i of status should not occur\n", status) end @@ -330,13 +318,13 @@ function test_trb() elseif status[] < 0 # error exit terminated = true elseif status[] == 2 # evaluate f - eval_status = fun_diag(n, x, f, userdata) + eval_status[] = fun_diag(n, x, f, userdata) elseif status[] == 3 # evaluate g - eval_status = grad_diag(n, x, g, userdata) + eval_status[] = grad_diag(n, x, g, userdata) elseif status[] == 4 # evaluate H - eval_status = hess_diag(n, n, x, H_diag, userdata) + eval_status[] = hess_diag(n, n, x, H_diag, userdata) elseif status[] == 6 # evaluate the product with P - eval_status = prec(n, x, u, v, userdata) + eval_status[] = prec(n, x, u, v, userdata) else @printf(" the value %1i of status should not occur\n", status) end @@ -347,27 +335,28 @@ function test_trb() if d == 5 st = 'P' trb_import(control, data, status, n, x_l, x_u, "absent", ne, C_NULL, C_NULL, C_NULL) - nnz_u = 0 + nnz_u = Ref{Cint}(0) terminated = false while !terminated # reverse-communication loop trb_solve_reverse_without_mat(data, status, eval_status, n, x, f[], g, u, v, - index_nz_v, nnz_v, index_nz_u, nnz_u) + index_nz_v, nnz_v, index_nz_u, nnz_u[]) if status[] == 0 # successful termination terminated = true elseif status[] < 0 # error exit terminated = true elseif status[] == 2 # evaluate f - eval_status = fun(n, x, f, userdata) + eval_status[] = fun(n, x, f, userdata) elseif status[] == 3 # evaluate g - eval_status = grad(n, x, g, userdata) + eval_status[] = grad(n, x, g, userdata) elseif status[] == 5 # evaluate H - eval_status = hessprod(n, x, u, v, false, userdata) + eval_status[] = hessprod(n, x, u, v, false, userdata) elseif status[] == 6 # evaluate the product with P - eval_status = prec(n, x, u, v, userdata) + eval_status[] = prec(n, x, u, v, userdata) elseif status[] == 7 # evaluate sparse Hessian-vect prod - eval_status = shessprod(n, x, nnz_v, index_nz_v, v, nnz_u, index_nz_u, u, false, - userdata) + eval_status[] = shessprod(n, x, nnz_v[], index_nz_v, v, nnz_u, index_nz_u, u, + false, + userdata) else @printf(" the value %1i of status should not occur\n", status) end diff --git a/src/trb/C/trbtf.c b/src/trb/C/trbtf.c index b8be6159c2..ccbf5650c1 100644 --- a/src/trb/C/trbtf.c +++ b/src/trb/C/trbtf.c @@ -468,15 +468,15 @@ ipc_ shessprod_diag( ipc_ n, const rpc_ x[], ipc_ nnz_v, for( ipc_ i = 0; i < nnz_v; i++){ ipc_ j = index_nz_v[i]; switch(j){ - case 0: + case 1: p[0] = p[0] - cos(x[0]) * v[0]; used[0] = true; break; - case 1: + case 2: p[1] = p[1] + 2.0 * v[1]; used[1] = true; break; - case 2: + case 3: p[2] = p[2] + 2.0 * v[2]; used[2] = true; break; From d76b7721924c3cb6bd25e16630b7b372a2a19738 Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Tue, 13 Feb 2024 19:16:39 -0500 Subject: [PATCH 32/33] Test all Julia interfaces with CI --- GALAHAD.jl/test/UGO.SPC | 0 GALAHAD.jl/test/test_arc.jl | 30 ++++--- GALAHAD.jl/test/test_bgo.jl | 32 +++---- GALAHAD.jl/test/test_blls.jl | 31 +++---- GALAHAD.jl/test/test_bqpb.jl | 1 - GALAHAD.jl/test/test_dgo.jl | 18 ++-- GALAHAD.jl/test/test_nls.jl | 24 ++--- GALAHAD.jl/test/test_psls.jl | 2 +- GALAHAD.jl/test/test_slls.jl | 33 +++---- GALAHAD.jl/test/test_sls.jl | 2 +- GALAHAD.jl/test/test_trb.jl | 28 +++--- GALAHAD.jl/test/test_tru.jl | 169 ++++++++++++++++++----------------- GALAHAD.jl/test/test_ugo.jl | 7 -- 13 files changed, 182 insertions(+), 195 deletions(-) delete mode 100644 GALAHAD.jl/test/UGO.SPC diff --git a/GALAHAD.jl/test/UGO.SPC b/GALAHAD.jl/test/UGO.SPC deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/GALAHAD.jl/test/test_arc.jl b/GALAHAD.jl/test/test_arc.jl index 38677f939d..9309efbdc5 100644 --- a/GALAHAD.jl/test/test_arc.jl +++ b/GALAHAD.jl/test/test_arc.jl @@ -7,20 +7,20 @@ using Printf using Accessors # Custom userdata struct -struct userdata_type +struct userdata_arc p::Float64 end function test_arc() # Objective function - function fun(n, x, f, userdata) + function fun(n::Int, x::Vector{Float64}, f::Ref{Float64}, userdata::userdata_arc) p = userdata.p f[] = (x[1] + x[3] + p)^2 + (x[2] + x[3])^2 + cos(x[1]) return 0 end # Gradient of the objective - function grad(n, x, g, userdata) + function grad(n::Int, x::Vector{Float64}, g::Vector{Float64}, userdata::userdata_arc) p = userdata.p g[1] = 2.0 * (x[1] + x[3] + p) - sin(x[1]) g[2] = 2.0 * (x[2] + x[3]) @@ -29,7 +29,8 @@ function test_arc() end # Hessian of the objective - function hess(n, ne, x, hval, userdata) + function hess(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, + userdata::userdata_arc) hval[1] = 2.0 - cos(x[1]) hval[2] = 2.0 hval[3] = 2.0 @@ -39,7 +40,8 @@ function test_arc() end # Dense Hessian - function hess_dense(n, ne, x, hval, userdata) + function hess_dense(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, + userdata::userdata_arc) hval[1] = 2.0 - cos(x[1]) hval[2] = 0.0 hval[3] = 2.0 @@ -50,7 +52,8 @@ function test_arc() end # Hessian-vector product - function hessprod(n, x, u, v, got_h, userdata) + function hessprod(n::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, + got_h::Bool, userdata::userdata_arc) u[1] = u[1] + 2.0 * (v[1] + v[3]) - cos(x[1]) * v[1] u[2] = u[2] + 2.0 * (v[2] + v[3]) u[3] = u[3] + 2.0 * (v[1] + v[2] + 2.0 * v[3]) @@ -58,7 +61,8 @@ function test_arc() end # Apply preconditioner - function prec(n, x, u, v, userdata) + function prec(n::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, + userdata::userdata_arc) u[1] = 0.5 * v[1] u[2] = 0.5 * v[2] u[3] = 0.25 * v[3] @@ -66,14 +70,14 @@ function test_arc() end # Objective function - function fun_diag(n, x, f, userdata) + function fun_diag(n::Int, x::Vector{Float64}, f::Ref{Float64}, userdata::userdata_arc) p = userdata.p f[] = (x[3] + p)^2 + x[2]^2 + cos(x[1]) return 0 end # Gradient of the objective - function grad_diag(n, x, g, userdata) + function grad_diag(n::Int, x::Vector{Float64}, g::Vector{Float64}, userdata::userdata_arc) p = userdata.p g[1] = -sin(x[1]) g[2] = 2.0 * x[2] @@ -82,7 +86,8 @@ function test_arc() end # Hessian of the objective - function hess_diag(n, ne, x, hval, userdata) + function hess_diag(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, + userdata::userdata_arc) hval[1] = -cos(x[1]) hval[2] = 2.0 hval[3] = 2.0 @@ -90,7 +95,8 @@ function test_arc() end # Hessian-vector product - function hessprod_diag(n, x, u, v, got_h, userdata) + function hessprod_diag(n::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, + got_h::Bool, userdata::userdata_arc) u[1] = u[1] + -cos(x[1]) * v[1] u[2] = u[2] + 2.0 * v[2] u[3] = u[3] + 2.0 * v[3] @@ -103,7 +109,7 @@ function test_arc() inform = Ref{arc_inform_type{Float64}}() # Set user data - userdata = userdata_type(4.0) + userdata = userdata_arc(4.0) # Set problem data n = 3 # dimension diff --git a/GALAHAD.jl/test/test_bgo.jl b/GALAHAD.jl/test/test_bgo.jl index 532fcebacc..381d8f3c7e 100644 --- a/GALAHAD.jl/test/test_bgo.jl +++ b/GALAHAD.jl/test/test_bgo.jl @@ -7,16 +7,15 @@ using Printf using Accessors # Custom userdata struct -struct userdata_type +struct userdata_bgo p::Float64 freq::Float64 mag::Float64 end function test_bgo() - # Objective function - function fun(n::Int, x::Vector{Float64}, f::Ref{Float64}, userdata::userdata_type) + function fun(n::Int, x::Vector{Float64}, f::Ref{Float64}, userdata::userdata_bgo) p = userdata.p freq = userdata.freq mag = userdata.mag @@ -25,7 +24,7 @@ function test_bgo() end # Gradient of the objective - function grad(n::Int, x::Vector{Float64}, g::Vector{Float64}, userdata::userdata_type) + function grad(n::Int, x::Vector{Float64}, g::Vector{Float64}, userdata::userdata_bgo) p = userdata.p freq = userdata.freq mag = userdata.mag @@ -37,7 +36,7 @@ function test_bgo() # Hessian of the objective function hess(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, - userdata::userdata_type) + userdata::userdata_bgo) p = userdata.p freq = userdata.freq mag = userdata.mag @@ -50,7 +49,7 @@ function test_bgo() # Dense Hessian function hess_dense(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, - userdata::userdata_type) + userdata::userdata_bgo) p = userdata.p freq = userdata.freq mag = userdata.mag @@ -64,7 +63,7 @@ function test_bgo() # Hessian-vector product function hessprod(n::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, - got_h::Bool, userdata::userdata_type) + got_h::Bool, userdata::userdata_bgo) p = userdata.p freq = userdata.freq mag = userdata.mag @@ -77,7 +76,7 @@ function test_bgo() # Sparse Hessian-vector product function shessprod(n::Int, x::Vector{Float64}, nnz_v::Cint, index_nz_v::Vector{Cint}, v::Vector{Float64}, nnz_u::Ref{Cint}, index_nz_u::Vector{Cint}, - u::Vector{Float64}, got_h::Bool, userdata::userdata_type) + u::Vector{Float64}, got_h::Bool, userdata::userdata_bgo) p = userdata.p freq = userdata.freq mag = userdata.mag @@ -118,7 +117,7 @@ function test_bgo() # Apply preconditioner function prec(n::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, - userdata::userdata_type) + userdata::userdata_bgo) u[1] = 0.5 * v[1] u[2] = 0.5 * v[2] u[3] = 0.25 * v[3] @@ -126,17 +125,17 @@ function test_bgo() end # Objective function - function fun_diag(n::Int, x::Vector{Float64}, f::Ref{Float64}, userdata) + function fun_diag(n::Int, x::Vector{Float64}, f::Ref{Float64}, userdata::userdata_bgo) p = userdata.p freq = userdata.freq mag = userdata.mag - f[] = (x[3] + p)^2 + x[2]^2 + mag * cos(freq * x[1]) + sum(x) + f[] = (x[3] + p)^2 + x[2]^2 + mag * cos(freq * x[1]) + x[1] + x[2] + x[3] return 0 end # Gradient of the objective - function grad_diag(n::Int, x::Vector{Float64}, g::Vector{Float64}, userdata) + function grad_diag(n::Int, x::Vector{Float64}, g::Vector{Float64}, userdata::userdata_bgo) p = userdata.p freq = userdata.freq mag = userdata.mag @@ -148,7 +147,8 @@ function test_bgo() end # Hessian of the objective - function hess_diag(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, userdata) + function hess_diag(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, + userdata::userdata_bgo) freq = userdata.freq mag = userdata.mag @@ -160,7 +160,7 @@ function test_bgo() # Hessian-vector product function hessprod_diag(n::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, - got_h::Bool, userdata) + got_h::Bool, userdata::userdata_bgo) freq = userdata.freq mag = userdata.mag @@ -173,7 +173,7 @@ function test_bgo() # Sparse Hessian-vector product function shessprod_diag(n::Int, x::Vector{Float64}, nnz_v::Cint, index_nz_v::Vector{Cint}, v::Vector{Float64}, nnz_u::Ref{Cint}, index_nz_u::Vector{Cint}, - u::Vector{Float64}, got_h::Bool, userdata) + u::Vector{Float64}, got_h::Bool, userdata::userdata_bgo) freq = userdata.freq mag = userdata.mag @@ -209,7 +209,7 @@ function test_bgo() inform = Ref{bgo_inform_type{Float64}}() # Set user data - userdata = userdata_type(4.0, 10, 1000) + userdata = userdata_bgo(4.0, 10, 1000) # Set problem data n = 3 # dimension diff --git a/GALAHAD.jl/test/test_blls.jl b/GALAHAD.jl/test/test_blls.jl index 98feca3e10..87ed7a11a9 100644 --- a/GALAHAD.jl/test/test_blls.jl +++ b/GALAHAD.jl/test/test_blls.jl @@ -7,12 +7,12 @@ using Printf using Accessors # Custom userdata struct -mutable struct userdata_type +mutable struct userdata_blls scale::Float64 end # Apply preconditioner -function prec(n::Int, x::Vector{Float64}, p::Vector{Float64}, userdata::userdata_type) +function prec(n::Int, x::Vector{Float64}, p::Vector{Float64}, userdata::userdata_blls) scale = userdata.scale for i in 1:n p[i] = scale * x[i] @@ -27,12 +27,7 @@ function test_blls() inform = Ref{blls_inform_type{Float64}}() # Set user data - userdata = userdata_type(1.0) - pointer_userdata = pointer_from_objref(userdata) - - # Pointer to call prec - pointer_prec = @cfunction(prec, Int, - (Int, Vector{Float64}, Vector{Float64}, userdata_type)) + userdata = userdata_blls(1.0) # Set problem data n = 10 # dimension @@ -169,9 +164,9 @@ function test_blls() blls_import(control, data, status, n, o, "coordinate", Ao_ne, Ao_row, Ao_col, 0, C_NULL) - blls_solve_given_a(data, pointer_userdata, status, n, o, + blls_solve_given_a(data, userdata_blls, status, n, o, Ao_ne, Ao_val, b, x_l, x_u, - x, z, r, g, x_stat, w, pointer_prec) + x, z, r, g, x_stat, w, prec) end # sparse by rows @@ -181,9 +176,9 @@ function test_blls() "sparse_by_rows", Ao_ne, C_NULL, Ao_col, Ao_ptr_ne, Ao_ptr) - blls_solve_given_a(data, pointer_userdata, status, n, o, + blls_solve_given_a(data, userdata_blls, status, n, o, Ao_ne, Ao_val, b, x_l, x_u, - x, z, r, g, x_stat, w, pointer_prec) + x, z, r, g, x_stat, w, prec) end # dense by rows @@ -193,9 +188,9 @@ function test_blls() "dense_by_rows", Ao_dense_ne, C_NULL, C_NULL, 0, C_NULL) - blls_solve_given_a(data, pointer_userdata, status, n, o, + blls_solve_given_a(data, userdata_blls, status, n, o, Ao_dense_ne, Ao_dense, b, x_l, x_u, - x, z, r, g, x_stat, w, pointer_prec) + x, z, r, g, x_stat, w, prec) end # sparse by columns @@ -205,9 +200,9 @@ function test_blls() "sparse_by_columns", Ao_ne, Ao_by_col_row, C_NULL, Ao_by_col_ptr_ne, Ao_by_col_ptr) - blls_solve_given_a(data, pointer_userdata, status, n, o, + blls_solve_given_a(data, userdata_blls, status, n, o, Ao_ne, Ao_by_col_val, b, x_l, x_u, - x, z, r, g, x_stat, w, pointer_prec) + x, z, r, g, x_stat, w, prec) end # dense by columns @@ -217,9 +212,9 @@ function test_blls() "dense_by_columns", Ao_dense_ne, C_NULL, C_NULL, 0, C_NULL) - blls_solve_given_a(data, pointer_userdata, status, n, o, + blls_solve_given_a(data, userdata_blls, status, n, o, Ao_dense_ne, Ao_by_col_dense, b, x_l, x_u, - x, z, r, g, x_stat, w, pointer_prec) + x, z, r, g, x_stat, w, prec) end blls_information(data, inform, status) diff --git a/GALAHAD.jl/test/test_bqpb.jl b/GALAHAD.jl/test/test_bqpb.jl index 0bb0334bc7..325089a57f 100644 --- a/GALAHAD.jl/test/test_bqpb.jl +++ b/GALAHAD.jl/test/test_bqpb.jl @@ -30,7 +30,6 @@ function test_bqpb() status = Ref{Cint}() @printf(" Fortran sparse matrix indexing\n\n") - @printf(" basic tests of qp storage formats\n\n") for d in 1:7 diff --git a/GALAHAD.jl/test/test_dgo.jl b/GALAHAD.jl/test/test_dgo.jl index 9ec4881d7d..da27fef3de 100644 --- a/GALAHAD.jl/test/test_dgo.jl +++ b/GALAHAD.jl/test/test_dgo.jl @@ -7,7 +7,7 @@ using Printf using Accessors # Custom userdata struct -struct userdata_type +struct userdata_dgo p::Float64 freq::Float64 mag::Float64 @@ -16,7 +16,7 @@ end function test_dgo() # Objective function - function fun(n::Int, x::Vector{Float64}, f::Ref{Float64}, userdata::userdata_type) + function fun(n::Int, x::Vector{Float64}, f::Ref{Float64}, userdata::userdata_dgo) p = userdata.p freq = userdata.freq mag = userdata.mag @@ -25,7 +25,7 @@ function test_dgo() end # Gradient of the objective - function grad(n::Int, x::Vector{Float64}, g::Vector{Float64}, userdata::userdata_type) + function grad(n::Int, x::Vector{Float64}, g::Vector{Float64}, userdata::userdata_dgo) p = userdata.p freq = userdata.freq mag = userdata.mag @@ -37,7 +37,7 @@ function test_dgo() # Hessian of the objective function hess(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, - userdata::userdata_type) + userdata::userdata_dgo) p = userdata.p freq = userdata.freq mag = userdata.mag @@ -50,7 +50,7 @@ function test_dgo() # Dense Hessian function hess_dense(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, - userdata::userdata_type) + userdata::userdata_dgo) p = userdata.p freq = userdata.freq mag = userdata.mag @@ -64,7 +64,7 @@ function test_dgo() # Hessian-vector product function hessprod(n::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, - got_h::Bool, userdata::userdata_type) + got_h::Bool, userdata::userdata_dgo) p = userdata.p freq = userdata.freq mag = userdata.mag @@ -77,7 +77,7 @@ function test_dgo() # Sparse Hessian-vector product function shessprod(n::Int, x::Vector{Float64}, nnz_v::Cint, index_nz_v::Vector{Cint}, v::Vector{Float64}, nnz_u::Ref{Cint}, index_nz_u::Vector{Cint}, - u::Vector{Float64}, got_h::Bool, userdata::userdata_type) + u::Vector{Float64}, got_h::Bool, userdata::userdata_dgo) p = userdata.p freq = userdata.freq mag = userdata.mag @@ -118,7 +118,7 @@ function test_dgo() # Apply preconditioner function prec(n::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, - userdata::userdata_type) + userdata::userdata_dgo) u[1] = 0.5 * v[1] u[2] = 0.5 * v[2] u[3] = 0.25 * v[3] @@ -209,7 +209,7 @@ function test_dgo() inform = Ref{dgo_inform_type{Float64}}() # Set user data - userdata = userdata_type(4.0, 10.0, 1000.0) + userdata = userdata_dgo(4.0, 10.0, 1000.0) # Set problem data n = 3 # dimension diff --git a/GALAHAD.jl/test/test_nls.jl b/GALAHAD.jl/test/test_nls.jl index bf4a9a0135..6ae2421baf 100644 --- a/GALAHAD.jl/test/test_nls.jl +++ b/GALAHAD.jl/test/test_nls.jl @@ -7,14 +7,14 @@ using Printf using Accessors # Custom userdata struct -struct userdata_type +struct userdata_nls p::Float64 end function test_nls() # compute the residuals function res(n::Int, m::Int, x::Vector{Float64}, c::Vector{Float64}, - userdata::userdata_type) + userdata::userdata_nls) c[1] = x[1]^2 + userdata.p c[2] = x[1] + x[2]^2 c[3] = x[1] - x[2] @@ -23,7 +23,7 @@ function test_nls() # compute the Jacobian function jac(n::Int, m::Int, jne::Int, x::Vector{Float64}, jval::Vector{Float64}, - userdata::userdata_type) + userdata::userdata_nls) jval[1] = 2.0 * x[1] jval[2] = 1.0 jval[3] = 2.0 * x[2] @@ -34,7 +34,7 @@ function test_nls() # compute the Hessian function hess(n::Int, m::Int, hne::Int, x::Vector{Float64}, y::Vector{Float64}, - hval::Vector{Float64}, userdata::userdata_type) + hval::Vector{Float64}, userdata::userdata_nls) hval[1] = 2.0 * y[1] hval[2] = 2.0 * y[2] return 0 @@ -42,7 +42,7 @@ function test_nls() # compute Jacobian-vector products function jacprod(n::Int, m::Int, x::Vector{Float64}, trans::Bool, u::Vector{Float64}, - v::Vector{Float64}, got_j::Bool, userdata::userdata_type) + v::Vector{Float64}, got_j::Bool, userdata::userdata_nls) if trans u[1] = u[1] + 2.0 * x[1] * v[1] + v[2] + v[3] u[2] = u[2] + 2.0 * x[2] * v[2] - v[3] @@ -57,7 +57,7 @@ function test_nls() # compute Hessian-vector products function hessprod(n::Int, m::Int, x::Vector{Float64}, y::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, got_h::Bool, - userdata::userdata_type) + userdata::userdata_nls) u[1] = u[1] + 2.0 * y[1] * v[1] u[2] = u[2] + 2.0 * y[2] * v[2] return 0 @@ -65,7 +65,7 @@ function test_nls() # compute residual-Hessians-vector products function rhessprods(n::Int, m::Int, pne::Int, x::Vector{Float64}, v::Vector{Float64}, - pval::Vector{Float64}, got_h::Bool, userdata::userdata_type) + pval::Vector{Float64}, got_h::Bool, userdata::userdata_nls) pval[1] = 2.0 * v[1] pval[2] = 2.0 * v[2] return 0 @@ -73,7 +73,7 @@ function test_nls() # # scale v function scale(n::Int, m::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, - userdata::userdata_type) + userdata::userdata_nls) u[1] = v[1] u[2] = v[2] return 0 @@ -81,7 +81,7 @@ function test_nls() # compute the dense Jacobian function jac_dense(n::Int, m::Int, jne::Int, x::Vector{Float64}, jval::Vector{Float64}, - userdata::userdata_type) + userdata::userdata_nls) jval[1] = 2.0 * x[1] jval[2] = 0.0 jval[3] = 1.0 @@ -93,7 +93,7 @@ function test_nls() # compute the dense Hessian function hess_dense(n::Int, m::Int, hne::Int, x::Vector{Float64}, y::Vector{Float64}, - hval::Vector{Float64}, userdata::userdata_type) + hval::Vector{Float64}, userdata::userdata_nls) hval[1] = 2.0 * y[1] hval[2] = 0.0 hval[3] = 2.0 * y[2] @@ -103,7 +103,7 @@ function test_nls() # compute dense residual-Hessians-vector products function rhessprods_dense(n::Int, m::Int, pne::Int, x::Vector{Float64}, v::Vector{Float64}, pval::Vector{Float64}, got_h::Bool, - userdata::userdata_type) + userdata::userdata_nls) pval[1] = 2.0 * v[1] pval[2] = 0.0 pval[3] = 0.0 @@ -119,7 +119,7 @@ function test_nls() inform = Ref{nls_inform_type{Float64}}() # Set user data - userdata = userdata_type(1.0) + userdata = userdata_nls(1.0) # Set problem data n = 2 # # variables diff --git a/GALAHAD.jl/test/test_psls.jl b/GALAHAD.jl/test/test_psls.jl index 909159e44f..49e3f60e2e 100644 --- a/GALAHAD.jl/test/test_psls.jl +++ b/GALAHAD.jl/test/test_psls.jl @@ -15,7 +15,7 @@ function test_psls() # Set problem data n = 5 # dimension of A ne = 7 # number of elements of A - dense_ne = n * (n + 1) / 2 # number of elements of dense A + dense_ne = div(n * (n + 1), 2) # number of elements of dense A row = Cint[1, 2, 2, 3, 3, 4, 5] # A indices values, NB lower triangle col = Cint[1, 1, 5, 2, 3, 3, 5] diff --git a/GALAHAD.jl/test/test_slls.jl b/GALAHAD.jl/test/test_slls.jl index 47ff9b2f1a..f8e46822f4 100644 --- a/GALAHAD.jl/test/test_slls.jl +++ b/GALAHAD.jl/test/test_slls.jl @@ -7,16 +7,15 @@ using Printf using Accessors # Custom userdata struct -mutable struct userdata_type +mutable struct userdata_slls scale::Float64 end # Apply preconditioner -function prec(n::Int, x::Vector{Float64}, p::Vector{Float64}, userdata::userdata_type) +function prec(n::Int, x::Vector{Float64}, p::Vector{Float64}, userdata::userdata_slls) scale = userdata.scale for i in 1:n p[i] = scale * x[i] - println(bob) end return 0 end @@ -29,12 +28,7 @@ function test_slls() inform = Ref{slls_inform_type{Float64}}() # Set user data - userdata = userdata_type(1.0) - pointer_userdata = pointer_from_objref(userdata) - - # Pointer to call prec - pointer_prec = @cfunction(prec, Int, - (Int, Vector{Float64}, Vector{Float64}, userdata_type)) + userdata = userdata_slls(1.0) # Set problem data n = 10 # dimension @@ -67,7 +61,6 @@ function test_slls() # A = ( I ) and b = (i * e) # (e^T) (n + 1) - for i in 1:n b[i] = i end @@ -151,8 +144,8 @@ function test_slls() slls_import(control, data, status, n, o, "coordinate", Ao_ne, Ao_row, Ao_col, 0, C_NULL) - slls_solve_given_a(data, pointer_userdata, status, n, o, Ao_ne, Ao_val, b, x, z, r, g, - x_stat, pointer_prec) + slls_solve_given_a(data, userdata, status, n, o, Ao_ne, Ao_val, b, x, z, r, g, + x_stat, prec) end # sparse by rows @@ -162,8 +155,8 @@ function test_slls() "sparse_by_rows", Ao_ne, C_NULL, Ao_col, Ao_ptr_ne, Ao_ptr) - slls_solve_given_a(data, pointer_userdata, status, n, o, Ao_ne, Ao_val, b, x, z, r, g, - x_stat, pointer_prec) + slls_solve_given_a(data, userdata, status, n, o, Ao_ne, Ao_val, b, x, z, r, g, + x_stat, prec) end # dense by rows @@ -173,9 +166,9 @@ function test_slls() "dense_by_rows", Ao_dense_ne, C_NULL, C_NULL, 0, C_NULL) - slls_solve_given_a(data, pointer_userdata, status, n, o, + slls_solve_given_a(data, userdata, status, n, o, Ao_dense_ne, Ao_dense, b, - x, z, r, g, x_stat, pointer_prec) + x, z, r, g, x_stat, prec) end # sparse by columns @@ -185,9 +178,9 @@ function test_slls() "sparse_by_columns", Ao_ne, Ao_by_col_row, C_NULL, Ao_by_col_ptr_ne, Ao_by_col_ptr) - slls_solve_given_a(data, pointer_userdata, status, n, o, + slls_solve_given_a(data, userdata, status, n, o, Ao_ne, Ao_by_col_val, b, - x, z, r, g, x_stat, pointer_prec) + x, z, r, g, x_stat, prec) end # dense by columns @@ -197,9 +190,9 @@ function test_slls() "dense_by_columns", Ao_dense_ne, C_NULL, C_NULL, 0, C_NULL) - slls_solve_given_a(data, pointer_userdata, status, n, o, Ao_dense_ne, Ao_by_col_dense, + slls_solve_given_a(data, userdata, status, n, o, Ao_dense_ne, Ao_by_col_dense, b, - x, z, r, g, x_stat, pointer_prec) + x, z, r, g, x_stat, prec) end slls_information(data, inform, status) diff --git a/GALAHAD.jl/test/test_sls.jl b/GALAHAD.jl/test/test_sls.jl index dc3a948e87..37eb3c8ce5 100644 --- a/GALAHAD.jl/test/test_sls.jl +++ b/GALAHAD.jl/test/test_sls.jl @@ -7,7 +7,7 @@ using Printf using Accessors function test_sls() - maxabsarray(a) = maximum(abs.(a)) + maxabsarray(a) = abs.(a) |> maximum # Derived types data = Ref{Ptr{Cvoid}}() diff --git a/GALAHAD.jl/test/test_trb.jl b/GALAHAD.jl/test/test_trb.jl index 26b1c9384c..da0c0869a5 100644 --- a/GALAHAD.jl/test/test_trb.jl +++ b/GALAHAD.jl/test/test_trb.jl @@ -7,20 +7,20 @@ using Printf using Accessors # Custom userdata struct -struct userdata_type +struct userdata_trb p::Float64 end function test_trb() # Objective function - function fun(n::Int, x::Vector{Float64}, f::Ref{Float64}, userdata::userdata_type) + function fun(n::Int, x::Vector{Float64}, f::Ref{Float64}, userdata::userdata_trb) p = userdata.p f[] = (x[1] + x[3] + p)^2 + (x[2] + x[3])^2 + cos(x[1]) return 0 end # Gradient of the objective - function grad(n::Int, x::Vector{Float64}, g::Vector{Float64}, userdata::userdata_type) + function grad(n::Int, x::Vector{Float64}, g::Vector{Float64}, userdata::userdata_trb) p = userdata.p g[1] = 2.0 * (x[1] + x[3] + p) - sin(x[1]) g[2] = 2.0 * (x[2] + x[3]) @@ -30,7 +30,7 @@ function test_trb() # Hessian of the objective function hess(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, - userdata::userdata_type) + userdata::userdata_trb) hval[1] = 2.0 - cos(x[1]) hval[2] = 2.0 hval[3] = 2.0 @@ -41,7 +41,7 @@ function test_trb() # Dense Hessian function hess_dense(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, - userdata::userdata_type) + userdata::userdata_trb) hval[1] = 2.0 - cos(x[1]) hval[2] = 0.0 hval[3] = 2.0 @@ -53,7 +53,7 @@ function test_trb() # Hessian-vector product function hessprod(n::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, - got_h::Bool, userdata::userdata_type) + got_h::Bool, userdata::userdata_trb) u[1] = u[1] + 2.0 * (v[1] + v[3]) - cos(x[1]) * v[1] u[2] = u[2] + 2.0 * (v[2] + v[3]) u[3] = u[3] + 2.0 * (v[1] + v[2] + 2.0 * v[3]) @@ -63,7 +63,7 @@ function test_trb() # Sparse Hessian-vector product function shessprod(n::Int, x::Vector{Float64}, nnz_v::Cint, index_nz_v::Vector{Cint}, v::Vector{Float64}, nnz_u::Ref{Cint}, index_nz_u::Vector{Cint}, - u::Vector{Float64}, got_h::Bool, userdata::userdata_type) + u::Vector{Float64}, got_h::Bool, userdata::userdata_trb) p = zeros(Float64, 3) used = falses(3) for i in 1:nnz_v @@ -101,7 +101,7 @@ function test_trb() # Apply preconditioner function prec(n::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, - userdata::userdata_type) + userdata::userdata_trb) u[1] = 0.5 * v[1] u[2] = 0.5 * v[2] u[3] = 0.25 * v[3] @@ -109,7 +109,7 @@ function test_trb() end # Objective function - function fun_diag(n::Int, x::Vector{Float64}, f::Ref{Float64}, userdata::userdata_type) + function fun_diag(n::Int, x::Vector{Float64}, f::Ref{Float64}, userdata::userdata_trb) p = userdata.p f[] = (x[3] + p)^2 + x[2]^2 + cos(x[1]) return 0 @@ -117,7 +117,7 @@ function test_trb() # Gradient of the objective function grad_diag(n::Int, x::Vector{Float64}, g::Vector{Float64}, - userdata::userdata_type) + userdata::userdata_trb) p = userdata.p g[1] = -sin(x[1]) g[2] = 2.0 * x[2] @@ -127,7 +127,7 @@ function test_trb() # Hessian of the objective function hess_diag(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, - userdata::userdata_type) + userdata::userdata_trb) hval[1] = -cos(x[1]) hval[2] = 2.0 hval[3] = 2.0 @@ -136,7 +136,7 @@ function test_trb() # Hessian-vector product function hessprod_diag(n::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, - got_h::Bool, userdata::userdata_type) + got_h::Bool, userdata::userdata_trb) u[1] = u[1] + -cos(x[1]) * v[1] u[2] = u[2] + 2.0 * v[2] u[3] = u[3] + 2.0 * v[3] @@ -147,7 +147,7 @@ function test_trb() function shessprod_diag(n::Int, x::Vector{Float64}, nnz_v::Cint, index_nz_v::Vector{Cint}, v::Vector{Float64}, nnz_u::Ref{Cint}, index_nz_u::Vector{Cint}, u::Vector{Float64}, got_h::Bool, - userdata::userdata_type) + userdata::userdata_trb) p = zeros(Float64, 3) used = falses(3) for i in 1:nnz_v @@ -181,7 +181,7 @@ function test_trb() inform = Ref{trb_inform_type{Float64}}() # Set user data - userdata = userdata_type(4.0) + userdata = userdata_trb(4.0) # Set problem data n = 3 # dimension diff --git a/GALAHAD.jl/test/test_tru.jl b/GALAHAD.jl/test/test_tru.jl index 53e8eff48d..21e32c7836 100644 --- a/GALAHAD.jl/test/test_tru.jl +++ b/GALAHAD.jl/test/test_tru.jl @@ -7,109 +7,110 @@ using Printf using Accessors # Custom userdata struct -mutable struct userdata_type +mutable struct userdata_tru p::Float64 end -# Objective function -function fun(n::Int, x::Vector{Float64}, f::Ref{Float64}, userdata::userdata_type) - p = userdata.p - f[] = (x[1] + x[3] + p)^2 + (x[2] + x[3])^2 + cos(x[1]) - return 0 -end +function test_tru() -# Gradient of the objective -function grad(n::Int, x::Vector{Float64}, g::Vector{Float64}, userdata::userdata_type) - p = userdata.p - g[1] = 2.0 * (x[1] + x[3] + p) - sin(x[1]) - g[2] = 2.0 * (x[2] + x[3]) - g[3] = 2.0 * (x[1] + x[3] + p) + 2.0 * (x[2] + x[3]) - return 0 -end + # Objective function + function fun(n::Int, x::Vector{Float64}, f::Ref{Float64}, userdata::userdata_tru) + p = userdata.p + f[] = (x[1] + x[3] + p)^2 + (x[2] + x[3])^2 + cos(x[1]) + return 0 + end -# Hessian of the objective -function hess(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, - userdata::userdata_type) - hval[1] = 2.0 - cos(x[1]) - hval[2] = 2.0 - hval[3] = 2.0 - hval[4] = 2.0 - hval[5] = 4.0 - return 0 -end + # Gradient of the objective + function grad(n::Int, x::Vector{Float64}, g::Vector{Float64}, userdata::userdata_tru) + p = userdata.p + g[1] = 2.0 * (x[1] + x[3] + p) - sin(x[1]) + g[2] = 2.0 * (x[2] + x[3]) + g[3] = 2.0 * (x[1] + x[3] + p) + 2.0 * (x[2] + x[3]) + return 0 + end -# Dense Hessian -function hess_dense(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, - userdata::userdata_type) - hval[1] = 2.0 - cos(x[1]) - hval[2] = 0.0 - hval[3] = 2.0 - hval[4] = 2.0 - hval[5] = 2.0 - hval[6] = 4.0 - return 0 -end + # Hessian of the objective + function hess(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, + userdata::userdata_tru) + hval[1] = 2.0 - cos(x[1]) + hval[2] = 2.0 + hval[3] = 2.0 + hval[4] = 2.0 + hval[5] = 4.0 + return 0 + end -# Hessian-vector product -function hessprod(n::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, - got_h::Bool, userdata::userdata_type) - u[1] = u[1] + 2.0 * (v[1] + v[3]) - cos(x[1]) * v[1] - u[2] = u[2] + 2.0 * (v[2] + v[3]) - u[3] = u[3] + 2.0 * (v[1] + v[2] + 2.0 * v[3]) - return 0 -end + # Dense Hessian + function hess_dense(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, + userdata::userdata_tru) + hval[1] = 2.0 - cos(x[1]) + hval[2] = 0.0 + hval[3] = 2.0 + hval[4] = 2.0 + hval[5] = 2.0 + hval[6] = 4.0 + return 0 + end -# Apply preconditioner -function prec(n::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, - userdata::userdata_type) - u[1] = 0.5 * v[1] - u[2] = 0.5 * v[2] - u[3] = 0.25 * v[3] - return 0 -end + # Hessian-vector product + function hessprod(n::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, + got_h::Bool, userdata::userdata_tru) + u[1] = u[1] + 2.0 * (v[1] + v[3]) - cos(x[1]) * v[1] + u[2] = u[2] + 2.0 * (v[2] + v[3]) + u[3] = u[3] + 2.0 * (v[1] + v[2] + 2.0 * v[3]) + return 0 + end -# Objective function -function fun_diag(n::Int, x::Vector{Float64}, f::Ref{Float64}, userdata::userdata_type) - p = userdata.p - f[] = (x[3] + p)^2 + x[2]^2 + cos(x[1]) - return 0 -end + # Apply preconditioner + function prec(n::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, + userdata::userdata_tru) + u[1] = 0.5 * v[1] + u[2] = 0.5 * v[2] + u[3] = 0.25 * v[3] + return 0 + end -# Gradient of the objective -function grad_diag(n::Int, x::Vector{Float64}, g::Vector{Float64}, userdata::userdata_type) - p = userdata.p - g[1] = -sin(x[1]) - g[2] = 2.0 * x[2] - g[3] = 2.0 * (x[3] + p) - return 0 -end + # Objective function + function fun_diag(n::Int, x::Vector{Float64}, f::Ref{Float64}, userdata::userdata_tru) + p = userdata.p + f[] = (x[3] + p)^2 + x[2]^2 + cos(x[1]) + return 0 + end -# Hessian of the objective -function hess_diag(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, - userdata::userdata_type) - hval[1] = -cos(x[1]) - hval[2] = 2.0 - hval[3] = 2.0 - return 0 -end + # Gradient of the objective + function grad_diag(n::Int, x::Vector{Float64}, g::Vector{Float64}, userdata::userdata_tru) + p = userdata.p + g[1] = -sin(x[1]) + g[2] = 2.0 * x[2] + g[3] = 2.0 * (x[3] + p) + return 0 + end -# Hessian-vector product -function hessprod_diag(n::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, - got_h::Bool, userdata::userdata_type) - u[1] = u[1] + -cos(x[1]) * v[1] - u[2] = u[2] + 2.0 * v[2] - u[3] = u[3] + 2.0 * v[3] - return 0 -end + # Hessian of the objective + function hess_diag(n::Int, ne::Int, x::Vector{Float64}, hval::Vector{Float64}, + userdata::userdata_tru) + hval[1] = -cos(x[1]) + hval[2] = 2.0 + hval[3] = 2.0 + return 0 + end + + # Hessian-vector product + function hessprod_diag(n::Int, x::Vector{Float64}, u::Vector{Float64}, v::Vector{Float64}, + got_h::Bool, userdata::userdata_tru) + u[1] = u[1] + -cos(x[1]) * v[1] + u[2] = u[2] + 2.0 * v[2] + u[3] = u[3] + 2.0 * v[3] + return 0 + end -function test_tru() # Derived types data = Ref{Ptr{Cvoid}}() control = Ref{tru_control_type{Float64}}() inform = Ref{tru_inform_type{Float64}}() # Set user data - userdata = userdata_type(4.0) + userdata = userdata_tru(4.0) # Set problem data n = 3 # dimension diff --git a/GALAHAD.jl/test/test_ugo.jl b/GALAHAD.jl/test/test_ugo.jl index cc10243021..fd8a45f532 100644 --- a/GALAHAD.jl/test/test_ugo.jl +++ b/GALAHAD.jl/test/test_ugo.jl @@ -41,13 +41,6 @@ function test_ugo() # Set user-defined control options @reset control[].print_level = Cint(1) - # control.prefix = "'ugo: '" - @reset control[].prefix = galahad_linear_solver("'ugo: '") - - # Read options from specfile - specfile = "UGO.SPC" - ugo_read_specfile(control, specfile) - # Test problem bounds x_l = Ref{Float64}(-1.0) x_u = Ref{Float64}(2.0) From 4d0f38ef2b60120ecefee1255c219f7838dca030 Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Tue, 13 Feb 2024 19:48:27 -0500 Subject: [PATCH 33/33] Update GALAHAD.jl/gen/README.md --- GALAHAD.jl/gen/README.md | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/GALAHAD.jl/gen/README.md b/GALAHAD.jl/gen/README.md index 2766aae9d2..0f463a07f0 100644 --- a/GALAHAD.jl/gen/README.md +++ b/GALAHAD.jl/gen/README.md @@ -111,16 +111,25 @@ loading the Julia interface with `using GALAHAD`. # Tests -The file `examples.jl` help to generate Julia tests based on the C tests of a GALAHAD package. -- Create symbolic link -- Explain "tf", "t" or "" -- Call clean_example(...) +The file `examples.jl` aids in generating Julia tests based on the +C tests within a GALAHAD package. To facilitate the translation of a C +test `GALAHAD/src/abcd/C/abcdtf.c` into a Julia test, follow these steps: + +Add the following entry to `examples.jl`: ```julia (name == "abcd") && examples("abcd", "tf") ``` -To test the new package named `abcd`, insert the following line in `GALAHAD.jl/test/runtests.jl`: +Replace `"tf"` with `"t"` if translating a test from `abcdt.c`, or use `""` if no corresponding C test exists. + +After including `examples.jl`, invoking `main("abcd")` will generate the file `test_abcd.jl` in the +directory `GALAHAD.jl/test`, along with a symbolic link pointing to this file in `GALAHAD/src/abcd/Julia`. + +After manual modifications to ensure the Julia test works correctly, you can utilize `clean_example("abcd")` +to format the file. + +To test the new package named `abcd` alongside other packages, insert the following line in `GALAHAD.jl/test/runtests.jl`: ```julia include("test_abcd.jl")