-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
88 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
for op in (:+, :-) | ||
@eval function Base.$op(a::ℒRadialBasisFunction, b::ℒRadialBasisFunction) | ||
additive_ℒRBF(x, xᵢ) = Base.$op(a(x, xᵢ), b(x, xᵢ)) | ||
return ℒRadialBasisFunction(additive_ℒRBF) | ||
end | ||
end | ||
|
||
for op in (:+, :-) | ||
@eval function Base.$op( | ||
a::ℒMonomialBasis{Dim,Deg}, b::ℒMonomialBasis{Dim,Deg} | ||
) where {Dim,Deg} | ||
function additive_ℒMon(m, x) | ||
m .= Base.$op.(a(x), b(x)) | ||
return nothing | ||
end | ||
return ℒMonomialBasis(Dim, Deg, additive_ℒMon) | ||
end | ||
end | ||
|
||
for op in (:+, :-) | ||
@eval function Base.$op(op1::RadialBasisOperator, op2::RadialBasisOperator) | ||
_check_compatible(op1, op2) | ||
k = _update_stencil(op1, op2) | ||
ℒ(x) = Base.$op(op1.ℒ(x), op2.ℒ(x)) | ||
return RadialBasisOperator(ℒ, op1.data, op1.basis; k=k, adjl=op1.adjl) | ||
end | ||
end | ||
|
||
function _check_compatible(op1::RadialBasisOperator, op2::RadialBasisOperator) | ||
if !all(op1.data .≈ op2.data) | ||
throw( | ||
ArgumentError("Can not add operators that were not built with the same data.") | ||
) | ||
end | ||
if !all(op1.adjl .≈ op2.adjl) | ||
throw(ArgumentError("Can not add operators that do not have the same stencils.")) | ||
end | ||
end | ||
|
||
function _update_stencil(op1::RadialBasisOperator, op2::RadialBasisOperator) | ||
k1 = length(first((op1.adjl))) | ||
k2 = length(first((op2.adjl))) | ||
k = k1 > k2 ? k1 : k2 | ||
return k | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using RadialBasisFunctions | ||
using StaticArrays | ||
using LinearAlgebra | ||
using Statistics | ||
using HaltonSequences | ||
|
||
mean_percent_error(test, correct) = mean(abs.((test .- correct) ./ correct)) * 100 | ||
|
||
f(x) = 2 * x[1] + 3 * x[2] | ||
df_dx(x) = 2 | ||
df_dy(x) = 3 | ||
|
||
N = 1000 | ||
x = SVector{2}.(HaltonPoint(2)[1:N]) | ||
y = f.(x) | ||
|
||
dx = partial(x, 1, 1) | ||
dy = partial(x, 1, 2) | ||
|
||
dxdy = dx + dy | ||
@test mean_percent_error(dxdy(y), df_dx.(x) .+ df_dy.(x)) < 1e-6 | ||
|
||
dxdy = dx - dy | ||
@test mean_percent_error(dxdy(y), df_dx.(x) .- df_dy.(x)) < 1e-6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters