Generated by Cython 0.29.26
Yellow lines hint at Python interaction.
Click on a line that starts with a "+" to see the C code that Cython generated for it.
Raw output: simulation.c
+001: import numpy as np
__pyx_t_1 = __Pyx_Import(__pyx_n_s_numpy, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_np, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* … */ __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
002: import cython
003: from libc.string cimport memcmp
004: from libc.math cimport log
005: from libc.stdlib cimport abort, malloc, free
006:
007: # Numpy must be initialized. When using numpy from C or Cython you must
008: # *ALWAYS* do that, or you will have segfaults
+009: np.import_array()
__pyx_t_2 = __pyx_f_5numpy_import_array(); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(0, 9, __pyx_L1_error)
010:
011: # Helper functions
012:
+013: cdef int extend_mode_to_code(str mode) except -1:
static int __pyx_f_6pyrost_3bin_10simulation_extend_mode_to_code(PyObject *__pyx_v_mode) {
int __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("extend_mode_to_code", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_3);
__Pyx_AddTraceback("pyrost.bin.simulation.extend_mode_to_code", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = -1;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
+014: if mode == 'constant':
__pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_v_mode, __pyx_n_u_constant, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 14, __pyx_L1_error) __pyx_t_2 = (__pyx_t_1 != 0); if (__pyx_t_2) { /* … */ }
+015: return EXTEND_CONSTANT
__pyx_r = __pyx_e_6pyrost_3bin_10simulation_EXTEND_CONSTANT;
goto __pyx_L0;
+016: elif mode == 'nearest':
__pyx_t_2 = (__Pyx_PyUnicode_Equals(__pyx_v_mode, __pyx_n_u_nearest, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 16, __pyx_L1_error) __pyx_t_1 = (__pyx_t_2 != 0); if (__pyx_t_1) { /* … */ }
+017: return EXTEND_NEAREST
__pyx_r = __pyx_e_6pyrost_3bin_10simulation_EXTEND_NEAREST;
goto __pyx_L0;
+018: elif mode == 'mirror':
__pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_v_mode, __pyx_n_u_mirror, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 18, __pyx_L1_error) __pyx_t_2 = (__pyx_t_1 != 0); if (__pyx_t_2) { /* … */ }
+019: return EXTEND_MIRROR
__pyx_r = __pyx_e_6pyrost_3bin_10simulation_EXTEND_MIRROR;
goto __pyx_L0;
+020: elif mode == 'reflect':
__pyx_t_2 = (__Pyx_PyUnicode_Equals(__pyx_v_mode, __pyx_n_u_reflect, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 20, __pyx_L1_error) __pyx_t_1 = (__pyx_t_2 != 0); if (__pyx_t_1) { /* … */ }
+021: return EXTEND_REFLECT
__pyx_r = __pyx_e_6pyrost_3bin_10simulation_EXTEND_REFLECT;
goto __pyx_L0;
+022: elif mode == 'wrap':
__pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_v_mode, __pyx_n_u_wrap, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 22, __pyx_L1_error) __pyx_t_2 = (__pyx_t_1 != 0); if (likely(__pyx_t_2)) { /* … */ }
+023: return EXTEND_WRAP
__pyx_r = __pyx_e_6pyrost_3bin_10simulation_EXTEND_WRAP;
goto __pyx_L0;
024: else:
+025: raise RuntimeError('boundary mode not supported')
/*else*/ {
__pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_RuntimeError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 25, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_Raise(__pyx_t_3, 0, 0, 0);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__PYX_ERR(0, 25, __pyx_L1_error)
}
/* … */
__pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_u_boundary_mode_not_supported); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 25, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple_);
__Pyx_GIVEREF(__pyx_tuple_);
026:
+027: cdef np.ndarray check_array(np.ndarray array, int type_num):
static PyArrayObject *__pyx_f_6pyrost_3bin_10simulation_check_array(PyArrayObject *__pyx_v_array, int __pyx_v_type_num) {
PyArrayObject *__pyx_v_out = 0;
int __pyx_v_tn;
PyArrayObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("check_array", 0);
__Pyx_INCREF((PyObject *)__pyx_v_array);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_2);
__Pyx_AddTraceback("pyrost.bin.simulation.check_array", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
__pyx_L0:;
__Pyx_XDECREF((PyObject *)__pyx_v_out);
__Pyx_XDECREF((PyObject *)__pyx_v_array);
__Pyx_XGIVEREF((PyObject *)__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
028: cdef np.ndarray out
+029: cdef int tn = np.PyArray_TYPE(array)
__pyx_v_tn = PyArray_TYPE(__pyx_v_array);
+030: if not np.PyArray_IS_C_CONTIGUOUS(array):
__pyx_t_1 = ((!(PyArray_IS_C_CONTIGUOUS(__pyx_v_array) != 0)) != 0);
if (__pyx_t_1) {
/* … */
}
+031: array = np.PyArray_GETCONTIGUOUS(array)
__pyx_t_2 = ((PyObject *)PyArray_GETCONTIGUOUS(__pyx_v_array)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 31, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF_SET(__pyx_v_array, ((PyArrayObject *)__pyx_t_2)); __pyx_t_2 = 0;
032:
+033: if tn != type_num:
__pyx_t_1 = ((__pyx_v_tn != __pyx_v_type_num) != 0);
if (__pyx_t_1) {
/* … */
goto __pyx_L4;
}
+034: out = np.PyArray_SimpleNew(array.ndim, <np.npy_intp *>array.shape, type_num)
__pyx_t_2 = PyArray_SimpleNew(__pyx_v_array->nd, ((npy_intp *)__pyx_v_array->dimensions), __pyx_v_type_num); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 34, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 34, __pyx_L1_error) __pyx_v_out = ((PyArrayObject *)__pyx_t_2); __pyx_t_2 = 0;
+035: np.PyArray_CastTo(out, array)
(void)(PyArray_CastTo(__pyx_v_out, __pyx_v_array));
036: else:
+037: out = array
/*else*/ {
__Pyx_INCREF(((PyObject *)__pyx_v_array));
__pyx_v_out = __pyx_v_array;
}
__pyx_L4:;
038:
+039: return out
__Pyx_XDECREF(((PyObject *)__pyx_r)); __Pyx_INCREF(((PyObject *)__pyx_v_out)); __pyx_r = __pyx_v_out; goto __pyx_L0;
040:
+041: cdef np.ndarray number_to_array(object num, np.npy_intp rank, int type_num):
static PyArrayObject *__pyx_f_6pyrost_3bin_10simulation_number_to_array(PyObject *__pyx_v_num, npy_intp __pyx_v_rank, int __pyx_v_type_num) {
npy_intp *__pyx_v_dims;
PyArrayObject *__pyx_v_arr = 0;
int __pyx_v_i;
PyArrayObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("number_to_array", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_AddTraceback("pyrost.bin.simulation.number_to_array", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
__pyx_L0:;
__Pyx_XDECREF((PyObject *)__pyx_v_arr);
__Pyx_XGIVEREF((PyObject *)__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
+042: cdef np.npy_intp *dims = [rank,]
__pyx_t_1[0] = __pyx_v_rank; __pyx_v_dims = __pyx_t_1;
+043: cdef np.ndarray arr = <np.ndarray>np.PyArray_SimpleNew(1, dims, type_num)
__pyx_t_2 = PyArray_SimpleNew(1, __pyx_v_dims, __pyx_v_type_num); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 43, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_arr = ((PyArrayObject *)__pyx_t_3); __pyx_t_3 = 0;
044: cdef int i
+045: for i in range(rank):
__pyx_t_4 = __pyx_v_rank;
__pyx_t_5 = __pyx_t_4;
for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) {
__pyx_v_i = __pyx_t_6;
+046: arr[i] = num
if (unlikely(__Pyx_SetItemInt(((PyObject *)__pyx_v_arr), __pyx_v_i, __pyx_v_num, int, 1, __Pyx_PyInt_From_int, 0, 0, 0) < 0)) __PYX_ERR(0, 46, __pyx_L1_error) }
+047: return arr
__Pyx_XDECREF(((PyObject *)__pyx_r)); __Pyx_INCREF(((PyObject *)__pyx_v_arr)); __pyx_r = __pyx_v_arr; goto __pyx_L0;
048:
+049: cdef np.ndarray normalize_sequence(object inp, np.npy_intp rank, int type_num):
static PyArrayObject *__pyx_f_6pyrost_3bin_10simulation_normalize_sequence(PyObject *__pyx_v_inp, npy_intp __pyx_v_rank, int __pyx_v_type_num) {
PyArrayObject *__pyx_v_array = 0;
PyArrayObject *__pyx_v_out = 0;
int __pyx_v_tn;
npy_intp __pyx_v_size;
PyArrayObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("normalize_sequence", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_AddTraceback("pyrost.bin.simulation.normalize_sequence", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
__pyx_L0:;
__Pyx_XDECREF((PyObject *)__pyx_v_array);
__Pyx_XDECREF((PyObject *)__pyx_v_out);
__Pyx_XGIVEREF((PyObject *)__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
050: # If input is a scalar, create a sequence of length equal to the
051: # rank by duplicating the input. If input is a sequence,
052: # check if its length is equal to the length of array.
053: cdef np.ndarray array, out
054: cdef int tn
+055: if np.PyArray_IsAnyScalar(inp):
__pyx_t_1 = (PyArray_IsAnyScalar(__pyx_v_inp) != 0);
if (__pyx_t_1) {
/* … */
goto __pyx_L3;
}
+056: out = number_to_array(inp, rank, type_num)
__pyx_t_2 = ((PyObject *)__pyx_f_6pyrost_3bin_10simulation_number_to_array(__pyx_v_inp, __pyx_v_rank, __pyx_v_type_num)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 56, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_out = ((PyArrayObject *)__pyx_t_2); __pyx_t_2 = 0;
057:
+058: elif np.PyArray_Check(inp):
__pyx_t_1 = (PyArray_Check(__pyx_v_inp) != 0);
if (__pyx_t_1) {
/* … */
goto __pyx_L3;
}
+059: array = <np.ndarray>inp
__pyx_t_2 = __pyx_v_inp;
__Pyx_INCREF(__pyx_t_2);
__pyx_v_array = ((PyArrayObject *)__pyx_t_2);
__pyx_t_2 = 0;
+060: tn = np.PyArray_TYPE(array)
__pyx_v_tn = PyArray_TYPE(__pyx_v_array);
+061: if tn != type_num:
__pyx_t_1 = ((__pyx_v_tn != __pyx_v_type_num) != 0);
if (__pyx_t_1) {
/* … */
goto __pyx_L4;
}
+062: out = np.PyArray_SimpleNew(array.ndim, <np.npy_intp *>array.shape, type_num)
__pyx_t_2 = PyArray_SimpleNew(__pyx_v_array->nd, ((npy_intp *)__pyx_v_array->dimensions), __pyx_v_type_num); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 62, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 62, __pyx_L1_error) __pyx_v_out = ((PyArrayObject *)__pyx_t_2); __pyx_t_2 = 0;
+063: np.PyArray_CastTo(out, array)
(void)(PyArray_CastTo(__pyx_v_out, __pyx_v_array));
064: else:
+065: out = array
/*else*/ {
__Pyx_INCREF(((PyObject *)__pyx_v_array));
__pyx_v_out = __pyx_v_array;
}
__pyx_L4:;
066:
+067: elif isinstance(inp, (list, tuple)):
__pyx_t_3 = PyList_Check(__pyx_v_inp); __pyx_t_4 = (__pyx_t_3 != 0); if (!__pyx_t_4) { } else { __pyx_t_1 = __pyx_t_4; goto __pyx_L5_bool_binop_done; } __pyx_t_4 = PyTuple_Check(__pyx_v_inp); __pyx_t_3 = (__pyx_t_4 != 0); __pyx_t_1 = __pyx_t_3; __pyx_L5_bool_binop_done:; __pyx_t_3 = (__pyx_t_1 != 0); if (likely(__pyx_t_3)) { /* … */ goto __pyx_L3; }
+068: out = <np.ndarray>np.PyArray_FROM_OTF(inp, type_num, np.NPY_ARRAY_C_CONTIGUOUS)
__pyx_t_2 = PyArray_FROM_OTF(__pyx_v_inp, __pyx_v_type_num, NPY_ARRAY_C_CONTIGUOUS); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 68, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_5 = __pyx_t_2; __Pyx_INCREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_out = ((PyArrayObject *)__pyx_t_5); __pyx_t_5 = 0;
069:
070: else:
+071: raise ValueError("Wrong sequence argument type")
/*else*/ {
__pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 71, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_Raise(__pyx_t_5, 0, 0, 0);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__PYX_ERR(0, 71, __pyx_L1_error)
}
__pyx_L3:;
/* … */
__pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_u_Wrong_sequence_argument_type); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 71, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__2);
__Pyx_GIVEREF(__pyx_tuple__2);
072:
+073: cdef np.npy_intp size = np.PyArray_SIZE(out)
__pyx_v_size = PyArray_SIZE(__pyx_v_out);
+074: if size != rank:
__pyx_t_3 = ((__pyx_v_size != __pyx_v_rank) != 0);
if (unlikely(__pyx_t_3)) {
/* … */
}
+075: raise ValueError("Sequence argument must have length equal to input rank")
__pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 75, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_Raise(__pyx_t_5, 0, 0, 0); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __PYX_ERR(0, 75, __pyx_L1_error) /* … */ __pyx_tuple__3 = PyTuple_Pack(1, __pyx_kp_u_Sequence_argument_must_have_leng); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 75, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__3); __Pyx_GIVEREF(__pyx_tuple__3);
+076: return out
__Pyx_XDECREF(((PyObject *)__pyx_r)); __Pyx_INCREF(((PyObject *)__pyx_v_out)); __pyx_r = __pyx_v_out; goto __pyx_L0;
077:
+078: def next_fast_len(unsigned target, str backend='numpy'):
/* Python wrapper */
static PyObject *__pyx_pw_6pyrost_3bin_10simulation_1next_fast_len(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6pyrost_3bin_10simulation_next_fast_len[] = "Find the next fast size of input data to fft, for zero-padding, etc.\n FFT algorithms gain their speed by a recursive divide and conquer strategy.\n This relies on efficient functions for small prime factors of the input length.\n Thus, the transforms are fastest when using composites of the prime factors handled\n by the fft implementation. If there are efficient functions for all radices <= n,\n then the result will be a number x >= target with only prime factors < n. (Also\n known as n-smooth numbers)\n\n Args:\n target (int) : Length to start searching from. Must be a positive integer.\n backend (str) : Find n-smooth number for the FFT implementation from the numpy\n ('numpy') or FFTW ('fftw') library.\n\n Returns:\n int : The smallest fast length greater than or equal to `target`.\n ";
static PyMethodDef __pyx_mdef_6pyrost_3bin_10simulation_1next_fast_len = {"next_fast_len", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_6pyrost_3bin_10simulation_1next_fast_len, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6pyrost_3bin_10simulation_next_fast_len};
static PyObject *__pyx_pw_6pyrost_3bin_10simulation_1next_fast_len(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
unsigned int __pyx_v_target;
PyObject *__pyx_v_backend = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("next_fast_len (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_target,&__pyx_n_s_backend,0};
PyObject* values[2] = {0,0};
values[1] = ((PyObject*)((PyObject*)__pyx_n_u_numpy));
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);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_target)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (kw_args > 0) {
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_backend);
if (value) { values[1] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "next_fast_len") < 0)) __PYX_ERR(0, 78, __pyx_L3_error)
}
} else {
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
break;
default: goto __pyx_L5_argtuple_error;
}
}
__pyx_v_target = __Pyx_PyInt_As_unsigned_int(values[0]); if (unlikely((__pyx_v_target == (unsigned int)-1) && PyErr_Occurred())) __PYX_ERR(0, 78, __pyx_L3_error)
__pyx_v_backend = ((PyObject*)values[1]);
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("next_fast_len", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 78, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("pyrost.bin.simulation.next_fast_len", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_backend), (&PyUnicode_Type), 1, "backend", 1))) __PYX_ERR(0, 78, __pyx_L1_error)
__pyx_r = __pyx_pf_6pyrost_3bin_10simulation_next_fast_len(__pyx_self, __pyx_v_target, __pyx_v_backend);
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
/* function exit code */
goto __pyx_L0;
__pyx_L1_error:;
__pyx_r = NULL;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_6pyrost_3bin_10simulation_next_fast_len(CYTHON_UNUSED PyObject *__pyx_self, unsigned int __pyx_v_target, PyObject *__pyx_v_backend) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("next_fast_len", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_AddTraceback("pyrost.bin.simulation.next_fast_len", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* … */
__pyx_tuple__10 = PyTuple_Pack(2, __pyx_n_s_target, __pyx_n_s_backend); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(0, 78, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__10);
__Pyx_GIVEREF(__pyx_tuple__10);
__pyx_codeobj__11 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__10, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pyrost_bin_simulation_pyx, __pyx_n_s_next_fast_len, 78, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__11)) __PYX_ERR(0, 78, __pyx_L1_error)
/* … */
__pyx_t_1 = __Pyx_CyFunction_New(&__pyx_mdef_6pyrost_3bin_10simulation_1next_fast_len, 0, __pyx_n_s_next_fast_len, NULL, __pyx_n_s_pyrost_bin_simulation, __pyx_d, ((PyObject *)__pyx_codeobj__11)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 78, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_CyFunction_SetDefaultsTuple(__pyx_t_1, __pyx_tuple__12);
if (PyDict_SetItem(__pyx_d, __pyx_n_s_next_fast_len, __pyx_t_1) < 0) __PYX_ERR(0, 78, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_tuple__12 = PyTuple_Pack(1, ((PyObject*)__pyx_n_u_numpy)); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(0, 78, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__12);
__Pyx_GIVEREF(__pyx_tuple__12);
079: r"""Find the next fast size of input data to fft, for zero-padding, etc.
080: FFT algorithms gain their speed by a recursive divide and conquer strategy.
081: This relies on efficient functions for small prime factors of the input length.
082: Thus, the transforms are fastest when using composites of the prime factors handled
083: by the fft implementation. If there are efficient functions for all radices <= n,
084: then the result will be a number x >= target with only prime factors < n. (Also
085: known as n-smooth numbers)
086:
087: Args:
088: target (int) : Length to start searching from. Must be a positive integer.
089: backend (str) : Find n-smooth number for the FFT implementation from the numpy
090: ('numpy') or FFTW ('fftw') library.
091:
092: Returns:
093: int : The smallest fast length greater than or equal to `target`.
094: """
+095: if target < 0:
__pyx_t_1 = ((__pyx_v_target < 0) != 0);
if (unlikely(__pyx_t_1)) {
/* … */
}
+096: raise ValueError('Target length must be positive')
__pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 96, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __PYX_ERR(0, 96, __pyx_L1_error) /* … */ __pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_u_Target_length_must_be_positive); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 96, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__4); __Pyx_GIVEREF(__pyx_tuple__4);
+097: if backend == 'fftw':
__pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_v_backend, __pyx_n_u_fftw, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 97, __pyx_L1_error) __pyx_t_3 = (__pyx_t_1 != 0); if (__pyx_t_3) { /* … */ }
+098: return next_fast_len_fftw(target)
__Pyx_XDECREF(__pyx_r); __pyx_t_2 = __Pyx_PyInt_From_unsigned_long(next_fast_len_fftw(__pyx_v_target)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 98, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
+099: elif backend == 'numpy':
__pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_v_backend, __pyx_n_u_numpy, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 99, __pyx_L1_error) __pyx_t_1 = (__pyx_t_3 != 0); if (likely(__pyx_t_1)) { /* … */ }
+100: return good_size(target)
__Pyx_XDECREF(__pyx_r); __pyx_t_2 = __Pyx_PyInt_From_unsigned_long(good_size(__pyx_v_target)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 100, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
101: else:
+102: raise ValueError('{:s} is invalid backend'.format(backend))
/*else*/ {
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_s_is_invalid_backend, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 102, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_5 = NULL;
if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
__pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
if (likely(__pyx_t_5)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
__Pyx_INCREF(__pyx_t_5);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_4, function);
}
}
__pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_v_backend) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_backend);
__Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 102, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 102, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_Raise(__pyx_t_4, 0, 0, 0);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__PYX_ERR(0, 102, __pyx_L1_error)
}
103:
+104: def fft_convolve(np.ndarray array not None, np.ndarray kernel not None, int axis=-1,
/* Python wrapper */
static PyObject *__pyx_pw_6pyrost_3bin_10simulation_3fft_convolve(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6pyrost_3bin_10simulation_2fft_convolve[] = "Convolve a multi-dimensional `array` with one-dimensional `kernel` along the\n `axis` by means of FFT. Output has the same size as `array`.\n\n Args:\n array (numpy.ndarray) : Input array.\n kernel (numpy.ndarray) : Kernel array.\n axis (int) : Array axis along which convolution is performed.\n mode (str) : The mode parameter determines how the input array is extended\n when the filter overlaps a border. Default value is 'constant'. The\n valid values and their behavior is as follows:\n\n * 'constant', (k k k k | a b c d | k k k k) : The input is extended by\n filling all values beyond the edge with the same constant value, defined\n by the `cval` parameter.\n * 'nearest', (a a a a | a b c d | d d d d) : The input is extended by\n replicating the last pixel.\n * 'mirror', (c d c b | a b c d | c b a b) : The input is extended by\n reflecting about the center of the last pixel. This mode is also sometimes\n referred to as whole-sample symmetric.\n * 'reflect', (d c b a | a b c d | d c b a) : The input is extended by\n reflecting about the edge of the last pixel. This mode is also sometimes\n referred to as half-sample symmetric.\n * 'wrap', (a b c d | a b c d | a b c d) : The input is extended by wrapping\n around to the opposite edge.\n\n cval (float) : Value to fill past edges of input if mode is 'constant'. Default\n is 0.0.\n backend (str) : Choose between numpy ('numpy') or FFTW ('fftw') library for the FFT\n implementation.\n num_threads (int) : Number of threads used in the calculations.\n\n Returns:\n numpy.ndarray : A multi-dimensional array containing the discrete linear\n convolution of `array` with `kernel`.\n ";
static PyMethodDef __pyx_mdef_6pyrost_3bin_10simulation_3fft_convolve = {"fft_convolve", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_6pyrost_3bin_10simulation_3fft_convolve, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6pyrost_3bin_10simulation_2fft_convolve};
static PyObject *__pyx_pw_6pyrost_3bin_10simulation_3fft_convolve(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyArrayObject *__pyx_v_array = 0;
PyArrayObject *__pyx_v_kernel = 0;
int __pyx_v_axis;
PyObject *__pyx_v_mode = 0;
double __pyx_v_cval;
PyObject *__pyx_v_backend = 0;
unsigned int __pyx_v_num_threads;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("fft_convolve (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_array,&__pyx_n_s_kernel,&__pyx_n_s_axis,&__pyx_n_s_mode,&__pyx_n_s_cval,&__pyx_n_s_backend,&__pyx_n_s_num_threads,0};
PyObject* values[7] = {0,0,0,0,0,0,0};
values[3] = ((PyObject*)((PyObject*)__pyx_n_u_constant));
values[5] = ((PyObject*)((PyObject*)__pyx_n_u_numpy));
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);
CYTHON_FALLTHROUGH;
case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
CYTHON_FALLTHROUGH;
case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
CYTHON_FALLTHROUGH;
case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
CYTHON_FALLTHROUGH;
case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
CYTHON_FALLTHROUGH;
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_array)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_kernel)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("fft_convolve", 0, 2, 7, 1); __PYX_ERR(0, 104, __pyx_L3_error)
}
CYTHON_FALLTHROUGH;
case 2:
if (kw_args > 0) {
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_axis);
if (value) { values[2] = value; kw_args--; }
}
CYTHON_FALLTHROUGH;
case 3:
if (kw_args > 0) {
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mode);
if (value) { values[3] = value; kw_args--; }
}
CYTHON_FALLTHROUGH;
case 4:
if (kw_args > 0) {
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_cval);
if (value) { values[4] = value; kw_args--; }
}
CYTHON_FALLTHROUGH;
case 5:
if (kw_args > 0) {
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_backend);
if (value) { values[5] = value; kw_args--; }
}
CYTHON_FALLTHROUGH;
case 6:
if (kw_args > 0) {
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_num_threads);
if (value) { values[6] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fft_convolve") < 0)) __PYX_ERR(0, 104, __pyx_L3_error)
}
} else {
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
CYTHON_FALLTHROUGH;
case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
CYTHON_FALLTHROUGH;
case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
CYTHON_FALLTHROUGH;
case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
CYTHON_FALLTHROUGH;
case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
CYTHON_FALLTHROUGH;
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
break;
default: goto __pyx_L5_argtuple_error;
}
}
__pyx_v_array = ((PyArrayObject *)values[0]);
__pyx_v_kernel = ((PyArrayObject *)values[1]);
if (values[2]) {
__pyx_v_axis = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_axis == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 104, __pyx_L3_error)
} else {
__pyx_v_axis = ((int)((int)-1));
}
__pyx_v_mode = ((PyObject*)values[3]);
if (values[4]) {
__pyx_v_cval = __pyx_PyFloat_AsDouble(values[4]); if (unlikely((__pyx_v_cval == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 105, __pyx_L3_error)
} else {
__pyx_v_cval = ((double)((double)0.0));
}
__pyx_v_backend = ((PyObject*)values[5]);
if (values[6]) {
__pyx_v_num_threads = __Pyx_PyInt_As_unsigned_int(values[6]); if (unlikely((__pyx_v_num_threads == (unsigned int)-1) && PyErr_Occurred())) __PYX_ERR(0, 106, __pyx_L3_error)
} else {
__pyx_v_num_threads = ((unsigned int)((unsigned int)1));
}
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("fft_convolve", 0, 2, 7, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 104, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("pyrost.bin.simulation.fft_convolve", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_array), __pyx_ptype_5numpy_ndarray, 0, "array", 0))) __PYX_ERR(0, 104, __pyx_L1_error)
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_kernel), __pyx_ptype_5numpy_ndarray, 0, "kernel", 0))) __PYX_ERR(0, 104, __pyx_L1_error)
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_mode), (&PyUnicode_Type), 1, "mode", 1))) __PYX_ERR(0, 105, __pyx_L1_error)
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_backend), (&PyUnicode_Type), 1, "backend", 1))) __PYX_ERR(0, 105, __pyx_L1_error)
__pyx_r = __pyx_pf_6pyrost_3bin_10simulation_2fft_convolve(__pyx_self, __pyx_v_array, __pyx_v_kernel, __pyx_v_axis, __pyx_v_mode, __pyx_v_cval, __pyx_v_backend, __pyx_v_num_threads);
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
/* function exit code */
goto __pyx_L0;
__pyx_L1_error:;
__pyx_r = NULL;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_6pyrost_3bin_10simulation_2fft_convolve(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_array, PyArrayObject *__pyx_v_kernel, int __pyx_v_axis, PyObject *__pyx_v_mode, double __pyx_v_cval, PyObject *__pyx_v_backend, unsigned int __pyx_v_num_threads) {
int __pyx_v_fail;
int __pyx_v_ndim;
npy_intp __pyx_v_ksize;
int __pyx_v__mode;
npy_intp *__pyx_v_dims;
unsigned long *__pyx_v__dims;
int __pyx_v_type_num;
PyArrayObject *__pyx_v_out = 0;
void *__pyx_v__out;
void *__pyx_v__inp;
void *__pyx_v__krn;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("fft_convolve", 0);
__Pyx_INCREF((PyObject *)__pyx_v_array);
__Pyx_INCREF((PyObject *)__pyx_v_kernel);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_6);
__Pyx_XDECREF(__pyx_t_7);
__Pyx_XDECREF(__pyx_t_8);
__Pyx_AddTraceback("pyrost.bin.simulation.fft_convolve", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF((PyObject *)__pyx_v_out);
__Pyx_XDECREF((PyObject *)__pyx_v_array);
__Pyx_XDECREF((PyObject *)__pyx_v_kernel);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* … */
__pyx_tuple__13 = PyTuple_Pack(18, __pyx_n_s_array, __pyx_n_s_kernel, __pyx_n_s_axis, __pyx_n_s_mode, __pyx_n_s_cval, __pyx_n_s_backend, __pyx_n_s_num_threads, __pyx_n_s_fail, __pyx_n_s_ndim, __pyx_n_s_ksize, __pyx_n_s_mode_2, __pyx_n_s_dims, __pyx_n_s_dims_2, __pyx_n_s_type_num, __pyx_n_s_out, __pyx_n_s_out_2, __pyx_n_s_inp_2, __pyx_n_s_krn); if (unlikely(!__pyx_tuple__13)) __PYX_ERR(0, 104, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__13);
__Pyx_GIVEREF(__pyx_tuple__13);
/* … */
__pyx_t_1 = __Pyx_PyInt_From_int(((int)-1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 104, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
/* … */
__pyx_t_5 = PyTuple_New(5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 104, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_GIVEREF(__pyx_t_1);
PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1);
__Pyx_INCREF(((PyObject*)__pyx_n_u_constant));
__Pyx_GIVEREF(((PyObject*)__pyx_n_u_constant));
PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject*)__pyx_n_u_constant));
__Pyx_GIVEREF(__pyx_t_3);
PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_3);
__Pyx_INCREF(((PyObject*)__pyx_n_u_numpy));
__Pyx_GIVEREF(((PyObject*)__pyx_n_u_numpy));
PyTuple_SET_ITEM(__pyx_t_5, 3, ((PyObject*)__pyx_n_u_numpy));
__Pyx_GIVEREF(__pyx_t_4);
PyTuple_SET_ITEM(__pyx_t_5, 4, __pyx_t_4);
__pyx_t_1 = 0;
__pyx_t_3 = 0;
__pyx_t_4 = 0;
__pyx_t_4 = __Pyx_CyFunction_New(&__pyx_mdef_6pyrost_3bin_10simulation_3fft_convolve, 0, __pyx_n_s_fft_convolve, NULL, __pyx_n_s_pyrost_bin_simulation, __pyx_d, ((PyObject *)__pyx_codeobj__14)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 104, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_CyFunction_SetDefaultsTuple(__pyx_t_4, __pyx_t_5);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
if (PyDict_SetItem(__pyx_d, __pyx_n_s_fft_convolve, __pyx_t_4) < 0) __PYX_ERR(0, 104, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_codeobj__14 = (PyObject*)__Pyx_PyCode_New(7, 0, 18, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__13, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pyrost_bin_simulation_pyx, __pyx_n_s_fft_convolve, 104, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__14)) __PYX_ERR(0, 104, __pyx_L1_error)
+105: str mode='constant', double cval=0.0, str backend='numpy',
__pyx_t_3 = PyFloat_FromDouble(((double)0.0)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 105, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3);
+106: unsigned num_threads=1):
__pyx_t_4 = __Pyx_PyInt_From_unsigned_int(((unsigned int)1)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 106, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4);
107: """Convolve a multi-dimensional `array` with one-dimensional `kernel` along the
108: `axis` by means of FFT. Output has the same size as `array`.
109:
110: Args:
111: array (numpy.ndarray) : Input array.
112: kernel (numpy.ndarray) : Kernel array.
113: axis (int) : Array axis along which convolution is performed.
114: mode (str) : The mode parameter determines how the input array is extended
115: when the filter overlaps a border. Default value is 'constant'. The
116: valid values and their behavior is as follows:
117:
118: * 'constant', (k k k k | a b c d | k k k k) : The input is extended by
119: filling all values beyond the edge with the same constant value, defined
120: by the `cval` parameter.
121: * 'nearest', (a a a a | a b c d | d d d d) : The input is extended by
122: replicating the last pixel.
123: * 'mirror', (c d c b | a b c d | c b a b) : The input is extended by
124: reflecting about the center of the last pixel. This mode is also sometimes
125: referred to as whole-sample symmetric.
126: * 'reflect', (d c b a | a b c d | d c b a) : The input is extended by
127: reflecting about the edge of the last pixel. This mode is also sometimes
128: referred to as half-sample symmetric.
129: * 'wrap', (a b c d | a b c d | a b c d) : The input is extended by wrapping
130: around to the opposite edge.
131:
132: cval (float) : Value to fill past edges of input if mode is 'constant'. Default
133: is 0.0.
134: backend (str) : Choose between numpy ('numpy') or FFTW ('fftw') library for the FFT
135: implementation.
136: num_threads (int) : Number of threads used in the calculations.
137:
138: Returns:
139: numpy.ndarray : A multi-dimensional array containing the discrete linear
140: convolution of `array` with `kernel`.
141: """
+142: cdef int fail = 0
__pyx_v_fail = 0;
+143: cdef int ndim = array.ndim
__pyx_t_1 = __pyx_v_array->nd; __pyx_v_ndim = __pyx_t_1;
+144: axis = axis if axis >= 0 else ndim + axis
if (((__pyx_v_axis >= 0) != 0)) {
__pyx_t_1 = __pyx_v_axis;
} else {
__pyx_t_1 = (__pyx_v_ndim + __pyx_v_axis);
}
__pyx_v_axis = __pyx_t_1;
+145: axis = axis if axis <= ndim - 1 else ndim - 1
if (((__pyx_v_axis <= (__pyx_v_ndim - 1)) != 0)) {
__pyx_t_2 = __pyx_v_axis;
} else {
__pyx_t_2 = (__pyx_v_ndim - 1);
}
__pyx_v_axis = __pyx_t_2;
+146: cdef np.npy_intp ksize = np.PyArray_DIM(kernel, 0)
__pyx_v_ksize = PyArray_DIM(__pyx_v_kernel, 0);
+147: cdef int _mode = extend_mode_to_code(mode)
__pyx_t_1 = __pyx_f_6pyrost_3bin_10simulation_extend_mode_to_code(__pyx_v_mode); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(0, 147, __pyx_L1_error)
__pyx_v__mode = __pyx_t_1;
+148: cdef np.npy_intp *dims = array.shape
__pyx_t_3 = __pyx_v_array->dimensions; __pyx_v_dims = __pyx_t_3;
+149: cdef unsigned long *_dims = <unsigned long *>dims
__pyx_v__dims = ((unsigned long *)__pyx_v_dims);
150:
151: cdef int type_num
+152: if np.PyArray_ISCOMPLEX(array) or np.PyArray_ISCOMPLEX(kernel):
__pyx_t_5 = (PyArray_ISCOMPLEX(__pyx_v_array) != 0); if (!__pyx_t_5) { } else { __pyx_t_4 = __pyx_t_5; goto __pyx_L4_bool_binop_done; } __pyx_t_5 = (PyArray_ISCOMPLEX(__pyx_v_kernel) != 0); __pyx_t_4 = __pyx_t_5; __pyx_L4_bool_binop_done:; if (__pyx_t_4) { /* … */ goto __pyx_L3; }
+153: type_num = np.NPY_COMPLEX128
__pyx_v_type_num = NPY_COMPLEX128;
154: else:
+155: type_num = np.NPY_FLOAT64
/*else*/ {
__pyx_v_type_num = NPY_FLOAT64;
}
__pyx_L3:;
156:
+157: cdef np.ndarray out = <np.ndarray>np.PyArray_SimpleNew(ndim, dims, type_num)
__pyx_t_6 = PyArray_SimpleNew(__pyx_v_ndim, __pyx_v_dims, __pyx_v_type_num); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 157, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_7 = __pyx_t_6; __Pyx_INCREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_v_out = ((PyArrayObject *)__pyx_t_7); __pyx_t_7 = 0;
+158: cdef void *_out = np.PyArray_DATA(out)
__pyx_v__out = PyArray_DATA(__pyx_v_out);
159: cdef void *_inp
160: cdef void *_krn
161:
+162: if np.PyArray_ISCOMPLEX(array) or np.PyArray_ISCOMPLEX(kernel):
__pyx_t_5 = (PyArray_ISCOMPLEX(__pyx_v_array) != 0); if (!__pyx_t_5) { } else { __pyx_t_4 = __pyx_t_5; goto __pyx_L7_bool_binop_done; } __pyx_t_5 = (PyArray_ISCOMPLEX(__pyx_v_kernel) != 0); __pyx_t_4 = __pyx_t_5; __pyx_L7_bool_binop_done:; if (__pyx_t_4) { /* … */ goto __pyx_L6; }
+163: array = check_array(array, np.NPY_COMPLEX128)
__pyx_t_7 = ((PyObject *)__pyx_f_6pyrost_3bin_10simulation_check_array(__pyx_v_array, NPY_COMPLEX128)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 163, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF_SET(__pyx_v_array, ((PyArrayObject *)__pyx_t_7)); __pyx_t_7 = 0;
+164: kernel = check_array(kernel, np.NPY_COMPLEX128)
__pyx_t_7 = ((PyObject *)__pyx_f_6pyrost_3bin_10simulation_check_array(__pyx_v_kernel, NPY_COMPLEX128)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 164, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF_SET(__pyx_v_kernel, ((PyArrayObject *)__pyx_t_7)); __pyx_t_7 = 0;
165:
+166: _inp = np.PyArray_DATA(array)
__pyx_v__inp = PyArray_DATA(__pyx_v_array);
+167: _krn = np.PyArray_DATA(kernel)
__pyx_v__krn = PyArray_DATA(__pyx_v_kernel);
168:
+169: with nogil:
{
#ifdef WITH_THREAD
PyThreadState *_save;
Py_UNBLOCK_THREADS
__Pyx_FastGIL_Remember();
#endif
/*try:*/ {
/* … */
/*finally:*/ {
/*normal exit:*/{
#ifdef WITH_THREAD
__Pyx_FastGIL_Forget();
Py_BLOCK_THREADS
#endif
goto __pyx_L11;
}
__pyx_L10_error: {
#ifdef WITH_THREAD
__Pyx_FastGIL_Forget();
Py_BLOCK_THREADS
#endif
goto __pyx_L1_error;
}
__pyx_L11:;
}
}
+170: if backend == 'fftw':
__pyx_t_4 = (__Pyx_PyUnicode_Equals(__pyx_v_backend, __pyx_n_u_fftw, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 170, __pyx_L10_error) __pyx_t_5 = (__pyx_t_4 != 0); if (__pyx_t_5) { /* … */ goto __pyx_L12; }
+171: fail = cfft_convolve_fftw(<double complex *>_out, <double complex *>_inp, ndim,
__pyx_v_fail = cfft_convolve_fftw(((__pyx_t_double_complex *)__pyx_v__out), ((__pyx_t_double_complex *)__pyx_v__inp), __pyx_v_ndim, __pyx_v__dims, ((__pyx_t_double_complex *)__pyx_v__krn), __pyx_v_ksize, __pyx_v_axis, __pyx_v__mode, __pyx_t_double_complex_from_parts(((double)__pyx_v_cval), 0), __pyx_v_num_threads);
172: _dims, <double complex *>_krn, ksize, axis, _mode,
173: <double complex>cval, num_threads)
+174: elif backend == 'numpy':
__pyx_t_5 = (__Pyx_PyUnicode_Equals(__pyx_v_backend, __pyx_n_u_numpy, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 174, __pyx_L10_error) __pyx_t_4 = (__pyx_t_5 != 0); if (__pyx_t_4) { /* … */ goto __pyx_L12; }
+175: fail = cfft_convolve_np(<double complex *>_out, <double complex *>_inp, ndim,
__pyx_v_fail = cfft_convolve_np(((__pyx_t_double_complex *)__pyx_v__out), ((__pyx_t_double_complex *)__pyx_v__inp), __pyx_v_ndim, __pyx_v__dims, ((__pyx_t_double_complex *)__pyx_v__krn), __pyx_v_ksize, __pyx_v_axis, __pyx_v__mode, __pyx_t_double_complex_from_parts(((double)__pyx_v_cval), 0), __pyx_v_num_threads);
176: _dims, <double complex *>_krn, ksize, axis, _mode,
177: <double complex>cval, num_threads)
178: else:
+179: raise ValueError('{:s} is invalid backend'.format(backend))
/*else*/ {
{
#ifdef WITH_THREAD
PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
#endif
/*try:*/ {
__pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_s_is_invalid_backend, __pyx_n_s_format); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 179, __pyx_L14_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_t_8 = NULL;
if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
__pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6);
if (likely(__pyx_t_8)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
__Pyx_INCREF(__pyx_t_8);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_6, function);
}
}
__pyx_t_7 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_8, __pyx_v_backend) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_backend);
__Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 179, __pyx_L14_error)
__Pyx_GOTREF(__pyx_t_7);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 179, __pyx_L14_error)
__Pyx_GOTREF(__pyx_t_6);
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
__Pyx_Raise(__pyx_t_6, 0, 0, 0);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__PYX_ERR(0, 179, __pyx_L14_error)
}
/*finally:*/ {
__pyx_L14_error: {
#ifdef WITH_THREAD
__Pyx_PyGILState_Release(__pyx_gilstate_save);
#endif
goto __pyx_L10_error;
}
}
}
}
__pyx_L12:;
}
180: else:
+181: array = check_array(array, np.NPY_FLOAT64)
/*else*/ {
__pyx_t_6 = ((PyObject *)__pyx_f_6pyrost_3bin_10simulation_check_array(__pyx_v_array, NPY_FLOAT64)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 181, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__Pyx_DECREF_SET(__pyx_v_array, ((PyArrayObject *)__pyx_t_6));
__pyx_t_6 = 0;
+182: kernel = check_array(kernel, np.NPY_FLOAT64)
__pyx_t_6 = ((PyObject *)__pyx_f_6pyrost_3bin_10simulation_check_array(__pyx_v_kernel, NPY_FLOAT64)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 182, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF_SET(__pyx_v_kernel, ((PyArrayObject *)__pyx_t_6)); __pyx_t_6 = 0;
183:
+184: _inp = np.PyArray_DATA(array)
__pyx_v__inp = PyArray_DATA(__pyx_v_array);
+185: _krn = np.PyArray_DATA(kernel)
__pyx_v__krn = PyArray_DATA(__pyx_v_kernel);
186:
+187: with nogil:
{
#ifdef WITH_THREAD
PyThreadState *_save;
Py_UNBLOCK_THREADS
__Pyx_FastGIL_Remember();
#endif
/*try:*/ {
/* … */
/*finally:*/ {
/*normal exit:*/{
#ifdef WITH_THREAD
__Pyx_FastGIL_Forget();
Py_BLOCK_THREADS
#endif
goto __pyx_L18;
}
__pyx_L17_error: {
#ifdef WITH_THREAD
__Pyx_FastGIL_Forget();
Py_BLOCK_THREADS
#endif
goto __pyx_L1_error;
}
__pyx_L18:;
}
}
}
__pyx_L6:;
+188: if backend == 'fftw':
__pyx_t_4 = (__Pyx_PyUnicode_Equals(__pyx_v_backend, __pyx_n_u_fftw, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 188, __pyx_L17_error) __pyx_t_5 = (__pyx_t_4 != 0); if (__pyx_t_5) { /* … */ goto __pyx_L19; }
+189: fail = rfft_convolve_fftw(<double *>_out, <double *>_inp, ndim, _dims,
__pyx_v_fail = rfft_convolve_fftw(((double *)__pyx_v__out), ((double *)__pyx_v__inp), __pyx_v_ndim, __pyx_v__dims, ((double *)__pyx_v__krn), __pyx_v_ksize, __pyx_v_axis, __pyx_v__mode, __pyx_v_cval, __pyx_v_num_threads);
190: <double *>_krn, ksize, axis, _mode, cval, num_threads)
+191: elif backend == 'numpy':
__pyx_t_5 = (__Pyx_PyUnicode_Equals(__pyx_v_backend, __pyx_n_u_numpy, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 191, __pyx_L17_error) __pyx_t_4 = (__pyx_t_5 != 0); if (__pyx_t_4) { /* … */ goto __pyx_L19; }
+192: fail = rfft_convolve_np(<double *>_out, <double *>_inp, ndim, _dims,
__pyx_v_fail = rfft_convolve_np(((double *)__pyx_v__out), ((double *)__pyx_v__inp), __pyx_v_ndim, __pyx_v__dims, ((double *)__pyx_v__krn), __pyx_v_ksize, __pyx_v_axis, __pyx_v__mode, __pyx_v_cval, __pyx_v_num_threads);
193: <double *>_krn, ksize, axis, _mode, cval, num_threads)
194: else:
+195: raise ValueError('{:s} is invalid backend'.format(backend))
/*else*/ {
{
#ifdef WITH_THREAD
PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
#endif
/*try:*/ {
__pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_s_is_invalid_backend, __pyx_n_s_format); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 195, __pyx_L21_error)
__Pyx_GOTREF(__pyx_t_7);
__pyx_t_8 = NULL;
if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
__pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
if (likely(__pyx_t_8)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
__Pyx_INCREF(__pyx_t_8);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_7, function);
}
}
__pyx_t_6 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_8, __pyx_v_backend) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_backend);
__Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 195, __pyx_L21_error)
__Pyx_GOTREF(__pyx_t_6);
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
__pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 195, __pyx_L21_error)
__Pyx_GOTREF(__pyx_t_7);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__Pyx_Raise(__pyx_t_7, 0, 0, 0);
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
__PYX_ERR(0, 195, __pyx_L21_error)
}
/*finally:*/ {
__pyx_L21_error: {
#ifdef WITH_THREAD
__Pyx_PyGILState_Release(__pyx_gilstate_save);
#endif
goto __pyx_L17_error;
}
}
}
}
__pyx_L19:;
}
196:
+197: if fail:
__pyx_t_4 = (__pyx_v_fail != 0);
if (unlikely(__pyx_t_4)) {
/* … */
}
+198: raise RuntimeError('C backend exited with error.')
__pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_RuntimeError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 198, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_Raise(__pyx_t_7, 0, 0, 0); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __PYX_ERR(0, 198, __pyx_L1_error) /* … */ __pyx_tuple__5 = PyTuple_Pack(1, __pyx_kp_u_C_backend_exited_with_error); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(0, 198, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__5); __Pyx_GIVEREF(__pyx_tuple__5);
+199: return out
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_out)); __pyx_r = ((PyObject *)__pyx_v_out); goto __pyx_L0;
200:
+201: def rsc_wp(np.ndarray wft not None, double dx0, double dx, double z,
/* Python wrapper */
static PyObject *__pyx_pw_6pyrost_3bin_10simulation_5rsc_wp(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6pyrost_3bin_10simulation_4rsc_wp[] = "Wavefront propagator based on Rayleigh-Sommerfeld convolution\n method [RSC]_. Propagates a wavefront `wft` by `z` distance downstream.\n You can choose between 'fftw' and 'numpy' backends for FFT calculations.\n\n Args: \n wft (numpy.ndarray) : Initial wavefront.\n dx0 (float) : Sampling interval at the plane upstream [um].\n dx (float) : Sampling interval at the plane downstream [um].\n z (float) : Propagation distance [um].\n wl (float) : Incoming beam's wavelength [um].\n axis (int) : Axis of `wft` array along which the calculation is performed.\n backend (str) : Choose between numpy ('numpy') or FFTW ('fftw') library\n for the FFT implementation.\n num_threads (int) : Number of threads used in the calculations.\n\n Returns:\n numpy.ndarray : Propagated wavefront.\n\n Raises:\n RuntimeError : If 'numpy' backend exits with eror during the calculation.\n ValueError : If `backend` option is invalid.\n\n Notes:\n The Rayleigh-Sommerfeld diffraction integral transform is defined as:\n\n .. math::\n u^{\\prime}(x^{\\prime}) = \\frac{z}{j \\sqrt{\\lambda}} \\int_{-\\infty}^{+\\infty}\n u(x) \\mathrm{exp} \\left[-j k r(x, x^{\\prime}) \\right] dx\n \n with\n\n .. math::\n r(x, x^{\\prime}) = \\left[ (x - x^{\\prime})^2 + z^2 \\right]^{1 / 2}\n\n References:\n .. [RSC] V. Nascov and P. C. Logof\304\203tu, \"Fast computation algorithm\n for the Rayleigh-Sommerfeld diffraction formula using\n a type of scaled convolution,\" Appl. Opt. 48, 4310-4319\n (2009).\n ";
static PyMethodDef __pyx_mdef_6pyrost_3bin_10simulation_5rsc_wp = {"rsc_wp", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_6pyrost_3bin_10simulation_5rsc_wp, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6pyrost_3bin_10simulation_4rsc_wp};
static PyObject *__pyx_pw_6pyrost_3bin_10simulation_5rsc_wp(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyArrayObject *__pyx_v_wft = 0;
double __pyx_v_dx0;
double __pyx_v_dx;
double __pyx_v_z;
double __pyx_v_wl;
int __pyx_v_axis;
PyObject *__pyx_v_backend = 0;
unsigned int __pyx_v_num_threads;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("rsc_wp (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_wft,&__pyx_n_s_dx0,&__pyx_n_s_dx,&__pyx_n_s_z,&__pyx_n_s_wl,&__pyx_n_s_axis,&__pyx_n_s_backend,&__pyx_n_s_num_threads,0};
PyObject* values[8] = {0,0,0,0,0,0,0,0};
values[6] = ((PyObject*)((PyObject*)__pyx_n_u_numpy));
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
CYTHON_FALLTHROUGH;
case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
CYTHON_FALLTHROUGH;
case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
CYTHON_FALLTHROUGH;
case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
CYTHON_FALLTHROUGH;
case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
CYTHON_FALLTHROUGH;
case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
CYTHON_FALLTHROUGH;
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_wft)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_dx0)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("rsc_wp", 0, 5, 8, 1); __PYX_ERR(0, 201, __pyx_L3_error)
}
CYTHON_FALLTHROUGH;
case 2:
if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_dx)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("rsc_wp", 0, 5, 8, 2); __PYX_ERR(0, 201, __pyx_L3_error)
}
CYTHON_FALLTHROUGH;
case 3:
if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_z)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("rsc_wp", 0, 5, 8, 3); __PYX_ERR(0, 201, __pyx_L3_error)
}
CYTHON_FALLTHROUGH;
case 4:
if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_wl)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("rsc_wp", 0, 5, 8, 4); __PYX_ERR(0, 201, __pyx_L3_error)
}
CYTHON_FALLTHROUGH;
case 5:
if (kw_args > 0) {
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_axis);
if (value) { values[5] = value; kw_args--; }
}
CYTHON_FALLTHROUGH;
case 6:
if (kw_args > 0) {
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_backend);
if (value) { values[6] = value; kw_args--; }
}
CYTHON_FALLTHROUGH;
case 7:
if (kw_args > 0) {
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_num_threads);
if (value) { values[7] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "rsc_wp") < 0)) __PYX_ERR(0, 201, __pyx_L3_error)
}
} else {
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
CYTHON_FALLTHROUGH;
case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
CYTHON_FALLTHROUGH;
case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
CYTHON_FALLTHROUGH;
case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
break;
default: goto __pyx_L5_argtuple_error;
}
}
__pyx_v_wft = ((PyArrayObject *)values[0]);
__pyx_v_dx0 = __pyx_PyFloat_AsDouble(values[1]); if (unlikely((__pyx_v_dx0 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 201, __pyx_L3_error)
__pyx_v_dx = __pyx_PyFloat_AsDouble(values[2]); if (unlikely((__pyx_v_dx == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 201, __pyx_L3_error)
__pyx_v_z = __pyx_PyFloat_AsDouble(values[3]); if (unlikely((__pyx_v_z == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 201, __pyx_L3_error)
__pyx_v_wl = __pyx_PyFloat_AsDouble(values[4]); if (unlikely((__pyx_v_wl == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 202, __pyx_L3_error)
if (values[5]) {
__pyx_v_axis = __Pyx_PyInt_As_int(values[5]); if (unlikely((__pyx_v_axis == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 202, __pyx_L3_error)
} else {
__pyx_v_axis = ((int)((int)-1));
}
__pyx_v_backend = ((PyObject*)values[6]);
if (values[7]) {
__pyx_v_num_threads = __Pyx_PyInt_As_unsigned_int(values[7]); if (unlikely((__pyx_v_num_threads == (unsigned int)-1) && PyErr_Occurred())) __PYX_ERR(0, 202, __pyx_L3_error)
} else {
__pyx_v_num_threads = ((unsigned int)((unsigned int)1));
}
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("rsc_wp", 0, 5, 8, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 201, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("pyrost.bin.simulation.rsc_wp", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_wft), __pyx_ptype_5numpy_ndarray, 0, "wft", 0))) __PYX_ERR(0, 201, __pyx_L1_error)
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_backend), (&PyUnicode_Type), 1, "backend", 1))) __PYX_ERR(0, 202, __pyx_L1_error)
__pyx_r = __pyx_pf_6pyrost_3bin_10simulation_4rsc_wp(__pyx_self, __pyx_v_wft, __pyx_v_dx0, __pyx_v_dx, __pyx_v_z, __pyx_v_wl, __pyx_v_axis, __pyx_v_backend, __pyx_v_num_threads);
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
/* function exit code */
goto __pyx_L0;
__pyx_L1_error:;
__pyx_r = NULL;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_6pyrost_3bin_10simulation_4rsc_wp(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_wft, double __pyx_v_dx0, double __pyx_v_dx, double __pyx_v_z, double __pyx_v_wl, int __pyx_v_axis, PyObject *__pyx_v_backend, unsigned int __pyx_v_num_threads) {
int __pyx_v_fail;
CYTHON_UNUSED npy_intp __pyx_v_isize;
int __pyx_v_ndim;
npy_intp *__pyx_v_dims;
unsigned long *__pyx_v__dims;
PyArrayObject *__pyx_v_out = 0;
__pyx_t_double_complex *__pyx_v__out;
__pyx_t_double_complex *__pyx_v__inp;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("rsc_wp", 0);
__Pyx_INCREF((PyObject *)__pyx_v_wft);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_XDECREF(__pyx_t_8);
__Pyx_AddTraceback("pyrost.bin.simulation.rsc_wp", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF((PyObject *)__pyx_v_out);
__Pyx_XDECREF((PyObject *)__pyx_v_wft);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* … */
__pyx_tuple__15 = PyTuple_Pack(16, __pyx_n_s_wft, __pyx_n_s_dx0, __pyx_n_s_dx, __pyx_n_s_z, __pyx_n_s_wl, __pyx_n_s_axis, __pyx_n_s_backend, __pyx_n_s_num_threads, __pyx_n_s_fail, __pyx_n_s_isize, __pyx_n_s_ndim, __pyx_n_s_dims, __pyx_n_s_dims_2, __pyx_n_s_out, __pyx_n_s_out_2, __pyx_n_s_inp_2); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(0, 201, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__15);
__Pyx_GIVEREF(__pyx_tuple__15);
/* … */
__pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 201, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_GIVEREF(__pyx_t_4);
PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
__Pyx_INCREF(((PyObject*)__pyx_n_u_numpy));
__Pyx_GIVEREF(((PyObject*)__pyx_n_u_numpy));
PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject*)__pyx_n_u_numpy));
__Pyx_GIVEREF(__pyx_t_5);
PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_5);
__pyx_t_4 = 0;
__pyx_t_5 = 0;
__pyx_t_5 = __Pyx_CyFunction_New(&__pyx_mdef_6pyrost_3bin_10simulation_5rsc_wp, 0, __pyx_n_s_rsc_wp, NULL, __pyx_n_s_pyrost_bin_simulation, __pyx_d, ((PyObject *)__pyx_codeobj__16)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 201, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_CyFunction_SetDefaultsTuple(__pyx_t_5, __pyx_t_3);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
if (PyDict_SetItem(__pyx_d, __pyx_n_s_rsc_wp, __pyx_t_5) < 0) __PYX_ERR(0, 201, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__pyx_codeobj__16 = (PyObject*)__Pyx_PyCode_New(8, 0, 16, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__15, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pyrost_bin_simulation_pyx, __pyx_n_s_rsc_wp, 201, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__16)) __PYX_ERR(0, 201, __pyx_L1_error)
+202: double wl, int axis=-1, str backend='numpy', unsigned num_threads=1):
__pyx_t_4 = __Pyx_PyInt_From_int(((int)-1)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 202, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = __Pyx_PyInt_From_unsigned_int(((unsigned int)1)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 202, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5);
203: r"""Wavefront propagator based on Rayleigh-Sommerfeld convolution
204: method [RSC]_. Propagates a wavefront `wft` by `z` distance downstream.
205: You can choose between 'fftw' and 'numpy' backends for FFT calculations.
206:
207: Args:
208: wft (numpy.ndarray) : Initial wavefront.
209: dx0 (float) : Sampling interval at the plane upstream [um].
210: dx (float) : Sampling interval at the plane downstream [um].
211: z (float) : Propagation distance [um].
212: wl (float) : Incoming beam's wavelength [um].
213: axis (int) : Axis of `wft` array along which the calculation is performed.
214: backend (str) : Choose between numpy ('numpy') or FFTW ('fftw') library
215: for the FFT implementation.
216: num_threads (int) : Number of threads used in the calculations.
217:
218: Returns:
219: numpy.ndarray : Propagated wavefront.
220:
221: Raises:
222: RuntimeError : If 'numpy' backend exits with eror during the calculation.
223: ValueError : If `backend` option is invalid.
224:
225: Notes:
226: The Rayleigh-Sommerfeld diffraction integral transform is defined as:
227:
228: .. math::
229: u^{\prime}(x^{\prime}) = \frac{z}{j \sqrt{\lambda}} \int_{-\infty}^{+\infty}
230: u(x) \mathrm{exp} \left[-j k r(x, x^{\prime}) \right] dx
231:
232: with
233:
234: .. math::
235: r(x, x^{\prime}) = \left[ (x - x^{\prime})^2 + z^2 \right]^{1 / 2}
236:
237: References:
238: .. [RSC] V. Nascov and P. C. Logofătu, "Fast computation algorithm
239: for the Rayleigh-Sommerfeld diffraction formula using
240: a type of scaled convolution," Appl. Opt. 48, 4310-4319
241: (2009).
242: """
+243: wft = check_array(wft, np.NPY_COMPLEX128)
__pyx_t_1 = ((PyObject *)__pyx_f_6pyrost_3bin_10simulation_check_array(__pyx_v_wft, NPY_COMPLEX128)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 243, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_wft, ((PyArrayObject *)__pyx_t_1)); __pyx_t_1 = 0;
244:
+245: cdef int fail = 0
__pyx_v_fail = 0;
+246: cdef np.npy_intp isize = np.PyArray_SIZE(wft)
__pyx_v_isize = PyArray_SIZE(__pyx_v_wft);
+247: cdef int ndim = wft.ndim
__pyx_t_2 = __pyx_v_wft->nd; __pyx_v_ndim = __pyx_t_2;
+248: axis = axis if axis >= 0 else ndim + axis
if (((__pyx_v_axis >= 0) != 0)) {
__pyx_t_2 = __pyx_v_axis;
} else {
__pyx_t_2 = (__pyx_v_ndim + __pyx_v_axis);
}
__pyx_v_axis = __pyx_t_2;
+249: axis = axis if axis <= ndim - 1 else ndim - 1
if (((__pyx_v_axis <= (__pyx_v_ndim - 1)) != 0)) {
__pyx_t_3 = __pyx_v_axis;
} else {
__pyx_t_3 = (__pyx_v_ndim - 1);
}
__pyx_v_axis = __pyx_t_3;
+250: cdef np.npy_intp *dims = wft.shape
__pyx_t_4 = __pyx_v_wft->dimensions; __pyx_v_dims = __pyx_t_4;
+251: cdef unsigned long *_dims = <unsigned long *>dims
__pyx_v__dims = ((unsigned long *)__pyx_v_dims);
+252: cdef np.ndarray out = <np.ndarray>np.PyArray_SimpleNew(ndim, dims, np.NPY_COMPLEX128)
__pyx_t_1 = PyArray_SimpleNew(__pyx_v_ndim, __pyx_v_dims, NPY_COMPLEX128); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 252, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_5 = __pyx_t_1; __Pyx_INCREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_out = ((PyArrayObject *)__pyx_t_5); __pyx_t_5 = 0;
+253: cdef complex *_out = <complex *>np.PyArray_DATA(out)
__pyx_v__out = ((__pyx_t_double_complex *)PyArray_DATA(__pyx_v_out));
+254: cdef complex *_inp = <complex *>np.PyArray_DATA(wft)
__pyx_v__inp = ((__pyx_t_double_complex *)PyArray_DATA(__pyx_v_wft));
+255: with nogil:
{
#ifdef WITH_THREAD
PyThreadState *_save;
Py_UNBLOCK_THREADS
__Pyx_FastGIL_Remember();
#endif
/*try:*/ {
/* … */
/*finally:*/ {
/*normal exit:*/{
#ifdef WITH_THREAD
__Pyx_FastGIL_Forget();
Py_BLOCK_THREADS
#endif
goto __pyx_L5;
}
__pyx_L4_error: {
#ifdef WITH_THREAD
__Pyx_FastGIL_Forget();
Py_BLOCK_THREADS
#endif
goto __pyx_L1_error;
}
__pyx_L5:;
}
}
+256: if backend == 'fftw':
__pyx_t_6 = (__Pyx_PyUnicode_Equals(__pyx_v_backend, __pyx_n_u_fftw, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 256, __pyx_L4_error) __pyx_t_7 = (__pyx_t_6 != 0); if (__pyx_t_7) { /* … */ goto __pyx_L6; }
+257: fail = rsc_fftw(_out, _inp, ndim, _dims, axis, dx0, dx, z, wl, num_threads)
__pyx_v_fail = rsc_fftw(__pyx_v__out, __pyx_v__inp, __pyx_v_ndim, __pyx_v__dims, __pyx_v_axis, __pyx_v_dx0, __pyx_v_dx, __pyx_v_z, __pyx_v_wl, __pyx_v_num_threads);
+258: elif backend == 'numpy':
__pyx_t_7 = (__Pyx_PyUnicode_Equals(__pyx_v_backend, __pyx_n_u_numpy, Py_EQ)); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 258, __pyx_L4_error) __pyx_t_6 = (__pyx_t_7 != 0); if (__pyx_t_6) { /* … */ goto __pyx_L6; }
+259: fail = rsc_np(_out, _inp, ndim, _dims, axis, dx0, dx, z, wl, num_threads)
__pyx_v_fail = rsc_np(__pyx_v__out, __pyx_v__inp, __pyx_v_ndim, __pyx_v__dims, __pyx_v_axis, __pyx_v_dx0, __pyx_v_dx, __pyx_v_z, __pyx_v_wl, __pyx_v_num_threads);
260: else:
+261: raise ValueError('{:s} is invalid backend'.format(backend))
/*else*/ {
{
#ifdef WITH_THREAD
PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
#endif
/*try:*/ {
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_s_is_invalid_backend, __pyx_n_s_format); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 261, __pyx_L8_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_8 = NULL;
if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
__pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1);
if (likely(__pyx_t_8)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
__Pyx_INCREF(__pyx_t_8);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_1, function);
}
}
__pyx_t_5 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_8, __pyx_v_backend) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_backend);
__Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 261, __pyx_L8_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 261, __pyx_L8_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__Pyx_Raise(__pyx_t_1, 0, 0, 0);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__PYX_ERR(0, 261, __pyx_L8_error)
}
/*finally:*/ {
__pyx_L8_error: {
#ifdef WITH_THREAD
__Pyx_PyGILState_Release(__pyx_gilstate_save);
#endif
goto __pyx_L4_error;
}
}
}
}
__pyx_L6:;
}
+262: if fail:
__pyx_t_6 = (__pyx_v_fail != 0);
if (unlikely(__pyx_t_6)) {
/* … */
}
+263: raise RuntimeError('C backend exited with error.')
__pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_RuntimeError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 263, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __PYX_ERR(0, 263, __pyx_L1_error)
+264: return out
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_out)); __pyx_r = ((PyObject *)__pyx_v_out); goto __pyx_L0;
265:
+266: def fraunhofer_wp(np.ndarray wft not None, double dx0, double dx, double z,
/* Python wrapper */
static PyObject *__pyx_pw_6pyrost_3bin_10simulation_7fraunhofer_wp(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6pyrost_3bin_10simulation_6fraunhofer_wp[] = "Fraunhofer diffraction propagator. Propagates a wavefront `wft` by `z`\n distance downstream. You can choose between 'fftw' and 'numpy' backends for\n FFT calculations.\n\n Args: \n wft (numpy.ndarray) : Initial wavefront.\n dx0 (float) : Sampling interval at the plane upstream [um].\n dx (float) : Sampling interval at the plane downstream [um].\n z (float) : Propagation distance [um].\n wl (float) : Incoming beam's wavelength [um].\n axis (int) : Axis of `wft` array along which the calculation is performed.\n backend (str) : Choose between numpy ('numpy') or FFTW ('fftw') library\n for the FFT implementation.\n num_threads (int) : Number of threads used in the calculations.\n\n Returns:\n numpy.ndarray : Propagated wavefront.\n\n Raises:\n RuntimeError : If 'numpy' backend exits with eror during the calculation.\n ValueError : If `backend` option is invalid.\n\n Notes:\n The Fraunhofer integral transform is defined as:\n\n .. math::\n u^{\\prime}(x^{\\prime}) = \\frac{e^{-j k z}}{j \\sqrt{\\lambda z}}\n e^{-\\frac{j k}{2 z} x^{\\prime 2}} \\int_{-\\infty}^{+\\infty} u(x)\n e^{j\\frac{2 \\pi}{\\lambda z} x x^{\\prime}} dx\n ";
static PyMethodDef __pyx_mdef_6pyrost_3bin_10simulation_7fraunhofer_wp = {"fraunhofer_wp", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_6pyrost_3bin_10simulation_7fraunhofer_wp, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6pyrost_3bin_10simulation_6fraunhofer_wp};
static PyObject *__pyx_pw_6pyrost_3bin_10simulation_7fraunhofer_wp(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyArrayObject *__pyx_v_wft = 0;
double __pyx_v_dx0;
double __pyx_v_dx;
double __pyx_v_z;
double __pyx_v_wl;
int __pyx_v_axis;
PyObject *__pyx_v_backend = 0;
unsigned int __pyx_v_num_threads;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("fraunhofer_wp (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_wft,&__pyx_n_s_dx0,&__pyx_n_s_dx,&__pyx_n_s_z,&__pyx_n_s_wl,&__pyx_n_s_axis,&__pyx_n_s_backend,&__pyx_n_s_num_threads,0};
PyObject* values[8] = {0,0,0,0,0,0,0,0};
values[6] = ((PyObject*)((PyObject*)__pyx_n_u_numpy));
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
CYTHON_FALLTHROUGH;
case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
CYTHON_FALLTHROUGH;
case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
CYTHON_FALLTHROUGH;
case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
CYTHON_FALLTHROUGH;
case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
CYTHON_FALLTHROUGH;
case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
CYTHON_FALLTHROUGH;
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_wft)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_dx0)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("fraunhofer_wp", 0, 5, 8, 1); __PYX_ERR(0, 266, __pyx_L3_error)
}
CYTHON_FALLTHROUGH;
case 2:
if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_dx)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("fraunhofer_wp", 0, 5, 8, 2); __PYX_ERR(0, 266, __pyx_L3_error)
}
CYTHON_FALLTHROUGH;
case 3:
if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_z)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("fraunhofer_wp", 0, 5, 8, 3); __PYX_ERR(0, 266, __pyx_L3_error)
}
CYTHON_FALLTHROUGH;
case 4:
if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_wl)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("fraunhofer_wp", 0, 5, 8, 4); __PYX_ERR(0, 266, __pyx_L3_error)
}
CYTHON_FALLTHROUGH;
case 5:
if (kw_args > 0) {
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_axis);
if (value) { values[5] = value; kw_args--; }
}
CYTHON_FALLTHROUGH;
case 6:
if (kw_args > 0) {
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_backend);
if (value) { values[6] = value; kw_args--; }
}
CYTHON_FALLTHROUGH;
case 7:
if (kw_args > 0) {
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_num_threads);
if (value) { values[7] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fraunhofer_wp") < 0)) __PYX_ERR(0, 266, __pyx_L3_error)
}
} else {
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
CYTHON_FALLTHROUGH;
case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
CYTHON_FALLTHROUGH;
case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
CYTHON_FALLTHROUGH;
case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
break;
default: goto __pyx_L5_argtuple_error;
}
}
__pyx_v_wft = ((PyArrayObject *)values[0]);
__pyx_v_dx0 = __pyx_PyFloat_AsDouble(values[1]); if (unlikely((__pyx_v_dx0 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 266, __pyx_L3_error)
__pyx_v_dx = __pyx_PyFloat_AsDouble(values[2]); if (unlikely((__pyx_v_dx == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 266, __pyx_L3_error)
__pyx_v_z = __pyx_PyFloat_AsDouble(values[3]); if (unlikely((__pyx_v_z == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 266, __pyx_L3_error)
__pyx_v_wl = __pyx_PyFloat_AsDouble(values[4]); if (unlikely((__pyx_v_wl == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 267, __pyx_L3_error)
if (values[5]) {
__pyx_v_axis = __Pyx_PyInt_As_int(values[5]); if (unlikely((__pyx_v_axis == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 267, __pyx_L3_error)
} else {
__pyx_v_axis = ((int)((int)-1));
}
__pyx_v_backend = ((PyObject*)values[6]);
if (values[7]) {
__pyx_v_num_threads = __Pyx_PyInt_As_unsigned_int(values[7]); if (unlikely((__pyx_v_num_threads == (unsigned int)-1) && PyErr_Occurred())) __PYX_ERR(0, 267, __pyx_L3_error)
} else {
__pyx_v_num_threads = ((unsigned int)((unsigned int)1));
}
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("fraunhofer_wp", 0, 5, 8, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 266, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("pyrost.bin.simulation.fraunhofer_wp", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_wft), __pyx_ptype_5numpy_ndarray, 0, "wft", 0))) __PYX_ERR(0, 266, __pyx_L1_error)
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_backend), (&PyUnicode_Type), 1, "backend", 1))) __PYX_ERR(0, 267, __pyx_L1_error)
__pyx_r = __pyx_pf_6pyrost_3bin_10simulation_6fraunhofer_wp(__pyx_self, __pyx_v_wft, __pyx_v_dx0, __pyx_v_dx, __pyx_v_z, __pyx_v_wl, __pyx_v_axis, __pyx_v_backend, __pyx_v_num_threads);
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
/* function exit code */
goto __pyx_L0;
__pyx_L1_error:;
__pyx_r = NULL;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_6pyrost_3bin_10simulation_6fraunhofer_wp(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_wft, double __pyx_v_dx0, double __pyx_v_dx, double __pyx_v_z, double __pyx_v_wl, int __pyx_v_axis, PyObject *__pyx_v_backend, unsigned int __pyx_v_num_threads) {
int __pyx_v_fail;
CYTHON_UNUSED npy_intp __pyx_v_isize;
int __pyx_v_ndim;
npy_intp *__pyx_v_dims;
unsigned long *__pyx_v__dims;
PyArrayObject *__pyx_v_out = 0;
__pyx_t_double_complex *__pyx_v__out;
__pyx_t_double_complex *__pyx_v__inp;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("fraunhofer_wp", 0);
__Pyx_INCREF((PyObject *)__pyx_v_wft);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_XDECREF(__pyx_t_8);
__Pyx_AddTraceback("pyrost.bin.simulation.fraunhofer_wp", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF((PyObject *)__pyx_v_out);
__Pyx_XDECREF((PyObject *)__pyx_v_wft);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* … */
__pyx_tuple__17 = PyTuple_Pack(16, __pyx_n_s_wft, __pyx_n_s_dx0, __pyx_n_s_dx, __pyx_n_s_z, __pyx_n_s_wl, __pyx_n_s_axis, __pyx_n_s_backend, __pyx_n_s_num_threads, __pyx_n_s_fail, __pyx_n_s_isize, __pyx_n_s_ndim, __pyx_n_s_dims, __pyx_n_s_dims_2, __pyx_n_s_out, __pyx_n_s_out_2, __pyx_n_s_inp_2); if (unlikely(!__pyx_tuple__17)) __PYX_ERR(0, 266, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__17);
__Pyx_GIVEREF(__pyx_tuple__17);
/* … */
__pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 266, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_GIVEREF(__pyx_t_5);
PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
__Pyx_INCREF(((PyObject*)__pyx_n_u_numpy));
__Pyx_GIVEREF(((PyObject*)__pyx_n_u_numpy));
PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject*)__pyx_n_u_numpy));
__Pyx_GIVEREF(__pyx_t_3);
PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_3);
__pyx_t_5 = 0;
__pyx_t_3 = 0;
__pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_6pyrost_3bin_10simulation_7fraunhofer_wp, 0, __pyx_n_s_fraunhofer_wp, NULL, __pyx_n_s_pyrost_bin_simulation, __pyx_d, ((PyObject *)__pyx_codeobj__18)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 266, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_CyFunction_SetDefaultsTuple(__pyx_t_3, __pyx_t_4);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
if (PyDict_SetItem(__pyx_d, __pyx_n_s_fraunhofer_wp, __pyx_t_3) < 0) __PYX_ERR(0, 266, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_codeobj__18 = (PyObject*)__Pyx_PyCode_New(8, 0, 16, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__17, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pyrost_bin_simulation_pyx, __pyx_n_s_fraunhofer_wp, 266, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__18)) __PYX_ERR(0, 266, __pyx_L1_error)
+267: double wl, int axis=-1, str backend='numpy', unsigned num_threads=1):
__pyx_t_5 = __Pyx_PyInt_From_int(((int)-1)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 267, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_3 = __Pyx_PyInt_From_unsigned_int(((unsigned int)1)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 267, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3);
268: r"""Fraunhofer diffraction propagator. Propagates a wavefront `wft` by `z`
269: distance downstream. You can choose between 'fftw' and 'numpy' backends for
270: FFT calculations.
271:
272: Args:
273: wft (numpy.ndarray) : Initial wavefront.
274: dx0 (float) : Sampling interval at the plane upstream [um].
275: dx (float) : Sampling interval at the plane downstream [um].
276: z (float) : Propagation distance [um].
277: wl (float) : Incoming beam's wavelength [um].
278: axis (int) : Axis of `wft` array along which the calculation is performed.
279: backend (str) : Choose between numpy ('numpy') or FFTW ('fftw') library
280: for the FFT implementation.
281: num_threads (int) : Number of threads used in the calculations.
282:
283: Returns:
284: numpy.ndarray : Propagated wavefront.
285:
286: Raises:
287: RuntimeError : If 'numpy' backend exits with eror during the calculation.
288: ValueError : If `backend` option is invalid.
289:
290: Notes:
291: The Fraunhofer integral transform is defined as:
292:
293: .. math::
294: u^{\prime}(x^{\prime}) = \frac{e^{-j k z}}{j \sqrt{\lambda z}}
295: e^{-\frac{j k}{2 z} x^{\prime 2}} \int_{-\infty}^{+\infty} u(x)
296: e^{j\frac{2 \pi}{\lambda z} x x^{\prime}} dx
297: """
+298: wft = check_array(wft, np.NPY_COMPLEX128)
__pyx_t_1 = ((PyObject *)__pyx_f_6pyrost_3bin_10simulation_check_array(__pyx_v_wft, NPY_COMPLEX128)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 298, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_wft, ((PyArrayObject *)__pyx_t_1)); __pyx_t_1 = 0;
299:
+300: cdef int fail = 0
__pyx_v_fail = 0;
+301: cdef np.npy_intp isize = np.PyArray_SIZE(wft)
__pyx_v_isize = PyArray_SIZE(__pyx_v_wft);
+302: cdef int ndim = wft.ndim
__pyx_t_2 = __pyx_v_wft->nd; __pyx_v_ndim = __pyx_t_2;
+303: axis = axis if axis >= 0 else ndim + axis
if (((__pyx_v_axis >= 0) != 0)) {
__pyx_t_2 = __pyx_v_axis;
} else {
__pyx_t_2 = (__pyx_v_ndim + __pyx_v_axis);
}
__pyx_v_axis = __pyx_t_2;
+304: axis = axis if axis <= ndim - 1 else ndim - 1
if (((__pyx_v_axis <= (__pyx_v_ndim - 1)) != 0)) {
__pyx_t_3 = __pyx_v_axis;
} else {
__pyx_t_3 = (__pyx_v_ndim - 1);
}
__pyx_v_axis = __pyx_t_3;
+305: cdef np.npy_intp *dims = wft.shape
__pyx_t_4 = __pyx_v_wft->dimensions; __pyx_v_dims = __pyx_t_4;
+306: cdef unsigned long *_dims = <unsigned long *>dims
__pyx_v__dims = ((unsigned long *)__pyx_v_dims);
+307: cdef np.ndarray out = <np.ndarray>np.PyArray_SimpleNew(ndim, dims, np.NPY_COMPLEX128)
__pyx_t_1 = PyArray_SimpleNew(__pyx_v_ndim, __pyx_v_dims, NPY_COMPLEX128); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 307, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_5 = __pyx_t_1; __Pyx_INCREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_out = ((PyArrayObject *)__pyx_t_5); __pyx_t_5 = 0;
+308: cdef complex *_out = <complex *>np.PyArray_DATA(out)
__pyx_v__out = ((__pyx_t_double_complex *)PyArray_DATA(__pyx_v_out));
+309: cdef complex *_inp = <complex *>np.PyArray_DATA(wft)
__pyx_v__inp = ((__pyx_t_double_complex *)PyArray_DATA(__pyx_v_wft));
+310: with nogil:
{
#ifdef WITH_THREAD
PyThreadState *_save;
Py_UNBLOCK_THREADS
__Pyx_FastGIL_Remember();
#endif
/*try:*/ {
/* … */
/*finally:*/ {
/*normal exit:*/{
#ifdef WITH_THREAD
__Pyx_FastGIL_Forget();
Py_BLOCK_THREADS
#endif
goto __pyx_L5;
}
__pyx_L4_error: {
#ifdef WITH_THREAD
__Pyx_FastGIL_Forget();
Py_BLOCK_THREADS
#endif
goto __pyx_L1_error;
}
__pyx_L5:;
}
}
+311: if backend == 'fftw':
__pyx_t_6 = (__Pyx_PyUnicode_Equals(__pyx_v_backend, __pyx_n_u_fftw, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 311, __pyx_L4_error) __pyx_t_7 = (__pyx_t_6 != 0); if (__pyx_t_7) { /* … */ goto __pyx_L6; }
+312: fail = fraunhofer_fftw(_out, _inp, ndim, _dims, axis, dx0, dx, z, wl, num_threads)
__pyx_v_fail = fraunhofer_fftw(__pyx_v__out, __pyx_v__inp, __pyx_v_ndim, __pyx_v__dims, __pyx_v_axis, __pyx_v_dx0, __pyx_v_dx, __pyx_v_z, __pyx_v_wl, __pyx_v_num_threads);
+313: elif backend == 'numpy':
__pyx_t_7 = (__Pyx_PyUnicode_Equals(__pyx_v_backend, __pyx_n_u_numpy, Py_EQ)); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 313, __pyx_L4_error) __pyx_t_6 = (__pyx_t_7 != 0); if (__pyx_t_6) { /* … */ goto __pyx_L6; }
+314: fail = fraunhofer_np(_out, _inp, ndim, _dims, axis, dx0, dx, z, wl, num_threads)
__pyx_v_fail = fraunhofer_np(__pyx_v__out, __pyx_v__inp, __pyx_v_ndim, __pyx_v__dims, __pyx_v_axis, __pyx_v_dx0, __pyx_v_dx, __pyx_v_z, __pyx_v_wl, __pyx_v_num_threads);
315: else:
+316: raise ValueError('{:s} is invalid backend'.format(backend))
/*else*/ {
{
#ifdef WITH_THREAD
PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
#endif
/*try:*/ {
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_s_is_invalid_backend, __pyx_n_s_format); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 316, __pyx_L8_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_8 = NULL;
if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
__pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1);
if (likely(__pyx_t_8)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
__Pyx_INCREF(__pyx_t_8);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_1, function);
}
}
__pyx_t_5 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_8, __pyx_v_backend) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_backend);
__Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 316, __pyx_L8_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 316, __pyx_L8_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__Pyx_Raise(__pyx_t_1, 0, 0, 0);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__PYX_ERR(0, 316, __pyx_L8_error)
}
/*finally:*/ {
__pyx_L8_error: {
#ifdef WITH_THREAD
__Pyx_PyGILState_Release(__pyx_gilstate_save);
#endif
goto __pyx_L4_error;
}
}
}
}
__pyx_L6:;
}
+317: if fail:
__pyx_t_6 = (__pyx_v_fail != 0);
if (unlikely(__pyx_t_6)) {
/* … */
}
+318: raise RuntimeError('C backend exited with error.')
__pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_RuntimeError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 318, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __PYX_ERR(0, 318, __pyx_L1_error)
+319: return out
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_out)); __pyx_r = ((PyObject *)__pyx_v_out); goto __pyx_L0;
320:
+321: def gaussian_kernel(double sigma, unsigned order=0, double truncate=4.):
/* Python wrapper */
static PyObject *__pyx_pw_6pyrost_3bin_10simulation_9gaussian_kernel(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6pyrost_3bin_10simulation_8gaussian_kernel[] = "Discrete Gaussian kernel.\n \n Parameters:\n sigma (float) : Standard deviation for Gaussian kernel.\n order (int) : The order of the filter. An order of 0 corresponds to\n convolution with a Gaussian kernel. A positive order corresponds\n to convolution with that derivative of a Gaussian. Default is 0.\n truncate (float) : Truncate the filter at this many standard deviations.\n Default is 4.0.\n \n Returns:\n numpy.ndarray : Gaussian kernel.\n ";
static PyMethodDef __pyx_mdef_6pyrost_3bin_10simulation_9gaussian_kernel = {"gaussian_kernel", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_6pyrost_3bin_10simulation_9gaussian_kernel, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6pyrost_3bin_10simulation_8gaussian_kernel};
static PyObject *__pyx_pw_6pyrost_3bin_10simulation_9gaussian_kernel(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
double __pyx_v_sigma;
unsigned int __pyx_v_order;
double __pyx_v_truncate;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("gaussian_kernel (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_sigma,&__pyx_n_s_order,&__pyx_n_s_truncate,0};
PyObject* values[3] = {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 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
CYTHON_FALLTHROUGH;
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_sigma)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (kw_args > 0) {
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_order);
if (value) { values[1] = value; kw_args--; }
}
CYTHON_FALLTHROUGH;
case 2:
if (kw_args > 0) {
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_truncate);
if (value) { values[2] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "gaussian_kernel") < 0)) __PYX_ERR(0, 321, __pyx_L3_error)
}
} else {
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
CYTHON_FALLTHROUGH;
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
break;
default: goto __pyx_L5_argtuple_error;
}
}
__pyx_v_sigma = __pyx_PyFloat_AsDouble(values[0]); if (unlikely((__pyx_v_sigma == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 321, __pyx_L3_error)
if (values[1]) {
__pyx_v_order = __Pyx_PyInt_As_unsigned_int(values[1]); if (unlikely((__pyx_v_order == (unsigned int)-1) && PyErr_Occurred())) __PYX_ERR(0, 321, __pyx_L3_error)
} else {
__pyx_v_order = ((unsigned int)((unsigned int)0));
}
if (values[2]) {
__pyx_v_truncate = __pyx_PyFloat_AsDouble(values[2]); if (unlikely((__pyx_v_truncate == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 321, __pyx_L3_error)
} else {
__pyx_v_truncate = ((double)((double)4.));
}
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("gaussian_kernel", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 321, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("pyrost.bin.simulation.gaussian_kernel", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_6pyrost_3bin_10simulation_8gaussian_kernel(__pyx_self, __pyx_v_sigma, __pyx_v_order, __pyx_v_truncate);
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_6pyrost_3bin_10simulation_8gaussian_kernel(CYTHON_UNUSED PyObject *__pyx_self, double __pyx_v_sigma, unsigned int __pyx_v_order, double __pyx_v_truncate) {
npy_intp __pyx_v_radius;
npy_intp *__pyx_v_dims;
PyArrayObject *__pyx_v_out = 0;
double *__pyx_v__out;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("gaussian_kernel", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_AddTraceback("pyrost.bin.simulation.gaussian_kernel", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF((PyObject *)__pyx_v_out);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* … */
__pyx_tuple__19 = PyTuple_Pack(7, __pyx_n_s_sigma, __pyx_n_s_order, __pyx_n_s_truncate, __pyx_n_s_radius, __pyx_n_s_dims, __pyx_n_s_out, __pyx_n_s_out_2); if (unlikely(!__pyx_tuple__19)) __PYX_ERR(0, 321, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__19);
__Pyx_GIVEREF(__pyx_tuple__19);
/* … */
__pyx_t_3 = __Pyx_PyInt_From_unsigned_int(((unsigned int)0)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 321, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_4 = PyFloat_FromDouble(((double)4.)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 321, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 321, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_GIVEREF(__pyx_t_3);
PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
__Pyx_GIVEREF(__pyx_t_4);
PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_4);
__pyx_t_3 = 0;
__pyx_t_4 = 0;
__pyx_t_4 = __Pyx_CyFunction_New(&__pyx_mdef_6pyrost_3bin_10simulation_9gaussian_kernel, 0, __pyx_n_s_gaussian_kernel, NULL, __pyx_n_s_pyrost_bin_simulation, __pyx_d, ((PyObject *)__pyx_codeobj__20)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 321, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_CyFunction_SetDefaultsTuple(__pyx_t_4, __pyx_t_5);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
if (PyDict_SetItem(__pyx_d, __pyx_n_s_gaussian_kernel, __pyx_t_4) < 0) __PYX_ERR(0, 321, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_codeobj__20 = (PyObject*)__Pyx_PyCode_New(3, 0, 7, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__19, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pyrost_bin_simulation_pyx, __pyx_n_s_gaussian_kernel, 321, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__20)) __PYX_ERR(0, 321, __pyx_L1_error)
322: """Discrete Gaussian kernel.
323:
324: Parameters:
325: sigma (float) : Standard deviation for Gaussian kernel.
326: order (int) : The order of the filter. An order of 0 corresponds to
327: convolution with a Gaussian kernel. A positive order corresponds
328: to convolution with that derivative of a Gaussian. Default is 0.
329: truncate (float) : Truncate the filter at this many standard deviations.
330: Default is 4.0.
331:
332: Returns:
333: numpy.ndarray : Gaussian kernel.
334: """
+335: cdef np.npy_intp radius = <np.npy_intp>(sigma * truncate)
__pyx_v_radius = ((npy_intp)(__pyx_v_sigma * __pyx_v_truncate));
+336: cdef np.npy_intp *dims = [2 * radius + 1,]
__pyx_t_1[0] = ((2 * __pyx_v_radius) + 1); __pyx_v_dims = __pyx_t_1;
+337: cdef np.ndarray out = <np.ndarray>np.PyArray_SimpleNew(1, dims, np.NPY_FLOAT64)
__pyx_t_2 = PyArray_SimpleNew(1, __pyx_v_dims, NPY_FLOAT64); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 337, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_out = ((PyArrayObject *)__pyx_t_3); __pyx_t_3 = 0;
+338: cdef double *_out = <double *>np.PyArray_DATA(out)
__pyx_v__out = ((double *)PyArray_DATA(__pyx_v_out));
+339: with nogil:
{
#ifdef WITH_THREAD
PyThreadState *_save;
Py_UNBLOCK_THREADS
__Pyx_FastGIL_Remember();
#endif
/*try:*/ {
/* … */
/*finally:*/ {
/*normal exit:*/{
#ifdef WITH_THREAD
__Pyx_FastGIL_Forget();
Py_BLOCK_THREADS
#endif
goto __pyx_L5;
}
__pyx_L5:;
}
}
+340: gauss_kernel1d(_out, sigma, order, dims[0], 1)
(void)(gauss_kernel1d(__pyx_v__out, __pyx_v_sigma, __pyx_v_order, (__pyx_v_dims[0]), 1));
}
+341: return out
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_out)); __pyx_r = ((PyObject *)__pyx_v_out); goto __pyx_L0;
342:
+343: def gaussian_filter(np.ndarray inp not None, object sigma not None, object order not None=0,
/* Python wrapper */
static PyObject *__pyx_pw_6pyrost_3bin_10simulation_11gaussian_filter(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6pyrost_3bin_10simulation_10gaussian_filter[] = "Multidimensional Gaussian filter. The multidimensional filter is implemented as\n a sequence of 1-D FFT convolutions.\n\n Args:\n inp (numpy.ndarray) : The input array.\n sigma (Union[float, List[float]]): Standard deviation for Gaussian kernel. The standard\n deviations of the Gaussian filter are given for each axis as a sequence, or as a\n single number, in which case it is equal for all axes.\n order (Union[int, List[int]]): The order of the filter along each axis is given as a\n sequence of integers, or as a single number. An order of 0 corresponds to convolution\n with a Gaussian kernel. A positive order corresponds to convolution with that\n derivative of a Gaussian.\n mode (str) : The mode parameter determines how the input array is extended when the\n filter overlaps a border. Default value is 'reflect'. The valid values and their\n behavior is as follows:\n\n * 'constant', (k k k k | a b c d | k k k k) : The input is extended by filling all\n values beyond the edge with the same constant value, defined by the `cval`\n parameter.\n * 'nearest', (a a a a | a b c d | d d d d) : The input is extended by replicating\n the last pixel.\n * 'mirror', (c d c b | a b c d | c b a b) : The input is extended by reflecting\n about the center of the last pixel. This mode is also sometimes referred to as\n whole-sample symmetric.\n * 'reflect', (d c b a | a b c d | d c b a) : The input is extended by reflecting\n about the edge of the last pixel. This mode is also sometimes referred to as\n half-sample symmetric.\n * 'wrap', (a b c d | a b c d | a b c d) : The input is extended by wrapping around\n to the opposite edge.\n\n cval (float) : Value to fill past edges of input if mode is 'constant'. Defaul""t is 0.0.\n truncate (float) : Truncate the filter at this many standard deviations. Default is 4.0.\n backend (str) : Choose between numpy ('numpy') or FFTW ('fftw') backend library for the\n FFT implementation.\n num_threads (int) : Number of threads.\n \n Returns:\n numpy.ndarray : Returned array of the same shape as `input`.\n ";
static PyMethodDef __pyx_mdef_6pyrost_3bin_10simulation_11gaussian_filter = {"gaussian_filter", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_6pyrost_3bin_10simulation_11gaussian_filter, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6pyrost_3bin_10simulation_10gaussian_filter};
static PyObject *__pyx_pw_6pyrost_3bin_10simulation_11gaussian_filter(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyArrayObject *__pyx_v_inp = 0;
PyObject *__pyx_v_sigma = 0;
PyObject *__pyx_v_order = 0;
PyObject *__pyx_v_mode = 0;
double __pyx_v_cval;
double __pyx_v_truncate;
PyObject *__pyx_v_backend = 0;
unsigned int __pyx_v_num_threads;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("gaussian_filter (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_inp,&__pyx_n_s_sigma,&__pyx_n_s_order,&__pyx_n_s_mode,&__pyx_n_s_cval,&__pyx_n_s_truncate,&__pyx_n_s_backend,&__pyx_n_s_num_threads,0};
PyObject* values[8] = {0,0,0,0,0,0,0,0};
values[2] = ((PyObject *)((PyObject *)__pyx_int_0));
values[3] = ((PyObject*)((PyObject*)__pyx_n_u_reflect));
values[6] = ((PyObject*)((PyObject*)__pyx_n_u_numpy));
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
CYTHON_FALLTHROUGH;
case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
CYTHON_FALLTHROUGH;
case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
CYTHON_FALLTHROUGH;
case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
CYTHON_FALLTHROUGH;
case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
CYTHON_FALLTHROUGH;
case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
CYTHON_FALLTHROUGH;
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_inp)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_sigma)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("gaussian_filter", 0, 2, 8, 1); __PYX_ERR(0, 343, __pyx_L3_error)
}
CYTHON_FALLTHROUGH;
case 2:
if (kw_args > 0) {
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_order);
if (value) { values[2] = value; kw_args--; }
}
CYTHON_FALLTHROUGH;
case 3:
if (kw_args > 0) {
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mode);
if (value) { values[3] = value; kw_args--; }
}
CYTHON_FALLTHROUGH;
case 4:
if (kw_args > 0) {
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_cval);
if (value) { values[4] = value; kw_args--; }
}
CYTHON_FALLTHROUGH;
case 5:
if (kw_args > 0) {
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_truncate);
if (value) { values[5] = value; kw_args--; }
}
CYTHON_FALLTHROUGH;
case 6:
if (kw_args > 0) {
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_backend);
if (value) { values[6] = value; kw_args--; }
}
CYTHON_FALLTHROUGH;
case 7:
if (kw_args > 0) {
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_num_threads);
if (value) { values[7] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "gaussian_filter") < 0)) __PYX_ERR(0, 343, __pyx_L3_error)
}
} else {
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
CYTHON_FALLTHROUGH;
case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
CYTHON_FALLTHROUGH;
case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
CYTHON_FALLTHROUGH;
case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
CYTHON_FALLTHROUGH;
case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
CYTHON_FALLTHROUGH;
case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
CYTHON_FALLTHROUGH;
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
break;
default: goto __pyx_L5_argtuple_error;
}
}
__pyx_v_inp = ((PyArrayObject *)values[0]);
__pyx_v_sigma = values[1];
__pyx_v_order = values[2];
__pyx_v_mode = ((PyObject*)values[3]);
if (values[4]) {
__pyx_v_cval = __pyx_PyFloat_AsDouble(values[4]); if (unlikely((__pyx_v_cval == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 344, __pyx_L3_error)
} else {
__pyx_v_cval = ((double)((double)0.));
}
if (values[5]) {
__pyx_v_truncate = __pyx_PyFloat_AsDouble(values[5]); if (unlikely((__pyx_v_truncate == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 344, __pyx_L3_error)
} else {
__pyx_v_truncate = ((double)((double)4.));
}
__pyx_v_backend = ((PyObject*)values[6]);
if (values[7]) {
__pyx_v_num_threads = __Pyx_PyInt_As_unsigned_int(values[7]); if (unlikely((__pyx_v_num_threads == (unsigned int)-1) && PyErr_Occurred())) __PYX_ERR(0, 345, __pyx_L3_error)
} else {
__pyx_v_num_threads = ((unsigned int)((unsigned int)1));
}
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("gaussian_filter", 0, 2, 8, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 343, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("pyrost.bin.simulation.gaussian_filter", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_inp), __pyx_ptype_5numpy_ndarray, 0, "inp", 0))) __PYX_ERR(0, 343, __pyx_L1_error)
if (unlikely(((PyObject *)__pyx_v_sigma) == Py_None)) {
PyErr_Format(PyExc_TypeError, "Argument '%.200s' must not be None", "sigma"); __PYX_ERR(0, 343, __pyx_L1_error)
}
if (unlikely(((PyObject *)__pyx_v_order) == Py_None)) {
PyErr_Format(PyExc_TypeError, "Argument '%.200s' must not be None", "order"); __PYX_ERR(0, 343, __pyx_L1_error)
}
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_mode), (&PyUnicode_Type), 1, "mode", 1))) __PYX_ERR(0, 344, __pyx_L1_error)
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_backend), (&PyUnicode_Type), 1, "backend", 1))) __PYX_ERR(0, 344, __pyx_L1_error)
__pyx_r = __pyx_pf_6pyrost_3bin_10simulation_10gaussian_filter(__pyx_self, __pyx_v_inp, __pyx_v_sigma, __pyx_v_order, __pyx_v_mode, __pyx_v_cval, __pyx_v_truncate, __pyx_v_backend, __pyx_v_num_threads);
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
/* function exit code */
goto __pyx_L0;
__pyx_L1_error:;
__pyx_r = NULL;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_6pyrost_3bin_10simulation_10gaussian_filter(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_inp, PyObject *__pyx_v_sigma, PyObject *__pyx_v_order, PyObject *__pyx_v_mode, double __pyx_v_cval, double __pyx_v_truncate, PyObject *__pyx_v_backend, unsigned int __pyx_v_num_threads) {
int __pyx_v_ndim;
PyArrayObject *__pyx_v_sigmas = 0;
PyArrayObject *__pyx_v_orders = 0;
double *__pyx_v__sig;
unsigned int *__pyx_v__ord;
int __pyx_v_n;
int __pyx_v_fail;
int __pyx_v__mode;
npy_intp *__pyx_v_dims;
unsigned long *__pyx_v__dims;
int __pyx_v_type_num;
PyArrayObject *__pyx_v_out = 0;
void *__pyx_v__out;
void *__pyx_v__inp;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("gaussian_filter", 0);
__Pyx_INCREF((PyObject *)__pyx_v_inp);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_7);
__Pyx_XDECREF(__pyx_t_9);
__Pyx_AddTraceback("pyrost.bin.simulation.gaussian_filter", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF((PyObject *)__pyx_v_sigmas);
__Pyx_XDECREF((PyObject *)__pyx_v_orders);
__Pyx_XDECREF((PyObject *)__pyx_v_out);
__Pyx_XDECREF((PyObject *)__pyx_v_inp);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* … */
__pyx_tuple__21 = PyTuple_Pack(22, __pyx_n_s_inp, __pyx_n_s_sigma, __pyx_n_s_order, __pyx_n_s_mode, __pyx_n_s_cval, __pyx_n_s_truncate, __pyx_n_s_backend, __pyx_n_s_num_threads, __pyx_n_s_ndim, __pyx_n_s_sigmas, __pyx_n_s_orders, __pyx_n_s_sig, __pyx_n_s_ord, __pyx_n_s_n, __pyx_n_s_fail, __pyx_n_s_mode_2, __pyx_n_s_dims, __pyx_n_s_dims_2, __pyx_n_s_type_num, __pyx_n_s_out, __pyx_n_s_out_2, __pyx_n_s_inp_2); if (unlikely(!__pyx_tuple__21)) __PYX_ERR(0, 343, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__21);
__Pyx_GIVEREF(__pyx_tuple__21);
/* … */
__pyx_t_1 = PyTuple_New(6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 343, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_INCREF(((PyObject *)__pyx_int_0));
__Pyx_GIVEREF(((PyObject *)__pyx_int_0));
PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_int_0));
__Pyx_INCREF(((PyObject*)__pyx_n_u_reflect));
__Pyx_GIVEREF(((PyObject*)__pyx_n_u_reflect));
PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject*)__pyx_n_u_reflect));
__Pyx_GIVEREF(__pyx_t_4);
PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_4);
__Pyx_GIVEREF(__pyx_t_5);
PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_5);
__Pyx_INCREF(((PyObject*)__pyx_n_u_numpy));
__Pyx_GIVEREF(((PyObject*)__pyx_n_u_numpy));
PyTuple_SET_ITEM(__pyx_t_1, 4, ((PyObject*)__pyx_n_u_numpy));
__Pyx_GIVEREF(__pyx_t_3);
PyTuple_SET_ITEM(__pyx_t_1, 5, __pyx_t_3);
__pyx_t_4 = 0;
__pyx_t_5 = 0;
__pyx_t_3 = 0;
__pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_6pyrost_3bin_10simulation_11gaussian_filter, 0, __pyx_n_s_gaussian_filter, NULL, __pyx_n_s_pyrost_bin_simulation, __pyx_d, ((PyObject *)__pyx_codeobj__22)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 343, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_CyFunction_SetDefaultsTuple(__pyx_t_3, __pyx_t_1);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
if (PyDict_SetItem(__pyx_d, __pyx_n_s_gaussian_filter, __pyx_t_3) < 0) __PYX_ERR(0, 343, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_codeobj__22 = (PyObject*)__Pyx_PyCode_New(8, 0, 22, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__21, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pyrost_bin_simulation_pyx, __pyx_n_s_gaussian_filter, 343, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__22)) __PYX_ERR(0, 343, __pyx_L1_error)
+344: str mode='reflect', double cval=0., double truncate=4., str backend='numpy',
__pyx_t_4 = PyFloat_FromDouble(((double)0.)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 344, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = PyFloat_FromDouble(((double)4.)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 344, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5);
+345: unsigned num_threads=1):
__pyx_t_3 = __Pyx_PyInt_From_unsigned_int(((unsigned int)1)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 345, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3);
346: r"""Multidimensional Gaussian filter. The multidimensional filter is implemented as
347: a sequence of 1-D FFT convolutions.
348:
349: Args:
350: inp (numpy.ndarray) : The input array.
351: sigma (Union[float, List[float]]): Standard deviation for Gaussian kernel. The standard
352: deviations of the Gaussian filter are given for each axis as a sequence, or as a
353: single number, in which case it is equal for all axes.
354: order (Union[int, List[int]]): The order of the filter along each axis is given as a
355: sequence of integers, or as a single number. An order of 0 corresponds to convolution
356: with a Gaussian kernel. A positive order corresponds to convolution with that
357: derivative of a Gaussian.
358: mode (str) : The mode parameter determines how the input array is extended when the
359: filter overlaps a border. Default value is 'reflect'. The valid values and their
360: behavior is as follows:
361:
362: * 'constant', (k k k k | a b c d | k k k k) : The input is extended by filling all
363: values beyond the edge with the same constant value, defined by the `cval`
364: parameter.
365: * 'nearest', (a a a a | a b c d | d d d d) : The input is extended by replicating
366: the last pixel.
367: * 'mirror', (c d c b | a b c d | c b a b) : The input is extended by reflecting
368: about the center of the last pixel. This mode is also sometimes referred to as
369: whole-sample symmetric.
370: * 'reflect', (d c b a | a b c d | d c b a) : The input is extended by reflecting
371: about the edge of the last pixel. This mode is also sometimes referred to as
372: half-sample symmetric.
373: * 'wrap', (a b c d | a b c d | a b c d) : The input is extended by wrapping around
374: to the opposite edge.
375:
376: cval (float) : Value to fill past edges of input if mode is 'constant'. Default is 0.0.
377: truncate (float) : Truncate the filter at this many standard deviations. Default is 4.0.
378: backend (str) : Choose between numpy ('numpy') or FFTW ('fftw') backend library for the
379: FFT implementation.
380: num_threads (int) : Number of threads.
381:
382: Returns:
383: numpy.ndarray : Returned array of the same shape as `input`.
384: """
385:
+386: cdef int ndim = inp.ndim
__pyx_t_1 = __pyx_v_inp->nd; __pyx_v_ndim = __pyx_t_1;
+387: cdef np.ndarray sigmas = normalize_sequence(sigma, ndim, np.NPY_FLOAT64)
__pyx_t_2 = ((PyObject *)__pyx_f_6pyrost_3bin_10simulation_normalize_sequence(__pyx_v_sigma, __pyx_v_ndim, NPY_FLOAT64)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 387, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_sigmas = ((PyArrayObject *)__pyx_t_2); __pyx_t_2 = 0;
+388: cdef np.ndarray orders = normalize_sequence(order, ndim, np.NPY_UINT32)
__pyx_t_2 = ((PyObject *)__pyx_f_6pyrost_3bin_10simulation_normalize_sequence(__pyx_v_order, __pyx_v_ndim, NPY_UINT32)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 388, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_orders = ((PyArrayObject *)__pyx_t_2); __pyx_t_2 = 0;
+389: cdef double *_sig = <double *>np.PyArray_DATA(sigmas)
__pyx_v__sig = ((double *)PyArray_DATA(__pyx_v_sigmas));
+390: cdef unsigned *_ord = <unsigned *>np.PyArray_DATA(orders)
__pyx_v__ord = ((unsigned int *)PyArray_DATA(__pyx_v_orders));
391:
392: cdef int n
+393: for n in range(ndim):
__pyx_t_1 = __pyx_v_ndim;
__pyx_t_3 = __pyx_t_1;
for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
__pyx_v_n = __pyx_t_4;
+394: if inp.shape[n] == 1:
__pyx_t_5 = (((__pyx_v_inp->dimensions[__pyx_v_n]) == 1) != 0);
if (__pyx_t_5) {
/* … */
}
}
+395: sigmas[n] = 0.0
if (unlikely(__Pyx_SetItemInt(((PyObject *)__pyx_v_sigmas), __pyx_v_n, __pyx_float_0_0, int, 1, __Pyx_PyInt_From_int, 0, 0, 0) < 0)) __PYX_ERR(0, 395, __pyx_L1_error)
396:
+397: cdef int fail = 0
__pyx_v_fail = 0;
+398: cdef int _mode = extend_mode_to_code(mode)
__pyx_t_1 = __pyx_f_6pyrost_3bin_10simulation_extend_mode_to_code(__pyx_v_mode); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(0, 398, __pyx_L1_error)
__pyx_v__mode = __pyx_t_1;
+399: cdef np.npy_intp *dims = inp.shape
__pyx_t_6 = __pyx_v_inp->dimensions; __pyx_v_dims = __pyx_t_6;
+400: cdef unsigned long *_dims = <unsigned long *>dims
__pyx_v__dims = ((unsigned long *)__pyx_v_dims);
401:
402: cdef int type_num
+403: if np.PyArray_ISCOMPLEX(inp):
__pyx_t_5 = (PyArray_ISCOMPLEX(__pyx_v_inp) != 0);
if (__pyx_t_5) {
/* … */
goto __pyx_L6;
}
+404: type_num = np.NPY_COMPLEX128
__pyx_v_type_num = NPY_COMPLEX128;
405: else:
+406: type_num = np.NPY_FLOAT64
/*else*/ {
__pyx_v_type_num = NPY_FLOAT64;
}
__pyx_L6:;
407:
+408: cdef np.ndarray out = <np.ndarray>np.PyArray_SimpleNew(ndim, dims, type_num)
__pyx_t_2 = PyArray_SimpleNew(__pyx_v_ndim, __pyx_v_dims, __pyx_v_type_num); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 408, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_7 = __pyx_t_2; __Pyx_INCREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_out = ((PyArrayObject *)__pyx_t_7); __pyx_t_7 = 0;
+409: cdef void *_out = np.PyArray_DATA(out)
__pyx_v__out = PyArray_DATA(__pyx_v_out);
410:
411: cdef void *_inp
+412: if np.PyArray_ISCOMPLEX(inp):
__pyx_t_5 = (PyArray_ISCOMPLEX(__pyx_v_inp) != 0);
if (__pyx_t_5) {
/* … */
goto __pyx_L7;
}
+413: inp = check_array(inp, np.NPY_COMPLEX128)
__pyx_t_7 = ((PyObject *)__pyx_f_6pyrost_3bin_10simulation_check_array(__pyx_v_inp, NPY_COMPLEX128)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 413, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF_SET(__pyx_v_inp, ((PyArrayObject *)__pyx_t_7)); __pyx_t_7 = 0;
+414: _inp = <double *>np.PyArray_DATA(inp)
__pyx_v__inp = ((double *)PyArray_DATA(__pyx_v_inp));
415:
+416: with nogil:
{
#ifdef WITH_THREAD
PyThreadState *_save;
Py_UNBLOCK_THREADS
__Pyx_FastGIL_Remember();
#endif
/*try:*/ {
/* … */
/*finally:*/ {
/*normal exit:*/{
#ifdef WITH_THREAD
__Pyx_FastGIL_Forget();
Py_BLOCK_THREADS
#endif
goto __pyx_L10;
}
__pyx_L9_error: {
#ifdef WITH_THREAD
__Pyx_FastGIL_Forget();
Py_BLOCK_THREADS
#endif
goto __pyx_L1_error;
}
__pyx_L10:;
}
}
+417: if backend == 'fftw':
__pyx_t_5 = (__Pyx_PyUnicode_Equals(__pyx_v_backend, __pyx_n_u_fftw, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 417, __pyx_L9_error) __pyx_t_8 = (__pyx_t_5 != 0); if (__pyx_t_8) { /* … */ goto __pyx_L11; }
+418: fail = gauss_filter_c(<double complex *>_out, <double complex *>_inp,
__pyx_v_fail = gauss_filter_c(((__pyx_t_double_complex *)__pyx_v__out), ((__pyx_t_double_complex *)__pyx_v__inp), __pyx_v_ndim, __pyx_v__dims, __pyx_v__sig, __pyx_v__ord, __pyx_v__mode, __pyx_t_double_complex_from_parts(((double)__pyx_v_cval), 0), __pyx_v_truncate, __pyx_v_num_threads, cfft_convolve_fftw);
419: ndim, _dims, _sig, _ord, _mode, <double complex>cval,
420: truncate, num_threads, cfft_convolve_fftw)
+421: elif backend == 'numpy':
__pyx_t_8 = (__Pyx_PyUnicode_Equals(__pyx_v_backend, __pyx_n_u_numpy, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 421, __pyx_L9_error) __pyx_t_5 = (__pyx_t_8 != 0); if (__pyx_t_5) { /* … */ goto __pyx_L11; }
+422: fail = gauss_filter_c(<double complex *>_out, <double complex *>_inp,
__pyx_v_fail = gauss_filter_c(((__pyx_t_double_complex *)__pyx_v__out), ((__pyx_t_double_complex *)__pyx_v__inp), __pyx_v_ndim, __pyx_v__dims, __pyx_v__sig, __pyx_v__ord, __pyx_v__mode, __pyx_t_double_complex_from_parts(((double)__pyx_v_cval), 0), __pyx_v_truncate, __pyx_v_num_threads, cfft_convolve_np);
423: ndim, _dims, _sig, _ord, _mode, <double complex>cval,
424: truncate, num_threads, cfft_convolve_np)
425: else:
+426: raise ValueError('{:s} is invalid backend'.format(backend))
/*else*/ {
{
#ifdef WITH_THREAD
PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
#endif
/*try:*/ {
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_s_is_invalid_backend, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 426, __pyx_L13_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_9 = NULL;
if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
__pyx_t_9 = PyMethod_GET_SELF(__pyx_t_2);
if (likely(__pyx_t_9)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
__Pyx_INCREF(__pyx_t_9);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_2, function);
}
}
__pyx_t_7 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_9, __pyx_v_backend) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_backend);
__Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 426, __pyx_L13_error)
__Pyx_GOTREF(__pyx_t_7);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 426, __pyx_L13_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
__Pyx_Raise(__pyx_t_2, 0, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__PYX_ERR(0, 426, __pyx_L13_error)
}
/*finally:*/ {
__pyx_L13_error: {
#ifdef WITH_THREAD
__Pyx_PyGILState_Release(__pyx_gilstate_save);
#endif
goto __pyx_L9_error;
}
}
}
}
__pyx_L11:;
}
427:
428: else:
+429: inp = check_array(inp, np.NPY_FLOAT64)
/*else*/ {
__pyx_t_2 = ((PyObject *)__pyx_f_6pyrost_3bin_10simulation_check_array(__pyx_v_inp, NPY_FLOAT64)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 429, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF_SET(__pyx_v_inp, ((PyArrayObject *)__pyx_t_2));
__pyx_t_2 = 0;
+430: _inp = <double *>np.PyArray_DATA(inp)
__pyx_v__inp = ((double *)PyArray_DATA(__pyx_v_inp));
431:
+432: with nogil:
{
#ifdef WITH_THREAD
PyThreadState *_save;
Py_UNBLOCK_THREADS
__Pyx_FastGIL_Remember();
#endif
/*try:*/ {
/* … */
/*finally:*/ {
/*normal exit:*/{
#ifdef WITH_THREAD
__Pyx_FastGIL_Forget();
Py_BLOCK_THREADS
#endif
goto __pyx_L17;
}
__pyx_L16_error: {
#ifdef WITH_THREAD
__Pyx_FastGIL_Forget();
Py_BLOCK_THREADS
#endif
goto __pyx_L1_error;
}
__pyx_L17:;
}
}
}
__pyx_L7:;
+433: if backend == 'fftw':
__pyx_t_5 = (__Pyx_PyUnicode_Equals(__pyx_v_backend, __pyx_n_u_fftw, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 433, __pyx_L16_error) __pyx_t_8 = (__pyx_t_5 != 0); if (__pyx_t_8) { /* … */ goto __pyx_L18; }
+434: fail = gauss_filter_r(<double *>_out, <double *>_inp, ndim, _dims, _sig,
__pyx_v_fail = gauss_filter_r(((double *)__pyx_v__out), ((double *)__pyx_v__inp), __pyx_v_ndim, __pyx_v__dims, __pyx_v__sig, __pyx_v__ord, __pyx_v__mode, __pyx_v_cval, __pyx_v_truncate, __pyx_v_num_threads, rfft_convolve_fftw);
435: _ord, _mode, cval, truncate, num_threads, rfft_convolve_fftw)
+436: elif backend == 'numpy':
__pyx_t_8 = (__Pyx_PyUnicode_Equals(__pyx_v_backend, __pyx_n_u_numpy, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 436, __pyx_L16_error) __pyx_t_5 = (__pyx_t_8 != 0); if (__pyx_t_5) { /* … */ goto __pyx_L18; }
+437: fail = gauss_filter_r(<double *>_out, <double *>_inp, ndim, _dims, _sig,
__pyx_v_fail = gauss_filter_r(((double *)__pyx_v__out), ((double *)__pyx_v__inp), __pyx_v_ndim, __pyx_v__dims, __pyx_v__sig, __pyx_v__ord, __pyx_v__mode, __pyx_v_cval, __pyx_v_truncate, __pyx_v_num_threads, rfft_convolve_np);
438: _ord, _mode, cval, truncate, num_threads, rfft_convolve_np)
439: else:
+440: raise ValueError('{:s} is invalid backend'.format(backend))
/*else*/ {
{
#ifdef WITH_THREAD
PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
#endif
/*try:*/ {
__pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_s_is_invalid_backend, __pyx_n_s_format); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 440, __pyx_L20_error)
__Pyx_GOTREF(__pyx_t_7);
__pyx_t_9 = NULL;
if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
__pyx_t_9 = PyMethod_GET_SELF(__pyx_t_7);
if (likely(__pyx_t_9)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
__Pyx_INCREF(__pyx_t_9);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_7, function);
}
}
__pyx_t_2 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_9, __pyx_v_backend) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_backend);
__Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 440, __pyx_L20_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
__pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 440, __pyx_L20_error)
__Pyx_GOTREF(__pyx_t_7);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_Raise(__pyx_t_7, 0, 0, 0);
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
__PYX_ERR(0, 440, __pyx_L20_error)
}
/*finally:*/ {
__pyx_L20_error: {
#ifdef WITH_THREAD
__Pyx_PyGILState_Release(__pyx_gilstate_save);
#endif
goto __pyx_L16_error;
}
}
}
}
__pyx_L18:;
}
441:
+442: if fail:
__pyx_t_5 = (__pyx_v_fail != 0);
if (unlikely(__pyx_t_5)) {
/* … */
}
+443: raise RuntimeError('C backend exited with error.')
__pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_RuntimeError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 443, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_Raise(__pyx_t_7, 0, 0, 0); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __PYX_ERR(0, 443, __pyx_L1_error)
+444: return out
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_out)); __pyx_r = ((PyObject *)__pyx_v_out); goto __pyx_L0;
445:
+446: def gaussian_gradient_magnitude(np.ndarray inp not None, object sigma not None, str mode='reflect',
/* Python wrapper */
static PyObject *__pyx_pw_6pyrost_3bin_10simulation_13gaussian_gradient_magnitude(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6pyrost_3bin_10simulation_12gaussian_gradient_magnitude[] = "Multidimensional gradient magnitude using Gaussian derivatives. The multidimensional\n filter is implemented as a sequence of 1-D FFT convolutions.\n\n Args:\n inp (numpy.ndarray) : The input array.\n sigma (Union[float, List[float]]): Standard deviation for Gaussian kernel. The standard\n deviations of the Gaussian filter are given for each axis as a sequence, or as a\n single number, in which case it is equal for all axes.\n mode (str) : The mode parameter determines how the input array is extended when the\n filter overlaps a border. Default value is 'reflect'. The valid values and their\n behavior is as follows:\n\n * 'constant', (k k k k | a b c d | k k k k) : The input is extended by filling all\n values beyond the edge with the same constant value, defined by the `cval`\n parameter.\n * 'nearest', (a a a a | a b c d | d d d d) : The input is extended by replicating\n the last pixel.\n * 'mirror', (c d c b | a b c d | c b a b) : The input is extended by reflecting\n about the center of the last pixel. This mode is also sometimes referred to as\n whole-sample symmetric.\n * 'reflect', (d c b a | a b c d | d c b a) : The input is extended by reflecting\n about the edge of the last pixel. This mode is also sometimes referred to as\n half-sample symmetric.\n * 'wrap', (a b c d | a b c d | a b c d) : The input is extended by wrapping around\n to the opposite edge.\n\n cval (float) : Value to fill past edges of input if mode is \342\200\230constant\342\200\231. Default is 0.0.\n truncate (float) : Truncate the filter at this many standard deviations. Default is 4.0.\n backend (str) : Choose between numpy ('numpy') or FFTW ('fftw') backend library for the\n FFT implementation.\n num_threads (int) : Numb""er of threads.\n\n Returns:\n numpy.ndarray : Gaussian gradient magnitude array. The array is the same shape as `input`.\n ";
static PyMethodDef __pyx_mdef_6pyrost_3bin_10simulation_13gaussian_gradient_magnitude = {"gaussian_gradient_magnitude", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_6pyrost_3bin_10simulation_13gaussian_gradient_magnitude, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6pyrost_3bin_10simulation_12gaussian_gradient_magnitude};
static PyObject *__pyx_pw_6pyrost_3bin_10simulation_13gaussian_gradient_magnitude(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyArrayObject *__pyx_v_inp = 0;
PyObject *__pyx_v_sigma = 0;
PyObject *__pyx_v_mode = 0;
double __pyx_v_cval;
double __pyx_v_truncate;
PyObject *__pyx_v_backend = 0;
unsigned int __pyx_v_num_threads;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("gaussian_gradient_magnitude (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_inp,&__pyx_n_s_sigma,&__pyx_n_s_mode,&__pyx_n_s_cval,&__pyx_n_s_truncate,&__pyx_n_s_backend,&__pyx_n_s_num_threads,0};
PyObject* values[7] = {0,0,0,0,0,0,0};
values[2] = ((PyObject*)((PyObject*)__pyx_n_u_reflect));
values[5] = ((PyObject*)((PyObject*)__pyx_n_u_numpy));
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);
CYTHON_FALLTHROUGH;
case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
CYTHON_FALLTHROUGH;
case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
CYTHON_FALLTHROUGH;
case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
CYTHON_FALLTHROUGH;
case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
CYTHON_FALLTHROUGH;
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_inp)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_sigma)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("gaussian_gradient_magnitude", 0, 2, 7, 1); __PYX_ERR(0, 446, __pyx_L3_error)
}
CYTHON_FALLTHROUGH;
case 2:
if (kw_args > 0) {
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mode);
if (value) { values[2] = value; kw_args--; }
}
CYTHON_FALLTHROUGH;
case 3:
if (kw_args > 0) {
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_cval);
if (value) { values[3] = value; kw_args--; }
}
CYTHON_FALLTHROUGH;
case 4:
if (kw_args > 0) {
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_truncate);
if (value) { values[4] = value; kw_args--; }
}
CYTHON_FALLTHROUGH;
case 5:
if (kw_args > 0) {
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_backend);
if (value) { values[5] = value; kw_args--; }
}
CYTHON_FALLTHROUGH;
case 6:
if (kw_args > 0) {
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_num_threads);
if (value) { values[6] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "gaussian_gradient_magnitude") < 0)) __PYX_ERR(0, 446, __pyx_L3_error)
}
} else {
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
CYTHON_FALLTHROUGH;
case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
CYTHON_FALLTHROUGH;
case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
CYTHON_FALLTHROUGH;
case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
CYTHON_FALLTHROUGH;
case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
CYTHON_FALLTHROUGH;
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
break;
default: goto __pyx_L5_argtuple_error;
}
}
__pyx_v_inp = ((PyArrayObject *)values[0]);
__pyx_v_sigma = values[1];
__pyx_v_mode = ((PyObject*)values[2]);
if (values[3]) {
__pyx_v_cval = __pyx_PyFloat_AsDouble(values[3]); if (unlikely((__pyx_v_cval == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 447, __pyx_L3_error)
} else {
__pyx_v_cval = ((double)((double)0.0));
}
if (values[4]) {
__pyx_v_truncate = __pyx_PyFloat_AsDouble(values[4]); if (unlikely((__pyx_v_truncate == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 447, __pyx_L3_error)
} else {
__pyx_v_truncate = ((double)((double)4.0));
}
__pyx_v_backend = ((PyObject*)values[5]);
if (values[6]) {
__pyx_v_num_threads = __Pyx_PyInt_As_unsigned_int(values[6]); if (unlikely((__pyx_v_num_threads == (unsigned int)-1) && PyErr_Occurred())) __PYX_ERR(0, 448, __pyx_L3_error)
} else {
__pyx_v_num_threads = ((unsigned int)((unsigned int)1));
}
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("gaussian_gradient_magnitude", 0, 2, 7, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 446, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("pyrost.bin.simulation.gaussian_gradient_magnitude", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_inp), __pyx_ptype_5numpy_ndarray, 0, "inp", 0))) __PYX_ERR(0, 446, __pyx_L1_error)
if (unlikely(((PyObject *)__pyx_v_sigma) == Py_None)) {
PyErr_Format(PyExc_TypeError, "Argument '%.200s' must not be None", "sigma"); __PYX_ERR(0, 446, __pyx_L1_error)
}
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_mode), (&PyUnicode_Type), 1, "mode", 1))) __PYX_ERR(0, 446, __pyx_L1_error)
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_backend), (&PyUnicode_Type), 1, "backend", 1))) __PYX_ERR(0, 447, __pyx_L1_error)
__pyx_r = __pyx_pf_6pyrost_3bin_10simulation_12gaussian_gradient_magnitude(__pyx_self, __pyx_v_inp, __pyx_v_sigma, __pyx_v_mode, __pyx_v_cval, __pyx_v_truncate, __pyx_v_backend, __pyx_v_num_threads);
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
/* function exit code */
goto __pyx_L0;
__pyx_L1_error:;
__pyx_r = NULL;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_6pyrost_3bin_10simulation_12gaussian_gradient_magnitude(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_inp, PyObject *__pyx_v_sigma, PyObject *__pyx_v_mode, double __pyx_v_cval, double __pyx_v_truncate, PyObject *__pyx_v_backend, unsigned int __pyx_v_num_threads) {
int __pyx_v_ndim;
PyArrayObject *__pyx_v_sigmas = 0;
double *__pyx_v__sig;
int __pyx_v_n;
int __pyx_v_fail;
int __pyx_v__mode;
npy_intp *__pyx_v_dims;
unsigned long *__pyx_v__dims;
PyArrayObject *__pyx_v_out = 0;
double *__pyx_v__out;
void *__pyx_v__inp;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("gaussian_gradient_magnitude", 0);
__Pyx_INCREF((PyObject *)__pyx_v_inp);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_7);
__Pyx_XDECREF(__pyx_t_9);
__Pyx_AddTraceback("pyrost.bin.simulation.gaussian_gradient_magnitude", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF((PyObject *)__pyx_v_sigmas);
__Pyx_XDECREF((PyObject *)__pyx_v_out);
__Pyx_XDECREF((PyObject *)__pyx_v_inp);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* … */
__pyx_tuple__23 = PyTuple_Pack(18, __pyx_n_s_inp, __pyx_n_s_sigma, __pyx_n_s_mode, __pyx_n_s_cval, __pyx_n_s_truncate, __pyx_n_s_backend, __pyx_n_s_num_threads, __pyx_n_s_ndim, __pyx_n_s_sigmas, __pyx_n_s_sig, __pyx_n_s_n, __pyx_n_s_fail, __pyx_n_s_mode_2, __pyx_n_s_dims, __pyx_n_s_dims_2, __pyx_n_s_out, __pyx_n_s_out_2, __pyx_n_s_inp_2); if (unlikely(!__pyx_tuple__23)) __PYX_ERR(0, 446, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__23);
__Pyx_GIVEREF(__pyx_tuple__23);
/* … */
__pyx_t_4 = PyTuple_New(5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 446, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_INCREF(((PyObject*)__pyx_n_u_reflect));
__Pyx_GIVEREF(((PyObject*)__pyx_n_u_reflect));
PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject*)__pyx_n_u_reflect));
__Pyx_GIVEREF(__pyx_t_3);
PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
__Pyx_GIVEREF(__pyx_t_1);
PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_1);
__Pyx_INCREF(((PyObject*)__pyx_n_u_numpy));
__Pyx_GIVEREF(((PyObject*)__pyx_n_u_numpy));
PyTuple_SET_ITEM(__pyx_t_4, 3, ((PyObject*)__pyx_n_u_numpy));
__Pyx_GIVEREF(__pyx_t_5);
PyTuple_SET_ITEM(__pyx_t_4, 4, __pyx_t_5);
__pyx_t_3 = 0;
__pyx_t_1 = 0;
__pyx_t_5 = 0;
__pyx_t_5 = __Pyx_CyFunction_New(&__pyx_mdef_6pyrost_3bin_10simulation_13gaussian_gradient_magnitude, 0, __pyx_n_s_gaussian_gradient_magnitude, NULL, __pyx_n_s_pyrost_bin_simulation, __pyx_d, ((PyObject *)__pyx_codeobj__24)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 446, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_CyFunction_SetDefaultsTuple(__pyx_t_5, __pyx_t_4);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
if (PyDict_SetItem(__pyx_d, __pyx_n_s_gaussian_gradient_magnitude, __pyx_t_5) < 0) __PYX_ERR(0, 446, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__pyx_codeobj__24 = (PyObject*)__Pyx_PyCode_New(7, 0, 18, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__23, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pyrost_bin_simulation_pyx, __pyx_n_s_gaussian_gradient_magnitude, 446, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__24)) __PYX_ERR(0, 446, __pyx_L1_error)
+447: double cval=0.0, double truncate=4.0, str backend='numpy',
__pyx_t_3 = PyFloat_FromDouble(((double)0.0)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 447, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_1 = PyFloat_FromDouble(((double)4.0)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 447, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1);
+448: unsigned num_threads=1):
__pyx_t_5 = __Pyx_PyInt_From_unsigned_int(((unsigned int)1)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 448, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5);
449: r"""Multidimensional gradient magnitude using Gaussian derivatives. The multidimensional
450: filter is implemented as a sequence of 1-D FFT convolutions.
451:
452: Args:
453: inp (numpy.ndarray) : The input array.
454: sigma (Union[float, List[float]]): Standard deviation for Gaussian kernel. The standard
455: deviations of the Gaussian filter are given for each axis as a sequence, or as a
456: single number, in which case it is equal for all axes.
457: mode (str) : The mode parameter determines how the input array is extended when the
458: filter overlaps a border. Default value is 'reflect'. The valid values and their
459: behavior is as follows:
460:
461: * 'constant', (k k k k | a b c d | k k k k) : The input is extended by filling all
462: values beyond the edge with the same constant value, defined by the `cval`
463: parameter.
464: * 'nearest', (a a a a | a b c d | d d d d) : The input is extended by replicating
465: the last pixel.
466: * 'mirror', (c d c b | a b c d | c b a b) : The input is extended by reflecting
467: about the center of the last pixel. This mode is also sometimes referred to as
468: whole-sample symmetric.
469: * 'reflect', (d c b a | a b c d | d c b a) : The input is extended by reflecting
470: about the edge of the last pixel. This mode is also sometimes referred to as
471: half-sample symmetric.
472: * 'wrap', (a b c d | a b c d | a b c d) : The input is extended by wrapping around
473: to the opposite edge.
474:
475: cval (float) : Value to fill past edges of input if mode is ‘constant’. Default is 0.0.
476: truncate (float) : Truncate the filter at this many standard deviations. Default is 4.0.
477: backend (str) : Choose between numpy ('numpy') or FFTW ('fftw') backend library for the
478: FFT implementation.
479: num_threads (int) : Number of threads.
480:
481: Returns:
482: numpy.ndarray : Gaussian gradient magnitude array. The array is the same shape as `input`.
483: """
+484: cdef int ndim = inp.ndim
__pyx_t_1 = __pyx_v_inp->nd; __pyx_v_ndim = __pyx_t_1;
+485: cdef np.ndarray sigmas = normalize_sequence(sigma, ndim, np.NPY_FLOAT64)
__pyx_t_2 = ((PyObject *)__pyx_f_6pyrost_3bin_10simulation_normalize_sequence(__pyx_v_sigma, __pyx_v_ndim, NPY_FLOAT64)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 485, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_sigmas = ((PyArrayObject *)__pyx_t_2); __pyx_t_2 = 0;
+486: cdef double *_sig = <double *>np.PyArray_DATA(sigmas)
__pyx_v__sig = ((double *)PyArray_DATA(__pyx_v_sigmas));
487:
488: cdef int n
+489: for n in range(ndim):
__pyx_t_1 = __pyx_v_ndim;
__pyx_t_3 = __pyx_t_1;
for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
__pyx_v_n = __pyx_t_4;
+490: if inp.shape[n] == 1:
__pyx_t_5 = (((__pyx_v_inp->dimensions[__pyx_v_n]) == 1) != 0);
if (__pyx_t_5) {
/* … */
}
}
+491: sigmas[n] = 0.0
if (unlikely(__Pyx_SetItemInt(((PyObject *)__pyx_v_sigmas), __pyx_v_n, __pyx_float_0_0, int, 1, __Pyx_PyInt_From_int, 0, 0, 0) < 0)) __PYX_ERR(0, 491, __pyx_L1_error)
492:
+493: cdef int fail = 0
__pyx_v_fail = 0;
+494: cdef int _mode = extend_mode_to_code(mode)
__pyx_t_1 = __pyx_f_6pyrost_3bin_10simulation_extend_mode_to_code(__pyx_v_mode); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(0, 494, __pyx_L1_error)
__pyx_v__mode = __pyx_t_1;
+495: cdef np.npy_intp *dims = inp.shape
__pyx_t_6 = __pyx_v_inp->dimensions; __pyx_v_dims = __pyx_t_6;
+496: cdef unsigned long *_dims = <unsigned long *>dims
__pyx_v__dims = ((unsigned long *)__pyx_v_dims);
497:
+498: cdef np.ndarray out = <np.ndarray>np.PyArray_SimpleNew(ndim, dims, np.NPY_FLOAT64)
__pyx_t_2 = PyArray_SimpleNew(__pyx_v_ndim, __pyx_v_dims, NPY_FLOAT64); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 498, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_7 = __pyx_t_2; __Pyx_INCREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_out = ((PyArrayObject *)__pyx_t_7); __pyx_t_7 = 0;
+499: cdef double *_out = <double *>np.PyArray_DATA(out)
__pyx_v__out = ((double *)PyArray_DATA(__pyx_v_out));
500:
501: cdef void *_inp
+502: if np.PyArray_ISCOMPLEX(inp):
__pyx_t_5 = (PyArray_ISCOMPLEX(__pyx_v_inp) != 0);
if (__pyx_t_5) {
/* … */
goto __pyx_L6;
}
+503: inp = check_array(inp, np.NPY_COMPLEX128)
__pyx_t_7 = ((PyObject *)__pyx_f_6pyrost_3bin_10simulation_check_array(__pyx_v_inp, NPY_COMPLEX128)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 503, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF_SET(__pyx_v_inp, ((PyArrayObject *)__pyx_t_7)); __pyx_t_7 = 0;
+504: _inp = <double *>np.PyArray_DATA(inp)
__pyx_v__inp = ((double *)PyArray_DATA(__pyx_v_inp));
505:
+506: with nogil:
{
#ifdef WITH_THREAD
PyThreadState *_save;
Py_UNBLOCK_THREADS
__Pyx_FastGIL_Remember();
#endif
/*try:*/ {
/* … */
/*finally:*/ {
/*normal exit:*/{
#ifdef WITH_THREAD
__Pyx_FastGIL_Forget();
Py_BLOCK_THREADS
#endif
goto __pyx_L9;
}
__pyx_L8_error: {
#ifdef WITH_THREAD
__Pyx_FastGIL_Forget();
Py_BLOCK_THREADS
#endif
goto __pyx_L1_error;
}
__pyx_L9:;
}
}
+507: if backend == 'fftw':
__pyx_t_5 = (__Pyx_PyUnicode_Equals(__pyx_v_backend, __pyx_n_u_fftw, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 507, __pyx_L8_error) __pyx_t_8 = (__pyx_t_5 != 0); if (__pyx_t_8) { /* … */ goto __pyx_L10; }
+508: fail = gauss_grad_mag_c(_out, <double complex *>_inp, ndim, _dims, _sig,
__pyx_v_fail = gauss_grad_mag_c(__pyx_v__out, ((__pyx_t_double_complex *)__pyx_v__inp), __pyx_v_ndim, __pyx_v__dims, __pyx_v__sig, __pyx_v__mode, __pyx_t_double_complex_from_parts(((double)__pyx_v_cval), 0), __pyx_v_truncate, __pyx_v_num_threads, cfft_convolve_fftw);
509: _mode, <double complex>cval, truncate, num_threads,
510: cfft_convolve_fftw)
+511: elif backend == 'numpy':
__pyx_t_8 = (__Pyx_PyUnicode_Equals(__pyx_v_backend, __pyx_n_u_numpy, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 511, __pyx_L8_error) __pyx_t_5 = (__pyx_t_8 != 0); if (__pyx_t_5) { /* … */ goto __pyx_L10; }
+512: fail = gauss_grad_mag_c(_out, <double complex *>_inp, ndim, _dims, _sig,
__pyx_v_fail = gauss_grad_mag_c(__pyx_v__out, ((__pyx_t_double_complex *)__pyx_v__inp), __pyx_v_ndim, __pyx_v__dims, __pyx_v__sig, __pyx_v__mode, __pyx_t_double_complex_from_parts(((double)__pyx_v_cval), 0), __pyx_v_truncate, __pyx_v_num_threads, cfft_convolve_np);
513: _mode, <double complex>cval, truncate, num_threads,
514: cfft_convolve_np)
515: else:
+516: raise ValueError('{:s} is invalid backend'.format(backend))
/*else*/ {
{
#ifdef WITH_THREAD
PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
#endif
/*try:*/ {
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_s_is_invalid_backend, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 516, __pyx_L12_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_9 = NULL;
if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
__pyx_t_9 = PyMethod_GET_SELF(__pyx_t_2);
if (likely(__pyx_t_9)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
__Pyx_INCREF(__pyx_t_9);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_2, function);
}
}
__pyx_t_7 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_9, __pyx_v_backend) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_backend);
__Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 516, __pyx_L12_error)
__Pyx_GOTREF(__pyx_t_7);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 516, __pyx_L12_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
__Pyx_Raise(__pyx_t_2, 0, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__PYX_ERR(0, 516, __pyx_L12_error)
}
/*finally:*/ {
__pyx_L12_error: {
#ifdef WITH_THREAD
__Pyx_PyGILState_Release(__pyx_gilstate_save);
#endif
goto __pyx_L8_error;
}
}
}
}
__pyx_L10:;
}
517:
518: else:
+519: inp = check_array(inp, np.NPY_FLOAT64)
/*else*/ {
__pyx_t_2 = ((PyObject *)__pyx_f_6pyrost_3bin_10simulation_check_array(__pyx_v_inp, NPY_FLOAT64)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 519, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF_SET(__pyx_v_inp, ((PyArrayObject *)__pyx_t_2));
__pyx_t_2 = 0;
+520: _inp = <double *>np.PyArray_DATA(inp)
__pyx_v__inp = ((double *)PyArray_DATA(__pyx_v_inp));
521:
+522: with nogil:
{
#ifdef WITH_THREAD
PyThreadState *_save;
Py_UNBLOCK_THREADS
__Pyx_FastGIL_Remember();
#endif
/*try:*/ {
/* … */
/*finally:*/ {
/*normal exit:*/{
#ifdef WITH_THREAD
__Pyx_FastGIL_Forget();
Py_BLOCK_THREADS
#endif
goto __pyx_L16;
}
__pyx_L15_error: {
#ifdef WITH_THREAD
__Pyx_FastGIL_Forget();
Py_BLOCK_THREADS
#endif
goto __pyx_L1_error;
}
__pyx_L16:;
}
}
}
__pyx_L6:;
+523: if backend == 'fftw':
__pyx_t_5 = (__Pyx_PyUnicode_Equals(__pyx_v_backend, __pyx_n_u_fftw, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 523, __pyx_L15_error) __pyx_t_8 = (__pyx_t_5 != 0); if (__pyx_t_8) { /* … */ goto __pyx_L17; }
+524: fail = gauss_grad_mag_r(_out, <double *>_inp, ndim, _dims, _sig, _mode,
__pyx_v_fail = gauss_grad_mag_r(__pyx_v__out, ((double *)__pyx_v__inp), __pyx_v_ndim, __pyx_v__dims, __pyx_v__sig, __pyx_v__mode, __pyx_v_cval, __pyx_v_truncate, __pyx_v_num_threads, rfft_convolve_fftw);
525: cval, truncate, num_threads, rfft_convolve_fftw)
+526: elif backend == 'numpy':
__pyx_t_8 = (__Pyx_PyUnicode_Equals(__pyx_v_backend, __pyx_n_u_numpy, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 526, __pyx_L15_error) __pyx_t_5 = (__pyx_t_8 != 0); if (__pyx_t_5) { /* … */ goto __pyx_L17; }
+527: fail = gauss_grad_mag_r(_out, <double *>_inp, ndim, _dims, _sig, _mode,
__pyx_v_fail = gauss_grad_mag_r(__pyx_v__out, ((double *)__pyx_v__inp), __pyx_v_ndim, __pyx_v__dims, __pyx_v__sig, __pyx_v__mode, __pyx_v_cval, __pyx_v_truncate, __pyx_v_num_threads, rfft_convolve_np);
528: cval, truncate, num_threads, rfft_convolve_np)
529: else:
+530: raise ValueError('{:s} is invalid backend'.format(backend))
/*else*/ {
{
#ifdef WITH_THREAD
PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
#endif
/*try:*/ {
__pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_s_is_invalid_backend, __pyx_n_s_format); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 530, __pyx_L19_error)
__Pyx_GOTREF(__pyx_t_7);
__pyx_t_9 = NULL;
if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
__pyx_t_9 = PyMethod_GET_SELF(__pyx_t_7);
if (likely(__pyx_t_9)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
__Pyx_INCREF(__pyx_t_9);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_7, function);
}
}
__pyx_t_2 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_9, __pyx_v_backend) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_backend);
__Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 530, __pyx_L19_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
__pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 530, __pyx_L19_error)
__Pyx_GOTREF(__pyx_t_7);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_Raise(__pyx_t_7, 0, 0, 0);
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
__PYX_ERR(0, 530, __pyx_L19_error)
}
/*finally:*/ {
__pyx_L19_error: {
#ifdef WITH_THREAD
__Pyx_PyGILState_Release(__pyx_gilstate_save);
#endif
goto __pyx_L15_error;
}
}
}
}
__pyx_L17:;
}
531:
+532: if fail:
__pyx_t_5 = (__pyx_v_fail != 0);
if (unlikely(__pyx_t_5)) {
/* … */
}
+533: raise RuntimeError('C backend exited with error.')
__pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_RuntimeError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 533, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_Raise(__pyx_t_7, 0, 0, 0); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __PYX_ERR(0, 533, __pyx_L1_error)
+534: return out
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_out)); __pyx_r = ((PyObject *)__pyx_v_out); goto __pyx_L0;
535:
+536: def bar_positions(double x0, double x1, double b_dx, double rd, long seed):
/* Python wrapper */
static PyObject *__pyx_pw_6pyrost_3bin_10simulation_15bar_positions(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6pyrost_3bin_10simulation_14bar_positions[] = "Generate a coordinate array of randomized barcode's bar positions.\n\n Args:\n x0 (float) : Barcode's lower bound along the x axis [um].\n x1 (float) : Barcode's upper bound along the x axis [um].\n b_dx (float) : Average bar's size [um].\n rd (float) : Random deviation of barcode's bar positions (0.0 - 1.0).\n seed (int) : Seed used for pseudo random number generation.\n\n Returns:\n numpy.ndarray : Array of barcode's bar coordinates.\n ";
static PyMethodDef __pyx_mdef_6pyrost_3bin_10simulation_15bar_positions = {"bar_positions", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_6pyrost_3bin_10simulation_15bar_positions, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6pyrost_3bin_10simulation_14bar_positions};
static PyObject *__pyx_pw_6pyrost_3bin_10simulation_15bar_positions(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
double __pyx_v_x0;
double __pyx_v_x1;
double __pyx_v_b_dx;
double __pyx_v_rd;
long __pyx_v_seed;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("bar_positions (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_x0,&__pyx_n_s_x1,&__pyx_n_s_b_dx,&__pyx_n_s_rd,&__pyx_n_s_seed,0};
PyObject* values[5] = {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 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
CYTHON_FALLTHROUGH;
case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
CYTHON_FALLTHROUGH;
case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
CYTHON_FALLTHROUGH;
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_x0)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_x1)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("bar_positions", 1, 5, 5, 1); __PYX_ERR(0, 536, __pyx_L3_error)
}
CYTHON_FALLTHROUGH;
case 2:
if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_b_dx)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("bar_positions", 1, 5, 5, 2); __PYX_ERR(0, 536, __pyx_L3_error)
}
CYTHON_FALLTHROUGH;
case 3:
if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_rd)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("bar_positions", 1, 5, 5, 3); __PYX_ERR(0, 536, __pyx_L3_error)
}
CYTHON_FALLTHROUGH;
case 4:
if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_seed)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("bar_positions", 1, 5, 5, 4); __PYX_ERR(0, 536, __pyx_L3_error)
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "bar_positions") < 0)) __PYX_ERR(0, 536, __pyx_L3_error)
}
} else if (PyTuple_GET_SIZE(__pyx_args) != 5) {
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);
}
__pyx_v_x0 = __pyx_PyFloat_AsDouble(values[0]); if (unlikely((__pyx_v_x0 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 536, __pyx_L3_error)
__pyx_v_x1 = __pyx_PyFloat_AsDouble(values[1]); if (unlikely((__pyx_v_x1 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 536, __pyx_L3_error)
__pyx_v_b_dx = __pyx_PyFloat_AsDouble(values[2]); if (unlikely((__pyx_v_b_dx == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 536, __pyx_L3_error)
__pyx_v_rd = __pyx_PyFloat_AsDouble(values[3]); if (unlikely((__pyx_v_rd == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 536, __pyx_L3_error)
__pyx_v_seed = __Pyx_PyInt_As_long(values[4]); if (unlikely((__pyx_v_seed == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 536, __pyx_L3_error)
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("bar_positions", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 536, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("pyrost.bin.simulation.bar_positions", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_6pyrost_3bin_10simulation_14bar_positions(__pyx_self, __pyx_v_x0, __pyx_v_x1, __pyx_v_b_dx, __pyx_v_rd, __pyx_v_seed);
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_6pyrost_3bin_10simulation_14bar_positions(CYTHON_UNUSED PyObject *__pyx_self, double __pyx_v_x0, double __pyx_v_x1, double __pyx_v_b_dx, double __pyx_v_rd, long __pyx_v_seed) {
npy_intp __pyx_v_size;
npy_intp *__pyx_v_dims;
PyArrayObject *__pyx_v_bars = 0;
double *__pyx_v__bars;
__Pyx_LocalBuf_ND __pyx_pybuffernd_bars;
__Pyx_Buffer __pyx_pybuffer_bars;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("bar_positions", 0);
__pyx_pybuffer_bars.pybuffer.buf = NULL;
__pyx_pybuffer_bars.refcount = 0;
__pyx_pybuffernd_bars.data = NULL;
__pyx_pybuffernd_bars.rcbuffer = &__pyx_pybuffer_bars;
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_4);
{ PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
__Pyx_PyThreadState_declare
__Pyx_PyThreadState_assign
__Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_bars.rcbuffer->pybuffer);
__Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
__Pyx_AddTraceback("pyrost.bin.simulation.bar_positions", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
goto __pyx_L2;
__pyx_L0:;
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_bars.rcbuffer->pybuffer);
__pyx_L2:;
__Pyx_XDECREF((PyObject *)__pyx_v_bars);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* … */
__pyx_tuple__25 = PyTuple_Pack(9, __pyx_n_s_x0, __pyx_n_s_x1, __pyx_n_s_b_dx, __pyx_n_s_rd, __pyx_n_s_seed, __pyx_n_s_size, __pyx_n_s_dims, __pyx_n_s_bars, __pyx_n_s_bars_2); if (unlikely(!__pyx_tuple__25)) __PYX_ERR(0, 536, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__25);
__Pyx_GIVEREF(__pyx_tuple__25);
/* … */
__pyx_t_5 = __Pyx_CyFunction_New(&__pyx_mdef_6pyrost_3bin_10simulation_15bar_positions, 0, __pyx_n_s_bar_positions, NULL, __pyx_n_s_pyrost_bin_simulation, __pyx_d, ((PyObject *)__pyx_codeobj__26)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 536, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
if (PyDict_SetItem(__pyx_d, __pyx_n_s_bar_positions, __pyx_t_5) < 0) __PYX_ERR(0, 536, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__pyx_codeobj__26 = (PyObject*)__Pyx_PyCode_New(5, 0, 9, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__25, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pyrost_bin_simulation_pyx, __pyx_n_s_bar_positions, 536, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__26)) __PYX_ERR(0, 536, __pyx_L1_error)
537: """Generate a coordinate array of randomized barcode's bar positions.
538:
539: Args:
540: x0 (float) : Barcode's lower bound along the x axis [um].
541: x1 (float) : Barcode's upper bound along the x axis [um].
542: b_dx (float) : Average bar's size [um].
543: rd (float) : Random deviation of barcode's bar positions (0.0 - 1.0).
544: seed (int) : Seed used for pseudo random number generation.
545:
546: Returns:
547: numpy.ndarray : Array of barcode's bar coordinates.
548: """
+549: cdef np.npy_intp size = 2 * (<np.npy_intp>((x1 - x0) / 2 / b_dx) + 1) if x1 > x0 else 0
if (((__pyx_v_x1 > __pyx_v_x0) != 0)) {
__pyx_t_1 = (2 * (((npy_intp)(((__pyx_v_x1 - __pyx_v_x0) / 2.0) / __pyx_v_b_dx)) + 1));
} else {
__pyx_t_1 = 0;
}
__pyx_v_size = __pyx_t_1;
+550: cdef np.npy_intp *dims = [size,]
__pyx_t_2[0] = __pyx_v_size; __pyx_v_dims = __pyx_t_2;
+551: cdef np.ndarray[double] bars = <np.ndarray>np.PyArray_SimpleNew(1, dims, np.NPY_FLOAT64)
__pyx_t_3 = PyArray_SimpleNew(1, __pyx_v_dims, NPY_FLOAT64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 551, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = __pyx_t_3; __Pyx_INCREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_bars.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_4), &__Pyx_TypeInfo_double, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { __pyx_v_bars = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_bars.rcbuffer->pybuffer.buf = NULL; __PYX_ERR(0, 551, __pyx_L1_error) } else {__pyx_pybuffernd_bars.diminfo[0].strides = __pyx_pybuffernd_bars.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_bars.diminfo[0].shape = __pyx_pybuffernd_bars.rcbuffer->pybuffer.shape[0]; } } __pyx_v_bars = ((PyArrayObject *)__pyx_t_4); __pyx_t_4 = 0;
+552: cdef double *_bars = <double *>np.PyArray_DATA(bars)
__pyx_v__bars = ((double *)PyArray_DATA(((PyArrayObject *)__pyx_v_bars)));
+553: if size:
__pyx_t_5 = (__pyx_v_size != 0);
if (__pyx_t_5) {
/* … */
}
+554: with nogil:
{
#ifdef WITH_THREAD
PyThreadState *_save;
Py_UNBLOCK_THREADS
__Pyx_FastGIL_Remember();
#endif
/*try:*/ {
/* … */
/*finally:*/ {
/*normal exit:*/{
#ifdef WITH_THREAD
__Pyx_FastGIL_Forget();
Py_BLOCK_THREADS
#endif
goto __pyx_L6;
}
__pyx_L6:;
}
}
+555: barcode_bars(_bars, size, x0, b_dx, rd, seed)
barcode_bars(__pyx_v__bars, __pyx_v_size, __pyx_v_x0, __pyx_v_b_dx, __pyx_v_rd, __pyx_v_seed);
}
+556: return bars
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_bars)); __pyx_r = ((PyObject *)__pyx_v_bars); goto __pyx_L0;
557:
+558: cdef np.ndarray ml_profile_wrapper(np.ndarray x_arr, np.ndarray layers, complex mt0,
static PyArrayObject *__pyx_f_6pyrost_3bin_10simulation_ml_profile_wrapper(PyArrayObject *__pyx_v_x_arr, PyArrayObject *__pyx_v_layers, __pyx_t_double_complex __pyx_v_mt0, __pyx_t_double_complex __pyx_v_mt1, __pyx_t_double_complex __pyx_v_mt2, double __pyx_v_sigma, unsigned int __pyx_v_num_threads) {
int __pyx_v_fail;
int __pyx_v_ndim;
npy_intp *__pyx_v_dims;
PyArrayObject *__pyx_v_out = 0;
npy_intp __pyx_v_isize;
npy_intp __pyx_v_lsize;
__pyx_t_double_complex *__pyx_v__out;
double *__pyx_v__x;
double *__pyx_v__lyrs;
PyArrayObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("ml_profile_wrapper", 0);
__Pyx_INCREF((PyObject *)__pyx_v_x_arr);
__Pyx_INCREF((PyObject *)__pyx_v_layers);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_AddTraceback("pyrost.bin.simulation.ml_profile_wrapper", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
__pyx_L0:;
__Pyx_XDECREF((PyObject *)__pyx_v_out);
__Pyx_XDECREF((PyObject *)__pyx_v_x_arr);
__Pyx_XDECREF((PyObject *)__pyx_v_layers);
__Pyx_XGIVEREF((PyObject *)__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
559: complex mt1, complex mt2, double sigma, unsigned num_threads):
+560: x_arr = check_array(x_arr, np.NPY_FLOAT64)
__pyx_t_1 = ((PyObject *)__pyx_f_6pyrost_3bin_10simulation_check_array(__pyx_v_x_arr, NPY_FLOAT64)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 560, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_x_arr, ((PyArrayObject *)__pyx_t_1)); __pyx_t_1 = 0;
+561: layers = check_array(layers, np.NPY_FLOAT64)
__pyx_t_1 = ((PyObject *)__pyx_f_6pyrost_3bin_10simulation_check_array(__pyx_v_layers, NPY_FLOAT64)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 561, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_layers, ((PyArrayObject *)__pyx_t_1)); __pyx_t_1 = 0;
562:
+563: cdef int fail = 0
__pyx_v_fail = 0;
+564: cdef int ndim = x_arr.ndim
__pyx_t_2 = __pyx_v_x_arr->nd; __pyx_v_ndim = __pyx_t_2;
+565: cdef np.npy_intp *dims = x_arr.shape
__pyx_t_3 = __pyx_v_x_arr->dimensions; __pyx_v_dims = __pyx_t_3;
+566: cdef np.ndarray out = <np.ndarray>np.PyArray_SimpleNew(ndim, dims, np.NPY_COMPLEX128)
__pyx_t_1 = PyArray_SimpleNew(__pyx_v_ndim, __pyx_v_dims, NPY_COMPLEX128); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 566, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_4 = __pyx_t_1; __Pyx_INCREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_out = ((PyArrayObject *)__pyx_t_4); __pyx_t_4 = 0;
567:
+568: cdef np.npy_intp isize = np.PyArray_SIZE(x_arr)
__pyx_v_isize = PyArray_SIZE(__pyx_v_x_arr);
+569: cdef np.npy_intp lsize = np.PyArray_SIZE(layers)
__pyx_v_lsize = PyArray_SIZE(__pyx_v_layers);
+570: cdef complex *_out = <complex *>np.PyArray_DATA(out)
__pyx_v__out = ((__pyx_t_double_complex *)PyArray_DATA(__pyx_v_out));
+571: cdef double *_x = <double *>np.PyArray_DATA(x_arr)
__pyx_v__x = ((double *)PyArray_DATA(__pyx_v_x_arr));
+572: cdef double *_lyrs = <double *>np.PyArray_DATA(layers)
__pyx_v__lyrs = ((double *)PyArray_DATA(__pyx_v_layers));
+573: with nogil:
{
#ifdef WITH_THREAD
PyThreadState *_save;
Py_UNBLOCK_THREADS
__Pyx_FastGIL_Remember();
#endif
/*try:*/ {
/* … */
/*finally:*/ {
/*normal exit:*/{
#ifdef WITH_THREAD
__Pyx_FastGIL_Forget();
Py_BLOCK_THREADS
#endif
goto __pyx_L5;
}
__pyx_L5:;
}
}
+574: fail = ml_profile(_out, _x, isize, _lyrs, lsize, mt0, mt1, mt2, sigma, num_threads)
__pyx_v_fail = ml_profile(__pyx_v__out, __pyx_v__x, __pyx_v_isize, __pyx_v__lyrs, __pyx_v_lsize, __pyx_v_mt0, __pyx_v_mt1, __pyx_v_mt2, __pyx_v_sigma, __pyx_v_num_threads);
}
+575: if fail:
__pyx_t_5 = (__pyx_v_fail != 0);
if (unlikely(__pyx_t_5)) {
/* … */
}
+576: raise RuntimeError('C backend exited with error.')
__pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_RuntimeError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 576, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __PYX_ERR(0, 576, __pyx_L1_error)
+577: return out
__Pyx_XDECREF(((PyObject *)__pyx_r)); __Pyx_INCREF(((PyObject *)__pyx_v_out)); __pyx_r = __pyx_v_out; goto __pyx_L0;
578:
+579: def barcode_profile(np.ndarray x_arr not None, np.ndarray bars not None, double bulk_atn,
/* Python wrapper */
static PyObject *__pyx_pw_6pyrost_3bin_10simulation_17barcode_profile(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6pyrost_3bin_10simulation_16barcode_profile[] = "Return an array of barcode's transmission profile calculated\n at `x_arr` coordinates.\n\n Args:\n x_arr (numpy.ndarray) : Array of the coordinates, where the transmission\n coefficients are calculated [um]. \n bars (numpy.ndarray) : Coordinates of barcode's bar positions [um].\n bulk_atn (float) : Barcode's bulk attenuation coefficient (0.0 - 1.0).\n bar_atn (float) : Barcode's bar attenuation coefficient (0.0 - 1.0).\n bar_sigma (float) : Bar's blurriness width [um].\n num_threads (int) : Number of threads used in the calculations.\n \n Returns:\n numpy.ndarray : Array of barcode's transmission profiles.\n\n Notes:\n Barcode's transmission profile is simulated with a set\n of error functions:\n \n .. math::\n \\begin{multline}\n T_{b}(x) = 1 - \\frac{T_{bulk}}{2} \\left\\{\n \\mathrm{erf}\\left[ \\frac{x - x_{bar}[0]}{\\sqrt{2} \\sigma} \\right] +\n \\mathrm{erf}\\left[ \\frac{x_{bar}[n - 1] - x}{\\sqrt{2} \\sigma} \\right]\n \\right\\} -\\\\\n \\frac{T_{bar}}{4} \\sum_{i = 1}^{n - 2} \\left\\{\n 2 \\mathrm{erf}\\left[ \\frac{x - x_{bar}[i]}{\\sqrt{2} \\sigma} \\right] -\n \\mathrm{erf}\\left[ \\frac{x - x_{bar}[i - 1]}{\\sqrt{2} \\sigma} \\right] -\n \\mathrm{erf}\\left[ \\frac{x - x_{bar}[i + 1]}{\\sqrt{2} \\sigma} \\right]\n \\right\\}\n \\end{multline}\n \n where :math:`x_{bar}` is an array of bar coordinates.\n ";
static PyMethodDef __pyx_mdef_6pyrost_3bin_10simulation_17barcode_profile = {"barcode_profile", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_6pyrost_3bin_10simulation_17barcode_profile, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6pyrost_3bin_10simulation_16barcode_profile};
static PyObject *__pyx_pw_6pyrost_3bin_10simulation_17barcode_profile(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyArrayObject *__pyx_v_x_arr = 0;
PyArrayObject *__pyx_v_bars = 0;
double __pyx_v_bulk_atn;
double __pyx_v_bar_atn;
double __pyx_v_bar_sigma;
unsigned int __pyx_v_num_threads;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("barcode_profile (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_x_arr,&__pyx_n_s_bars,&__pyx_n_s_bulk_atn,&__pyx_n_s_bar_atn,&__pyx_n_s_bar_sigma,&__pyx_n_s_num_threads,0};
PyObject* values[6] = {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 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
CYTHON_FALLTHROUGH;
case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
CYTHON_FALLTHROUGH;
case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
CYTHON_FALLTHROUGH;
case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
CYTHON_FALLTHROUGH;
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_x_arr)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_bars)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("barcode_profile", 0, 5, 6, 1); __PYX_ERR(0, 579, __pyx_L3_error)
}
CYTHON_FALLTHROUGH;
case 2:
if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_bulk_atn)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("barcode_profile", 0, 5, 6, 2); __PYX_ERR(0, 579, __pyx_L3_error)
}
CYTHON_FALLTHROUGH;
case 3:
if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_bar_atn)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("barcode_profile", 0, 5, 6, 3); __PYX_ERR(0, 579, __pyx_L3_error)
}
CYTHON_FALLTHROUGH;
case 4:
if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_bar_sigma)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("barcode_profile", 0, 5, 6, 4); __PYX_ERR(0, 579, __pyx_L3_error)
}
CYTHON_FALLTHROUGH;
case 5:
if (kw_args > 0) {
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_num_threads);
if (value) { values[5] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "barcode_profile") < 0)) __PYX_ERR(0, 579, __pyx_L3_error)
}
} else {
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
CYTHON_FALLTHROUGH;
case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
break;
default: goto __pyx_L5_argtuple_error;
}
}
__pyx_v_x_arr = ((PyArrayObject *)values[0]);
__pyx_v_bars = ((PyArrayObject *)values[1]);
__pyx_v_bulk_atn = __pyx_PyFloat_AsDouble(values[2]); if (unlikely((__pyx_v_bulk_atn == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 579, __pyx_L3_error)
__pyx_v_bar_atn = __pyx_PyFloat_AsDouble(values[3]); if (unlikely((__pyx_v_bar_atn == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 580, __pyx_L3_error)
__pyx_v_bar_sigma = __pyx_PyFloat_AsDouble(values[4]); if (unlikely((__pyx_v_bar_sigma == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 580, __pyx_L3_error)
if (values[5]) {
__pyx_v_num_threads = __Pyx_PyInt_As_unsigned_int(values[5]); if (unlikely((__pyx_v_num_threads == (unsigned int)-1) && PyErr_Occurred())) __PYX_ERR(0, 580, __pyx_L3_error)
} else {
__pyx_v_num_threads = ((unsigned int)((unsigned int)1));
}
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("barcode_profile", 0, 5, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 579, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("pyrost.bin.simulation.barcode_profile", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x_arr), __pyx_ptype_5numpy_ndarray, 0, "x_arr", 0))) __PYX_ERR(0, 579, __pyx_L1_error)
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_bars), __pyx_ptype_5numpy_ndarray, 0, "bars", 0))) __PYX_ERR(0, 579, __pyx_L1_error)
__pyx_r = __pyx_pf_6pyrost_3bin_10simulation_16barcode_profile(__pyx_self, __pyx_v_x_arr, __pyx_v_bars, __pyx_v_bulk_atn, __pyx_v_bar_atn, __pyx_v_bar_sigma, __pyx_v_num_threads);
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
/* function exit code */
goto __pyx_L0;
__pyx_L1_error:;
__pyx_r = NULL;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_6pyrost_3bin_10simulation_16barcode_profile(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_x_arr, PyArrayObject *__pyx_v_bars, double __pyx_v_bulk_atn, double __pyx_v_bar_atn, double __pyx_v_bar_sigma, unsigned int __pyx_v_num_threads) {
__pyx_t_double_complex __pyx_v_mt0;
__pyx_t_double_complex __pyx_v_mt1;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("barcode_profile", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_AddTraceback("pyrost.bin.simulation.barcode_profile", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* … */
__pyx_tuple__27 = PyTuple_Pack(8, __pyx_n_s_x_arr, __pyx_n_s_bars, __pyx_n_s_bulk_atn, __pyx_n_s_bar_atn, __pyx_n_s_bar_sigma, __pyx_n_s_num_threads, __pyx_n_s_mt0, __pyx_n_s_mt1); if (unlikely(!__pyx_tuple__27)) __PYX_ERR(0, 579, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__27);
__Pyx_GIVEREF(__pyx_tuple__27);
/* … */
__pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 579, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_GIVEREF(__pyx_t_5);
PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
__pyx_t_5 = 0;
__pyx_t_5 = __Pyx_CyFunction_New(&__pyx_mdef_6pyrost_3bin_10simulation_17barcode_profile, 0, __pyx_n_s_barcode_profile, NULL, __pyx_n_s_pyrost_bin_simulation, __pyx_d, ((PyObject *)__pyx_codeobj__28)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 579, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_CyFunction_SetDefaultsTuple(__pyx_t_5, __pyx_t_4);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
if (PyDict_SetItem(__pyx_d, __pyx_n_s_barcode_profile, __pyx_t_5) < 0) __PYX_ERR(0, 579, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__pyx_codeobj__28 = (PyObject*)__Pyx_PyCode_New(6, 0, 8, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__27, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pyrost_bin_simulation_pyx, __pyx_n_s_barcode_profile, 579, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__28)) __PYX_ERR(0, 579, __pyx_L1_error)
+580: double bar_atn, double bar_sigma, unsigned num_threads=1):
__pyx_t_5 = __Pyx_PyInt_From_unsigned_int(((unsigned int)1)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 580, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5);
581: r"""Return an array of barcode's transmission profile calculated
582: at `x_arr` coordinates.
583:
584: Args:
585: x_arr (numpy.ndarray) : Array of the coordinates, where the transmission
586: coefficients are calculated [um].
587: bars (numpy.ndarray) : Coordinates of barcode's bar positions [um].
588: bulk_atn (float) : Barcode's bulk attenuation coefficient (0.0 - 1.0).
589: bar_atn (float) : Barcode's bar attenuation coefficient (0.0 - 1.0).
590: bar_sigma (float) : Bar's blurriness width [um].
591: num_threads (int) : Number of threads used in the calculations.
592:
593: Returns:
594: numpy.ndarray : Array of barcode's transmission profiles.
595:
596: Notes:
597: Barcode's transmission profile is simulated with a set
598: of error functions:
599:
600: .. math::
601: \begin{multline}
602: T_{b}(x) = 1 - \frac{T_{bulk}}{2} \left\{
603: \mathrm{erf}\left[ \frac{x - x_{bar}[0]}{\sqrt{2} \sigma} \right] +
604: \mathrm{erf}\left[ \frac{x_{bar}[n - 1] - x}{\sqrt{2} \sigma} \right]
605: \right\} -\\
606: \frac{T_{bar}}{4} \sum_{i = 1}^{n - 2} \left\{
607: 2 \mathrm{erf}\left[ \frac{x - x_{bar}[i]}{\sqrt{2} \sigma} \right] -
608: \mathrm{erf}\left[ \frac{x - x_{bar}[i - 1]}{\sqrt{2} \sigma} \right] -
609: \mathrm{erf}\left[ \frac{x - x_{bar}[i + 1]}{\sqrt{2} \sigma} \right]
610: \right\}
611: \end{multline}
612:
613: where :math:`x_{bar}` is an array of bar coordinates.
614: """
+615: cdef complex mt0 = -1j * log(1 - bulk_atn)
__pyx_v_mt0 = __Pyx_c_prod_double(__Pyx_c_neg_double(__pyx_t_double_complex_from_parts(0, 1.0)), __pyx_t_double_complex_from_parts(log((1.0 - __pyx_v_bulk_atn)), 0));
+616: cdef complex mt1 = -1j * log(1 - bar_atn)
__pyx_v_mt1 = __Pyx_c_prod_double(__Pyx_c_neg_double(__pyx_t_double_complex_from_parts(0, 1.0)), __pyx_t_double_complex_from_parts(log((1.0 - __pyx_v_bar_atn)), 0));
+617: return ml_profile_wrapper(x_arr, bars, mt0, mt1, 0., bar_sigma, num_threads)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = ((PyObject *)__pyx_f_6pyrost_3bin_10simulation_ml_profile_wrapper(__pyx_v_x_arr, __pyx_v_bars, __pyx_v_mt0, __pyx_v_mt1, __pyx_t_double_complex_from_parts(0., 0), __pyx_v_bar_sigma, __pyx_v_num_threads)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 617, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
618:
+619: def mll_profile(np.ndarray x_arr not None, np.ndarray layers not None, complex mt0,
/* Python wrapper */
static PyObject *__pyx_pw_6pyrost_3bin_10simulation_19mll_profile(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6pyrost_3bin_10simulation_18mll_profile[] = "Return an array of MLL's transmission profile calculated\n at `x_arr` coordinates.\n\n Args:\n x_arr (numpy.ndarray) : Array of the coordinates, where the transmission\n coefficients are calculated [um]. \n layers (numpy.ndarray) : Coordinates of MLL's layers positions [um].\n mt0 (complex) : Fresnel transmission coefficient for the first material of\n MLL's bilayer.\n mt1 (complex) : Fresnel transmission coefficient for the first material of\n MLL's bilayer.\n sigma (float) : Interdiffusion length [um].\n num_threads (int) : Number of threads used in the calculations.\n \n Returns:\n numpy.ndarray : Array of barcode's transmission profiles.\n\n Notes:\n MLL's transmission profile is simulated with a set\n of error functions:\n \n .. math::\n \\begin{multline}\n T_{b}(x) = 1 - \\frac{T_{bulk}}{2} \\left\\{\n \\mathrm{erf}\\left[ \\frac{x - x_{lyr}[0]}{\\sqrt{2} \\sigma} \\right] +\n \\mathrm{erf}\\left[ \\frac{x_{lyr}[n - 1] - x}{\\sqrt{2} \\sigma} \\right]\n \\right\\} -\\\\\n \\frac{T_{bar}}{4} \\sum_{i = 1}^{n - 2} \\left\\{\n 2 \\mathrm{erf}\\left[ \\frac{x - x_{lyr}[i]}{\\sqrt{2} \\sigma} \\right] -\n \\mathrm{erf}\\left[ \\frac{x - x_{lyr}[i - 1]}{\\sqrt{2} \\sigma} \\right] -\n \\mathrm{erf}\\left[ \\frac{x - x_{lyr}[i + 1]}{\\sqrt{2} \\sigma} \\right]\n \\right\\}\n \\end{multline}\n \n where :math:`x_{lyr}` is an array of MLL's layer coordinates.\n ";
static PyMethodDef __pyx_mdef_6pyrost_3bin_10simulation_19mll_profile = {"mll_profile", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_6pyrost_3bin_10simulation_19mll_profile, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6pyrost_3bin_10simulation_18mll_profile};
static PyObject *__pyx_pw_6pyrost_3bin_10simulation_19mll_profile(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyArrayObject *__pyx_v_x_arr = 0;
PyArrayObject *__pyx_v_layers = 0;
__pyx_t_double_complex __pyx_v_mt0;
__pyx_t_double_complex __pyx_v_mt1;
double __pyx_v_sigma;
unsigned int __pyx_v_num_threads;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("mll_profile (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_x_arr,&__pyx_n_s_layers,&__pyx_n_s_mt0,&__pyx_n_s_mt1,&__pyx_n_s_sigma,&__pyx_n_s_num_threads,0};
PyObject* values[6] = {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 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
CYTHON_FALLTHROUGH;
case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
CYTHON_FALLTHROUGH;
case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
CYTHON_FALLTHROUGH;
case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
CYTHON_FALLTHROUGH;
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_x_arr)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_layers)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("mll_profile", 0, 5, 6, 1); __PYX_ERR(0, 619, __pyx_L3_error)
}
CYTHON_FALLTHROUGH;
case 2:
if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mt0)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("mll_profile", 0, 5, 6, 2); __PYX_ERR(0, 619, __pyx_L3_error)
}
CYTHON_FALLTHROUGH;
case 3:
if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mt1)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("mll_profile", 0, 5, 6, 3); __PYX_ERR(0, 619, __pyx_L3_error)
}
CYTHON_FALLTHROUGH;
case 4:
if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_sigma)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("mll_profile", 0, 5, 6, 4); __PYX_ERR(0, 619, __pyx_L3_error)
}
CYTHON_FALLTHROUGH;
case 5:
if (kw_args > 0) {
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_num_threads);
if (value) { values[5] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "mll_profile") < 0)) __PYX_ERR(0, 619, __pyx_L3_error)
}
} else {
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
CYTHON_FALLTHROUGH;
case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
break;
default: goto __pyx_L5_argtuple_error;
}
}
__pyx_v_x_arr = ((PyArrayObject *)values[0]);
__pyx_v_layers = ((PyArrayObject *)values[1]);
__pyx_v_mt0 = __Pyx_PyComplex_As___pyx_t_double_complex(values[2]); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 619, __pyx_L3_error)
__pyx_v_mt1 = __Pyx_PyComplex_As___pyx_t_double_complex(values[3]); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 620, __pyx_L3_error)
__pyx_v_sigma = __pyx_PyFloat_AsDouble(values[4]); if (unlikely((__pyx_v_sigma == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 620, __pyx_L3_error)
if (values[5]) {
__pyx_v_num_threads = __Pyx_PyInt_As_unsigned_int(values[5]); if (unlikely((__pyx_v_num_threads == (unsigned int)-1) && PyErr_Occurred())) __PYX_ERR(0, 620, __pyx_L3_error)
} else {
__pyx_v_num_threads = ((unsigned int)((unsigned int)1));
}
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("mll_profile", 0, 5, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 619, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("pyrost.bin.simulation.mll_profile", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x_arr), __pyx_ptype_5numpy_ndarray, 0, "x_arr", 0))) __PYX_ERR(0, 619, __pyx_L1_error)
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_layers), __pyx_ptype_5numpy_ndarray, 0, "layers", 0))) __PYX_ERR(0, 619, __pyx_L1_error)
__pyx_r = __pyx_pf_6pyrost_3bin_10simulation_18mll_profile(__pyx_self, __pyx_v_x_arr, __pyx_v_layers, __pyx_v_mt0, __pyx_v_mt1, __pyx_v_sigma, __pyx_v_num_threads);
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
/* function exit code */
goto __pyx_L0;
__pyx_L1_error:;
__pyx_r = NULL;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_6pyrost_3bin_10simulation_18mll_profile(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_x_arr, PyArrayObject *__pyx_v_layers, __pyx_t_double_complex __pyx_v_mt0, __pyx_t_double_complex __pyx_v_mt1, double __pyx_v_sigma, unsigned int __pyx_v_num_threads) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("mll_profile", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_AddTraceback("pyrost.bin.simulation.mll_profile", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* … */
__pyx_tuple__29 = PyTuple_Pack(6, __pyx_n_s_x_arr, __pyx_n_s_layers, __pyx_n_s_mt0, __pyx_n_s_mt1, __pyx_n_s_sigma, __pyx_n_s_num_threads); if (unlikely(!__pyx_tuple__29)) __PYX_ERR(0, 619, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__29);
__Pyx_GIVEREF(__pyx_tuple__29);
/* … */
__pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 619, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_GIVEREF(__pyx_t_5);
PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
__pyx_t_5 = 0;
__pyx_t_5 = __Pyx_CyFunction_New(&__pyx_mdef_6pyrost_3bin_10simulation_19mll_profile, 0, __pyx_n_s_mll_profile, NULL, __pyx_n_s_pyrost_bin_simulation, __pyx_d, ((PyObject *)__pyx_codeobj__30)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 619, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_CyFunction_SetDefaultsTuple(__pyx_t_5, __pyx_t_4);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
if (PyDict_SetItem(__pyx_d, __pyx_n_s_mll_profile, __pyx_t_5) < 0) __PYX_ERR(0, 619, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__pyx_codeobj__30 = (PyObject*)__Pyx_PyCode_New(6, 0, 6, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__29, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pyrost_bin_simulation_pyx, __pyx_n_s_mll_profile, 619, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__30)) __PYX_ERR(0, 619, __pyx_L1_error)
+620: complex mt1, double sigma, unsigned num_threads=1):
__pyx_t_5 = __Pyx_PyInt_From_unsigned_int(((unsigned int)1)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 620, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5);
621: r"""Return an array of MLL's transmission profile calculated
622: at `x_arr` coordinates.
623:
624: Args:
625: x_arr (numpy.ndarray) : Array of the coordinates, where the transmission
626: coefficients are calculated [um].
627: layers (numpy.ndarray) : Coordinates of MLL's layers positions [um].
628: mt0 (complex) : Fresnel transmission coefficient for the first material of
629: MLL's bilayer.
630: mt1 (complex) : Fresnel transmission coefficient for the first material of
631: MLL's bilayer.
632: sigma (float) : Interdiffusion length [um].
633: num_threads (int) : Number of threads used in the calculations.
634:
635: Returns:
636: numpy.ndarray : Array of barcode's transmission profiles.
637:
638: Notes:
639: MLL's transmission profile is simulated with a set
640: of error functions:
641:
642: .. math::
643: \begin{multline}
644: T_{b}(x) = 1 - \frac{T_{bulk}}{2} \left\{
645: \mathrm{erf}\left[ \frac{x - x_{lyr}[0]}{\sqrt{2} \sigma} \right] +
646: \mathrm{erf}\left[ \frac{x_{lyr}[n - 1] - x}{\sqrt{2} \sigma} \right]
647: \right\} -\\
648: \frac{T_{bar}}{4} \sum_{i = 1}^{n - 2} \left\{
649: 2 \mathrm{erf}\left[ \frac{x - x_{lyr}[i]}{\sqrt{2} \sigma} \right] -
650: \mathrm{erf}\left[ \frac{x - x_{lyr}[i - 1]}{\sqrt{2} \sigma} \right] -
651: \mathrm{erf}\left[ \frac{x - x_{lyr}[i + 1]}{\sqrt{2} \sigma} \right]
652: \right\}
653: \end{multline}
654:
655: where :math:`x_{lyr}` is an array of MLL's layer coordinates.
656: """
+657: return ml_profile_wrapper(x_arr, layers, 0., mt0, mt1, sigma, num_threads)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = ((PyObject *)__pyx_f_6pyrost_3bin_10simulation_ml_profile_wrapper(__pyx_v_x_arr, __pyx_v_layers, __pyx_t_double_complex_from_parts(0., 0), __pyx_v_mt0, __pyx_v_mt1, __pyx_v_sigma, __pyx_v_num_threads)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 657, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
658:
+659: def make_frames(np.ndarray pfx not None, np.ndarray pfy not None, double dx, double dy,
/* Python wrapper */
static PyObject *__pyx_pw_6pyrost_3bin_10simulation_21make_frames(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6pyrost_3bin_10simulation_20make_frames[] = "Generate intensity frames from one-dimensional intensity profiles (`pfx`,\n `pfy`) and whitefield profiles (`wfx`, `wfy`). Intensity profiles resized into\n the shape of a frame. Poisson noise is applied if `seed` is non-negative.\n\n Args:\n pfx (numpy.ndarray) : Intensity profile along the x axis.\n pfy (numpy.ndarray) : Intensity profile along the y axis.\n dx (float) : Sampling interval along the x axis [um].\n dy (float) : Sampling interval along the y axis [um].\n shape (Tuple[int, int]) : Shape of the detector array.\n seed (int) : Seed for pseudo-random number generation.\n num_threads (int) : Number of threads used in the calculations.\n\n Returns:\n numpy.ndarray : Intensity frames.\n ";
static PyMethodDef __pyx_mdef_6pyrost_3bin_10simulation_21make_frames = {"make_frames", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_6pyrost_3bin_10simulation_21make_frames, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6pyrost_3bin_10simulation_20make_frames};
static PyObject *__pyx_pw_6pyrost_3bin_10simulation_21make_frames(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyArrayObject *__pyx_v_pfx = 0;
PyArrayObject *__pyx_v_pfy = 0;
double __pyx_v_dx;
double __pyx_v_dy;
PyObject *__pyx_v_shape = 0;
long __pyx_v_seed;
unsigned int __pyx_v_num_threads;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("make_frames (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pfx,&__pyx_n_s_pfy,&__pyx_n_s_dx,&__pyx_n_s_dy,&__pyx_n_s_shape,&__pyx_n_s_seed,&__pyx_n_s_num_threads,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);
CYTHON_FALLTHROUGH;
case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
CYTHON_FALLTHROUGH;
case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
CYTHON_FALLTHROUGH;
case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
CYTHON_FALLTHROUGH;
case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
CYTHON_FALLTHROUGH;
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pfx)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pfy)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("make_frames", 0, 6, 7, 1); __PYX_ERR(0, 659, __pyx_L3_error)
}
CYTHON_FALLTHROUGH;
case 2:
if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_dx)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("make_frames", 0, 6, 7, 2); __PYX_ERR(0, 659, __pyx_L3_error)
}
CYTHON_FALLTHROUGH;
case 3:
if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_dy)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("make_frames", 0, 6, 7, 3); __PYX_ERR(0, 659, __pyx_L3_error)
}
CYTHON_FALLTHROUGH;
case 4:
if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_shape)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("make_frames", 0, 6, 7, 4); __PYX_ERR(0, 659, __pyx_L3_error)
}
CYTHON_FALLTHROUGH;
case 5:
if (likely((values[5] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_seed)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("make_frames", 0, 6, 7, 5); __PYX_ERR(0, 659, __pyx_L3_error)
}
CYTHON_FALLTHROUGH;
case 6:
if (kw_args > 0) {
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_num_threads);
if (value) { values[6] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "make_frames") < 0)) __PYX_ERR(0, 659, __pyx_L3_error)
}
} else {
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
CYTHON_FALLTHROUGH;
case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
break;
default: goto __pyx_L5_argtuple_error;
}
}
__pyx_v_pfx = ((PyArrayObject *)values[0]);
__pyx_v_pfy = ((PyArrayObject *)values[1]);
__pyx_v_dx = __pyx_PyFloat_AsDouble(values[2]); if (unlikely((__pyx_v_dx == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 659, __pyx_L3_error)
__pyx_v_dy = __pyx_PyFloat_AsDouble(values[3]); if (unlikely((__pyx_v_dy == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 659, __pyx_L3_error)
__pyx_v_shape = ((PyObject*)values[4]);
__pyx_v_seed = __Pyx_PyInt_As_long(values[5]); if (unlikely((__pyx_v_seed == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 660, __pyx_L3_error)
if (values[6]) {
__pyx_v_num_threads = __Pyx_PyInt_As_unsigned_int(values[6]); if (unlikely((__pyx_v_num_threads == (unsigned int)-1) && PyErr_Occurred())) __PYX_ERR(0, 660, __pyx_L3_error)
} else {
__pyx_v_num_threads = ((unsigned int)((unsigned int)1));
}
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("make_frames", 0, 6, 7, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 659, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("pyrost.bin.simulation.make_frames", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_pfx), __pyx_ptype_5numpy_ndarray, 0, "pfx", 0))) __PYX_ERR(0, 659, __pyx_L1_error)
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_pfy), __pyx_ptype_5numpy_ndarray, 0, "pfy", 0))) __PYX_ERR(0, 659, __pyx_L1_error)
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_shape), (&PyTuple_Type), 1, "shape", 1))) __PYX_ERR(0, 660, __pyx_L1_error)
__pyx_r = __pyx_pf_6pyrost_3bin_10simulation_20make_frames(__pyx_self, __pyx_v_pfx, __pyx_v_pfy, __pyx_v_dx, __pyx_v_dy, __pyx_v_shape, __pyx_v_seed, __pyx_v_num_threads);
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
/* function exit code */
goto __pyx_L0;
__pyx_L1_error:;
__pyx_r = NULL;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_6pyrost_3bin_10simulation_20make_frames(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_pfx, PyArrayObject *__pyx_v_pfy, double __pyx_v_dx, double __pyx_v_dy, PyObject *__pyx_v_shape, long __pyx_v_seed, unsigned int __pyx_v_num_threads) {
int __pyx_v_fail;
npy_intp *__pyx_v_oshape;
PyArrayObject *__pyx_v_out = 0;
unsigned long *__pyx_v__ishape;
unsigned long *__pyx_v__oshape;
double *__pyx_v__out;
double *__pyx_v__pfx;
double *__pyx_v__pfy;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("make_frames", 0);
__Pyx_INCREF((PyObject *)__pyx_v_pfx);
__Pyx_INCREF((PyObject *)__pyx_v_pfy);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_AddTraceback("pyrost.bin.simulation.make_frames", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF((PyObject *)__pyx_v_out);
__Pyx_XDECREF((PyObject *)__pyx_v_pfx);
__Pyx_XDECREF((PyObject *)__pyx_v_pfy);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* … */
__pyx_tuple__31 = PyTuple_Pack(15, __pyx_n_s_pfx, __pyx_n_s_pfy, __pyx_n_s_dx, __pyx_n_s_dy, __pyx_n_s_shape, __pyx_n_s_seed, __pyx_n_s_num_threads, __pyx_n_s_fail, __pyx_n_s_oshape, __pyx_n_s_out, __pyx_n_s_ishape, __pyx_n_s_oshape_2, __pyx_n_s_out_2, __pyx_n_s_pfx_2, __pyx_n_s_pfy_2); if (unlikely(!__pyx_tuple__31)) __PYX_ERR(0, 659, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__31);
__Pyx_GIVEREF(__pyx_tuple__31);
/* … */
__pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 659, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_GIVEREF(__pyx_t_5);
PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
__pyx_t_5 = 0;
__pyx_t_5 = __Pyx_CyFunction_New(&__pyx_mdef_6pyrost_3bin_10simulation_21make_frames, 0, __pyx_n_s_make_frames, NULL, __pyx_n_s_pyrost_bin_simulation, __pyx_d, ((PyObject *)__pyx_codeobj__32)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 659, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_CyFunction_SetDefaultsTuple(__pyx_t_5, __pyx_t_4);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
if (PyDict_SetItem(__pyx_d, __pyx_n_s_make_frames, __pyx_t_5) < 0) __PYX_ERR(0, 659, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__pyx_codeobj__32 = (PyObject*)__Pyx_PyCode_New(7, 0, 15, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__31, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pyrost_bin_simulation_pyx, __pyx_n_s_make_frames, 659, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__32)) __PYX_ERR(0, 659, __pyx_L1_error)
+660: tuple shape, long seed, unsigned num_threads=1):
__pyx_t_5 = __Pyx_PyInt_From_unsigned_int(((unsigned int)1)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 660, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5);
661: """Generate intensity frames from one-dimensional intensity profiles (`pfx`,
662: `pfy`) and whitefield profiles (`wfx`, `wfy`). Intensity profiles resized into
663: the shape of a frame. Poisson noise is applied if `seed` is non-negative.
664:
665: Args:
666: pfx (numpy.ndarray) : Intensity profile along the x axis.
667: pfy (numpy.ndarray) : Intensity profile along the y axis.
668: dx (float) : Sampling interval along the x axis [um].
669: dy (float) : Sampling interval along the y axis [um].
670: shape (Tuple[int, int]) : Shape of the detector array.
671: seed (int) : Seed for pseudo-random number generation.
672: num_threads (int) : Number of threads used in the calculations.
673:
674: Returns:
675: numpy.ndarray : Intensity frames.
676: """
+677: pfx = check_array(pfx, np.NPY_FLOAT64)
__pyx_t_1 = ((PyObject *)__pyx_f_6pyrost_3bin_10simulation_check_array(__pyx_v_pfx, NPY_FLOAT64)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 677, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_pfx, ((PyArrayObject *)__pyx_t_1)); __pyx_t_1 = 0;
+678: pfy = check_array(pfy, np.NPY_FLOAT64)
__pyx_t_1 = ((PyObject *)__pyx_f_6pyrost_3bin_10simulation_check_array(__pyx_v_pfy, NPY_FLOAT64)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 678, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_pfy, ((PyArrayObject *)__pyx_t_1)); __pyx_t_1 = 0;
679:
+680: cdef int fail = 0
__pyx_v_fail = 0;
+681: cdef np.npy_intp *oshape = [pfx.shape[0], <np.npy_intp>(shape[0]), <np.npy_intp>(shape[1])]
if (unlikely(__pyx_v_shape == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
__PYX_ERR(0, 681, __pyx_L1_error)
}
__pyx_t_2 = __Pyx_PyInt_As_Py_intptr_t(PyTuple_GET_ITEM(__pyx_v_shape, 0)); if (unlikely((__pyx_t_2 == ((npy_intp)-1)) && PyErr_Occurred())) __PYX_ERR(0, 681, __pyx_L1_error)
if (unlikely(__pyx_v_shape == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
__PYX_ERR(0, 681, __pyx_L1_error)
}
__pyx_t_3 = __Pyx_PyInt_As_Py_intptr_t(PyTuple_GET_ITEM(__pyx_v_shape, 1)); if (unlikely((__pyx_t_3 == ((npy_intp)-1)) && PyErr_Occurred())) __PYX_ERR(0, 681, __pyx_L1_error)
__pyx_t_4[0] = (__pyx_v_pfx->dimensions[0]);
__pyx_t_4[1] = ((npy_intp)__pyx_t_2);
__pyx_t_4[2] = ((npy_intp)__pyx_t_3);
__pyx_v_oshape = __pyx_t_4;
+682: cdef np.ndarray out = <np.ndarray>np.PyArray_SimpleNew(3, oshape, np.NPY_FLOAT64)
__pyx_t_1 = PyArray_SimpleNew(3, __pyx_v_oshape, NPY_FLOAT64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 682, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_5 = __pyx_t_1; __Pyx_INCREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_out = ((PyArrayObject *)__pyx_t_5); __pyx_t_5 = 0;
+683: cdef unsigned long *_ishape = [<unsigned long>(pfx.shape[0]), <unsigned long>(pfy.shape[0]),
__pyx_t_6[0] = ((unsigned long)(__pyx_v_pfx->dimensions[0])); __pyx_t_6[1] = ((unsigned long)(__pyx_v_pfy->dimensions[0])); __pyx_t_6[2] = ((unsigned long)(__pyx_v_pfx->dimensions[1])); __pyx_v__ishape = __pyx_t_6;
684: <unsigned long>(pfx.shape[1])]
+685: cdef unsigned long *_oshape = [<unsigned long>(oshape[0]), <unsigned long>(oshape[1]), <unsigned long>(oshape[2])]
__pyx_t_7[0] = ((unsigned long)(__pyx_v_oshape[0])); __pyx_t_7[1] = ((unsigned long)(__pyx_v_oshape[1])); __pyx_t_7[2] = ((unsigned long)(__pyx_v_oshape[2])); __pyx_v__oshape = __pyx_t_7;
+686: cdef double *_out = <double *>np.PyArray_DATA(out)
__pyx_v__out = ((double *)PyArray_DATA(__pyx_v_out));
+687: cdef double *_pfx = <double *>np.PyArray_DATA(pfx)
__pyx_v__pfx = ((double *)PyArray_DATA(__pyx_v_pfx));
+688: cdef double *_pfy = <double *>np.PyArray_DATA(pfy)
__pyx_v__pfy = ((double *)PyArray_DATA(__pyx_v_pfy));
+689: with nogil:
{
#ifdef WITH_THREAD
PyThreadState *_save;
Py_UNBLOCK_THREADS
__Pyx_FastGIL_Remember();
#endif
/*try:*/ {
/* … */
/*finally:*/ {
/*normal exit:*/{
#ifdef WITH_THREAD
__Pyx_FastGIL_Forget();
Py_BLOCK_THREADS
#endif
goto __pyx_L5;
}
__pyx_L5:;
}
}
+690: fail = frames(_out, _pfx, _pfy, dx, dy, _ishape, _oshape, seed, num_threads)
__pyx_v_fail = frames(__pyx_v__out, __pyx_v__pfx, __pyx_v__pfy, __pyx_v_dx, __pyx_v_dy, __pyx_v__ishape, __pyx_v__oshape, __pyx_v_seed, __pyx_v_num_threads);
}
+691: if fail:
__pyx_t_8 = (__pyx_v_fail != 0);
if (unlikely(__pyx_t_8)) {
/* … */
}
+692: raise RuntimeError('C backend exited with error.')
__pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_RuntimeError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 692, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_Raise(__pyx_t_5, 0, 0, 0); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __PYX_ERR(0, 692, __pyx_L1_error)
+693: return out
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_out)); __pyx_r = ((PyObject *)__pyx_v_out); goto __pyx_L0;
694:
+695: def median(np.ndarray data not None, np.ndarray mask=None, int axis=0, unsigned num_threads=1):
/* Python wrapper */
static PyObject *__pyx_pw_6pyrost_3bin_10simulation_23median(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6pyrost_3bin_10simulation_22median[] = "Calculate a median along the `axis`.\n\n Args:\n data (numpy.ndarray) : Intensity frames.\n mask (numpy.ndarray) : Bad pixel mask.\n axis (int) : Array axis along which median values are calculated.\n num_threads (int) : Number of threads used in the calculations.\n\n Returns:\n numpy.ndarray : Array of medians along the given axis.\n ";
static PyMethodDef __pyx_mdef_6pyrost_3bin_10simulation_23median = {"median", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_6pyrost_3bin_10simulation_23median, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6pyrost_3bin_10simulation_22median};
static PyObject *__pyx_pw_6pyrost_3bin_10simulation_23median(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyArrayObject *__pyx_v_data = 0;
PyArrayObject *__pyx_v_mask = 0;
int __pyx_v_axis;
unsigned int __pyx_v_num_threads;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("median (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_data,&__pyx_n_s_mask,&__pyx_n_s_axis,&__pyx_n_s_num_threads,0};
PyObject* values[4] = {0,0,0,0};
values[1] = (PyObject *)((PyArrayObject *)((PyObject *)Py_None));
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
CYTHON_FALLTHROUGH;
case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
CYTHON_FALLTHROUGH;
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_data)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (kw_args > 0) {
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mask);
if (value) { values[1] = value; kw_args--; }
}
CYTHON_FALLTHROUGH;
case 2:
if (kw_args > 0) {
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_axis);
if (value) { values[2] = value; kw_args--; }
}
CYTHON_FALLTHROUGH;
case 3:
if (kw_args > 0) {
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_num_threads);
if (value) { values[3] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "median") < 0)) __PYX_ERR(0, 695, __pyx_L3_error)
}
} else {
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
CYTHON_FALLTHROUGH;
case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
CYTHON_FALLTHROUGH;
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
break;
default: goto __pyx_L5_argtuple_error;
}
}
__pyx_v_data = ((PyArrayObject *)values[0]);
__pyx_v_mask = ((PyArrayObject *)values[1]);
if (values[2]) {
__pyx_v_axis = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_axis == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 695, __pyx_L3_error)
} else {
__pyx_v_axis = ((int)((int)0));
}
if (values[3]) {
__pyx_v_num_threads = __Pyx_PyInt_As_unsigned_int(values[3]); if (unlikely((__pyx_v_num_threads == (unsigned int)-1) && PyErr_Occurred())) __PYX_ERR(0, 695, __pyx_L3_error)
} else {
__pyx_v_num_threads = ((unsigned int)((unsigned int)1));
}
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("median", 0, 1, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 695, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("pyrost.bin.simulation.median", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_data), __pyx_ptype_5numpy_ndarray, 0, "data", 0))) __PYX_ERR(0, 695, __pyx_L1_error)
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_mask), __pyx_ptype_5numpy_ndarray, 1, "mask", 0))) __PYX_ERR(0, 695, __pyx_L1_error)
__pyx_r = __pyx_pf_6pyrost_3bin_10simulation_22median(__pyx_self, __pyx_v_data, __pyx_v_mask, __pyx_v_axis, __pyx_v_num_threads);
/* function exit code */
goto __pyx_L0;
__pyx_L1_error:;
__pyx_r = NULL;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_6pyrost_3bin_10simulation_22median(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_data, PyArrayObject *__pyx_v_mask, int __pyx_v_axis, unsigned int __pyx_v_num_threads) {
int __pyx_v_ndim;
unsigned long *__pyx_v__dims;
npy_intp *__pyx_v_odims;
int __pyx_v_i;
int __pyx_v_type_num;
PyArrayObject *__pyx_v_out = 0;
void *__pyx_v__out;
void *__pyx_v__data;
unsigned char *__pyx_v__mask;
int __pyx_v_fail;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("median", 0);
__Pyx_INCREF((PyObject *)__pyx_v_data);
__Pyx_INCREF((PyObject *)__pyx_v_mask);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_6);
__Pyx_XDECREF(__pyx_t_9);
__Pyx_XDECREF(__pyx_t_10);
__Pyx_AddTraceback("pyrost.bin.simulation.median", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF((PyObject *)__pyx_v_out);
__Pyx_XDECREF((PyObject *)__pyx_v_data);
__Pyx_XDECREF((PyObject *)__pyx_v_mask);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* … */
__pyx_tuple__33 = PyTuple_Pack(14, __pyx_n_s_data, __pyx_n_s_mask, __pyx_n_s_axis, __pyx_n_s_num_threads, __pyx_n_s_ndim, __pyx_n_s_dims_2, __pyx_n_s_odims, __pyx_n_s_i, __pyx_n_s_type_num, __pyx_n_s_out, __pyx_n_s_out_2, __pyx_n_s_data_2, __pyx_n_s_mask_2, __pyx_n_s_fail); if (unlikely(!__pyx_tuple__33)) __PYX_ERR(0, 695, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__33);
__Pyx_GIVEREF(__pyx_tuple__33);
/* … */
__pyx_t_5 = __Pyx_PyInt_From_int(((int)0)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 695, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__pyx_t_4 = __Pyx_PyInt_From_unsigned_int(((unsigned int)1)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 695, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 695, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_INCREF(((PyObject *)Py_None));
__Pyx_GIVEREF(((PyObject *)Py_None));
PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_None));
__Pyx_GIVEREF(__pyx_t_5);
PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_5);
__Pyx_GIVEREF(__pyx_t_4);
PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_4);
__pyx_t_5 = 0;
__pyx_t_4 = 0;
__pyx_t_4 = __Pyx_CyFunction_New(&__pyx_mdef_6pyrost_3bin_10simulation_23median, 0, __pyx_n_s_median, NULL, __pyx_n_s_pyrost_bin_simulation, __pyx_d, ((PyObject *)__pyx_codeobj__34)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 695, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_CyFunction_SetDefaultsTuple(__pyx_t_4, __pyx_t_1);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
if (PyDict_SetItem(__pyx_d, __pyx_n_s_median, __pyx_t_4) < 0) __PYX_ERR(0, 695, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_codeobj__34 = (PyObject*)__Pyx_PyCode_New(4, 0, 14, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__33, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pyrost_bin_simulation_pyx, __pyx_n_s_median, 695, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__34)) __PYX_ERR(0, 695, __pyx_L1_error)
696: """Calculate a median along the `axis`.
697:
698: Args:
699: data (numpy.ndarray) : Intensity frames.
700: mask (numpy.ndarray) : Bad pixel mask.
701: axis (int) : Array axis along which median values are calculated.
702: num_threads (int) : Number of threads used in the calculations.
703:
704: Returns:
705: numpy.ndarray : Array of medians along the given axis.
706: """
+707: if not np.PyArray_IS_C_CONTIGUOUS(data):
__pyx_t_1 = ((!(PyArray_IS_C_CONTIGUOUS(__pyx_v_data) != 0)) != 0);
if (__pyx_t_1) {
/* … */
}
+708: data = np.PyArray_GETCONTIGUOUS(data)
__pyx_t_2 = ((PyObject *)PyArray_GETCONTIGUOUS(__pyx_v_data)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 708, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF_SET(__pyx_v_data, ((PyArrayObject *)__pyx_t_2)); __pyx_t_2 = 0;
709:
+710: cdef int ndim = data.ndim
__pyx_t_3 = __pyx_v_data->nd; __pyx_v_ndim = __pyx_t_3;
+711: axis = axis if axis >= 0 else ndim + axis
if (((__pyx_v_axis >= 0) != 0)) {
__pyx_t_3 = __pyx_v_axis;
} else {
__pyx_t_3 = (__pyx_v_ndim + __pyx_v_axis);
}
__pyx_v_axis = __pyx_t_3;
+712: axis = axis if axis <= ndim - 1 else ndim - 1
if (((__pyx_v_axis <= (__pyx_v_ndim - 1)) != 0)) {
__pyx_t_4 = __pyx_v_axis;
} else {
__pyx_t_4 = (__pyx_v_ndim - 1);
}
__pyx_v_axis = __pyx_t_4;
713:
+714: if mask is None:
__pyx_t_1 = (((PyObject *)__pyx_v_mask) == Py_None);
__pyx_t_5 = (__pyx_t_1 != 0);
if (__pyx_t_5) {
/* … */
goto __pyx_L4;
}
+715: mask = <np.ndarray>np.PyArray_SimpleNew(ndim, data.shape, np.NPY_BOOL)
__pyx_t_2 = PyArray_SimpleNew(__pyx_v_ndim, __pyx_v_data->dimensions, NPY_BOOL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 715, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_6 = __pyx_t_2; __Pyx_INCREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF_SET(__pyx_v_mask, ((PyArrayObject *)__pyx_t_6)); __pyx_t_6 = 0;
+716: np.PyArray_FILLWBYTE(mask, 1)
PyArray_FILLWBYTE(((PyObject *)__pyx_v_mask), 1);
717: else:
+718: mask = check_array(mask, np.NPY_BOOL)
/*else*/ {
__pyx_t_6 = ((PyObject *)__pyx_f_6pyrost_3bin_10simulation_check_array(__pyx_v_mask, NPY_BOOL)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 718, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__Pyx_DECREF_SET(__pyx_v_mask, ((PyArrayObject *)__pyx_t_6));
__pyx_t_6 = 0;
+719: if memcmp(data.shape, mask.shape, ndim * sizeof(np.npy_intp)):
__pyx_t_5 = (memcmp(__pyx_v_data->dimensions, __pyx_v_mask->dimensions, (__pyx_v_ndim * (sizeof(npy_intp)))) != 0);
if (unlikely(__pyx_t_5)) {
/* … */
}
}
__pyx_L4:;
+720: raise ValueError('mask and data arrays must have identical shapes')
__pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__6, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 720, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_Raise(__pyx_t_6, 0, 0, 0); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __PYX_ERR(0, 720, __pyx_L1_error) /* … */ __pyx_tuple__6 = PyTuple_Pack(1, __pyx_kp_u_mask_and_data_arrays_must_have_i); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(0, 720, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__6); __Pyx_GIVEREF(__pyx_tuple__6);
721:
+722: cdef unsigned long *_dims = <unsigned long *>data.shape
__pyx_v__dims = ((unsigned long *)__pyx_v_data->dimensions);
723:
+724: cdef np.npy_intp *odims = <np.npy_intp *>malloc((ndim - 1) * sizeof(np.npy_intp))
__pyx_v_odims = ((npy_intp *)malloc(((__pyx_v_ndim - 1) * (sizeof(npy_intp)))));
+725: if odims is NULL:
__pyx_t_5 = ((__pyx_v_odims == NULL) != 0);
if (unlikely(__pyx_t_5)) {
/* … */
}
+726: raise MemoryError('not enough memory')
__pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_tuple__7, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 726, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_Raise(__pyx_t_6, 0, 0, 0); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __PYX_ERR(0, 726, __pyx_L1_error) /* … */ __pyx_tuple__7 = PyTuple_Pack(1, __pyx_kp_u_not_enough_memory); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(0, 726, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__7); __Pyx_GIVEREF(__pyx_tuple__7);
727: cdef int i
+728: for i in range(axis):
__pyx_t_3 = __pyx_v_axis;
__pyx_t_7 = __pyx_t_3;
for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) {
__pyx_v_i = __pyx_t_8;
+729: odims[i] = data.shape[i]
(__pyx_v_odims[__pyx_v_i]) = (__pyx_v_data->dimensions[__pyx_v_i]); }
+730: for i in range(axis + 1, ndim):
__pyx_t_3 = __pyx_v_ndim;
__pyx_t_7 = __pyx_t_3;
for (__pyx_t_8 = (__pyx_v_axis + 1); __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) {
__pyx_v_i = __pyx_t_8;
+731: odims[i - 1] = data.shape[i]
(__pyx_v_odims[(__pyx_v_i - 1)]) = (__pyx_v_data->dimensions[__pyx_v_i]); }
732:
+733: cdef int type_num = np.PyArray_TYPE(data)
__pyx_v_type_num = PyArray_TYPE(__pyx_v_data);
+734: cdef np.ndarray out = <np.ndarray>np.PyArray_SimpleNew(ndim - 1, odims, type_num)
__pyx_t_6 = PyArray_SimpleNew((__pyx_v_ndim - 1), __pyx_v_odims, __pyx_v_type_num); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 734, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_2 = __pyx_t_6; __Pyx_INCREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_v_out = ((PyArrayObject *)__pyx_t_2); __pyx_t_2 = 0;
+735: cdef void *_out = <void *>np.PyArray_DATA(out)
__pyx_v__out = ((void *)PyArray_DATA(__pyx_v_out));
+736: cdef void *_data = <void *>np.PyArray_DATA(data)
__pyx_v__data = ((void *)PyArray_DATA(__pyx_v_data));
+737: cdef unsigned char *_mask = <unsigned char *>np.PyArray_DATA(mask)
__pyx_v__mask = ((unsigned char *)PyArray_DATA(__pyx_v_mask));
738:
+739: with nogil:
{
#ifdef WITH_THREAD
PyThreadState *_save;
Py_UNBLOCK_THREADS
__Pyx_FastGIL_Remember();
#endif
/*try:*/ {
/* … */
/*finally:*/ {
/*normal exit:*/{
#ifdef WITH_THREAD
__Pyx_FastGIL_Forget();
Py_BLOCK_THREADS
#endif
goto __pyx_L13;
}
__pyx_L12_error: {
#ifdef WITH_THREAD
__Pyx_FastGIL_Forget();
Py_BLOCK_THREADS
#endif
goto __pyx_L1_error;
}
__pyx_L13:;
}
}
+740: if type_num == np.NPY_FLOAT64:
switch (__pyx_v_type_num) {
case NPY_FLOAT64:
/* … */
break;
case NPY_FLOAT32:
+741: fail = median_c(_out, _data, _mask, ndim, _dims, 8, axis, compare_double, num_threads)
__pyx_v_fail = median(__pyx_v__out, __pyx_v__data, __pyx_v__mask, __pyx_v_ndim, __pyx_v__dims, 8, __pyx_v_axis, compare_double, __pyx_v_num_threads);
+742: elif type_num == np.NPY_FLOAT32:
break;
case NPY_INT32:
+743: fail = median_c(_out, _data, _mask, ndim, _dims, 4, axis, compare_float, num_threads)
__pyx_v_fail = median(__pyx_v__out, __pyx_v__data, __pyx_v__mask, __pyx_v_ndim, __pyx_v__dims, 4, __pyx_v_axis, compare_float, __pyx_v_num_threads);
+744: elif type_num == np.NPY_INT32:
break;
case NPY_UINT32:
+745: fail = median_c(_out, _data, _mask, ndim, _dims, 4, axis, compare_int, num_threads)
__pyx_v_fail = median(__pyx_v__out, __pyx_v__data, __pyx_v__mask, __pyx_v_ndim, __pyx_v__dims, 4, __pyx_v_axis, compare_int, __pyx_v_num_threads);
+746: elif type_num == np.NPY_UINT32:
break;
case NPY_UINT64:
+747: fail = median_c(_out, _data, _mask, ndim, _dims, 4, axis, compare_uint, num_threads)
__pyx_v_fail = median(__pyx_v__out, __pyx_v__data, __pyx_v__mask, __pyx_v_ndim, __pyx_v__dims, 4, __pyx_v_axis, compare_uint, __pyx_v_num_threads);
+748: elif type_num == np.NPY_UINT64:
break;
default:
+749: fail = median_c(_out, _data, _mask, ndim, _dims, 8, axis, compare_ulong, num_threads)
__pyx_v_fail = median(__pyx_v__out, __pyx_v__data, __pyx_v__mask, __pyx_v_ndim, __pyx_v__dims, 8, __pyx_v_axis, compare_ulong, __pyx_v_num_threads);
750: else:
+751: raise TypeError('data argument has incompatible type: {:s}'.format(data.dtype))
{
#ifdef WITH_THREAD
PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
#endif
/*try:*/ {
__pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_data_argument_has_incompatible_t, __pyx_n_s_format); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 751, __pyx_L15_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_t_9 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_data), __pyx_n_s_dtype); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 751, __pyx_L15_error)
__Pyx_GOTREF(__pyx_t_9);
__pyx_t_10 = NULL;
if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
__pyx_t_10 = PyMethod_GET_SELF(__pyx_t_6);
if (likely(__pyx_t_10)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
__Pyx_INCREF(__pyx_t_10);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_6, function);
}
}
__pyx_t_2 = (__pyx_t_10) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_10, __pyx_t_9) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_9);
__Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
__Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 751, __pyx_L15_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 751, __pyx_L15_error)
__Pyx_GOTREF(__pyx_t_6);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_Raise(__pyx_t_6, 0, 0, 0);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__PYX_ERR(0, 751, __pyx_L15_error)
}
/*finally:*/ {
__pyx_L15_error: {
#ifdef WITH_THREAD
__Pyx_PyGILState_Release(__pyx_gilstate_save);
#endif
goto __pyx_L12_error;
}
}
}
break;
}
}
+752: if fail:
__pyx_t_5 = (__pyx_v_fail != 0);
if (unlikely(__pyx_t_5)) {
/* … */
}
+753: raise RuntimeError('C backend exited with error.')
__pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_RuntimeError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 753, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_Raise(__pyx_t_6, 0, 0, 0); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __PYX_ERR(0, 753, __pyx_L1_error)
754:
+755: free(odims)
free(__pyx_v_odims);
+756: return out
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_out)); __pyx_r = ((PyObject *)__pyx_v_out); goto __pyx_L0;
757:
+758: def median_filter(np.ndarray data not None, object size not None, np.ndarray mask=None,
/* Python wrapper */
static PyObject *__pyx_pw_6pyrost_3bin_10simulation_25median_filter(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6pyrost_3bin_10simulation_24median_filter[] = "Calculate a median along the `axis`.\n\n Args:\n data (numpy.ndarray) : Intensity frames.\n size (numpy.ndarray) : Gives the shape that is taken from the input array, at every\n element position, to define the input to the filter function. We adjust size to\n the number of dimensions of the input array, so that, if the input array is shape\n (10,10,10), and size is 2, then the actual size used is (2,2,2).\n mask (Optional[numpy.ndarray]) : Bad pixel mask.\n mode (str) : The mode parameter determines how the input array is extended when the\n filter overlaps a border. Default value is 'reflect'. The valid values and their\n behavior is as follows:\n\n * 'constant', (k k k k | a b c d | k k k k) : The input is extended by filling all\n values beyond the edge with the same constant value, defined by the `cval`\n parameter.\n * 'nearest', (a a a a | a b c d | d d d d) : The input is extended by replicating\n the last pixel.\n * 'mirror', (c d c b | a b c d | c b a b) : The input is extended by reflecting\n about the center of the last pixel. This mode is also sometimes referred to as\n whole-sample symmetric.\n * 'reflect', (d c b a | a b c d | d c b a) : The input is extended by reflecting\n about the edge of the last pixel. This mode is also sometimes referred to as\n half-sample symmetric.\n * 'wrap', (a b c d | a b c d | a b c d) : The input is extended by wrapping around\n to the opposite edge.\n cval (float) : Value to fill past edges of input if mode is 'constant'. Default is 0.0.\n num_threads (int) : Number of threads used in the calculations.\n\n Returns:\n numpy.ndarray : Filtered array. Has the same shape as `input`.\n ";
static PyMethodDef __pyx_mdef_6pyrost_3bin_10simulation_25median_filter = {"median_filter", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_6pyrost_3bin_10simulation_25median_filter, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6pyrost_3bin_10simulation_24median_filter};
static PyObject *__pyx_pw_6pyrost_3bin_10simulation_25median_filter(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyArrayObject *__pyx_v_data = 0;
PyObject *__pyx_v_size = 0;
PyArrayObject *__pyx_v_mask = 0;
PyObject *__pyx_v_mode = 0;
double __pyx_v_cval;
unsigned int __pyx_v_num_threads;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("median_filter (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_data,&__pyx_n_s_size,&__pyx_n_s_mask,&__pyx_n_s_mode,&__pyx_n_s_cval,&__pyx_n_s_num_threads,0};
PyObject* values[6] = {0,0,0,0,0,0};
values[2] = (PyObject *)((PyArrayObject *)((PyObject *)Py_None));
values[3] = ((PyObject*)((PyObject*)__pyx_n_u_reflect));
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
CYTHON_FALLTHROUGH;
case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
CYTHON_FALLTHROUGH;
case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
CYTHON_FALLTHROUGH;
case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
CYTHON_FALLTHROUGH;
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_data)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_size)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("median_filter", 0, 2, 6, 1); __PYX_ERR(0, 758, __pyx_L3_error)
}
CYTHON_FALLTHROUGH;
case 2:
if (kw_args > 0) {
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mask);
if (value) { values[2] = value; kw_args--; }
}
CYTHON_FALLTHROUGH;
case 3:
if (kw_args > 0) {
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mode);
if (value) { values[3] = value; kw_args--; }
}
CYTHON_FALLTHROUGH;
case 4:
if (kw_args > 0) {
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_cval);
if (value) { values[4] = value; kw_args--; }
}
CYTHON_FALLTHROUGH;
case 5:
if (kw_args > 0) {
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_num_threads);
if (value) { values[5] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "median_filter") < 0)) __PYX_ERR(0, 758, __pyx_L3_error)
}
} else {
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
CYTHON_FALLTHROUGH;
case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
CYTHON_FALLTHROUGH;
case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
CYTHON_FALLTHROUGH;
case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
CYTHON_FALLTHROUGH;
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
break;
default: goto __pyx_L5_argtuple_error;
}
}
__pyx_v_data = ((PyArrayObject *)values[0]);
__pyx_v_size = values[1];
__pyx_v_mask = ((PyArrayObject *)values[2]);
__pyx_v_mode = ((PyObject*)values[3]);
if (values[4]) {
__pyx_v_cval = __pyx_PyFloat_AsDouble(values[4]); if (unlikely((__pyx_v_cval == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 759, __pyx_L3_error)
} else {
__pyx_v_cval = ((double)((double)0.0));
}
if (values[5]) {
__pyx_v_num_threads = __Pyx_PyInt_As_unsigned_int(values[5]); if (unlikely((__pyx_v_num_threads == (unsigned int)-1) && PyErr_Occurred())) __PYX_ERR(0, 759, __pyx_L3_error)
} else {
__pyx_v_num_threads = ((unsigned int)((unsigned int)1));
}
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("median_filter", 0, 2, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 758, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("pyrost.bin.simulation.median_filter", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_data), __pyx_ptype_5numpy_ndarray, 0, "data", 0))) __PYX_ERR(0, 758, __pyx_L1_error)
if (unlikely(((PyObject *)__pyx_v_size) == Py_None)) {
PyErr_Format(PyExc_TypeError, "Argument '%.200s' must not be None", "size"); __PYX_ERR(0, 758, __pyx_L1_error)
}
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_mask), __pyx_ptype_5numpy_ndarray, 1, "mask", 0))) __PYX_ERR(0, 758, __pyx_L1_error)
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_mode), (&PyUnicode_Type), 1, "mode", 1))) __PYX_ERR(0, 759, __pyx_L1_error)
__pyx_r = __pyx_pf_6pyrost_3bin_10simulation_24median_filter(__pyx_self, __pyx_v_data, __pyx_v_size, __pyx_v_mask, __pyx_v_mode, __pyx_v_cval, __pyx_v_num_threads);
/* function exit code */
goto __pyx_L0;
__pyx_L1_error:;
__pyx_r = NULL;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_6pyrost_3bin_10simulation_24median_filter(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_data, PyObject *__pyx_v_size, PyArrayObject *__pyx_v_mask, PyObject *__pyx_v_mode, double __pyx_v_cval, unsigned int __pyx_v_num_threads) {
int __pyx_v_ndim;
npy_intp *__pyx_v_dims;
PyArrayObject *__pyx_v_fsize = 0;
unsigned long *__pyx_v__fsize;
unsigned long *__pyx_v__dims;
int __pyx_v_type_num;
PyArrayObject *__pyx_v_out = 0;
void *__pyx_v__out;
void *__pyx_v__data;
unsigned char *__pyx_v__mask;
int __pyx_v__mode;
void *__pyx_v__cval;
int __pyx_v_fail;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("median_filter", 0);
__Pyx_INCREF((PyObject *)__pyx_v_data);
__Pyx_INCREF((PyObject *)__pyx_v_mask);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_6);
__Pyx_XDECREF(__pyx_t_7);
__Pyx_XDECREF(__pyx_t_8);
__Pyx_AddTraceback("pyrost.bin.simulation.median_filter", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF((PyObject *)__pyx_v_fsize);
__Pyx_XDECREF((PyObject *)__pyx_v_out);
__Pyx_XDECREF((PyObject *)__pyx_v_data);
__Pyx_XDECREF((PyObject *)__pyx_v_mask);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* … */
__pyx_tuple__35 = PyTuple_Pack(19, __pyx_n_s_data, __pyx_n_s_size, __pyx_n_s_mask, __pyx_n_s_mode, __pyx_n_s_cval, __pyx_n_s_num_threads, __pyx_n_s_ndim, __pyx_n_s_dims, __pyx_n_s_fsize, __pyx_n_s_fsize_2, __pyx_n_s_dims_2, __pyx_n_s_type_num, __pyx_n_s_out, __pyx_n_s_out_2, __pyx_n_s_data_2, __pyx_n_s_mask_2, __pyx_n_s_mode_2, __pyx_n_s_cval_2, __pyx_n_s_fail); if (unlikely(!__pyx_tuple__35)) __PYX_ERR(0, 758, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__35);
__Pyx_GIVEREF(__pyx_tuple__35);
/* … */
__pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 758, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_INCREF(((PyObject *)Py_None));
__Pyx_GIVEREF(((PyObject *)Py_None));
PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)Py_None));
__Pyx_INCREF(((PyObject*)__pyx_n_u_reflect));
__Pyx_GIVEREF(((PyObject*)__pyx_n_u_reflect));
PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject*)__pyx_n_u_reflect));
__Pyx_GIVEREF(__pyx_t_4);
PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_4);
__Pyx_GIVEREF(__pyx_t_1);
PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_1);
__pyx_t_4 = 0;
__pyx_t_1 = 0;
__pyx_t_1 = __Pyx_CyFunction_New(&__pyx_mdef_6pyrost_3bin_10simulation_25median_filter, 0, __pyx_n_s_median_filter, NULL, __pyx_n_s_pyrost_bin_simulation, __pyx_d, ((PyObject *)__pyx_codeobj__36)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 758, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_CyFunction_SetDefaultsTuple(__pyx_t_1, __pyx_t_5);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
if (PyDict_SetItem(__pyx_d, __pyx_n_s_median_filter, __pyx_t_1) < 0) __PYX_ERR(0, 758, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+759: str mode='reflect', double cval=0.0, unsigned num_threads=1):
__pyx_t_4 = PyFloat_FromDouble(((double)0.0)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 759, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = __Pyx_PyInt_From_unsigned_int(((unsigned int)1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 759, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1);
760: """Calculate a median along the `axis`.
761:
762: Args:
763: data (numpy.ndarray) : Intensity frames.
764: size (numpy.ndarray) : Gives the shape that is taken from the input array, at every
765: element position, to define the input to the filter function. We adjust size to
766: the number of dimensions of the input array, so that, if the input array is shape
767: (10,10,10), and size is 2, then the actual size used is (2,2,2).
768: mask (Optional[numpy.ndarray]) : Bad pixel mask.
769: mode (str) : The mode parameter determines how the input array is extended when the
770: filter overlaps a border. Default value is 'reflect'. The valid values and their
771: behavior is as follows:
772:
773: * 'constant', (k k k k | a b c d | k k k k) : The input is extended by filling all
774: values beyond the edge with the same constant value, defined by the `cval`
775: parameter.
776: * 'nearest', (a a a a | a b c d | d d d d) : The input is extended by replicating
777: the last pixel.
778: * 'mirror', (c d c b | a b c d | c b a b) : The input is extended by reflecting
779: about the center of the last pixel. This mode is also sometimes referred to as
780: whole-sample symmetric.
781: * 'reflect', (d c b a | a b c d | d c b a) : The input is extended by reflecting
782: about the edge of the last pixel. This mode is also sometimes referred to as
783: half-sample symmetric.
784: * 'wrap', (a b c d | a b c d | a b c d) : The input is extended by wrapping around
785: to the opposite edge.
786: cval (float) : Value to fill past edges of input if mode is 'constant'. Default is 0.0.
787: num_threads (int) : Number of threads used in the calculations.
788:
789: Returns:
790: numpy.ndarray : Filtered array. Has the same shape as `input`.
791: """
+792: if not np.PyArray_IS_C_CONTIGUOUS(data):
__pyx_t_1 = ((!(PyArray_IS_C_CONTIGUOUS(__pyx_v_data) != 0)) != 0);
if (__pyx_t_1) {
/* … */
}
+793: data = np.PyArray_GETCONTIGUOUS(data)
__pyx_t_2 = ((PyObject *)PyArray_GETCONTIGUOUS(__pyx_v_data)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 793, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF_SET(__pyx_v_data, ((PyArrayObject *)__pyx_t_2)); __pyx_t_2 = 0;
794:
+795: cdef int ndim = data.ndim
__pyx_t_3 = __pyx_v_data->nd; __pyx_v_ndim = __pyx_t_3;
+796: cdef np.npy_intp *dims = data.shape
__pyx_t_4 = __pyx_v_data->dimensions; __pyx_v_dims = __pyx_t_4;
797:
+798: if mask is None:
__pyx_t_1 = (((PyObject *)__pyx_v_mask) == Py_None);
__pyx_t_5 = (__pyx_t_1 != 0);
if (__pyx_t_5) {
/* … */
goto __pyx_L4;
}
+799: mask = <np.ndarray>np.PyArray_SimpleNew(ndim, dims, np.NPY_BOOL)
__pyx_t_2 = PyArray_SimpleNew(__pyx_v_ndim, __pyx_v_dims, NPY_BOOL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 799, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_6 = __pyx_t_2; __Pyx_INCREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF_SET(__pyx_v_mask, ((PyArrayObject *)__pyx_t_6)); __pyx_t_6 = 0;
+800: np.PyArray_FILLWBYTE(mask, 1)
PyArray_FILLWBYTE(((PyObject *)__pyx_v_mask), 1);
801: else:
+802: mask = check_array(mask, np.NPY_BOOL)
/*else*/ {
__pyx_t_6 = ((PyObject *)__pyx_f_6pyrost_3bin_10simulation_check_array(__pyx_v_mask, NPY_BOOL)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 802, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__Pyx_DECREF_SET(__pyx_v_mask, ((PyArrayObject *)__pyx_t_6));
__pyx_t_6 = 0;
}
__pyx_L4:;
803:
+804: cdef np.ndarray fsize = normalize_sequence(size, ndim, np.NPY_INTP)
__pyx_t_6 = ((PyObject *)__pyx_f_6pyrost_3bin_10simulation_normalize_sequence(__pyx_v_size, __pyx_v_ndim, NPY_INTP)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 804, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_v_fsize = ((PyArrayObject *)__pyx_t_6); __pyx_t_6 = 0;
+805: cdef unsigned long *_fsize = <unsigned long *>np.PyArray_DATA(fsize)
__pyx_v__fsize = ((unsigned long *)PyArray_DATA(__pyx_v_fsize));
806:
+807: cdef unsigned long *_dims = <unsigned long *>dims
__pyx_v__dims = ((unsigned long *)__pyx_v_dims);
+808: cdef int type_num = np.PyArray_TYPE(data)
__pyx_v_type_num = PyArray_TYPE(__pyx_v_data);
+809: cdef np.ndarray out = <np.ndarray>np.PyArray_SimpleNew(ndim, dims, type_num)
__pyx_t_6 = PyArray_SimpleNew(__pyx_v_ndim, __pyx_v_dims, __pyx_v_type_num); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 809, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_2 = __pyx_t_6; __Pyx_INCREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_v_out = ((PyArrayObject *)__pyx_t_2); __pyx_t_2 = 0;
+810: cdef void *_out = <void *>np.PyArray_DATA(out)
__pyx_v__out = ((void *)PyArray_DATA(__pyx_v_out));
+811: cdef void *_data = <void *>np.PyArray_DATA(data)
__pyx_v__data = ((void *)PyArray_DATA(__pyx_v_data));
+812: cdef unsigned char *_mask = <unsigned char *>np.PyArray_DATA(mask)
__pyx_v__mask = ((unsigned char *)PyArray_DATA(__pyx_v_mask));
+813: cdef int _mode = extend_mode_to_code(mode)
__pyx_t_3 = __pyx_f_6pyrost_3bin_10simulation_extend_mode_to_code(__pyx_v_mode); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 813, __pyx_L1_error)
__pyx_v__mode = __pyx_t_3;
+814: cdef void *_cval = <void *>&cval
__pyx_v__cval = ((void *)(&__pyx_v_cval));
815:
+816: with nogil:
{
#ifdef WITH_THREAD
PyThreadState *_save;
Py_UNBLOCK_THREADS
__Pyx_FastGIL_Remember();
#endif
/*try:*/ {
/* … */
/*finally:*/ {
/*normal exit:*/{
#ifdef WITH_THREAD
__Pyx_FastGIL_Forget();
Py_BLOCK_THREADS
#endif
goto __pyx_L7;
}
__pyx_L6_error: {
#ifdef WITH_THREAD
__Pyx_FastGIL_Forget();
Py_BLOCK_THREADS
#endif
goto __pyx_L1_error;
}
__pyx_L7:;
}
}
+817: if type_num == np.NPY_FLOAT64:
switch (__pyx_v_type_num) {
case NPY_FLOAT64:
/* … */
break;
case NPY_FLOAT32:
+818: fail = median_filter_c(_out, _data, _mask, ndim, _dims, 8, _fsize, _mode, _cval, compare_double, num_threads)
__pyx_v_fail = median_filter(__pyx_v__out, __pyx_v__data, __pyx_v__mask, __pyx_v_ndim, __pyx_v__dims, 8, __pyx_v__fsize, __pyx_v__mode, __pyx_v__cval, compare_double, __pyx_v_num_threads);
+819: elif type_num == np.NPY_FLOAT32:
break;
case NPY_INT32:
+820: fail = median_filter_c(_out, _data, _mask, ndim, _dims, 4, _fsize, _mode, _cval, compare_float, num_threads)
__pyx_v_fail = median_filter(__pyx_v__out, __pyx_v__data, __pyx_v__mask, __pyx_v_ndim, __pyx_v__dims, 4, __pyx_v__fsize, __pyx_v__mode, __pyx_v__cval, compare_float, __pyx_v_num_threads);
+821: elif type_num == np.NPY_INT32:
break;
case NPY_UINT32:
+822: fail = median_filter_c(_out, _data, _mask, ndim, _dims, 4, _fsize, _mode, _cval, compare_int, num_threads)
__pyx_v_fail = median_filter(__pyx_v__out, __pyx_v__data, __pyx_v__mask, __pyx_v_ndim, __pyx_v__dims, 4, __pyx_v__fsize, __pyx_v__mode, __pyx_v__cval, compare_int, __pyx_v_num_threads);
+823: elif type_num == np.NPY_UINT32:
break;
case NPY_UINT64:
+824: fail = median_filter_c(_out, _data, _mask, ndim, _dims, 4, _fsize, _mode, _cval, compare_uint, num_threads)
__pyx_v_fail = median_filter(__pyx_v__out, __pyx_v__data, __pyx_v__mask, __pyx_v_ndim, __pyx_v__dims, 4, __pyx_v__fsize, __pyx_v__mode, __pyx_v__cval, compare_uint, __pyx_v_num_threads);
+825: elif type_num == np.NPY_UINT64:
break;
default:
+826: fail = median_filter_c(_out, _data, _mask, ndim, _dims, 8, _fsize, _mode, _cval, compare_ulong, num_threads)
__pyx_v_fail = median_filter(__pyx_v__out, __pyx_v__data, __pyx_v__mask, __pyx_v_ndim, __pyx_v__dims, 8, __pyx_v__fsize, __pyx_v__mode, __pyx_v__cval, compare_ulong, __pyx_v_num_threads);
827: else:
+828: raise TypeError('data argument has incompatible type: {:s}'.format(data.dtype))
{
#ifdef WITH_THREAD
PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
#endif
/*try:*/ {
__pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_data_argument_has_incompatible_t, __pyx_n_s_format); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 828, __pyx_L9_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_data), __pyx_n_s_dtype); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 828, __pyx_L9_error)
__Pyx_GOTREF(__pyx_t_7);
__pyx_t_8 = NULL;
if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
__pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6);
if (likely(__pyx_t_8)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
__Pyx_INCREF(__pyx_t_8);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_6, function);
}
}
__pyx_t_2 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_8, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7);
__Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 828, __pyx_L9_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 828, __pyx_L9_error)
__Pyx_GOTREF(__pyx_t_6);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_Raise(__pyx_t_6, 0, 0, 0);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__PYX_ERR(0, 828, __pyx_L9_error)
}
/*finally:*/ {
__pyx_L9_error: {
#ifdef WITH_THREAD
__Pyx_PyGILState_Release(__pyx_gilstate_save);
#endif
goto __pyx_L6_error;
}
}
}
break;
}
}
+829: if fail:
__pyx_t_5 = (__pyx_v_fail != 0);
if (unlikely(__pyx_t_5)) {
/* … */
}
+830: raise RuntimeError('C backend exited with error.')
__pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_RuntimeError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 830, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_Raise(__pyx_t_6, 0, 0, 0); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __PYX_ERR(0, 830, __pyx_L1_error)
831:
+832: return out
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_out)); __pyx_r = ((PyObject *)__pyx_v_out); goto __pyx_L0;