diff --git a/src/HYPRE.jl b/src/HYPRE.jl index 07b11a2..294ded2 100644 --- a/src/HYPRE.jl +++ b/src/HYPRE.jl @@ -207,7 +207,6 @@ function Internals.to_hypre_data(A::SparseMatrixCSR, ilower, iupper) return nrows, ncols, rows, cols, values end -# TODO: Default to ilower = 1, iupper = size(B, 1)? function HYPREMatrix(comm::MPI.Comm, B::Union{SparseMatrixCSC,SparseMatrixCSR}, ilower, iupper) A = HYPREMatrix(comm, ilower, iupper) nrows, ncols, rows, cols, values = Internals.to_hypre_data(B, ilower, iupper) @@ -216,7 +215,7 @@ function HYPREMatrix(comm::MPI.Comm, B::Union{SparseMatrixCSC,SparseMatrixCSR}, return A end -HYPREMatrix(B::Union{SparseMatrixCSC,SparseMatrixCSR}, ilower, iupper) = +HYPREMatrix(B::Union{SparseMatrixCSC,SparseMatrixCSR}, ilower=1, iupper=size(B, 1)) = HYPREMatrix(MPI.COMM_WORLD, B, ilower, iupper) ######################### @@ -231,7 +230,6 @@ function Internals.to_hypre_data(x::Vector, ilower, iupper) end # TODO: Internals.to_hypre_data(x::SparseVector, ilower, iupper) (?) -# TODO: Default to ilower = 1, iupper = length(x)? function HYPREVector(comm::MPI.Comm, x::Vector, ilower, iupper) b = HYPREVector(comm, ilower, iupper) nvalues, indices, values = Internals.to_hypre_data(x, ilower, iupper) @@ -240,7 +238,8 @@ function HYPREVector(comm::MPI.Comm, x::Vector, ilower, iupper) return b end -HYPREVector(x::Vector, ilower, iupper) = HYPREVector(MPI.COMM_WORLD, x, ilower, iupper) +HYPREVector(x::Vector, ilower=1, iupper=length(x)) = + HYPREVector(MPI.COMM_WORLD, x, ilower, iupper) function Base.copy!(x::Vector, h::HYPREVector) ilower, iupper = Internals.get_proc_rows(h) diff --git a/test/runtests.jl b/test/runtests.jl index 8b851db..71d9e50 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -52,18 +52,36 @@ end CSC = sprand(5, 10, 0.3) CSR = sparsecsr(findnz(CSC)..., size(CSC)...) @test CSC == CSR + H = HYPREMatrix(CSC, ilower, iupper) @test H.IJMatrix != HYPRE_IJMatrix(C_NULL) @test H.ParCSRMatrix != HYPRE_ParCSRMatrix(C_NULL) H = HYPREMatrix(MPI.COMM_WORLD, CSC, ilower, iupper) @test H.IJMatrix != HYPRE_IJMatrix(C_NULL) @test H.ParCSRMatrix != HYPRE_ParCSRMatrix(C_NULL) + H = HYPREMatrix(CSR, ilower, iupper) @test H.IJMatrix != HYPRE_IJMatrix(C_NULL) @test H.ParCSRMatrix != HYPRE_ParCSRMatrix(C_NULL) H = HYPREMatrix(MPI.COMM_WORLD, CSR, ilower, iupper) @test H.IJMatrix != HYPRE_IJMatrix(C_NULL) @test H.ParCSRMatrix != HYPRE_ParCSRMatrix(C_NULL) + + # Default to owning all rows + CSC = sprand(10, 10, 0.3) + CSR = sparsecsr(findnz(CSC)..., size(CSC)...) + H = HYPREMatrix(CSC) + @test H.IJMatrix != HYPRE_IJMatrix(C_NULL) + @test H.ParCSRMatrix != HYPRE_ParCSRMatrix(C_NULL) + @test H.comm == MPI.COMM_WORLD + @test H.ilower == H.jlower == 1 + @test H.iupper == H.jupper == 10 + H = HYPREMatrix(CSR) + @test H.IJMatrix != HYPRE_IJMatrix(C_NULL) + @test H.ParCSRMatrix != HYPRE_ParCSRMatrix(C_NULL) + @test H.comm == MPI.COMM_WORLD + @test H.ilower == H.jlower == 1 + @test H.iupper == H.jupper == 10 end function tomain(x) @@ -192,6 +210,13 @@ end @test h.IJVector != HYPRE_IJVector(C_NULL) @test h.ParVector != HYPRE_ParVector(C_NULL) @test_throws ArgumentError HYPREVector([1, 2], ilower, iupper) + # Default to owning all rows + h = HYPREVector(b) + @test h.IJVector != HYPRE_IJVector(C_NULL) + @test h.ParVector != HYPRE_ParVector(C_NULL) + @test h.comm == MPI.COMM_WORLD + @test h.ilower == 1 + @test h.iupper == 10 ilower, iupper = 1, 10 b = rand(HYPRE_Complex, 10)