@@ -86,18 +86,94 @@ function test_interface(
86
86
@test kernelmatrix_diag! (tmp_diag, k, x0, x1) ≈ kernelmatrix_diag (k, x0, x1)
87
87
end
88
88
89
- function test_interface (
90
- rng:: AbstractRNG , k:: Kernel , :: Type{Vector{T}} ; kwargs...
91
- ) where {T<: Real }
92
- return test_interface (
93
- k, randn (rng, T, 11 ), randn (rng, T, 11 ), randn (rng, T, 13 ); kwargs...
89
+ """
90
+ test_interface([rng::AbstractRNG], k::Kernel, ::Type{T}=Float64; kwargs...) where {T}
91
+
92
+ Run the [`test_interface`](@ref) tests for randomly generated inputs of types `Vector{T}`,
93
+ `Vector{Vector{T}}`, `ColVecs{T}`, and `RowVecs{T}`.
94
+
95
+ For other input types, please provide the data manually.
96
+
97
+ The keyword arguments are forwarded to the invocations of [`test_interface`](@ref) with the
98
+ randomly generated inputs.
99
+ """
100
+ function test_interface (k:: Kernel , T:: Type = Float64; kwargs... )
101
+ return test_interface (Random. GLOBAL_RNG, k, T; kwargs... )
102
+ end
103
+
104
+ function test_interface (rng:: AbstractRNG , k:: Kernel , T:: Type = Float64; kwargs... )
105
+ return test_with_type (test_interface, rng, k, T; kwargs... )
106
+ end
107
+
108
+ """
109
+ test_type_stability(
110
+ k::Kernel,
111
+ x0::AbstractVector,
112
+ x1::AbstractVector,
113
+ x2::AbstractVector,
94
114
)
115
+
116
+ Run type stability checks over `k(x,y)` and the different functions of the API
117
+ (`kernelmatrix`, `kernelmatrix_diag`). `x0` and `x1` should be of the same
118
+ length with different values, while `x0` and `x2` should be of different lengths.
119
+ """
120
+ function test_type_stability (
121
+ k:: Kernel , x0:: AbstractVector , x1:: AbstractVector , x2:: AbstractVector
122
+ )
123
+ # Ensure that we have the required inputs.
124
+ @assert length (x0) == length (x1)
125
+ @assert length (x0) ≠ length (x2)
126
+ @test @inferred (kernelmatrix (k, x0)) isa AbstractMatrix
127
+ @test @inferred (kernelmatrix (k, x0, x2)) isa AbstractMatrix
128
+ @test @inferred (kernelmatrix_diag (k, x0)) isa AbstractVector
129
+ @test @inferred (kernelmatrix_diag (k, x0, x1)) isa AbstractVector
95
130
end
96
131
97
- function test_interface (
98
- rng:: AbstractRNG , k:: MOKernel , :: Type{Vector{Tuple{T,Int}}} ; dim_out= 3 , kwargs...
132
+ function test_type_stability (k:: Kernel , :: Type{T} = Float64; kwargs... ) where {T}
133
+ return test_type_stability (Random. GLOBAL_RNG, k, T; kwargs... )
134
+ end
135
+
136
+ function test_type_stability (rng:: AbstractRNG , k:: Kernel , :: Type{T} ; kwargs... ) where {T}
137
+ return test_with_type (test_type_stability, rng, k, T; kwargs... )
138
+ end
139
+
140
+ """
141
+ test_with_type(f, rng::AbstractRNG, k::Kernel, ::Type{T}; kwargs...) where {T}
142
+
143
+ Run the functions `f`, (for example [`test_interface`](@ref) or
144
+ [`test_type_stable`](@ref)) for randomly generated inputs of types `Vector{T}`,
145
+ `Vector{Vector{T}}`, `ColVecs{T}`, and `RowVecs{T}`.
146
+
147
+ For other input types, please provide the data manually.
148
+
149
+ The keyword arguments are forwarded to the invocations of `f` with the
150
+ randomly generated inputs.
151
+ """
152
+ function test_with_type (f, rng:: AbstractRNG , k:: Kernel , :: Type{T} ; kwargs... ) where {T}
153
+ @testset " Vector{$T }" begin
154
+ test_with_type (f, rng, k, Vector{T}; kwargs... )
155
+ end
156
+ @testset " ColVecs{$T }" begin
157
+ test_with_type (f, rng, k, ColVecs{T}; kwargs... )
158
+ end
159
+ @testset " RowVecs{$T }" begin
160
+ test_with_type (f, rng, k, RowVecs{T}; kwargs... )
161
+ end
162
+ @testset " Vector{Vector{$T }}" begin
163
+ test_with_type (f, rng, k, Vector{Vector{T}}; kwargs... )
164
+ end
165
+ end
166
+
167
+ function test_with_type (
168
+ f, rng:: AbstractRNG , k:: Kernel , :: Type{Vector{T}} ; kwargs...
169
+ ) where {T<: Real }
170
+ return f (k, randn (rng, T, 11 ), randn (rng, T, 11 ), randn (rng, T, 13 ); kwargs... )
171
+ end
172
+
173
+ function test_with_type (
174
+ f, rng:: AbstractRNG , k:: MOKernel , :: Type{Vector{Tuple{T,Int}}} ; dim_out= 3 , kwargs...
99
175
) where {T<: Real }
100
- return test_interface (
176
+ return f (
101
177
k,
102
178
[(randn (rng, T), rand (rng, 1 : dim_out)) for i in 1 : 11 ],
103
179
[(randn (rng, T), rand (rng, 1 : dim_out)) for i in 1 : 11 ],
@@ -106,10 +182,10 @@ function test_interface(
106
182
)
107
183
end
108
184
109
- function test_interface (
110
- rng:: AbstractRNG , k:: Kernel , :: Type{<:ColVecs{T}} ; dim_in= 2 , kwargs...
185
+ function test_with_type (
186
+ f, rng:: AbstractRNG , k:: Kernel , :: Type{<:ColVecs{T}} ; dim_in= 2 , kwargs...
111
187
) where {T<: Real }
112
- return test_interface (
188
+ return f (
113
189
k,
114
190
ColVecs (randn (rng, T, dim_in, 11 )),
115
191
ColVecs (randn (rng, T, dim_in, 11 )),
@@ -118,10 +194,10 @@ function test_interface(
118
194
)
119
195
end
120
196
121
- function test_interface (
122
- rng:: AbstractRNG , k:: Kernel , :: Type{<:RowVecs{T}} ; dim_in= 2 , kwargs...
197
+ function test_with_type (
198
+ f, rng:: AbstractRNG , k:: Kernel , :: Type{<:RowVecs{T}} ; dim_in= 2 , kwargs...
123
199
) where {T<: Real }
124
- return test_interface (
200
+ return f (
125
201
k,
126
202
RowVecs (randn (rng, T, 11 , dim_in)),
127
203
RowVecs (randn (rng, T, 11 , dim_in)),
@@ -130,10 +206,10 @@ function test_interface(
130
206
)
131
207
end
132
208
133
- function test_interface (
134
- rng:: AbstractRNG , k:: Kernel , :: Type{<:Vector{Vector{T}}} ; dim_in= 2 , kwargs...
209
+ function test_with_type (
210
+ f, rng:: AbstractRNG , k:: Kernel , :: Type{<:Vector{Vector{T}}} ; dim_in= 2 , kwargs...
135
211
) where {T<: Real }
136
- return test_interface (
212
+ return f (
137
213
k,
138
214
[randn (rng, T, dim_in) for _ in 1 : 11 ],
139
215
[randn (rng, T, dim_in) for _ in 1 : 11 ],
@@ -142,8 +218,8 @@ function test_interface(
142
218
)
143
219
end
144
220
145
- function test_interface ( rng:: AbstractRNG , k:: Kernel , :: Type{Vector{String}} ; kwargs... )
146
- return test_interface (
221
+ function test_with_type (f, rng:: AbstractRNG , k:: Kernel , :: Type{Vector{String}} ; kwargs... )
222
+ return f (
147
223
k,
148
224
[randstring (rng) for _ in 1 : 3 ],
149
225
[randstring (rng) for _ in 1 : 3 ],
@@ -152,10 +228,10 @@ function test_interface(rng::AbstractRNG, k::Kernel, ::Type{Vector{String}}; kwa
152
228
)
153
229
end
154
230
155
- function test_interface (
156
- rng:: AbstractRNG , k:: Kernel , :: Type{ColVecs{String}} ; dim_in= 2 , kwargs...
231
+ function test_with_type (
232
+ f, rng:: AbstractRNG , k:: Kernel , :: Type{ColVecs{String}} ; dim_in= 2 , kwargs...
157
233
)
158
- return test_interface (
234
+ return f (
159
235
k,
160
236
ColVecs ([randstring (rng) for _ in 1 : dim_in, _ in 1 : 3 ]),
161
237
ColVecs ([randstring (rng) for _ in 1 : dim_in, _ in 1 : 3 ]),
@@ -164,38 +240,8 @@ function test_interface(
164
240
)
165
241
end
166
242
167
- function test_interface (k:: Kernel , T:: Type{<:AbstractVector} ; kwargs... )
168
- return test_interface (Random. GLOBAL_RNG, k, T; kwargs... )
169
- end
170
-
171
- """
172
- test_interface([rng::AbstractRNG], k::Kernel, ::Type{T}; kwargs...) where {T<:Real}
173
-
174
- Run the [`test_interface`](@ref) tests for randomly generated inputs of types `Vector{T}`,
175
- `Vector{Vector{T}}`, `ColVecs{T}`, and `RowVecs{T}`.
176
-
177
- For other input types, please provide the data manually.
178
-
179
- The keyword arguments are forwarded to the invocations of [`test_interface`](@ref) with the
180
- randomly generated inputs.
181
- """
182
- function test_interface (rng:: AbstractRNG , k:: Kernel , :: Type{T} ; kwargs... ) where {T<: Real }
183
- @testset " Vector{$T }" begin
184
- test_interface (rng, k, Vector{T}; kwargs... )
185
- end
186
- @testset " ColVecs{$T }" begin
187
- test_interface (rng, k, ColVecs{T}; kwargs... )
188
- end
189
- @testset " RowVecs{$T }" begin
190
- test_interface (rng, k, RowVecs{T}; kwargs... )
191
- end
192
- @testset " Vector{Vector{T}}" begin
193
- test_interface (rng, k, Vector{Vector{T}}; kwargs... )
194
- end
195
- end
196
-
197
- function test_interface (k:: Kernel , T:: Type{<:Real} = Float64; kwargs... )
198
- return test_interface (Random. GLOBAL_RNG, k, T; kwargs... )
243
+ function test_with_type (f, k:: Kernel , T:: Type{<:Real} ; kwargs... )
244
+ return test_with_type (f, Random. GLOBAL_RNG, k, T; kwargs... )
199
245
end
200
246
201
247
"""
0 commit comments