Cython: metis_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: metis_ext.c

    +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: from libc.stdlib cimport malloc, free

     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: np.import_array()

      __pyx_t_2 = __pyx_f_5numpy_import_array(); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(0, 8, __pyx_L1_error)

     09:

     10: ctypedef int idxtype

     11:

     12: cdef extern from 'metis_bridge.c':

     13: 	void bridge_partMeshNodal(int* ne, int* nn, idxtype* elmnts, int* etype, int* numflag, int* nparts, int* edgecut, idxtype* epart, idxtype* npart)

     14:

    +15: def partMeshNodal(int ne, int nn, object elements, int etype, int nparts):

    /* Python wrapper */
    static PyObject *__pyx_pw_5anuga_9pymetis_4_9metis_ext_1partMeshNodal(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
    static PyMethodDef __pyx_mdef_5anuga_9pymetis_4_9metis_ext_1partMeshNodal = {"partMeshNodal", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5anuga_9pymetis_4_9metis_ext_1partMeshNodal, METH_VARARGS|METH_KEYWORDS, 0};
    static PyObject *__pyx_pw_5anuga_9pymetis_4_9metis_ext_1partMeshNodal(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
      int __pyx_v_ne;
      int __pyx_v_nn;
      PyObject *__pyx_v_elements = 0;
      int __pyx_v_etype;
      int __pyx_v_nparts;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("partMeshNodal (wrapper)", 0);
      {
        static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_ne,&__pyx_n_s_nn,&__pyx_n_s_elements,&__pyx_n_s_etype,&__pyx_n_s_nparts,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_ne)) != 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_nn)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("partMeshNodal", 1, 5, 5, 1); __PYX_ERR(0, 15, __pyx_L3_error)
            }
            CYTHON_FALLTHROUGH;
            case  2:
            if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_elements)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("partMeshNodal", 1, 5, 5, 2); __PYX_ERR(0, 15, __pyx_L3_error)
            }
            CYTHON_FALLTHROUGH;
            case  3:
            if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_etype)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("partMeshNodal", 1, 5, 5, 3); __PYX_ERR(0, 15, __pyx_L3_error)
            }
            CYTHON_FALLTHROUGH;
            case  4:
            if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_nparts)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("partMeshNodal", 1, 5, 5, 4); __PYX_ERR(0, 15, __pyx_L3_error)
            }
          }
          if (unlikely(kw_args > 0)) {
            if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "partMeshNodal") < 0)) __PYX_ERR(0, 15, __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_ne = __Pyx_PyInt_As_int(values[0]); if (unlikely((__pyx_v_ne == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 15, __pyx_L3_error)
        __pyx_v_nn = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_nn == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 15, __pyx_L3_error)
        __pyx_v_elements = values[2];
        __pyx_v_etype = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_etype == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 15, __pyx_L3_error)
        __pyx_v_nparts = __Pyx_PyInt_As_int(values[4]); if (unlikely((__pyx_v_nparts == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 15, __pyx_L3_error)
      }
      goto __pyx_L4_argument_unpacking_done;
      __pyx_L5_argtuple_error:;
      __Pyx_RaiseArgtupleInvalid("partMeshNodal", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 15, __pyx_L3_error)
      __pyx_L3_error:;
      __Pyx_AddTraceback("anuga.pymetis_4.metis_ext.partMeshNodal", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __Pyx_RefNannyFinishContext();
      return NULL;
      __pyx_L4_argument_unpacking_done:;
      __pyx_r = __pyx_pf_5anuga_9pymetis_4_9metis_ext_partMeshNodal(__pyx_self, __pyx_v_ne, __pyx_v_nn, __pyx_v_elements, __pyx_v_etype, __pyx_v_nparts);
      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_5anuga_9pymetis_4_9metis_ext_partMeshNodal(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_ne, int __pyx_v_nn, PyObject *__pyx_v_elements, int __pyx_v_etype, int __pyx_v_nparts) {
      int __pyx_v_i;
      int __pyx_v_edgecut;
      int __pyx_v_numflag;
      int __pyx_v_malloc_elem_c_arr;
      PyArrayObject *__pyx_v_elem_arr = 0;
      PyArrayObject *__pyx_v_epart_pyarr = 0;
      PyArrayObject *__pyx_v_npart_pyarr = 0;
      npy_intp *__pyx_v_dims;
      __pyx_t_5anuga_9pymetis_4_9metis_ext_idxtype *__pyx_v_elem_c_arr;
      __pyx_t_5anuga_9pymetis_4_9metis_ext_idxtype *__pyx_v_epart;
      __pyx_t_5anuga_9pymetis_4_9metis_ext_idxtype *__pyx_v_npart;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_epart_pyarr;
      __Pyx_Buffer __pyx_pybuffer_epart_pyarr;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_npart_pyarr;
      __Pyx_Buffer __pyx_pybuffer_npart_pyarr;
      PyObject *__pyx_r = NULL;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("partMeshNodal", 0);
      __pyx_pybuffer_epart_pyarr.pybuffer.buf = NULL;
      __pyx_pybuffer_epart_pyarr.refcount = 0;
      __pyx_pybuffernd_epart_pyarr.data = NULL;
      __pyx_pybuffernd_epart_pyarr.rcbuffer = &__pyx_pybuffer_epart_pyarr;
      __pyx_pybuffer_npart_pyarr.pybuffer.buf = NULL;
      __pyx_pybuffer_npart_pyarr.refcount = 0;
      __pyx_pybuffernd_npart_pyarr.data = NULL;
      __pyx_pybuffernd_npart_pyarr.rcbuffer = &__pyx_pybuffer_npart_pyarr;
    /* … */
      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_4);
      __Pyx_XDECREF(__pyx_t_5);
      __Pyx_XDECREF(__pyx_t_6);
      __Pyx_XDECREF(__pyx_t_7);
      __Pyx_XDECREF(__pyx_t_8);
      __Pyx_XDECREF(__pyx_t_9);
      { 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_epart_pyarr.rcbuffer->pybuffer);
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_npart_pyarr.rcbuffer->pybuffer);
      __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
      __Pyx_AddTraceback("anuga.pymetis_4.metis_ext.partMeshNodal", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      goto __pyx_L2;
      __pyx_L0:;
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_epart_pyarr.rcbuffer->pybuffer);
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_npart_pyarr.rcbuffer->pybuffer);
      __pyx_L2:;
      __Pyx_XDECREF((PyObject *)__pyx_v_elem_arr);
      __Pyx_XDECREF((PyObject *)__pyx_v_epart_pyarr);
      __Pyx_XDECREF((PyObject *)__pyx_v_npart_pyarr);
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }
    /* … */
      __pyx_tuple__3 = PyTuple_Pack(16, __pyx_n_s_ne, __pyx_n_s_nn, __pyx_n_s_elements, __pyx_n_s_etype, __pyx_n_s_nparts, __pyx_n_s_i, __pyx_n_s_edgecut, __pyx_n_s_numflag, __pyx_n_s_malloc_elem_c_arr, __pyx_n_s_elem_arr, __pyx_n_s_epart_pyarr, __pyx_n_s_npart_pyarr, __pyx_n_s_dims, __pyx_n_s_elem_c_arr, __pyx_n_s_epart, __pyx_n_s_npart); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 15, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_tuple__3);
      __Pyx_GIVEREF(__pyx_tuple__3);
    /* … */
      __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5anuga_9pymetis_4_9metis_ext_1partMeshNodal, NULL, __pyx_n_s_anuga_pymetis_4_metis_ext); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 15, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_partMeshNodal, __pyx_t_1) < 0) __PYX_ERR(0, 15, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

     16:

     17: 	cdef int i

     18: 	cdef int edgecut

    +19: 	cdef int numflag = 0

      __pyx_v_numflag = 0;

    +20: 	cdef int malloc_elem_c_arr = 0

      __pyx_v_malloc_elem_c_arr = 0;

     21: 	cdef np.ndarray elem_arr

     22: 	cdef np.ndarray[int, ndim=1, mode="c"] epart_pyarr

     23: 	cdef np.ndarray[int, ndim=1, mode="c"] npart_pyarr

     24: 	cdef np.npy_intp* dims

     25:

     26: 	cdef idxtype* elem_c_arr

     27: 	cdef idxtype* epart

     28: 	cdef idxtype* npart

     29:

    +30: 	assert isinstance(elements,list) or isinstance(elements,np.ndarray), "elements must be a list or an array"

      #ifndef CYTHON_WITHOUT_ASSERTIONS
      if (unlikely(!Py_OptimizeFlag)) {
        __pyx_t_2 = PyList_Check(__pyx_v_elements);
        __pyx_t_3 = (__pyx_t_2 != 0);
        if (!__pyx_t_3) {
        } else {
          __pyx_t_1 = __pyx_t_3;
          goto __pyx_L3_bool_binop_done;
        }
        __pyx_t_3 = __Pyx_TypeCheck(__pyx_v_elements, __pyx_ptype_5numpy_ndarray);
        __pyx_t_2 = (__pyx_t_3 != 0);
        __pyx_t_1 = __pyx_t_2;
        __pyx_L3_bool_binop_done:;
        if (unlikely(!__pyx_t_1)) {
          PyErr_SetObject(PyExc_AssertionError, __pyx_kp_s_elements_must_be_a_list_or_an_ar);
          __PYX_ERR(0, 30, __pyx_L1_error)
        }
      }
      #endif

     31:

    +32: 	elem_arr =  np.ascontiguousarray(np.array(elements, dtype=int))

      __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 32, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_ascontiguousarray); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 32, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 32, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_array); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 32, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 32, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_INCREF(__pyx_v_elements);
      __Pyx_GIVEREF(__pyx_v_elements);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_elements);
      __pyx_t_8 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 32, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_dtype, ((PyObject *)(&PyInt_Type))) < 0) __PYX_ERR(0, 32, __pyx_L1_error)
      __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_5, __pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 32, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(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_4 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_8, __pyx_t_9) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_9);
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 32, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 32, __pyx_L1_error)
      __pyx_v_elem_arr = ((PyArrayObject *)__pyx_t_4);
      __pyx_t_4 = 0;

     33:

    +34: 	if elem_arr.dtype == 'int64':

      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_elem_arr), __pyx_n_s_dtype); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 34, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_4, __pyx_n_s_int64, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 34, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_1) {
    /* … */
        goto __pyx_L5;
      }

    +35: 		elem_c_arr = <idxtype* > malloc(elem_arr.shape[0] * sizeof(idxtype))

        __pyx_v_elem_c_arr = ((__pyx_t_5anuga_9pymetis_4_9metis_ext_idxtype *)malloc(((__pyx_v_elem_arr->dimensions[0]) * (sizeof(__pyx_t_5anuga_9pymetis_4_9metis_ext_idxtype)))));

    +36: 		malloc_elem_c_arr = 1

        __pyx_v_malloc_elem_c_arr = 1;

    +37: 		if not(elem_c_arr):

        __pyx_t_1 = ((!(__pyx_v_elem_c_arr != 0)) != 0);
        if (__pyx_t_1) {
    /* … */
        }

    +38: 			return None

          __Pyx_XDECREF(__pyx_r);
          __pyx_r = Py_None; __Pyx_INCREF(Py_None);
          goto __pyx_L0;

    +39: 		for i in xrange(elem_arr.shape[0]):

        __pyx_t_10 = (__pyx_v_elem_arr->dimensions[0]);
        __pyx_t_11 = __pyx_t_10;
        for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) {
          __pyx_v_i = __pyx_t_12;

    +40: 			elem_c_arr[i] = <idxtype> elem_arr[i]

          __pyx_t_4 = __Pyx_GetItemInt(((PyObject *)__pyx_v_elem_arr), __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 0, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 40, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 40, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          (__pyx_v_elem_c_arr[__pyx_v_i]) = ((__pyx_t_5anuga_9pymetis_4_9metis_ext_idxtype)__pyx_t_13);

    +41: 			if elem_c_arr[i] != elem_arr[i]:

          __pyx_t_4 = __Pyx_PyInt_From_int((__pyx_v_elem_c_arr[__pyx_v_i])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 41, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __pyx_t_6 = __Pyx_GetItemInt(((PyObject *)__pyx_v_elem_arr), __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 0, 0, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 41, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_9 = PyObject_RichCompare(__pyx_t_4, __pyx_t_6, Py_NE); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 41, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 41, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          if (__pyx_t_1) {
    /* … */
          }
        }

    +42: 				free(elem_c_arr)

            free(__pyx_v_elem_c_arr);

    +43: 				return None

            __Pyx_XDECREF(__pyx_r);
            __pyx_r = Py_None; __Pyx_INCREF(Py_None);
            goto __pyx_L0;

     44: 	else:

    +45: 		elem_c_arr = <idxtype* > elem_arr.data

      /*else*/ {
        __pyx_v_elem_c_arr = ((__pyx_t_5anuga_9pymetis_4_9metis_ext_idxtype *)__pyx_v_elem_arr->data);
      }
      __pyx_L5:;

     46:

    +47: 	epart = <idxtype* > malloc(ne * sizeof(idxtype))

      __pyx_v_epart = ((__pyx_t_5anuga_9pymetis_4_9metis_ext_idxtype *)malloc((__pyx_v_ne * (sizeof(__pyx_t_5anuga_9pymetis_4_9metis_ext_idxtype)))));

    +48: 	if epart == NULL:

      __pyx_t_1 = ((__pyx_v_epart == NULL) != 0);
      if (__pyx_t_1) {
    /* … */
      }

    +49: 		if malloc_elem_c_arr:

        __pyx_t_1 = (__pyx_v_malloc_elem_c_arr != 0);
        if (__pyx_t_1) {
    /* … */
        }

    +50: 			free(elem_c_arr)

          free(__pyx_v_elem_c_arr);

    +51: 		return None

        __Pyx_XDECREF(__pyx_r);
        __pyx_r = Py_None; __Pyx_INCREF(Py_None);
        goto __pyx_L0;

     52:

    +53: 	npart = <idxtype* > malloc(nn * sizeof(idxtype))

      __pyx_v_npart = ((__pyx_t_5anuga_9pymetis_4_9metis_ext_idxtype *)malloc((__pyx_v_nn * (sizeof(__pyx_t_5anuga_9pymetis_4_9metis_ext_idxtype)))));

    +54: 	if npart == NULL:

      __pyx_t_1 = ((__pyx_v_npart == NULL) != 0);
      if (__pyx_t_1) {
    /* … */
      }

    +55: 		if malloc_elem_c_arr:

        __pyx_t_1 = (__pyx_v_malloc_elem_c_arr != 0);
        if (__pyx_t_1) {
    /* … */
        }

    +56: 			free(elem_c_arr)

          free(__pyx_v_elem_c_arr);

    +57: 		free(epart)

        free(__pyx_v_epart);

    +58: 		return None

        __Pyx_XDECREF(__pyx_r);
        __pyx_r = Py_None; __Pyx_INCREF(Py_None);
        goto __pyx_L0;

     59:

    +60: 	bridge_partMeshNodal(&ne, &nn, elem_c_arr, &etype, &numflag, &nparts, &edgecut, epart, npart)

      bridge_partMeshNodal((&__pyx_v_ne), (&__pyx_v_nn), __pyx_v_elem_c_arr, (&__pyx_v_etype), (&__pyx_v_numflag), (&__pyx_v_nparts), (&__pyx_v_edgecut), __pyx_v_epart, __pyx_v_npart);

     61:

    +62: 	dims = <np.npy_intp* > malloc(2 * sizeof(np.npy_intp))

      __pyx_v_dims = ((npy_intp *)malloc((2 * (sizeof(npy_intp)))));

     63:

    +64: 	dims[0] = ne

      (__pyx_v_dims[0]) = __pyx_v_ne;

    +65: 	epart_pyarr = np.PyArray_SimpleNewFromData(1, dims, np.NPY_INT32, epart)

      __pyx_t_9 = PyArray_SimpleNewFromData(1, __pyx_v_dims, NPY_INT32, __pyx_v_epart); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 65, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      if (!(likely(((__pyx_t_9) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_9, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 65, __pyx_L1_error)
      __pyx_t_14 = ((PyArrayObject *)__pyx_t_9);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_epart_pyarr.rcbuffer->pybuffer);
        __pyx_t_12 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_epart_pyarr.rcbuffer->pybuffer, (PyObject*)__pyx_t_14, &__Pyx_TypeInfo_int, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack);
        if (unlikely(__pyx_t_12 < 0)) {
          PyErr_Fetch(&__pyx_t_15, &__pyx_t_16, &__pyx_t_17);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_epart_pyarr.rcbuffer->pybuffer, (PyObject*)__pyx_v_epart_pyarr, &__Pyx_TypeInfo_int, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_15); Py_XDECREF(__pyx_t_16); Py_XDECREF(__pyx_t_17);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_15, __pyx_t_16, __pyx_t_17);
          }
          __pyx_t_15 = __pyx_t_16 = __pyx_t_17 = 0;
        }
        __pyx_pybuffernd_epart_pyarr.diminfo[0].strides = __pyx_pybuffernd_epart_pyarr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_epart_pyarr.diminfo[0].shape = __pyx_pybuffernd_epart_pyarr.rcbuffer->pybuffer.shape[0];
        if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 65, __pyx_L1_error)
      }
      __pyx_t_14 = 0;
      __pyx_v_epart_pyarr = ((PyArrayObject *)__pyx_t_9);
      __pyx_t_9 = 0;

     66:

    +67: 	dims[0] = nn

      (__pyx_v_dims[0]) = __pyx_v_nn;

    +68: 	npart_pyarr = np.PyArray_SimpleNewFromData(1, dims, np.NPY_INT32, npart)

      __pyx_t_9 = PyArray_SimpleNewFromData(1, __pyx_v_dims, NPY_INT32, __pyx_v_npart); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 68, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      if (!(likely(((__pyx_t_9) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_9, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 68, __pyx_L1_error)
      __pyx_t_18 = ((PyArrayObject *)__pyx_t_9);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_npart_pyarr.rcbuffer->pybuffer);
        __pyx_t_12 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_npart_pyarr.rcbuffer->pybuffer, (PyObject*)__pyx_t_18, &__Pyx_TypeInfo_int, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack);
        if (unlikely(__pyx_t_12 < 0)) {
          PyErr_Fetch(&__pyx_t_17, &__pyx_t_16, &__pyx_t_15);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_npart_pyarr.rcbuffer->pybuffer, (PyObject*)__pyx_v_npart_pyarr, &__Pyx_TypeInfo_int, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_17); Py_XDECREF(__pyx_t_16); Py_XDECREF(__pyx_t_15);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_17, __pyx_t_16, __pyx_t_15);
          }
          __pyx_t_17 = __pyx_t_16 = __pyx_t_15 = 0;
        }
        __pyx_pybuffernd_npart_pyarr.diminfo[0].strides = __pyx_pybuffernd_npart_pyarr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_npart_pyarr.diminfo[0].shape = __pyx_pybuffernd_npart_pyarr.rcbuffer->pybuffer.shape[0];
        if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 68, __pyx_L1_error)
      }
      __pyx_t_18 = 0;
      __pyx_v_npart_pyarr = ((PyArrayObject *)__pyx_t_9);
      __pyx_t_9 = 0;

     69:

    +70: 	if malloc_elem_c_arr:

      __pyx_t_1 = (__pyx_v_malloc_elem_c_arr != 0);
      if (__pyx_t_1) {
    /* … */
      }

    +71: 		free(elem_c_arr)

        free(__pyx_v_elem_c_arr);

     72:

    +73: 	free(dims)

      free(__pyx_v_dims);

     74:

    +75: 	return edgecut, np.ascontiguousarray(epart_pyarr), np.ascontiguousarray(npart_pyarr)

      __Pyx_XDECREF(__pyx_r);
      __pyx_t_9 = __Pyx_PyInt_From_int(__pyx_v_edgecut); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 75, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 75, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_ascontiguousarray); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 75, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
        __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_8);
        if (likely(__pyx_t_4)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
          __Pyx_INCREF(__pyx_t_4);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_8, function);
        }
      }
      __pyx_t_6 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_4, ((PyObject *)__pyx_v_epart_pyarr)) : __Pyx_PyObject_CallOneArg(__pyx_t_8, ((PyObject *)__pyx_v_epart_pyarr));
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 75, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 75, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_ascontiguousarray); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 75, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
        __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
        if (likely(__pyx_t_4)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_4);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_5, function);
        }
      }
      __pyx_t_8 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_4, ((PyObject *)__pyx_v_npart_pyarr)) : __Pyx_PyObject_CallOneArg(__pyx_t_5, ((PyObject *)__pyx_v_npart_pyarr));
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 75, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 75, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_9);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_9);
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_8);
      PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_8);
      __pyx_t_9 = 0;
      __pyx_t_6 = 0;
      __pyx_t_8 = 0;
      __pyx_r = __pyx_t_5;
      __pyx_t_5 = 0;
      goto __pyx_L0;

     76: