@@ -6,27 +6,58 @@ using .Kronecker: Kronecker
66export kernelkronmat
77export kronecker_kernelmatrix
88
9- function kernelkronmat (κ:: Kernel , X:: AbstractVector , dims:: Int )
10- @assert iskroncompatible (κ) " The chosen kernel is not compatible for kroenecker matrices (see [`iskroncompatible`](@ref))"
11- k = kernelmatrix (κ, X)
12- return Kronecker. kronecker (k, dims)
9+ @doc raw """
10+ kernelkronmat(κ::Kernel, X::AbstractVector{<:Real}, dims::Int) -> KroneckerPower
11+
12+ Return a `KroneckerPower` matrix on the `D`-dimensional input grid constructed by ``\o times_{i=1}^D X``,
13+ where `D` is given by `dims`.
14+
15+ !!! warning
16+
17+ Require `Kronecker.jl` and for `iskroncompatible(κ)` to return `true`.
18+ """
19+ function kernelkronmat (κ:: Kernel , X:: AbstractVector{<:Real} , dims:: Int )
20+ checkkroncompatible (κ)
21+ K = kernelmatrix (κ, X)
22+ return Kronecker. kronecker (K, dims)
1323end
1424
15- function kernelkronmat (
16- κ:: Kernel , X:: AbstractVector{<:AbstractVector} ; obsdim:: Int = defaultobs
17- )
18- @assert iskroncompatible (κ) " The chosen kernel is not compatible for Kronecker matrices"
25+ @doc raw """
26+
27+ kernelkronmat(κ::Kernel, X::AbstractVector{<:AbstractVector}) -> KroneckerProduct
28+
29+ Returns a `KroneckerProduct` matrix on the grid built with the collection of vectors ``\{ X_i\} _{i=1}^D``: ``\o times_{i=1}^D X_i``.
30+
31+ !!! warning
32+
33+ Requires `Kronecker.jl` and for `iskroncompatible(κ)` to return `true`.
34+ """
35+ function kernelkronmat (κ:: Kernel , X:: AbstractVector{<:AbstractVector} )
36+ checkkroncompatible (κ)
1937 Ks = kernelmatrix .(κ, X)
20- return K = reduce (Kronecker.:⊗ , Ks)
38+ return reduce (Kronecker.:⊗ , Ks)
2139end
2240
23- """
24- To be compatible with kroenecker constructions the kernel must satisfy
25- the property : for x,x' ∈ ℜᴰ
26- k(x,x') = ∏ᵢᴰ k(xᵢ,x'ᵢ)
41+ @doc raw """
42+ iskroncompatible(k::Kernel)
43+
44+ Determine whether kernel `k` is compatible with Kronecker constructions such as [`kernelkronmat`](@ref)
45+
46+ The function returns `false` by default. If `k` is compatible it must satisfy for all ``x, x' \i n \m athbb{R}^D`:
47+ ```math
48+ k(x, x') = \p rod_{i=1}^D k(x_i, x'_i).
49+ ```
2750"""
2851@inline iskroncompatible (κ:: Kernel ) = false # Default return for kernels
2952
53+ function checkkroncompatible (κ:: Kernel )
54+ return iskroncompatible (κ) || throw (
55+ ArgumentError (
56+ " The chosen kernel is not compatible for Kronecker matrices (see [`iskroncompatible`](@ref))" ,
57+ ),
58+ )
59+ end
60+
3061function _kernelmatrix_kroneckerjl_helper (
3162 :: Type{<:MOInputIsotopicByFeatures} , Kfeatures, Koutputs
3263)
0 commit comments