Generated by Cython 3.2.8
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: lattice_tools.c
+01: ## ...........................................................................
__pyx_t_4 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_test, __pyx_t_4) < (0)) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
02: ##
03: ## PIMMS (Polymer Interactions in Multicomponent Mixtures)
04: ## Author: Alex Holehouse
05: ## Developed by the Holehouse and Pappu labs
06: ## Copyright 2015 - 2026
07: ##
08: ## ...........................................................................
09:
10:
+11: import numpy as np
__pyx_t_1 = __Pyx_Import(__pyx_mstate_global->__pyx_n_u_numpy, 0, 0, NULL, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 11, __pyx_L1_error) __pyx_t_4 = __pyx_t_1; __Pyx_GOTREF(__pyx_t_4); if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_np, __pyx_t_4) < (0)) __PYX_ERR(0, 11, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
12: cimport numpy as cnp
+13: cnp.import_array()
__pyx_t_9 = __pyx_f_5numpy_import_array(); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(0, 13, __pyx_L1_error)
14: cimport cython
15:
16:
17: from pimms.cython_config cimport NUMPY_INT_TYPE
+18: from pimms.CONFIG import NP_INT_TYPE as NUMPY_INT_TYPE_PYTHON
{
PyObject* const __pyx_imported_names[] = {__pyx_mstate_global->__pyx_n_u_NP_INT_TYPE};
__pyx_t_1 = __Pyx_Import(__pyx_mstate_global->__pyx_n_u_pimms_CONFIG, __pyx_imported_names, 1, NULL, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 18, __pyx_L1_error)
}
__pyx_t_4 = __pyx_t_1;
__Pyx_GOTREF(__pyx_t_4);
{
PyObject* const __pyx_imported_names[] = {__pyx_mstate_global->__pyx_n_u_NP_INT_TYPE};
__pyx_t_10 = 0; {
__pyx_t_5 = __Pyx_ImportFrom(__pyx_t_4, __pyx_imported_names[__pyx_t_10]); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 18, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
switch (__pyx_t_10) {
case 0:
if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_NUMPY_INT_TYPE_PYTHON, __pyx_t_5) < (0)) __PYX_ERR(0, 18, __pyx_L1_error)
break;
default:;
}
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
}
}
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
19: #ctypedef cnp.int_t NUMPY_INT_TYPE
20:
21:
22: ## File that contains discrete, stateless functions
23: ## for high performance lattice operations
24: ##
25: ##
26:
27:
+28: @cython.boundscheck(False)
/* Python wrapper */ static PyObject *__pyx_pw_5pimms_13lattice_tools_1pbc_correct_3D(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ PyDoc_STRVAR(__pyx_doc_5pimms_13lattice_tools_pbc_correct_3D, "\n Function which performs relative PBC correction using positionA as the universal reference and\n repositioning B if necessary\n\n "); static PyMethodDef __pyx_mdef_5pimms_13lattice_tools_1pbc_correct_3D = {"pbc_correct_3D", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pimms_13lattice_tools_1pbc_correct_3D, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pimms_13lattice_tools_pbc_correct_3D}; static PyObject *__pyx_pw_5pimms_13lattice_tools_1pbc_correct_3D(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { __Pyx_memviewslice __pyx_v_posA = { 0, 0, { 0 }, { 0 }, { 0 } }; __Pyx_memviewslice __pyx_v_posB = { 0, 0, { 0 }, { 0 }, { 0 } }; __Pyx_memviewslice __pyx_v_DIM = { 0, 0, { 0 }, { 0 }, { 0 } }; #if !CYTHON_METH_FASTCALL CYTHON_UNUSED Py_ssize_t __pyx_nargs; #endif CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("pbc_correct_3D (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_SIZE __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); #else __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; #endif #endif __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); { PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_posA,&__pyx_mstate_global->__pyx_n_u_posB,&__pyx_mstate_global->__pyx_n_u_DIM,0}; PyObject* values[3] = {0,0,0}; const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; if (unlikely(__pyx_kwds_len < 0)) __PYX_ERR(0, 28, __pyx_L3_error) if (__pyx_kwds_len > 0) { switch (__pyx_nargs) { case 3: values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 28, __pyx_L3_error) CYTHON_FALLTHROUGH; case 2: values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 28, __pyx_L3_error) CYTHON_FALLTHROUGH; case 1: values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 28, __pyx_L3_error) CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } const Py_ssize_t kwd_pos_args = __pyx_nargs; if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "pbc_correct_3D", 0) < (0)) __PYX_ERR(0, 28, __pyx_L3_error) for (Py_ssize_t i = __pyx_nargs; i < 3; i++) { if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("pbc_correct_3D", 1, 3, 3, i); __PYX_ERR(0, 28, __pyx_L3_error) } } } else if (unlikely(__pyx_nargs != 3)) { goto __pyx_L5_argtuple_error; } else { values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 28, __pyx_L3_error) values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 28, __pyx_L3_error) values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 28, __pyx_L3_error) } __pyx_v_posA = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE(values[0], PyBUF_WRITABLE); if (unlikely(!__pyx_v_posA.memview)) __PYX_ERR(0, 30, __pyx_L3_error) __pyx_v_posB = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE(values[1], PyBUF_WRITABLE); if (unlikely(!__pyx_v_posB.memview)) __PYX_ERR(0, 30, __pyx_L3_error) __pyx_v_DIM = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE(values[2], PyBUF_WRITABLE); if (unlikely(!__pyx_v_DIM.memview)) __PYX_ERR(0, 30, __pyx_L3_error) } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("pbc_correct_3D", 1, 3, 3, __pyx_nargs); __PYX_ERR(0, 28, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } __PYX_XCLEAR_MEMVIEW(&__pyx_v_posA, 1); __PYX_XCLEAR_MEMVIEW(&__pyx_v_posB, 1); __PYX_XCLEAR_MEMVIEW(&__pyx_v_DIM, 1); __Pyx_AddTraceback("pimms.lattice_tools.pbc_correct_3D", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_5pimms_13lattice_tools_pbc_correct_3D(__pyx_self, __pyx_v_posA, __pyx_v_posB, __pyx_v_DIM); int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; /* function exit code */ for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } __PYX_XCLEAR_MEMVIEW(&__pyx_v_posA, 1); __PYX_XCLEAR_MEMVIEW(&__pyx_v_posB, 1); __PYX_XCLEAR_MEMVIEW(&__pyx_v_DIM, 1); __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_5pimms_13lattice_tools_pbc_correct_3D(CYTHON_UNUSED PyObject *__pyx_self, __Pyx_memviewslice __pyx_v_posA, __Pyx_memviewslice __pyx_v_posB, __Pyx_memviewslice __pyx_v_DIM) { PyArrayObject *__pyx_v_newB = 0; int __pyx_v_i; __Pyx_LocalBuf_ND __pyx_pybuffernd_newB; __Pyx_Buffer __pyx_pybuffer_newB; PyObject *__pyx_r = NULL; __pyx_pybuffer_newB.pybuffer.buf = NULL; __pyx_pybuffer_newB.refcount = 0; __pyx_pybuffernd_newB.data = NULL; __pyx_pybuffernd_newB.rcbuffer = &__pyx_pybuffer_newB; /* … */ __pyx_t_4 = __Pyx_CyFunction_New(&__pyx_mdef_5pimms_13lattice_tools_1pbc_correct_3D, 0, __pyx_mstate_global->__pyx_n_u_pbc_correct_3D, NULL, __pyx_mstate_global->__pyx_n_u_pimms_lattice_tools, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[0])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 28, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030E0000 PyUnstable_Object_EnableDeferredRefcount(__pyx_t_4); #endif if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_pbc_correct_3D, __pyx_t_4) < (0)) __PYX_ERR(0, 28, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
29: @cython.wraparound(False)
30: def pbc_correct_3D(NUMPY_INT_TYPE[:] posA, NUMPY_INT_TYPE[:] posB, NUMPY_INT_TYPE[:] DIM):
31: """
32: Function which performs relative PBC correction using positionA as the universal reference and
33: repositioning B if necessary
34:
35: """
36:
+37: cdef cnp.ndarray[NUMPY_INT_TYPE, ndim=1] newB = np.zeros((3), dtype=NUMPY_INT_TYPE_PYTHON)
__pyx_t_2 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 37, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_zeros); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 37, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_NUMPY_INT_TYPE_PYTHON); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 37, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_5 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_4))) { __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_4); assert(__pyx_t_2); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_4); __Pyx_INCREF(__pyx_t_2); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_4, __pyx__function); __pyx_t_5 = 0; } #endif { PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_2, __pyx_mstate_global->__pyx_int_3}; __pyx_t_6 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 37, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_dtype, __pyx_t_3, __pyx_t_6, __pyx_callargs+2, 0) < (0)) __PYX_ERR(0, 37, __pyx_L1_error) __pyx_t_1 = __Pyx_Object_Vectorcall_CallFromBuilder((PyObject*)__pyx_t_4, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_6); __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 37, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_mstate_global->__pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 37, __pyx_L1_error) { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_newB.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_1), &__Pyx_TypeInfo_nn___pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { __pyx_v_newB = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_newB.rcbuffer->pybuffer.buf = NULL; __PYX_ERR(0, 37, __pyx_L1_error) } else {__pyx_pybuffernd_newB.diminfo[0].strides = __pyx_pybuffernd_newB.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_newB.diminfo[0].shape = __pyx_pybuffernd_newB.rcbuffer->pybuffer.shape[0]; } } __pyx_v_newB = ((PyArrayObject *)__pyx_t_1); __pyx_t_1 = 0;
38:
39: cdef int i;
40:
+41: for i in range(0,3):
for (__pyx_t_7 = 0; __pyx_t_7 < 3; __pyx_t_7+=1) {
__pyx_v_i = __pyx_t_7;
+42: if posA[i] - posB[i] > DIM[i]/2:
__pyx_t_8 = __pyx_v_i;
__pyx_t_9 = __pyx_v_i;
__pyx_t_10 = __pyx_v_i;
__pyx_t_11 = (((*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=0 */ (__pyx_v_posA.data + __pyx_t_8 * __pyx_v_posA.strides[0]) ))) - (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=0 */ (__pyx_v_posB.data + __pyx_t_9 * __pyx_v_posB.strides[0]) )))) > (((double)(*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=0 */ (__pyx_v_DIM.data + __pyx_t_10 * __pyx_v_DIM.strides[0]) )))) / 2.0));
if (__pyx_t_11) {
/* … */
goto __pyx_L5;
}
+43: newB[i] = posB[i] + DIM[i]
__pyx_t_10 = __pyx_v_i;
__pyx_t_9 = __pyx_v_i;
__pyx_t_8 = __pyx_v_i;
*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_newB.rcbuffer->pybuffer.buf, __pyx_t_8, __pyx_pybuffernd_newB.diminfo[0].strides) = ((*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=0 */ (__pyx_v_posB.data + __pyx_t_10 * __pyx_v_posB.strides[0]) ))) + (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=0 */ (__pyx_v_DIM.data + __pyx_t_9 * __pyx_v_DIM.strides[0]) ))));
+44: elif posA[i] - posB[i] < -DIM[i]/2:
__pyx_t_9 = __pyx_v_i;
__pyx_t_10 = __pyx_v_i;
__pyx_t_8 = __pyx_v_i;
__pyx_t_11 = (((*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=0 */ (__pyx_v_posA.data + __pyx_t_9 * __pyx_v_posA.strides[0]) ))) - (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=0 */ (__pyx_v_posB.data + __pyx_t_10 * __pyx_v_posB.strides[0]) )))) < (((double)(-(*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=0 */ (__pyx_v_DIM.data + __pyx_t_8 * __pyx_v_DIM.strides[0]) ))))) / 2.0));
if (__pyx_t_11) {
/* … */
goto __pyx_L5;
}
+45: newB[i] = posB[i] - DIM[i]
__pyx_t_8 = __pyx_v_i;
__pyx_t_10 = __pyx_v_i;
__pyx_t_9 = __pyx_v_i;
*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_newB.rcbuffer->pybuffer.buf, __pyx_t_9, __pyx_pybuffernd_newB.diminfo[0].strides) = ((*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=0 */ (__pyx_v_posB.data + __pyx_t_8 * __pyx_v_posB.strides[0]) ))) - (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=0 */ (__pyx_v_DIM.data + __pyx_t_10 * __pyx_v_DIM.strides[0]) ))));
46: else:
+47: newB[i] = posB[i]
/*else*/ {
__pyx_t_10 = __pyx_v_i;
__pyx_t_8 = __pyx_v_i;
*__Pyx_BufPtrStrided1d(__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *, __pyx_pybuffernd_newB.rcbuffer->pybuffer.buf, __pyx_t_8, __pyx_pybuffernd_newB.diminfo[0].strides) = (*((__pyx_t_5pimms_13cython_config_NUMPY_INT_TYPE *) ( /* dim=0 */ (__pyx_v_posB.data + __pyx_t_10 * __pyx_v_posB.strides[0]) )));
}
__pyx_L5:;
}
48:
49:
50: """
51: print ">>>> IN"
52: print posA
53: print posB
54: print newB
55: print ""
56: """
57:
58:
+59: return newB
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF((PyObject *)__pyx_v_newB); __pyx_r = ((PyObject *)__pyx_v_newB); goto __pyx_L0;
60:
61:
62:
63:
64:
65:
66: