Browse Source

copy! -> copyto! (??)

fe/copyto
Fredrik Ekre 3 years ago
parent
commit
2a0ed3dfa2
  1. 7
      src/HYPRE.jl
  2. 8
      src/solvers.jl
  3. 36
      test/runtests.jl

7
src/HYPRE.jl

@ -269,11 +269,12 @@ HYPREVector(x::Vector, ilower=1, iupper=length(x)) = @@ -269,11 +269,12 @@ HYPREVector(x::Vector, ilower=1, iupper=length(x)) =
HYPREVector(MPI.COMM_WORLD, x, ilower, iupper)
# TODO: Other eltypes could be support by using a intermediate buffer
function Base.copy!(x::Vector{HYPRE_Complex}, h::HYPREVector)
function Base.copyto!(x::Vector{HYPRE_Complex}, h::HYPREVector)
ilower, iupper = Internals.get_proc_rows(h)
nvalues = iupper - ilower + 1
if length(x) != nvalues
throw(ArgumentError("different lengths"))
# TODO: This isn't required by the copyto! interface, only that there is enough room
throw(ArgumentError("length(dst) != length(src)"))
end
indices = collect(HYPRE_BigInt, ilower:iupper)
@check HYPRE_IJVectorGetValues(h.IJVector, nvalues, indices, x)
@ -455,7 +456,7 @@ function HYPREVector(v::PVector) @@ -455,7 +456,7 @@ function HYPREVector(v::PVector)
end
# TODO: Other eltypes could be support by using a intermediate buffer
function Base.copy!(v::PVector{HYPRE_Complex}, h::HYPREVector)
function Base.copyto!(v::PVector{HYPRE_Complex}, h::HYPREVector)
ilower_v, iupper_v = Internals.get_proc_rows(v)
ilower_h, iupper_h = Internals.get_proc_rows(h)
if ilower_v != ilower_h && iupper_v != iupper_h

8
src/solvers.jl

@ -40,13 +40,13 @@ solve!(pcg::HYPRESolver, x::HYPREVector, A::HYPREMatrix, ::HYPREVector) @@ -40,13 +40,13 @@ solve!(pcg::HYPRESolver, x::HYPREVector, A::HYPREMatrix, ::HYPREVector)
function solve(solver::HYPRESolver, A::PSparseMatrix, b::PVector)
hypre_x = solve(solver, HYPREMatrix(A), HYPREVector(b))
x = copy!(similar(b, HYPRE_Complex), hypre_x)
x = copyto!(similar(b, HYPRE_Complex), hypre_x)
return x
end
function solve!(solver::HYPRESolver, x::PVector, A::PSparseMatrix, b::PVector)
hypre_x = HYPREVector(x)
solve!(solver, hypre_x, HYPREMatrix(A), HYPREVector(b))
copy!(x, hypre_x)
copyto!(x, hypre_x)
return x
end
@ -58,13 +58,13 @@ end @@ -58,13 +58,13 @@ end
function solve(solver::HYPRESolver, A::Union{SparseMatrixCSC,SparseMatrixCSR}, b::Vector)
hypre_x = solve(solver, HYPREMatrix(A), HYPREVector(b))
x = copy!(similar(b, HYPRE_Complex), hypre_x)
x = copyto!(similar(b, HYPRE_Complex), hypre_x)
return x
end
function solve!(solver::HYPRESolver, x::Vector, A::Union{SparseMatrixCSC,SparseMatrixCSR}, b::Vector)
hypre_x = HYPREVector(x)
solve!(solver, hypre_x, HYPREMatrix(A), HYPREVector(b))
copy!(x, hypre_x)
copyto!(x, hypre_x)
return x
end

36
test/runtests.jl

