Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw errors #20

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Problem/SpkProblem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ The value is *added* to the existing contents.
"""
function inaij!(p::Problem{IT,FT}, rnum, cnum, aij=zero(FT)) where {IT<:BlasInt, FT}
if (rnum < 1 || cnum < 1)
@warn "$(@__FILE__): invalid matrix subscripts $(rnum), $(cnum): input ignored"
@warn "Invalid matrix subscripts $(rnum), $(cnum): input ignored"
return false
end

Expand Down Expand Up @@ -257,7 +257,7 @@ Input an entry of the right-hand side vector.
"""
function inbi!(p::Problem{IT, FT}, rnum::IT, bi::FT) where {IT<:BlasInt, FT}
if (rnum < 1)
@error "$(@__FILE__): Invalid rhs subscript $(rnum)."
error("Invalid rhs subscript $(rnum).")
return false
end

Expand Down Expand Up @@ -401,7 +401,7 @@ Updated Parameter:
"""
function makerhs!(p::Problem, x::Vector{FT}, mtype = "T") where {FT}
if (p.nnz == 0)
@error "$(@__FILE__): Matrix is NULL. The rhs cannot be computed."
error("Matrix is NULL. The rhs cannot be computed.")
return p
end

Expand Down Expand Up @@ -462,7 +462,7 @@ function computeresidual(p::Problem, res::Vector{FT}, xin::Vector{FT} = FT[], mt
if (lowercase(mtype) == "t" || lowercase(mtype) == "l" || lowercase(mtype) == "u")
flag = 1
else
@error "$(@__FILE__): Invalid value for mtype, $mtype."
error("Invalid value for mtype, $mtype.")
return false
end

Expand Down
6 changes: 3 additions & 3 deletions src/SparseCSCInterface/SparseCSCInterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ end

function _inmatrix!(s::_SparseBase{IT, FT}, m::SparseMatrixCSC{FT,IT}) where {IT, FT}
if (s.n == 0)
@error "$(@__FILE__): An empty problem. No matrix."
error("An empty problem. No matrix.")
return false
end

Expand All @@ -128,7 +128,7 @@ function _inmatrix!(s::_SparseBase{IT, FT}, m::SparseMatrixCSC{FT,IT}) where {IT
for nxtsub in fstsub:lstsub
irow = lindx[nxtsub]
if (irow > inew)
@error "$(@__FILE__): No space for matrix element $(inew), $(jnew)."
error("No space for matrix element ($(inew), $(jnew)).")
return false
end
if (irow == inew)
Expand All @@ -151,7 +151,7 @@ function _inmatrix!(s::_SparseBase{IT, FT}, m::SparseMatrixCSC{FT,IT}) where {IT
for nxtsub in fstsub:lstsub
irow = lindx[nxtsub]
if (irow > jnew)
@error "$(@__FILE__): No space for matrix element $(inew), $(jnew)."
error("No space for matrix element ($(inew), $(jnew)).")
return false
end
if (irow == jnew)
Expand Down
2 changes: 1 addition & 1 deletion src/SparseMethod/SpkLUFactor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ function _luusolve!(n::IT, nsuper::IT, xsuper::Vector{IT}, xlindx::Vector{IT}, l
jj = jj + 1
isub = lindx[jj]
if (isub > n)
@error "$(@__FILE__): $(isub) index out of bounds in rhs"
error("Index $(isub) out of bounds in rhs")
return false
end
temp[j] = rhs[isub]
Expand Down
16 changes: 8 additions & 8 deletions src/SparseMethod/SpkSparseBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ end

function _findorder!(s::_SparseBase{IT}, orderfunction::F) where {IT, F}
if (s.n == 0)
@error "$(@__FILE__): An empty problem, no ordering found."
error("An empty problem, no ordering found.")
return false
end
makestructuresymmetric(s.g) # Make it symmetric
Expand All @@ -196,7 +196,7 @@ function _symbolicfactor!(s::_SparseBase{IT, FT}) where {IT, FT}
#
# """
if (s.n == 0)
@error "$(@__FILE__): An empty problem. No symbolic factorization done."
error("An empty problem. No symbolic factorization done.")
return false
end

Expand Down Expand Up @@ -304,7 +304,7 @@ end

function _inmatrix!(s::_SparseBase{IT, FT}, p::Problem{IT, FT}) where {IT, FT}
if (s.n == 0)
@error "$(@__FILE__): An empty problem. No matrix."
error("An empty problem. No matrix.")
return false
end

