From 1dabf67c936f1534ee13c72ce3362d102864a941 Mon Sep 17 00:00:00 2001 From: Max Zwiessele Date: Fri, 28 Mar 2014 12:02:34 +0000 Subject: [PATCH] assertion checks for all kernels --- GPy/kern/_src/add.py | 12 ------------ GPy/kern/_src/kernel_slice_operations.py | 2 ++ GPy/kern/_src/prod.py | 2 -- 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/GPy/kern/_src/add.py b/GPy/kern/_src/add.py index ddc480de..fb0e114b 100644 --- a/GPy/kern/_src/add.py +++ b/GPy/kern/_src/add.py @@ -23,7 +23,6 @@ class Add(CombinationKernel): If a list of parts (of this kernel!) `which_parts` is given, only the parts of the list are taken to compute the covariance. """ - assert X.shape[1] > max(np.r_[self.active_dims]) if which_parts is None: which_parts = self.parts elif not isinstance(which_parts, (list, tuple)): @@ -33,7 +32,6 @@ class Add(CombinationKernel): @Cache_this(limit=2, force_kwargs=['which_parts']) def Kdiag(self, X, which_parts=None): - assert X.shape[1] > max(np.r_[self.active_dims]) if which_parts is None: which_parts = self.parts elif not isinstance(which_parts, (list, tuple)): @@ -160,16 +158,6 @@ class Add(CombinationKernel): target_S += b return target_mu, target_S - def _getstate(self): - """ - Get the current state of the class, - here just all the indices, rest can get recomputed - """ - return super(Add, self)._getstate() - - def _setstate(self, state): - super(Add, self)._setstate(state) - def add(self, other, name='sum'): if isinstance(other, Add): other_params = other._parameters_[:] diff --git a/GPy/kern/_src/kernel_slice_operations.py b/GPy/kern/_src/kernel_slice_operations.py index 21421cc0..42306504 100644 --- a/GPy/kern/_src/kernel_slice_operations.py +++ b/GPy/kern/_src/kernel_slice_operations.py @@ -56,6 +56,7 @@ class _Slice_wrap(object): def _slice_K(f): @wraps(f) def wrap(self, X, X2 = None, *a, **kw): + assert X.shape[1] > max(np.r_[self.active_dims]), "At least {} dimensional X needed".format(max(np.r_[self.active_dims])) with _Slice_wrap(self, X, X2) as s: ret = f(self, s.X, s.X2, *a, **kw) return ret @@ -64,6 +65,7 @@ def _slice_K(f): def _slice_Kdiag(f): @wraps(f) def wrap(self, X, *a, **kw): + assert X.shape[1] > max(np.r_[self.active_dims]), "At least {} dimensional X needed".format(max(np.r_[self.active_dims])) with _Slice_wrap(self, X, None) as s: ret = f(self, s.X, *a, **kw) return ret diff --git a/GPy/kern/_src/prod.py b/GPy/kern/_src/prod.py index 98b60366..b8f92f27 100644 --- a/GPy/kern/_src/prod.py +++ b/GPy/kern/_src/prod.py @@ -23,7 +23,6 @@ class Prod(CombinationKernel): @Cache_this(limit=2, force_kwargs=['which_parts']) def K(self, X, X2=None, which_parts=None): - assert X.shape[1] == self.input_dim if which_parts is None: which_parts = self.parts elif not isinstance(which_parts, (list, tuple)): @@ -33,7 +32,6 @@ class Prod(CombinationKernel): @Cache_this(limit=2, force_kwargs=['which_parts']) def Kdiag(self, X, which_parts=None): - assert X.shape[1] == self.input_dim if which_parts is None: which_parts = self.parts return reduce(np.multiply, (p.Kdiag(X) for p in which_parts))