@ -191,11 +191,11 @@ end @@ -191,11 +191,11 @@ end
@test h.IJVector != HYPRE_IJVector(C_NULL)
@test h.ParVector != HYPRE_ParVector(C_NULL)
# Base.zero(::HYPREVector) and Base.copy!(::Vector, HYPREVector)
# Base.zero(::HYPREVector) and Base.copyto!(::Vector, HYPREVector)
b = rand(10)
h = HYPREVector(b, 1, 10)
z = zero(h)
b′ = copy!(b, z)
b′ = copyto!(b, z)
@test b === b′
@test iszero(b)
end
@ -254,7 +254,7 @@ end @@ -254,7 +254,7 @@ end
@test H.IJVector != HYPRE_IJVector(C_NULL)
@test H.ParVector != HYPRE_ParVector(C_NULL)
pbc = fill!(copy(pb), 0)
copy!(pbc, H)
copyto!(pbc, H)
@test tomain(pbc) == tomain(pb)
# MPI backend
backend = MPIBackend()
@ -271,7 +271,7 @@ end @@ -271,7 +271,7 @@ end
@test H.IJVector != HYPRE_IJVector(C_NULL)
@test H.ParVector != HYPRE_ParVector(C_NULL)
pbc = fill!(copy(pb), 0)
copy!(pbc, H)
copyto!(pbc, H)
@test tomain(pbc) == tomain(pb)
end
@ -292,12 +292,12 @@ end @@ -292,12 +292,12 @@ end
tol = 1e-9
bicg = HYPRE.BiCGSTAB(; Tol = tol)
HYPRE.solve!(bicg, x_h, A_h, b_h)
copy!(x, x_h)
copyto!(x, x_h)
# Test result with direct solver
@test x A \ b atol=tol
# Test without passing initial guess
x_h = HYPRE.solve(bicg, A_h, b_h)
copy!(x, x_h)
copyto!(x, x_h)
@test x A \ b atol=tol
# Solve with preconditioner
@ -305,12 +305,12 @@ end @@ -305,12 +305,12 @@ end
bicg = HYPRE.BiCGSTAB(; Tol = tol, Precond = precond)
x_h = HYPREVector(zeros(100))
HYPRE.solve!(bicg, x_h, A_h, b_h)
copy!(x, x_h)
copyto!(x, x_h)
# Test result with direct solver
@test x A \ b atol=tol
# Test without passing initial guess
x_h = HYPRE.solve(bicg, A_h, b_h)
copy!(x, x_h)
copyto!(x, x_h)
@test x A \ b atol=tol
end
@ -332,12 +332,12 @@ end @@ -332,12 +332,12 @@ end
tol = 1e-9
amg = HYPRE.BoomerAMG(; Tol = tol)
HYPRE.solve!(amg, x_h, A_h, b_h)
copy!(x, x_h)
copyto!(x, x_h)
# Test result with direct solver
@test x A \ b atol=tol
# Test without passing initial guess
x_h = HYPRE.solve(amg, A_h, b_h)
copy!(x, x_h)
copyto!(x, x_h)
@test x A \ b atol=tol
end
@ -358,12 +358,12 @@ end @@ -358,12 +358,12 @@ end
tol = 1e-9
gmres = HYPRE.GMRES(; Tol = tol)
HYPRE.solve!(gmres, x_h, A_h, b_h)
copy!(x, x_h)
copyto!(x, x_h)
# Test result with direct solver
@test x A \ b atol=tol
# Test without passing initial guess
x_h = HYPRE.solve(gmres, A_h, b_h)
copy!(x, x_h)
copyto!(x, x_h)
@test x A \ b atol=tol
# Solve with preconditioner
@ -371,12 +371,12 @@ end @@ -371,12 +371,12 @@ end
gmres = HYPRE.GMRES(; Tol = tol, Precond = precond)
x_h = HYPREVector(zeros(100))
HYPRE.solve!(gmres, x_h, A_h, b_h)
copy!(x, x_h)
copyto!(x, x_h)
# Test result with direct solver
@test x A \ b atol=tol
# Test without passing initial guess
x_h = HYPRE.solve(gmres, A_h, b_h)
copy!(x, x_h)
copyto!(x, x_h)
@test x A \ b atol=tol
end
@ -398,24 +398,24 @@ end @@ -398,24 +398,24 @@ end
tol = 1e-9
pcg = HYPRE.PCG(; Tol = tol)
HYPRE.solve!(pcg, x_h, A_h, b_h)
copy!(x, x_h)
copyto!(x, x_h)
# Test result with direct solver
@test x A \ b atol=tol
# Test without passing initial guess
x_h = HYPRE.solve(pcg, A_h, b_h)
copy!(x, x_h)
copyto!(x, x_h)
@test x A \ b atol=tol
# Solve with AMG preconditioner
precond = HYPRE.BoomerAMG(; MaxIter = 1, Tol = 0.0)
pcg = HYPRE.PCG(; Tol = tol, Precond = precond)
x_h = HYPREVector(zeros(100))
HYPRE.solve!(pcg, x_h, A_h, b_h)
copy!(x, x_h)
copyto!(x, x_h)
# Test result with direct solver
@test x A \ b atol=tol
# Test without passing initial guess
x_h = HYPRE.solve(pcg, A_h, b_h)
copy!(x, x_h)
copyto!(x, x_h)
@test x A \ b atol=tol
end

Loading…
Cancel
Save