Expand All @@ -331,7 +331,7 @@ function _inmatrix!(s::_SparseBase{IT, FT}, p::Problem{IT, FT}) where {IT, FT}
for nxtsub in fstsub:lstsub
irow = lindx[nxtsub]
if (irow > inew)
@error "$(@__FILE__): No space for matrix element $(inew), $(jnew)."
error("No space for matrix element ($(inew), $(jnew)).")
return false
end
if (irow == inew)
Expand All @@ -354,7 +354,7 @@ function _inmatrix!(s::_SparseBase{IT, FT}, p::Problem{IT, FT}) where {IT, FT}
for nxtsub in fstsub:lstsub
irow = lindx[nxtsub]
if (irow > jnew)
@error "$(@__FILE__): No space for matrix element $(inew), $(jnew)."
error("No space for matrix element ($(inew), $(jnew)).")
return false
end
if (irow == jnew)
Expand All @@ -380,14 +380,14 @@ end
# in the comments at the beginning of this module.
function _factor!(s::_SparseBase{IT, FT}) where {IT, FT}
if (s.n == 0)
@error "$(@__FILE__): An empty problem. No matrix."
error("An empty problem. No matrix.")
return false
end

s.errflag = _lufactor!(s.n, s.nsuper, s.xsuper, s.snode, s.xlindx, s.lindx, s.xlnz, s.lnz, s.xunz, s.unz, s.ipiv)

if (s.errflag != 0)
@error "$(@__FILE__): An empty problem. No matrix."
error("An empty problem. No matrix.")
return false
end
return true
Expand All @@ -402,7 +402,7 @@ end
# object is applied as appropriate.
function _triangularsolve!(s::_SparseBase{IT, FT}, solution::AbstractVector{FT}) where {IT, FT}
if (s.n == 0)
@error "$(@__FILE__): An empty problem. No solution."
error("An empty problem. No solution.")
return false
end

