Skip to content

Commit

Permalink
[HSL_SUBSET] Add default constructors (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
amontoison authored Dec 26, 2024
1 parent 8df68fa commit f7d0158
Show file tree
Hide file tree
Showing 12 changed files with 255 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "HSL"
uuid = "34c5aeac-e683-54a6-a0e9-6e0fdc586c50"
version = "0.4.3"
version = "0.5.0"

[deps]
HSL_jll = "017b0a0e-03f4-516a-9b91-836bbd1904dd"
Expand Down
21 changes: 21 additions & 0 deletions gen/rewriter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ function hsl_subset_rewrite!(path::String, name::String, optimized::Bool)
routine = code * "end\n"
if name == "hsl_mc68"
endswith(fname, "_i") || error("The symbol $fname should have the suffix _i")
pp_fname = replace(pp_fname, "control_d" => "control_i")
pp_fname = replace(pp_fname, "order_d" => "order_i")
routine = replace(routine, "function $fname(" => "function $(fname_generic)(::Type{$ipc_}, ")
else
endswith(fname, "_d") || error("The symbol $fname should have the suffix _d")
Expand Down Expand Up @@ -191,11 +193,30 @@ function hsl_subset_rewrite!(path::String, name::String, optimized::Bool)
structure = replace(structure, "ipc_" => "INT")
if !contains(code, "rpc_")
structure = replace(structure, structure_name => generic_structure_name * "{INT}")
types = "{INT}"
push!(info_structures, (structure_name, generic_structure_name, false))
else
structure = replace(structure, structure_name => generic_structure_name * "{T,INT}")
types = "{T,INT}"
push!(info_structures, (structure_name, generic_structure_name, true))
end

# Add two constructors for each structure
arguments = ""
lines = split(code, "\n", keepempty=false)
for line in lines
if contains(line, "::")
argument = split(line, "::")[1][3:end]
if arguments == ""
arguments *= argument
else
arguments *= ", $argument"
end
end
end
structure = replace(structure, "end\n" => "\n " * generic_structure_name * "$types() where $types = new$types()\nend\n")
structure = replace(structure, "end\n" => "\n " * generic_structure_name * "$types($arguments) where $types = new$types($arguments)\nend\n")

structures = structures * structure * "\n"
else
text = text * code
Expand Down
31 changes: 31 additions & 0 deletions src/C/hsl_subset/hsl_ma48.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ mutable struct Ma48Control{T, INT}
diagonal_pivoting::INT
fill_in::INT
switch_mode::INT

Ma48Control{T, INT}() where {T,INT} = new{T, INT}()

function Ma48Control{T, INT}(f_arrays, multiplier, u, switch_, drop, tolerance, cgce, lp, wp, mp,
ldiag, btf, struct_, maxit, factor_blocking, solve_blas, pivoting,
diagonal_pivoting, fill_in, switch_mode) where {T,INT}
return new{T, INT}(f_arrays, multiplier, u, switch_, drop, tolerance, cgce, lp, wp, mp, ldiag,
btf, struct_, maxit, factor_blocking, solve_blas, pivoting,
diagonal_pivoting, fill_in, switch_mode)
end
end

mutable struct Ma48Ainfo{T, INT}
Expand All @@ -39,6 +49,15 @@ mutable struct Ma48Ainfo{T, INT}
lblock::INT
sblock::INT
tblock::Int64

Ma48Ainfo{T, INT}() where {T,INT} = new{T, INT}()

function Ma48Ainfo{T, INT}(ops, flag, more, lena_analyse, lenj_analyse, lena_factorize,
leni_factorize, ncmpa, rank, drop, struc_rank, oor, dup, stat, lblock,
sblock, tblock) where {T,INT}
return new{T, INT}(ops, flag, more, lena_analyse, lenj_analyse, lena_factorize, leni_factorize,
ncmpa, rank, drop, struc_rank, oor, dup, stat, lblock, sblock, tblock)
end
end

mutable struct Ma48Finfo{T, INT}
Expand All @@ -51,12 +70,24 @@ mutable struct Ma48Finfo{T, INT}
drop::Int64
rank::INT
stat::INT

Ma48Finfo{T, INT}() where {T,INT} = new{T, INT}()

function Ma48Finfo{T, INT}(ops, flag, more, size_factor, lena_factorize, leni_factorize, drop,
rank, stat) where {T,INT}
return new{T, INT}(ops, flag, more, size_factor, lena_factorize, leni_factorize, drop, rank,
stat)
end
end

mutable struct Ma48Sinfo{INT}
flag::INT
more::INT
stat::INT

Ma48Sinfo{INT}() where {INT} = new{INT}()

Ma48Sinfo{INT}(flag, more, stat) where {INT} = new{INT}(flag, more, stat)
end

function ma48_initialize(::Type{Float32}, ::Type{Int32}, factors)
Expand Down
40 changes: 40 additions & 0 deletions src/C/hsl_subset/hsl_ma57.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ mutable struct Ma57Control{T, INT}
rank_deficient::INT
ispare::NTuple{5, INT}
rspare::NTuple{10, T}

Ma57Control{T, INT}() where {T,INT} = new{T, INT}()

function Ma57Control{T, INT}(f_arrays, multiplier, reduce, u, static_tolerance, static_level,
tolerance, convergence, consist, lp, wp, mp, sp, ldiag, nemin,
factorblocking, solveblocking, la, liw, maxla, maxliw, pivoting,
thresh, ordering, scaling, rank_deficient, ispare,
rspare) where {T,INT}
return new{T, INT}(f_arrays, multiplier, reduce, u, static_tolerance, static_level, tolerance,
convergence, consist, lp, wp, mp, sp, ldiag, nemin, factorblocking,
solveblocking, la, liw, maxla, maxliw, pivoting, thresh, ordering, scaling,
rank_deficient, ispare, rspare)
end
end

mutable struct Ma57Ainfo{T, INT}
Expand All @@ -49,6 +62,15 @@ mutable struct Ma57Ainfo{T, INT}
stat::INT
ispare::NTuple{5, INT}
rspare::NTuple{10, T}

Ma57Ainfo{T, INT}() where {T,INT} = new{T, INT}()

function Ma57Ainfo{T, INT}(opsa, opse, flag, more, nsteps, nrltot, nirtot, nrlnec, nirnec, nrladu,
niradu, ncmpa, ordering, oor, dup, maxfrt, stat, ispare,
rspare) where {T,INT}
return new{T, INT}(opsa, opse, flag, more, nsteps, nrltot, nirtot, nrlnec, nirnec, nrladu,
niradu, ncmpa, ordering, oor, dup, maxfrt, stat, ispare, rspare)
end
end

mutable struct Ma57Finfo{T, INT}
Expand Down Expand Up @@ -80,6 +102,17 @@ mutable struct Ma57Finfo{T, INT}
stat::INT
ispare::NTuple{5, INT}
rspare::NTuple{10, T}

Ma57Finfo{T, INT}() where {T,INT} = new{T, INT}()

function Ma57Finfo{T, INT}(opsa, opse, opsb, maxchange, smin, smax, flag, more, maxfrt, nebdu,
nrlbdu, nirbdu, nrltot, nirtot, nrlnec, nirnec, ncmpbr, ncmpbi, ntwo,
neig, delay, signc, static_, modstep, rank, stat, ispare,
rspare) where {T,INT}
return new{T, INT}(opsa, opse, opsb, maxchange, smin, smax, flag, more, maxfrt, nebdu, nrlbdu,
nirbdu, nrltot, nirtot, nrlnec, nirnec, ncmpbr, ncmpbi, ntwo, neig, delay,
signc, static_, modstep, rank, stat, ispare, rspare)
end
end

mutable struct Ma57Sinfo{T, INT}
Expand All @@ -92,6 +125,13 @@ mutable struct Ma57Sinfo{T, INT}
stat::INT
ispare::NTuple{5, INT}
rspare::NTuple{10, T}

Ma57Sinfo{T, INT}() where {T,INT} = new{T, INT}()

function Ma57Sinfo{T, INT}(cond, cond2, berr, berr2, error, flag, stat, ispare,
rspare) where {T,INT}
return new{T, INT}(cond, cond2, berr, berr2, error, flag, stat, ispare, rspare)
end
end

function ma57_default_control(::Type{Float32}, ::Type{Int32}, control)
Expand Down
27 changes: 27 additions & 0 deletions src/C/hsl_subset/hsl_ma77.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ mutable struct Ma77Control{T, INT}
ispare::NTuple{5, INT}
lspare::NTuple{5, Int64}
rspare::NTuple{5, T}

Ma77Control{T, INT}() where {T,INT} = new{T, INT}()

function Ma77Control{T, INT}(f_arrays, print_level, unit_diagnostics, unit_error, unit_warning,
bits, buffer_lpage, buffer_npage, file_size, maxstore, storage,
nemin, maxit, infnorm, thresh, nb54, action, multiplier, nb64, nbi,
small, static_, storage_indef, u, umin, consist_tol, ispare, lspare,
rspare) where {T,INT}
return new{T, INT}(f_arrays, print_level, unit_diagnostics, unit_error, unit_warning, bits,
buffer_lpage, buffer_npage, file_size, maxstore, storage, nemin, maxit,
infnorm, thresh, nb54, action, multiplier, nb64, nbi, small, static_,
storage_indef, u, umin, consist_tol, ispare, lspare, rspare)
end
end

mutable struct Ma77Info{T, INT}
Expand Down Expand Up @@ -65,6 +78,20 @@ mutable struct Ma77Info{T, INT}
ispare::NTuple{5, INT}
lspare::NTuple{5, Int64}
rspare::NTuple{5, T}

Ma77Info{T, INT}() where {T,INT} = new{T, INT}()

function Ma77Info{T, INT}(detlog, detsign, flag, iostat, matrix_dup, matrix_rank, matrix_outrange,
maxdepth, maxfront, minstore, ndelay, nfactor, nflops, niter, nsup,
num_neg, num_nothresh, num_perturbed, ntwo, stat, index, nio_read,
nio_write, nwd_read, nwd_write, num_file, storage, tree_nodes,
unit_restart, unused, usmall, ispare, lspare, rspare) where {T,INT}
return new{T, INT}(detlog, detsign, flag, iostat, matrix_dup, matrix_rank, matrix_outrange,
maxdepth, maxfront, minstore, ndelay, nfactor, nflops, niter, nsup, num_neg,
num_nothresh, num_perturbed, ntwo, stat, index, nio_read, nio_write,
nwd_read, nwd_write, num_file, storage, tree_nodes, unit_restart, unused,
usmall, ispare, lspare, rspare)
end
end

function ma77_default_control(::Type{Float32}, ::Type{Int32}, control)
Expand Down
19 changes: 19 additions & 0 deletions src/C/hsl_subset/hsl_ma86.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ mutable struct Ma86Control{T, INT}
u::T
umin::T
scaling::INT

Ma86Control{T, INT}() where {T,INT} = new{T, INT}()

function Ma86Control{T, INT}(f_arrays, diagnostics_level, unit_diagnostics, unit_error,
unit_warning, nemin, nb, action, nbi, pool_size, small_, static_, u,
umin, scaling) where {T,INT}
return new{T, INT}(f_arrays, diagnostics_level, unit_diagnostics, unit_error, unit_warning,
nemin, nb, action, nbi, pool_size, small_, static_, u, umin, scaling)
end
end

mutable struct Ma86Info{T, INT}
Expand All @@ -33,6 +42,16 @@ mutable struct Ma86Info{T, INT}
pool_size::INT
stat::INT
usmall::T

Ma86Info{T, INT}() where {T,INT} = new{T, INT}()

function Ma86Info{T, INT}(detlog, detsign, flag, matrix_rank, maxdepth, num_delay, num_factor,
num_flops, num_neg, num_nodes, num_nothresh, num_perturbed, num_two,
pool_size, stat, usmall) where {T,INT}
return new{T, INT}(detlog, detsign, flag, matrix_rank, maxdepth, num_delay, num_factor,
num_flops, num_neg, num_nodes, num_nothresh, num_perturbed, num_two,
pool_size, stat, usmall)
end
end

function ma86_default_control(::Type{Float32}, ::Type{Int32}, control)
Expand Down
17 changes: 17 additions & 0 deletions src/C/hsl_subset/hsl_ma87.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ mutable struct Ma87Control{T, INT}
diag_zero_minus::T
diag_zero_plus::T
unused::NTuple{40, Cchar}

Ma87Control{T, INT}() where {T,INT} = new{T, INT}()

function Ma87Control{T, INT}(f_arrays, diagnostics_level, unit_diagnostics, unit_error,
unit_warning, nemin, nb, pool_size, diag_zero_minus, diag_zero_plus,
unused) where {T,INT}
return new{T, INT}(f_arrays, diagnostics_level, unit_diagnostics, unit_error, unit_warning,
nemin, nb, pool_size, diag_zero_minus, diag_zero_plus, unused)
end
end

mutable struct Ma87Info{T, INT}
Expand All @@ -23,6 +32,14 @@ mutable struct Ma87Info{T, INT}
stat::INT
num_zero::INT
unused::NTuple{40, Cchar}

Ma87Info{T, INT}() where {T,INT} = new{T, INT}()

function Ma87Info{T, INT}(detlog, flag, maxdepth, num_factor, num_flops, num_nodes, pool_size,
stat, num_zero, unused) where {T,INT}
return new{T, INT}(detlog, flag, maxdepth, num_factor, num_flops, num_nodes, pool_size, stat,
num_zero, unused)
end
end

function ma87_default_control(::Type{Float32}, ::Type{Int32}, control)
Expand Down
22 changes: 22 additions & 0 deletions src/C/hsl_subset/hsl_ma97.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ mutable struct Ma97Control{T, INT}
consist_tol::T
ispare::NTuple{5, INT}
rspare::NTuple{10, T}

Ma97Control{T, INT}() where {T,INT} = new{T, INT}()

function Ma97Control{T, INT}(f_arrays, action, nemin, multiplier, ordering, print_level, scaling,
small, u, unit_diagnostics, unit_error, unit_warning, factor_min,
solve_blas3, solve_min, solve_mf, consist_tol, ispare,
rspare) where {T,INT}
return new{T, INT}(f_arrays, action, nemin, multiplier, ordering, print_level, scaling, small,
u, unit_diagnostics, unit_error, unit_warning, factor_min, solve_blas3,
solve_min, solve_mf, consist_tol, ispare, rspare)
end
end

mutable struct Ma97Info{T, INT}
Expand All @@ -41,6 +52,17 @@ mutable struct Ma97Info{T, INT}
maxsupernode::INT
ispare::NTuple{4, INT}
rspare::NTuple{10, T}

Ma97Info{T, INT}() where {T,INT} = new{T, INT}()

function Ma97Info{T, INT}(flag, flag68, flag77, matrix_dup, matrix_rank, matrix_outrange,
matrix_missing_diag, maxdepth, maxfront, num_delay, num_factor,
num_flops, num_neg, num_sup, num_two, ordering, stat, maxsupernode,
ispare, rspare) where {T,INT}
return new{T, INT}(flag, flag68, flag77, matrix_dup, matrix_rank, matrix_outrange,
matrix_missing_diag, maxdepth, maxfront, num_delay, num_factor, num_flops,
num_neg, num_sup, num_two, ordering, stat, maxsupernode, ispare, rspare)
end
end

function ma97_default_control(::Type{Float32}, ::Type{Int32}, control)
Expand Down
10 changes: 10 additions & 0 deletions src/C/hsl_subset/hsl_mc64.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,23 @@ mutable struct Mc64Control{INT}
sp::INT
ldiag::INT
checking::INT

Mc64Control{INT}() where {INT} = new{INT}()

function Mc64Control{INT}(f_arrays, lp, wp, sp, ldiag, checking) where {INT}
return new{INT}(f_arrays, lp, wp, sp, ldiag, checking)
end
end

mutable struct Mc64Info{INT}
flag::INT
more::INT
strucrank::INT
stat::INT

Mc64Info{INT}() where {INT} = new{INT}()

Mc64Info{INT}(flag, more, strucrank, stat) where {INT} = new{INT}(flag, more, strucrank, stat)
end

function mc64_default_control(::Type{Float32}, ::Type{Int32}, control)
Expand Down
24 changes: 20 additions & 4 deletions src/C/hsl_subset/hsl_mc68.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ mutable struct Mc68Control{INT}
print_level::INT
row_full_thresh::INT
row_search::INT

Mc68Control{INT}() where {INT} = new{INT}()

function Mc68Control{INT}(f_array_in, f_array_out, min_l_workspace, lp, wp, mp, nemin,
print_level, row_full_thresh, row_search) where {INT}
return new{INT}(f_array_in, f_array_out, min_l_workspace, lp, wp, mp, nemin, print_level,
row_full_thresh, row_search)
end
end

mutable struct Mc68Info{INT}
Expand All @@ -22,25 +30,33 @@ mutable struct Mc68Info{INT}
l_workspace::Int64
zb01_info::INT
n_dense_rows::INT

Mc68Info{INT}() where {INT} = new{INT}()

function Mc68Info{INT}(flag, iostat, stat, out_range, duplicate, n_compressions, n_zero_eigs,
l_workspace, zb01_info, n_dense_rows) where {INT}
return new{INT}(flag, iostat, stat, out_range, duplicate, n_compressions, n_zero_eigs,
l_workspace, zb01_info, n_dense_rows)
end
end

function mc68_default_control(::Type{Int32}, control)
@ccall libhsl_subset.mc68_default_control_d(control::Ref{Mc68Control{Int32}})::Cvoid
@ccall libhsl_subset.mc68_default_control_i(control::Ref{Mc68Control{Int32}})::Cvoid
end

function mc68_default_control(::Type{Int64}, control)
@ccall libhsl_subset_64.mc68_default_control_d_64(control::Ref{Mc68Control{Int64}})::Cvoid
@ccall libhsl_subset_64.mc68_default_control_i_64(control::Ref{Mc68Control{Int64}})::Cvoid
end

function mc68_order(::Type{Int32}, ord, n, ptr, row, perm, control, info)
@ccall libhsl_subset.mc68_order_d(ord::Int32, n::Int32, ptr::Ptr{Int32}, row::Ptr{Int32},
@ccall libhsl_subset.mc68_order_i(ord::Int32, n::Int32, ptr::Ptr{Int32}, row::Ptr{Int32},
perm::Ptr{Int32},
control::Ref{Mc68Control{Int32}},
info::Ref{Mc68Info{Int32}})::Cvoid
end

function mc68_order(::Type{Int64}, ord, n, ptr, row, perm, control, info)
@ccall libhsl_subset_64.mc68_order_d_64(ord::Int64, n::Int64, ptr::Ptr{Int64}, row::Ptr{Int64},
@ccall libhsl_subset_64.mc68_order_i_64(ord::Int64, n::Int64, ptr::Ptr{Int64}, row::Ptr{Int64},
perm::Ptr{Int64},
control::Ref{Mc68Control{Int64}},
info::Ref{Mc68Info{Int64}})::Cvoid
Expand Down
Loading

0 comments on commit f7d0158

Please sign in to comment.