Cython: neighbour_table_ext.pyx

Generated by Cython 0.29.28

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: neighbour_table_ext.cpp

    +01: #cython: wraparound=False, boundscheck=False, cdivision=True, profile=False, nonecheck=False, overflowcheck=False, cdivision_warnings=False, unraisable_tracebacks=False

      __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;

     02: import cython

     03:

     04: # import both numpy and the Cython declarations for numpy

    +05: import numpy as np

      __pyx_t_1 = __Pyx_Import(__pyx_n_s_numpy, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_np, __pyx_t_1) < 0) __PYX_ERR(0, 5, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

     06: cimport numpy as np

     07:

     08: ctypedef long keyint

     09:

     10: # declare the interface to the C code

     11: cdef extern from "neighbour_table.cpp":

     12: 	int _build_neighbour_structure(keyint N, keyint M, long* triangles, long* neighbours, long* neighbour_edges, long* number_of_boundaries)

     13:

    +14: def build_neighbour_structure(keyint N,\

    /* Python wrapper */
    static PyObject *__pyx_pw_5anuga_26abstract_2d_finite_volumes_19neighbour_table_ext_1build_neighbour_structure(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
    static PyMethodDef __pyx_mdef_5anuga_26abstract_2d_finite_volumes_19neighbour_table_ext_1build_neighbour_structure = {"build_neighbour_structure", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5anuga_26abstract_2d_finite_volumes_19neighbour_table_ext_1build_neighbour_structure, METH_VARARGS|METH_KEYWORDS, 0};
    static PyObject *__pyx_pw_5anuga_26abstract_2d_finite_volumes_19neighbour_table_ext_1build_neighbour_structure(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
      __pyx_t_5anuga_26abstract_2d_finite_volumes_19neighbour_table_ext_keyint __pyx_v_N;
      PyArrayObject *__pyx_v_triangles = 0;
      PyArrayObject *__pyx_v_neighbours = 0;
      PyArrayObject *__pyx_v_neighbour_edges = 0;
      PyArrayObject *__pyx_v_number_of_boundaries = 0;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("build_neighbour_structure (wrapper)", 0);
      {
        static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_N,&__pyx_n_s_triangles,&__pyx_n_s_neighbours,&__pyx_n_s_neighbour_edges,&__pyx_n_s_number_of_boundaries,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_N)) != 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_triangles)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("build_neighbour_structure", 1, 5, 5, 1); __PYX_ERR(0, 14, __pyx_L3_error)
            }
            CYTHON_FALLTHROUGH;
            case  2:
            if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_neighbours)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("build_neighbour_structure", 1, 5, 5, 2); __PYX_ERR(0, 14, __pyx_L3_error)
            }
            CYTHON_FALLTHROUGH;
            case  3:
            if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_neighbour_edges)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("build_neighbour_structure", 1, 5, 5, 3); __PYX_ERR(0, 14, __pyx_L3_error)
            }
            CYTHON_FALLTHROUGH;
            case  4:
            if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_number_of_boundaries)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("build_neighbour_structure", 1, 5, 5, 4); __PYX_ERR(0, 14, __pyx_L3_error)
            }
          }
          if (unlikely(kw_args > 0)) {
            if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "build_neighbour_structure") < 0)) __PYX_ERR(0, 14, __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_N = __Pyx_PyInt_As_long(values[0]); if (unlikely((__pyx_v_N == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 14, __pyx_L3_error)
        __pyx_v_triangles = ((PyArrayObject *)values[1]);
        __pyx_v_neighbours = ((PyArrayObject *)values[2]);
        __pyx_v_neighbour_edges = ((PyArrayObject *)values[3]);
        __pyx_v_number_of_boundaries = ((PyArrayObject *)values[4]);
      }
      goto __pyx_L4_argument_unpacking_done;
      __pyx_L5_argtuple_error:;
      __Pyx_RaiseArgtupleInvalid("build_neighbour_structure", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 14, __pyx_L3_error)
      __pyx_L3_error:;
      __Pyx_AddTraceback("anuga.abstract_2d_finite_volumes.neighbour_table_ext.build_neighbour_structure", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __Pyx_RefNannyFinishContext();
      return NULL;
      __pyx_L4_argument_unpacking_done:;
      if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_triangles), __pyx_ptype_5numpy_ndarray, 0, "triangles", 0))) __PYX_ERR(0, 15, __pyx_L1_error)
      if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_neighbours), __pyx_ptype_5numpy_ndarray, 0, "neighbours", 0))) __PYX_ERR(0, 16, __pyx_L1_error)
      if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_neighbour_edges), __pyx_ptype_5numpy_ndarray, 0, "neighbour_edges", 0))) __PYX_ERR(0, 17, __pyx_L1_error)
      if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_number_of_boundaries), __pyx_ptype_5numpy_ndarray, 0, "number_of_boundaries", 0))) __PYX_ERR(0, 18, __pyx_L1_error)
      __pyx_r = __pyx_pf_5anuga_26abstract_2d_finite_volumes_19neighbour_table_ext_build_neighbour_structure(__pyx_self, __pyx_v_N, __pyx_v_triangles, __pyx_v_neighbours, __pyx_v_neighbour_edges, __pyx_v_number_of_boundaries);
      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_5anuga_26abstract_2d_finite_volumes_19neighbour_table_ext_build_neighbour_structure(CYTHON_UNUSED PyObject *__pyx_self, __pyx_t_5anuga_26abstract_2d_finite_volumes_19neighbour_table_ext_keyint __pyx_v_N, PyArrayObject *__pyx_v_triangles, PyArrayObject *__pyx_v_neighbours, PyArrayObject *__pyx_v_neighbour_edges, PyArrayObject *__pyx_v_number_of_boundaries) {
      __pyx_t_5anuga_26abstract_2d_finite_volumes_19neighbour_table_ext_keyint __pyx_v_M;
      int __pyx_v_err;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_neighbour_edges;
      __Pyx_Buffer __pyx_pybuffer_neighbour_edges;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_neighbours;
      __Pyx_Buffer __pyx_pybuffer_neighbours;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_number_of_boundaries;
      __Pyx_Buffer __pyx_pybuffer_number_of_boundaries;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_triangles;
      __Pyx_Buffer __pyx_pybuffer_triangles;
      PyObject *__pyx_r = NULL;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("build_neighbour_structure", 0);
      __pyx_pybuffer_triangles.pybuffer.buf = NULL;
      __pyx_pybuffer_triangles.refcount = 0;
      __pyx_pybuffernd_triangles.data = NULL;
      __pyx_pybuffernd_triangles.rcbuffer = &__pyx_pybuffer_triangles;
      __pyx_pybuffer_neighbours.pybuffer.buf = NULL;
      __pyx_pybuffer_neighbours.refcount = 0;
      __pyx_pybuffernd_neighbours.data = NULL;
      __pyx_pybuffernd_neighbours.rcbuffer = &__pyx_pybuffer_neighbours;
      __pyx_pybuffer_neighbour_edges.pybuffer.buf = NULL;
      __pyx_pybuffer_neighbour_edges.refcount = 0;
      __pyx_pybuffernd_neighbour_edges.data = NULL;
      __pyx_pybuffernd_neighbour_edges.rcbuffer = &__pyx_pybuffer_neighbour_edges;
      __pyx_pybuffer_number_of_boundaries.pybuffer.buf = NULL;
      __pyx_pybuffer_number_of_boundaries.refcount = 0;
      __pyx_pybuffernd_number_of_boundaries.data = NULL;
      __pyx_pybuffernd_number_of_boundaries.rcbuffer = &__pyx_pybuffer_number_of_boundaries;
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_triangles.rcbuffer->pybuffer, (PyObject*)__pyx_v_triangles, &__Pyx_TypeInfo_long, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 14, __pyx_L1_error)
      }
      __pyx_pybuffernd_triangles.diminfo[0].strides = __pyx_pybuffernd_triangles.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_triangles.diminfo[0].shape = __pyx_pybuffernd_triangles.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_triangles.diminfo[1].strides = __pyx_pybuffernd_triangles.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_triangles.diminfo[1].shape = __pyx_pybuffernd_triangles.rcbuffer->pybuffer.shape[1];
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_neighbours.rcbuffer->pybuffer, (PyObject*)__pyx_v_neighbours, &__Pyx_TypeInfo_long, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 14, __pyx_L1_error)
      }
      __pyx_pybuffernd_neighbours.diminfo[0].strides = __pyx_pybuffernd_neighbours.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_neighbours.diminfo[0].shape = __pyx_pybuffernd_neighbours.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_neighbours.diminfo[1].strides = __pyx_pybuffernd_neighbours.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_neighbours.diminfo[1].shape = __pyx_pybuffernd_neighbours.rcbuffer->pybuffer.shape[1];
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_neighbour_edges.rcbuffer->pybuffer, (PyObject*)__pyx_v_neighbour_edges, &__Pyx_TypeInfo_long, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 14, __pyx_L1_error)
      }
      __pyx_pybuffernd_neighbour_edges.diminfo[0].strides = __pyx_pybuffernd_neighbour_edges.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_neighbour_edges.diminfo[0].shape = __pyx_pybuffernd_neighbour_edges.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_neighbour_edges.diminfo[1].strides = __pyx_pybuffernd_neighbour_edges.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_neighbour_edges.diminfo[1].shape = __pyx_pybuffernd_neighbour_edges.rcbuffer->pybuffer.shape[1];
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_number_of_boundaries.rcbuffer->pybuffer, (PyObject*)__pyx_v_number_of_boundaries, &__Pyx_TypeInfo_long, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 14, __pyx_L1_error)
      }
      __pyx_pybuffernd_number_of_boundaries.diminfo[0].strides = __pyx_pybuffernd_number_of_boundaries.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_number_of_boundaries.diminfo[0].shape = __pyx_pybuffernd_number_of_boundaries.rcbuffer->pybuffer.shape[0];
    /* … */
      /* function exit code */
      __pyx_r = Py_None; __Pyx_INCREF(Py_None);
      goto __pyx_L0;
      __pyx_L1_error:;
      { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
        __Pyx_PyThreadState_declare
        __Pyx_PyThreadState_assign
        __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_neighbour_edges.rcbuffer->pybuffer);
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_neighbours.rcbuffer->pybuffer);
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_number_of_boundaries.rcbuffer->pybuffer);
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_triangles.rcbuffer->pybuffer);
      __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
      __Pyx_AddTraceback("anuga.abstract_2d_finite_volumes.neighbour_table_ext.build_neighbour_structure", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      goto __pyx_L2;
      __pyx_L0:;
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_neighbour_edges.rcbuffer->pybuffer);
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_neighbours.rcbuffer->pybuffer);
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_number_of_boundaries.rcbuffer->pybuffer);
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_triangles.rcbuffer->pybuffer);
      __pyx_L2:;
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }
    /* … */
      __pyx_tuple__3 = PyTuple_Pack(7, __pyx_n_s_N, __pyx_n_s_triangles, __pyx_n_s_neighbours, __pyx_n_s_neighbour_edges, __pyx_n_s_number_of_boundaries, __pyx_n_s_M, __pyx_n_s_err); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 14, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_tuple__3);
      __Pyx_GIVEREF(__pyx_tuple__3);
    /* … */
      __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5anuga_26abstract_2d_finite_volumes_19neighbour_table_ext_1build_neighbour_structure, NULL, __pyx_n_s_anuga_abstract_2d_finite_volumes_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 14, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_build_neighbour_structure, __pyx_t_1) < 0) __PYX_ERR(0, 14, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

     15: 						np.ndarray[long, ndim=2, mode="c"] triangles not None,\

     16: 						np.ndarray[long, ndim=2, mode="c"] neighbours not None,\

     17: 						np.ndarray[long, ndim=2, mode="c"] neighbour_edges not None,\

     18: 						np.ndarray[long, ndim=1, mode="c"] number_of_boundaries not None):

     19:

     20: 	cdef keyint M

     21: 	cdef int err

     22:

    +23: 	M = triangles.shape[0]

      __pyx_v_M = (__pyx_v_triangles->dimensions[0]);

     24:

    +25: 	err = _build_neighbour_structure(N, M, &triangles[0,0], &neighbours[0,0], &neighbour_edges[0,0], &number_of_boundaries[0])

      __pyx_t_1 = 0;
      __pyx_t_2 = 0;
      __pyx_t_3 = 0;
      __pyx_t_4 = 0;
      __pyx_t_5 = 0;
      __pyx_t_6 = 0;
      __pyx_t_7 = 0;
      __pyx_v_err = _build_neighbour_structure(__pyx_v_N, __pyx_v_M, (&(*__Pyx_BufPtrCContig2d(long *, __pyx_pybuffernd_triangles.rcbuffer->pybuffer.buf, __pyx_t_1, __pyx_pybuffernd_triangles.diminfo[0].strides, __pyx_t_2, __pyx_pybuffernd_triangles.diminfo[1].strides))), (&(*__Pyx_BufPtrCContig2d(long *, __pyx_pybuffernd_neighbours.rcbuffer->pybuffer.buf, __pyx_t_3, __pyx_pybuffernd_neighbours.diminfo[0].strides, __pyx_t_4, __pyx_pybuffernd_neighbours.diminfo[1].strides))), (&(*__Pyx_BufPtrCContig2d(long *, __pyx_pybuffernd_neighbour_edges.rcbuffer->pybuffer.buf, __pyx_t_5, __pyx_pybuffernd_neighbour_edges.diminfo[0].strides, __pyx_t_6, __pyx_pybuffernd_neighbour_edges.diminfo[1].strides))), (&(*__Pyx_BufPtrCContig1d(long *, __pyx_pybuffernd_number_of_boundaries.rcbuffer->pybuffer.buf, __pyx_t_7, __pyx_pybuffernd_number_of_boundaries.diminfo[0].strides))));

     26:

    +27: 	assert err == 0, "Duplicate Edge"

      #ifndef CYTHON_WITHOUT_ASSERTIONS
      if (unlikely(!Py_OptimizeFlag)) {
        if (unlikely(!((__pyx_v_err == 0) != 0))) {
          PyErr_SetObject(PyExc_AssertionError, __pyx_kp_s_Duplicate_Edge);
          __PYX_ERR(0, 27, __pyx_L1_error)
        }
      }
      #endif

     28:

     29:

     30: