Skip to content

Commit

Permalink
Restructure evaluateRBF! and exploit RBF matrix symmetry.
Browse files Browse the repository at this point in the history
  • Loading branch information
eljungsk committed Aug 14, 2019
1 parent f457409 commit 4188da5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 31 deletions.
47 changes: 17 additions & 30 deletions src/rbf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ function interpolate(rbf::Union{T, AbstractVector{T}} where T <: AbstractRadialB
# and optional smoothing (ridge regression)
A = pairwise(metric, points;dims=2)

evaluateRBF!(A, rbf, smooth)
A = evaluateRBF!(A, rbf, smooth)

# Solve for the weights
itp = solveForWeights(A, points, samples, rbf, metric)
Expand All @@ -211,47 +211,34 @@ end

@inline function evaluateRBF!(A, rbf)
A .= rbf.(A)
return Symmetric(A)
end
@inline function evaluateRBF!(A, rbfs::AbstractVector{<:AbstractRadialBasisFunction})
for (j, rbf) in enumerate(rbfs)
A[:,j] .= rbf.(@view A[:,j])
end
return A
end
@inline function evaluateRBF!(A, rbf, smooth::Bool)
A .= rbf.(A)
@inline function evaluateRBF!(A, rbf, smooth)
A = evaluateRBF!(A, rbf)
A = addSmoothing!(A, smooth)
return A
end
@inline function evaluateRBF!(A, rbfs::AbstractVector{<:AbstractRadialBasisFunction}, smooth::Bool)
for (j, rbf) in enumerate(rbfs)
A[:,j] .= rbf.(@view A[:,j])
end

@inline function addSmoothing!(A, smooth::Bool)
return A
end
@inline function evaluateRBF!(A, rbf, smooth::Vector{T}) where T <: Number
A .= rbf.(A)
for i = 1:size(A,1)
@inline function addSmoothing!(A, smooth::Vector{T}) where T <: Number
for i = 1:size(A, 1)
A[i,i] += smooth[i]
end
return A
end
@inline function evaluateRBF!(A, rbfs::AbstractVector{<:AbstractRadialBasisFunction}, smooth::Vector{T}) where T <: Number
for (j, rbf) in enumerate(rbfs)
A[:,j] .= rbf.(@view A[:,j])
end
for i = 1:size(A,1)
A[i,i] += smooth[i]
end
end
@inline function evaluateRBF!(A, rbf, smooth::T) where T <: Number
A .= rbf.(A)
for i = 1:size(A,1)
A[i,i] += smooth
end
end
@inline function evaluateRBF!(A, rbfs::AbstractVector{<:AbstractRadialBasisFunction}, smooth::T) where T <: Number
for (j, rbf) in enumerate(rbfs)
A[:,j] .= rbf.(@view A[:,j])
end
for i = 1:size(A,1)
@inline function addSmoothing!(A, smooth::T) where T <: Number
for i = 1:size(A, 1)
A[i,i] += smooth
end
return A
end

@inline function solveForWeights(A, points, samples,
Expand Down Expand Up @@ -282,7 +269,7 @@ function evaluate(itp::RadialBasisInterpolant, points::AbstractArray{<:Real, 2})

# Compute distance matrix and evaluate the RBF
A = pairwise(itp.metric, points, itp.points;dims=2)
evaluateRBF!(A, itp.rbf)
A = evaluateRBF!(A, itp.rbf)

# Compute polynomial matrix for generalized RBF:s
P = getPolynomial(itp.rbf, points)
Expand Down
2 changes: 1 addition & 1 deletion test/rbf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ radialBasisFunctions = (Gaussian(2),

# Check that the result is the same when dispatching on multiple,
# but equal RBFs for each interpolation point
@test evaluate(itpConstant, points) == evaluate(itpMixed, points)
@test evaluate(itpConstant, points) evaluate(itpMixed, points)
end
end

Expand Down

2 comments on commit 4188da5

@eljungsk
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:

Performance improvement for RBF interpolation using the same RBF for all points.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error while trying to register: Version 0.3.3 already exists

Please sign in to comment.