28
28
from typing import Callable , ClassVar , Literal , Mapping , Optional , Sequence , Union
29
29
30
30
import numpy as np
31
+ import numpy .typing as npt
31
32
from scipy import optimize
32
33
from scipy .optimize import Bounds
33
34
from sklearn .gaussian_process import GaussianProcessRegressor
@@ -334,7 +335,7 @@ def __call__(
334
335
335
336
return self .beta_l * C_theta , K_gradient
336
337
337
- def diag (self , X : np . ndarray ) -> np .ndarray :
338
+ def diag (self , X : npt . ArrayLike ) -> np .ndarray :
338
339
"""Returns the diagonal of the kernel k(X, X).
339
340
340
341
The result of this method is identical to np.diag(self(X)); however,
@@ -351,7 +352,7 @@ def diag(self, X: np.ndarray) -> np.ndarray:
351
352
K_diag : :obj:`~numpy.ndarray` of shape (n_samples_X,)
352
353
Diagonal of kernel k(X, X)
353
354
"""
354
- return self .beta_l * np .ones (X .shape [0 ])
355
+ return self .beta_l * np .ones (np . asanyarray ( X ) .shape [0 ])
355
356
356
357
def is_stationary (self ) -> bool :
357
358
"""Returns whether the kernel is stationary."""
@@ -444,7 +445,7 @@ def __call__(
444
445
445
446
return self .beta_l * C_theta , K_gradient
446
447
447
- def diag (self , X : np . ndarray ) -> np .ndarray :
448
+ def diag (self , X : npt . ArrayLike ) -> np .ndarray :
448
449
"""Returns the diagonal of the kernel k(X, X).
449
450
450
451
The result of this method is identical to np.diag(self(X)); however,
@@ -461,7 +462,7 @@ def diag(self, X: np.ndarray) -> np.ndarray:
461
462
K_diag : :obj:`~numpy.ndarray` of shape (n_samples_X,)
462
463
Diagonal of kernel k(X, X)
463
464
"""
464
- return self .beta_l * np .ones (X .shape [0 ])
465
+ return self .beta_l * np .ones (np . asanyarray ( X ) .shape [0 ])
465
466
466
467
def is_stationary (self ) -> bool :
467
468
"""Returns whether the kernel is stationary."""
0 commit comments