tidien up coregionlize w AS

This commit is contained in:
James Hensman 2015-04-28 14:06:21 +01:00
parent a11cf422c2
commit e1c2eeb25d
6 changed files with 350 additions and 234 deletions

View file

@ -5,14 +5,9 @@ from .kern import Kern
import numpy as np import numpy as np
from ...core.parameterization import Param from ...core.parameterization import Param
from ...core.parameterization.transformations import Logexp from ...core.parameterization.transformations import Logexp
from ...util.config import config # for assesing whether to use weave from ...util.config import config # for assesing whether to use cython
import coregionalize_cython import coregionalize_cython
try:
from scipy import weave
except ImportError:
config.set('weave', 'working', 'False')
class Coregionalize(Kern): class Coregionalize(Kern):
""" """
Covariance function for intrinsic/linear coregionalization models Covariance function for intrinsic/linear coregionalization models
@ -62,13 +57,8 @@ class Coregionalize(Kern):
self.B = np.dot(self.W, self.W.T) + np.diag(self.kappa) self.B = np.dot(self.W, self.W.T) + np.diag(self.kappa)
def K(self, X, X2=None): def K(self, X, X2=None):
if config.getboolean('weave', 'working'): if config.getboolean('cython', 'working'):
try: return self._K_cython(X, X2)
return self._K_weave(X, X2)
except:
print("\n Weave compilation failed. Falling back to (slower) numpy implementation\n")
config.set('weave', 'working', 'False')
return self._K_numpy(X, X2)
else: else:
return self._K_numpy(X, X2) return self._K_numpy(X, X2)
@ -81,37 +71,6 @@ class Coregionalize(Kern):
index2 = np.asarray(X2, dtype=np.int) index2 = np.asarray(X2, dtype=np.int)
return self.B[index,index2.T] return self.B[index,index2.T]
def _K_weave(self, X, X2=None):
"""compute the kernel function using scipy.weave"""
index = np.asarray(X, dtype=np.int)
if X2 is None:
target = np.empty((X.shape[0], X.shape[0]), dtype=np.float64)
code="""
for(int i=0;i<N; i++){
target[i+i*N] = B[index[i]+output_dim*index[i]];
for(int j=0; j<i; j++){
target[j+i*N] = B[index[i]+output_dim*index[j]];
target[i+j*N] = target[j+i*N];
}
}
"""
N, B, output_dim = index.size, self.B, self.output_dim
weave.inline(code, ['target', 'index', 'N', 'B', 'output_dim'])
else:
index2 = np.asarray(X2, dtype=np.int)
target = np.empty((X.shape[0], X2.shape[0]), dtype=np.float64)
code="""
for(int i=0;i<num_inducing; i++){
for(int j=0; j<N; j++){
target[i+j*num_inducing] = B[output_dim*index[j]+index2[i]];
}
}
"""
N, num_inducing, B, output_dim = index.size, index2.size, self.B, self.output_dim
weave.inline(code, ['target', 'index', 'index2', 'N', 'num_inducing', 'B', 'output_dim'])
return target
def _K_cython(self, X, X2=None): def _K_cython(self, X, X2=None):
if X2 is None: if X2 is None:
return coregionalize_cython.K_symmetric(self.B, X[:,0]) return coregionalize_cython.K_symmetric(self.B, X[:,0])
@ -128,19 +87,13 @@ class Coregionalize(Kern):
else: else:
index2 = np.asarray(X2, dtype=np.int) index2 = np.asarray(X2, dtype=np.int)
#attempt to use weave for a nasty double indexing loop: fall back to numpy #attempt to use cython for a nasty double indexing loop: fall back to numpy
if config.getboolean('weave', 'working'): if config.getboolean('cython', 'working'):
try: dL_dK_small = self._gradient_reduce_cython(dL_dK, index, index2)
dL_dK_small = self._gradient_reduce_weave(dL_dK, index, index2)
except:
print("\n Weave compilation failed. Falling back to (slower) numpy implementation\n")
config.set('weave', 'working', 'False')
dL_dK_small = self._gradient_reduce_weave(dL_dK, index, index2)
else: else:
dL_dK_small = self._gradient_reduce_numpy(dL_dK, index, index2) dL_dK_small = self._gradient_reduce_numpy(dL_dK, index, index2)
dkappa = np.diag(dL_dK_small) dkappa = np.diag(dL_dK_small)
dL_dK_small += dL_dK_small.T dL_dK_small += dL_dK_small.T
dW = (self.W[:, None, :]*dL_dK_small[:, :, None]).sum(0) dW = (self.W[:, None, :]*dL_dK_small[:, :, None]).sum(0)
@ -148,19 +101,6 @@ class Coregionalize(Kern):
self.W.gradient = dW self.W.gradient = dW
self.kappa.gradient = dkappa self.kappa.gradient = dkappa
def _gradient_reduce_weave(self, dL_dK, index, index2):
dL_dK_small = np.zeros_like(self.B)
code="""
for(int i=0; i<num_inducing; i++){
for(int j=0; j<N; j++){
dL_dK_small[index[j] + output_dim*index2[i]] += dL_dK[i+j*num_inducing];
}
}
"""
N, num_inducing, output_dim = index.size, index2.size, self.output_dim
weave.inline(code, ['N', 'num_inducing', 'output_dim', 'dL_dK', 'dL_dK_small', 'index', 'index2'])
return dL_dK_small
def _gradient_reduce_numpy(self, dL_dK, index, index2): def _gradient_reduce_numpy(self, dL_dK, index, index2):
index, index2 = index[:,0], index2[:,0] index, index2 = index[:,0], index2[:,0]
dL_dK_small = np.zeros_like(self.B) dL_dK_small = np.zeros_like(self.B)

View file

