Cython: pmesh2domain_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: pmesh2domain_ext.c

    +001: #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;

     002: import cython

     003: from cython cimport typeof

     004:

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

    +006: import numpy as np

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

     007: cimport numpy as np

     008:

     009: # declare the interface to the C code

     010: cdef extern from "pmesh2domain.c":

     011: 	# If the structs are defined using typedef in the C code, we have to use ctypedef here.

     012: 	# Otherwise, it will lead to weird errors.

     013: 	ctypedef struct UT_hash_handle:

     014: 		pass

     015: 	ctypedef struct segment_key_t:

     016: 		int i

     017: 		int j

     018: 	ctypedef struct segment_t:

     019: 		segment_key_t key

     020: 		int vol_id

     021: 		int edge_id

     022: 		UT_hash_handle hh

     023: 	void add_segment(segment_key_t key, int vol_id, int edge_id)

     024: 	segment_t* find_segment(segment_key_t key)

     025: 	void delete_segment(segment_t* segment)

     026: 	void delete_segment_all()

     027: 	void print_segments()

     028: 	int vol_id_sort(segment_t* a, segment_t* b)

     029: 	int key_sort(segment_t* a, segment_t* b)

     030: 	void sort_by_vol_id()

     031: 	void sort_by_key()

     032:

    +033: def build_boundary_dictionary(np.ndarray[long, ndim=2, mode="c"] triangles not None,\

    /* Python wrapper */
    static PyObject *__pyx_pw_5anuga_26abstract_2d_finite_volumes_16pmesh2domain_ext_1build_boundary_dictionary(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
    static char __pyx_doc_5anuga_26abstract_2d_finite_volumes_16pmesh2domain_ext_build_boundary_dictionary[] = "\n\tUpdate neighbours array using triangle\n\n\tN is number of nodes (vertices)\n\ttriangle nodes defining triangles\n\tneighbour across edge_id\n\tneighbour_segments edge_id of segment in neighbouring triangle\n\tnumber_of_boundaries\n\t";
    static PyMethodDef __pyx_mdef_5anuga_26abstract_2d_finite_volumes_16pmesh2domain_ext_1build_boundary_dictionary = {"build_boundary_dictionary", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5anuga_26abstract_2d_finite_volumes_16pmesh2domain_ext_1build_boundary_dictionary, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5anuga_26abstract_2d_finite_volumes_16pmesh2domain_ext_build_boundary_dictionary};
    static PyObject *__pyx_pw_5anuga_26abstract_2d_finite_volumes_16pmesh2domain_ext_1build_boundary_dictionary(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
      PyArrayObject *__pyx_v_triangles = 0;
      PyArrayObject *__pyx_v_segments = 0;
      PyObject *__pyx_v_segment_tags = 0;
      PyObject *__pyx_v_tag_dict = 0;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("build_boundary_dictionary (wrapper)", 0);
      {
        static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_triangles,&__pyx_n_s_segments,&__pyx_n_s_segment_tags,&__pyx_n_s_tag_dict,0};
        PyObject* values[4] = {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  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_triangles)) != 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_segments)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("build_boundary_dictionary", 1, 4, 4, 1); __PYX_ERR(0, 33, __pyx_L3_error)
            }
            CYTHON_FALLTHROUGH;
            case  2:
            if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_segment_tags)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("build_boundary_dictionary", 1, 4, 4, 2); __PYX_ERR(0, 33, __pyx_L3_error)
            }
            CYTHON_FALLTHROUGH;
            case  3:
            if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_tag_dict)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("build_boundary_dictionary", 1, 4, 4, 3); __PYX_ERR(0, 33, __pyx_L3_error)
            }
          }
          if (unlikely(kw_args > 0)) {
            if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "build_boundary_dictionary") < 0)) __PYX_ERR(0, 33, __pyx_L3_error)
          }
        } else if (PyTuple_GET_SIZE(__pyx_args) != 4) {
          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);
        }
        __pyx_v_triangles = ((PyArrayObject *)values[0]);
        __pyx_v_segments = ((PyArrayObject *)values[1]);
        __pyx_v_segment_tags = ((PyObject*)values[2]);
        __pyx_v_tag_dict = ((PyObject*)values[3]);
      }
      goto __pyx_L4_argument_unpacking_done;
      __pyx_L5_argtuple_error:;
      __Pyx_RaiseArgtupleInvalid("build_boundary_dictionary", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 33, __pyx_L3_error)
      __pyx_L3_error:;
      __Pyx_AddTraceback("anuga.abstract_2d_finite_volumes.pmesh2domain_ext.build_boundary_dictionary", __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, 33, __pyx_L1_error)
      if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_segments), __pyx_ptype_5numpy_ndarray, 0, "segments", 0))) __PYX_ERR(0, 34, __pyx_L1_error)
      if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_segment_tags), (&PyList_Type), 1, "segment_tags", 1))) __PYX_ERR(0, 35, __pyx_L1_error)
      if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_tag_dict), (&PyDict_Type), 1, "tag_dict", 1))) __PYX_ERR(0, 36, __pyx_L1_error)
      __pyx_r = __pyx_pf_5anuga_26abstract_2d_finite_volumes_16pmesh2domain_ext_build_boundary_dictionary(__pyx_self, __pyx_v_triangles, __pyx_v_segments, __pyx_v_segment_tags, __pyx_v_tag_dict);
      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_16pmesh2domain_ext_build_boundary_dictionary(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_triangles, PyArrayObject *__pyx_v_segments, PyObject *__pyx_v_segment_tags, PyObject *__pyx_v_tag_dict) {
      int __pyx_v_M;
      int __pyx_v_N;
      int __pyx_v_err;
      int __pyx_v_k;
      int __pyx_v_a;
      int __pyx_v_b;
      int __pyx_v_c;
      int __pyx_v_vol_id;
      int __pyx_v_edge_id;
      int __pyx_v_len_tag;
      char *__pyx_v_string;
      segment_t *__pyx_v_s;
      segment_key_t __pyx_v_key;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_segments;
      __Pyx_Buffer __pyx_pybuffer_segments;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_triangles;
      __Pyx_Buffer __pyx_pybuffer_triangles;
      PyObject *__pyx_r = NULL;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("build_boundary_dictionary", 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_segments.pybuffer.buf = NULL;
      __pyx_pybuffer_segments.refcount = 0;
      __pyx_pybuffernd_segments.data = NULL;
      __pyx_pybuffernd_segments.rcbuffer = &__pyx_pybuffer_segments;
      {
        __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, 33, __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_segments.rcbuffer->pybuffer, (PyObject*)__pyx_v_segments, &__Pyx_TypeInfo_long, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 33, __pyx_L1_error)
      }
      __pyx_pybuffernd_segments.diminfo[0].strides = __pyx_pybuffernd_segments.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_segments.diminfo[0].shape = __pyx_pybuffernd_segments.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_segments.diminfo[1].strides = __pyx_pybuffernd_segments.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_segments.diminfo[1].shape = __pyx_pybuffernd_segments.rcbuffer->pybuffer.shape[1];
    /* … */
      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_11);
      __Pyx_XDECREF(__pyx_t_12);
      __Pyx_XDECREF(__pyx_t_13);
      __Pyx_XDECREF(__pyx_t_14);
      { 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_segments.rcbuffer->pybuffer);
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_triangles.rcbuffer->pybuffer);
      __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
      __Pyx_AddTraceback("anuga.abstract_2d_finite_volumes.pmesh2domain_ext.build_boundary_dictionary", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      goto __pyx_L2;
      __pyx_L0:;
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_segments.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(17, __pyx_n_s_triangles, __pyx_n_s_segments, __pyx_n_s_segment_tags, __pyx_n_s_tag_dict, __pyx_n_s_M, __pyx_n_s_N, __pyx_n_s_err, __pyx_n_s_k, __pyx_n_s_a, __pyx_n_s_b, __pyx_n_s_c, __pyx_n_s_vol_id, __pyx_n_s_edge_id, __pyx_n_s_len_tag, __pyx_n_s_string, __pyx_n_s_s, __pyx_n_s_key); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 33, __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_16pmesh2domain_ext_1build_boundary_dictionary, NULL, __pyx_n_s_anuga_abstract_2d_finite_volumes_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 33, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_build_boundary_dictionary, __pyx_t_1) < 0) __PYX_ERR(0, 33, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_codeobj__4 = (PyObject*)__Pyx_PyCode_New(4, 0, 17, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__3, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_anuga_abstract_2d_finite_volumes, __pyx_n_s_build_boundary_dictionary, 33, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__4)) __PYX_ERR(0, 33, __pyx_L1_error)

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

     035: 							list segment_tags,\

     036: 							dict tag_dict):

     037: 	"""

     038: 	Update neighbours array using triangle

     039:

     040: 	N is number of nodes (vertices)

     041: 	triangle nodes defining triangles

     042: 	neighbour across edge_id

     043: 	neighbour_segments edge_id of segment in neighbouring triangle

     044: 	number_of_boundaries

     045: 	"""

     046:

     047: 	cdef int M, N

    +048: 	cdef int err = 0

      __pyx_v_err = 0;

     049: 	cdef int k, a, b, c, vol_id, edge_id, len_tag

     050:

     051: 	cdef char* string

     052: 	cdef segment_t* s

     053: 	cdef segment_key_t key

     054:

    +055: 	M = triangles.shape[0]

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

    +056: 	N = segments.shape[0]

      __pyx_v_N = (__pyx_v_segments->dimensions[0]);

     057:

     058: 	# Step 1: Populate hashtable. We use a key based on the node_ids of the two nodes defining the segment

    +059: 	for k in xrange(M):

      __pyx_t_1 = __pyx_v_M;
      __pyx_t_2 = __pyx_t_1;
      for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
        __pyx_v_k = __pyx_t_3;

     060:

    +061: 		a = triangles[k,0]

        __pyx_t_4 = __pyx_v_k;
        __pyx_t_5 = 0;
        __pyx_v_a = (*__Pyx_BufPtrCContig2d(long *, __pyx_pybuffernd_triangles.rcbuffer->pybuffer.buf, __pyx_t_4, __pyx_pybuffernd_triangles.diminfo[0].strides, __pyx_t_5, __pyx_pybuffernd_triangles.diminfo[1].strides));

    +062: 		b = triangles[k,1]

        __pyx_t_5 = __pyx_v_k;
        __pyx_t_4 = 1;
        __pyx_v_b = (*__Pyx_BufPtrCContig2d(long *, __pyx_pybuffernd_triangles.rcbuffer->pybuffer.buf, __pyx_t_5, __pyx_pybuffernd_triangles.diminfo[0].strides, __pyx_t_4, __pyx_pybuffernd_triangles.diminfo[1].strides));

    +063: 		c = triangles[k,2]

        __pyx_t_4 = __pyx_v_k;
        __pyx_t_5 = 2;
        __pyx_v_c = (*__Pyx_BufPtrCContig2d(long *, __pyx_pybuffernd_triangles.rcbuffer->pybuffer.buf, __pyx_t_4, __pyx_pybuffernd_triangles.diminfo[0].strides, __pyx_t_5, __pyx_pybuffernd_triangles.diminfo[1].strides));

     064:

     065: 		# Add segment a,b to hashtable

    +066: 		key.i = a

        __pyx_v_key.i = __pyx_v_a;

    +067: 		key.j = b

        __pyx_v_key.j = __pyx_v_b;

    +068: 		vol_id = k

        __pyx_v_vol_id = __pyx_v_k;

    +069: 		edge_id = 2

        __pyx_v_edge_id = 2;

     070:

    +071: 		s = find_segment(key)

        __pyx_v_s = find_segment(__pyx_v_key);

     072:

    +073: 		if s:

        __pyx_t_6 = (__pyx_v_s != 0);
        if (__pyx_t_6) {
    /* … */
        }

    +074: 			err = 1

          __pyx_v_err = 1;

    +075: 			break

          goto __pyx_L4_break;

     076:

    +077: 		add_segment(key, vol_id, edge_id)

        add_segment(__pyx_v_key, __pyx_v_vol_id, __pyx_v_edge_id);

     078:

     079: 		# Add segment b,c to hashtable

    +080: 		key.i = b

        __pyx_v_key.i = __pyx_v_b;

    +081: 		key.j = c

        __pyx_v_key.j = __pyx_v_c;

    +082: 		vol_id = k

        __pyx_v_vol_id = __pyx_v_k;

    +083: 		edge_id = 0

        __pyx_v_edge_id = 0;

     084:

    +085: 		s = find_segment(key)

        __pyx_v_s = find_segment(__pyx_v_key);

     086:

    +087: 		if s:

        __pyx_t_6 = (__pyx_v_s != 0);
        if (__pyx_t_6) {
    /* … */
        }

    +088: 			err = 1

          __pyx_v_err = 1;

    +089: 			break

          goto __pyx_L4_break;

     090:

    +091: 		add_segment(key, vol_id, edge_id)

        add_segment(__pyx_v_key, __pyx_v_vol_id, __pyx_v_edge_id);

     092:

     093: 		# Add segment c,a to hashtable

    +094: 		key.i = c

        __pyx_v_key.i = __pyx_v_c;

    +095: 		key.j = a

        __pyx_v_key.j = __pyx_v_a;

    +096: 		vol_id = k

        __pyx_v_vol_id = __pyx_v_k;

    +097: 		edge_id = 1

        __pyx_v_edge_id = 1;

     098:

    +099: 		s = find_segment(key)

        __pyx_v_s = find_segment(__pyx_v_key);

     100:

    +101: 		if s:

        __pyx_t_6 = (__pyx_v_s != 0);
        if (__pyx_t_6) {
    /* … */
        }

    +102: 			err = 1

          __pyx_v_err = 1;

    +103: 			break

          goto __pyx_L4_break;

     104:

    +105: 		add_segment(key, vol_id, edge_id)

        add_segment(__pyx_v_key, __pyx_v_vol_id, __pyx_v_edge_id);
      }
      __pyx_L4_break:;

     106:

    +107: 	if err == 1:

      __pyx_t_6 = ((__pyx_v_err == 1) != 0);
      if (__pyx_t_6) {
    /* … */
      }

    +108: 		delete_segment_all()

        delete_segment_all();

     109:

    +110: 	assert err != 1, "pmesh2domain.c: build_boundary_dictionary Duplicate segments"

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

     111:

     112: 	# Step 2: Go through segments. Those with null tags are added to tag_dict

    +113: 	for k in xrange(N):

      __pyx_t_1 = __pyx_v_N;
      __pyx_t_2 = __pyx_t_1;
      for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
        __pyx_v_k = __pyx_t_3;

     114:

    +115: 		a = segments[k,0]

        __pyx_t_5 = __pyx_v_k;
        __pyx_t_4 = 0;
        __pyx_v_a = (*__Pyx_BufPtrCContig2d(long *, __pyx_pybuffernd_segments.rcbuffer->pybuffer.buf, __pyx_t_5, __pyx_pybuffernd_segments.diminfo[0].strides, __pyx_t_4, __pyx_pybuffernd_segments.diminfo[1].strides));

    +116: 		b = segments[k,1]

        __pyx_t_4 = __pyx_v_k;
        __pyx_t_5 = 1;
        __pyx_v_b = (*__Pyx_BufPtrCContig2d(long *, __pyx_pybuffernd_segments.rcbuffer->pybuffer.buf, __pyx_t_4, __pyx_pybuffernd_segments.diminfo[0].strides, __pyx_t_5, __pyx_pybuffernd_segments.diminfo[1].strides));

     117:

    +118: 		string = segment_tags[k]

        if (unlikely(__pyx_v_segment_tags == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
          __PYX_ERR(0, 118, __pyx_L1_error)
        }
        __pyx_t_7 = __Pyx_PyObject_AsWritableString(PyList_GET_ITEM(__pyx_v_segment_tags, __pyx_v_k)); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) __PYX_ERR(0, 118, __pyx_L1_error)
        __pyx_v_string = __pyx_t_7;

    +119: 		len_tag = len(string)

        __pyx_t_8 = strlen(__pyx_v_string);
        __pyx_v_len_tag = __pyx_t_8;

     120:

    +121: 		key.i = a

        __pyx_v_key.i = __pyx_v_a;

    +122: 		key.j = b

        __pyx_v_key.j = __pyx_v_b;

    +123: 		s = find_segment(key)

        __pyx_v_s = find_segment(__pyx_v_key);

     124:

    +125: 		if s and len_tag > 0:

        __pyx_t_9 = (__pyx_v_s != 0);
        if (__pyx_t_9) {
        } else {
          __pyx_t_6 = __pyx_t_9;
          goto __pyx_L12_bool_binop_done;
        }
        __pyx_t_9 = ((__pyx_v_len_tag > 0) != 0);
        __pyx_t_6 = __pyx_t_9;
        __pyx_L12_bool_binop_done:;
        if (__pyx_t_6) {
    /* … */
        }

    +126: 			vol_id = s.vol_id

          __pyx_t_10 = __pyx_v_s->vol_id;
          __pyx_v_vol_id = __pyx_t_10;

    +127: 			edge_id = s.edge_id

          __pyx_t_10 = __pyx_v_s->edge_id;
          __pyx_v_edge_id = __pyx_t_10;

    +128: 			tag_dict[(vol_id, edge_id)] = string

          __pyx_t_11 = __Pyx_PyBytes_FromString(__pyx_v_string); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 128, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_11);
          if (unlikely(__pyx_v_tag_dict == Py_None)) {
            PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
            __PYX_ERR(0, 128, __pyx_L1_error)
          }
          __pyx_t_12 = __Pyx_PyInt_From_int(__pyx_v_vol_id); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 128, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_12);
          __pyx_t_13 = __Pyx_PyInt_From_int(__pyx_v_edge_id); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 128, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_13);
          __pyx_t_14 = PyTuple_New(2); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 128, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_14);
          __Pyx_GIVEREF(__pyx_t_12);
          PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_12);
          __Pyx_GIVEREF(__pyx_t_13);
          PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_t_13);
          __pyx_t_12 = 0;
          __pyx_t_13 = 0;
          if (unlikely(PyDict_SetItem(__pyx_v_tag_dict, __pyx_t_14, __pyx_t_11) < 0)) __PYX_ERR(0, 128, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

     129:

    +130: 		key.i = b

        __pyx_v_key.i = __pyx_v_b;

    +131: 		key.j = a

        __pyx_v_key.j = __pyx_v_a;

    +132: 		s = find_segment(key)

        __pyx_v_s = find_segment(__pyx_v_key);

     133:

    +134: 		if s and len_tag > 0:

        __pyx_t_9 = (__pyx_v_s != 0);
        if (__pyx_t_9) {
        } else {
          __pyx_t_6 = __pyx_t_9;
          goto __pyx_L15_bool_binop_done;
        }
        __pyx_t_9 = ((__pyx_v_len_tag > 0) != 0);
        __pyx_t_6 = __pyx_t_9;
        __pyx_L15_bool_binop_done:;
        if (__pyx_t_6) {
    /* … */
        }
      }

    +135: 			vol_id = s.vol_id

          __pyx_t_10 = __pyx_v_s->vol_id;
          __pyx_v_vol_id = __pyx_t_10;

    +136: 			edge_id = s.edge_id

          __pyx_t_10 = __pyx_v_s->edge_id;
          __pyx_v_edge_id = __pyx_t_10;

    +137: 			tag_dict[(vol_id, edge_id)] = string

          __pyx_t_11 = __Pyx_PyBytes_FromString(__pyx_v_string); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 137, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_11);
          if (unlikely(__pyx_v_tag_dict == Py_None)) {
            PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
            __PYX_ERR(0, 137, __pyx_L1_error)
          }
          __pyx_t_14 = __Pyx_PyInt_From_int(__pyx_v_vol_id); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 137, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_14);
          __pyx_t_13 = __Pyx_PyInt_From_int(__pyx_v_edge_id); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 137, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_13);
          __pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 137, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_12);
          __Pyx_GIVEREF(__pyx_t_14);
          PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_14);
          __Pyx_GIVEREF(__pyx_t_13);
          PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_t_13);
          __pyx_t_14 = 0;
          __pyx_t_13 = 0;
          if (unlikely(PyDict_SetItem(__pyx_v_tag_dict, __pyx_t_12, __pyx_t_11) < 0)) __PYX_ERR(0, 137, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

     138:

    +139: 	delete_segment_all()

      delete_segment_all();

    +140: 	return tag_dict

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

     141:

    +142: def build_sides_dictionary(np.ndarray[long, ndim=2, mode="c"] triangles not None, dict sides):

    /* Python wrapper */
    static PyObject *__pyx_pw_5anuga_26abstract_2d_finite_volumes_16pmesh2domain_ext_3build_sides_dictionary(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
    static PyMethodDef __pyx_mdef_5anuga_26abstract_2d_finite_volumes_16pmesh2domain_ext_3build_sides_dictionary = {"build_sides_dictionary", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5anuga_26abstract_2d_finite_volumes_16pmesh2domain_ext_3build_sides_dictionary, METH_VARARGS|METH_KEYWORDS, 0};
    static PyObject *__pyx_pw_5anuga_26abstract_2d_finite_volumes_16pmesh2domain_ext_3build_sides_dictionary(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
      PyArrayObject *__pyx_v_triangles = 0;
      PyObject *__pyx_v_sides = 0;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("build_sides_dictionary (wrapper)", 0);
      {
        static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_triangles,&__pyx_n_s_sides,0};
        PyObject* values[2] = {0,0};
        if (unlikely(__pyx_kwds)) {
          Py_ssize_t kw_args;
          const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
          switch (pos_args) {
            case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
            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_triangles)) != 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_sides)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("build_sides_dictionary", 1, 2, 2, 1); __PYX_ERR(0, 142, __pyx_L3_error)
            }
          }
          if (unlikely(kw_args > 0)) {
            if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "build_sides_dictionary") < 0)) __PYX_ERR(0, 142, __pyx_L3_error)
          }
        } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
          goto __pyx_L5_argtuple_error;
        } else {
          values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
          values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        }
        __pyx_v_triangles = ((PyArrayObject *)values[0]);
        __pyx_v_sides = ((PyObject*)values[1]);
      }
      goto __pyx_L4_argument_unpacking_done;
      __pyx_L5_argtuple_error:;
      __Pyx_RaiseArgtupleInvalid("build_sides_dictionary", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 142, __pyx_L3_error)
      __pyx_L3_error:;
      __Pyx_AddTraceback("anuga.abstract_2d_finite_volumes.pmesh2domain_ext.build_sides_dictionary", __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, 142, __pyx_L1_error)
      if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_sides), (&PyDict_Type), 1, "sides", 1))) __PYX_ERR(0, 142, __pyx_L1_error)
      __pyx_r = __pyx_pf_5anuga_26abstract_2d_finite_volumes_16pmesh2domain_ext_2build_sides_dictionary(__pyx_self, __pyx_v_triangles, __pyx_v_sides);
      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_16pmesh2domain_ext_2build_sides_dictionary(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_triangles, PyObject *__pyx_v_sides) {
      long __pyx_v_i;
      long __pyx_v_numTriangle;
      long __pyx_v_a;
      long __pyx_v_b;
      long __pyx_v_c;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_triangles;
      __Pyx_Buffer __pyx_pybuffer_triangles;
      PyObject *__pyx_r = NULL;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("build_sides_dictionary", 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_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, 142, __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];
    /* … */
      /* function exit code */
      __pyx_L1_error:;
      __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_triangles.rcbuffer->pybuffer);
      __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
      __Pyx_AddTraceback("anuga.abstract_2d_finite_volumes.pmesh2domain_ext.build_sides_dictionary", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      goto __pyx_L2;
      __pyx_L0:;
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_triangles.rcbuffer->pybuffer);
      __pyx_L2:;
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }
    /* … */
      __pyx_tuple__5 = PyTuple_Pack(7, __pyx_n_s_triangles, __pyx_n_s_sides, __pyx_n_s_i, __pyx_n_s_numTriangle, __pyx_n_s_a, __pyx_n_s_b, __pyx_n_s_c); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(0, 142, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_tuple__5);
      __Pyx_GIVEREF(__pyx_tuple__5);
    /* … */
      __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5anuga_26abstract_2d_finite_volumes_16pmesh2domain_ext_3build_sides_dictionary, NULL, __pyx_n_s_anuga_abstract_2d_finite_volumes_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 142, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_build_sides_dictionary, __pyx_t_1) < 0) __PYX_ERR(0, 142, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

     143:

     144: 	cdef long i, numTriangle, a, b, c

     145:

    +146: 	numTriangle = triangles.shape[0]

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

     147:

    +148: 	for i in xrange(numTriangle):

      __pyx_t_1 = __pyx_v_numTriangle;
      __pyx_t_2 = __pyx_t_1;
      for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
        __pyx_v_i = __pyx_t_3;

     149:

    +150: 		a = triangles[i,0]

        __pyx_t_4 = __pyx_v_i;
        __pyx_t_5 = 0;
        __pyx_v_a = (*__Pyx_BufPtrCContig2d(long *, __pyx_pybuffernd_triangles.rcbuffer->pybuffer.buf, __pyx_t_4, __pyx_pybuffernd_triangles.diminfo[0].strides, __pyx_t_5, __pyx_pybuffernd_triangles.diminfo[1].strides));

    +151: 		b = triangles[i,1]

        __pyx_t_5 = __pyx_v_i;
        __pyx_t_4 = 1;
        __pyx_v_b = (*__Pyx_BufPtrCContig2d(long *, __pyx_pybuffernd_triangles.rcbuffer->pybuffer.buf, __pyx_t_5, __pyx_pybuffernd_triangles.diminfo[0].strides, __pyx_t_4, __pyx_pybuffernd_triangles.diminfo[1].strides));

    +152: 		c = triangles[i,2]

        __pyx_t_4 = __pyx_v_i;
        __pyx_t_5 = 2;
        __pyx_v_c = (*__Pyx_BufPtrCContig2d(long *, __pyx_pybuffernd_triangles.rcbuffer->pybuffer.buf, __pyx_t_4, __pyx_pybuffernd_triangles.diminfo[0].strides, __pyx_t_5, __pyx_pybuffernd_triangles.diminfo[1].strides));

     153:

    +154: 		sides[(a,b)] = 3*i + 2 # sides[a,b] = (id, 2) #(id, face)

        __pyx_t_6 = __Pyx_PyInt_From_long(((3 * __pyx_v_i) + 2)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 154, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        if (unlikely(__pyx_v_sides == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
          __PYX_ERR(0, 154, __pyx_L1_error)
        }
        __pyx_t_7 = __Pyx_PyInt_From_long(__pyx_v_a); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 154, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_8 = __Pyx_PyInt_From_long(__pyx_v_b); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 154, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 154, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_GIVEREF(__pyx_t_7);
        PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7);
        __Pyx_GIVEREF(__pyx_t_8);
        PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_8);
        __pyx_t_7 = 0;
        __pyx_t_8 = 0;
        if (unlikely(PyDict_SetItem(__pyx_v_sides, __pyx_t_9, __pyx_t_6) < 0)) __PYX_ERR(0, 154, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

    +155: 		sides[(b,c)] = 3*i + 0 # sides[b,c] = (id, 0) #(id, face)

        __pyx_t_6 = __Pyx_PyInt_From_long(((3 * __pyx_v_i) + 0)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 155, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        if (unlikely(__pyx_v_sides == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
          __PYX_ERR(0, 155, __pyx_L1_error)
        }
        __pyx_t_9 = __Pyx_PyInt_From_long(__pyx_v_b); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 155, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_8 = __Pyx_PyInt_From_long(__pyx_v_c); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 155, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 155, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_GIVEREF(__pyx_t_9);
        PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_9);
        __Pyx_GIVEREF(__pyx_t_8);
        PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_8);
        __pyx_t_9 = 0;
        __pyx_t_8 = 0;
        if (unlikely(PyDict_SetItem(__pyx_v_sides, __pyx_t_7, __pyx_t_6) < 0)) __PYX_ERR(0, 155, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

    +156: 		sides[(c,a)] = 3*i + 1 # sides[c,a] = (id, 1) #(id, face)

        __pyx_t_6 = __Pyx_PyInt_From_long(((3 * __pyx_v_i) + 1)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 156, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        if (unlikely(__pyx_v_sides == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
          __PYX_ERR(0, 156, __pyx_L1_error)
        }
        __pyx_t_7 = __Pyx_PyInt_From_long(__pyx_v_c); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 156, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_8 = __Pyx_PyInt_From_long(__pyx_v_a); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 156, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 156, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_GIVEREF(__pyx_t_7);
        PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7);
        __Pyx_GIVEREF(__pyx_t_8);
        PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_8);
        __pyx_t_7 = 0;
        __pyx_t_8 = 0;
        if (unlikely(PyDict_SetItem(__pyx_v_sides, __pyx_t_9, __pyx_t_6) < 0)) __PYX_ERR(0, 156, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      }

     157:

    +158: 	return sides

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

     159:

     160:

     161:

     162:

     163:

     164:

     165:

     166:

     167:

     168: