Generated by Cython 0.19 on Mon Sep 30 17:13:04 2013
Raw output: bilinear.c
1: # -*- coding: utf-8 -*-
/* "bilinear.pyx":1 * # -*- coding: utf-8 -*- #<<<<<<<<<<<<<<* # * # Project: Azimuthal integration */ __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); if (PyDict_SetItem(__pyx_d, __pyx_n_s____test__, ((PyObject *)__pyx_t_1))<0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
2: #
3: # Project: Azimuthal integration
4: # https://forge.epn-campus.eu/projects/azimuthal
5: #
6: # File: "$Id$"
7: #
8: # Copyright (C) European Synchrotron Radiation Facility, Grenoble, France
9: #
10: # Principal author: Jérôme Kieffer (Jerome.Kieffer@ESRF.eu)
11: #
12: # This program is free software: you can redistribute it and/or modify
13: # it under the terms of the GNU General Public License as published by
14: # the Free Software Foundation, either version 3 of the License, or
15: # (at your option) any later version.
16: #
17: # This program is distributed in the hope that it will be useful,
18: # but WITHOUT ANY WARRANTY; without even the implied warranty of
19: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20: # GNU General Public License for more details.
21: #
22: # You should have received a copy of the GNU General Public License
23: # along with this program. If not, see <http://www.gnu.org/licenses/>.
24: #
25:
26: __author__ = "Jerome Kieffer"
/* "bilinear.pyx":26 * # * * __author__ = "Jerome Kieffer" #<<<<<<<<<<<<<<* __license__ = "GPLv3" * __date__ = "31/01/2013" */ if (PyDict_SetItem(__pyx_d, __pyx_n_s____author__, ((PyObject *)__pyx_kp_s_49))<0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27: __license__ = "GPLv3"
/* "bilinear.pyx":27 * * __author__ = "Jerome Kieffer" * __license__ = "GPLv3" #<<<<<<<<<<<<<<* __date__ = "31/01/2013" * __copyright__ = "2011-2013, ESRF" */ if (PyDict_SetItem(__pyx_d, __pyx_n_s____license__, ((PyObject *)__pyx_n_s__GPLv3))<0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28: __date__ = "31/01/2013"
/* "bilinear.pyx":28 * __author__ = "Jerome Kieffer" * __license__ = "GPLv3" * __date__ = "31/01/2013" #<<<<<<<<<<<<<<* __copyright__ = "2011-2013, ESRF" * __contact__ = "jerome.kieffer@esrf.fr" */ if (PyDict_SetItem(__pyx_d, __pyx_n_s____date__, ((PyObject *)__pyx_kp_s_50))<0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29: __copyright__ = "2011-2013, ESRF"
/* "bilinear.pyx":29 * __license__ = "GPLv3" * __date__ = "31/01/2013" * __copyright__ = "2011-2013, ESRF" #<<<<<<<<<<<<<<* __contact__ = "jerome.kieffer@esrf.fr" * */ if (PyDict_SetItem(__pyx_d, __pyx_n_s____copyright__, ((PyObject *)__pyx_kp_s_51))<0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30: __contact__ = "jerome.kieffer@esrf.fr"
/* "bilinear.pyx":30 * __date__ = "31/01/2013" * __copyright__ = "2011-2013, ESRF" * __contact__ = "jerome.kieffer@esrf.fr" #<<<<<<<<<<<<<<* * import cython */ if (PyDict_SetItem(__pyx_d, __pyx_n_s____contact__, ((PyObject *)__pyx_kp_s_52))<0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31:
32: import cython
33: import numpy
/* "bilinear.pyx":33 * * import cython * import numpy #<<<<<<<<<<<<<<* cimport numpy * */ __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__numpy), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s__numpy, __pyx_t_1)<0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
34: cimport numpy
35:
36: from libc.math cimport floor,ceil
37:
38:
39: cdef class Bilinear:
/* "bilinear.pyx":39 * * * cdef class Bilinear: #<<<<<<<<<<<<<<* """Bilinear interpolator for finding max""" * */ struct __pyx_obj_8bilinear_Bilinear { PyObject_HEAD __Pyx_memviewslice data; float maxi; float mini; size_t d0_max; size_t d1_max; size_t r; };
40: """Bilinear interpolator for finding max"""
41:
42: cdef float[:,:] data
43: cdef float maxi, mini
44: cdef size_t d0_max, d1_max, r
45:
46: def __cinit__(self, data not None):
/* "bilinear.pyx":46 * cdef size_t d0_max, d1_max, r * * def __cinit__(self, data not None): #<<<<<<<<<<<<<<* assert data.ndim == 2 * self.d0_max = data.shape[0] - 1 */ static int __pyx_pf_8bilinear_8Bilinear___cinit__(struct __pyx_obj_8bilinear_Bilinear *__pyx_v_self, PyObject *__pyx_v_data) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__cinit__", 0);
47: assert data.ndim == 2
/* "bilinear.pyx":47 * * def __cinit__(self, data not None): * assert data.ndim == 2 #<<<<<<<<<<<<<<* self.d0_max = data.shape[0] - 1 * self.d1_max = data.shape[1] - 1 */ #ifndef CYTHON_WITHOUT_ASSERTIONS __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_data, __pyx_n_s__ndim); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, __pyx_int_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3<0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (unlikely(!__pyx_t_3)) { PyErr_SetNone(PyExc_AssertionError); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } #endif
48: self.d0_max = data.shape[0] - 1
/* "bilinear.pyx":48 * def __cinit__(self, data not None): * assert data.ndim == 2 * self.d0_max = data.shape[0] - 1 #<<<<<<<<<<<<<<* self.d1_max = data.shape[1] - 1 * self.maxi = data.max() */ __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_data, __pyx_n_s__shape); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_2, 0, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = PyNumber_Subtract(__pyx_t_1, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_4 = __Pyx_PyInt_AsSize_t(__pyx_t_2); if (unlikely((__pyx_t_4 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_self->d0_max = __pyx_t_4;
49: self.d1_max = data.shape[1] - 1
/* "bilinear.pyx":49 * assert data.ndim == 2 * self.d0_max = data.shape[0] - 1 * self.d1_max = data.shape[1] - 1 #<<<<<<<<<<<<<<* self.maxi = data.max() * self.mini = data.min() */ __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_data, __pyx_n_s__shape); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_2, 1, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = PyNumber_Subtract(__pyx_t_1, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_4 = __Pyx_PyInt_AsSize_t(__pyx_t_2); if (unlikely((__pyx_t_4 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_self->d1_max = __pyx_t_4;
50: self.maxi = data.max()
/* "bilinear.pyx":50 * self.d0_max = data.shape[0] - 1 * self.d1_max = data.shape[1] - 1 * self.maxi = data.max() #<<<<<<<<<<<<<<* self.mini = data.min() * self.data = numpy.ascontiguousarray(data, dtype=numpy.float32) */ __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_data, __pyx_n_s__max); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_5 = __pyx_PyFloat_AsFloat(__pyx_t_1); if (unlikely((__pyx_t_5 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_self->maxi = __pyx_t_5;
51: self.mini = data.min()
/* "bilinear.pyx":51 * self.d1_max = data.shape[1] - 1 * self.maxi = data.max() * self.mini = data.min() #<<<<<<<<<<<<<<* self.data = numpy.ascontiguousarray(data, dtype=numpy.float32) * */ __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_data, __pyx_n_s__min); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_5 = __pyx_PyFloat_AsFloat(__pyx_t_2); if (unlikely((__pyx_t_5 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_self->mini = __pyx_t_5;
52: self.data = numpy.ascontiguousarray(data, dtype=numpy.float32)
/* "bilinear.pyx":52 * self.maxi = data.max() * self.mini = data.min() * self.data = numpy.ascontiguousarray(data, dtype=numpy.float32) #<<<<<<<<<<<<<<* * @cython.boundscheck(False) */ __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__numpy); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__ascontiguousarray); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_v_data); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_data); __Pyx_GIVEREF(__pyx_v_data); __pyx_t_6 = PyDict_New(); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_6)); __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s__numpy); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s__float32); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; if (PyDict_SetItem(__pyx_t_6, ((PyObject *)__pyx_n_s__dtype), __pyx_t_8)<0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_t_8 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_dsds_float(__pyx_t_8); if (unlikely(!__pyx_t_9.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __PYX_XDEC_MEMVIEW(&__pyx_v_self->data, 0); __pyx_v_self->data = __pyx_t_9; __pyx_t_9.memview = NULL; __pyx_t_9.data = NULL; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_6); __Pyx_XDECREF(__pyx_t_7); __Pyx_XDECREF(__pyx_t_8); __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1); __Pyx_AddTraceback("bilinear.Bilinear.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_pw_8bilinear_8Bilinear_3f_cy(PyObject *__pyx_v_self, PyObject *__pyx_v_x); /*proto*/ static char __pyx_doc_8bilinear_8Bilinear_2f_cy[] = "\n Function f((y,x)) where f is a continuous function (y,x) are pixel coordinates\n @param x: 2-tuple of float\n @return: Interpolated signal from the image (negative for minimizer)\n\n "; static PyObject *__pyx_pw_8bilinear_8Bilinear_3f_cy(PyObject *__pyx_v_self, PyObject *__pyx_v_x) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("f_cy (wrapper)", 0); __pyx_r = __pyx_pf_8bilinear_8Bilinear_2f_cy(((struct __pyx_obj_8bilinear_Bilinear *)__pyx_v_self), ((PyObject *)__pyx_v_x)); __Pyx_RefNannyFinishContext(); return __pyx_r; }
53:
54: @cython.boundscheck(False)
55: @cython.wraparound(False)
56: def f_cy(self, x):
/* "bilinear.pyx":56 * @cython.boundscheck(False) * @cython.wraparound(False) * def f_cy(self, x): #<<<<<<<<<<<<<<* """ * Function f((y,x)) where f is a continuous function (y,x) are pixel coordinates */ static PyObject *__pyx_pf_8bilinear_8Bilinear_2f_cy(struct __pyx_obj_8bilinear_Bilinear *__pyx_v_self, PyObject *__pyx_v_x) { float __pyx_v_d0; float __pyx_v_d1; int __pyx_v_i0; int __pyx_v_i1; int __pyx_v_j0; int __pyx_v_j1; float __pyx_v_x0; float __pyx_v_x1; float __pyx_v_y0; float __pyx_v_y1; float __pyx_v_res; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("f_cy", 0);
57: """
58: Function f((y,x)) where f is a continuous function (y,x) are pixel coordinates
59: @param x: 2-tuple of float
60: @return: Interpolated signal from the image (negative for minimizer)
61:
62: """
63: cdef float d0 = x[0]
/* "bilinear.pyx":63 * * """ * cdef float d0 = x[0] #<<<<<<<<<<<<<<* cdef float d1 = x[1] * cdef int i0, i1, j0, j1 */ __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_x, 0, sizeof(long), PyInt_FromLong, 0, 0, 0); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __pyx_PyFloat_AsFloat(__pyx_t_1); if (unlikely((__pyx_t_2 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_d0 = __pyx_t_2;
64: cdef float d1 = x[1]
/* "bilinear.pyx":64 * """ * cdef float d0 = x[0] * cdef float d1 = x[1] #<<<<<<<<<<<<<<* cdef int i0, i1, j0, j1 * cdef float x0, x1, y0, y1, res */ __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_x, 1, sizeof(long), PyInt_FromLong, 0, 0, 0); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __pyx_PyFloat_AsFloat(__pyx_t_1); if (unlikely((__pyx_t_2 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_d1 = __pyx_t_2;
65: cdef int i0, i1, j0, j1
66: cdef float x0, x1, y0, y1, res
67: with nogil:
/* "bilinear.pyx":67 * cdef int i0, i1, j0, j1 * cdef float x0, x1, y0, y1, res * with nogil: #<<<<<<<<<<<<<<* x0 = floor(d0) * x1 = ceil(d0) */ { #ifdef WITH_THREAD PyThreadState *_save; Py_UNBLOCK_THREADS #endif /*try:*/ { /* "bilinear.pyx":67 * cdef int i0, i1, j0, j1 * cdef float x0, x1, y0, y1, res * with nogil: #<<<<<<<<<<<<<<* x0 = floor(d0) * x1 = ceil(d0) */ /*finally:*/ { int __pyx_why; __pyx_why = 0; goto __pyx_L5; __pyx_L4: __pyx_why = 4; goto __pyx_L5; __pyx_L5:; #ifdef WITH_THREAD Py_BLOCK_THREADS #endif switch (__pyx_why) { case 4: goto __pyx_L1_error; } } }
68: x0 = floor(d0)
/* "bilinear.pyx":68
* cdef float x0, x1, y0, y1, res
* with nogil:
* x0 = floor(d0) # <<<<<<<<<<<<<<
* x1 = ceil(d0)
* y0 = floor(d1)
*/
__pyx_v_x0 = floor(__pyx_v_d0);
69: x1 = ceil(d0)
/* "bilinear.pyx":69
* with nogil:
* x0 = floor(d0)
* x1 = ceil(d0) # <<<<<<<<<<<<<<
* y0 = floor(d1)
* y1 = ceil(d1)
*/
__pyx_v_x1 = ceil(__pyx_v_d0);
70: y0 = floor(d1)
/* "bilinear.pyx":70
* x0 = floor(d0)
* x1 = ceil(d0)
* y0 = floor(d1) # <<<<<<<<<<<<<<
* y1 = ceil(d1)
* i0 = < int > x0
*/
__pyx_v_y0 = floor(__pyx_v_d1);
71: y1 = ceil(d1)
/* "bilinear.pyx":71
* x1 = ceil(d0)
* y0 = floor(d1)
* y1 = ceil(d1) # <<<<<<<<<<<<<<
* i0 = < int > x0
* i1 = < int > x1
*/
__pyx_v_y1 = ceil(__pyx_v_d1);
72: i0 = < int > x0
/* "bilinear.pyx":72
* y0 = floor(d1)
* y1 = ceil(d1)
* i0 = < int > x0 # <<<<<<<<<<<<<<
* i1 = < int > x1
* j0 = < int > y0
*/
__pyx_v_i0 = ((int)__pyx_v_x0);
73: i1 = < int > x1
/* "bilinear.pyx":73
* y1 = ceil(d1)
* i0 = < int > x0
* i1 = < int > x1 # <<<<<<<<<<<<<<
* j0 = < int > y0
* j1 = < int > y1
*/
__pyx_v_i1 = ((int)__pyx_v_x1);
74: j0 = < int > y0
/* "bilinear.pyx":74
* i0 = < int > x0
* i1 = < int > x1
* j0 = < int > y0 # <<<<<<<<<<<<<<
* j1 = < int > y1
* if d0 < 0:
*/
__pyx_v_j0 = ((int)__pyx_v_y0);
75: j1 = < int > y1
/* "bilinear.pyx":75
* i1 = < int > x1
* j0 = < int > y0
* j1 = < int > y1 # <<<<<<<<<<<<<<
* if d0 < 0:
* res = self.mini + d0
*/
__pyx_v_j1 = ((int)__pyx_v_y1);
76: if d0 < 0:
/* "bilinear.pyx":76
* j0 = < int > y0
* j1 = < int > y1
* if d0 < 0: # <<<<<<<<<<<<<<
* res = self.mini + d0
* elif d1 < 0:
*/
__pyx_t_3 = (__pyx_v_d0 < 0.0);
if (__pyx_t_3) {
77: res = self.mini + d0
/* "bilinear.pyx":77
* j1 = < int > y1
* if d0 < 0:
* res = self.mini + d0 # <<<<<<<<<<<<<<
* elif d1 < 0:
* res = self.mini + d1
*/
__pyx_v_res = (__pyx_v_self->mini + __pyx_v_d0);
goto __pyx_L6;
}
78: elif d1 < 0:
/* "bilinear.pyx":78
* if d0 < 0:
* res = self.mini + d0
* elif d1 < 0: # <<<<<<<<<<<<<<
* res = self.mini + d1
* elif d0 > self.d0_max:
*/
__pyx_t_3 = (__pyx_v_d1 < 0.0);
if (__pyx_t_3) {
79: res = self.mini + d1
/* "bilinear.pyx":79
* res = self.mini + d0
* elif d1 < 0:
* res = self.mini + d1 # <<<<<<<<<<<<<<
* elif d0 > self.d0_max:
* res = self.mini - d0 + self.d0_max
*/
__pyx_v_res = (__pyx_v_self->mini + __pyx_v_d1);
goto __pyx_L6;
}
80: elif d0 > self.d0_max:
/* "bilinear.pyx":80
* elif d1 < 0:
* res = self.mini + d1
* elif d0 > self.d0_max: # <<<<<<<<<<<<<<
* res = self.mini - d0 + self.d0_max
* elif d1 > self.d1_max:
*/
__pyx_t_3 = (__pyx_v_d0 > __pyx_v_self->d0_max);
if (__pyx_t_3) {
81: res = self.mini - d0 + self.d0_max
/* "bilinear.pyx":81
* res = self.mini + d1
* elif d0 > self.d0_max:
* res = self.mini - d0 + self.d0_max # <<<<<<<<<<<<<<
* elif d1 > self.d1_max:
* res = self.mini - d1 + self.d1_max
*/
__pyx_v_res = ((__pyx_v_self->mini - __pyx_v_d0) + __pyx_v_self->d0_max);
goto __pyx_L6;
}
82: elif d1 > self.d1_max:
/* "bilinear.pyx":82
* elif d0 > self.d0_max:
* res = self.mini - d0 + self.d0_max
* elif d1 > self.d1_max: # <<<<<<<<<<<<<<
* res = self.mini - d1 + self.d1_max
* elif (i0 == i1) and (j0 == j1):
*/
__pyx_t_3 = (__pyx_v_d1 > __pyx_v_self->d1_max);
if (__pyx_t_3) {
83: res = self.mini - d1 + self.d1_max
/* "bilinear.pyx":83
* res = self.mini - d0 + self.d0_max
* elif d1 > self.d1_max:
* res = self.mini - d1 + self.d1_max # <<<<<<<<<<<<<<
* elif (i0 == i1) and (j0 == j1):
* res = self.data[i0,j0]
*/
__pyx_v_res = ((__pyx_v_self->mini - __pyx_v_d1) + __pyx_v_self->d1_max);
goto __pyx_L6;
}
84: elif (i0 == i1) and (j0 == j1):
/* "bilinear.pyx":84
* elif d1 > self.d1_max:
* res = self.mini - d1 + self.d1_max
* elif (i0 == i1) and (j0 == j1): # <<<<<<<<<<<<<<
* res = self.data[i0,j0]
* elif i0 == i1:
*/
__pyx_t_3 = (__pyx_v_i0 == __pyx_v_i1);
if (__pyx_t_3) {
__pyx_t_4 = (__pyx_v_j0 == __pyx_v_j1);
__pyx_t_5 = __pyx_t_4;
} else {
__pyx_t_5 = __pyx_t_3;
}
if (__pyx_t_5) {
85: res = self.data[i0,j0]
/* "bilinear.pyx":85
* res = self.mini - d1 + self.d1_max
* elif (i0 == i1) and (j0 == j1):
* res = self.data[i0,j0] # <<<<<<<<<<<<<<
* elif i0 == i1:
* res = (self.data[i0,j0] * (y1 - d1)) + (self.data[i0,j1] * (d1 - y0))
*/
if (unlikely(!__pyx_v_self->data.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");{__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L4;}}
__pyx_t_6 = __pyx_v_i0;
__pyx_t_7 = __pyx_v_j0;
__pyx_v_res = (*((float *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_self->data.data + __pyx_t_6 * __pyx_v_self->data.strides[0]) ) + __pyx_t_7 * __pyx_v_self->data.strides[1]) )));
goto __pyx_L6;
}
86: elif i0 == i1:
/* "bilinear.pyx":86
* elif (i0 == i1) and (j0 == j1):
* res = self.data[i0,j0]
* elif i0 == i1: # <<<<<<<<<<<<<<
* res = (self.data[i0,j0] * (y1 - d1)) + (self.data[i0,j1] * (d1 - y0))
* elif j0 == j1:
*/
__pyx_t_5 = (__pyx_v_i0 == __pyx_v_i1);
if (__pyx_t_5) {
87: res = (self.data[i0,j0] * (y1 - d1)) + (self.data[i0,j1] * (d1 - y0))
/* "bilinear.pyx":87
* res = self.data[i0,j0]
* elif i0 == i1:
* res = (self.data[i0,j0] * (y1 - d1)) + (self.data[i0,j1] * (d1 - y0)) # <<<<<<<<<<<<<<
* elif j0 == j1:
* res = (self.data[i0,j0] * (x1 - d0)) + (self.data[i1,j0] * (d0 - x0))
*/
if (unlikely(!__pyx_v_self->data.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");{__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L4;}}
__pyx_t_8 = __pyx_v_i0;
__pyx_t_9 = __pyx_v_j0;
if (unlikely(!__pyx_v_self->data.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");{__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L4;}}
__pyx_t_10 = __pyx_v_i0;
__pyx_t_11 = __pyx_v_j1;
__pyx_v_res = (((*((float *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_self->data.data + __pyx_t_8 * __pyx_v_self->data.strides[0]) ) + __pyx_t_9 * __pyx_v_self->data.strides[1]) ))) * (__pyx_v_y1 - __pyx_v_d1)) + ((*((float *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_self->data.data + __pyx_t_10 * __pyx_v_self->data.strides[0]) ) + __pyx_t_11 * __pyx_v_self->data.strides[1]) ))) * (__pyx_v_d1 - __pyx_v_y0)));
goto __pyx_L6;
}
88: elif j0 == j1:
/* "bilinear.pyx":88
* elif i0 == i1:
* res = (self.data[i0,j0] * (y1 - d1)) + (self.data[i0,j1] * (d1 - y0))
* elif j0 == j1: # <<<<<<<<<<<<<<
* res = (self.data[i0,j0] * (x1 - d0)) + (self.data[i1,j0] * (d0 - x0))
* else:
*/
__pyx_t_5 = (__pyx_v_j0 == __pyx_v_j1);
if (__pyx_t_5) {
89: res = (self.data[i0,j0] * (x1 - d0)) + (self.data[i1,j0] * (d0 - x0))
/* "bilinear.pyx":89
* res = (self.data[i0,j0] * (y1 - d1)) + (self.data[i0,j1] * (d1 - y0))
* elif j0 == j1:
* res = (self.data[i0,j0] * (x1 - d0)) + (self.data[i1,j0] * (d0 - x0)) # <<<<<<<<<<<<<<
* else:
* res = (self.data[i0,j0] * (x1 - d0) * (y1 - d1)) \
*/
if (unlikely(!__pyx_v_self->data.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");{__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L4;}}
__pyx_t_12 = __pyx_v_i0;
__pyx_t_13 = __pyx_v_j0;
if (unlikely(!__pyx_v_self->data.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");{__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L4;}}
__pyx_t_14 = __pyx_v_i1;
__pyx_t_15 = __pyx_v_j0;
__pyx_v_res = (((*((float *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_self->data.data + __pyx_t_12 * __pyx_v_self->data.strides[0]) ) + __pyx_t_13 * __pyx_v_self->data.strides[1]) ))) * (__pyx_v_x1 - __pyx_v_d0)) + ((*((float *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_self->data.data + __pyx_t_14 * __pyx_v_self->data.strides[0]) ) + __pyx_t_15 * __pyx_v_self->data.strides[1]) ))) * (__pyx_v_d0 - __pyx_v_x0)));
goto __pyx_L6;
}
/*else*/ {
90: else:
91: res = (self.data[i0,j0] * (x1 - d0) * (y1 - d1)) \
/* "bilinear.pyx":91
* res = (self.data[i0,j0] * (x1 - d0)) + (self.data[i1,j0] * (d0 - x0))
* else:
* res = (self.data[i0,j0] * (x1 - d0) * (y1 - d1)) \ # <<<<<<<<<<<<<<
* + (self.data[i1,j0] * (d0 - x0) * (y1 - d1)) \
* + (self.data[i0,j1] * (x1 - d0) * (d1 - y0)) \
*/
if (unlikely(!__pyx_v_self->data.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");{__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L4;}}
__pyx_t_16 = __pyx_v_i0;
__pyx_t_17 = __pyx_v_j0;
92: + (self.data[i1,j0] * (d0 - x0) * (y1 - d1)) \
/* "bilinear.pyx":92
* else:
* res = (self.data[i0,j0] * (x1 - d0) * (y1 - d1)) \
* + (self.data[i1,j0] * (d0 - x0) * (y1 - d1)) \ # <<<<<<<<<<<<<<
* + (self.data[i0,j1] * (x1 - d0) * (d1 - y0)) \
* + (self.data[i1,j1] * (d0 - x0) * (d1 - y0))
*/
if (unlikely(!__pyx_v_self->data.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");{__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L4;}}
__pyx_t_18 = __pyx_v_i1;
__pyx_t_19 = __pyx_v_j0;
93: + (self.data[i0,j1] * (x1 - d0) * (d1 - y0)) \
/* "bilinear.pyx":93
* res = (self.data[i0,j0] * (x1 - d0) * (y1 - d1)) \
* + (self.data[i1,j0] * (d0 - x0) * (y1 - d1)) \
* + (self.data[i0,j1] * (x1 - d0) * (d1 - y0)) \ # <<<<<<<<<<<<<<
* + (self.data[i1,j1] * (d0 - x0) * (d1 - y0))
* return - res
*/
if (unlikely(!__pyx_v_self->data.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");{__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L4;}}
__pyx_t_20 = __pyx_v_i0;
__pyx_t_21 = __pyx_v_j1;
94: + (self.data[i1,j1] * (d0 - x0) * (d1 - y0))
/* "bilinear.pyx":94
* + (self.data[i1,j0] * (d0 - x0) * (y1 - d1)) \
* + (self.data[i0,j1] * (x1 - d0) * (d1 - y0)) \
* + (self.data[i1,j1] * (d0 - x0) * (d1 - y0)) # <<<<<<<<<<<<<<
* return - res
*
*/
if (unlikely(!__pyx_v_self->data.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");{__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L4;}}
__pyx_t_22 = __pyx_v_i1;
__pyx_t_23 = __pyx_v_j1;
__pyx_v_res = ((((((*((float *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_self->data.data + __pyx_t_16 * __pyx_v_self->data.strides[0]) ) + __pyx_t_17 * __pyx_v_self->data.strides[1]) ))) * (__pyx_v_x1 - __pyx_v_d0)) * (__pyx_v_y1 - __pyx_v_d1)) + (((*((float *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_self->data.data + __pyx_t_18 * __pyx_v_self->data.strides[0]) ) + __pyx_t_19 * __pyx_v_self->data.strides[1]) ))) * (__pyx_v_d0 - __pyx_v_x0)) * (__pyx_v_y1 - __pyx_v_d1))) + (((*((float *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_self->data.data + __pyx_t_20 * __pyx_v_self->data.strides[0]) ) + __pyx_t_21 * __pyx_v_self->data.strides[1]) ))) * (__pyx_v_x1 - __pyx_v_d0)) * (__pyx_v_d1 - __pyx_v_y0))) + (((*((float *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_self->data.data + __pyx_t_22 * __pyx_v_self->data.strides[0]) ) + __pyx_t_23 * __pyx_v_self->data.strides[1]) ))) * (__pyx_v_d0 - __pyx_v_x0)) * (__pyx_v_d1 - __pyx_v_y0)));
}
__pyx_L6:;
}
95: return - res
/* "bilinear.pyx":95 * + (self.data[i0,j1] * (x1 - d0) * (d1 - y0)) \ * + (self.data[i1,j1] * (d0 - x0) * (d1 - y0)) * return - res #<<<<<<<<<<<<<<* * @cython.boundscheck(False) */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyFloat_FromDouble((-__pyx_v_res)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("bilinear.Bilinear.f_cy", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_pw_8bilinear_8Bilinear_5local_maxi(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static char __pyx_doc_8bilinear_8Bilinear_4local_maxi[] = "\n Return the local maximum ... with sub-pixel refinement\n \n @param x: 2-tuple of int\n @param w: half with of the window: 1 or 2 are adviced\n @return: 2-tuple of int with the nearest local maximum\n\n Sub-pixel refinement:\n Second order taylor expansion of the function; first derivative is nul\n delta = x-i = -Inverse[Hessian].gradient \n "; static PyObject *__pyx_pw_8bilinear_8Bilinear_5local_maxi(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_x = 0; int __pyx_v_w; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("local_maxi (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__x,&__pyx_n_s__w,0}; PyObject* values[2] = {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 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__x)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; case 1: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__w); if (value) { values[1] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "local_maxi")<0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); break; default: goto __pyx_L5_argtuple_error; } } __pyx_v_x = values[0]; if (values[1]) { __pyx_v_w = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_w == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } else { __pyx_v_w = ((int)1); } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("local_maxi", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("bilinear.Bilinear.local_maxi", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_8bilinear_8Bilinear_4local_maxi(((struct __pyx_obj_8bilinear_Bilinear *)__pyx_v_self), __pyx_v_x, __pyx_v_w); int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannyFinishContext(); return __pyx_r; }
96:
97: @cython.boundscheck(False)
98: @cython.wraparound(False)
99: @cython.cdivision(True)
100: def local_maxi(self, x, int w=1):
/* "bilinear.pyx":100 * @cython.wraparound(False) * @cython.cdivision(True) * def local_maxi(self, x, int w=1): #<<<<<<<<<<<<<<* """ * Return the local maximum ... with sub-pixel refinement */ static PyObject *__pyx_pf_8bilinear_8Bilinear_4local_maxi(struct __pyx_obj_8bilinear_Bilinear *__pyx_v_self, PyObject *__pyx_v_x, int __pyx_v_w) { int __pyx_v_current0; int __pyx_v_current1; int __pyx_v_i0; int __pyx_v_i1; int __pyx_v_start0; int __pyx_v_stop0; int __pyx_v_start1; int __pyx_v_stop1; int __pyx_v_new0; int __pyx_v_new1; int __pyx_v_cnt; int __pyx_v_width0; int __pyx_v_width1; float __pyx_v_tmp; float __pyx_v_value; float __pyx_v_current_value; float __pyx_v_sum0; float __pyx_v_sum1; float __pyx_v_sum; float __pyx_v_a00; float __pyx_v_a01; float __pyx_v_a02; float __pyx_v_a10; float __pyx_v_a11; float __pyx_v_a12; float __pyx_v_a20; float __pyx_v_a21; float __pyx_v_a22; float __pyx_v_d00; float __pyx_v_d11; float __pyx_v_d01; float __pyx_v_denom; PyObject *__pyx_v_delta0 = NULL; PyObject *__pyx_v_delta1 = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("local_maxi", 0);
101: """
102: Return the local maximum ... with sub-pixel refinement
103:
104: @param x: 2-tuple of int
105: @param w: half with of the window: 1 or 2 are adviced
106: @return: 2-tuple of int with the nearest local maximum
107:
108: Sub-pixel refinement:
109: Second order taylor expansion of the function; first derivative is nul
110: delta = x-i = -Inverse[Hessian].gradient
111: """
112: cdef int current0 = x[0]
/* "bilinear.pyx":112 * delta = x-i = -Inverse[Hessian].gradient * """ * cdef int current0 = x[0] #<<<<<<<<<<<<<<* cdef int current1 = x[1] * cdef int i0, i1, start0, stop0, start1, stop1, new0, new1, cnt=0, width0=w, width1=w */ __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_x, 0, sizeof(long), PyInt_FromLong, 0, 0, 0); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_current0 = __pyx_t_2;
113: cdef int current1 = x[1]
/* "bilinear.pyx":113 * """ * cdef int current0 = x[0] * cdef int current1 = x[1] #<<<<<<<<<<<<<<* cdef int i0, i1, start0, stop0, start1, stop1, new0, new1, cnt=0, width0=w, width1=w * cdef float tmp, value, current_value, sum0=0, sum1=0, sum=0 */ __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_x, 1, sizeof(long), PyInt_FromLong, 0, 0, 0); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_current1 = __pyx_t_2;
114: cdef int i0, i1, start0, stop0, start1, stop1, new0, new1, cnt=0, width0=w, width1=w
/* "bilinear.pyx":114 * cdef int current0 = x[0] * cdef int current1 = x[1] * cdef int i0, i1, start0, stop0, start1, stop1, new0, new1, cnt=0, width0=w, width1=w #<<<<<<<<<<<<<<* cdef float tmp, value, current_value, sum0=0, sum1=0, sum=0 * value = self.data[current0,current1] */ __pyx_v_cnt = 0; __pyx_v_width0 = __pyx_v_w; __pyx_v_width1 = __pyx_v_w;
115: cdef float tmp, value, current_value, sum0=0, sum1=0, sum=0
/* "bilinear.pyx":115 * cdef int current1 = x[1] * cdef int i0, i1, start0, stop0, start1, stop1, new0, new1, cnt=0, width0=w, width1=w * cdef float tmp, value, current_value, sum0=0, sum1=0, sum=0 #<<<<<<<<<<<<<<* value = self.data[current0,current1] * current_value = value-1.0 */ __pyx_v_sum0 = 0.0; __pyx_v_sum1 = 0.0; __pyx_v_sum = 0.0;
116: value = self.data[current0,current1]
/* "bilinear.pyx":116 * cdef int i0, i1, start0, stop0, start1, stop1, new0, new1, cnt=0, width0=w, width1=w * cdef float tmp, value, current_value, sum0=0, sum1=0, sum=0 * value = self.data[current0,current1] #<<<<<<<<<<<<<<* current_value = value-1.0 * new0,new1 = current0,current1 */ if (unlikely(!__pyx_v_self->data.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");{__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}} __pyx_t_2 = __pyx_v_current0; __pyx_t_3 = __pyx_v_current1; __pyx_v_value = (*((float *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_self->data.data + __pyx_t_2 * __pyx_v_self->data.strides[0]) ) + __pyx_t_3 * __pyx_v_self->data.strides[1]) )));
117: current_value = value-1.0
/* "bilinear.pyx":117 * cdef float tmp, value, current_value, sum0=0, sum1=0, sum=0 * value = self.data[current0,current1] * current_value = value-1.0 #<<<<<<<<<<<<<<* new0,new1 = current0,current1 * with nogil: */ __pyx_v_current_value = (__pyx_v_value - 1.0);
118: new0,new1 = current0,current1
/* "bilinear.pyx":118 * value = self.data[current0,current1] * current_value = value-1.0 * new0,new1 = current0,current1 #<<<<<<<<<<<<<<* with nogil: * while value>current_value: */ __pyx_t_4 = __pyx_v_current0; __pyx_t_5 = __pyx_v_current1; __pyx_v_new0 = __pyx_t_4; __pyx_v_new1 = __pyx_t_5;
119: with nogil:
/* "bilinear.pyx":119 * current_value = value-1.0 * new0,new1 = current0,current1 * with nogil: #<<<<<<<<<<<<<<* while value>current_value: * current_value=value */ { #ifdef WITH_THREAD PyThreadState *_save; Py_UNBLOCK_THREADS #endif /*try:*/ { /* "bilinear.pyx":119 * current_value = value-1.0 * new0,new1 = current0,current1 * with nogil: #<<<<<<<<<<<<<<* while value>current_value: * current_value=value */ /*finally:*/ { int __pyx_why; __pyx_why = 0; goto __pyx_L5; __pyx_L4: __pyx_why = 4; goto __pyx_L5; __pyx_L5:; #ifdef WITH_THREAD Py_BLOCK_THREADS #endif switch (__pyx_why) { case 4: goto __pyx_L1_error; } } }
120: while value>current_value:
/* "bilinear.pyx":120
* new0,new1 = current0,current1
* with nogil:
* while value>current_value: # <<<<<<<<<<<<<<
* current_value=value
* cnt+=1
*/
while (1) {
__pyx_t_6 = (__pyx_v_value > __pyx_v_current_value);
if (!__pyx_t_6) break;
121: current_value=value
/* "bilinear.pyx":121
* with nogil:
* while value>current_value:
* current_value=value # <<<<<<<<<<<<<<
* cnt+=1
* if current0 < width0:
*/
__pyx_v_current_value = __pyx_v_value;
122: cnt+=1
/* "bilinear.pyx":122
* while value>current_value:
* current_value=value
* cnt+=1 # <<<<<<<<<<<<<<
* if current0 < width0:
* start0 = 0
*/
__pyx_v_cnt = (__pyx_v_cnt + 1);
123: if current0 < width0:
/* "bilinear.pyx":123
* current_value=value
* cnt+=1
* if current0 < width0: # <<<<<<<<<<<<<<
* start0 = 0
* else:
*/
__pyx_t_6 = (__pyx_v_current0 < __pyx_v_width0);
if (__pyx_t_6) {
124: start0 = 0
/* "bilinear.pyx":124
* cnt+=1
* if current0 < width0:
* start0 = 0 # <<<<<<<<<<<<<<
* else:
* start0 = current0 - width0
*/
__pyx_v_start0 = 0;
goto __pyx_L8;
}
/*else*/ {
125: else:
126: start0 = current0 - width0
/* "bilinear.pyx":126
* start0 = 0
* else:
* start0 = current0 - width0 # <<<<<<<<<<<<<<
* if current0 >= self.d0_max - width0:
* stop0 = self.d0_max
*/
__pyx_v_start0 = (__pyx_v_current0 - __pyx_v_width0);
}
__pyx_L8:;
127: if current0 >= self.d0_max - width0:
/* "bilinear.pyx":127
* else:
* start0 = current0 - width0
* if current0 >= self.d0_max - width0: # <<<<<<<<<<<<<<
* stop0 = self.d0_max
* else:
*/
__pyx_t_6 = (__pyx_v_current0 >= (__pyx_v_self->d0_max - __pyx_v_width0));
if (__pyx_t_6) {
128: stop0 = self.d0_max
/* "bilinear.pyx":128
* start0 = current0 - width0
* if current0 >= self.d0_max - width0:
* stop0 = self.d0_max # <<<<<<<<<<<<<<
* else:
* stop0 = current0 + width0
*/
__pyx_t_7 = __pyx_v_self->d0_max;
__pyx_v_stop0 = __pyx_t_7;
goto __pyx_L9;
}
/*else*/ {
129: else:
130: stop0 = current0 + width0
/* "bilinear.pyx":130
* stop0 = self.d0_max
* else:
* stop0 = current0 + width0 # <<<<<<<<<<<<<<
* if current1 < width1:
* start1 = 0
*/
__pyx_v_stop0 = (__pyx_v_current0 + __pyx_v_width0);
}
__pyx_L9:;
131: if current1 < width1:
/* "bilinear.pyx":131
* else:
* stop0 = current0 + width0
* if current1 < width1: # <<<<<<<<<<<<<<
* start1 = 0
* else:
*/
__pyx_t_6 = (__pyx_v_current1 < __pyx_v_width1);
if (__pyx_t_6) {
132: start1 = 0
/* "bilinear.pyx":132
* stop0 = current0 + width0
* if current1 < width1:
* start1 = 0 # <<<<<<<<<<<<<<
* else:
* start1 = current1 - width1
*/
__pyx_v_start1 = 0;
goto __pyx_L10;
}
/*else*/ {
133: else:
134: start1 = current1 - width1
/* "bilinear.pyx":134
* start1 = 0
* else:
* start1 = current1 - width1 # <<<<<<<<<<<<<<
* if current1 >= self.d1_max - width1:
* stop1=self.d1_max
*/
__pyx_v_start1 = (__pyx_v_current1 - __pyx_v_width1);
}
__pyx_L10:;
135: if current1 >= self.d1_max - width1:
/* "bilinear.pyx":135
* else:
* start1 = current1 - width1
* if current1 >= self.d1_max - width1: # <<<<<<<<<<<<<<
* stop1=self.d1_max
* else:
*/
__pyx_t_6 = (__pyx_v_current1 >= (__pyx_v_self->d1_max - __pyx_v_width1));
if (__pyx_t_6) {
136: stop1=self.d1_max
/* "bilinear.pyx":136
* start1 = current1 - width1
* if current1 >= self.d1_max - width1:
* stop1=self.d1_max # <<<<<<<<<<<<<<
* else:
* stop1 = current1 + width1
*/
__pyx_t_7 = __pyx_v_self->d1_max;
__pyx_v_stop1 = __pyx_t_7;
goto __pyx_L11;
}
/*else*/ {
137: else:
138: stop1 = current1 + width1
/* "bilinear.pyx":138
* stop1=self.d1_max
* else:
* stop1 = current1 + width1 # <<<<<<<<<<<<<<
* for i0 in range(start0, stop0+1):
* for i1 in range(start1, stop1+1):
*/
__pyx_v_stop1 = (__pyx_v_current1 + __pyx_v_width1);
}
__pyx_L11:;
139: for i0 in range(start0, stop0+1):
/* "bilinear.pyx":139
* else:
* stop1 = current1 + width1
* for i0 in range(start0, stop0+1): # <<<<<<<<<<<<<<
* for i1 in range(start1, stop1+1):
* tmp=self.data[i0,i1]
*/
__pyx_t_8 = (__pyx_v_stop0 + 1);
for (__pyx_t_5 = __pyx_v_start0; __pyx_t_5 < __pyx_t_8; __pyx_t_5+=1) {
__pyx_v_i0 = __pyx_t_5;
140: for i1 in range(start1, stop1+1):
/* "bilinear.pyx":140
* stop1 = current1 + width1
* for i0 in range(start0, stop0+1):
* for i1 in range(start1, stop1+1): # <<<<<<<<<<<<<<
* tmp=self.data[i0,i1]
* if tmp>current_value:
*/
__pyx_t_9 = (__pyx_v_stop1 + 1);
for (__pyx_t_4 = __pyx_v_start1; __pyx_t_4 < __pyx_t_9; __pyx_t_4+=1) {
__pyx_v_i1 = __pyx_t_4;
141: tmp=self.data[i0,i1]
/* "bilinear.pyx":141
* for i0 in range(start0, stop0+1):
* for i1 in range(start1, stop1+1):
* tmp=self.data[i0,i1] # <<<<<<<<<<<<<<
* if tmp>current_value:
* new0,new1=i0,i1
*/
if (unlikely(!__pyx_v_self->data.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");{__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L4;}}
__pyx_t_10 = __pyx_v_i0;
__pyx_t_11 = __pyx_v_i1;
__pyx_v_tmp = (*((float *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_self->data.data + __pyx_t_10 * __pyx_v_self->data.strides[0]) ) + __pyx_t_11 * __pyx_v_self->data.strides[1]) )));
142: if tmp>current_value:
/* "bilinear.pyx":142
* for i1 in range(start1, stop1+1):
* tmp=self.data[i0,i1]
* if tmp>current_value: # <<<<<<<<<<<<<<
* new0,new1=i0,i1
* value = tmp
*/
__pyx_t_6 = (__pyx_v_tmp > __pyx_v_current_value);
if (__pyx_t_6) {
143: new0,new1=i0,i1
/* "bilinear.pyx":143
* tmp=self.data[i0,i1]
* if tmp>current_value:
* new0,new1=i0,i1 # <<<<<<<<<<<<<<
* value = tmp
* current0,current1=new0,new1
*/
__pyx_t_12 = __pyx_v_i0;
__pyx_t_13 = __pyx_v_i1;
__pyx_v_new0 = __pyx_t_12;
__pyx_v_new1 = __pyx_t_13;
144: value = tmp
/* "bilinear.pyx":144
* if tmp>current_value:
* new0,new1=i0,i1
* value = tmp # <<<<<<<<<<<<<<
* current0,current1=new0,new1
*
*/
__pyx_v_value = __pyx_v_tmp;
goto __pyx_L16;
}
__pyx_L16:;
}
}
145: current0,current1=new0,new1
/* "bilinear.pyx":145
* new0,new1=i0,i1
* value = tmp
* current0,current1=new0,new1 # <<<<<<<<<<<<<<
*
* cdef float a00, a01, a02, a10, a11, a12, a20, a21, a22 # coefficients of the array
*/
__pyx_t_5 = __pyx_v_new0;
__pyx_t_4 = __pyx_v_new1;
__pyx_v_current0 = __pyx_t_5;
__pyx_v_current1 = __pyx_t_4;
}
}
146:
147: cdef float a00, a01, a02, a10, a11, a12, a20, a21, a22 # coefficients of the array
148: # cdef float g0, g1 # gradient values
149: cdef float d00, d11, d01, denom # Hessian coefficient
150: # print(current0,current1)
151: if (stop0>current0) and (current0>start0) and (stop1>current1) and (current1>start1):
/* "bilinear.pyx":151 * cdef float d00, d11, d01, denom # Hessian coefficient * # print(current0,current1) * if (stop0>current0) and (current0>start0) and (stop1>current1) and (current1>start1): #<<<<<<<<<<<<<<* #Use second order polynomial taylor expansion * a00 = self.data[current0-1,current1-1] */ __pyx_t_6 = (__pyx_v_stop0 > __pyx_v_current0); if (__pyx_t_6) { __pyx_t_14 = (__pyx_v_current0 > __pyx_v_start0); if (__pyx_t_14) { __pyx_t_15 = (__pyx_v_stop1 > __pyx_v_current1); if (__pyx_t_15) { __pyx_t_16 = (__pyx_v_current1 > __pyx_v_start1); __pyx_t_17 = __pyx_t_16; } else { __pyx_t_17 = __pyx_t_15; } __pyx_t_15 = __pyx_t_17; } else { __pyx_t_15 = __pyx_t_14; } __pyx_t_14 = __pyx_t_15; } else { __pyx_t_14 = __pyx_t_6; } if (__pyx_t_14) {
152: #Use second order polynomial taylor expansion
153: a00 = self.data[current0-1,current1-1]
/* "bilinear.pyx":153
* if (stop0>current0) and (current0>start0) and (stop1>current1) and (current1>start1):
* #Use second order polynomial taylor expansion
* a00 = self.data[current0-1,current1-1] # <<<<<<<<<<<<<<
* a01 = self.data[current0-1,current1 ]
* a02 = self.data[current0-1,current1+1]
*/
if (unlikely(!__pyx_v_self->data.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");{__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}}
__pyx_t_8 = (__pyx_v_current0 - 1);
__pyx_t_9 = (__pyx_v_current1 - 1);
__pyx_v_a00 = (*((float *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_self->data.data + __pyx_t_8 * __pyx_v_self->data.strides[0]) ) + __pyx_t_9 * __pyx_v_self->data.strides[1]) )));
154: a01 = self.data[current0-1,current1 ]
/* "bilinear.pyx":154
* #Use second order polynomial taylor expansion
* a00 = self.data[current0-1,current1-1]
* a01 = self.data[current0-1,current1 ] # <<<<<<<<<<<<<<
* a02 = self.data[current0-1,current1+1]
* a10 = self.data[current0 ,current1-1]
*/
if (unlikely(!__pyx_v_self->data.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");{__pyx_filename = __pyx_f[0]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;}}
__pyx_t_18 = (__pyx_v_current0 - 1);
__pyx_t_4 = __pyx_v_current1;
__pyx_v_a01 = (*((float *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_self->data.data + __pyx_t_18 * __pyx_v_self->data.strides[0]) ) + __pyx_t_4 * __pyx_v_self->data.strides[1]) )));
155: a02 = self.data[current0-1,current1+1]
/* "bilinear.pyx":155
* a00 = self.data[current0-1,current1-1]
* a01 = self.data[current0-1,current1 ]
* a02 = self.data[current0-1,current1+1] # <<<<<<<<<<<<<<
* a10 = self.data[current0 ,current1-1]
* a11 = self.data[current0 ,current1 ]
*/
if (unlikely(!__pyx_v_self->data.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");{__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}}
__pyx_t_19 = (__pyx_v_current0 - 1);
__pyx_t_20 = (__pyx_v_current1 + 1);
__pyx_v_a02 = (*((float *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_self->data.data + __pyx_t_19 * __pyx_v_self->data.strides[0]) ) + __pyx_t_20 * __pyx_v_self->data.strides[1]) )));
156: a10 = self.data[current0 ,current1-1]
/* "bilinear.pyx":156
* a01 = self.data[current0-1,current1 ]
* a02 = self.data[current0-1,current1+1]
* a10 = self.data[current0 ,current1-1] # <<<<<<<<<<<<<<
* a11 = self.data[current0 ,current1 ]
* a12 = self.data[current0 ,current1+1]
*/
if (unlikely(!__pyx_v_self->data.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");{__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}}
__pyx_t_5 = __pyx_v_current0;
__pyx_t_21 = (__pyx_v_current1 - 1);
__pyx_v_a10 = (*((float *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_self->data.data + __pyx_t_5 * __pyx_v_self->data.strides[0]) ) + __pyx_t_21 * __pyx_v_self->data.strides[1]) )));
157: a11 = self.data[current0 ,current1 ]
/* "bilinear.pyx":157
* a02 = self.data[current0-1,current1+1]
* a10 = self.data[current0 ,current1-1]
* a11 = self.data[current0 ,current1 ] # <<<<<<<<<<<<<<
* a12 = self.data[current0 ,current1+1]
* a20 = self.data[current0+1,current1-1]
*/
if (unlikely(!__pyx_v_self->data.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");{__pyx_filename = __pyx_f[0]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}}
__pyx_t_13 = __pyx_v_current0;
__pyx_t_12 = __pyx_v_current1;
__pyx_v_a11 = (*((float *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_self->data.data + __pyx_t_13 * __pyx_v_self->data.strides[0]) ) + __pyx_t_12 * __pyx_v_self->data.strides[1]) )));
158: a12 = self.data[current0 ,current1+1]
/* "bilinear.pyx":158
* a10 = self.data[current0 ,current1-1]
* a11 = self.data[current0 ,current1 ]
* a12 = self.data[current0 ,current1+1] # <<<<<<<<<<<<<<
* a20 = self.data[current0+1,current1-1]
* a21 = self.data[current0+1,current1 ]
*/
if (unlikely(!__pyx_v_self->data.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");{__pyx_filename = __pyx_f[0]; __pyx_lineno = 158; __pyx_clineno = __LINE__; goto __pyx_L1_error;}}
__pyx_t_22 = __pyx_v_current0;
__pyx_t_23 = (__pyx_v_current1 + 1);
__pyx_v_a12 = (*((float *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_self->data.data + __pyx_t_22 * __pyx_v_self->data.strides[0]) ) + __pyx_t_23 * __pyx_v_self->data.strides[1]) )));
159: a20 = self.data[current0+1,current1-1]
/* "bilinear.pyx":159
* a11 = self.data[current0 ,current1 ]
* a12 = self.data[current0 ,current1+1]
* a20 = self.data[current0+1,current1-1] # <<<<<<<<<<<<<<
* a21 = self.data[current0+1,current1 ]
* a22 = self.data[current0+1,current1-1]
*/
if (unlikely(!__pyx_v_self->data.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");{__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}}
__pyx_t_24 = (__pyx_v_current0 + 1);
__pyx_t_25 = (__pyx_v_current1 - 1);
__pyx_v_a20 = (*((float *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_self->data.data + __pyx_t_24 * __pyx_v_self->data.strides[0]) ) + __pyx_t_25 * __pyx_v_self->data.strides[1]) )));
160: a21 = self.data[current0+1,current1 ]
/* "bilinear.pyx":160
* a12 = self.data[current0 ,current1+1]
* a20 = self.data[current0+1,current1-1]
* a21 = self.data[current0+1,current1 ] # <<<<<<<<<<<<<<
* a22 = self.data[current0+1,current1-1]
* # g0 = (a21 - a01)/2.0
*/
if (unlikely(!__pyx_v_self->data.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");{__pyx_filename = __pyx_f[0]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}}
__pyx_t_26 = (__pyx_v_current0 + 1);
__pyx_t_27 = __pyx_v_current1;
__pyx_v_a21 = (*((float *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_self->data.data + __pyx_t_26 * __pyx_v_self->data.strides[0]) ) + __pyx_t_27 * __pyx_v_self->data.strides[1]) )));
161: a22 = self.data[current0+1,current1-1]
/* "bilinear.pyx":161
* a20 = self.data[current0+1,current1-1]
* a21 = self.data[current0+1,current1 ]
* a22 = self.data[current0+1,current1-1] # <<<<<<<<<<<<<<
* # g0 = (a21 - a01)/2.0
* # g1 = (a12 - a10)/2.0
*/
if (unlikely(!__pyx_v_self->data.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");{__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}}
__pyx_t_28 = (__pyx_v_current0 + 1);
__pyx_t_29 = (__pyx_v_current1 - 1);
__pyx_v_a22 = (*((float *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_self->data.data + __pyx_t_28 * __pyx_v_self->data.strides[0]) ) + __pyx_t_29 * __pyx_v_self->data.strides[1]) )));
162: # g0 = (a21 - a01)/2.0
163: # g1 = (a12 - a10)/2.0
164: d00 = a12 - 2.0*a11 + a10
/* "bilinear.pyx":164
* # g0 = (a21 - a01)/2.0
* # g1 = (a12 - a10)/2.0
* d00 = a12 - 2.0*a11 + a10 # <<<<<<<<<<<<<<
* d11 = a21 - 2.0*a11 + a01
* d01 = (a00 - a02 - a20 + a22)/4.0
*/
__pyx_v_d00 = ((__pyx_v_a12 - (2.0 * __pyx_v_a11)) + __pyx_v_a10);
165: d11 = a21 - 2.0*a11 + a01
/* "bilinear.pyx":165
* # g1 = (a12 - a10)/2.0
* d00 = a12 - 2.0*a11 + a10
* d11 = a21 - 2.0*a11 + a01 # <<<<<<<<<<<<<<
* d01 = (a00 - a02 - a20 + a22)/4.0
* denom = 2.0*(d00*d11-d01*d01)
*/
__pyx_v_d11 = ((__pyx_v_a21 - (2.0 * __pyx_v_a11)) + __pyx_v_a01);
166: d01 = (a00 - a02 - a20 + a22)/4.0
/* "bilinear.pyx":166
* d00 = a12 - 2.0*a11 + a10
* d11 = a21 - 2.0*a11 + a01
* d01 = (a00 - a02 - a20 + a22)/4.0 # <<<<<<<<<<<<<<
* denom = 2.0*(d00*d11-d01*d01)
* if abs(denom)<1e-10:
*/
__pyx_v_d01 = ((((__pyx_v_a00 - __pyx_v_a02) - __pyx_v_a20) + __pyx_v_a22) / 4.0);
167: denom = 2.0*(d00*d11-d01*d01)
/* "bilinear.pyx":167
* d11 = a21 - 2.0*a11 + a01
* d01 = (a00 - a02 - a20 + a22)/4.0
* denom = 2.0*(d00*d11-d01*d01) # <<<<<<<<<<<<<<
* if abs(denom)<1e-10:
* print("Singular determinant, Hessian undefined")
*/
__pyx_v_denom = (2.0 * ((__pyx_v_d00 * __pyx_v_d11) - (__pyx_v_d01 * __pyx_v_d01)));
168: if abs(denom)<1e-10:
/* "bilinear.pyx":168
* d01 = (a00 - a02 - a20 + a22)/4.0
* denom = 2.0*(d00*d11-d01*d01)
* if abs(denom)<1e-10: # <<<<<<<<<<<<<<
* print("Singular determinant, Hessian undefined")
* else:
*/
__pyx_t_14 = (fabsf(__pyx_v_denom) < 1e-10);
if (__pyx_t_14) {
169: print("Singular determinant, Hessian undefined")
/* "bilinear.pyx":169
* denom = 2.0*(d00*d11-d01*d01)
* if abs(denom)<1e-10:
* print("Singular determinant, Hessian undefined") # <<<<<<<<<<<<<<
* else:
* delta0 = ((a12 - a10)*d01 + (a01 - a21)*d11)/denom
*/
if (__Pyx_PrintOne(0, ((PyObject *)__pyx_kp_s_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L19;
}
/*else*/ {
170: else:
171: delta0 = ((a12 - a10)*d01 + (a01 - a21)*d11)/denom
/* "bilinear.pyx":171
* print("Singular determinant, Hessian undefined")
* else:
* delta0 = ((a12 - a10)*d01 + (a01 - a21)*d11)/denom # <<<<<<<<<<<<<<
* delta1 = ((a10 - a12)*d00 + (a21 - a01)*d01)/denom
* # print(delta0,delta1)
*/
__pyx_t_1 = PyFloat_FromDouble(((((__pyx_v_a12 - __pyx_v_a10) * __pyx_v_d01) + ((__pyx_v_a01 - __pyx_v_a21) * __pyx_v_d11)) / __pyx_v_denom)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__pyx_v_delta0 = __pyx_t_1;
__pyx_t_1 = 0;
172: delta1 = ((a10 - a12)*d00 + (a21 - a01)*d01)/denom
/* "bilinear.pyx":172
* else:
* delta0 = ((a12 - a10)*d01 + (a01 - a21)*d11)/denom
* delta1 = ((a10 - a12)*d00 + (a21 - a01)*d01)/denom # <<<<<<<<<<<<<<
* # print(delta0,delta1)
* if abs(delta0)<=1.0 and abs(delta1)<=1.0: #Result is OK is nower than 0.5.
*/
__pyx_t_1 = PyFloat_FromDouble(((((__pyx_v_a10 - __pyx_v_a12) * __pyx_v_d00) + ((__pyx_v_a21 - __pyx_v_a01) * __pyx_v_d01)) / __pyx_v_denom)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__pyx_v_delta1 = __pyx_t_1;
__pyx_t_1 = 0;
173: # print(delta0,delta1)
174: if abs(delta0)<=1.0 and abs(delta1)<=1.0: #Result is OK is nower than 0.5.
/* "bilinear.pyx":174
* delta1 = ((a10 - a12)*d00 + (a21 - a01)*d01)/denom
* # print(delta0,delta1)
* if abs(delta0)<=1.0 and abs(delta1)<=1.0: #Result is OK is nower than 0.5. # <<<<<<<<<<<<<<
* return (float(current0) + delta0, float(current1) + delta1)
* else:
*/
__pyx_t_1 = PyNumber_Absolute(__pyx_v_delta0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_30 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_t_30)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_30);
__pyx_t_31 = PyObject_RichCompare(__pyx_t_1, __pyx_t_30, Py_LE); __Pyx_XGOTREF(__pyx_t_31); if (unlikely(!__pyx_t_31)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0;
__pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_31); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0;
if (__pyx_t_14) {
__pyx_t_31 = PyNumber_Absolute(__pyx_v_delta1); if (unlikely(!__pyx_t_31)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_31);
__pyx_t_30 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_t_30)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_30);
__pyx_t_1 = PyObject_RichCompare(__pyx_t_31, __pyx_t_30, Py_LE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0;
__Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0;
__pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_15 = __pyx_t_6;
} else {
__pyx_t_15 = __pyx_t_14;
}
if (__pyx_t_15) {
175: return (float(current0) + delta0, float(current1) + delta1)
/* "bilinear.pyx":175
* # print(delta0,delta1)
* if abs(delta0)<=1.0 and abs(delta1)<=1.0: #Result is OK is nower than 0.5.
* return (float(current0) + delta0, float(current1) + delta1) # <<<<<<<<<<<<<<
* else:
* print("Failed to find root using second order expansion")
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = PyFloat_FromDouble(((double)__pyx_v_current0)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_30 = PyNumber_Add(__pyx_t_1, __pyx_v_delta0); if (unlikely(!__pyx_t_30)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_30);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_1 = PyFloat_FromDouble(((double)__pyx_v_current1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_31 = PyNumber_Add(__pyx_t_1, __pyx_v_delta1); if (unlikely(!__pyx_t_31)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_31);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_30);
__Pyx_GIVEREF(__pyx_t_30);
PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_31);
__Pyx_GIVEREF(__pyx_t_31);
__pyx_t_30 = 0;
__pyx_t_31 = 0;
__pyx_r = ((PyObject *)__pyx_t_1);
__pyx_t_1 = 0;
goto __pyx_L0;
goto __pyx_L20;
}
/*else*/ {
176: else:
177: print("Failed to find root using second order expansion")
/* "bilinear.pyx":177
* return (float(current0) + delta0, float(current1) + delta1)
* else:
* print("Failed to find root using second order expansion") # <<<<<<<<<<<<<<
* #refinement of the position by a simple center of mass of the last valid region used
* for i0 in range(start0, stop0+1):
*/
if (__Pyx_PrintOne(0, ((PyObject *)__pyx_kp_s_2)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
__pyx_L20:;
}
__pyx_L19:;
goto __pyx_L18;
}
__pyx_L18:;
178: #refinement of the position by a simple center of mass of the last valid region used
179: for i0 in range(start0, stop0+1):
/* "bilinear.pyx":179
* print("Failed to find root using second order expansion")
* #refinement of the position by a simple center of mass of the last valid region used
* for i0 in range(start0, stop0+1): # <<<<<<<<<<<<<<
* for i1 in range(start1, stop1+1):
* tmp = self.data[i0,i1]
*/
__pyx_t_32 = (__pyx_v_stop0 + 1);
for (__pyx_t_33 = __pyx_v_start0; __pyx_t_33 < __pyx_t_32; __pyx_t_33+=1) {
__pyx_v_i0 = __pyx_t_33;
180: for i1 in range(start1, stop1+1):
/* "bilinear.pyx":180
* #refinement of the position by a simple center of mass of the last valid region used
* for i0 in range(start0, stop0+1):
* for i1 in range(start1, stop1+1): # <<<<<<<<<<<<<<
* tmp = self.data[i0,i1]
* sum0 += tmp * i0
*/
__pyx_t_34 = (__pyx_v_stop1 + 1);
for (__pyx_t_35 = __pyx_v_start1; __pyx_t_35 < __pyx_t_34; __pyx_t_35+=1) {
__pyx_v_i1 = __pyx_t_35;
181: tmp = self.data[i0,i1]
/* "bilinear.pyx":181
* for i0 in range(start0, stop0+1):
* for i1 in range(start1, stop1+1):
* tmp = self.data[i0,i1] # <<<<<<<<<<<<<<
* sum0 += tmp * i0
* sum1 += tmp * i1
*/
if (unlikely(!__pyx_v_self->data.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");{__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}}
__pyx_t_36 = __pyx_v_i0;
__pyx_t_37 = __pyx_v_i1;
__pyx_v_tmp = (*((float *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_self->data.data + __pyx_t_36 * __pyx_v_self->data.strides[0]) ) + __pyx_t_37 * __pyx_v_self->data.strides[1]) )));
182: sum0 += tmp * i0
/* "bilinear.pyx":182
* for i1 in range(start1, stop1+1):
* tmp = self.data[i0,i1]
* sum0 += tmp * i0 # <<<<<<<<<<<<<<
* sum1 += tmp * i1
* sum += tmp
*/
__pyx_v_sum0 = (__pyx_v_sum0 + (__pyx_v_tmp * __pyx_v_i0));
183: sum1 += tmp * i1
/* "bilinear.pyx":183
* tmp = self.data[i0,i1]
* sum0 += tmp * i0
* sum1 += tmp * i1 # <<<<<<<<<<<<<<
* sum += tmp
* if sum>0:
*/
__pyx_v_sum1 = (__pyx_v_sum1 + (__pyx_v_tmp * __pyx_v_i1));
184: sum += tmp
/* "bilinear.pyx":184
* sum0 += tmp * i0
* sum1 += tmp * i1
* sum += tmp # <<<<<<<<<<<<<<
* if sum>0:
* #print current0,current1,sum0/sum,sum1/sum
*/
__pyx_v_sum = (__pyx_v_sum + __pyx_v_tmp);
}
}
185: if sum>0:
/* "bilinear.pyx":185 * sum1 += tmp * i1 * sum += tmp * if sum>0: #<<<<<<<<<<<<<<* #print current0,current1,sum0/sum,sum1/sum * return (sum0/sum,sum1/sum) */ __pyx_t_15 = (__pyx_v_sum > 0.0); if (__pyx_t_15) {
186: #print current0,current1,sum0/sum,sum1/sum
187: return (sum0/sum,sum1/sum)
/* "bilinear.pyx":187
* if sum>0:
* #print current0,current1,sum0/sum,sum1/sum
* return (sum0/sum,sum1/sum) # <<<<<<<<<<<<<<
* else:
* return (current0,current1)
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = PyFloat_FromDouble((__pyx_v_sum0 / __pyx_v_sum)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_31 = PyFloat_FromDouble((__pyx_v_sum1 / __pyx_v_sum)); if (unlikely(!__pyx_t_31)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_31);
__pyx_t_30 = PyTuple_New(2); if (unlikely(!__pyx_t_30)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_30);
PyTuple_SET_ITEM(__pyx_t_30, 0, __pyx_t_1);
__Pyx_GIVEREF(__pyx_t_1);
PyTuple_SET_ITEM(__pyx_t_30, 1, __pyx_t_31);
__Pyx_GIVEREF(__pyx_t_31);
__pyx_t_1 = 0;
__pyx_t_31 = 0;
__pyx_r = ((PyObject *)__pyx_t_30);
__pyx_t_30 = 0;
goto __pyx_L0;
goto __pyx_L25;
}
/*else*/ {
188: else:
189: return (current0,current1)
/* "bilinear.pyx":189
* return (sum0/sum,sum1/sum)
* else:
* return (current0,current1) # <<<<<<<<<<<<<<
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_30 = PyInt_FromLong(__pyx_v_current0); if (unlikely(!__pyx_t_30)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_30);
__pyx_t_31 = PyInt_FromLong(__pyx_v_current1); if (unlikely(!__pyx_t_31)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_31);
__pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_30);
__Pyx_GIVEREF(__pyx_t_30);
PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_31);
__Pyx_GIVEREF(__pyx_t_31);
__pyx_t_30 = 0;
__pyx_t_31 = 0;
__pyx_r = ((PyObject *)__pyx_t_1);
__pyx_t_1 = 0;
goto __pyx_L0;
}
__pyx_L25:;
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_30);
__Pyx_XDECREF(__pyx_t_31);
__Pyx_AddTraceback("bilinear.Bilinear.local_maxi", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_delta0);
__Pyx_XDECREF(__pyx_v_delta1);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* Python wrapper */
static CYTHON_UNUSED int __pyx_pw_5numpy_7ndarray_1__getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/
static CYTHON_UNUSED int __pyx_pw_5numpy_7ndarray_1__getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) {
int __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__getbuffer__ (wrapper)", 0);
__pyx_r = __pyx_pf_5numpy_7ndarray___getbuffer__(((PyArrayObject *)__pyx_v_self), ((Py_buffer *)__pyx_v_info), ((int)__pyx_v_flags));
__Pyx_RefNannyFinishContext();
return __pyx_r;
}