Skip to content
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "KernelFunctions"
uuid = "ec8451be-7e33-11e9-00cf-bbf324bd1392"
version = "0.10.38"
version = "0.10.39"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand Down
33 changes: 14 additions & 19 deletions src/TestUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,14 @@ using KernelFunctions
using Random
using Test

# default tolerance values for test_interface:
const __ATOL = sqrt(eps(Float64))
const __RTOL = sqrt(eps(Float64))
# ≈ 1.5e-8; chosen for no particular reason other than because it seems to
# satisfy our own test cases within KernelFunctions.jl

"""
test_interface(
k::Kernel,
x0::AbstractVector,
x1::AbstractVector,
x2::AbstractVector;
atol=__ATOL,
rtol=__RTOL,
rtol=1e-6,
atol=rtol,
)

Run various consistency checks on `k` at the inputs `x0`, `x1`, and `x2`.
Expand All @@ -29,22 +23,14 @@ be of different lengths.
These tests are intended to pick up on really substantial issues with a kernel implementation
(e.g. substantial asymmetry in the kernel matrix, large negative eigenvalues), rather than to
test the numerics in detail, which can be kernel-specific.
The default value of `__ATOL` and `__RTOL` is `sqrt(eps(Float64)) ≈ 1.5e-8`, which satisfied
this intention in the cases tested within KernelFunctions.jl itself.

test_interface([rng::AbstractRNG], k::Kernel, T::Type{<:Real}; atol=__ATOL, rtol=__RTOL)

`test_interface` offers automated test data generation for kernels whose inputs are reals.
This will run the tests for `Vector{T}`, `Vector{Vector{T}}`, `ColVecs{T}`, and `RowVecs{T}`.
For other input vector types, please provide the data manually.
"""
function test_interface(
k::Kernel,
x0::AbstractVector,
x1::AbstractVector,
x2::AbstractVector;
atol=__ATOL,
rtol=__RTOL,
rtol=1e-6,
atol=rtol,
)
# Ensure that we have the required inputs.
@assert length(x0) == length(x1)
Expand Down Expand Up @@ -160,7 +146,16 @@ function test_interface(k::Kernel, T::Type{<:AbstractVector}; kwargs...)
return test_interface(Random.GLOBAL_RNG, k, T; kwargs...)
end

function test_interface(rng::AbstractRNG, k::Kernel, T::Type{<:Real}; kwargs...)
"""
test_interface([rng::AbstractRNG], k::Kernel, ::Type{T}; kwargs...) where {T<:Real}

Run the [`test_interface`](@ref) tests for randomly generated inputs of types `Vector{T}`, `Vector{Vector{T}}`, `ColVecs{T}`, and `RowVecs{T}`.

For other input types, please provide the data manually.

The keyword arguments are forwarded to the invocations of [`test_interface`](@ref) with the randomly generated inputs.
"""
function test_interface(rng::AbstractRNG, k::Kernel, ::Type{T}; kwargs...) where {T<:Real}
@testset "Vector{$T}" begin
test_interface(rng, k, Vector{T}; kwargs...)
end
Expand Down
5 changes: 1 addition & 4 deletions src/basekernels/matern.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,8 @@ MaternKernel(; nu::Real=1.5, ν::Real=nu, metric=Euclidean()) = MaternKernel(ν,

@functor MaternKernel

@inline _get_ν(k::MaternKernel) = only(k.ν)
ChainRulesCore.@non_differentiable _get_ν(k) # work-around; should be "NotImplemented" rather than NoTangent

@inline function kappa(k::MaternKernel, d::Real)
result = _matern(_get_ν(k), d)
result = _matern(only(k.ν), d)
return ifelse(iszero(d), one(result), result)
end

Expand Down
2 changes: 1 addition & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ LogExpFunctions = "0.2, 0.3"
PDMats = "0.9, 0.10, 0.11"
ReverseDiff = "1.2"
SpecialFunctions = "0.10, 1, 2"
Zygote = "0.4, 0.5, 0.6"
Zygote = "0.6.38"