30
30
31
31
function kernelmatrix! (
32
32
K:: AbstractMatrix ,
33
- κ:: BaseKernel ,
33
+ κ:: Kernel ,
34
34
X:: AbstractMatrix ;
35
35
obsdim:: Int = defaultobs
36
36
)
37
37
@assert obsdim ∈ [1 , 2 ] " obsdim should be 1 or 2 (see docs of `kernelmatrix`))"
38
38
if obsdim == 1
39
- kernelmatrix! (K, κ, ColVecs (X))
40
- else
41
39
kernelmatrix! (K, κ, ColVecs (X' ))
40
+ else
41
+ kernelmatrix! (K, κ, ColVecs (X))
42
42
end
43
43
end
44
44
45
45
function kernelmatrix! (
46
46
K:: AbstractMatrix ,
47
- κ:: BaseKernel ,
47
+ κ:: Kernel ,
48
48
X:: AbstractVector
49
49
)
50
50
if ! check_dims (K, X, X, feature_dim (obsdim), obsdim)
@@ -74,27 +74,27 @@ function kernelmatrix!(
74
74
if ! check_dims (K, X, Y, feature_dim (obsdim), obsdim)
75
75
throw (DimensionMismatch (" Dimensions $(size (K)) of the target array K are not consistent with X ($(size (X)) ) and Y ($(size (Y)) )" ))
76
76
end
77
- map! (κ , K, pairwise (metric (κ), X, Y, dims = obsdim))
77
+ map! (x -> kappa (κ, x) , K, pairwise (metric (κ), X, Y, dims = obsdim))
78
78
end
79
79
80
80
function kernelmatrix! (
81
81
K:: AbstractMatrix ,
82
- κ:: BaseKernel ,
82
+ κ:: Kernel ,
83
83
X:: AbstractMatrix ,
84
84
Y:: AbstractMatrix ;
85
85
obsdim:: Int = defaultobs
86
86
)
87
87
@assert obsdim ∈ [1 , 2 ] " obsdim should be 1 or 2 (see docs of `kernelmatrix`))"
88
88
if obsdim == 1
89
- @compat kernelmatrix! (K, κ, ColVecs (X), ColVecs (Y))
89
+ kernelmatrix! (K, κ, ColVecs (X' ), ColVecs (Y' ))
90
90
else
91
- @compat kernelmatrix! (K, κ, RowVecs (X), RowVecs (Y))
91
+ kernelmatrix! (K, κ, ColVecs (X), ColVecs (Y))
92
92
end
93
93
end
94
94
95
95
function kernelmatrix! (
96
96
K:: AbstractMatrix ,
97
- κ:: BaseKernel ,
97
+ κ:: Kernel ,
98
98
X:: AbstractVector ,
99
99
Y:: AbstractVector
100
100
)
135
135
function kernelmatrix (κ:: Kernel , X:: AbstractMatrix ; obsdim:: Int = defaultobs)
136
136
@assert obsdim ∈ [1 , 2 ] " obsdim should be 1 or 2 (see docs of `kernelmatrix`))"
137
137
if obsdim == 1
138
- kernelmatrix (κ, ColVecs (X))
138
+ kernelmatrix (κ, ColVecs (X' ))
139
139
else
140
- kernelmatrix (κ, RowVecs (X))
140
+ kernelmatrix (κ, ColVecs (X))
141
141
end
142
142
end
143
143
@@ -181,9 +181,9 @@ function kerneldiagmatrix(
181
181
)
182
182
@assert obsdim ∈ [1 ,2 ] " obsdim should be 1 or 2 (see docs of kernelmatrix))"
183
183
if obsdim == 1
184
- kerneldiagmatrix (κ, ColVecs (X))
185
- elseif obsdim == 2
186
184
kerneldiagmatrix (κ, ColVecs (X' ))
185
+ else
186
+ kerneldiagmatrix (κ, ColVecs (X))
187
187
end
188
188
end
189
189
@@ -207,13 +207,9 @@ function kerneldiagmatrix!(
207
207
throw (DimensionMismatch (" Dimensions of the target array K $(size (K)) are not consistent with X $(size (X)) " ))
208
208
end
209
209
if obsdim == 1
210
- for i in eachindex (K)
211
- @inbounds @views K[i] = κ (X[i,:], X[i,:])
212
- end
210
+ kerneldiagmatrix! (K, κ, ColVecs (X' ))
213
211
else
214
- for i in eachindex (K)
215
- @inbounds @views K[i] = κ (X[:,i], X[:,i])
216
- end
212
+ kerneldiagmatrix! (K, κ, ColVecs (X))
217
213
end
218
214
return K
219
215
end
0 commit comments