mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-07-23 17:01:06 +02:00
Merge branch 'cython-fix' of git://github.com/jayanthkoushik/GPy into jayanthkoushik-cython-fix
This commit is contained in:
commit
da82f356a8
6 changed files with 55 additions and 37 deletions
|
|
@ -6,11 +6,14 @@ import numpy as np
|
|||
from ...core.parameterization import Param
|
||||
from paramz.transformations import Logexp
|
||||
from ...util.config import config # for assesing whether to use cython
|
||||
|
||||
try:
|
||||
from . import coregionalize_cython
|
||||
config.set('cython', 'working', 'True')
|
||||
use_coregionalize_cython = config.getboolean('cython', 'working')
|
||||
except ImportError:
|
||||
config.set('cython', 'working', 'False')
|
||||
print('warning in coregionalize: failed to import cython module: falling back to numpy')
|
||||
use_coregionalize_cython = False
|
||||
|
||||
|
||||
class Coregionalize(Kern):
|
||||
"""
|
||||
|
|
@ -61,7 +64,7 @@ class Coregionalize(Kern):
|
|||
self.B = np.dot(self.W, self.W.T) + np.diag(self.kappa)
|
||||
|
||||
def K(self, X, X2=None):
|
||||
if config.getboolean('cython', 'working'):
|
||||
if use_coregionalize_cython:
|
||||
return self._K_cython(X, X2)
|
||||
else:
|
||||
return self._K_numpy(X, X2)
|
||||
|
|
@ -92,7 +95,7 @@ class Coregionalize(Kern):
|
|||
index2 = np.asarray(X2, dtype=np.int)
|
||||
|
||||
#attempt to use cython for a nasty double indexing loop: fall back to numpy
|
||||
if config.getboolean('cython', 'working'):
|
||||
if use_coregionalize_cython:
|
||||
dL_dK_small = self._gradient_reduce_cython(dL_dK, index, index2)
|
||||
else:
|
||||
dL_dK_small = self._gradient_reduce_numpy(dL_dK, index, index2)
|
||||
|
|
|
|||
|
|
@ -14,9 +14,10 @@ from paramz.transformations import Logexp
|
|||
|
||||
try:
|
||||
from . import stationary_cython
|
||||
use_stationary_cython = config.getboolean('cython', 'working')
|
||||
except ImportError:
|
||||
print('warning in stationary: failed to import cython module: falling back to numpy')
|
||||
config.set('cython', 'working', 'false')
|
||||
use_stationary_cython = False
|
||||
|
||||
|
||||
class Stationary(Kern):
|
||||
|
|
@ -203,7 +204,7 @@ class Stationary(Kern):
|
|||
|
||||
tmp = dL_dr*self._inv_dist(X, X2)
|
||||
if X2 is None: X2 = X
|
||||
if config.getboolean('cython', 'working'):
|
||||
if use_stationary_cython:
|
||||
self.lengthscale.gradient = self._lengthscale_grads_cython(tmp, X, X2)
|
||||
else:
|
||||
self.lengthscale.gradient = self._lengthscale_grads_pure(tmp, X, X2)
|
||||
|
|
@ -246,7 +247,7 @@ class Stationary(Kern):
|
|||
"""
|
||||
Given the derivative of the objective wrt K (dL_dK), compute the derivative wrt X
|
||||
"""
|
||||
if config.getboolean('cython', 'working'):
|
||||
if use_stationary_cython:
|
||||
return self._gradients_X_cython(dL_dK, X, X2)
|
||||
else:
|
||||
return self._gradients_X_pure(dL_dK, X, X2)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue