mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-04-26 21:36:23 +02:00
added cython code for lengthscale gradients
This commit is contained in:
parent
b36a845821
commit
2e8ce34ee0
5 changed files with 369 additions and 39 deletions
|
|
@ -212,6 +212,17 @@ class Stationary(Kern):
|
|||
weave.inline(code, ['tmp', 'X', 'X2', 'grads', 'N', 'M', 'Q'], type_converters=weave.converters.blitz, support_code="#include <math.h>")
|
||||
return -grads/self.lengthscale**3
|
||||
|
||||
def cython_lengthscale_grads(self, tmp, X, X2):
|
||||
N,M = tmp.shape
|
||||
Q = X.shape[1]
|
||||
if hasattr(X, 'values'):X = X.values
|
||||
if hasattr(X2, 'values'):X2 = X2.values
|
||||
grads = np.zeros(self.input_dim)
|
||||
stationary_cython.lengthscale_grads(N, M, Q, tmp, X, X2, grads)
|
||||
return -grads/self.lengthscale**3
|
||||
|
||||
|
||||
|
||||
def gradients_X(self, dL_dK, X, X2=None):
|
||||
"""
|
||||
Given the derivative of the objective wrt K (dL_dK), compute the derivative wrt X
|
||||
|
|
|
|||
|
|
@ -1048,6 +1048,7 @@ static PyObject *__pyx_builtin_ValueError;
|
|||
static PyObject *__pyx_builtin_range;
|
||||
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_2lengthscale_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 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 char __pyx_k_B[] = "B";
|
||||
|
|
@ -1087,6 +1088,7 @@ static char __pyx_k_grad_X[] = "grad_X";
|
|||
static char __pyx_k_import[] = "__import__";
|
||||
static char __pyx_k_ValueError[] = "ValueError";
|
||||
static char __pyx_k_RuntimeError[] = "RuntimeError";
|
||||
static char __pyx_k_lengthscale_grads[] = "lengthscale_grads";
|
||||
static char __pyx_k_ndarray_is_not_C_contiguous[] = "ndarray is not C contiguous";
|
||||
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";
|
||||
|
|
@ -1102,6 +1104,7 @@ static PyObject *__pyx_n_s_GPy_kern__src_stationary_cython;
|
|||
static PyObject *__pyx_n_s_M;
|
||||
static PyObject *__pyx_n_s_N;
|
||||
static PyObject *__pyx_kp_u_Non_native_byte_order_not_suppor;
|
||||
static PyObject *__pyx_n_s_Q;
|
||||
static PyObject *__pyx_n_s_RuntimeError;
|
||||
static PyObject *__pyx_n_s_ValueError;
|
||||
static PyObject *__pyx_n_s_X;
|
||||
|
|
@ -1113,6 +1116,7 @@ static PyObject *__pyx_n_s_grad_2;
|
|||
static PyObject *__pyx_n_s_grad_X;
|
||||
static PyObject *__pyx_kp_s_home_james_work_GPy_GPy_kern__s;
|
||||
static PyObject *__pyx_n_s_import;
|
||||
static PyObject *__pyx_n_s_lengthscale_grads;
|
||||
static PyObject *__pyx_n_s_main;
|
||||
static PyObject *__pyx_kp_u_ndarray_is_not_C_contiguous;
|
||||
static PyObject *__pyx_kp_u_ndarray_is_not_Fortran_contiguou;
|
||||
|
|
@ -1130,10 +1134,12 @@ static PyObject *__pyx_tuple__4;
|
|||
static PyObject *__pyx_tuple__5;
|
||||
static PyObject *__pyx_tuple__6;
|
||||
static PyObject *__pyx_tuple__7;
|
||||
static PyObject *__pyx_tuple__9;
|
||||
static PyObject *__pyx_codeobj__8;
|
||||
static PyObject *__pyx_codeobj__10;
|
||||
|
||||
/* "GPy/kern/_src/stationary_cython.pyx":11
|
||||
* void _grad_X "_grad_X" (int N, int D, int M, double* X, double* X2, double* tmp, double* grad)
|
||||
/* "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)
|
||||
*
|
||||
* def grad_X(int N, int D, int M, # <<<<<<<<<<<<<<
|
||||
* np.ndarray[DTYPE_t, ndim=2] _X,
|
||||
|
|
@ -1182,36 +1188,36 @@ static PyObject *__pyx_pw_3GPy_4kern_4_src_17stationary_cython_1grad_X(PyObject
|
|||
case 1:
|
||||
if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_D)) != 0)) kw_args--;
|
||||
else {
|
||||
__Pyx_RaiseArgtupleInvalid("grad_X", 1, 7, 7, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
|
||||
__Pyx_RaiseArgtupleInvalid("grad_X", 1, 7, 7, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
|
||||
}
|
||||
case 2:
|
||||
if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_M)) != 0)) kw_args--;
|
||||
else {
|
||||
__Pyx_RaiseArgtupleInvalid("grad_X", 1, 7, 7, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
|
||||
__Pyx_RaiseArgtupleInvalid("grad_X", 1, 7, 7, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
|
||||
}
|
||||
case 3:
|
||||
if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_X)) != 0)) kw_args--;
|
||||
else {
|
||||
__Pyx_RaiseArgtupleInvalid("grad_X", 1, 7, 7, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
|
||||
__Pyx_RaiseArgtupleInvalid("grad_X", 1, 7, 7, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
|
||||
}
|
||||
case 4:
|
||||
if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_X2)) != 0)) kw_args--;
|
||||
else {
|
||||
__Pyx_RaiseArgtupleInvalid("grad_X", 1, 7, 7, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
|
||||
__Pyx_RaiseArgtupleInvalid("grad_X", 1, 7, 7, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
|
||||
}
|
||||
case 5:
|
||||
if (likely((values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_tmp)) != 0)) kw_args--;
|
||||
else {
|
||||
__Pyx_RaiseArgtupleInvalid("grad_X", 1, 7, 7, 5); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
|
||||
__Pyx_RaiseArgtupleInvalid("grad_X", 1, 7, 7, 5); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
|
||||
}
|
||||
case 6:
|
||||
if (likely((values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_grad)) != 0)) kw_args--;
|
||||
else {
|
||||
__Pyx_RaiseArgtupleInvalid("grad_X", 1, 7, 7, 6); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
|
||||
__Pyx_RaiseArgtupleInvalid("grad_X", 1, 7, 7, 6); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
|
||||
}
|
||||
}
|
||||
if (unlikely(kw_args > 0)) {
|
||||
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "grad_X") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
|
||||
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "grad_X") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
|
||||
}
|
||||
} else if (PyTuple_GET_SIZE(__pyx_args) != 7) {
|
||||
goto __pyx_L5_argtuple_error;
|
||||
|
|
@ -1224,9 +1230,9 @@ static PyObject *__pyx_pw_3GPy_4kern_4_src_17stationary_cython_1grad_X(PyObject
|
|||
values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
|
||||
values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
|
||||
}
|
||||
__pyx_v_N = __Pyx_PyInt_As_int(values[0]); if (unlikely((__pyx_v_N == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
|
||||
__pyx_v_D = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_D == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
|
||||
__pyx_v_M = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_M == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
|
||||
__pyx_v_N = __Pyx_PyInt_As_int(values[0]); if (unlikely((__pyx_v_N == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
|
||||
__pyx_v_D = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_D == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
|
||||
__pyx_v_M = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_M == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
|
||||
__pyx_v__X = ((PyArrayObject *)values[3]);
|
||||
__pyx_v__X2 = ((PyArrayObject *)values[4]);
|
||||
__pyx_v__tmp = ((PyArrayObject *)values[5]);
|
||||
|
|
@ -1234,16 +1240,16 @@ static PyObject *__pyx_pw_3GPy_4kern_4_src_17stationary_cython_1grad_X(PyObject
|
|||
}
|
||||
goto __pyx_L4_argument_unpacking_done;
|
||||
__pyx_L5_argtuple_error:;
|
||||
__Pyx_RaiseArgtupleInvalid("grad_X", 1, 7, 7, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
|
||||
__Pyx_RaiseArgtupleInvalid("grad_X", 1, 7, 7, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
|
||||
__pyx_L3_error:;
|
||||
__Pyx_AddTraceback("GPy.kern._src.stationary_cython.grad_X", __pyx_clineno, __pyx_lineno, __pyx_filename);
|
||||
__Pyx_RefNannyFinishContext();
|
||||
return NULL;
|
||||
__pyx_L4_argument_unpacking_done:;
|
||||
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v__X), __pyx_ptype_5numpy_ndarray, 1, "_X", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
|
||||
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v__X2), __pyx_ptype_5numpy_ndarray, 1, "_X2", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
|
||||
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v__tmp), __pyx_ptype_5numpy_ndarray, 1, "_tmp", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
|
||||
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v__grad), __pyx_ptype_5numpy_ndarray, 1, "_grad", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
|
||||
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v__X), __pyx_ptype_5numpy_ndarray, 1, "_X", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
|
||||
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v__X2), __pyx_ptype_5numpy_ndarray, 1, "_X2", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
|
||||
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v__tmp), __pyx_ptype_5numpy_ndarray, 1, "_tmp", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
|
||||
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v__grad), __pyx_ptype_5numpy_ndarray, 1, "_grad", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
|
||||
__pyx_r = __pyx_pf_3GPy_4kern_4_src_17stationary_cython_grad_X(__pyx_self, __pyx_v_N, __pyx_v_D, __pyx_v_M, __pyx_v__X, __pyx_v__X2, __pyx_v__tmp, __pyx_v__grad);
|
||||
|
||||
/* function exit code */
|
||||
|
|
@ -1292,26 +1298,26 @@ static PyObject *__pyx_pf_3GPy_4kern_4_src_17stationary_cython_grad_X(CYTHON_UNU
|
|||
__pyx_pybuffernd__grad.rcbuffer = &__pyx_pybuffer__grad;
|
||||
{
|
||||
__Pyx_BufFmt_StackElem __pyx_stack[1];
|
||||
if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd__X.rcbuffer->pybuffer, (PyObject*)__pyx_v__X, &__Pyx_TypeInfo_nn___pyx_t_3GPy_4kern_4_src_17stationary_cython_DTYPE_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __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_3GPy_4kern_4_src_17stationary_cython_DTYPE_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __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[1].strides = __pyx_pybuffernd__X.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd__X.diminfo[1].shape = __pyx_pybuffernd__X.rcbuffer->pybuffer.shape[1];
|
||||
{
|
||||
__Pyx_BufFmt_StackElem __pyx_stack[1];
|
||||
if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd__X2.rcbuffer->pybuffer, (PyObject*)__pyx_v__X2, &__Pyx_TypeInfo_nn___pyx_t_3GPy_4kern_4_src_17stationary_cython_DTYPE_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __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_3GPy_4kern_4_src_17stationary_cython_DTYPE_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __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[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];
|
||||
if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd__tmp.rcbuffer->pybuffer, (PyObject*)__pyx_v__tmp, &__Pyx_TypeInfo_nn___pyx_t_3GPy_4kern_4_src_17stationary_cython_DTYPE_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
|
||||
if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd__tmp.rcbuffer->pybuffer, (PyObject*)__pyx_v__tmp, &__Pyx_TypeInfo_nn___pyx_t_3GPy_4kern_4_src_17stationary_cython_DTYPE_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
|
||||
}
|
||||
__pyx_pybuffernd__tmp.diminfo[0].strides = __pyx_pybuffernd__tmp.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd__tmp.diminfo[0].shape = __pyx_pybuffernd__tmp.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd__tmp.diminfo[1].strides = __pyx_pybuffernd__tmp.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd__tmp.diminfo[1].shape = __pyx_pybuffernd__tmp.rcbuffer->pybuffer.shape[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, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __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, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __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[1].strides = __pyx_pybuffernd__grad.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd__grad.diminfo[1].shape = __pyx_pybuffernd__grad.rcbuffer->pybuffer.shape[1];
|
||||
|
||||
/* "GPy/kern/_src/stationary_cython.pyx":16
|
||||
/* "GPy/kern/_src/stationary_cython.pyx":19
|
||||
* np.ndarray[DTYPE_t, ndim=2] _tmp,
|
||||
* np.ndarray[DTYPE_t, ndim=2] _grad):
|
||||
* cdef double *X = <double*> _X.data # <<<<<<<<<<<<<<
|
||||
|
|
@ -1320,7 +1326,7 @@ static PyObject *__pyx_pf_3GPy_4kern_4_src_17stationary_cython_grad_X(CYTHON_UNU
|
|||
*/
|
||||
__pyx_v_X = ((double *)__pyx_v__X->data);
|
||||
|
||||
/* "GPy/kern/_src/stationary_cython.pyx":17
|
||||
/* "GPy/kern/_src/stationary_cython.pyx":20
|
||||
* np.ndarray[DTYPE_t, ndim=2] _grad):
|
||||
* cdef double *X = <double*> _X.data
|
||||
* cdef double *X2 = <double*> _X2.data # <<<<<<<<<<<<<<
|
||||
|
|
@ -1329,7 +1335,7 @@ static PyObject *__pyx_pf_3GPy_4kern_4_src_17stationary_cython_grad_X(CYTHON_UNU
|
|||
*/
|
||||
__pyx_v_X2 = ((double *)__pyx_v__X2->data);
|
||||
|
||||
/* "GPy/kern/_src/stationary_cython.pyx":18
|
||||
/* "GPy/kern/_src/stationary_cython.pyx":21
|
||||
* cdef double *X = <double*> _X.data
|
||||
* cdef double *X2 = <double*> _X2.data
|
||||
* cdef double *tmp = <double*> _tmp.data # <<<<<<<<<<<<<<
|
||||
|
|
@ -1338,23 +1344,26 @@ static PyObject *__pyx_pf_3GPy_4kern_4_src_17stationary_cython_grad_X(CYTHON_UNU
|
|||
*/
|
||||
__pyx_v_tmp = ((double *)__pyx_v__tmp->data);
|
||||
|
||||
/* "GPy/kern/_src/stationary_cython.pyx":19
|
||||
/* "GPy/kern/_src/stationary_cython.pyx":22
|
||||
* cdef double *X2 = <double*> _X2.data
|
||||
* cdef double *tmp = <double*> _tmp.data
|
||||
* cdef double *grad = <double*> _grad.data # <<<<<<<<<<<<<<
|
||||
* _grad_X(N, D, M, X, X2, tmp, grad) # return nothing, work in place.
|
||||
*
|
||||
*/
|
||||
__pyx_v_grad = ((double *)__pyx_v__grad->data);
|
||||
|
||||
/* "GPy/kern/_src/stationary_cython.pyx":20
|
||||
/* "GPy/kern/_src/stationary_cython.pyx":23
|
||||
* cdef double *tmp = <double*> _tmp.data
|
||||
* cdef double *grad = <double*> _grad.data
|
||||
* _grad_X(N, D, M, X, X2, tmp, grad) # return nothing, work in place. # <<<<<<<<<<<<<<
|
||||
*
|
||||
* def lengthscale_grads(int N, int M, int Q,
|
||||
*/
|
||||
_grad_X(__pyx_v_N, __pyx_v_D, __pyx_v_M, __pyx_v_X, __pyx_v_X2, __pyx_v_tmp, __pyx_v_grad);
|
||||
|
||||
/* "GPy/kern/_src/stationary_cython.pyx":11
|
||||
* void _grad_X "_grad_X" (int N, int D, int M, double* X, double* X2, double* tmp, double* grad)
|
||||
/* "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)
|
||||
*
|
||||
* def grad_X(int N, int D, int M, # <<<<<<<<<<<<<<
|
||||
* np.ndarray[DTYPE_t, ndim=2] _X,
|
||||
|
|
@ -1386,6 +1395,260 @@ static PyObject *__pyx_pf_3GPy_4kern_4_src_17stationary_cython_grad_X(CYTHON_UNU
|
|||
return __pyx_r;
|
||||
}
|
||||
|
||||
/* "GPy/kern/_src/stationary_cython.pyx":25
|
||||
* _grad_X(N, D, M, X, X2, tmp, 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,
|
||||
*/
|
||||
|
||||
/* Python wrapper */
|
||||
static PyObject *__pyx_pw_3GPy_4kern_4_src_17stationary_cython_3lengthscale_grads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
|
||||
static PyMethodDef __pyx_mdef_3GPy_4kern_4_src_17stationary_cython_3lengthscale_grads = {"lengthscale_grads", (PyCFunction)__pyx_pw_3GPy_4kern_4_src_17stationary_cython_3lengthscale_grads, METH_VARARGS|METH_KEYWORDS, 0};
|
||||
static PyObject *__pyx_pw_3GPy_4kern_4_src_17stationary_cython_3lengthscale_grads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
|
||||
int __pyx_v_N;
|
||||
int __pyx_v_M;
|
||||
int __pyx_v_Q;
|
||||
PyArrayObject *__pyx_v__tmp = 0;
|
||||
PyArrayObject *__pyx_v__X = 0;
|
||||
PyArrayObject *__pyx_v__X2 = 0;
|
||||
PyArrayObject *__pyx_v__grad = 0;
|
||||
int __pyx_lineno = 0;
|
||||
const char *__pyx_filename = NULL;
|
||||
int __pyx_clineno = 0;
|
||||
PyObject *__pyx_r = 0;
|
||||
__Pyx_RefNannyDeclarations
|
||||
__Pyx_RefNannySetupContext("lengthscale_grads (wrapper)", 0);
|
||||
{
|
||||
static PyObject **__pyx_pyargnames[] = {&__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,0};
|
||||
PyObject* values[7] = {0,0,0,0,0,0,0};
|
||||
if (unlikely(__pyx_kwds)) {
|
||||
Py_ssize_t kw_args;
|
||||
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
|
||||
switch (pos_args) {
|
||||
case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
|
||||
case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
|
||||
case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
|
||||
case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
|
||||
case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
|
||||
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
|
||||
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
|
||||
case 0: break;
|
||||
default: goto __pyx_L5_argtuple_error;
|
||||
}
|
||||
kw_args = PyDict_Size(__pyx_kwds);
|
||||
switch (pos_args) {
|
||||
case 0:
|
||||
if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_N)) != 0)) kw_args--;
|
||||
else goto __pyx_L5_argtuple_error;
|
||||
case 1:
|
||||
if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_M)) != 0)) kw_args--;
|
||||
else {
|
||||
__Pyx_RaiseArgtupleInvalid("lengthscale_grads", 1, 7, 7, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
|
||||
}
|
||||
case 2:
|
||||
if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_Q)) != 0)) kw_args--;
|
||||
else {
|
||||
__Pyx_RaiseArgtupleInvalid("lengthscale_grads", 1, 7, 7, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
|
||||
}
|
||||
case 3:
|
||||
if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_tmp)) != 0)) kw_args--;
|
||||
else {
|
||||
__Pyx_RaiseArgtupleInvalid("lengthscale_grads", 1, 7, 7, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
|
||||
}
|
||||
case 4:
|
||||
if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_X)) != 0)) kw_args--;
|
||||
else {
|
||||
__Pyx_RaiseArgtupleInvalid("lengthscale_grads", 1, 7, 7, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
|
||||
}
|
||||
case 5:
|
||||
if (likely((values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_X2)) != 0)) kw_args--;
|
||||
else {
|
||||
__Pyx_RaiseArgtupleInvalid("lengthscale_grads", 1, 7, 7, 5); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
|
||||
}
|
||||
case 6:
|
||||
if (likely((values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_grad)) != 0)) kw_args--;
|
||||
else {
|
||||
__Pyx_RaiseArgtupleInvalid("lengthscale_grads", 1, 7, 7, 6); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
|
||||
}
|
||||
}
|
||||
if (unlikely(kw_args > 0)) {
|
||||
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "lengthscale_grads") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
|
||||
}
|
||||
} else if (PyTuple_GET_SIZE(__pyx_args) != 7) {
|
||||
goto __pyx_L5_argtuple_error;
|
||||
} else {
|
||||
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
|
||||
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
|
||||
values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
|
||||
values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
|
||||
values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
|
||||
values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
|
||||
values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
|
||||
}
|
||||
__pyx_v_N = __Pyx_PyInt_As_int(values[0]); if (unlikely((__pyx_v_N == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
|
||||
__pyx_v_M = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_M == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
|
||||
__pyx_v_Q = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_Q == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
|
||||
__pyx_v__tmp = ((PyArrayObject *)values[3]);
|
||||
__pyx_v__X = ((PyArrayObject *)values[4]);
|
||||
__pyx_v__X2 = ((PyArrayObject *)values[5]);
|
||||
__pyx_v__grad = ((PyArrayObject *)values[6]);
|
||||
}
|
||||
goto __pyx_L4_argument_unpacking_done;
|
||||
__pyx_L5_argtuple_error:;
|
||||
__Pyx_RaiseArgtupleInvalid("lengthscale_grads", 1, 7, 7, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
|
||||
__pyx_L3_error:;
|
||||
__Pyx_AddTraceback("GPy.kern._src.stationary_cython.lengthscale_grads", __pyx_clineno, __pyx_lineno, __pyx_filename);
|
||||
__Pyx_RefNannyFinishContext();
|
||||
return NULL;
|
||||
__pyx_L4_argument_unpacking_done:;
|
||||
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v__tmp), __pyx_ptype_5numpy_ndarray, 1, "_tmp", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
|
||||
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v__X), __pyx_ptype_5numpy_ndarray, 1, "_X", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
|
||||
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v__X2), __pyx_ptype_5numpy_ndarray, 1, "_X2", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
|
||||
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v__grad), __pyx_ptype_5numpy_ndarray, 1, "_grad", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
|
||||
__pyx_r = __pyx_pf_3GPy_4kern_4_src_17stationary_cython_2lengthscale_grads(__pyx_self, __pyx_v_N, __pyx_v_M, __pyx_v_Q, __pyx_v__tmp, __pyx_v__X, __pyx_v__X2, __pyx_v__grad);
|
||||
|
||||
/* function exit code */
|
||||
goto __pyx_L0;
|
||||
__pyx_L1_error:;
|
||||
__pyx_r = NULL;
|
||||
__pyx_L0:;
|
||||
__Pyx_RefNannyFinishContext();
|
||||
return __pyx_r;
|
||||
}
|
||||
|
||||
static PyObject *__pyx_pf_3GPy_4kern_4_src_17stationary_cython_2lengthscale_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) {
|
||||
double *__pyx_v_tmp;
|
||||
double *__pyx_v_X;
|
||||
double *__pyx_v_X2;
|
||||
double *__pyx_v_grad;
|
||||
__Pyx_LocalBuf_ND __pyx_pybuffernd__X;
|
||||
__Pyx_Buffer __pyx_pybuffer__X;
|
||||
__Pyx_LocalBuf_ND __pyx_pybuffernd__X2;
|
||||
__Pyx_Buffer __pyx_pybuffer__X2;
|
||||
__Pyx_LocalBuf_ND __pyx_pybuffernd__grad;
|
||||
__Pyx_Buffer __pyx_pybuffer__grad;
|
||||
__Pyx_LocalBuf_ND __pyx_pybuffernd__tmp;
|
||||
__Pyx_Buffer __pyx_pybuffer__tmp;
|
||||
PyObject *__pyx_r = NULL;
|
||||
__Pyx_RefNannyDeclarations
|
||||
int __pyx_lineno = 0;
|
||||
const char *__pyx_filename = NULL;
|
||||
int __pyx_clineno = 0;
|
||||
__Pyx_RefNannySetupContext("lengthscale_grads", 0);
|
||||
__pyx_pybuffer__tmp.pybuffer.buf = NULL;
|
||||
__pyx_pybuffer__tmp.refcount = 0;
|
||||
__pyx_pybuffernd__tmp.data = NULL;
|
||||
__pyx_pybuffernd__tmp.rcbuffer = &__pyx_pybuffer__tmp;
|
||||
__pyx_pybuffer__X.pybuffer.buf = NULL;
|
||||
__pyx_pybuffer__X.refcount = 0;
|
||||
__pyx_pybuffernd__X.data = NULL;
|
||||
__pyx_pybuffernd__X.rcbuffer = &__pyx_pybuffer__X;
|
||||
__pyx_pybuffer__X2.pybuffer.buf = NULL;
|
||||
__pyx_pybuffer__X2.refcount = 0;
|
||||
__pyx_pybuffernd__X2.data = NULL;
|
||||
__pyx_pybuffernd__X2.rcbuffer = &__pyx_pybuffer__X2;
|
||||
__pyx_pybuffer__grad.pybuffer.buf = NULL;
|
||||
__pyx_pybuffer__grad.refcount = 0;
|
||||
__pyx_pybuffernd__grad.data = NULL;
|
||||
__pyx_pybuffernd__grad.rcbuffer = &__pyx_pybuffer__grad;
|
||||
{
|
||||
__Pyx_BufFmt_StackElem __pyx_stack[1];
|
||||
if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd__tmp.rcbuffer->pybuffer, (PyObject*)__pyx_v__tmp, &__Pyx_TypeInfo_nn___pyx_t_3GPy_4kern_4_src_17stationary_cython_DTYPE_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
|
||||
}
|
||||
__pyx_pybuffernd__tmp.diminfo[0].strides = __pyx_pybuffernd__tmp.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd__tmp.diminfo[0].shape = __pyx_pybuffernd__tmp.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd__tmp.diminfo[1].strides = __pyx_pybuffernd__tmp.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd__tmp.diminfo[1].shape = __pyx_pybuffernd__tmp.rcbuffer->pybuffer.shape[1];
|
||||
{
|
||||
__Pyx_BufFmt_StackElem __pyx_stack[1];
|
||||
if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd__X.rcbuffer->pybuffer, (PyObject*)__pyx_v__X, &__Pyx_TypeInfo_nn___pyx_t_3GPy_4kern_4_src_17stationary_cython_DTYPE_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __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[1].strides = __pyx_pybuffernd__X.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd__X.diminfo[1].shape = __pyx_pybuffernd__X.rcbuffer->pybuffer.shape[1];
|
||||
{
|
||||
__Pyx_BufFmt_StackElem __pyx_stack[1];
|
||||
if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd__X2.rcbuffer->pybuffer, (PyObject*)__pyx_v__X2, &__Pyx_TypeInfo_nn___pyx_t_3GPy_4kern_4_src_17stationary_cython_DTYPE_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __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[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];
|
||||
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 = 25; __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];
|
||||
|
||||
/* "GPy/kern/_src/stationary_cython.pyx":30
|
||||
* np.ndarray[DTYPE_t, ndim=2] _X2,
|
||||
* np.ndarray[DTYPE_t, ndim=1] _grad):
|
||||
* cdef double *tmp = <double*> _tmp.data # <<<<<<<<<<<<<<
|
||||
* cdef double *X = <double*> _X.data
|
||||
* cdef double *X2 = <double*> _X2.data
|
||||
*/
|
||||
__pyx_v_tmp = ((double *)__pyx_v__tmp->data);
|
||||
|
||||
/* "GPy/kern/_src/stationary_cython.pyx":31
|
||||
* np.ndarray[DTYPE_t, ndim=1] _grad):
|
||||
* cdef double *tmp = <double*> _tmp.data
|
||||
* cdef double *X = <double*> _X.data # <<<<<<<<<<<<<<
|
||||
* cdef double *X2 = <double*> _X2.data
|
||||
* cdef double *grad = <double*> _grad.data
|
||||
*/
|
||||
__pyx_v_X = ((double *)__pyx_v__X->data);
|
||||
|
||||
/* "GPy/kern/_src/stationary_cython.pyx":32
|
||||
* cdef double *tmp = <double*> _tmp.data
|
||||
* cdef double *X = <double*> _X.data
|
||||
* cdef double *X2 = <double*> _X2.data # <<<<<<<<<<<<<<
|
||||
* cdef double *grad = <double*> _grad.data
|
||||
* _lengthscale_grads(N, M, Q, tmp, X, X2, grad) # return nothing, work in place.
|
||||
*/
|
||||
__pyx_v_X2 = ((double *)__pyx_v__X2->data);
|
||||
|
||||
/* "GPy/kern/_src/stationary_cython.pyx":33
|
||||
* cdef double *X = <double*> _X.data
|
||||
* cdef double *X2 = <double*> _X2.data
|
||||
* cdef double *grad = <double*> _grad.data # <<<<<<<<<<<<<<
|
||||
* _lengthscale_grads(N, M, Q, tmp, X, X2, grad) # return nothing, work in place.
|
||||
*/
|
||||
__pyx_v_grad = ((double *)__pyx_v__grad->data);
|
||||
|
||||
/* "GPy/kern/_src/stationary_cython.pyx":34
|
||||
* cdef double *X2 = <double*> _X2.data
|
||||
* cdef double *grad = <double*> _grad.data
|
||||
* _lengthscale_grads(N, M, Q, tmp, X, X2, grad) # return nothing, work in place. # <<<<<<<<<<<<<<
|
||||
*/
|
||||
_lengthscale_grads(__pyx_v_N, __pyx_v_M, __pyx_v_Q, __pyx_v_tmp, __pyx_v_X, __pyx_v_X2, __pyx_v_grad);
|
||||
|
||||
/* "GPy/kern/_src/stationary_cython.pyx":25
|
||||
* _grad_X(N, D, M, X, X2, tmp, 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,
|
||||
*/
|
||||
|
||||
/* function exit code */
|
||||
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
|
||||
goto __pyx_L0;
|
||||
__pyx_L1_error:;
|
||||
{ PyObject *__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__X2.rcbuffer->pybuffer);
|
||||
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd__grad.rcbuffer->pybuffer);
|
||||
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd__tmp.rcbuffer->pybuffer);
|
||||
__Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
|
||||
__Pyx_AddTraceback("GPy.kern._src.stationary_cython.lengthscale_grads", __pyx_clineno, __pyx_lineno, __pyx_filename);
|
||||
__pyx_r = NULL;
|
||||
goto __pyx_L2;
|
||||
__pyx_L0:;
|
||||
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd__X.rcbuffer->pybuffer);
|
||||
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd__X2.rcbuffer->pybuffer);
|
||||
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd__grad.rcbuffer->pybuffer);
|
||||
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd__tmp.rcbuffer->pybuffer);
|
||||
__pyx_L2:;
|
||||
__Pyx_XGIVEREF(__pyx_r);
|
||||
__Pyx_RefNannyFinishContext();
|
||||
return __pyx_r;
|
||||
}
|
||||
|
||||
/* "../../../../../anaconda/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":194
|
||||
* # experimental exception made for __getbuffer__ and __releasebuffer__
|
||||
* # -- the details of this may change.
|
||||
|
|
@ -3430,6 +3693,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
|
|||
{&__pyx_n_s_M, __pyx_k_M, sizeof(__pyx_k_M), 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_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_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},
|
||||
|
|
@ -3441,6 +3705,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
|
|||
{&__pyx_n_s_grad_X, __pyx_k_grad_X, sizeof(__pyx_k_grad_X), 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_lengthscale_grads, __pyx_k_lengthscale_grads, sizeof(__pyx_k_lengthscale_grads), 0, 0, 1, 1},
|
||||
{&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
|
||||
{&__pyx_kp_u_ndarray_is_not_C_contiguous, __pyx_k_ndarray_is_not_C_contiguous, sizeof(__pyx_k_ndarray_is_not_C_contiguous), 0, 1, 0, 0},
|
||||
{&__pyx_kp_u_ndarray_is_not_Fortran_contiguou, __pyx_k_ndarray_is_not_Fortran_contiguou, sizeof(__pyx_k_ndarray_is_not_Fortran_contiguou), 0, 1, 0, 0},
|
||||
|
|
@ -3532,17 +3797,29 @@ static int __Pyx_InitCachedConstants(void) {
|
|||
__Pyx_GOTREF(__pyx_tuple__6);
|
||||
__Pyx_GIVEREF(__pyx_tuple__6);
|
||||
|
||||
/* "GPy/kern/_src/stationary_cython.pyx":11
|
||||
* void _grad_X "_grad_X" (int N, int D, int M, double* X, double* X2, double* tmp, double* grad)
|
||||
/* "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)
|
||||
*
|
||||
* def grad_X(int N, int D, int M, # <<<<<<<<<<<<<<
|
||||
* np.ndarray[DTYPE_t, ndim=2] _X,
|
||||
* 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 = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
|
||||
__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_GOTREF(__pyx_tuple__7);
|
||||
__Pyx_GIVEREF(__pyx_tuple__7);
|
||||
__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_home_james_work_GPy_GPy_kern__s, __pyx_n_s_grad_X, 11, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
|
||||
__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_home_james_work_GPy_GPy_kern__s, __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;}
|
||||
|
||||
/* "GPy/kern/_src/stationary_cython.pyx":25
|
||||
* _grad_X(N, D, M, X, X2, tmp, 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,
|
||||
*/
|
||||
__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_GOTREF(__pyx_tuple__9);
|
||||
__Pyx_GIVEREF(__pyx_tuple__9);
|
||||
__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_lengthscale_grads, 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_RefNannyFinishContext();
|
||||
return 0;
|
||||
__pyx_L1_error:;
|
||||
|
|
@ -3666,16 +3943,28 @@ PyMODINIT_FUNC PyInit_stationary_cython(void)
|
|||
if (PyDict_SetItem(__pyx_d, __pyx_n_s_np, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
|
||||
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
|
||||
|
||||
/* "GPy/kern/_src/stationary_cython.pyx":11
|
||||
* void _grad_X "_grad_X" (int N, int D, int M, double* X, double* X2, double* tmp, double* grad)
|
||||
/* "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)
|
||||
*
|
||||
* def grad_X(int N, int D, int M, # <<<<<<<<<<<<<<
|
||||
* np.ndarray[DTYPE_t, ndim=2] _X,
|
||||
* np.ndarray[DTYPE_t, ndim=2] _X2,
|
||||
*/
|
||||
__pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_3GPy_4kern_4_src_17stationary_cython_1grad_X, NULL, __pyx_n_s_GPy_kern__src_stationary_cython); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
|
||||
__pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_3GPy_4kern_4_src_17stationary_cython_1grad_X, NULL, __pyx_n_s_GPy_kern__src_stationary_cython); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
|
||||
__Pyx_GOTREF(__pyx_t_1);
|
||||
if (PyDict_SetItem(__pyx_d, __pyx_n_s_grad_X, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
|
||||
if (PyDict_SetItem(__pyx_d, __pyx_n_s_grad_X, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
|
||||
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
|
||||
|
||||
/* "GPy/kern/_src/stationary_cython.pyx":25
|
||||
* _grad_X(N, D, M, X, X2, tmp, 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,
|
||||
*/
|
||||
__pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_3GPy_4kern_4_src_17stationary_cython_3lengthscale_grads, NULL, __pyx_n_s_GPy_kern__src_stationary_cython); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
|
||||
__Pyx_GOTREF(__pyx_t_1);
|
||||
if (PyDict_SetItem(__pyx_d, __pyx_n_s_lengthscale_grads, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
|
||||
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
|
||||
|
||||
/* "GPy/kern/_src/stationary_cython.pyx":1
|
||||
|
|
|
|||
|
|
@ -7,6 +7,9 @@ ctypedef np.float64_t DTYPE_t
|
|||
|
||||
cdef extern from "stationary_utils.h":
|
||||
void _grad_X "_grad_X" (int N, int D, int M, double* X, double* X2, double* tmp, double* grad)
|
||||
|
||||
cdef extern from "stationary_utils.h":
|
||||
void _lengthscale_grads "_lengthscale_grads" (int N, int M, int Q, double* tmp, double* X, double* X2, double* grad)
|
||||
|
||||
def grad_X(int N, int D, int M,
|
||||
np.ndarray[DTYPE_t, ndim=2] _X,
|
||||
|
|
@ -18,3 +21,14 @@ def grad_X(int N, int D, int M,
|
|||
cdef double *tmp = <double*> _tmp.data
|
||||
cdef double *grad = <double*> _grad.data
|
||||
_grad_X(N, D, M, X, X2, tmp, 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):
|
||||
cdef double *tmp = <double*> _tmp.data
|
||||
cdef double *X = <double*> _X.data
|
||||
cdef double *X2 = <double*> _X2.data
|
||||
cdef double *grad = <double*> _grad.data
|
||||
_lengthscale_grads(N, M, Q, tmp, X, X2, grad) # return nothing, work in place.
|
||||
|
|
|
|||
|
|
@ -13,8 +13,23 @@ for(d=0;d<D;d++){
|
|||
}
|
||||
} //grad_X
|
||||
|
||||
//#weave_options = {'headers' : ['<omp.h>'],
|
||||
//'extra_compile_args': ['-fopenmp -O3'], # -march=native'],
|
||||
//'extra_link_args' : ['-lgomp']}
|
||||
|
||||
void _lengthscale_grads(int N, int M, int Q, double* tmp, double* X, double* X2, double* grad){
|
||||
int n,m,q;
|
||||
double gradq, dist;
|
||||
#pragma omp parallel for private(n,m, gradq, dist)
|
||||
for(q=0; q<Q; q++){
|
||||
gradq = 0;
|
||||
for(n=0; n<N; n++){
|
||||
for(m=0; m<M; m++){
|
||||
dist = X[n*Q+q]-X2[m*Q+q];
|
||||
gradq += tmp[n*M+m]*dist*dist;
|
||||
}
|
||||
}
|
||||
grad[q] = gradq;
|
||||
}
|
||||
} //lengthscale_grads
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,2 +1,3 @@
|
|||
#include <omp.h>
|
||||
void _grad_X(int N, int D, int M, double*X, double* X2, double* tmp, double* grad);
|
||||
void _lengthscale_grads(int N, int D, int M, double* X, double* X2, double* tmp, double* grad);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue