@@ -26,11 +26,7 @@ function kernelmatrix!(
26
26
obsdim:: Int = defaultobs
27
27
)
28
28
@assert obsdim ∈ [1 , 2 ] " obsdim should be 1 or 2 (see docs of `kernelmatrix`))"
29
- if obsdim == 1
30
- kernelmatrix! (K, κ, ColVecs (X' ))
31
- else
32
- kernelmatrix! (K, κ, ColVecs (X))
33
- end
29
+ kernelmatrix! (K, κ, vec_of_vecs (X, obsdim = obsdim))
34
30
end
35
31
36
32
function kernelmatrix! (
@@ -66,11 +62,8 @@ function kernelmatrix!(
66
62
obsdim:: Int = defaultobs
67
63
)
68
64
@assert obsdim ∈ [1 , 2 ] " obsdim should be 1 or 2 (see docs of `kernelmatrix`))"
69
- if obsdim == 1
70
- kernelmatrix! (K, κ, ColVecs (X' ), ColVecs (Y' ))
71
- else
72
- kernelmatrix! (K, κ, ColVecs (X), ColVecs (Y))
73
- end
65
+ kernelmatrix! (K, κ, vec_of_vecs (X, obsdim = obsdim), vec_of_vecs (Y, obsdim = obsdim))
66
+
74
67
end
75
68
76
69
function kernelmatrix! (
110
103
111
104
function kernelmatrix (κ:: Kernel , X:: AbstractMatrix ; obsdim:: Int = defaultobs)
112
105
@assert obsdim ∈ [1 , 2 ] " obsdim should be 1 or 2 (see docs of `kernelmatrix`))"
113
- if obsdim == 1
114
- kernelmatrix (κ, ColVecs (X' ))
115
- else
116
- kernelmatrix (κ, ColVecs (X))
117
- end
106
+ kernelmatrix (κ, vec_of_vecs (X, obsdim = obsdim))
118
107
end
119
108
120
109
function kernelmatrix (
@@ -127,21 +116,14 @@ function kernelmatrix(
127
116
if ! check_dims (X, Y, feature_dim (obsdim))
128
117
throw (DimensionMismatch (" X $(size (X)) and Y $(size (Y)) do not have the same number of features on the dimension : $(feature_dim (obsdim)) " ))
129
118
end
130
- _kernelmatrix ( κ, X, Y, obsdim)
119
+ map (x -> kappa ( κ, x), pairwise ( metric (κ), X, Y, dims = obsdim) )
131
120
end
132
121
133
122
function kernelmatrix (κ:: Kernel , X:: AbstractMatrix , Y:: AbstractMatrix ; obsdim:: Int = defaultobs)
134
123
@assert obsdim ∈ [1 , 2 ] " obsdim should be 1 or 2 (see docs of `kernelmatrix`))"
135
- if obsdim == 1
136
- kernelmatrix (κ, ColVecs (X' ), ColVecs (Y' ))
137
- else
138
- kernelmatrix (κ, ColVecs (X), ColVecs (Y))
139
- end
124
+ kernelmatrix (κ, vec_of_vecs (X, obsdim = obsdim), vec_of_vecs (Y, obsdim = obsdim))
140
125
end
141
126
142
- @inline _kernelmatrix (κ:: SimpleKernel , X, Y, obsdim) =
143
- map (x -> kappa (κ, x), pairwise (metric (κ), X, Y, dims = obsdim))
144
-
145
127
"""
146
128
kerneldiagmatrix(κ::Kernel, X; obsdim::Int = 2)
147
129
@@ -157,11 +139,7 @@ function kerneldiagmatrix(
157
139
obsdim:: Int = defaultobs
158
140
)
159
141
@assert obsdim ∈ [1 ,2 ] " obsdim should be 1 or 2 (see docs of kernelmatrix))"
160
- if obsdim == 1
161
- kerneldiagmatrix (κ, ColVecs (X' ))
162
- else
163
- kerneldiagmatrix (κ, ColVecs (X))
164
- end
142
+ kerneldiagmatrix (κ, vec_of_vecs (X, obsdim = obsdim))
165
143
end
166
144
167
145
function kerneldiagmatrix (κ:: Kernel , X:: AbstractVector )
@@ -183,11 +161,7 @@ function kerneldiagmatrix!(
183
161
if length (K) != size (X,obsdim)
184
162
throw (DimensionMismatch (" Dimensions of the target array K $(size (K)) are not consistent with X $(size (X)) " ))
185
163
end
186
- if obsdim == 1
187
- kerneldiagmatrix! (K, κ, ColVecs (X' ))
188
- else
189
- kerneldiagmatrix! (K, κ, ColVecs (X))
190
- end
164
+ kerneldiagmatrix! (K, κ, vec_of_vecs (X, obsdim = obsdim))
191
165
return K
192
166
end
193
167
0 commit comments