@ -1042,7 +1042,7 @@ static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *, cha
/* Module declarations from 'GPy.kern._src.coregionalize_cython' */ /* Module declarations from 'GPy.kern._src.coregionalize_cython' */
static __Pyx_TypeInfo __Pyx_TypeInfo_double = { "double", NULL, sizeof(double), { 0 }, 0, 'R', 0, 0 }; static __Pyx_TypeInfo __Pyx_TypeInfo_double = { "double", NULL, sizeof(double), { 0 }, 0, 'R', 0, 0 };
static __Pyx_TypeInfo __Pyx_TypeInfo_int = { "int", NULL, sizeof(int), { 0 }, 0, IS_UNSIGNED(int) ? 'U' : 'I', IS_UNSIGNED(int), 0 }; static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t = { "int64_t", NULL, sizeof(__pyx_t_5numpy_int64_t), { 0 }, 0, IS_UNSIGNED(__pyx_t_5numpy_int64_t) ? 'U' : 'I', IS_UNSIGNED(__pyx_t_5numpy_int64_t), 0 };
static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_double_t = { "double_t", NULL, sizeof(__pyx_t_5numpy_double_t), { 0 }, 0, 'R', 0, 0 }; static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_double_t = { "double_t", NULL, sizeof(__pyx_t_5numpy_double_t), { 0 }, 0, 'R', 0, 0 };
#define __Pyx_MODULE_NAME "GPy.kern._src.coregionalize_cython" #define __Pyx_MODULE_NAME "GPy.kern._src.coregionalize_cython"
int __pyx_module_is_main_GPy__kern___src__coregionalize_cython = 0; int __pyx_module_is_main_GPy__kern___src__coregionalize_cython = 0;
@ -1101,7 +1101,7 @@ static char __pyx_k_K_asymmetric[] = "K_asymmetric";
static char __pyx_k_RuntimeError[] = "RuntimeError"; static char __pyx_k_RuntimeError[] = "RuntimeError";
static char __pyx_k_gradient_reduce[] = "gradient_reduce"; static char __pyx_k_gradient_reduce[] = "gradient_reduce";
static char __pyx_k_ndarray_is_not_C_contiguous[] = "ndarray is not C contiguous"; static char __pyx_k_ndarray_is_not_C_contiguous[] = "ndarray is not C contiguous";
static char __pyx_k_Users_james_work_GPy_GPy_kern[] = "/Users/james/work/GPy/GPy/kern/_src/coregionalize_cython.pyx"; static char __pyx_k_home_james_work_GPy_GPy_kern__s[] = "/home/james/work/GPy/GPy/kern/_src/coregionalize_cython.pyx";
static char __pyx_k_unknown_dtype_code_in_numpy_pxd[] = "unknown dtype code in numpy.pxd (%d)"; static char __pyx_k_unknown_dtype_code_in_numpy_pxd[] = "unknown dtype code in numpy.pxd (%d)";
static char __pyx_k_Format_string_allocated_too_shor[] = "Format string allocated too short, see comment in numpy.pxd"; static char __pyx_k_Format_string_allocated_too_shor[] = "Format string allocated too short, see comment in numpy.pxd";
static char __pyx_k_GPy_kern__src_coregionalize_cyth[] = "GPy.kern._src.coregionalize_cython"; static char __pyx_k_GPy_kern__src_coregionalize_cyth[] = "GPy.kern._src.coregionalize_cython";
@ -1120,7 +1120,6 @@ static PyObject *__pyx_n_s_M;
static PyObject *__pyx_n_s_N; static PyObject *__pyx_n_s_N;
static PyObject *__pyx_kp_u_Non_native_byte_order_not_suppor; static PyObject *__pyx_kp_u_Non_native_byte_order_not_suppor;
static PyObject *__pyx_n_s_RuntimeError; static PyObject *__pyx_n_s_RuntimeError;
static PyObject *__pyx_kp_s_Users_james_work_GPy_GPy_kern;
static PyObject *__pyx_n_s_ValueError; static PyObject *__pyx_n_s_ValueError;
static PyObject *__pyx_n_s_X; static PyObject *__pyx_n_s_X;
static PyObject *__pyx_n_s_X2; static PyObject *__pyx_n_s_X2;
@ -1128,6 +1127,7 @@ static PyObject *__pyx_n_s_dL_dK;
static PyObject *__pyx_n_s_dL_dK_small; static PyObject *__pyx_n_s_dL_dK_small;
static PyObject *__pyx_n_s_empty; static PyObject *__pyx_n_s_empty;
static PyObject *__pyx_n_s_gradient_reduce; static PyObject *__pyx_n_s_gradient_reduce;
static PyObject *__pyx_kp_s_home_james_work_GPy_GPy_kern__s;
static PyObject *__pyx_n_s_i; static PyObject *__pyx_n_s_i;
static PyObject *__pyx_n_s_import; static PyObject *__pyx_n_s_import;
static PyObject *__pyx_n_s_index; static PyObject *__pyx_n_s_index;
@ -1161,7 +1161,7 @@ static PyObject *__pyx_codeobj__12;
/* "GPy/kern/_src/coregionalize_cython.pyx":7 /* "GPy/kern/_src/coregionalize_cython.pyx":7
* cimport numpy as np * cimport numpy as np
* *
* def K_symmetric(np.ndarray[double, ndim=2] B, np.ndarray[int, ndim=1] X): # <<<<<<<<<<<<<< * def K_symmetric(np.ndarray[double, ndim=2] B, np.ndarray[np.int64_t, ndim=1] X): # <<<<<<<<<<<<<<
* cdef int N = X.size * cdef int N = X.size
* cdef np.ndarray[np.double_t, ndim=2] K = np.empty((N, N)) * cdef np.ndarray[np.double_t, ndim=2] K = np.empty((N, N))
*/ */
@ -1259,8 +1259,8 @@ static PyObject *__pyx_pf_3GPy_4kern_4_src_20coregionalize_cython_K_symmetric(CY
int __pyx_t_10; int __pyx_t_10;
int __pyx_t_11; int __pyx_t_11;
int __pyx_t_12; int __pyx_t_12;
int __pyx_t_13; __pyx_t_5numpy_int64_t __pyx_t_13;
int __pyx_t_14; __pyx_t_5numpy_int64_t __pyx_t_14;
int __pyx_t_15; int __pyx_t_15;
int __pyx_t_16; int __pyx_t_16;
int __pyx_lineno = 0; int __pyx_lineno = 0;
@ -1286,13 +1286,13 @@ static PyObject *__pyx_pf_3GPy_4kern_4_src_20coregionalize_cython_K_symmetric(CY
__pyx_pybuffernd_B.diminfo[0].strides = __pyx_pybuffernd_B.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_B.diminfo[0].shape = __pyx_pybuffernd_B.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_B.diminfo[1].strides = __pyx_pybuffernd_B.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_B.diminfo[1].shape = __pyx_pybuffernd_B.rcbuffer->pybuffer.shape[1]; __pyx_pybuffernd_B.diminfo[0].strides = __pyx_pybuffernd_B.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_B.diminfo[0].shape = __pyx_pybuffernd_B.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_B.diminfo[1].strides = __pyx_pybuffernd_B.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_B.diminfo[1].shape = __pyx_pybuffernd_B.rcbuffer->pybuffer.shape[1];
{ {
__Pyx_BufFmt_StackElem __pyx_stack[1]; __Pyx_BufFmt_StackElem __pyx_stack[1];
if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_X.rcbuffer->pybuffer, (PyObject*)__pyx_v_X, &__Pyx_TypeInfo_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_X.rcbuffer->pybuffer, (PyObject*)__pyx_v_X, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
} }
__pyx_pybuffernd_X.diminfo[0].strides = __pyx_pybuffernd_X.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_X.diminfo[0].shape = __pyx_pybuffernd_X.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_X.diminfo[0].strides = __pyx_pybuffernd_X.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_X.diminfo[0].shape = __pyx_pybuffernd_X.rcbuffer->pybuffer.shape[0];
/* "GPy/kern/_src/coregionalize_cython.pyx":8 /* "GPy/kern/_src/coregionalize_cython.pyx":8
* *
* def K_symmetric(np.ndarray[double, ndim=2] B, np.ndarray[int, ndim=1] X): * def K_symmetric(np.ndarray[double, ndim=2] B, np.ndarray[np.int64_t, ndim=1] X):
* cdef int N = X.size # <<<<<<<<<<<<<< * cdef int N = X.size # <<<<<<<<<<<<<<
* cdef np.ndarray[np.double_t, ndim=2] K = np.empty((N, N)) * cdef np.ndarray[np.double_t, ndim=2] K = np.empty((N, N))
* for n in range(N): * for n in range(N):
@ -1304,7 +1304,7 @@ static PyObject *__pyx_pf_3GPy_4kern_4_src_20coregionalize_cython_K_symmetric(CY
__pyx_v_N = __pyx_t_2; __pyx_v_N = __pyx_t_2;
/* "GPy/kern/_src/coregionalize_cython.pyx":9 /* "GPy/kern/_src/coregionalize_cython.pyx":9
* def K_symmetric(np.ndarray[double, ndim=2] B, np.ndarray[int, ndim=1] X): * def K_symmetric(np.ndarray[double, ndim=2] B, np.ndarray[np.int64_t, ndim=1] X):
* cdef int N = X.size * cdef int N = X.size
* cdef np.ndarray[np.double_t, ndim=2] K = np.empty((N, N)) # <<<<<<<<<<<<<< * cdef np.ndarray[np.double_t, ndim=2] K = np.empty((N, N)) # <<<<<<<<<<<<<<
* for n in range(N): * for n in range(N):
@ -1398,8 +1398,8 @@ static PyObject *__pyx_pf_3GPy_4kern_4_src_20coregionalize_cython_K_symmetric(CY
*/ */
__pyx_t_11 = __pyx_v_n; __pyx_t_11 = __pyx_v_n;
__pyx_t_12 = __pyx_v_m; __pyx_t_12 = __pyx_v_m;
__pyx_t_13 = (*__Pyx_BufPtrStrided1d(int *, __pyx_pybuffernd_X.rcbuffer->pybuffer.buf, __pyx_t_11, __pyx_pybuffernd_X.diminfo[0].strides)); __pyx_t_13 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_pybuffernd_X.rcbuffer->pybuffer.buf, __pyx_t_11, __pyx_pybuffernd_X.diminfo[0].strides));
__pyx_t_14 = (*__Pyx_BufPtrStrided1d(int *, __pyx_pybuffernd_X.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_X.diminfo[0].strides)); __pyx_t_14 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_pybuffernd_X.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_X.diminfo[0].strides));
__pyx_t_15 = __pyx_v_n; __pyx_t_15 = __pyx_v_n;
__pyx_t_16 = __pyx_v_m; __pyx_t_16 = __pyx_v_m;
*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_pybuffernd_K.rcbuffer->pybuffer.buf, __pyx_t_15, __pyx_pybuffernd_K.diminfo[0].strides, __pyx_t_16, __pyx_pybuffernd_K.diminfo[1].strides) = (*__Pyx_BufPtrStrided2d(double *, __pyx_pybuffernd_B.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_B.diminfo[0].strides, __pyx_t_14, __pyx_pybuffernd_B.diminfo[1].strides)); *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_pybuffernd_K.rcbuffer->pybuffer.buf, __pyx_t_15, __pyx_pybuffernd_K.diminfo[0].strides, __pyx_t_16, __pyx_pybuffernd_K.diminfo[1].strides) = (*__Pyx_BufPtrStrided2d(double *, __pyx_pybuffernd_B.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_B.diminfo[0].strides, __pyx_t_14, __pyx_pybuffernd_B.diminfo[1].strides));
@ -1411,7 +1411,7 @@ static PyObject *__pyx_pf_3GPy_4kern_4_src_20coregionalize_cython_K_symmetric(CY
* K[n,m] = B[X[n],X[m]] * K[n,m] = B[X[n],X[m]]
* return K # <<<<<<<<<<<<<< * return K # <<<<<<<<<<<<<<
* *
* def K_asymmetric(np.ndarray[double, ndim=2] B, np.ndarray[int, ndim=1] X, np.ndarray[int, ndim=1] X2): * def K_asymmetric(np.ndarray[double, ndim=2] B, np.ndarray[np.int64_t, ndim=1] X, np.ndarray[np.int64_t, ndim=1] X2):
*/ */
__Pyx_XDECREF(__pyx_r); __Pyx_XDECREF(__pyx_r);
__Pyx_INCREF(((PyObject *)__pyx_v_K)); __Pyx_INCREF(((PyObject *)__pyx_v_K));
@ -1421,7 +1421,7 @@ static PyObject *__pyx_pf_3GPy_4kern_4_src_20coregionalize_cython_K_symmetric(CY
/* "GPy/kern/_src/coregionalize_cython.pyx":7 /* "GPy/kern/_src/coregionalize_cython.pyx":7
* cimport numpy as np * cimport numpy as np
* *
* def K_symmetric(np.ndarray[double, ndim=2] B, np.ndarray[int, ndim=1] X): # <<<<<<<<<<<<<< * def K_symmetric(np.ndarray[double, ndim=2] B, np.ndarray[np.int64_t, ndim=1] X): # <<<<<<<<<<<<<<
* cdef int N = X.size * cdef int N = X.size
* cdef np.ndarray[np.double_t, ndim=2] K = np.empty((N, N)) * cdef np.ndarray[np.double_t, ndim=2] K = np.empty((N, N))
*/ */
@ -1456,7 +1456,7 @@ static PyObject *__pyx_pf_3GPy_4kern_4_src_20coregionalize_cython_K_symmetric(CY
/* "GPy/kern/_src/coregionalize_cython.pyx":15 /* "GPy/kern/_src/coregionalize_cython.pyx":15
* return K * return K
* *
* def K_asymmetric(np.ndarray[double, ndim=2] B, np.ndarray[int, ndim=1] X, np.ndarray[int, ndim=1] X2): # <<<<<<<<<<<<<< * def K_asymmetric(np.ndarray[double, ndim=2] B, np.ndarray[np.int64_t, ndim=1] X, np.ndarray[np.int64_t, ndim=1] X2): # <<<<<<<<<<<<<<
* cdef int N = X.size * cdef int N = X.size
* cdef int M = X2.size * cdef int M = X2.size
*/ */
@ -1567,8 +1567,8 @@ static PyObject *__pyx_pf_3GPy_4kern_4_src_20coregionalize_cython_2K_asymmetric(
int __pyx_t_10; int __pyx_t_10;
int __pyx_t_11; int __pyx_t_11;
int __pyx_t_12; int __pyx_t_12;
int __pyx_t_13; __pyx_t_5numpy_int64_t __pyx_t_13;
int __pyx_t_14; __pyx_t_5numpy_int64_t __pyx_t_14;
int __pyx_t_15; int __pyx_t_15;
int __pyx_t_16; int __pyx_t_16;
int __pyx_lineno = 0; int __pyx_lineno = 0;
@ -1598,18 +1598,18 @@ static PyObject *__pyx_pf_3GPy_4kern_4_src_20coregionalize_cython_2K_asymmetric(
__pyx_pybuffernd_B.diminfo[0].strides = __pyx_pybuffernd_B.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_B.diminfo[0].shape = __pyx_pybuffernd_B.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_B.diminfo[1].strides = __pyx_pybuffernd_B.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_B.diminfo[1].shape = __pyx_pybuffernd_B.rcbuffer->pybuffer.shape[1]; __pyx_pybuffernd_B.diminfo[0].strides = __pyx_pybuffernd_B.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_B.diminfo[0].shape = __pyx_pybuffernd_B.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_B.diminfo[1].strides = __pyx_pybuffernd_B.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_B.diminfo[1].shape = __pyx_pybuffernd_B.rcbuffer->pybuffer.shape[1];
{ {
__Pyx_BufFmt_StackElem __pyx_stack[1]; __Pyx_BufFmt_StackElem __pyx_stack[1];
if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_X.rcbuffer->pybuffer, (PyObject*)__pyx_v_X, &__Pyx_TypeInfo_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_X.rcbuffer->pybuffer, (PyObject*)__pyx_v_X, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
} }
__pyx_pybuffernd_X.diminfo[0].strides = __pyx_pybuffernd_X.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_X.diminfo[0].shape = __pyx_pybuffernd_X.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_X.diminfo[0].strides = __pyx_pybuffernd_X.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_X.diminfo[0].shape = __pyx_pybuffernd_X.rcbuffer->pybuffer.shape[0];
{ {
__Pyx_BufFmt_StackElem __pyx_stack[1]; __Pyx_BufFmt_StackElem __pyx_stack[1];
if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_X2.rcbuffer->pybuffer, (PyObject*)__pyx_v_X2, &__Pyx_TypeInfo_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_X2.rcbuffer->pybuffer, (PyObject*)__pyx_v_X2, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
} }
__pyx_pybuffernd_X2.diminfo[0].strides = __pyx_pybuffernd_X2.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_X2.diminfo[0].shape = __pyx_pybuffernd_X2.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_X2.diminfo[0].strides = __pyx_pybuffernd_X2.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_X2.diminfo[0].shape = __pyx_pybuffernd_X2.rcbuffer->pybuffer.shape[0];
/* "GPy/kern/_src/coregionalize_cython.pyx":16 /* "GPy/kern/_src/coregionalize_cython.pyx":16
* *
* def K_asymmetric(np.ndarray[double, ndim=2] B, np.ndarray[int, ndim=1] X, np.ndarray[int, ndim=1] X2): * def K_asymmetric(np.ndarray[double, ndim=2] B, np.ndarray[np.int64_t, ndim=1] X, np.ndarray[np.int64_t, ndim=1] X2):
* cdef int N = X.size # <<<<<<<<<<<<<< * cdef int N = X.size # <<<<<<<<<<<<<<
* cdef int M = X2.size * cdef int M = X2.size
* cdef np.ndarray[np.double_t, ndim=2] K = np.empty((N, M)) * cdef np.ndarray[np.double_t, ndim=2] K = np.empty((N, M))
@ -1621,7 +1621,7 @@ static PyObject *__pyx_pf_3GPy_4kern_4_src_20coregionalize_cython_2K_asymmetric(
__pyx_v_N = __pyx_t_2; __pyx_v_N = __pyx_t_2;
/* "GPy/kern/_src/coregionalize_cython.pyx":17 /* "GPy/kern/_src/coregionalize_cython.pyx":17
* def K_asymmetric(np.ndarray[double, ndim=2] B, np.ndarray[int, ndim=1] X, np.ndarray[int, ndim=1] X2): * def K_asymmetric(np.ndarray[double, ndim=2] B, np.ndarray[np.int64_t, ndim=1] X, np.ndarray[np.int64_t, ndim=1] X2):
* cdef int N = X.size * cdef int N = X.size
* cdef int M = X2.size # <<<<<<<<<<<<<< * cdef int M = X2.size # <<<<<<<<<<<<<<
* cdef np.ndarray[np.double_t, ndim=2] K = np.empty((N, M)) * cdef np.ndarray[np.double_t, ndim=2] K = np.empty((N, M))
@ -1728,8 +1728,8 @@ static PyObject *__pyx_pf_3GPy_4kern_4_src_20coregionalize_cython_2K_asymmetric(
*/ */
__pyx_t_11 = __pyx_v_n; __pyx_t_11 = __pyx_v_n;
__pyx_t_12 = __pyx_v_m; __pyx_t_12 = __pyx_v_m;
__pyx_t_13 = (*__Pyx_BufPtrStrided1d(int *, __pyx_pybuffernd_X.rcbuffer->pybuffer.buf, __pyx_t_11, __pyx_pybuffernd_X.diminfo[0].strides)); __pyx_t_13 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_pybuffernd_X.rcbuffer->pybuffer.buf, __pyx_t_11, __pyx_pybuffernd_X.diminfo[0].strides));
__pyx_t_14 = (*__Pyx_BufPtrStrided1d(int *, __pyx_pybuffernd_X2.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_X2.diminfo[0].strides)); __pyx_t_14 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_pybuffernd_X2.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_X2.diminfo[0].strides));
__pyx_t_15 = __pyx_v_n; __pyx_t_15 = __pyx_v_n;
__pyx_t_16 = __pyx_v_m; __pyx_t_16 = __pyx_v_m;
*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_pybuffernd_K.rcbuffer->pybuffer.buf, __pyx_t_15, __pyx_pybuffernd_K.diminfo[0].strides, __pyx_t_16, __pyx_pybuffernd_K.diminfo[1].strides) = (*__Pyx_BufPtrStrided2d(double *, __pyx_pybuffernd_B.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_B.diminfo[0].strides, __pyx_t_14, __pyx_pybuffernd_B.diminfo[1].strides)); *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_pybuffernd_K.rcbuffer->pybuffer.buf, __pyx_t_15, __pyx_pybuffernd_K.diminfo[0].strides, __pyx_t_16, __pyx_pybuffernd_K.diminfo[1].strides) = (*__Pyx_BufPtrStrided2d(double *, __pyx_pybuffernd_B.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_B.diminfo[0].strides, __pyx_t_14, __pyx_pybuffernd_B.diminfo[1].strides));
@ -1741,7 +1741,7 @@ static PyObject *__pyx_pf_3GPy_4kern_4_src_20coregionalize_cython_2K_asymmetric(
* K[n,m] = B[X[n],X2[m]] * K[n,m] = B[X[n],X2[m]]
* return K # <<<<<<<<<<<<<< * return K # <<<<<<<<<<<<<<
* *
* def gradient_reduce(int D, np.ndarray[double, ndim=2] dL_dK, np.ndarray[int, ndim=1] index, np.ndarray[int, ndim=1] index2): * def gradient_reduce(int D, np.ndarray[double, ndim=2] dL_dK, np.ndarray[np.int64_t, ndim=1] index, np.ndarray[np.int64_t, ndim=1] index2):
*/ */
__Pyx_XDECREF(__pyx_r); __Pyx_XDECREF(__pyx_r);
__Pyx_INCREF(((PyObject *)__pyx_v_K)); __Pyx_INCREF(((PyObject *)__pyx_v_K));
@ -1751,7 +1751,7 @@ static PyObject *__pyx_pf_3GPy_4kern_4_src_20coregionalize_cython_2K_asymmetric(
/* "GPy/kern/_src/coregionalize_cython.pyx":15 /* "GPy/kern/_src/coregionalize_cython.pyx":15
* return K * return K
* *
* def K_asymmetric(np.ndarray[double, ndim=2] B, np.ndarray[int, ndim=1] X, np.ndarray[int, ndim=1] X2): # <<<<<<<<<<<<<< * def K_asymmetric(np.ndarray[double, ndim=2] B, np.ndarray[np.int64_t, ndim=1] X, np.ndarray[np.int64_t, ndim=1] X2): # <<<<<<<<<<<<<<
* cdef int N = X.size * cdef int N = X.size
* cdef int M = X2.size * cdef int M = X2.size
*/ */
@ -1788,7 +1788,7 @@ static PyObject *__pyx_pf_3GPy_4kern_4_src_20coregionalize_cython_2K_asymmetric(
/* "GPy/kern/_src/coregionalize_cython.pyx":24 /* "GPy/kern/_src/coregionalize_cython.pyx":24
* return K * return K
* *
* def gradient_reduce(int D, np.ndarray[double, ndim=2] dL_dK, np.ndarray[int, ndim=1] index, np.ndarray[int, ndim=1] index2): # <<<<<<<<<<<<<< * def gradient_reduce(int D, np.ndarray[double, ndim=2] dL_dK, np.ndarray[np.int64_t, ndim=1] index, np.ndarray[np.int64_t, ndim=1] index2): # <<<<<<<<<<<<<<
* cdef np.ndarray[np.double_t, ndim=2] dL_dK_small = np.zeros((D, D)) * cdef np.ndarray[np.double_t, ndim=2] dL_dK_small = np.zeros((D, D))
* cdef int N = index.size * cdef int N = index.size
*/ */
@ -1910,8 +1910,8 @@ static PyObject *__pyx_pf_3GPy_4kern_4_src_20coregionalize_cython_4gradient_redu
int __pyx_t_12; int __pyx_t_12;
int __pyx_t_13; int __pyx_t_13;
int __pyx_t_14; int __pyx_t_14;
int __pyx_t_15; __pyx_t_5numpy_int64_t __pyx_t_15;
int __pyx_t_16; __pyx_t_5numpy_int64_t __pyx_t_16;
int __pyx_lineno = 0; int __pyx_lineno = 0;
const char *__pyx_filename = NULL; const char *__pyx_filename = NULL;
int __pyx_clineno = 0; int __pyx_clineno = 0;
@ -1939,18 +1939,18 @@ static PyObject *__pyx_pf_3GPy_4kern_4_src_20coregionalize_cython_4gradient_redu
__pyx_pybuffernd_dL_dK.diminfo[0].strides = __pyx_pybuffernd_dL_dK.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_dL_dK.diminfo[0].shape = __pyx_pybuffernd_dL_dK.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_dL_dK.diminfo[1].strides = __pyx_pybuffernd_dL_dK.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_dL_dK.diminfo[1].shape = __pyx_pybuffernd_dL_dK.rcbuffer->pybuffer.shape[1]; __pyx_pybuffernd_dL_dK.diminfo[0].strides = __pyx_pybuffernd_dL_dK.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_dL_dK.diminfo[0].shape = __pyx_pybuffernd_dL_dK.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_dL_dK.diminfo[1].strides = __pyx_pybuffernd_dL_dK.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_dL_dK.diminfo[1].shape = __pyx_pybuffernd_dL_dK.rcbuffer->pybuffer.shape[1];
{ {
__Pyx_BufFmt_StackElem __pyx_stack[1]; __Pyx_BufFmt_StackElem __pyx_stack[1];
if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_index.rcbuffer->pybuffer, (PyObject*)__pyx_v_index, &__Pyx_TypeInfo_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_index.rcbuffer->pybuffer, (PyObject*)__pyx_v_index, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
} }
__pyx_pybuffernd_index.diminfo[0].strides = __pyx_pybuffernd_index.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_index.diminfo[0].shape = __pyx_pybuffernd_index.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_index.diminfo[0].strides = __pyx_pybuffernd_index.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_index.diminfo[0].shape = __pyx_pybuffernd_index.rcbuffer->pybuffer.shape[0];
{ {
__Pyx_BufFmt_StackElem __pyx_stack[1]; __Pyx_BufFmt_StackElem __pyx_stack[1];
if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_index2.rcbuffer->pybuffer, (PyObject*)__pyx_v_index2, &__Pyx_TypeInfo_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_index2.rcbuffer->pybuffer, (PyObject*)__pyx_v_index2, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
} }
__pyx_pybuffernd_index2.diminfo[0].strides = __pyx_pybuffernd_index2.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_index2.diminfo[0].shape = __pyx_pybuffernd_index2.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_index2.diminfo[0].strides = __pyx_pybuffernd_index2.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_index2.diminfo[0].shape = __pyx_pybuffernd_index2.rcbuffer->pybuffer.shape[0];
/* "GPy/kern/_src/coregionalize_cython.pyx":25 /* "GPy/kern/_src/coregionalize_cython.pyx":25
* *
* def gradient_reduce(int D, np.ndarray[double, ndim=2] dL_dK, np.ndarray[int, ndim=1] index, np.ndarray[int, ndim=1] index2): * def gradient_reduce(int D, np.ndarray[double, ndim=2] dL_dK, np.ndarray[np.int64_t, ndim=1] index, np.ndarray[np.int64_t, ndim=1] index2):
* cdef np.ndarray[np.double_t, ndim=2] dL_dK_small = np.zeros((D, D)) # <<<<<<<<<<<<<< * cdef np.ndarray[np.double_t, ndim=2] dL_dK_small = np.zeros((D, D)) # <<<<<<<<<<<<<<
* cdef int N = index.size * cdef int N = index.size
* cdef int M = index2.size * cdef int M = index2.size
@ -2013,7 +2013,7 @@ static PyObject *__pyx_pf_3GPy_4kern_4_src_20coregionalize_cython_4gradient_redu
__pyx_t_1 = 0; __pyx_t_1 = 0;
/* "GPy/kern/_src/coregionalize_cython.pyx":26 /* "GPy/kern/_src/coregionalize_cython.pyx":26
* def gradient_reduce(int D, np.ndarray[double, ndim=2] dL_dK, np.ndarray[int, ndim=1] index, np.ndarray[int, ndim=1] index2): * def gradient_reduce(int D, np.ndarray[double, ndim=2] dL_dK, np.ndarray[np.int64_t, ndim=1] index, np.ndarray[np.int64_t, ndim=1] index2):
* cdef np.ndarray[np.double_t, ndim=2] dL_dK_small = np.zeros((D, D)) * cdef np.ndarray[np.double_t, ndim=2] dL_dK_small = np.zeros((D, D))
* cdef int N = index.size # <<<<<<<<<<<<<< * cdef int N = index.size # <<<<<<<<<<<<<<
* cdef int M = index2.size * cdef int M = index2.size
@ -2071,8 +2071,8 @@ static PyObject *__pyx_pf_3GPy_4kern_4_src_20coregionalize_cython_4gradient_redu
__pyx_t_12 = __pyx_v_j; __pyx_t_12 = __pyx_v_j;
__pyx_t_13 = __pyx_v_j; __pyx_t_13 = __pyx_v_j;
__pyx_t_14 = __pyx_v_i; __pyx_t_14 = __pyx_v_i;
__pyx_t_15 = (*__Pyx_BufPtrStrided1d(int *, __pyx_pybuffernd_index.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_index.diminfo[0].strides)); __pyx_t_15 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_pybuffernd_index.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_index.diminfo[0].strides));
__pyx_t_16 = (*__Pyx_BufPtrStrided1d(int *, __pyx_pybuffernd_index2.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_index2.diminfo[0].strides)); __pyx_t_16 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_pybuffernd_index2.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_index2.diminfo[0].strides));
*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_pybuffernd_dL_dK_small.rcbuffer->pybuffer.buf, __pyx_t_15, __pyx_pybuffernd_dL_dK_small.diminfo[0].strides, __pyx_t_16, __pyx_pybuffernd_dL_dK_small.diminfo[1].strides) += (*__Pyx_BufPtrStrided2d(double *, __pyx_pybuffernd_dL_dK.rcbuffer->pybuffer.buf, __pyx_t_11, __pyx_pybuffernd_dL_dK.diminfo[0].strides, __pyx_t_12, __pyx_pybuffernd_dL_dK.diminfo[1].strides)); *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_pybuffernd_dL_dK_small.rcbuffer->pybuffer.buf, __pyx_t_15, __pyx_pybuffernd_dL_dK_small.diminfo[0].strides, __pyx_t_16, __pyx_pybuffernd_dL_dK_small.diminfo[1].strides) += (*__Pyx_BufPtrStrided2d(double *, __pyx_pybuffernd_dL_dK.rcbuffer->pybuffer.buf, __pyx_t_11, __pyx_pybuffernd_dL_dK.diminfo[0].strides, __pyx_t_12, __pyx_pybuffernd_dL_dK.diminfo[1].strides));
} }
} }
@ -2092,7 +2092,7 @@ static PyObject *__pyx_pf_3GPy_4kern_4_src_20coregionalize_cython_4gradient_redu
/* "GPy/kern/_src/coregionalize_cython.pyx":24 /* "GPy/kern/_src/coregionalize_cython.pyx":24
* return K * return K
* *
* def gradient_reduce(int D, np.ndarray[double, ndim=2] dL_dK, np.ndarray[int, ndim=1] index, np.ndarray[int, ndim=1] index2): # <<<<<<<<<<<<<< * def gradient_reduce(int D, np.ndarray[double, ndim=2] dL_dK, np.ndarray[np.int64_t, ndim=1] index, np.ndarray[np.int64_t, ndim=1] index2): # <<<<<<<<<<<<<<
* cdef np.ndarray[np.double_t, ndim=2] dL_dK_small = np.zeros((D, D)) * cdef np.ndarray[np.double_t, ndim=2] dL_dK_small = np.zeros((D, D))
* cdef int N = index.size * cdef int N = index.size
*/ */
@ -4175,7 +4175,6 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
{&__pyx_n_s_N, __pyx_k_N, sizeof(__pyx_k_N), 0, 0, 1, 1}, {&__pyx_n_s_N, __pyx_k_N, sizeof(__pyx_k_N), 0, 0, 1, 1},
{&__pyx_kp_u_Non_native_byte_order_not_suppor, __pyx_k_Non_native_byte_order_not_suppor, sizeof(__pyx_k_Non_native_byte_order_not_suppor), 0, 1, 0, 0}, {&__pyx_kp_u_Non_native_byte_order_not_suppor, __pyx_k_Non_native_byte_order_not_suppor, sizeof(__pyx_k_Non_native_byte_order_not_suppor), 0, 1, 0, 0},
{&__pyx_n_s_RuntimeError, __pyx_k_RuntimeError, sizeof(__pyx_k_RuntimeError), 0, 0, 1, 1}, {&__pyx_n_s_RuntimeError, __pyx_k_RuntimeError, sizeof(__pyx_k_RuntimeError), 0, 0, 1, 1},
{&__pyx_kp_s_Users_james_work_GPy_GPy_kern, __pyx_k_Users_james_work_GPy_GPy_kern, sizeof(__pyx_k_Users_james_work_GPy_GPy_kern), 0, 0, 1, 0},
{&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1}, {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1},
{&__pyx_n_s_X, __pyx_k_X, sizeof(__pyx_k_X), 0, 0, 1, 1}, {&__pyx_n_s_X, __pyx_k_X, sizeof(__pyx_k_X), 0, 0, 1, 1},
{&__pyx_n_s_X2, __pyx_k_X2, sizeof(__pyx_k_X2), 0, 0, 1, 1}, {&__pyx_n_s_X2, __pyx_k_X2, sizeof(__pyx_k_X2), 0, 0, 1, 1},
@ -4183,6 +4182,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
{&__pyx_n_s_dL_dK_small, __pyx_k_dL_dK_small, sizeof(__pyx_k_dL_dK_small), 0, 0, 1, 1}, {&__pyx_n_s_dL_dK_small, __pyx_k_dL_dK_small, sizeof(__pyx_k_dL_dK_small), 0, 0, 1, 1},
{&__pyx_n_s_empty, __pyx_k_empty, sizeof(__pyx_k_empty), 0, 0, 1, 1}, {&__pyx_n_s_empty, __pyx_k_empty, sizeof(__pyx_k_empty), 0, 0, 1, 1},
{&__pyx_n_s_gradient_reduce, __pyx_k_gradient_reduce, sizeof(__pyx_k_gradient_reduce), 0, 0, 1, 1}, {&__pyx_n_s_gradient_reduce, __pyx_k_gradient_reduce, sizeof(__pyx_k_gradient_reduce), 0, 0, 1, 1},
{&__pyx_kp_s_home_james_work_GPy_GPy_kern__s, __pyx_k_home_james_work_GPy_GPy_kern__s, sizeof(__pyx_k_home_james_work_GPy_GPy_kern__s), 0, 0, 1, 0},
{&__pyx_n_s_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 0, 1, 1}, {&__pyx_n_s_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 0, 1, 1},
{&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1}, {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1},
{&__pyx_n_s_index, __pyx_k_index, sizeof(__pyx_k_index), 0, 0, 1, 1}, {&__pyx_n_s_index, __pyx_k_index, sizeof(__pyx_k_index), 0, 0, 1, 1},
@ -4284,38 +4284,38 @@ static int __Pyx_InitCachedConstants(void) {
/* "GPy/kern/_src/coregionalize_cython.pyx":7 /* "GPy/kern/_src/coregionalize_cython.pyx":7
* cimport numpy as np * cimport numpy as np
* *
* def K_symmetric(np.ndarray[double, ndim=2] B, np.ndarray[int, ndim=1] X): # <<<<<<<<<<<<<< * def K_symmetric(np.ndarray[double, ndim=2] B, np.ndarray[np.int64_t, ndim=1] X): # <<<<<<<<<<<<<<
* cdef int N = X.size * cdef int N = X.size
* cdef np.ndarray[np.double_t, ndim=2] K = np.empty((N, N)) * cdef np.ndarray[np.double_t, ndim=2] K = np.empty((N, N))
*/ */
__pyx_tuple__7 = PyTuple_Pack(6, __pyx_n_s_B, __pyx_n_s_X, __pyx_n_s_N, __pyx_n_s_K, __pyx_n_s_n, __pyx_n_s_m); if (unlikely(!__pyx_tuple__7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_tuple__7 = PyTuple_Pack(6, __pyx_n_s_B, __pyx_n_s_X, __pyx_n_s_N, __pyx_n_s_K, __pyx_n_s_n, __pyx_n_s_m); if (unlikely(!__pyx_tuple__7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_tuple__7); __Pyx_GOTREF(__pyx_tuple__7);
__Pyx_GIVEREF(__pyx_tuple__7); __Pyx_GIVEREF(__pyx_tuple__7);
__pyx_codeobj__8 = (PyObject*)__Pyx_PyCode_New(2, 0, 6, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__7, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_Users_james_work_GPy_GPy_kern, __pyx_n_s_K_symmetric, 7, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_codeobj__8 = (PyObject*)__Pyx_PyCode_New(2, 0, 6, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__7, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_james_work_GPy_GPy_kern__s, __pyx_n_s_K_symmetric, 7, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
/* "GPy/kern/_src/coregionalize_cython.pyx":15 /* "GPy/kern/_src/coregionalize_cython.pyx":15
* return K * return K
* *
* def K_asymmetric(np.ndarray[double, ndim=2] B, np.ndarray[int, ndim=1] X, np.ndarray[int, ndim=1] X2): # <<<<<<<<<<<<<< * def K_asymmetric(np.ndarray[double, ndim=2] B, np.ndarray[np.int64_t, ndim=1] X, np.ndarray[np.int64_t, ndim=1] X2): # <<<<<<<<<<<<<<
* cdef int N = X.size * cdef int N = X.size
* cdef int M = X2.size * cdef int M = X2.size
*/ */
__pyx_tuple__9 = PyTuple_Pack(8, __pyx_n_s_B, __pyx_n_s_X, __pyx_n_s_X2, __pyx_n_s_N, __pyx_n_s_M, __pyx_n_s_K, __pyx_n_s_n, __pyx_n_s_m); if (unlikely(!__pyx_tuple__9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_tuple__9 = PyTuple_Pack(8, __pyx_n_s_B, __pyx_n_s_X, __pyx_n_s_X2, __pyx_n_s_N, __pyx_n_s_M, __pyx_n_s_K, __pyx_n_s_n, __pyx_n_s_m); if (unlikely(!__pyx_tuple__9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_tuple__9); __Pyx_GOTREF(__pyx_tuple__9);
__Pyx_GIVEREF(__pyx_tuple__9); __Pyx_GIVEREF(__pyx_tuple__9);
__pyx_codeobj__10 = (PyObject*)__Pyx_PyCode_New(3, 0, 8, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__9, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_Users_james_work_GPy_GPy_kern, __pyx_n_s_K_asymmetric, 15, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_codeobj__10 = (PyObject*)__Pyx_PyCode_New(3, 0, 8, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__9, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_james_work_GPy_GPy_kern__s, __pyx_n_s_K_asymmetric, 15, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
/* "GPy/kern/_src/coregionalize_cython.pyx":24 /* "GPy/kern/_src/coregionalize_cython.pyx":24
* return K * return K
* *
* def gradient_reduce(int D, np.ndarray[double, ndim=2] dL_dK, np.ndarray[int, ndim=1] index, np.ndarray[int, ndim=1] index2): # <<<<<<<<<<<<<< * def gradient_reduce(int D, np.ndarray[double, ndim=2] dL_dK, np.ndarray[np.int64_t, ndim=1] index, np.ndarray[np.int64_t, ndim=1] index2): # <<<<<<<<<<<<<<
* cdef np.ndarray[np.double_t, ndim=2] dL_dK_small = np.zeros((D, D)) * cdef np.ndarray[np.double_t, ndim=2] dL_dK_small = np.zeros((D, D))
* cdef int N = index.size * cdef int N = index.size
*/ */
__pyx_tuple__11 = PyTuple_Pack(9, __pyx_n_s_D, __pyx_n_s_dL_dK, __pyx_n_s_index, __pyx_n_s_index2, __pyx_n_s_dL_dK_small, __pyx_n_s_N, __pyx_n_s_M, __pyx_n_s_i, __pyx_n_s_j); if (unlikely(!__pyx_tuple__11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_tuple__11 = PyTuple_Pack(9, __pyx_n_s_D, __pyx_n_s_dL_dK, __pyx_n_s_index, __pyx_n_s_index2, __pyx_n_s_dL_dK_small, __pyx_n_s_N, __pyx_n_s_M, __pyx_n_s_i, __pyx_n_s_j); if (unlikely(!__pyx_tuple__11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_tuple__11); __Pyx_GOTREF(__pyx_tuple__11);
__Pyx_GIVEREF(__pyx_tuple__11); __Pyx_GIVEREF(__pyx_tuple__11);
__pyx_codeobj__12 = (PyObject*)__Pyx_PyCode_New(4, 0, 9, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__11, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_Users_james_work_GPy_GPy_kern, __pyx_n_s_gradient_reduce, 24, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_codeobj__12 = (PyObject*)__Pyx_PyCode_New(4, 0, 9, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__11, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_james_work_GPy_GPy_kern__s, __pyx_n_s_gradient_reduce, 24, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_RefNannyFinishContext(); __Pyx_RefNannyFinishContext();
return 0; return 0;
__pyx_L1_error:; __pyx_L1_error:;
@ -4442,7 +4442,7 @@ PyMODINIT_FUNC PyInit_coregionalize_cython(void)
/* "GPy/kern/_src/coregionalize_cython.pyx":7 /* "GPy/kern/_src/coregionalize_cython.pyx":7
* cimport numpy as np * cimport numpy as np
* *
* def K_symmetric(np.ndarray[double, ndim=2] B, np.ndarray[int, ndim=1] X): # <<<<<<<<<<<<<< * def K_symmetric(np.ndarray[double, ndim=2] B, np.ndarray[np.int64_t, ndim=1] X): # <<<<<<<<<<<<<<
* cdef int N = X.size * cdef int N = X.size
* cdef np.ndarray[np.double_t, ndim=2] K = np.empty((N, N)) * cdef np.ndarray[np.double_t, ndim=2] K = np.empty((N, N))
*/ */
@ -4454,7 +4454,7 @@ PyMODINIT_FUNC PyInit_coregionalize_cython(void)
/* "GPy/kern/_src/coregionalize_cython.pyx":15 /* "GPy/kern/_src/coregionalize_cython.pyx":15
* return K * return K
* *
* def K_asymmetric(np.ndarray[double, ndim=2] B, np.ndarray[int, ndim=1] X, np.ndarray[int, ndim=1] X2): # <<<<<<<<<<<<<< * def K_asymmetric(np.ndarray[double, ndim=2] B, np.ndarray[np.int64_t, ndim=1] X, np.ndarray[np.int64_t, ndim=1] X2): # <<<<<<<<<<<<<<
* cdef int N = X.size * cdef int N = X.size
* cdef int M = X2.size * cdef int M = X2.size
*/ */
@ -4466,7 +4466,7 @@ PyMODINIT_FUNC PyInit_coregionalize_cython(void)
/* "GPy/kern/_src/coregionalize_cython.pyx":24 /* "GPy/kern/_src/coregionalize_cython.pyx":24
* return K * return K
* *
* def gradient_reduce(int D, np.ndarray[double, ndim=2] dL_dK, np.ndarray[int, ndim=1] index, np.ndarray[int, ndim=1] index2): # <<<<<<<<<<<<<< * def gradient_reduce(int D, np.ndarray[double, ndim=2] dL_dK, np.ndarray[np.int64_t, ndim=1] index, np.ndarray[np.int64_t, ndim=1] index2): # <<<<<<<<<<<<<<
* cdef np.ndarray[np.double_t, ndim=2] dL_dK_small = np.zeros((D, D)) * cdef np.ndarray[np.double_t, ndim=2] dL_dK_small = np.zeros((D, D))
* cdef int N = index.size * cdef int N = index.size
*/ */

View file

@ -4,7 +4,7 @@ import cython
import numpy as np import numpy as np
cimport numpy as np cimport numpy as np
def K_symmetric(np.ndarray[double, ndim=2] B, np.ndarray[int, ndim=1] X): def K_symmetric(np.ndarray[double, ndim=2] B, np.ndarray[np.int64_t, ndim=1] X):
cdef int N = X.size cdef int N = X.size
cdef np.ndarray[np.double_t, ndim=2] K = np.empty((N, N)) cdef np.ndarray[np.double_t, ndim=2] K = np.empty((N, N))
for n in range(N): for n in range(N):
@ -12,7 +12,7 @@ def K_symmetric(np.ndarray[double, ndim=2] B, np.ndarray[int, ndim=1] X):
K[n,m] = B[X[n],X[m]] K[n,m] = B[X[n],X[m]]
return K return K
def K_asymmetric(np.ndarray[double, ndim=2] B, np.ndarray[int, ndim=1] X, np.ndarray[int, ndim=1] X2): def K_asymmetric(np.ndarray[double, ndim=2] B, np.ndarray[np.int64_t, ndim=1] X, np.ndarray[np.int64_t, ndim=1] X2):
cdef int N = X.size cdef int N = X.size
cdef int M = X2.size cdef int M = X2.size
cdef np.ndarray[np.double_t, ndim=2] K = np.empty((N, M)) cdef np.ndarray[np.double_t, ndim=2] K = np.empty((N, M))
@ -21,7 +21,7 @@ def K_asymmetric(np.ndarray[double, ndim=2] B, np.ndarray[int, ndim=1] X, np.nda
K[n,m] = B[X[n],X2[m]] K[n,m] = B[X[n],X2[m]]
return K return K
def gradient_reduce(int D, np.ndarray[double, ndim=2] dL_dK, np.ndarray[int, ndim=1] index, np.ndarray[int, ndim=1] index2): def gradient_reduce(int D, np.ndarray[double, ndim=2] dL_dK, np.ndarray[np.int64_t, ndim=1] index, np.ndarray[np.int64_t, ndim=1] index2):
cdef np.ndarray[np.double_t, ndim=2] dL_dK_small = np.zeros((D, D)) cdef np.ndarray[np.double_t, ndim=2] dL_dK_small = np.zeros((D, D))
cdef int N = index.size cdef int N = index.size
cdef int M = index2.size cdef int M = index2.size

View file

@ -186,9 +186,8 @@ class Stationary(Kern):
def _lengthscale_grads_cython(self, tmp, X, X2): def _lengthscale_grads_cython(self, tmp, X, X2):
N,M = tmp.shape N,M = tmp.shape
Q = X.shape[1] Q = self.input_dim
if hasattr(X, 'values'):X = X.values X, X2 = np.ascontiguousarray(X), np.ascontiguousarray(X2)
if hasattr(X2, 'values'):X2 = X2.values
grads = np.zeros(self.input_dim) grads = np.zeros(self.input_dim)
stationary_cython.lengthscale_grads(N, M, Q, tmp, X, X2, grads) stationary_cython.lengthscale_grads(N, M, Q, tmp, X, X2, grads)
return -grads/self.lengthscale**3 return -grads/self.lengthscale**3

View file

@ -828,14 +828,24 @@ static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info);
static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb);
static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb);
#define __Pyx_BufPtrStrided2d(type, buf, i0, s0, i1, s1) (type)((char*)buf + i0 * s0 + i1 * s1)
#define __Pyx_BufPtrStrided1d(type, buf, i0, s0) (type)((char*)buf + i0 * s0)
#if CYTHON_COMPILING_IN_CPYTHON #if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw); static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw);
#else #else
#define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw) #define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw)
#endif #endif
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg);
#endif
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg);
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func);
#else
#define __Pyx_PyObject_CallNoArg(func) __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL)
#endif
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause);
static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected); static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected);
@ -1051,7 +1061,7 @@ static PyObject *__pyx_builtin_ValueError;
static PyObject *__pyx_builtin_RuntimeError; static PyObject *__pyx_builtin_RuntimeError;
static PyObject *__pyx_pf_3GPy_4kern_4_src_17stationary_cython_grad_X(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_N, int __pyx_v_D, int __pyx_v_M, PyArrayObject *__pyx_v__X, PyArrayObject *__pyx_v__X2, PyArrayObject *__pyx_v__tmp, PyArrayObject *__pyx_v__grad); /* proto */ static PyObject *__pyx_pf_3GPy_4kern_4_src_17stationary_cython_grad_X(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_N, int __pyx_v_D, int __pyx_v_M, PyArrayObject *__pyx_v__X, PyArrayObject *__pyx_v__X2, PyArrayObject *__pyx_v__tmp, PyArrayObject *__pyx_v__grad); /* proto */
static PyObject *__pyx_pf_3GPy_4kern_4_src_17stationary_cython_2lengthscale_grads_c(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_N, int __pyx_v_M, int __pyx_v_Q, PyArrayObject *__pyx_v__tmp, PyArrayObject *__pyx_v__X, PyArrayObject *__pyx_v__X2, PyArrayObject *__pyx_v__grad); /* proto */ static PyObject *__pyx_pf_3GPy_4kern_4_src_17stationary_cython_2lengthscale_grads_c(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_N, int __pyx_v_M, int __pyx_v_Q, PyArrayObject *__pyx_v__tmp, PyArrayObject *__pyx_v__X, PyArrayObject *__pyx_v__X2, PyArrayObject *__pyx_v__grad); /* proto */
static PyObject *__pyx_pf_3GPy_4kern_4_src_17stationary_cython_4lengthscale_grads(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_N, int __pyx_v_M, int __pyx_v_Q, PyArrayObject *__pyx_v_tmp, PyArrayObject *__pyx_v_X, PyArrayObject *__pyx_v_X2, PyArrayObject *__pyx_v_grad); /* proto */ static PyObject *__pyx_pf_3GPy_4kern_4_src_17stationary_cython_4lengthscale_grads(CYTHON_UNUSED PyObject *__pyx_self, CYTHON_UNUSED int __pyx_v_N, CYTHON_UNUSED int __pyx_v_M, int __pyx_v_Q, PyArrayObject *__pyx_v_tmp, PyArrayObject *__pyx_v_X, PyArrayObject *__pyx_v_X2, PyArrayObject *__pyx_v_grad); /* proto */
static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /* proto */ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /* proto */
static void __pyx_pf_5numpy_7ndarray_2__releasebuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info); /* proto */ static void __pyx_pf_5numpy_7ndarray_2__releasebuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info); /* proto */
static char __pyx_k_B[] = "B"; static char __pyx_k_B[] = "B";
@ -1063,6 +1073,7 @@ static char __pyx_k_M[] = "M";
static char __pyx_k_N[] = "N"; static char __pyx_k_N[] = "N";
static char __pyx_k_O[] = "O"; static char __pyx_k_O[] = "O";
static char __pyx_k_Q[] = "Q"; static char __pyx_k_Q[] = "Q";
static char __pyx_k_T[] = "T";
static char __pyx_k_X[] = "_X"; static char __pyx_k_X[] = "_X";
static char __pyx_k_b[] = "b"; static char __pyx_k_b[] = "b";
static char __pyx_k_d[] = "d"; static char __pyx_k_d[] = "d";
@ -1070,7 +1081,6 @@ static char __pyx_k_f[] = "f";
static char __pyx_k_g[] = "g"; static char __pyx_k_g[] = "g";
static char __pyx_k_h[] = "h"; static char __pyx_k_h[] = "h";
static char __pyx_k_i[] = "i"; static char __pyx_k_i[] = "i";
static char __pyx_k_j[] = "j";
static char __pyx_k_l[] = "l"; static char __pyx_k_l[] = "l";
static char __pyx_k_q[] = "q"; static char __pyx_k_q[] = "q";
static char __pyx_k_X2[] = "_X2"; static char __pyx_k_X2[] = "_X2";
@ -1079,6 +1089,7 @@ static char __pyx_k_Zf[] = "Zf";
static char __pyx_k_Zg[] = "Zg"; static char __pyx_k_Zg[] = "Zg";
static char __pyx_k_np[] = "np"; static char __pyx_k_np[] = "np";
static char __pyx_k_X_2[] = "X"; static char __pyx_k_X_2[] = "X";
static char __pyx_k_sum[] = "sum";
static char __pyx_k_tmp[] = "_tmp"; static char __pyx_k_tmp[] = "_tmp";
static char __pyx_k_X2_2[] = "X2"; static char __pyx_k_X2_2[] = "X2";
static char __pyx_k_grad[] = "_grad"; static char __pyx_k_grad[] = "_grad";
@ -1095,8 +1106,8 @@ static char __pyx_k_RuntimeError[] = "RuntimeError";
static char __pyx_k_lengthscale_grads[] = "lengthscale_grads"; static char __pyx_k_lengthscale_grads[] = "lengthscale_grads";
static char __pyx_k_lengthscale_grads_c[] = "lengthscale_grads_c"; static char __pyx_k_lengthscale_grads_c[] = "lengthscale_grads_c";
static char __pyx_k_ndarray_is_not_C_contiguous[] = "ndarray is not C contiguous"; static char __pyx_k_ndarray_is_not_C_contiguous[] = "ndarray is not C contiguous";
static char __pyx_k_Users_james_work_GPy_GPy_kern[] = "/Users/james/work/GPy/GPy/kern/_src/stationary_cython.pyx";
static char __pyx_k_GPy_kern__src_stationary_cython[] = "GPy.kern._src.stationary_cython"; static char __pyx_k_GPy_kern__src_stationary_cython[] = "GPy.kern._src.stationary_cython";
static char __pyx_k_home_james_work_GPy_GPy_kern__s[] = "/home/james/work/GPy/GPy/kern/_src/stationary_cython.pyx";
static char __pyx_k_unknown_dtype_code_in_numpy_pxd[] = "unknown dtype code in numpy.pxd (%d)"; static char __pyx_k_unknown_dtype_code_in_numpy_pxd[] = "unknown dtype code in numpy.pxd (%d)";
static char __pyx_k_Format_string_allocated_too_shor[] = "Format string allocated too short, see comment in numpy.pxd"; static char __pyx_k_Format_string_allocated_too_shor[] = "Format string allocated too short, see comment in numpy.pxd";
static char __pyx_k_Non_native_byte_order_not_suppor[] = "Non-native byte order not supported"; static char __pyx_k_Non_native_byte_order_not_suppor[] = "Non-native byte order not supported";
@ -1111,7 +1122,7 @@ static PyObject *__pyx_n_s_N;
static PyObject *__pyx_kp_u_Non_native_byte_order_not_suppor; static PyObject *__pyx_kp_u_Non_native_byte_order_not_suppor;
static PyObject *__pyx_n_s_Q; static PyObject *__pyx_n_s_Q;
static PyObject *__pyx_n_s_RuntimeError; static PyObject *__pyx_n_s_RuntimeError;
static PyObject *__pyx_kp_s_Users_james_work_GPy_GPy_kern; static PyObject *__pyx_n_s_T;
static PyObject *__pyx_n_s_ValueError; static PyObject *__pyx_n_s_ValueError;
static PyObject *__pyx_n_s_X; static PyObject *__pyx_n_s_X;
static PyObject *__pyx_n_s_X2; static PyObject *__pyx_n_s_X2;
@ -1120,9 +1131,8 @@ static PyObject *__pyx_n_s_X_2;
static PyObject *__pyx_n_s_grad; static PyObject *__pyx_n_s_grad;
static PyObject *__pyx_n_s_grad_2; static PyObject *__pyx_n_s_grad_2;
static PyObject *__pyx_n_s_grad_X; static PyObject *__pyx_n_s_grad_X;
static PyObject *__pyx_n_s_i; static PyObject *__pyx_kp_s_home_james_work_GPy_GPy_kern__s;
static PyObject *__pyx_n_s_import; static PyObject *__pyx_n_s_import;
static PyObject *__pyx_n_s_j;
static PyObject *__pyx_n_s_lengthscale_grads; static PyObject *__pyx_n_s_lengthscale_grads;
static PyObject *__pyx_n_s_lengthscale_grads_c; static PyObject *__pyx_n_s_lengthscale_grads_c;
static PyObject *__pyx_n_s_main; static PyObject *__pyx_n_s_main;
@ -1132,22 +1142,27 @@ static PyObject *__pyx_n_s_np;
static PyObject *__pyx_n_s_numpy; static PyObject *__pyx_n_s_numpy;
static PyObject *__pyx_n_s_q; static PyObject *__pyx_n_s_q;
static PyObject *__pyx_n_s_range; static PyObject *__pyx_n_s_range;
static PyObject *__pyx_n_s_sum;
static PyObject *__pyx_n_s_test; static PyObject *__pyx_n_s_test;
static PyObject *__pyx_n_s_tmp; static PyObject *__pyx_n_s_tmp;
static PyObject *__pyx_n_s_tmp_2; static PyObject *__pyx_n_s_tmp_2;
static PyObject *__pyx_kp_u_unknown_dtype_code_in_numpy_pxd; static PyObject *__pyx_kp_u_unknown_dtype_code_in_numpy_pxd;
static PyObject *__pyx_tuple_; static PyObject *__pyx_int_1;
static PyObject *__pyx_tuple__2; static PyObject *__pyx_int_2;
static PyObject *__pyx_slice_;
static PyObject *__pyx_slice__2;
static PyObject *__pyx_tuple__3; static PyObject *__pyx_tuple__3;
static PyObject *__pyx_tuple__4; static PyObject *__pyx_tuple__4;
static PyObject *__pyx_tuple__5; static PyObject *__pyx_tuple__5;
static PyObject *__pyx_tuple__6; static PyObject *__pyx_tuple__6;
static PyObject *__pyx_tuple__7; static PyObject *__pyx_tuple__7;
static PyObject *__pyx_tuple__8;
static PyObject *__pyx_tuple__9; static PyObject *__pyx_tuple__9;
static PyObject *__pyx_tuple__11; static PyObject *__pyx_tuple__11;
static PyObject *__pyx_codeobj__8; static PyObject *__pyx_tuple__13;
static PyObject *__pyx_codeobj__10; static PyObject *__pyx_codeobj__10;
static PyObject *__pyx_codeobj__12; static PyObject *__pyx_codeobj__12;
static PyObject *__pyx_codeobj__14;
/* "GPy/kern/_src/stationary_cython.pyx":14 /* "GPy/kern/_src/stationary_cython.pyx":14
* void _lengthscale_grads "_lengthscale_grads" (int N, int M, int Q, double* tmp, double* X, double* X2, double* grad) * void _lengthscale_grads "_lengthscale_grads" (int N, int M, int Q, double* tmp, double* X, double* X2, double* grad)
@ -1675,8 +1690,8 @@ static PyObject *__pyx_pf_3GPy_4kern_4_src_17stationary_cython_2lengthscale_grad
static PyObject *__pyx_pw_3GPy_4kern_4_src_17stationary_cython_5lengthscale_grads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyObject *__pyx_pw_3GPy_4kern_4_src_17stationary_cython_5lengthscale_grads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_3GPy_4kern_4_src_17stationary_cython_5lengthscale_grads = {"lengthscale_grads", (PyCFunction)__pyx_pw_3GPy_4kern_4_src_17stationary_cython_5lengthscale_grads, METH_VARARGS|METH_KEYWORDS, 0}; static PyMethodDef __pyx_mdef_3GPy_4kern_4_src_17stationary_cython_5lengthscale_grads = {"lengthscale_grads", (PyCFunction)__pyx_pw_3GPy_4kern_4_src_17stationary_cython_5lengthscale_grads, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_3GPy_4kern_4_src_17stationary_cython_5lengthscale_grads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { static PyObject *__pyx_pw_3GPy_4kern_4_src_17stationary_cython_5lengthscale_grads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
int __pyx_v_N; CYTHON_UNUSED int __pyx_v_N;
int __pyx_v_M; CYTHON_UNUSED int __pyx_v_M;
int __pyx_v_Q; int __pyx_v_Q;
PyArrayObject *__pyx_v_tmp = 0; PyArrayObject *__pyx_v_tmp = 0;
PyArrayObject *__pyx_v_X = 0; PyArrayObject *__pyx_v_X = 0;
@ -1786,10 +1801,8 @@ static PyObject *__pyx_pw_3GPy_4kern_4_src_17stationary_cython_5lengthscale_grad
return __pyx_r; return __pyx_r;
} }
static PyObject *__pyx_pf_3GPy_4kern_4_src_17stationary_cython_4lengthscale_grads(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_N, int __pyx_v_M, int __pyx_v_Q, PyArrayObject *__pyx_v_tmp, PyArrayObject *__pyx_v_X, PyArrayObject *__pyx_v_X2, PyArrayObject *__pyx_v_grad) { static PyObject *__pyx_pf_3GPy_4kern_4_src_17stationary_cython_4lengthscale_grads(CYTHON_UNUSED PyObject *__pyx_self, CYTHON_UNUSED int __pyx_v_N, CYTHON_UNUSED int __pyx_v_M, int __pyx_v_Q, PyArrayObject *__pyx_v_tmp, PyArrayObject *__pyx_v_X, PyArrayObject *__pyx_v_X2, PyArrayObject *__pyx_v_grad) {
int __pyx_v_q; PyObject *__pyx_v_q = NULL;
int __pyx_v_i;
int __pyx_v_j;
__Pyx_LocalBuf_ND __pyx_pybuffernd_X; __Pyx_LocalBuf_ND __pyx_pybuffernd_X;
__Pyx_Buffer __pyx_pybuffer_X; __Pyx_Buffer __pyx_pybuffer_X;
__Pyx_LocalBuf_ND __pyx_pybuffernd_X2; __Pyx_LocalBuf_ND __pyx_pybuffernd_X2;
@ -1800,19 +1813,13 @@ static PyObject *__pyx_pf_3GPy_4kern_4_src_17stationary_cython_4lengthscale_grad
__Pyx_Buffer __pyx_pybuffer_tmp; __Pyx_Buffer __pyx_pybuffer_tmp;
PyObject *__pyx_r = NULL; PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations __Pyx_RefNannyDeclarations
int __pyx_t_1; PyObject *__pyx_t_1 = NULL;
int __pyx_t_2; PyObject *__pyx_t_2 = NULL;
int __pyx_t_3; Py_ssize_t __pyx_t_3;
int __pyx_t_4; PyObject *(*__pyx_t_4)(PyObject *);
int __pyx_t_5; PyObject *__pyx_t_5 = NULL;
int __pyx_t_6; PyObject *__pyx_t_6 = NULL;
int __pyx_t_7; PyObject *__pyx_t_7 = NULL;
int __pyx_t_8;
int __pyx_t_9;
int __pyx_t_10;
int __pyx_t_11;
int __pyx_t_12;
int __pyx_t_13;
int __pyx_lineno = 0; int __pyx_lineno = 0;
const char *__pyx_filename = NULL; const char *__pyx_filename = NULL;
int __pyx_clineno = 0; int __pyx_clineno = 0;
@ -1850,7 +1857,7 @@ static PyObject *__pyx_pf_3GPy_4kern_4_src_17stationary_cython_4lengthscale_grad
__pyx_pybuffernd_X2.diminfo[0].strides = __pyx_pybuffernd_X2.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_X2.diminfo[0].shape = __pyx_pybuffernd_X2.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_X2.diminfo[1].strides = __pyx_pybuffernd_X2.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_X2.diminfo[1].shape = __pyx_pybuffernd_X2.rcbuffer->pybuffer.shape[1]; __pyx_pybuffernd_X2.diminfo[0].strides = __pyx_pybuffernd_X2.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_X2.diminfo[0].shape = __pyx_pybuffernd_X2.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_X2.diminfo[1].strides = __pyx_pybuffernd_X2.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_X2.diminfo[1].shape = __pyx_pybuffernd_X2.rcbuffer->pybuffer.shape[1];
{ {
__Pyx_BufFmt_StackElem __pyx_stack[1]; __Pyx_BufFmt_StackElem __pyx_stack[1];
if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_grad.rcbuffer->pybuffer, (PyObject*)__pyx_v_grad, &__Pyx_TypeInfo_nn___pyx_t_3GPy_4kern_4_src_17stationary_cython_DTYPE_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_grad.rcbuffer->pybuffer, (PyObject*)__pyx_v_grad, &__Pyx_TypeInfo_nn___pyx_t_3GPy_4kern_4_src_17stationary_cython_DTYPE_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
} }
__pyx_pybuffernd_grad.diminfo[0].strides = __pyx_pybuffernd_grad.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_grad.diminfo[0].shape = __pyx_pybuffernd_grad.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_grad.diminfo[0].strides = __pyx_pybuffernd_grad.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_grad.diminfo[0].shape = __pyx_pybuffernd_grad.rcbuffer->pybuffer.shape[0];
@ -1858,52 +1865,145 @@ static PyObject *__pyx_pf_3GPy_4kern_4_src_17stationary_cython_4lengthscale_grad
* np.ndarray[DTYPE_t, ndim=2] X2, * np.ndarray[DTYPE_t, ndim=2] X2,
* np.ndarray[DTYPE_t, ndim=1] grad): * np.ndarray[DTYPE_t, ndim=1] grad):
* for q in range(Q): # <<<<<<<<<<<<<< * for q in range(Q): # <<<<<<<<<<<<<<
* for i in range(N): * grad[q] = (tmp*(X[:,q:q+1]-X2[:,q:q+1].T)**2).sum()
* for j in range(M): * #for i in range(N):
*/ */
__pyx_t_1 = __pyx_v_Q; __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_Q); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { __Pyx_GOTREF(__pyx_t_1);
__pyx_v_q = __pyx_t_2; __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
__Pyx_GIVEREF(__pyx_t_1);
__pyx_t_1 = 0;
__pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_range, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
__pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0;
__pyx_t_4 = NULL;
} else {
__pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
for (;;) {
if (likely(!__pyx_t_4)) {
if (likely(PyList_CheckExact(__pyx_t_2))) {
if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break;
#if CYTHON_COMPILING_IN_CPYTHON
__pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
#else
__pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
#endif
} else {
if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
#if CYTHON_COMPILING_IN_CPYTHON
__pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
#else
__pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
#endif
}
} else {
__pyx_t_1 = __pyx_t_4(__pyx_t_2);
if (unlikely(!__pyx_t_1)) {
PyObject* exc_type = PyErr_Occurred();
if (exc_type) {
if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
break;
}
__Pyx_GOTREF(__pyx_t_1);
}
__Pyx_XDECREF_SET(__pyx_v_q, __pyx_t_1);
__pyx_t_1 = 0;
/* "GPy/kern/_src/stationary_cython.pyx":42 /* "GPy/kern/_src/stationary_cython.pyx":42
* np.ndarray[DTYPE_t, ndim=1] grad): * np.ndarray[DTYPE_t, ndim=1] grad):
* for q in range(Q): * for q in range(Q):
* for i in range(N): # <<<<<<<<<<<<<< * grad[q] = (tmp*(X[:,q:q+1]-X2[:,q:q+1].T)**2).sum() # <<<<<<<<<<<<<<
* for j in range(M): * #for i in range(N):
* grad[q] += tmp[i,j]*(X[i,q]-X2[j,q])**2 * #for j in range(M):
*/ */
__pyx_t_3 = __pyx_v_N; __pyx_t_5 = PyNumber_Add(__pyx_v_q, __pyx_int_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { __Pyx_GOTREF(__pyx_t_5);
__pyx_v_i = __pyx_t_4; __pyx_t_6 = PySlice_New(__pyx_v_q, __pyx_t_5, Py_None); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_6);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__Pyx_INCREF(__pyx_slice_);
PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_slice_);
__Pyx_GIVEREF(__pyx_slice_);
PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_6);
__Pyx_GIVEREF(__pyx_t_6);
__pyx_t_6 = 0;
__pyx_t_6 = PyObject_GetItem(((PyObject *)__pyx_v_X), __pyx_t_5); if (unlikely(__pyx_t_6 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
__Pyx_GOTREF(__pyx_t_6);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__pyx_t_5 = PyNumber_Add(__pyx_v_q, __pyx_int_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__pyx_t_7 = PySlice_New(__pyx_v_q, __pyx_t_5, Py_None); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_7);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__Pyx_INCREF(__pyx_slice__2);
PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_slice__2);
__Pyx_GIVEREF(__pyx_slice__2);
PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_7);
__Pyx_GIVEREF(__pyx_t_7);
__pyx_t_7 = 0;
__pyx_t_7 = PyObject_GetItem(((PyObject *)__pyx_v_X2), __pyx_t_5); if (unlikely(__pyx_t_7 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
__Pyx_GOTREF(__pyx_t_7);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_T); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
__pyx_t_7 = PyNumber_Subtract(__pyx_t_6, __pyx_t_5); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_7);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__pyx_t_5 = PyNumber_Power(__pyx_t_7, __pyx_int_2, Py_None); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
__pyx_t_7 = PyNumber_Multiply(((PyObject *)__pyx_v_tmp), __pyx_t_5); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_7);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_sum); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
__pyx_t_7 = NULL;
if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_5))) {
__pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5);
if (likely(__pyx_t_7)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
__Pyx_INCREF(__pyx_t_7);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_5, function);
}
}
if (__pyx_t_7) {
__pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_7); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
} else {
__pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_5); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_grad), __pyx_v_q, __pyx_t_1) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
/* "GPy/kern/_src/stationary_cython.pyx":43 /* "GPy/kern/_src/stationary_cython.pyx":41
* for q in range(Q): * np.ndarray[DTYPE_t, ndim=2] X2,
* for i in range(N): * np.ndarray[DTYPE_t, ndim=1] grad):
* for j in range(M): # <<<<<<<<<<<<<< * for q in range(Q): # <<<<<<<<<<<<<<
* grad[q] += tmp[i,j]*(X[i,q]-X2[j,q])**2 * grad[q] = (tmp*(X[:,q:q+1]-X2[:,q:q+1].T)**2).sum()
* * #for i in range(N):
*/ */
__pyx_t_5 = __pyx_v_M;
for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) {
__pyx_v_j = __pyx_t_6;
/* "GPy/kern/_src/stationary_cython.pyx":44
* for i in range(N):
* for j in range(M):
* grad[q] += tmp[i,j]*(X[i,q]-X2[j,q])**2 # <<<<<<<<<<<<<<
*
*/
__pyx_t_7 = __pyx_v_i;
__pyx_t_8 = __pyx_v_j;
__pyx_t_9 = __pyx_v_i;
__pyx_t_10 = __pyx_v_q;
__pyx_t_11 = __pyx_v_j;
__pyx_t_12 = __pyx_v_q;
__pyx_t_13 = __pyx_v_q;
*__Pyx_BufPtrStrided1d(__pyx_t_3GPy_4kern_4_src_17stationary_cython_DTYPE_t *, __pyx_pybuffernd_grad.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_grad.diminfo[0].strides) += ((*__Pyx_BufPtrStrided2d(__pyx_t_3GPy_4kern_4_src_17stationary_cython_DTYPE_t *, __pyx_pybuffernd_tmp.rcbuffer->pybuffer.buf, __pyx_t_7, __pyx_pybuffernd_tmp.diminfo[0].strides, __pyx_t_8, __pyx_pybuffernd_tmp.diminfo[1].strides)) * pow(((*__Pyx_BufPtrStrided2d(__pyx_t_3GPy_4kern_4_src_17stationary_cython_DTYPE_t *, __pyx_pybuffernd_X.rcbuffer->pybuffer.buf, __pyx_t_9, __pyx_pybuffernd_X.diminfo[0].strides, __pyx_t_10, __pyx_pybuffernd_X.diminfo[1].strides)) - (*__Pyx_BufPtrStrided2d(__pyx_t_3GPy_4kern_4_src_17stationary_cython_DTYPE_t *, __pyx_pybuffernd_X2.rcbuffer->pybuffer.buf, __pyx_t_11, __pyx_pybuffernd_X2.diminfo[0].strides, __pyx_t_12, __pyx_pybuffernd_X2.diminfo[1].strides))), 2.0));
}
}
} }
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
/* "GPy/kern/_src/stationary_cython.pyx":36 /* "GPy/kern/_src/stationary_cython.pyx":36
* _lengthscale_grads(N, M, Q, tmp, X, X2, grad) # return nothing, work in place. * _lengthscale_grads(N, M, Q, tmp, X, X2, grad) # return nothing, work in place.
@ -1917,6 +2017,11 @@ static PyObject *__pyx_pf_3GPy_4kern_4_src_17stationary_cython_4lengthscale_grad
__pyx_r = Py_None; __Pyx_INCREF(Py_None); __pyx_r = Py_None; __Pyx_INCREF(Py_None);
goto __pyx_L0; goto __pyx_L0;
__pyx_L1_error:; __pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_XDECREF(__pyx_t_6);
__Pyx_XDECREF(__pyx_t_7);
{ PyObject *__pyx_type, *__pyx_value, *__pyx_tb; { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
__Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_X.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_X.rcbuffer->pybuffer);
@ -1933,6 +2038,7 @@ static PyObject *__pyx_pf_3GPy_4kern_4_src_17stationary_cython_4lengthscale_grad
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_grad.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_grad.rcbuffer->pybuffer);
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_tmp.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_tmp.rcbuffer->pybuffer);
__pyx_L2:; __pyx_L2:;
__Pyx_XDECREF(__pyx_v_q);
__Pyx_XGIVEREF(__pyx_r); __Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext(); __Pyx_RefNannyFinishContext();
return __pyx_r; return __pyx_r;
@ -2096,7 +2202,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P
* *
* if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS) * if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
*/ */
__pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3); __Pyx_GOTREF(__pyx_t_3);
__Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_Raise(__pyx_t_3, 0, 0, 0);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
@ -2138,7 +2244,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P
* *
* info.buf = PyArray_DATA(self) * info.buf = PyArray_DATA(self)
*/ */
__pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3); __Pyx_GOTREF(__pyx_t_3);
__Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_Raise(__pyx_t_3, 0, 0, 0);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
@ -2422,7 +2528,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P
* if t == NPY_BYTE: f = "b" * if t == NPY_BYTE: f = "b"
* elif t == NPY_UBYTE: f = "B" * elif t == NPY_UBYTE: f = "B"
*/ */
__pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3); __Pyx_GOTREF(__pyx_t_3);
__Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_Raise(__pyx_t_3, 0, 0, 0);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
@ -3230,7 +3336,7 @@ static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx
* *
* if ((child.byteorder == c'>' and little_endian) or * if ((child.byteorder == c'>' and little_endian) or
*/ */
__pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_RuntimeError, __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_RuntimeError, __pyx_tuple__6, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3); __Pyx_GOTREF(__pyx_t_3);
__Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_Raise(__pyx_t_3, 0, 0, 0);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
@ -3287,7 +3393,7 @@ static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx
* # One could encode it in the format string and have Cython * # One could encode it in the format string and have Cython
* # complain instead, BUT: < and > in format strings also imply * # complain instead, BUT: < and > in format strings also imply
*/ */
__pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__7, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3); __Pyx_GOTREF(__pyx_t_3);
__Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_Raise(__pyx_t_3, 0, 0, 0);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
@ -3388,7 +3494,7 @@ static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx
* *
* # Until ticket #99 is fixed, use integers to avoid warnings * # Until ticket #99 is fixed, use integers to avoid warnings
*/ */
__pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_RuntimeError, __pyx_tuple__6, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 823; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_RuntimeError, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 823; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4); __Pyx_GOTREF(__pyx_t_4);
__Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_Raise(__pyx_t_4, 0, 0, 0);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
@ -3984,7 +4090,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
{&__pyx_kp_u_Non_native_byte_order_not_suppor, __pyx_k_Non_native_byte_order_not_suppor, sizeof(__pyx_k_Non_native_byte_order_not_suppor), 0, 1, 0, 0}, {&__pyx_kp_u_Non_native_byte_order_not_suppor, __pyx_k_Non_native_byte_order_not_suppor, sizeof(__pyx_k_Non_native_byte_order_not_suppor), 0, 1, 0, 0},
{&__pyx_n_s_Q, __pyx_k_Q, sizeof(__pyx_k_Q), 0, 0, 1, 1}, {&__pyx_n_s_Q, __pyx_k_Q, sizeof(__pyx_k_Q), 0, 0, 1, 1},
{&__pyx_n_s_RuntimeError, __pyx_k_RuntimeError, sizeof(__pyx_k_RuntimeError), 0, 0, 1, 1}, {&__pyx_n_s_RuntimeError, __pyx_k_RuntimeError, sizeof(__pyx_k_RuntimeError), 0, 0, 1, 1},
{&__pyx_kp_s_Users_james_work_GPy_GPy_kern, __pyx_k_Users_james_work_GPy_GPy_kern, sizeof(__pyx_k_Users_james_work_GPy_GPy_kern), 0, 0, 1, 0}, {&__pyx_n_s_T, __pyx_k_T, sizeof(__pyx_k_T), 0, 0, 1, 1},
{&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1}, {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1},
{&__pyx_n_s_X, __pyx_k_X, sizeof(__pyx_k_X), 0, 0, 1, 1}, {&__pyx_n_s_X, __pyx_k_X, sizeof(__pyx_k_X), 0, 0, 1, 1},
{&__pyx_n_s_X2, __pyx_k_X2, sizeof(__pyx_k_X2), 0, 0, 1, 1}, {&__pyx_n_s_X2, __pyx_k_X2, sizeof(__pyx_k_X2), 0, 0, 1, 1},
@ -3993,9 +4099,8 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
{&__pyx_n_s_grad, __pyx_k_grad, sizeof(__pyx_k_grad), 0, 0, 1, 1}, {&__pyx_n_s_grad, __pyx_k_grad, sizeof(__pyx_k_grad), 0, 0, 1, 1},
{&__pyx_n_s_grad_2, __pyx_k_grad_2, sizeof(__pyx_k_grad_2), 0, 0, 1, 1}, {&__pyx_n_s_grad_2, __pyx_k_grad_2, sizeof(__pyx_k_grad_2), 0, 0, 1, 1},
{&__pyx_n_s_grad_X, __pyx_k_grad_X, sizeof(__pyx_k_grad_X), 0, 0, 1, 1}, {&__pyx_n_s_grad_X, __pyx_k_grad_X, sizeof(__pyx_k_grad_X), 0, 0, 1, 1},
{&__pyx_n_s_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 0, 1, 1}, {&__pyx_kp_s_home_james_work_GPy_GPy_kern__s, __pyx_k_home_james_work_GPy_GPy_kern__s, sizeof(__pyx_k_home_james_work_GPy_GPy_kern__s), 0, 0, 1, 0},
{&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1}, {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1},
{&__pyx_n_s_j, __pyx_k_j, sizeof(__pyx_k_j), 0, 0, 1, 1},
{&__pyx_n_s_lengthscale_grads, __pyx_k_lengthscale_grads, sizeof(__pyx_k_lengthscale_grads), 0, 0, 1, 1}, {&__pyx_n_s_lengthscale_grads, __pyx_k_lengthscale_grads, sizeof(__pyx_k_lengthscale_grads), 0, 0, 1, 1},
{&__pyx_n_s_lengthscale_grads_c, __pyx_k_lengthscale_grads_c, sizeof(__pyx_k_lengthscale_grads_c), 0, 0, 1, 1}, {&__pyx_n_s_lengthscale_grads_c, __pyx_k_lengthscale_grads_c, sizeof(__pyx_k_lengthscale_grads_c), 0, 0, 1, 1},
{&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1}, {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
@ -4005,6 +4110,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
{&__pyx_n_s_numpy, __pyx_k_numpy, sizeof(__pyx_k_numpy), 0, 0, 1, 1}, {&__pyx_n_s_numpy, __pyx_k_numpy, sizeof(__pyx_k_numpy), 0, 0, 1, 1},
{&__pyx_n_s_q, __pyx_k_q, sizeof(__pyx_k_q), 0, 0, 1, 1}, {&__pyx_n_s_q, __pyx_k_q, sizeof(__pyx_k_q), 0, 0, 1, 1},
{&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1}, {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1},
{&__pyx_n_s_sum, __pyx_k_sum, sizeof(__pyx_k_sum), 0, 0, 1, 1},
{&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1}, {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
{&__pyx_n_s_tmp, __pyx_k_tmp, sizeof(__pyx_k_tmp), 0, 0, 1, 1}, {&__pyx_n_s_tmp, __pyx_k_tmp, sizeof(__pyx_k_tmp), 0, 0, 1, 1},
{&__pyx_n_s_tmp_2, __pyx_k_tmp_2, sizeof(__pyx_k_tmp_2), 0, 0, 1, 1}, {&__pyx_n_s_tmp_2, __pyx_k_tmp_2, sizeof(__pyx_k_tmp_2), 0, 0, 1, 1},
@ -4024,6 +4130,20 @@ static int __Pyx_InitCachedConstants(void) {
__Pyx_RefNannyDeclarations __Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);
/* "GPy/kern/_src/stationary_cython.pyx":42
* np.ndarray[DTYPE_t, ndim=1] grad):
* for q in range(Q):
* grad[q] = (tmp*(X[:,q:q+1]-X2[:,q:q+1].T)**2).sum() # <<<<<<<<<<<<<<
* #for i in range(N):
* #for j in range(M):
*/
__pyx_slice_ = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice_)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_slice_);
__Pyx_GIVEREF(__pyx_slice_);
__pyx_slice__2 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_slice__2);
__Pyx_GIVEREF(__pyx_slice__2);
/* "../../../../../anaconda/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":215 /* "../../../../../anaconda/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":215
* if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS) * if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)
* and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)): * and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)):
@ -4031,9 +4151,9 @@ static int __Pyx_InitCachedConstants(void) {
* *
* if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS) * if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
*/ */
__pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_u_ndarray_is_not_C_contiguous); if (unlikely(!__pyx_tuple_)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_tuple__3 = PyTuple_Pack(1, __pyx_kp_u_ndarray_is_not_C_contiguous); if (unlikely(!__pyx_tuple__3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_tuple_); __Pyx_GOTREF(__pyx_tuple__3);
__Pyx_GIVEREF(__pyx_tuple_); __Pyx_GIVEREF(__pyx_tuple__3);
/* "../../../../../anaconda/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":219 /* "../../../../../anaconda/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":219
* if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS) * if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
@ -4042,9 +4162,9 @@ static int __Pyx_InitCachedConstants(void) {
* *
* info.buf = PyArray_DATA(self) * info.buf = PyArray_DATA(self)
*/ */
__pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_u_ndarray_is_not_Fortran_contiguou); if (unlikely(!__pyx_tuple__2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_u_ndarray_is_not_Fortran_contiguou); if (unlikely(!__pyx_tuple__4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_tuple__2); __Pyx_GOTREF(__pyx_tuple__4);
__Pyx_GIVEREF(__pyx_tuple__2); __Pyx_GIVEREF(__pyx_tuple__4);
/* "../../../../../anaconda/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":257 /* "../../../../../anaconda/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":257
* if ((descr.byteorder == c'>' and little_endian) or * if ((descr.byteorder == c'>' and little_endian) or
@ -4053,9 +4173,9 @@ static int __Pyx_InitCachedConstants(void) {
* if t == NPY_BYTE: f = "b" * if t == NPY_BYTE: f = "b"
* elif t == NPY_UBYTE: f = "B" * elif t == NPY_UBYTE: f = "B"
*/ */
__pyx_tuple__3 = PyTuple_Pack(1, __pyx_kp_u_Non_native_byte_order_not_suppor); if (unlikely(!__pyx_tuple__3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_tuple__5 = PyTuple_Pack(1, __pyx_kp_u_Non_native_byte_order_not_suppor); if (unlikely(!__pyx_tuple__5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_tuple__3); __Pyx_GOTREF(__pyx_tuple__5);
__Pyx_GIVEREF(__pyx_tuple__3); __Pyx_GIVEREF(__pyx_tuple__5);
/* "../../../../../anaconda/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":799 /* "../../../../../anaconda/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":799
* *
@ -4064,9 +4184,9 @@ static int __Pyx_InitCachedConstants(void) {
* *
* if ((child.byteorder == c'>' and little_endian) or * if ((child.byteorder == c'>' and little_endian) or
*/ */
__pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_u_Format_string_allocated_too_shor); if (unlikely(!__pyx_tuple__4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_tuple__6 = PyTuple_Pack(1, __pyx_kp_u_Format_string_allocated_too_shor); if (unlikely(!__pyx_tuple__6)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_tuple__4); __Pyx_GOTREF(__pyx_tuple__6);
__Pyx_GIVEREF(__pyx_tuple__4); __Pyx_GIVEREF(__pyx_tuple__6);
/* "../../../../../anaconda/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":803 /* "../../../../../anaconda/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":803
* if ((child.byteorder == c'>' and little_endian) or * if ((child.byteorder == c'>' and little_endian) or
@ -4075,9 +4195,9 @@ static int __Pyx_InitCachedConstants(void) {
* # One could encode it in the format string and have Cython * # One could encode it in the format string and have Cython
* # complain instead, BUT: < and > in format strings also imply * # complain instead, BUT: < and > in format strings also imply
*/ */
__pyx_tuple__5 = PyTuple_Pack(1, __pyx_kp_u_Non_native_byte_order_not_suppor); if (unlikely(!__pyx_tuple__5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_tuple__7 = PyTuple_Pack(1, __pyx_kp_u_Non_native_byte_order_not_suppor); if (unlikely(!__pyx_tuple__7)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_tuple__5); __Pyx_GOTREF(__pyx_tuple__7);
__Pyx_GIVEREF(__pyx_tuple__5); __Pyx_GIVEREF(__pyx_tuple__7);
/* "../../../../../anaconda/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":823 /* "../../../../../anaconda/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":823
* t = child.type_num * t = child.type_num
@ -4086,9 +4206,9 @@ static int __Pyx_InitCachedConstants(void) {
* *
* # Until ticket #99 is fixed, use integers to avoid warnings * # Until ticket #99 is fixed, use integers to avoid warnings
*/ */
__pyx_tuple__6 = PyTuple_Pack(1, __pyx_kp_u_Format_string_allocated_too_shor_2); if (unlikely(!__pyx_tuple__6)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 823; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_tuple__8 = PyTuple_Pack(1, __pyx_kp_u_Format_string_allocated_too_shor_2); if (unlikely(!__pyx_tuple__8)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 823; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_tuple__6); __Pyx_GOTREF(__pyx_tuple__8);
__Pyx_GIVEREF(__pyx_tuple__6); __Pyx_GIVEREF(__pyx_tuple__8);
/* "GPy/kern/_src/stationary_cython.pyx":14 /* "GPy/kern/_src/stationary_cython.pyx":14
* void _lengthscale_grads "_lengthscale_grads" (int N, int M, int Q, double* tmp, double* X, double* X2, double* grad) * void _lengthscale_grads "_lengthscale_grads" (int N, int M, int Q, double* tmp, double* X, double* X2, double* grad)
@ -4097,10 +4217,10 @@ static int __Pyx_InitCachedConstants(void) {
* np.ndarray[DTYPE_t, ndim=2] _X, * np.ndarray[DTYPE_t, ndim=2] _X,
* np.ndarray[DTYPE_t, ndim=2] _X2, * np.ndarray[DTYPE_t, ndim=2] _X2,
*/ */
__pyx_tuple__7 = PyTuple_Pack(11, __pyx_n_s_N, __pyx_n_s_D, __pyx_n_s_M, __pyx_n_s_X, __pyx_n_s_X2, __pyx_n_s_tmp, __pyx_n_s_grad, __pyx_n_s_X_2, __pyx_n_s_X2_2, __pyx_n_s_tmp_2, __pyx_n_s_grad_2); if (unlikely(!__pyx_tuple__7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_tuple__9 = PyTuple_Pack(11, __pyx_n_s_N, __pyx_n_s_D, __pyx_n_s_M, __pyx_n_s_X, __pyx_n_s_X2, __pyx_n_s_tmp, __pyx_n_s_grad, __pyx_n_s_X_2, __pyx_n_s_X2_2, __pyx_n_s_tmp_2, __pyx_n_s_grad_2); if (unlikely(!__pyx_tuple__9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_tuple__7); __Pyx_GOTREF(__pyx_tuple__9);
__Pyx_GIVEREF(__pyx_tuple__7); __Pyx_GIVEREF(__pyx_tuple__9);
__pyx_codeobj__8 = (PyObject*)__Pyx_PyCode_New(7, 0, 11, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__7, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_Users_james_work_GPy_GPy_kern, __pyx_n_s_grad_X, 14, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_codeobj__10 = (PyObject*)__Pyx_PyCode_New(7, 0, 11, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__9, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_james_work_GPy_GPy_kern__s, __pyx_n_s_grad_X, 14, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
/* "GPy/kern/_src/stationary_cython.pyx":25 /* "GPy/kern/_src/stationary_cython.pyx":25
* _grad_X(N, D, M, X, X2, tmp, grad) # return nothing, work in place. * _grad_X(N, D, M, X, X2, tmp, grad) # return nothing, work in place.
@ -4109,10 +4229,10 @@ static int __Pyx_InitCachedConstants(void) {
* np.ndarray[DTYPE_t, ndim=2] _tmp, * np.ndarray[DTYPE_t, ndim=2] _tmp,
* np.ndarray[DTYPE_t, ndim=2] _X, * np.ndarray[DTYPE_t, ndim=2] _X,
*/ */
__pyx_tuple__9 = PyTuple_Pack(11, __pyx_n_s_N, __pyx_n_s_M, __pyx_n_s_Q, __pyx_n_s_tmp, __pyx_n_s_X, __pyx_n_s_X2, __pyx_n_s_grad, __pyx_n_s_tmp_2, __pyx_n_s_X_2, __pyx_n_s_X2_2, __pyx_n_s_grad_2); if (unlikely(!__pyx_tuple__9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_tuple__11 = PyTuple_Pack(11, __pyx_n_s_N, __pyx_n_s_M, __pyx_n_s_Q, __pyx_n_s_tmp, __pyx_n_s_X, __pyx_n_s_X2, __pyx_n_s_grad, __pyx_n_s_tmp_2, __pyx_n_s_X_2, __pyx_n_s_X2_2, __pyx_n_s_grad_2); if (unlikely(!__pyx_tuple__11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_tuple__9); __Pyx_GOTREF(__pyx_tuple__11);
__Pyx_GIVEREF(__pyx_tuple__9); __Pyx_GIVEREF(__pyx_tuple__11);
__pyx_codeobj__10 = (PyObject*)__Pyx_PyCode_New(7, 0, 11, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__9, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_Users_james_work_GPy_GPy_kern, __pyx_n_s_lengthscale_grads_c, 25, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_codeobj__12 = (PyObject*)__Pyx_PyCode_New(7, 0, 11, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__11, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_james_work_GPy_GPy_kern__s, __pyx_n_s_lengthscale_grads_c, 25, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
/* "GPy/kern/_src/stationary_cython.pyx":36 /* "GPy/kern/_src/stationary_cython.pyx":36
* _lengthscale_grads(N, M, Q, tmp, X, X2, grad) # return nothing, work in place. * _lengthscale_grads(N, M, Q, tmp, X, X2, grad) # return nothing, work in place.
@ -4121,10 +4241,10 @@ static int __Pyx_InitCachedConstants(void) {
* np.ndarray[DTYPE_t, ndim=2] tmp, * np.ndarray[DTYPE_t, ndim=2] tmp,
* np.ndarray[DTYPE_t, ndim=2] X, * np.ndarray[DTYPE_t, ndim=2] X,
*/ */
__pyx_tuple__11 = PyTuple_Pack(10, __pyx_n_s_N, __pyx_n_s_M, __pyx_n_s_Q, __pyx_n_s_tmp_2, __pyx_n_s_X_2, __pyx_n_s_X2_2, __pyx_n_s_grad_2, __pyx_n_s_q, __pyx_n_s_i, __pyx_n_s_j); if (unlikely(!__pyx_tuple__11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_tuple__13 = PyTuple_Pack(8, __pyx_n_s_N, __pyx_n_s_M, __pyx_n_s_Q, __pyx_n_s_tmp_2, __pyx_n_s_X_2, __pyx_n_s_X2_2, __pyx_n_s_grad_2, __pyx_n_s_q); if (unlikely(!__pyx_tuple__13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_tuple__11); __Pyx_GOTREF(__pyx_tuple__13);
__Pyx_GIVEREF(__pyx_tuple__11); __Pyx_GIVEREF(__pyx_tuple__13);
__pyx_codeobj__12 = (PyObject*)__Pyx_PyCode_New(7, 0, 10, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__11, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_Users_james_work_GPy_GPy_kern, __pyx_n_s_lengthscale_grads, 36, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_codeobj__14 = (PyObject*)__Pyx_PyCode_New(7, 0, 8, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__13, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_james_work_GPy_GPy_kern__s, __pyx_n_s_lengthscale_grads, 36, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_RefNannyFinishContext(); __Pyx_RefNannyFinishContext();
return 0; return 0;
__pyx_L1_error:; __pyx_L1_error:;
@ -4134,6 +4254,8 @@ static int __Pyx_InitCachedConstants(void) {
static int __Pyx_InitGlobals(void) { static int __Pyx_InitGlobals(void) {
if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
__pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
return 0; return 0;
__pyx_L1_error:; __pyx_L1_error:;
return -1; return -1;
@ -5119,6 +5241,70 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg
} }
#endif #endif
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) {
PyObject *self, *result;
PyCFunction cfunc;
cfunc = PyCFunction_GET_FUNCTION(func);
self = PyCFunction_GET_SELF(func);
if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
return NULL;
result = cfunc(self, arg);
Py_LeaveRecursiveCall();
if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
PyErr_SetString(
PyExc_SystemError,
"NULL result without error in PyObject_Call");
}
return result;
}
#endif
#if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) {
PyObject *result;
PyObject *args = PyTuple_New(1);
if (unlikely(!args)) return NULL;
Py_INCREF(arg);
PyTuple_SET_ITEM(args, 0, arg);
result = __Pyx_PyObject_Call(func, args, NULL);
Py_DECREF(args);
return result;
}
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
#ifdef __Pyx_CyFunction_USED
if (likely(PyCFunction_Check(func) || PyObject_TypeCheck(func, __pyx_CyFunctionType))) {
#else
if (likely(PyCFunction_Check(func))) {
#endif
if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) {
return __Pyx_PyObject_CallMethO(func, arg);
}
}
return __Pyx__PyObject_CallOneArg(func, arg);
}
#else
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
PyObject* args = PyTuple_Pack(1, arg);
return (likely(args)) ? __Pyx_PyObject_Call(func, args, NULL) : NULL;
}
#endif
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) {
#ifdef __Pyx_CyFunction_USED
if (likely(PyCFunction_Check(func) || PyObject_TypeCheck(func, __pyx_CyFunctionType))) {
#else
if (likely(PyCFunction_Check(func))) {
#endif
if (likely(PyCFunction_GET_FLAGS(func) & METH_NOARGS)) {
return __Pyx_PyObject_CallMethO(func, NULL);
}
}
return __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL);
}
#endif
#if PY_MAJOR_VERSION < 3 #if PY_MAJOR_VERSION < 3
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
CYTHON_UNUSED PyObject *cause) { CYTHON_UNUSED PyObject *cause) {

View file

@ -22,7 +22,7 @@ def grad_X(int N, int D, int M,
cdef double *grad = <double*> _grad.data cdef double *grad = <double*> _grad.data
_grad_X(N, D, M, X, X2, tmp, grad) # return nothing, work in place. _grad_X(N, D, M, X, X2, tmp, grad) # return nothing, work in place.
def lengthscale_grads_c(int N, int M, int Q, def lengthscale_grads(int N, int M, int Q,
np.ndarray[DTYPE_t, ndim=2] _tmp, np.ndarray[DTYPE_t, ndim=2] _tmp,
np.ndarray[DTYPE_t, ndim=2] _X, np.ndarray[DTYPE_t, ndim=2] _X,
np.ndarray[DTYPE_t, ndim=2] _X2, np.ndarray[DTYPE_t, ndim=2] _X2,
@ -33,13 +33,4 @@ def lengthscale_grads_c(int N, int M, int Q,
cdef double *grad = <double*> _grad.data cdef double *grad = <double*> _grad.data
_lengthscale_grads(N, M, Q, tmp, X, X2, grad) # return nothing, work in place. _lengthscale_grads(N, M, Q, tmp, X, X2, grad) # return nothing, work in place.
def lengthscale_grads(int N, int M, int Q,
np.ndarray[DTYPE_t, ndim=2] tmp,
np.ndarray[DTYPE_t, ndim=2] X,
np.ndarray[DTYPE_t, ndim=2] X2,
np.ndarray[DTYPE_t, ndim=1] grad):
for q in range(Q):
for i in range(N):
for j in range(M):
grad[q] += tmp[i,j]*(X[i,q]-X2[j,q])**2