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

Use LinearSolve.jl for RBF #27

Open
wants to merge 5 commits into
base: master
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fail-fast: false
matrix:
version:
- '1.0'
- '1.6'
- '1'
- 'nightly'
os:
Expand Down
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ os:
- linux
- osx
julia:
- 1.0
- 1.1
- 1.2
- 1.6
- 1.7
- nightly
matrix:
allow_failures:
Expand Down
7 changes: 4 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
NearestNeighbors = "b8a86587-4115-5ab1-83bc-aa920d37bbce"
LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae"

[compat]
Combinatorics = "1"
Distances = "0.9,0.10"
NearestNeighbors = "0.4"
julia = "1"
LinearSolve = "1"
julia = "1.6"

[extras]
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "Random"]
test = ["Test"]
2 changes: 1 addition & 1 deletion src/ScatteredInterpolation.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module ScatteredInterpolation

using Distances, NearestNeighbors, Combinatorics, LinearAlgebra
using Distances, NearestNeighbors, Combinatorics, LinearAlgebra, LinearSolve

export interpolate,
evaluate
Expand Down
14 changes: 8 additions & 6 deletions src/rbf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ end
function interpolate(rbf::Union{T, AbstractVector{T}} where T <: AbstractRadialBasisFunction,
points::AbstractArray{<:Real,2},
samples::AbstractArray{<:Number,N};
metric = Euclidean(), returnRBFmatrix::Bool = false,
metric = Euclidean(), returnRBFmatrix::Bool = false, linsolve = nothing,
smooth::Union{S, AbstractVector{S}} = false) where {N} where {S<:Number}

#hinder smooth from being set to true and interpreted as the value 1
Expand All @@ -198,7 +198,7 @@ function interpolate(rbf::Union{T, AbstractVector{T}} where T <: AbstractRadialB
A = evaluateRBF!(A, rbf, smooth)

# Solve for the weights
itp = solveForWeights(A, points, samples, rbf, metric)
itp = solveForWeights(A, points, samples, rbf, metric; linsolve)

# Create and return an interpolation object
if returnRBFmatrix # Return matrix A
Expand Down Expand Up @@ -245,13 +245,15 @@ end

@inline function solveForWeights(A, points, samples,
rbf::Union{T, AbstractVector{T}} where T <: RadialBasisFunction,
metric)
w = A\samples
RBFInterpolant(w, points, rbf, metric)
metric; linsolve)
prob = LinearProblem(A, samples)
sol = solve(prob, linsolve)

RBFInterpolant(sol.u, points, rbf, metric)
end
@inline function solveForWeights(A, points, samples,
rbf::Union{T, AbstractVector{T}} where T <: Union{GeneralizedRadialBasisFunction, RadialBasisFunction},
metric)
metric; linsolve)
# Use the maximum degree among the generalized RBF:s
P = getPolynomial(rbf, points)

Expand Down
21 changes: 12 additions & 9 deletions test/rbf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,18 @@ radialBasisFunctions = (Gaussian(2),

@test r.(data) ≈ f.(data)

for points in (arrayPoints, adjointPoints)
itp = interpolate(r, points, data)

# Check that we get back the original data at the sample points and that we get
# close when evaluating near the sampling points
ev = evaluate(itp, points)
@test ev ≈ data
ev = evaluate(itp, points .+ 0.001*randn(size(points)))
@test all(isapprox.(data, ev, atol = 1e-2))
offset = 2e-4
for linsolve in (nothing, IterativeSolversJL_GMRES())
for points in (arrayPoints, adjointPoints)
itp = interpolate(r, points, data; linsolve = linsolve)

# Check that we get back the original data at the sample points and that we get
# close when evaluating near the sampling points
ev = evaluate(itp, points)
@test ev ≈ data
ev = evaluate(itp, points .+ offset)
@test all(isapprox.(data, ev, atol = 1e-2))
end
end
end

Expand Down
10 changes: 1 addition & 9 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
using ScatteredInterpolation, Random

Random.seed!(2)

if VERSION < v"0.7-"
using Base.Test
else
using Test
end
using ScatteredInterpolation, Test, LinearSolve

include("rbf.jl")
include("idw.jl")
Expand Down