Skip to content

Commit

Permalink
[GALAHAD.jl] Add test_blls.jl and test_slls.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
amontoison committed Feb 14, 2024
1 parent 52d8f7b commit 4ca7f94
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 235 deletions.
4 changes: 2 additions & 2 deletions GALAHAD.jl/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ include("test_structures.jl")

include("test_arc.jl")
include("test_bgo.jl")
## include("test_blls.jl")
include("test_blls.jl")
include("test_bllsb.jl")
include("test_bqp.jl")
include("test_bqpb.jl")
Expand Down Expand Up @@ -49,7 +49,7 @@ include("test_scu.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")
Expand Down
139 changes: 20 additions & 119 deletions GALAHAD.jl/test/test_blls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,103 +142,7 @@ function test_blls()
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, C_NULL)

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, prec)
end

# sparse by rows
if d == 2
st = "SR"
blls_import(control, data, status, n, o,
"sparse_by_rows", Ao_ne, C_NULL, Ao_col,
Ao_ptr_ne, Ao_ptr)

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, prec)
end

# dense by rows
if d == 3
st = "DR"
blls_import(control, data, status, n, o,
"dense_by_rows", Ao_dense_ne,
C_NULL, C_NULL, 0, C_NULL)

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, prec)
end

# sparse by columns
if d == 4
st = "SC"
blls_import(control, data, status, n, o,
"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, userdata_blls, 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,
C_NULL, C_NULL, 0, C_NULL)

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, 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
@printf(" tests reverse-communication options\n\n")

# reverse-communication input/output
on = max(o, n)
Expand All @@ -250,7 +154,6 @@ function test_blls()
mask = zeros(Cint, o)
v = zeros(Float64, on)
p = zeros(Float64, on)

nz_p_end = 1

# Initialize BLLS
Expand All @@ -265,7 +168,7 @@ function test_blls()
z[i] = 0.0
end

st = "RZ"
st = "RC"
for i in 1:o
mask[i] = 0
end
Expand All @@ -283,51 +186,47 @@ function test_blls()
elseif status[] < 0 # error exit
terminated = true
elseif status[] == 2 # evaluate p = Av
p[n + 1] = 0.0
p[o] = 0.0
for i in 1:n
p[i] = v[i]
p[n + 1] = p[n + 1] + v[i]
p[o] = p[o] + v[i]
end
elseif status[] == 3 # evaluate p = A^Tv
for i in 1:n
p[i] = v[i] + v[n + 1]
p[i] = v[i] + v[o]
end
elseif status[] == 4 # evaluate p = Av for sparse v
p[n + 1] = 0.0
for i in 1:n
for i in 1:o
p[i] = 0.0
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]
p[o] = p[o] + v[i]
end
elseif status[] == 5 # evaluate p = sparse Av for sparse v
nz_p_end = 1
nz_p_end = 0
for l in nz_v_start[]:nz_v_end[]
i = nz_v[l]
nz_p_end = nz_p_end + 1
nz_p[nz_p_end] = i
p[i] = v[i]
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]
p[o] = v[i]
else
p[n + 1] = p[n + 1] + v[i]
end
for l in 1:nz_p_end
mask[nz_p[l]] = 0 # <-- Nick I need your help here
p[o] = p[o] + 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]
p[i] = v[i] + v[n + 1]
p[i] = v[i] + v[o]
end
elseif status[] == 7 # evaluate p = P^{-}v
for i in 1:n
Expand Down Expand Up @@ -360,7 +259,9 @@ function test_blls()
# @printf("\n")

# Delete internal workspace
return blls_terminate(data, control, inform)
blls_terminate(data, control, inform)

return 0
end

@testset "BLLS" begin
Expand Down
128 changes: 14 additions & 114 deletions GALAHAD.jl/test/test_slls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,103 +123,8 @@ function test_slls()
end

@printf(" fortran sparse matrix indexing\n\n")
@printf(" basic tests of slls storage formats\n\n")
@printf(" tests reverse-communication options\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, C_NULL)

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, 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)
end

# dense by rows
if d == 3
st = "DR"
slls_import(control, data, status, n, o,
"dense_by_rows", Ao_dense_ne,
C_NULL, C_NULL, 0, C_NULL)

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,
C_NULL, 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,
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)
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}()
Expand All @@ -231,8 +136,7 @@ function test_slls()
mask = zeros(Cint, o)
v = zeros(Float64, on)
p = zeros(Float64, on)

nz_p_end = 0
nz_p_end = 1

# Initialize SLLS
slls_initialize(data, control, status)
Expand Down Expand Up @@ -264,42 +168,38 @@ function test_slls()
elseif status[] < 0 # error exit
terminated = true
elseif status[] == 2 # evaluate p = Av
p[n + 1] = 0.0
p[o] = 0.0
for i in 1:n
p[i] = v[i]
p[n + 1] = p[n + 1] + v[i]
p[o] = p[o] + v[i]
end
elseif status[] == 3 # evaluate p = A^Tv
for i in 1:n
p[i] = v[i] + v[n + 1]
p[i] = v[i] + v[o]
end
elseif status[] == 4 # evaluate p = Av for sparse v
p[n + 1] = 0.0
for i in 1:n
for i in 1:o
p[i] = 0.0
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]
p[o] = p[o] + v[i]
end
elseif status[] == 5 # evaluate p = sparse Av for sparse v
nz_p_end = 1
nz_p_end = 0
for l in nz_v_start[]:nz_v_end[]
i = nz_v[l]
nz_p_end = nz_p_end + 1
nz_p[nz_p_end] = i
p[i] = v[i]
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]
p[o] = v[i]
else
p[n] = p[n] + v[i]
p[o] = p[o] + v[i]
end
end
for l in 1:nz_p_end
Expand All @@ -308,7 +208,7 @@ function test_slls()
elseif status[] == 6 # evaluate p = sparse A^Tv
for l in nz_v_start[]:nz_v_end[]
i = nz_v[l]
p[i] = v[i] + v[n]
p[i] = v[i] + v[o]
end
elseif status[] == 7 # evaluate p = P^{-}v
for i in 1:n
Expand Down

0 comments on commit 4ca7f94

Please sign in to comment.