1
1
module TestUtils
2
2
3
3
const __ATOL = 1e-9
4
+ const __RTOL = 1e-9
4
5
6
+ using Distances
5
7
using LinearAlgebra
6
8
using KernelFunctions
7
9
using Random
@@ -33,6 +35,7 @@ function test_interface(
33
35
x1:: AbstractVector ,
34
36
x2:: AbstractVector ;
35
37
atol= __ATOL,
38
+ rtol= __RTOL,
36
39
)
37
40
# Ensure that we have the required inputs.
38
41
@assert length (x0) == length (x1)
@@ -69,8 +72,8 @@ function test_interface(
69
72
@test eigmin (Matrix (kernelmatrix (k, x0))) > - atol
70
73
71
74
# 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
74
77
75
78
# Check that basic kernel evaluation succeeds and is consistent with `kernelmatrix`.
76
79
@test k (first (x0), first (x1)) isa Real
89
92
function test_interface (
90
93
rng:: AbstractRNG , k:: Kernel , :: Type{Vector{T}} ; kwargs...
91
94
) 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... )
93
96
end
94
97
95
98
function test_interface (
96
99
rng:: AbstractRNG , k:: Kernel , :: Type{<:ColVecs{T}} ; dim_in= 2 , kwargs... ,
97
100
) where {T<: Real }
98
101
test_interface (
99
102
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 ));
103
106
kwargs... ,
104
107
)
105
108
end
@@ -109,9 +112,9 @@ function test_interface(
109
112
) where {T<: Real }
110
113
test_interface (
111
114
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));
115
118
kwargs... ,
116
119
)
117
120
end
@@ -121,9 +124,15 @@ function test_interface(k::Kernel, T::Type{<:AbstractVector}; kwargs...)
121
124
end
122
125
123
126
function 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
127
136
end
128
137
129
138
function test_interface (k:: Kernel , T:: Type{<:Real} = Float64; kwargs... )
0 commit comments