11module TestUtils
22
33const __ATOL = 1e-9
4+ const __RTOL = 1e-9
45
6+ using Distances
57using LinearAlgebra
68using KernelFunctions
79using Random
@@ -33,6 +35,7 @@ function test_interface(
3335 x1:: AbstractVector ,
3436 x2:: AbstractVector ;
3537 atol= __ATOL,
38+ rtol= __RTOL,
3639)
3740 # Ensure that we have the required inputs.
3841 @assert length (x0) == length (x1)
@@ -69,8 +72,8 @@ function test_interface(
6972 @test eigmin (Matrix (kernelmatrix (k, x0))) > - atol
7073
7174 # Check that unary elementwise / pairwise are consistent with the binary versions.
72- @test kerneldiagmatrix (k, x0) ≈ kerneldiagmatrix (k, x0, x0) atol= atol
73- @test kernelmatrix (k, x0) ≈ kernelmatrix (k, x0, x0) atol= atol
75+ @test kerneldiagmatrix (k, x0) ≈ kerneldiagmatrix (k, x0, x0) atol= atol rtol = rtol
76+ @test kernelmatrix (k, x0) ≈ kernelmatrix (k, x0, x0) atol= atol rtol = rtol
7477
7578 # Check that basic kernel evaluation succeeds and is consistent with `kernelmatrix`.
7679 @test k (first (x0), first (x1)) isa Real
8992function test_interface (
9093 rng:: AbstractRNG , k:: Kernel , :: Type{Vector{T}} ; kwargs...
9194) where {T<: Real }
92- test_interface (k, randn (rng, T, 3 ), randn (rng, T, 3 ), randn (rng, T, 2 ); kwargs... )
95+ test_interface (k, randn (rng, T, 1001 ), randn (rng, T, 1001 ), randn (rng, T, 1000 ); kwargs... )
9396end
9497
9598function test_interface (
9699 rng:: AbstractRNG , k:: Kernel , :: Type{<:ColVecs{T}} ; dim_in= 2 , kwargs... ,
97100) where {T<: Real }
98101 test_interface (
99102 k,
100- ColVecs (randn (rng, T, dim_in, 3 )),
101- ColVecs (randn (rng, T, dim_in, 3 )),
102- ColVecs (randn (rng, T, dim_in, 2 ));
103+ ColVecs (randn (rng, T, dim_in, 1001 )),
104+ ColVecs (randn (rng, T, dim_in, 1001 )),
105+ ColVecs (randn (rng, T, dim_in, 1000 ));
103106 kwargs... ,
104107 )
105108end
@@ -109,9 +112,9 @@ function test_interface(
109112) where {T<: Real }
110113 test_interface (
111114 k,
112- RowVecs (randn (rng, T, 3 , dim_in)),
113- RowVecs (randn (rng, T, 3 , dim_in)),
114- RowVecs (randn (rng, T, 2 , dim_in));
115+ RowVecs (randn (rng, T, 1001 , dim_in)),
116+ RowVecs (randn (rng, T, 1001 , dim_in)),
117+ RowVecs (randn (rng, T, 1000 , dim_in));
115118 kwargs... ,
116119 )
117120end
@@ -121,9 +124,15 @@ function test_interface(k::Kernel, T::Type{<:AbstractVector}; kwargs...)
121124end
122125
123126function test_interface (rng:: AbstractRNG , k:: Kernel , T:: Type{<:Real} ; kwargs... )
124- test_interface (rng, k, Vector{T}; kwargs... )
125- test_interface (rng, k, ColVecs{T}; kwargs... )
126- test_interface (rng, k, RowVecs{T}; kwargs... )
127+ @testset " Vector{$T }" begin
128+ test_interface (rng, k, Vector{T}; kwargs... )
129+ end
130+ @testset " ColVecs{$T }" begin
131+ test_interface (rng, k, ColVecs{T}; kwargs... )
132+ end
133+ @testset " RowVecs{$T }" begin
134+ test_interface (rng, k, RowVecs{T}; kwargs... )
135+ end
127136end
128137
129138function test_interface (k:: Kernel , T:: Type{<:Real} = Float64; kwargs... )
0 commit comments