Skip to content

Commit

Permalink
add unit tests for LagrangeBasis
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaLampert committed Nov 6, 2024
1 parent 42b0269 commit dda6b3d
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/test_unit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,37 @@ end
for (i, b) in enumerate(basis)
@test b.(nodeset) == basis_functions[i].(nodeset)
end

kernel = ThinPlateSplineKernel{dim(nodeset)}()
basis = @test_nowarn LagrangeBasis(nodeset, kernel)
@test_throws DimensionMismatch LagrangeBasis(nodeset,
GaussKernel{1}(shape_parameter = 0.5))
@test_nowarn println(basis)
@test_nowarn display(basis)
A = kernel_matrix(basis)
@test isapprox(stack(basis.(nodeset)), A)
@test isapprox(A, I)
basis_functions = collect(basis)
for (i, b) in enumerate(basis)
@test b.(nodeset) == basis_functions[i].(nodeset)
end
# Test for Theorem 11.1 in Wendland's book
stdbasis = StandardBasis(nodeset, kernel)
R(x) = stdbasis(x)
function S(x)
v = zeros(length(basis.ps))
for i in eachindex(v)
v[i] = basis.ps[i](basis.xx => x)
end
return v
end
b(x) = [R(x); S(x)]
K = KernelInterpolation.interpolation_matrix(stdbasis, basis.ps)
x = rand(dim(nodeset))
uv = K \ b(x)
u = basis(x)
# Difficult to test for v
@test isapprox(u, uv[1:length(u)])
end

@testitem "Interpolation" setup=[Setup, AdditionalImports] begin
Expand Down

0 comments on commit dda6b3d

Please sign in to comment.