Expand Down
2 changes: 1 addition & 1 deletion src/SparseSpdMethod/SpkSymFct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ function _symbolicfact!(n, xadj, adj, perm, invp, colcnt, nsuper, xsuper, snode,
# - - - - - - - - - - -
nzbeg = nzend + 1; nzend = nzend + knz
if (nzend + 1 != xlindx[ksup + 1])
@error "$(@__FILE__): inconsistency in data structure."
error("Inconsistency in data structure.")
return false
end

Expand Down
12 changes: 12 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
using Test


#
# Error in LinearSolve - once fixed, move to the end...
#
# @time @testset "Smallmatrix" begin
# include("test_smallmatrix.jl")
# end

@time @testset "Small tricky problem" begin
include("test_small.jl")
end

@time @testset "Problem" begin
include("test_problem.jl")
end
Expand Down
200 changes: 193 additions & 7 deletions test/test_small.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

module m_simpletest
using Test
using Sparspak
using Random, SparseArrays, LinearAlgebra
Expand All @@ -14,18 +14,204 @@ function simpletest(;n=4)
A[2,1]=-0.1
pr = SpkProblem.Problem(n,n, 10)
@test SpkProblem.insparse!(pr, A)
@show pr
s = SpkSparseSolver.SparseSolver(pr)
@test SpkSparseSolver.findorder!(s)
end

simpletest()
end

#
module m_inconsistency_data_structure_symm
using Test
using LinearAlgebra
using SparseArrays
using Sparspak.SpkOrdering
using Sparspak.SpkProblem
using Sparspak.SpkProblem: inaij!, inbi!, outsparse
using Sparspak.SpkSparseSolver: SparseSolver, findorder!, symbolicfactor!, inmatrix!, factor!, solve!, triangularsolve!

function makeaproblem()
# Matrix is not symmetric, but it does have a symmetric structure.
n = 4
A = [1.21883 -0.02432 0.0 0.942235;
0.0243952 1.0 0.0 0.0;
0.0 0.0 1.53656 0.0;
0.340938 0.0 0.0 1.0]

p = SpkProblem.Problem(n, n)
for i in 1:n, j in 1:n
if A[i, j] != 0.0
inaij!(p, i, j, A[i, j])
end
end
inbi!(p, 1, 1.0)

return p
end

function _test()
p = makeaproblem()

s = SparseSolver(p)

solve!(s)

A = outsparse(p)
x = A \ p.rhs
@test norm(p.x - x) / norm(x) < 1.0e-6

return true
end

_test()
end # module

module m_inconsistency_data_structure_symm_forced
using Test
using LinearAlgebra
using SparseArrays
using Sparspak.SpkOrdering
using Sparspak.SpkProblem
using Sparspak.SpkProblem: inaij!, inbi!, outsparse
using Sparspak.SpkSparseSolver: SparseSolver, findorder!, symbolicfactor!, inmatrix!, factor!, solve!, triangularsolve!

function makeaproblem()
# Matrix is not symmetric, but it will be input so that the structure is symmetric by definition.
n = 4
A = [1.21883 0.0 0.0 0.942235;
0.0243952 1.0 0.0 0.0;
0.0 0.0 1.53656 0.0;
0.0 0.0 0.0 1.0]

p = SpkProblem.Problem(n, n)
for i in 1:n, j in 1:n
if A[i, j] != 0.0
inaij!(p, i, j, A[i, j])
inaij!(p, j, i, 0.0)
end
end
inbi!(p, 1, 1.0)

return p
end

function _test()
p = makeaproblem()

s = SparseSolver(p)

solve!(s)

A = outsparse(p)
x = A \ p.rhs
@test norm(p.x - x) / norm(x) < 1.0e-6

#=
return true
end

_test()
end # module

module m_inconsistency_data_structure_unsymm
using Test
using LinearAlgebra
using SparseArrays
using Sparspak.SpkOrdering
using Sparspak.SpkProblem
using Sparspak.SpkProblem: inaij!, inbi!, outsparse
using Sparspak.SpkSparseSolver: SparseSolver, findorder!, symbolicfactor!, inmatrix!, factor!, solve!, triangularsolve!

function makeaproblem()
# Matrix is not symmetric and it does not have a symmetric structure.
n = 4
A = [1.21883 0.0 0.0 0.942235;
0.0243952 1.0 0.0 0.0;
0.0 0.0 1.53656 0.0;
0.340938 0.0 0.0 1.0]

p = SpkProblem.Problem(n, n)
# inaij!(p, 1, 1, 1.21883);
# inaij!(p, 2, 1, 0.0243952);
# inaij!(p, 4, 1, 0.340938);
# inaij!(p, 2, 2, 1.0);
# inaij!(p, 3, 3, 1.53656);
# inaij!(p, 1, 4, 0.942235);
# inaij!(p, 4, 4, 1.0);
for i in 1:n, j in 1:n
if A[i, j] != 0.0
inaij!(p, i, j, A[i, j])
end
end
inbi!(p, 1, 1.0)

return p
end

function _test()
p = makeaproblem()

s = SparseSolver(p)

solve!(s)

A = outsparse(p)
x = A \ p.rhs
@test norm(p.x - x) / norm(x) < 1.0e-6

return true
end

_test()
end # module
#
module m_inconsistency_symfact
using Test
using LinearAlgebra
using SparseArrays
using Sparspak.SpkOrdering
using Sparspak.SpkProblem
using Sparspak.SpkProblem: inaij!, inbi!, outsparse
using Sparspak.SpkSparseSolver: SparseSolver, findorder!, symbolicfactor!, inmatrix!, factor!, solve!, triangularsolve!

julia> include("C:\\Users\\pkonl\\Documents\\00WIP\\Sparspak.jl\\test\\test_small.jl")pr = Sparspak.SpkProblem.Problem{Int64, Float64}("", 4, 10, 4, 5, [1, 3, 4, 5], [2, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 2, 2, 3, 4, 0, 0, 0, 0, 0], 4, 4, 15, 4, 5, 4, [1.00000e+00, -1.00000e-01, 1.00000e+00, 1.00000e+00, 1.00000e+00, Inf, Inf, Inf, Inf, Inf], Float64[], Float64[], [0.00000e+00, 0.00000e+00, 0.00000e+00, 0.00000e+00], [0.00000e+00, 0.00000e+00, 0.00000e+00, 0.00000e+00])
function makeaproblem()
n = 4
A = [1.21883 0.0 0.0 0.942235;
0.0243952 1.0 0.0 0.0;
0.0 0.0 1.53656 0.0;
0.340938 0.0 0.0 1.0]

p = SpkProblem.Problem(n, n)
inaij!(p, 1, 1, 1.21883);
inaij!(p, 2, 1, 0.0243952);
inaij!(p, 4, 1, 0.340938);
inaij!(p, 2, 2, 1.0);
inaij!(p, 3, 3, 1.53656);
inaij!(p, 1, 4, 0.942235);
inaij!(p, 4, 4, 1.0);
# for i in 1:n, j in 1:n
# if A[i, j] != 0.0
# inaij!(p, i, j, A[i, j])
# end
# end

return p
end

function _test()
p = makeaproblem()

s = SparseSolver(p)

solve!(s)

A = outsparse(p)
x = A \ p.rhs
@test norm(p.x - x) / norm(x) < 1.0e-6

return true
end

g = Sparspak.SpkGraph.Graph{Int64}(4, 1, 4, 4, [1, 2, 2, 2, 2], [2])
(k, first, g.adj) = (2, [1, 2, 2, 2], [2])
_test()
end # module

=#