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

     004: from cpython.pycapsule cimport *

     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: # declare the interface to the C code

     009: cdef extern from "fitsmooth.c":

     010: 	ctypedef struct quad_tree:

     011: 		double xmin, xmax, ymin, ymax

     012: 		int count

     013: 		quad_tree* parent

     014: 		quad_tree* q[4]

     015: 		triangle* leaves

     016: 		triangle* end_leaves

     017: 	ctypedef struct UT_hash_handle:

     018: 		pass

     019: 	ctypedef struct edge_key_t:

     020: 		int i

     021: 		int j

     022: 	ctypedef struct edge_t:

     023: 		edge_key_t key

     024: 		double entry

     025: 		UT_hash_handle hh

     026: 	ctypedef struct sparse_dok:

     027: 		edge_t* edgetable

     028: 		int num_entries

     029: 		int num_rows

     030: 	ctypedef struct triangle:

     031: 		double x1, y1

     032: 		double x2, y2

     033: 		double x3, y3

     034: 		int index

     035: 		double nx1, ny1

     036: 		double nx2, ny2

     037: 		double nx3, ny3

     038: 		triangle* next

     039: 	ctypedef struct sparse_csr:

     040: 		double* data

     041: 		int* colind

     042: 		int* row_ptr

     043: 		int num_rows

     044: 		int num_entries

     045: 	void delete_quad_tree(quad_tree* tree)

     046: 	quad_tree* _build_quad_tree(int n, long* triangles, double* vertex_coordinates, double* extents)

     047: 	void delete_dok_matrix(sparse_dok* mat)

     048: 	sparse_dok* make_dok()

     049: 	int _build_smoothing_matrix(int n, long* triangles, double* areas, double* vertex_coordinates, int* strides, sparse_dok* smoothing_mat)

     050: 	int _build_matrix_AtA_Atz_points(int N, long* triangles, double* point_coordinates, double* point_values, int zdims, int npts, sparse_dok* AtA, double** Atz, quad_tree* quadtree)

     051: 	void _combine_partial_AtA_Atz(sparse_dok* dok_AtA1, sparse_dok* dok_AtA2, double* Atz1, double* Atz2, int n, int zdim)

     052: 	triangle* search(quad_tree* node ,double xp, double yp)

     053: 	double* calculate_sigma(triangle* T, double x, double y)

     054: 	int quad_tree_node_count(quad_tree* tree)

     055: 	int get_dok_rows(sparse_dok* dok);

     056: 	edge_t* find_dok_entry(sparse_dok* edgetable, edge_key_t key)

     057: 	void add_sparse_dok(sparse_dok* dok1, double mult1, sparse_dok* dok2, double mult2)

     058: 	sparse_csr* make_csr()

     059: 	void delete_csr_matrix(sparse_csr* mat)

     060: 	void convert_to_csr_ptr(sparse_csr* new_csr, sparse_dok* hashtable)

     061:

    +062: cdef delete_quad_tree_cap(object cap):

    static PyObject *__pyx_f_5anuga_15fit_interpolate_9fitsmooth_delete_quad_tree_cap(PyObject *__pyx_v_cap) {
      quad_tree *__pyx_v_kill;
      PyObject *__pyx_r = NULL;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("delete_quad_tree_cap", 0);
    /* … */
      /* function exit code */
      __pyx_r = Py_None; __Pyx_INCREF(Py_None);
      goto __pyx_L0;
      __pyx_L1_error:;
      __Pyx_AddTraceback("anuga.fit_interpolate.fitsmooth.delete_quad_tree_cap", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = 0;
      __pyx_L0:;
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    +063: 	kill = <quad_tree* > PyCapsule_GetPointer(cap, "quad tree")

      __pyx_t_1 = PyCapsule_GetPointer(__pyx_v_cap, ((char const *)"quad tree")); if (unlikely(__pyx_t_1 == ((void *)NULL) && PyErr_Occurred())) __PYX_ERR(0, 63, __pyx_L1_error)
      __pyx_v_kill = ((quad_tree *)__pyx_t_1);

    +064: 	if kill != NULL:

      __pyx_t_2 = ((__pyx_v_kill != NULL) != 0);
      if (__pyx_t_2) {
    /* … */
      }

    +065: 		delete_quad_tree(kill)

        delete_quad_tree(__pyx_v_kill);

     066:

    +067: cdef delete_dok_cap(object cap):

    static PyObject *__pyx_f_5anuga_15fit_interpolate_9fitsmooth_delete_dok_cap(PyObject *__pyx_v_cap) {
      sparse_dok *__pyx_v_kill;
      PyObject *__pyx_r = NULL;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("delete_dok_cap", 0);
    /* … */
      /* function exit code */
      __pyx_r = Py_None; __Pyx_INCREF(Py_None);
      goto __pyx_L0;
      __pyx_L1_error:;
      __Pyx_AddTraceback("anuga.fit_interpolate.fitsmooth.delete_dok_cap", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = 0;
      __pyx_L0:;
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    +068: 	kill = <sparse_dok* > PyCapsule_GetPointer(cap, "sparse dok")

      __pyx_t_1 = PyCapsule_GetPointer(__pyx_v_cap, ((char const *)"sparse dok")); if (unlikely(__pyx_t_1 == ((void *)NULL) && PyErr_Occurred())) __PYX_ERR(0, 68, __pyx_L1_error)
      __pyx_v_kill = ((sparse_dok *)__pyx_t_1);

    +069: 	if kill != NULL:

      __pyx_t_2 = ((__pyx_v_kill != NULL) != 0);
      if (__pyx_t_2) {
    /* … */
      }

    +070: 		delete_dok_matrix(kill)

        delete_dok_matrix(__pyx_v_kill);

     071:

    +072: cdef c_double_array_to_list(double* mat, int cols):

    static PyObject *__pyx_f_5anuga_15fit_interpolate_9fitsmooth_c_double_array_to_list(double *__pyx_v_mat, int __pyx_v_cols) {
      int __pyx_v_j;
      PyObject *__pyx_v_lst = 0;
      PyObject *__pyx_r = NULL;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("c_double_array_to_list", 0);
    /* … */
      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_1);
      __Pyx_XDECREF(__pyx_t_11);
      __Pyx_XDECREF(__pyx_t_12);
      __Pyx_AddTraceback("anuga.fit_interpolate.fitsmooth.c_double_array_to_list", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = 0;
      __pyx_L0:;
      __Pyx_XDECREF(__pyx_v_lst);
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

     073: 	cdef int j

     074: 	cdef list lst

    +075: 	lst = []

      __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 75, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_v_lst = ((PyObject*)__pyx_t_1);
      __pyx_t_1 = 0;

    +076: 	if not(isinstance(lst, list)):

      __pyx_t_2 = PyList_Check(__pyx_v_lst);
      __pyx_t_3 = ((!(__pyx_t_2 != 0)) != 0);
      if (__pyx_t_3) {
    /* … */
      }

    +077: 		return None

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

    +078: 	for j in xrange(cols):

      __pyx_t_4 = __pyx_v_cols;
      __pyx_t_5 = __pyx_t_4;
      for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) {
        __pyx_v_j = __pyx_t_6;

    +079: 		try:

        {
          /*try:*/ {
    /* … */
          }
          __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
          goto __pyx_L13_try_end;
          __pyx_L6_error:;
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    /* … */
          __Pyx_XGIVEREF(__pyx_t_7);
          __Pyx_XGIVEREF(__pyx_t_8);
          __Pyx_XGIVEREF(__pyx_t_9);
          __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9);
          goto __pyx_L1_error;
          __pyx_L9_except_return:;
          __Pyx_XGIVEREF(__pyx_t_7);
          __Pyx_XGIVEREF(__pyx_t_8);
          __Pyx_XGIVEREF(__pyx_t_9);
          __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9);
          goto __pyx_L0;
          __pyx_L13_try_end:;
        }
      }

    +080: 			lst.append(mat[j])

            __pyx_t_1 = PyFloat_FromDouble((__pyx_v_mat[__pyx_v_j])); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 80, __pyx_L6_error)
            __Pyx_GOTREF(__pyx_t_1);
            __pyx_t_10 = __Pyx_PyList_Append(__pyx_v_lst, __pyx_t_1); if (unlikely(__pyx_t_10 == ((int)-1))) __PYX_ERR(0, 80, __pyx_L6_error)
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    +081: 		except:

          /*except:*/ {
            __Pyx_AddTraceback("anuga.fit_interpolate.fitsmooth.c_double_array_to_list", __pyx_clineno, __pyx_lineno, __pyx_filename);
            if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_11, &__pyx_t_12) < 0) __PYX_ERR(0, 81, __pyx_L8_except_error)
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_GOTREF(__pyx_t_11);
            __Pyx_GOTREF(__pyx_t_12);

    +082: 			return None

            __Pyx_XDECREF(__pyx_r);
            __pyx_r = Py_None; __Pyx_INCREF(Py_None);
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
            __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
            goto __pyx_L9_except_return;
          }
          __pyx_L8_except_error:;

    +083: 	return lst

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

     084:

    +085: cdef c_int_array_to_list(int* mat, int cols):

    static PyObject *__pyx_f_5anuga_15fit_interpolate_9fitsmooth_c_int_array_to_list(int *__pyx_v_mat, int __pyx_v_cols) {
      int __pyx_v_j;
      PyObject *__pyx_v_lst = 0;
      PyObject *__pyx_r = NULL;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("c_int_array_to_list", 0);
    /* … */
      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_1);
      __Pyx_XDECREF(__pyx_t_11);
      __Pyx_XDECREF(__pyx_t_12);
      __Pyx_AddTraceback("anuga.fit_interpolate.fitsmooth.c_int_array_to_list", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = 0;
      __pyx_L0:;
      __Pyx_XDECREF(__pyx_v_lst);
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

     086: 	cdef int j

     087: 	cdef list lst

    +088: 	lst = []

      __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 88, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_v_lst = ((PyObject*)__pyx_t_1);
      __pyx_t_1 = 0;

    +089: 	if not(isinstance(lst, list)):

      __pyx_t_2 = PyList_Check(__pyx_v_lst);
      __pyx_t_3 = ((!(__pyx_t_2 != 0)) != 0);
      if (__pyx_t_3) {
    /* … */
      }

    +090: 		return None

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

    +091: 	for j in xrange(cols):

      __pyx_t_4 = __pyx_v_cols;
      __pyx_t_5 = __pyx_t_4;
      for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) {
        __pyx_v_j = __pyx_t_6;

    +092: 		try:

        {
          /*try:*/ {
    /* … */
          }
          __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
          goto __pyx_L13_try_end;
          __pyx_L6_error:;
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    /* … */
          __Pyx_XGIVEREF(__pyx_t_7);
          __Pyx_XGIVEREF(__pyx_t_8);
          __Pyx_XGIVEREF(__pyx_t_9);
          __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9);
          goto __pyx_L1_error;
          __pyx_L9_except_return:;
          __Pyx_XGIVEREF(__pyx_t_7);
          __Pyx_XGIVEREF(__pyx_t_8);
          __Pyx_XGIVEREF(__pyx_t_9);
          __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9);
          goto __pyx_L0;
          __pyx_L13_try_end:;
        }
      }

    +093: 			lst.append(mat[j])

            __pyx_t_1 = __Pyx_PyInt_From_int((__pyx_v_mat[__pyx_v_j])); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 93, __pyx_L6_error)
            __Pyx_GOTREF(__pyx_t_1);
            __pyx_t_10 = __Pyx_PyList_Append(__pyx_v_lst, __pyx_t_1); if (unlikely(__pyx_t_10 == ((int)-1))) __PYX_ERR(0, 93, __pyx_L6_error)
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    +094: 		except:

          /*except:*/ {
            __Pyx_AddTraceback("anuga.fit_interpolate.fitsmooth.c_int_array_to_list", __pyx_clineno, __pyx_lineno, __pyx_filename);
            if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_11, &__pyx_t_12) < 0) __PYX_ERR(0, 94, __pyx_L8_except_error)
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_GOTREF(__pyx_t_11);
            __Pyx_GOTREF(__pyx_t_12);

    +095: 			return None

            __Pyx_XDECREF(__pyx_r);
            __pyx_r = Py_None; __Pyx_INCREF(Py_None);
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
            __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
            goto __pyx_L9_except_return;
          }
          __pyx_L8_except_error:;

    +096: 	return lst

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

     097:

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

    /* Python wrapper */
    static PyObject *__pyx_pw_5anuga_15fit_interpolate_9fitsmooth_1build_quad_tree(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
    static PyMethodDef __pyx_mdef_5anuga_15fit_interpolate_9fitsmooth_1build_quad_tree = {"build_quad_tree", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5anuga_15fit_interpolate_9fitsmooth_1build_quad_tree, METH_VARARGS|METH_KEYWORDS, 0};
    static PyObject *__pyx_pw_5anuga_15fit_interpolate_9fitsmooth_1build_quad_tree(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
      PyArrayObject *__pyx_v_triangles = 0;
      PyArrayObject *__pyx_v_vertex_coordinates = 0;
      PyArrayObject *__pyx_v_extents = 0;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("build_quad_tree (wrapper)", 0);
      {
        static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_triangles,&__pyx_n_s_vertex_coordinates,&__pyx_n_s_extents,0};
        PyObject* values[3] = {0,0,0};
        if (unlikely(__pyx_kwds)) {
          Py_ssize_t kw_args;
          const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
          switch (pos_args) {
            case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
            CYTHON_FALLTHROUGH;
            case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
            CYTHON_FALLTHROUGH;
            case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
            CYTHON_FALLTHROUGH;
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
          kw_args = PyDict_Size(__pyx_kwds);
          switch (pos_args) {
            case  0:
            if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_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_vertex_coordinates)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("build_quad_tree", 1, 3, 3, 1); __PYX_ERR(0, 98, __pyx_L3_error)
            }
            CYTHON_FALLTHROUGH;
            case  2:
            if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_extents)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("build_quad_tree", 1, 3, 3, 2); __PYX_ERR(0, 98, __pyx_L3_error)
            }
          }
          if (unlikely(kw_args > 0)) {
            if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "build_quad_tree") < 0)) __PYX_ERR(0, 98, __pyx_L3_error)
          }
        } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
          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);
        }
        __pyx_v_triangles = ((PyArrayObject *)values[0]);
        __pyx_v_vertex_coordinates = ((PyArrayObject *)values[1]);
        __pyx_v_extents = ((PyArrayObject *)values[2]);
      }
      goto __pyx_L4_argument_unpacking_done;
      __pyx_L5_argtuple_error:;
      __Pyx_RaiseArgtupleInvalid("build_quad_tree", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 98, __pyx_L3_error)
      __pyx_L3_error:;
      __Pyx_AddTraceback("anuga.fit_interpolate.fitsmooth.build_quad_tree", __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, 98, __pyx_L1_error)
      if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_vertex_coordinates), __pyx_ptype_5numpy_ndarray, 0, "vertex_coordinates", 0))) __PYX_ERR(0, 99, __pyx_L1_error)
      if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_extents), __pyx_ptype_5numpy_ndarray, 0, "extents", 0))) __PYX_ERR(0, 100, __pyx_L1_error)
      __pyx_r = __pyx_pf_5anuga_15fit_interpolate_9fitsmooth_build_quad_tree(__pyx_self, __pyx_v_triangles, __pyx_v_vertex_coordinates, __pyx_v_extents);
      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_15fit_interpolate_9fitsmooth_build_quad_tree(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_triangles, PyArrayObject *__pyx_v_vertex_coordinates, PyArrayObject *__pyx_v_extents) {
      int __pyx_v_n;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_extents;
      __Pyx_Buffer __pyx_pybuffer_extents;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_triangles;
      __Pyx_Buffer __pyx_pybuffer_triangles;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_vertex_coordinates;
      __Pyx_Buffer __pyx_pybuffer_vertex_coordinates;
      PyObject *__pyx_r = NULL;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("build_quad_tree", 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_vertex_coordinates.pybuffer.buf = NULL;
      __pyx_pybuffer_vertex_coordinates.refcount = 0;
      __pyx_pybuffernd_vertex_coordinates.data = NULL;
      __pyx_pybuffernd_vertex_coordinates.rcbuffer = &__pyx_pybuffer_vertex_coordinates;
      __pyx_pybuffer_extents.pybuffer.buf = NULL;
      __pyx_pybuffer_extents.refcount = 0;
      __pyx_pybuffernd_extents.data = NULL;
      __pyx_pybuffernd_extents.rcbuffer = &__pyx_pybuffer_extents;
      {
        __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, 98, __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_vertex_coordinates.rcbuffer->pybuffer, (PyObject*)__pyx_v_vertex_coordinates, &__Pyx_TypeInfo_double, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 98, __pyx_L1_error)
      }
      __pyx_pybuffernd_vertex_coordinates.diminfo[0].strides = __pyx_pybuffernd_vertex_coordinates.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vertex_coordinates.diminfo[0].shape = __pyx_pybuffernd_vertex_coordinates.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vertex_coordinates.diminfo[1].strides = __pyx_pybuffernd_vertex_coordinates.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vertex_coordinates.diminfo[1].shape = __pyx_pybuffernd_vertex_coordinates.rcbuffer->pybuffer.shape[1];
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_extents.rcbuffer->pybuffer, (PyObject*)__pyx_v_extents, &__Pyx_TypeInfo_double, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 98, __pyx_L1_error)
      }
      __pyx_pybuffernd_extents.diminfo[0].strides = __pyx_pybuffernd_extents.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_extents.diminfo[0].shape = __pyx_pybuffernd_extents.rcbuffer->pybuffer.shape[0];
    /* … */
      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_6);
      { 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_extents.rcbuffer->pybuffer);
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_triangles.rcbuffer->pybuffer);
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vertex_coordinates.rcbuffer->pybuffer);
      __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
      __Pyx_AddTraceback("anuga.fit_interpolate.fitsmooth.build_quad_tree", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      goto __pyx_L2;
      __pyx_L0:;
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_extents.rcbuffer->pybuffer);
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_triangles.rcbuffer->pybuffer);
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vertex_coordinates.rcbuffer->pybuffer);
      __pyx_L2:;
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }
    /* … */
      __pyx_tuple__3 = PyTuple_Pack(4, __pyx_n_s_triangles, __pyx_n_s_vertex_coordinates, __pyx_n_s_extents, __pyx_n_s_n); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 98, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_tuple__3);
      __Pyx_GIVEREF(__pyx_tuple__3);
    /* … */
      __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5anuga_15fit_interpolate_9fitsmooth_1build_quad_tree, NULL, __pyx_n_s_anuga_fit_interpolate_fitsmooth_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 98, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_build_quad_tree, __pyx_t_1) < 0) __PYX_ERR(0, 98, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_codeobj__4 = (PyObject*)__Pyx_PyCode_New(3, 0, 4, 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_fit_interpolate_fitsmooth, __pyx_n_s_build_quad_tree, 98, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__4)) __PYX_ERR(0, 98, __pyx_L1_error)

     099: 					np.ndarray[double, ndim=2, mode="c"] vertex_coordinates not None,\

     100: 					np.ndarray[double, ndim=1, mode="c"] extents not None):

     101:

     102: 	cdef int n

     103:

    +104: 	n = triangles.shape[0]

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

     105:

    +106: 	return PyCapsule_New(<void* > _build_quad_tree(n, &triangles[0,0], &vertex_coordinates[0,0], &extents[0]), "quad tree", <PyCapsule_Destructor> delete_quad_tree_cap)

      __Pyx_XDECREF(__pyx_r);
      __pyx_t_1 = 0;
      __pyx_t_2 = 0;
      __pyx_t_3 = 0;
      __pyx_t_4 = 0;
      __pyx_t_5 = 0;
      __pyx_t_6 = PyCapsule_New(((void *)_build_quad_tree(__pyx_v_n, (&(*__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(double *, __pyx_pybuffernd_vertex_coordinates.rcbuffer->pybuffer.buf, __pyx_t_3, __pyx_pybuffernd_vertex_coordinates.diminfo[0].strides, __pyx_t_4, __pyx_pybuffernd_vertex_coordinates.diminfo[1].strides))), (&(*__Pyx_BufPtrCContig1d(double *, __pyx_pybuffernd_extents.rcbuffer->pybuffer.buf, __pyx_t_5, __pyx_pybuffernd_extents.diminfo[0].strides))))), ((char const *)"quad tree"), ((PyCapsule_Destructor)__pyx_f_5anuga_15fit_interpolate_9fitsmooth_delete_quad_tree_cap)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 106, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_r = __pyx_t_6;
      __pyx_t_6 = 0;
      goto __pyx_L0;

     107:

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

    /* Python wrapper */
    static PyObject *__pyx_pw_5anuga_15fit_interpolate_9fitsmooth_3build_smoothing_matrix(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
    static PyMethodDef __pyx_mdef_5anuga_15fit_interpolate_9fitsmooth_3build_smoothing_matrix = {"build_smoothing_matrix", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5anuga_15fit_interpolate_9fitsmooth_3build_smoothing_matrix, METH_VARARGS|METH_KEYWORDS, 0};
    static PyObject *__pyx_pw_5anuga_15fit_interpolate_9fitsmooth_3build_smoothing_matrix(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
      PyArrayObject *__pyx_v_triangles = 0;
      PyArrayObject *__pyx_v_areas = 0;
      PyArrayObject *__pyx_v_vertex_coordinates = 0;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("build_smoothing_matrix (wrapper)", 0);
      {
        static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_triangles,&__pyx_n_s_areas,&__pyx_n_s_vertex_coordinates,0};
        PyObject* values[3] = {0,0,0};
        if (unlikely(__pyx_kwds)) {
          Py_ssize_t kw_args;
          const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
          switch (pos_args) {
            case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
            CYTHON_FALLTHROUGH;
            case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
            CYTHON_FALLTHROUGH;
            case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
            CYTHON_FALLTHROUGH;
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
          kw_args = PyDict_Size(__pyx_kwds);
          switch (pos_args) {
            case  0:
            if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_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_areas)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("build_smoothing_matrix", 1, 3, 3, 1); __PYX_ERR(0, 108, __pyx_L3_error)
            }
            CYTHON_FALLTHROUGH;
            case  2:
            if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_vertex_coordinates)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("build_smoothing_matrix", 1, 3, 3, 2); __PYX_ERR(0, 108, __pyx_L3_error)
            }
          }
          if (unlikely(kw_args > 0)) {
            if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "build_smoothing_matrix") < 0)) __PYX_ERR(0, 108, __pyx_L3_error)
          }
        } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
          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);
        }
        __pyx_v_triangles = ((PyArrayObject *)values[0]);
        __pyx_v_areas = ((PyArrayObject *)values[1]);
        __pyx_v_vertex_coordinates = ((PyArrayObject *)values[2]);
      }
      goto __pyx_L4_argument_unpacking_done;
      __pyx_L5_argtuple_error:;
      __Pyx_RaiseArgtupleInvalid("build_smoothing_matrix", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 108, __pyx_L3_error)
      __pyx_L3_error:;
      __Pyx_AddTraceback("anuga.fit_interpolate.fitsmooth.build_smoothing_matrix", __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, 108, __pyx_L1_error)
      if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_areas), __pyx_ptype_5numpy_ndarray, 0, "areas", 0))) __PYX_ERR(0, 109, __pyx_L1_error)
      if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_vertex_coordinates), __pyx_ptype_5numpy_ndarray, 0, "vertex_coordinates", 0))) __PYX_ERR(0, 110, __pyx_L1_error)
      __pyx_r = __pyx_pf_5anuga_15fit_interpolate_9fitsmooth_2build_smoothing_matrix(__pyx_self, __pyx_v_triangles, __pyx_v_areas, __pyx_v_vertex_coordinates);
      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_15fit_interpolate_9fitsmooth_2build_smoothing_matrix(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_triangles, PyArrayObject *__pyx_v_areas, PyArrayObject *__pyx_v_vertex_coordinates) {
      int __pyx_v_err;
      int __pyx_v_n;
      sparse_dok *__pyx_v_smoothing_mat;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_areas;
      __Pyx_Buffer __pyx_pybuffer_areas;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_triangles;
      __Pyx_Buffer __pyx_pybuffer_triangles;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_vertex_coordinates;
      __Pyx_Buffer __pyx_pybuffer_vertex_coordinates;
      PyObject *__pyx_r = NULL;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("build_smoothing_matrix", 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_areas.pybuffer.buf = NULL;
      __pyx_pybuffer_areas.refcount = 0;
      __pyx_pybuffernd_areas.data = NULL;
      __pyx_pybuffernd_areas.rcbuffer = &__pyx_pybuffer_areas;
      __pyx_pybuffer_vertex_coordinates.pybuffer.buf = NULL;
      __pyx_pybuffer_vertex_coordinates.refcount = 0;
      __pyx_pybuffernd_vertex_coordinates.data = NULL;
      __pyx_pybuffernd_vertex_coordinates.rcbuffer = &__pyx_pybuffer_vertex_coordinates;
      {
        __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, 108, __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_areas.rcbuffer->pybuffer, (PyObject*)__pyx_v_areas, &__Pyx_TypeInfo_double, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 108, __pyx_L1_error)
      }
      __pyx_pybuffernd_areas.diminfo[0].strides = __pyx_pybuffernd_areas.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_areas.diminfo[0].shape = __pyx_pybuffernd_areas.rcbuffer->pybuffer.shape[0];
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vertex_coordinates.rcbuffer->pybuffer, (PyObject*)__pyx_v_vertex_coordinates, &__Pyx_TypeInfo_double, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 108, __pyx_L1_error)
      }
      __pyx_pybuffernd_vertex_coordinates.diminfo[0].strides = __pyx_pybuffernd_vertex_coordinates.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vertex_coordinates.diminfo[0].shape = __pyx_pybuffernd_vertex_coordinates.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vertex_coordinates.diminfo[1].strides = __pyx_pybuffernd_vertex_coordinates.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vertex_coordinates.diminfo[1].shape = __pyx_pybuffernd_vertex_coordinates.rcbuffer->pybuffer.shape[1];
    /* … */
      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_6);
      { 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_areas.rcbuffer->pybuffer);
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_triangles.rcbuffer->pybuffer);
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vertex_coordinates.rcbuffer->pybuffer);
      __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
      __Pyx_AddTraceback("anuga.fit_interpolate.fitsmooth.build_smoothing_matrix", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      goto __pyx_L2;
      __pyx_L0:;
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_areas.rcbuffer->pybuffer);
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_triangles.rcbuffer->pybuffer);
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vertex_coordinates.rcbuffer->pybuffer);
      __pyx_L2:;
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }
    /* … */
      __pyx_tuple__5 = PyTuple_Pack(6, __pyx_n_s_triangles, __pyx_n_s_areas, __pyx_n_s_vertex_coordinates, __pyx_n_s_err, __pyx_n_s_n, __pyx_n_s_smoothing_mat); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(0, 108, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_tuple__5);
      __Pyx_GIVEREF(__pyx_tuple__5);
    /* … */
      __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5anuga_15fit_interpolate_9fitsmooth_3build_smoothing_matrix, NULL, __pyx_n_s_anuga_fit_interpolate_fitsmooth_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 108, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_build_smoothing_matrix, __pyx_t_1) < 0) __PYX_ERR(0, 108, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_codeobj__6 = (PyObject*)__Pyx_PyCode_New(3, 0, 6, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__5, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_anuga_fit_interpolate_fitsmooth, __pyx_n_s_build_smoothing_matrix, 108, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__6)) __PYX_ERR(0, 108, __pyx_L1_error)

     109: 							np.ndarray[double, ndim=1, mode="c"] areas not None,\

     110: 							np.ndarray[double, ndim=2, mode="c"] vertex_coordinates not None):

     111:

     112: 	cdef int err, n

     113: 	cdef sparse_dok* smoothing_mat

     114:

    +115: 	n = triangles.shape[0]

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

    +116: 	smoothing_mat = make_dok()

      __pyx_v_smoothing_mat = make_dok();

     117:

    +118: 	err = _build_smoothing_matrix(n, &triangles[0,0], &areas[0], &vertex_coordinates[0,0], <int* > &vertex_coordinates.strides[0], smoothing_mat)

      __pyx_t_1 = 0;
      __pyx_t_2 = 0;
      __pyx_t_3 = 0;
      __pyx_t_4 = 0;
      __pyx_t_5 = 0;
      __pyx_v_err = _build_smoothing_matrix(__pyx_v_n, (&(*__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_BufPtrCContig1d(double *, __pyx_pybuffernd_areas.rcbuffer->pybuffer.buf, __pyx_t_3, __pyx_pybuffernd_areas.diminfo[0].strides))), (&(*__Pyx_BufPtrCContig2d(double *, __pyx_pybuffernd_vertex_coordinates.rcbuffer->pybuffer.buf, __pyx_t_4, __pyx_pybuffernd_vertex_coordinates.diminfo[0].strides, __pyx_t_5, __pyx_pybuffernd_vertex_coordinates.diminfo[1].strides))), ((int *)(&(__pyx_v_vertex_coordinates->strides[0]))), __pyx_v_smoothing_mat);

     119:

    +120: 	assert err == 0, "Unknown Error"

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

     121:

    +122: 	return PyCapsule_New(<void* > smoothing_mat, "sparse dok", <PyCapsule_Destructor> delete_dok_cap)

      __Pyx_XDECREF(__pyx_r);
      __pyx_t_6 = PyCapsule_New(((void *)__pyx_v_smoothing_mat), ((char const *)"sparse dok"), ((PyCapsule_Destructor)__pyx_f_5anuga_15fit_interpolate_9fitsmooth_delete_dok_cap)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 122, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_r = __pyx_t_6;
      __pyx_t_6 = 0;
      goto __pyx_L0;

     123:

     124:

    +125: def build_matrix_AtA_Atz_points(object tree, int N,\

    /* Python wrapper */
    static PyObject *__pyx_pw_5anuga_15fit_interpolate_9fitsmooth_5build_matrix_AtA_Atz_points(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
    static PyMethodDef __pyx_mdef_5anuga_15fit_interpolate_9fitsmooth_5build_matrix_AtA_Atz_points = {"build_matrix_AtA_Atz_points", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5anuga_15fit_interpolate_9fitsmooth_5build_matrix_AtA_Atz_points, METH_VARARGS|METH_KEYWORDS, 0};
    static PyObject *__pyx_pw_5anuga_15fit_interpolate_9fitsmooth_5build_matrix_AtA_Atz_points(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
      PyObject *__pyx_v_tree = 0;
      int __pyx_v_N;
      PyArrayObject *__pyx_v_triangles = 0;
      PyArrayObject *__pyx_v_point_coordinates = 0;
      PyArrayObject *__pyx_v_z = 0;
      int __pyx_v_zdims;
      int __pyx_v_npts;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("build_matrix_AtA_Atz_points (wrapper)", 0);
      {
        static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_tree,&__pyx_n_s_N,&__pyx_n_s_triangles,&__pyx_n_s_point_coordinates,&__pyx_n_s_z,&__pyx_n_s_zdims,&__pyx_n_s_npts,0};
        PyObject* values[7] = {0,0,0,0,0,0,0};
        if (unlikely(__pyx_kwds)) {
          Py_ssize_t kw_args;
          const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
          switch (pos_args) {
            case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
            CYTHON_FALLTHROUGH;
            case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
            CYTHON_FALLTHROUGH;
            case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
            CYTHON_FALLTHROUGH;
            case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
            CYTHON_FALLTHROUGH;
            case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
            CYTHON_FALLTHROUGH;
            case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
            CYTHON_FALLTHROUGH;
            case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
            CYTHON_FALLTHROUGH;
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
          kw_args = PyDict_Size(__pyx_kwds);
          switch (pos_args) {
            case  0:
            if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_tree)) != 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_N)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("build_matrix_AtA_Atz_points", 1, 7, 7, 1); __PYX_ERR(0, 125, __pyx_L3_error)
            }
            CYTHON_FALLTHROUGH;
            case  2:
            if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_triangles)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("build_matrix_AtA_Atz_points", 1, 7, 7, 2); __PYX_ERR(0, 125, __pyx_L3_error)
            }
            CYTHON_FALLTHROUGH;
            case  3:
            if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_point_coordinates)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("build_matrix_AtA_Atz_points", 1, 7, 7, 3); __PYX_ERR(0, 125, __pyx_L3_error)
            }
            CYTHON_FALLTHROUGH;
            case  4:
            if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_z)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("build_matrix_AtA_Atz_points", 1, 7, 7, 4); __PYX_ERR(0, 125, __pyx_L3_error)
            }
            CYTHON_FALLTHROUGH;
            case  5:
            if (likely((values[5] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_zdims)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("build_matrix_AtA_Atz_points", 1, 7, 7, 5); __PYX_ERR(0, 125, __pyx_L3_error)
            }
            CYTHON_FALLTHROUGH;
            case  6:
            if (likely((values[6] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_npts)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("build_matrix_AtA_Atz_points", 1, 7, 7, 6); __PYX_ERR(0, 125, __pyx_L3_error)
            }
          }
          if (unlikely(kw_args > 0)) {
            if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "build_matrix_AtA_Atz_points") < 0)) __PYX_ERR(0, 125, __pyx_L3_error)
          }
        } else if (PyTuple_GET_SIZE(__pyx_args) != 7) {
          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);
          values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
          values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        }
        __pyx_v_tree = values[0];
        __pyx_v_N = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_N == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 125, __pyx_L3_error)
        __pyx_v_triangles = ((PyArrayObject *)values[2]);
        __pyx_v_point_coordinates = ((PyArrayObject *)values[3]);
        __pyx_v_z = ((PyArrayObject *)values[4]);
        __pyx_v_zdims = __Pyx_PyInt_As_int(values[5]); if (unlikely((__pyx_v_zdims == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 129, __pyx_L3_error)
        __pyx_v_npts = __Pyx_PyInt_As_int(values[6]); if (unlikely((__pyx_v_npts == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 130, __pyx_L3_error)
      }
      goto __pyx_L4_argument_unpacking_done;
      __pyx_L5_argtuple_error:;
      __Pyx_RaiseArgtupleInvalid("build_matrix_AtA_Atz_points", 1, 7, 7, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 125, __pyx_L3_error)
      __pyx_L3_error:;
      __Pyx_AddTraceback("anuga.fit_interpolate.fitsmooth.build_matrix_AtA_Atz_points", __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, 126, __pyx_L1_error)
      if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_point_coordinates), __pyx_ptype_5numpy_ndarray, 0, "point_coordinates", 0))) __PYX_ERR(0, 127, __pyx_L1_error)
      if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_z), __pyx_ptype_5numpy_ndarray, 0, "z", 0))) __PYX_ERR(0, 128, __pyx_L1_error)
      __pyx_r = __pyx_pf_5anuga_15fit_interpolate_9fitsmooth_4build_matrix_AtA_Atz_points(__pyx_self, __pyx_v_tree, __pyx_v_N, __pyx_v_triangles, __pyx_v_point_coordinates, __pyx_v_z, __pyx_v_zdims, __pyx_v_npts);
      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_15fit_interpolate_9fitsmooth_4build_matrix_AtA_Atz_points(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_tree, int __pyx_v_N, PyArrayObject *__pyx_v_triangles, PyArrayObject *__pyx_v_point_coordinates, PyArrayObject *__pyx_v_z, int __pyx_v_zdims, int __pyx_v_npts) {
      quad_tree *__pyx_v_quadtree;
      sparse_dok *__pyx_v_dok_AtA;
      PyObject *__pyx_v_AtA_cap = 0;
      double **__pyx_v_Atz;
      PyObject *__pyx_v_Atz_ret = 0;
      int __pyx_v_err;
      int __pyx_v_i;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_point_coordinates;
      __Pyx_Buffer __pyx_pybuffer_point_coordinates;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_triangles;
      __Pyx_Buffer __pyx_pybuffer_triangles;
      PyObject *__pyx_r = NULL;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("build_matrix_AtA_Atz_points", 0);
      __Pyx_INCREF((PyObject *)__pyx_v_z);
      __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_point_coordinates.pybuffer.buf = NULL;
      __pyx_pybuffer_point_coordinates.refcount = 0;
      __pyx_pybuffernd_point_coordinates.data = NULL;
      __pyx_pybuffernd_point_coordinates.rcbuffer = &__pyx_pybuffer_point_coordinates;
      {
        __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, 125, __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_point_coordinates.rcbuffer->pybuffer, (PyObject*)__pyx_v_point_coordinates, &__Pyx_TypeInfo_double, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 125, __pyx_L1_error)
      }
      __pyx_pybuffernd_point_coordinates.diminfo[0].strides = __pyx_pybuffernd_point_coordinates.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_point_coordinates.diminfo[0].shape = __pyx_pybuffernd_point_coordinates.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_point_coordinates.diminfo[1].strides = __pyx_pybuffernd_point_coordinates.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_point_coordinates.diminfo[1].shape = __pyx_pybuffernd_point_coordinates.rcbuffer->pybuffer.shape[1];
    /* … */
      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_1);
      __Pyx_XDECREF(__pyx_t_2);
      __Pyx_XDECREF(__pyx_t_3);
      { 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_point_coordinates.rcbuffer->pybuffer);
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_triangles.rcbuffer->pybuffer);
      __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
      __Pyx_AddTraceback("anuga.fit_interpolate.fitsmooth.build_matrix_AtA_Atz_points", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      goto __pyx_L2;
      __pyx_L0:;
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_point_coordinates.rcbuffer->pybuffer);
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_triangles.rcbuffer->pybuffer);
      __pyx_L2:;
      __Pyx_XDECREF(__pyx_v_AtA_cap);
      __Pyx_XDECREF(__pyx_v_Atz_ret);
      __Pyx_XDECREF((PyObject *)__pyx_v_z);
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }
    /* … */
      __pyx_tuple__7 = PyTuple_Pack(14, __pyx_n_s_tree, __pyx_n_s_N, __pyx_n_s_triangles, __pyx_n_s_point_coordinates, __pyx_n_s_z, __pyx_n_s_zdims, __pyx_n_s_npts, __pyx_n_s_quadtree, __pyx_n_s_dok_AtA, __pyx_n_s_AtA_cap, __pyx_n_s_Atz, __pyx_n_s_Atz_ret, __pyx_n_s_err, __pyx_n_s_i); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(0, 125, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_tuple__7);
      __Pyx_GIVEREF(__pyx_tuple__7);
    /* … */
      __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5anuga_15fit_interpolate_9fitsmooth_5build_matrix_AtA_Atz_points, NULL, __pyx_n_s_anuga_fit_interpolate_fitsmooth_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 125, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_build_matrix_AtA_Atz_points, __pyx_t_1) < 0) __PYX_ERR(0, 125, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_codeobj__8 = (PyObject*)__Pyx_PyCode_New(7, 0, 14, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__7, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_anuga_fit_interpolate_fitsmooth, __pyx_n_s_build_matrix_AtA_Atz_points, 125, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__8)) __PYX_ERR(0, 125, __pyx_L1_error)

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

     127: 							np.ndarray[double, ndim=2, mode="c"] point_coordinates not None,\

     128: 							np.ndarray z not None,\

     129: 							int zdims,\

     130: 							int npts):

     131:

     132: 	cdef quad_tree* quadtree

     133: 	cdef sparse_dok* dok_AtA

     134: 	cdef object AtA_cap

     135: 	cdef double** Atz

     136: 	cdef list Atz_ret

     137: 	cdef int err

     138: 	cdef int i

     139:

    +140: 	z = np.ascontiguousarray(z)

      __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 140, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_ascontiguousarray); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 140, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
        __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
        if (likely(__pyx_t_2)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
          __Pyx_INCREF(__pyx_t_2);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_3, function);
        }
      }
      __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, ((PyObject *)__pyx_v_z)) : __Pyx_PyObject_CallOneArg(__pyx_t_3, ((PyObject *)__pyx_v_z));
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 140, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 140, __pyx_L1_error)
      __Pyx_DECREF_SET(__pyx_v_z, ((PyArrayObject *)__pyx_t_1));
      __pyx_t_1 = 0;

     141:

    +142: 	quadtree = <quad_tree* > PyCapsule_GetPointer(tree, "quad tree")

      __pyx_t_4 = PyCapsule_GetPointer(__pyx_v_tree, ((char const *)"quad tree")); if (unlikely(__pyx_t_4 == ((void *)NULL) && PyErr_Occurred())) __PYX_ERR(0, 142, __pyx_L1_error)
      __pyx_v_quadtree = ((quad_tree *)__pyx_t_4);

     143:

    +144: 	dok_AtA = make_dok()

      __pyx_v_dok_AtA = make_dok();

     145:

    +146: 	Atz = <double** > malloc(zdims * sizeof(double*))

      __pyx_v_Atz = ((double **)malloc((__pyx_v_zdims * (sizeof(double *)))));

    +147: 	for i in xrange(zdims):

      __pyx_t_5 = __pyx_v_zdims;
      __pyx_t_6 = __pyx_t_5;
      for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_6; __pyx_t_7+=1) {
        __pyx_v_i = __pyx_t_7;

    +148: 		Atz[i] = <double* > malloc(N * sizeof(double))

        (__pyx_v_Atz[__pyx_v_i]) = ((double *)malloc((__pyx_v_N * (sizeof(double)))));
      }

     149:

    +150: 	err = _build_matrix_AtA_Atz_points(N, &triangles[0,0],\

      __pyx_t_8 = 0;
      __pyx_t_9 = 0;
    /* … */
      __pyx_v_err = _build_matrix_AtA_Atz_points(__pyx_v_N, (&(*__Pyx_BufPtrCContig2d(long *, __pyx_pybuffernd_triangles.rcbuffer->pybuffer.buf, __pyx_t_8, __pyx_pybuffernd_triangles.diminfo[0].strides, __pyx_t_9, __pyx_pybuffernd_triangles.diminfo[1].strides))), (&(*__Pyx_BufPtrCContig2d(double *, __pyx_pybuffernd_point_coordinates.rcbuffer->pybuffer.buf, __pyx_t_10, __pyx_pybuffernd_point_coordinates.diminfo[0].strides, __pyx_t_11, __pyx_pybuffernd_point_coordinates.diminfo[1].strides))), ((double *)__pyx_v_z->data), __pyx_v_zdims, __pyx_v_npts, __pyx_v_dok_AtA, __pyx_v_Atz, __pyx_v_quadtree);

    +151: 										&point_coordinates[0,0],\

      __pyx_t_10 = 0;
      __pyx_t_11 = 0;

     152: 										<double* > z.data,\

     153: 										zdims,\

     154: 										npts,\

     155: 										dok_AtA,\

     156: 										Atz,\

     157: 										quadtree)

     158:

    +159: 	assert err == 0, "Unknown Error"

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

     160:

    +161: 	AtA_cap = PyCapsule_New(<void* > dok_AtA, "sparse dok", <PyCapsule_Destructor> delete_dok_cap)

      __pyx_t_1 = PyCapsule_New(((void *)__pyx_v_dok_AtA), ((char const *)"sparse dok"), ((PyCapsule_Destructor)__pyx_f_5anuga_15fit_interpolate_9fitsmooth_delete_dok_cap)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 161, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_v_AtA_cap = __pyx_t_1;
      __pyx_t_1 = 0;

     162:

    +163: 	Atz_ret = []

      __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 163, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_v_Atz_ret = ((PyObject*)__pyx_t_1);
      __pyx_t_1 = 0;

    +164: 	for i in xrange(zdims):

      __pyx_t_5 = __pyx_v_zdims;
      __pyx_t_6 = __pyx_t_5;
      for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_6; __pyx_t_7+=1) {
        __pyx_v_i = __pyx_t_7;

    +165: 		Atz_ret.append(c_double_array_to_list(Atz[i],N))

        __pyx_t_1 = __pyx_f_5anuga_15fit_interpolate_9fitsmooth_c_double_array_to_list((__pyx_v_Atz[__pyx_v_i]), __pyx_v_N); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 165, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_Atz_ret, __pyx_t_1); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 165, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    +166: 		free(Atz[i])

        free((__pyx_v_Atz[__pyx_v_i]));
      }

    +167: 	free(Atz)

      free(__pyx_v_Atz);

     168:

    +169: 	return [AtA_cap, Atz_ret]

      __Pyx_XDECREF(__pyx_r);
      __pyx_t_1 = PyList_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 169, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_v_AtA_cap);
      __Pyx_GIVEREF(__pyx_v_AtA_cap);
      PyList_SET_ITEM(__pyx_t_1, 0, __pyx_v_AtA_cap);
      __Pyx_INCREF(__pyx_v_Atz_ret);
      __Pyx_GIVEREF(__pyx_v_Atz_ret);
      PyList_SET_ITEM(__pyx_t_1, 1, __pyx_v_Atz_ret);
      __pyx_r = __pyx_t_1;
      __pyx_t_1 = 0;
      goto __pyx_L0;

     170:

    +171: def combine_partial_AtA_Atz(object AtA_cap1, object AtA_cap2,\

    /* Python wrapper */
    static PyObject *__pyx_pw_5anuga_15fit_interpolate_9fitsmooth_7combine_partial_AtA_Atz(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
    static PyMethodDef __pyx_mdef_5anuga_15fit_interpolate_9fitsmooth_7combine_partial_AtA_Atz = {"combine_partial_AtA_Atz", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5anuga_15fit_interpolate_9fitsmooth_7combine_partial_AtA_Atz, METH_VARARGS|METH_KEYWORDS, 0};
    static PyObject *__pyx_pw_5anuga_15fit_interpolate_9fitsmooth_7combine_partial_AtA_Atz(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
      PyObject *__pyx_v_AtA_cap1 = 0;
      PyObject *__pyx_v_AtA_cap2 = 0;
      PyArrayObject *__pyx_v_Atz1 = 0;
      PyArrayObject *__pyx_v_Atz2 = 0;
      int __pyx_v_zdim;
      int __pyx_v_n;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("combine_partial_AtA_Atz (wrapper)", 0);
      {
        static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_AtA_cap1,&__pyx_n_s_AtA_cap2,&__pyx_n_s_Atz1,&__pyx_n_s_Atz2,&__pyx_n_s_zdim,&__pyx_n_s_n,0};
        PyObject* values[6] = {0,0,0,0,0,0};
        if (unlikely(__pyx_kwds)) {
          Py_ssize_t kw_args;
          const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
          switch (pos_args) {
            case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
            CYTHON_FALLTHROUGH;
            case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
            CYTHON_FALLTHROUGH;
            case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
            CYTHON_FALLTHROUGH;
            case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
            CYTHON_FALLTHROUGH;
            case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
            CYTHON_FALLTHROUGH;
            case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
            CYTHON_FALLTHROUGH;
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
          kw_args = PyDict_Size(__pyx_kwds);
          switch (pos_args) {
            case  0:
            if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_AtA_cap1)) != 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_AtA_cap2)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("combine_partial_AtA_Atz", 1, 6, 6, 1); __PYX_ERR(0, 171, __pyx_L3_error)
            }
            CYTHON_FALLTHROUGH;
            case  2:
            if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_Atz1)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("combine_partial_AtA_Atz", 1, 6, 6, 2); __PYX_ERR(0, 171, __pyx_L3_error)
            }
            CYTHON_FALLTHROUGH;
            case  3:
            if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_Atz2)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("combine_partial_AtA_Atz", 1, 6, 6, 3); __PYX_ERR(0, 171, __pyx_L3_error)
            }
            CYTHON_FALLTHROUGH;
            case  4:
            if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_zdim)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("combine_partial_AtA_Atz", 1, 6, 6, 4); __PYX_ERR(0, 171, __pyx_L3_error)
            }
            CYTHON_FALLTHROUGH;
            case  5:
            if (likely((values[5] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("combine_partial_AtA_Atz", 1, 6, 6, 5); __PYX_ERR(0, 171, __pyx_L3_error)
            }
          }
          if (unlikely(kw_args > 0)) {
            if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "combine_partial_AtA_Atz") < 0)) __PYX_ERR(0, 171, __pyx_L3_error)
          }
        } else if (PyTuple_GET_SIZE(__pyx_args) != 6) {
          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);
          values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        }
        __pyx_v_AtA_cap1 = values[0];
        __pyx_v_AtA_cap2 = values[1];
        __pyx_v_Atz1 = ((PyArrayObject *)values[2]);
        __pyx_v_Atz2 = ((PyArrayObject *)values[3]);
        __pyx_v_zdim = __Pyx_PyInt_As_int(values[4]); if (unlikely((__pyx_v_zdim == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 174, __pyx_L3_error)
        __pyx_v_n = __Pyx_PyInt_As_int(values[5]); if (unlikely((__pyx_v_n == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 175, __pyx_L3_error)
      }
      goto __pyx_L4_argument_unpacking_done;
      __pyx_L5_argtuple_error:;
      __Pyx_RaiseArgtupleInvalid("combine_partial_AtA_Atz", 1, 6, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 171, __pyx_L3_error)
      __pyx_L3_error:;
      __Pyx_AddTraceback("anuga.fit_interpolate.fitsmooth.combine_partial_AtA_Atz", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __Pyx_RefNannyFinishContext();
      return NULL;
      __pyx_L4_argument_unpacking_done:;
      if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Atz1), __pyx_ptype_5numpy_ndarray, 1, "Atz1", 0))) __PYX_ERR(0, 172, __pyx_L1_error)
      if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Atz2), __pyx_ptype_5numpy_ndarray, 1, "Atz2", 0))) __PYX_ERR(0, 173, __pyx_L1_error)
      __pyx_r = __pyx_pf_5anuga_15fit_interpolate_9fitsmooth_6combine_partial_AtA_Atz(__pyx_self, __pyx_v_AtA_cap1, __pyx_v_AtA_cap2, __pyx_v_Atz1, __pyx_v_Atz2, __pyx_v_zdim, __pyx_v_n);
      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_15fit_interpolate_9fitsmooth_6combine_partial_AtA_Atz(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_AtA_cap1, PyObject *__pyx_v_AtA_cap2, PyArrayObject *__pyx_v_Atz1, PyArrayObject *__pyx_v_Atz2, int __pyx_v_zdim, int __pyx_v_n) {
      sparse_dok *__pyx_v_dok_AtA1;
      sparse_dok *__pyx_v_dok_AtA2;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_Atz1;
      __Pyx_Buffer __pyx_pybuffer_Atz1;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_Atz2;
      __Pyx_Buffer __pyx_pybuffer_Atz2;
      PyObject *__pyx_r = NULL;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("combine_partial_AtA_Atz", 0);
      __pyx_pybuffer_Atz1.pybuffer.buf = NULL;
      __pyx_pybuffer_Atz1.refcount = 0;
      __pyx_pybuffernd_Atz1.data = NULL;
      __pyx_pybuffernd_Atz1.rcbuffer = &__pyx_pybuffer_Atz1;
      __pyx_pybuffer_Atz2.pybuffer.buf = NULL;
      __pyx_pybuffer_Atz2.refcount = 0;
      __pyx_pybuffernd_Atz2.data = NULL;
      __pyx_pybuffernd_Atz2.rcbuffer = &__pyx_pybuffer_Atz2;
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_Atz1.rcbuffer->pybuffer, (PyObject*)__pyx_v_Atz1, &__Pyx_TypeInfo_double, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 171, __pyx_L1_error)
      }
      __pyx_pybuffernd_Atz1.diminfo[0].strides = __pyx_pybuffernd_Atz1.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_Atz1.diminfo[0].shape = __pyx_pybuffernd_Atz1.rcbuffer->pybuffer.shape[0];
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_Atz2.rcbuffer->pybuffer, (PyObject*)__pyx_v_Atz2, &__Pyx_TypeInfo_double, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 171, __pyx_L1_error)
      }
      __pyx_pybuffernd_Atz2.diminfo[0].strides = __pyx_pybuffernd_Atz2.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_Atz2.diminfo[0].shape = __pyx_pybuffernd_Atz2.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_Atz1.rcbuffer->pybuffer);
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Atz2.rcbuffer->pybuffer);
      __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
      __Pyx_AddTraceback("anuga.fit_interpolate.fitsmooth.combine_partial_AtA_Atz", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      goto __pyx_L2;
      __pyx_L0:;
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Atz1.rcbuffer->pybuffer);
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Atz2.rcbuffer->pybuffer);
      __pyx_L2:;
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }
    /* … */
      __pyx_tuple__9 = PyTuple_Pack(8, __pyx_n_s_AtA_cap1, __pyx_n_s_AtA_cap2, __pyx_n_s_Atz1, __pyx_n_s_Atz2, __pyx_n_s_zdim, __pyx_n_s_n, __pyx_n_s_dok_AtA1, __pyx_n_s_dok_AtA2); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(0, 171, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_tuple__9);
      __Pyx_GIVEREF(__pyx_tuple__9);
    /* … */
      __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5anuga_15fit_interpolate_9fitsmooth_7combine_partial_AtA_Atz, NULL, __pyx_n_s_anuga_fit_interpolate_fitsmooth_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 171, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_combine_partial_AtA_Atz, __pyx_t_1) < 0) __PYX_ERR(0, 171, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_codeobj__10 = (PyObject*)__Pyx_PyCode_New(6, 0, 8, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__9, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_anuga_fit_interpolate_fitsmooth, __pyx_n_s_combine_partial_AtA_Atz, 171, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__10)) __PYX_ERR(0, 171, __pyx_L1_error)

     172: 							np.ndarray[double, ndim=1, mode="c"] Atz1,\

     173: 							np.ndarray[double, ndim=1, mode="c"] Atz2,\

     174: 							int zdim,\

     175: 							int n):

     176:

     177: 	cdef sparse_dok* dok_AtA1

     178: 	cdef sparse_dok* dok_AtA2

     179:

    +180: 	dok_AtA1 = <sparse_dok* > PyCapsule_GetPointer(AtA_cap1, "sparse dok")

      __pyx_t_1 = PyCapsule_GetPointer(__pyx_v_AtA_cap1, ((char const *)"sparse dok")); if (unlikely(__pyx_t_1 == ((void *)NULL) && PyErr_Occurred())) __PYX_ERR(0, 180, __pyx_L1_error)
      __pyx_v_dok_AtA1 = ((sparse_dok *)__pyx_t_1);

    +181: 	dok_AtA2 = <sparse_dok* > PyCapsule_GetPointer(AtA_cap2, "sparse dok")

      __pyx_t_1 = PyCapsule_GetPointer(__pyx_v_AtA_cap2, ((char const *)"sparse dok")); if (unlikely(__pyx_t_1 == ((void *)NULL) && PyErr_Occurred())) __PYX_ERR(0, 181, __pyx_L1_error)
      __pyx_v_dok_AtA2 = ((sparse_dok *)__pyx_t_1);

     182:

    +183: 	_combine_partial_AtA_Atz(dok_AtA1, dok_AtA2, &Atz1[0], &Atz2[0], n, zdim)

      __pyx_t_2 = 0;
      __pyx_t_3 = 0;
      _combine_partial_AtA_Atz(__pyx_v_dok_AtA1, __pyx_v_dok_AtA2, (&(*__Pyx_BufPtrCContig1d(double *, __pyx_pybuffernd_Atz1.rcbuffer->pybuffer.buf, __pyx_t_2, __pyx_pybuffernd_Atz1.diminfo[0].strides))), (&(*__Pyx_BufPtrCContig1d(double *, __pyx_pybuffernd_Atz2.rcbuffer->pybuffer.buf, __pyx_t_3, __pyx_pybuffernd_Atz2.diminfo[0].strides))), __pyx_v_n, __pyx_v_zdim);

     184:

    +185: def individual_tree_search(object tree, np.ndarray[double, ndim=1, mode="c"] point):

    /* Python wrapper */
    static PyObject *__pyx_pw_5anuga_15fit_interpolate_9fitsmooth_9individual_tree_search(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
    static PyMethodDef __pyx_mdef_5anuga_15fit_interpolate_9fitsmooth_9individual_tree_search = {"individual_tree_search", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5anuga_15fit_interpolate_9fitsmooth_9individual_tree_search, METH_VARARGS|METH_KEYWORDS, 0};
    static PyObject *__pyx_pw_5anuga_15fit_interpolate_9fitsmooth_9individual_tree_search(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
      PyObject *__pyx_v_tree = 0;
      PyArrayObject *__pyx_v_point = 0;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("individual_tree_search (wrapper)", 0);
      {
        static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_tree,&__pyx_n_s_point,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_tree)) != 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_point)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("individual_tree_search", 1, 2, 2, 1); __PYX_ERR(0, 185, __pyx_L3_error)
            }
          }
          if (unlikely(kw_args > 0)) {
            if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "individual_tree_search") < 0)) __PYX_ERR(0, 185, __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_tree = values[0];
        __pyx_v_point = ((PyArrayObject *)values[1]);
      }
      goto __pyx_L4_argument_unpacking_done;
      __pyx_L5_argtuple_error:;
      __Pyx_RaiseArgtupleInvalid("individual_tree_search", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 185, __pyx_L3_error)
      __pyx_L3_error:;
      __Pyx_AddTraceback("anuga.fit_interpolate.fitsmooth.individual_tree_search", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __Pyx_RefNannyFinishContext();
      return NULL;
      __pyx_L4_argument_unpacking_done:;
      if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_point), __pyx_ptype_5numpy_ndarray, 1, "point", 0))) __PYX_ERR(0, 185, __pyx_L1_error)
      __pyx_r = __pyx_pf_5anuga_15fit_interpolate_9fitsmooth_8individual_tree_search(__pyx_self, __pyx_v_tree, __pyx_v_point);
      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_15fit_interpolate_9fitsmooth_8individual_tree_search(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_tree, PyArrayObject *__pyx_v_point) {
      quad_tree *__pyx_v_quadtree;
      double __pyx_v_xp;
      double __pyx_v_yp;
      double *__pyx_v_sigma;
      triangle *__pyx_v_T;
      long __pyx_v_found;
      long __pyx_v_index;
      PyObject *__pyx_v_sigmalist = 0;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_point;
      __Pyx_Buffer __pyx_pybuffer_point;
      PyObject *__pyx_r = NULL;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("individual_tree_search", 0);
      __pyx_pybuffer_point.pybuffer.buf = NULL;
      __pyx_pybuffer_point.refcount = 0;
      __pyx_pybuffernd_point.data = NULL;
      __pyx_pybuffernd_point.rcbuffer = &__pyx_pybuffer_point;
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_point.rcbuffer->pybuffer, (PyObject*)__pyx_v_point, &__Pyx_TypeInfo_double, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 185, __pyx_L1_error)
      }
      __pyx_pybuffernd_point.diminfo[0].strides = __pyx_pybuffernd_point.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_point.diminfo[0].shape = __pyx_pybuffernd_point.rcbuffer->pybuffer.shape[0];
    /* … */
      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_3);
      __Pyx_XDECREF(__pyx_t_6);
      __Pyx_XDECREF(__pyx_t_7);
      { 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_point.rcbuffer->pybuffer);
      __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
      __Pyx_AddTraceback("anuga.fit_interpolate.fitsmooth.individual_tree_search", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      goto __pyx_L2;
      __pyx_L0:;
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_point.rcbuffer->pybuffer);
      __pyx_L2:;
      __Pyx_XDECREF(__pyx_v_sigmalist);
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }
    /* … */
      __pyx_tuple__11 = PyTuple_Pack(10, __pyx_n_s_tree, __pyx_n_s_point, __pyx_n_s_quadtree, __pyx_n_s_xp, __pyx_n_s_yp, __pyx_n_s_sigma, __pyx_n_s_T, __pyx_n_s_found, __pyx_n_s_index, __pyx_n_s_sigmalist); if (unlikely(!__pyx_tuple__11)) __PYX_ERR(0, 185, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_tuple__11);
      __Pyx_GIVEREF(__pyx_tuple__11);
    /* … */
      __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5anuga_15fit_interpolate_9fitsmooth_9individual_tree_search, NULL, __pyx_n_s_anuga_fit_interpolate_fitsmooth_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 185, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_individual_tree_search, __pyx_t_1) < 0) __PYX_ERR(0, 185, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_codeobj__12 = (PyObject*)__Pyx_PyCode_New(2, 0, 10, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__11, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_anuga_fit_interpolate_fitsmooth, __pyx_n_s_individual_tree_search, 185, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__12)) __PYX_ERR(0, 185, __pyx_L1_error)

     186:

     187: 	cdef quad_tree* quadtree

     188: 	cdef double xp,yp

     189: 	cdef double* sigma

     190: 	cdef triangle* T

     191: 	cdef long found

     192: 	cdef long index

     193: 	cdef list sigmalist

     194:

    +195: 	quadtree = <quad_tree* > PyCapsule_GetPointer(tree, "quad tree")

      __pyx_t_1 = PyCapsule_GetPointer(__pyx_v_tree, ((char const *)"quad tree")); if (unlikely(__pyx_t_1 == ((void *)NULL) && PyErr_Occurred())) __PYX_ERR(0, 195, __pyx_L1_error)
      __pyx_v_quadtree = ((quad_tree *)__pyx_t_1);

    +196: 	xp = point[0]

      __pyx_t_2 = 0;
      __pyx_v_xp = (*__Pyx_BufPtrCContig1d(double *, __pyx_pybuffernd_point.rcbuffer->pybuffer.buf, __pyx_t_2, __pyx_pybuffernd_point.diminfo[0].strides));

    +197: 	yp = point[1]

      __pyx_t_2 = 1;
      __pyx_v_yp = (*__Pyx_BufPtrCContig1d(double *, __pyx_pybuffernd_point.rcbuffer->pybuffer.buf, __pyx_t_2, __pyx_pybuffernd_point.diminfo[0].strides));

     198:

    +199: 	T = search(quadtree, xp, yp)

      __pyx_v_T = search(__pyx_v_quadtree, __pyx_v_xp, __pyx_v_yp);

    +200: 	sigmalist = []

      __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 200, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_v_sigmalist = ((PyObject*)__pyx_t_3);
      __pyx_t_3 = 0;

     201:

    +202: 	if T != NULL:

      __pyx_t_4 = ((__pyx_v_T != NULL) != 0);
      if (__pyx_t_4) {
    /* … */
        goto __pyx_L3;
      }

    +203: 		sigma = calculate_sigma(T, xp, yp)

        __pyx_v_sigma = calculate_sigma(__pyx_v_T, __pyx_v_xp, __pyx_v_yp);

    +204: 		sigmalist = c_double_array_to_list(sigma, 3)

        __pyx_t_3 = __pyx_f_5anuga_15fit_interpolate_9fitsmooth_c_double_array_to_list(__pyx_v_sigma, 3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 204, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        if (!(likely(PyList_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(0, 204, __pyx_L1_error)
        __Pyx_DECREF_SET(__pyx_v_sigmalist, ((PyObject*)__pyx_t_3));
        __pyx_t_3 = 0;

    +205: 		free(sigma)

        free(__pyx_v_sigma);

    +206: 		found = 1

        __pyx_v_found = 1;

    +207: 		index = T.index

        __pyx_t_5 = __pyx_v_T->index;
        __pyx_v_index = __pyx_t_5;

     208: 	else:

    +209: 		sigmalist = [-1, -1, -1]

      /*else*/ {
        __pyx_t_3 = PyList_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 209, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_INCREF(__pyx_int_neg_1);
        __Pyx_GIVEREF(__pyx_int_neg_1);
        PyList_SET_ITEM(__pyx_t_3, 0, __pyx_int_neg_1);
        __Pyx_INCREF(__pyx_int_neg_1);
        __Pyx_GIVEREF(__pyx_int_neg_1);
        PyList_SET_ITEM(__pyx_t_3, 1, __pyx_int_neg_1);
        __Pyx_INCREF(__pyx_int_neg_1);
        __Pyx_GIVEREF(__pyx_int_neg_1);
        PyList_SET_ITEM(__pyx_t_3, 2, __pyx_int_neg_1);
        __Pyx_DECREF_SET(__pyx_v_sigmalist, ((PyObject*)__pyx_t_3));
        __pyx_t_3 = 0;

    +210: 		index = -10

        __pyx_v_index = -10L;

    +211: 		found = 0

        __pyx_v_found = 0;
      }
      __pyx_L3:;

     212:

    +213: 	return [found, sigmalist, index]

      __Pyx_XDECREF(__pyx_r);
      __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_found); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 213, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_6 = __Pyx_PyInt_From_long(__pyx_v_index); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 213, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_7 = PyList_New(3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 213, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_3);
      PyList_SET_ITEM(__pyx_t_7, 0, __pyx_t_3);
      __Pyx_INCREF(__pyx_v_sigmalist);
      __Pyx_GIVEREF(__pyx_v_sigmalist);
      PyList_SET_ITEM(__pyx_t_7, 1, __pyx_v_sigmalist);
      __Pyx_GIVEREF(__pyx_t_6);
      PyList_SET_ITEM(__pyx_t_7, 2, __pyx_t_6);
      __pyx_t_3 = 0;
      __pyx_t_6 = 0;
      __pyx_r = __pyx_t_7;
      __pyx_t_7 = 0;
      goto __pyx_L0;

     214:

    +215: def items_in_tree(object tree):

    /* Python wrapper */
    static PyObject *__pyx_pw_5anuga_15fit_interpolate_9fitsmooth_11items_in_tree(PyObject *__pyx_self, PyObject *__pyx_v_tree); /*proto*/
    static PyMethodDef __pyx_mdef_5anuga_15fit_interpolate_9fitsmooth_11items_in_tree = {"items_in_tree", (PyCFunction)__pyx_pw_5anuga_15fit_interpolate_9fitsmooth_11items_in_tree, METH_O, 0};
    static PyObject *__pyx_pw_5anuga_15fit_interpolate_9fitsmooth_11items_in_tree(PyObject *__pyx_self, PyObject *__pyx_v_tree) {
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("items_in_tree (wrapper)", 0);
      __pyx_r = __pyx_pf_5anuga_15fit_interpolate_9fitsmooth_10items_in_tree(__pyx_self, ((PyObject *)__pyx_v_tree));

      /* function exit code */
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    static PyObject *__pyx_pf_5anuga_15fit_interpolate_9fitsmooth_10items_in_tree(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_tree) {
      quad_tree *__pyx_v_quadtree;
      PyObject *__pyx_r = NULL;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("items_in_tree", 0);
    /* … */
      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_2);
      __Pyx_AddTraceback("anuga.fit_interpolate.fitsmooth.items_in_tree", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      __pyx_L0:;
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }
    /* … */
      __pyx_tuple__13 = PyTuple_Pack(2, __pyx_n_s_tree, __pyx_n_s_quadtree); if (unlikely(!__pyx_tuple__13)) __PYX_ERR(0, 215, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_tuple__13);
      __Pyx_GIVEREF(__pyx_tuple__13);
    /* … */
      __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5anuga_15fit_interpolate_9fitsmooth_11items_in_tree, NULL, __pyx_n_s_anuga_fit_interpolate_fitsmooth_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 215, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_items_in_tree, __pyx_t_1) < 0) __PYX_ERR(0, 215, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_codeobj__14 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__13, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_anuga_fit_interpolate_fitsmooth, __pyx_n_s_items_in_tree, 215, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__14)) __PYX_ERR(0, 215, __pyx_L1_error)

     216:

     217: 	cdef quad_tree* quadtree

     218:

    +219: 	quadtree = <quad_tree* > PyCapsule_GetPointer(tree, "quad tree")

      __pyx_t_1 = PyCapsule_GetPointer(__pyx_v_tree, ((char const *)"quad tree")); if (unlikely(__pyx_t_1 == ((void *)NULL) && PyErr_Occurred())) __PYX_ERR(0, 219, __pyx_L1_error)
      __pyx_v_quadtree = ((quad_tree *)__pyx_t_1);

     220:

    +221: 	return quadtree.count

      __Pyx_XDECREF(__pyx_r);
      __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_quadtree->count); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 221, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_r = __pyx_t_2;
      __pyx_t_2 = 0;
      goto __pyx_L0;

     222:

    +223: def return_full_D(object D_cap, int n):

    /* Python wrapper */
    static PyObject *__pyx_pw_5anuga_15fit_interpolate_9fitsmooth_13return_full_D(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
    static PyMethodDef __pyx_mdef_5anuga_15fit_interpolate_9fitsmooth_13return_full_D = {"return_full_D", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5anuga_15fit_interpolate_9fitsmooth_13return_full_D, METH_VARARGS|METH_KEYWORDS, 0};
    static PyObject *__pyx_pw_5anuga_15fit_interpolate_9fitsmooth_13return_full_D(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
      PyObject *__pyx_v_D_cap = 0;
      int __pyx_v_n;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("return_full_D (wrapper)", 0);
      {
        static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_D_cap,&__pyx_n_s_n,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_D_cap)) != 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_n)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("return_full_D", 1, 2, 2, 1); __PYX_ERR(0, 223, __pyx_L3_error)
            }
          }
          if (unlikely(kw_args > 0)) {
            if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "return_full_D") < 0)) __PYX_ERR(0, 223, __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_D_cap = values[0];
        __pyx_v_n = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_n == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 223, __pyx_L3_error)
      }
      goto __pyx_L4_argument_unpacking_done;
      __pyx_L5_argtuple_error:;
      __Pyx_RaiseArgtupleInvalid("return_full_D", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 223, __pyx_L3_error)
      __pyx_L3_error:;
      __Pyx_AddTraceback("anuga.fit_interpolate.fitsmooth.return_full_D", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __Pyx_RefNannyFinishContext();
      return NULL;
      __pyx_L4_argument_unpacking_done:;
      __pyx_r = __pyx_pf_5anuga_15fit_interpolate_9fitsmooth_12return_full_D(__pyx_self, __pyx_v_D_cap, __pyx_v_n);
      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_15fit_interpolate_9fitsmooth_12return_full_D(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_D_cap, int __pyx_v_n) {
      sparse_dok *__pyx_v_D_mat;
      int __pyx_v_i;
      int __pyx_v_j;
      edge_key_t __pyx_v_key;
      edge_t *__pyx_v_s;
      PyObject *__pyx_v_ret_D = 0;
      PyObject *__pyx_v_temp = 0;
      PyObject *__pyx_r = NULL;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("return_full_D", 0);
    /* … */
      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_4);
      __Pyx_AddTraceback("anuga.fit_interpolate.fitsmooth.return_full_D", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      __pyx_L0:;
      __Pyx_XDECREF(__pyx_v_ret_D);
      __Pyx_XDECREF(__pyx_v_temp);
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }
    /* … */
      __pyx_tuple__15 = PyTuple_Pack(9, __pyx_n_s_D_cap, __pyx_n_s_n, __pyx_n_s_D_mat, __pyx_n_s_i, __pyx_n_s_j, __pyx_n_s_key, __pyx_n_s_s, __pyx_n_s_ret_D, __pyx_n_s_temp); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(0, 223, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_tuple__15);
      __Pyx_GIVEREF(__pyx_tuple__15);
    /* … */
      __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5anuga_15fit_interpolate_9fitsmooth_13return_full_D, NULL, __pyx_n_s_anuga_fit_interpolate_fitsmooth_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 223, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_return_full_D, __pyx_t_1) < 0) __PYX_ERR(0, 223, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_codeobj__16 = (PyObject*)__Pyx_PyCode_New(2, 0, 9, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__15, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_anuga_fit_interpolate_fitsmooth, __pyx_n_s_return_full_D, 223, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__16)) __PYX_ERR(0, 223, __pyx_L1_error)

     224:

     225: 	cdef sparse_dok* D_mat

     226: 	cdef int i,j

     227: 	cdef edge_key_t key

     228: 	cdef edge_t* s

     229: 	cdef list ret_D

     230: 	cdef list temp

     231:

    +232: 	D_mat = <sparse_dok* > PyCapsule_GetPointer(D_cap, "sparse dok")

      __pyx_t_1 = PyCapsule_GetPointer(__pyx_v_D_cap, ((char const *)"sparse dok")); if (unlikely(__pyx_t_1 == ((void *)NULL) && PyErr_Occurred())) __PYX_ERR(0, 232, __pyx_L1_error)
      __pyx_v_D_mat = ((sparse_dok *)__pyx_t_1);

     233:

    +234: 	assert D_mat.num_rows <= n and get_dok_rows(D_mat) <= n, "fitsmooth.return_full_D: sparse_dok is bigger than size specified for return."

      #ifndef CYTHON_WITHOUT_ASSERTIONS
      if (unlikely(!Py_OptimizeFlag)) {
        __pyx_t_3 = ((__pyx_v_D_mat->num_rows <= __pyx_v_n) != 0);
        if (__pyx_t_3) {
        } else {
          __pyx_t_2 = __pyx_t_3;
          goto __pyx_L3_bool_binop_done;
        }
        __pyx_t_3 = ((get_dok_rows(__pyx_v_D_mat) <= __pyx_v_n) != 0);
        __pyx_t_2 = __pyx_t_3;
        __pyx_L3_bool_binop_done:;
        if (unlikely(!__pyx_t_2)) {
          PyErr_SetObject(PyExc_AssertionError, __pyx_kp_s_fitsmooth_return_full_D_sparse_d);
          __PYX_ERR(0, 234, __pyx_L1_error)
        }
      }
      #endif

     235:

    +236: 	ret_D = []

      __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 236, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_v_ret_D = ((PyObject*)__pyx_t_4);
      __pyx_t_4 = 0;

    +237: 	for i in xrange(n):

      __pyx_t_5 = __pyx_v_n;
      __pyx_t_6 = __pyx_t_5;
      for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_6; __pyx_t_7+=1) {
        __pyx_v_i = __pyx_t_7;

    +238: 		temp = []

        __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 238, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_XDECREF_SET(__pyx_v_temp, ((PyObject*)__pyx_t_4));
        __pyx_t_4 = 0;

    +239: 		for j in xrange(n):

        __pyx_t_8 = __pyx_v_n;
        __pyx_t_9 = __pyx_t_8;
        for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) {
          __pyx_v_j = __pyx_t_10;

    +240: 			key.i = i

          __pyx_v_key.i = __pyx_v_i;

    +241: 			key.j = j

          __pyx_v_key.j = __pyx_v_j;

    +242: 			s = find_dok_entry(D_mat, key)

          __pyx_v_s = find_dok_entry(__pyx_v_D_mat, __pyx_v_key);

    +243: 			if s:

          __pyx_t_2 = (__pyx_v_s != 0);
          if (__pyx_t_2) {
    /* … */
            goto __pyx_L9;
          }

    +244: 				temp.append(s.entry)

            __pyx_t_4 = PyFloat_FromDouble(__pyx_v_s->entry); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 244, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_4);
            __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_temp, __pyx_t_4); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 244, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

     245: 			else:

    +246: 				temp.append(float(0))

          /*else*/ {
            __pyx_t_4 = __Pyx_PyNumber_Float(__pyx_int_0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 246, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_4);
            __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_temp, __pyx_t_4); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 246, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          }
          __pyx_L9:;
        }

    +247: 		ret_D.append(temp)

        __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_ret_D, __pyx_v_temp); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 247, __pyx_L1_error)
      }

     248:

    +249: 	return ret_D

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

     250:

    +251: def build_matrix_B(object smoothing_mat_cap, object AtA_cap, double alpha):

    /* Python wrapper */
    static PyObject *__pyx_pw_5anuga_15fit_interpolate_9fitsmooth_15build_matrix_B(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
    static PyMethodDef __pyx_mdef_5anuga_15fit_interpolate_9fitsmooth_15build_matrix_B = {"build_matrix_B", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5anuga_15fit_interpolate_9fitsmooth_15build_matrix_B, METH_VARARGS|METH_KEYWORDS, 0};
    static PyObject *__pyx_pw_5anuga_15fit_interpolate_9fitsmooth_15build_matrix_B(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
      PyObject *__pyx_v_smoothing_mat_cap = 0;
      PyObject *__pyx_v_AtA_cap = 0;
      double __pyx_v_alpha;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("build_matrix_B (wrapper)", 0);
      {
        static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_smoothing_mat_cap,&__pyx_n_s_AtA_cap,&__pyx_n_s_alpha,0};
        PyObject* values[3] = {0,0,0};
        if (unlikely(__pyx_kwds)) {
          Py_ssize_t kw_args;
          const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
          switch (pos_args) {
            case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
            CYTHON_FALLTHROUGH;
            case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
            CYTHON_FALLTHROUGH;
            case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
            CYTHON_FALLTHROUGH;
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
          kw_args = PyDict_Size(__pyx_kwds);
          switch (pos_args) {
            case  0:
            if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_smoothing_mat_cap)) != 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_AtA_cap)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("build_matrix_B", 1, 3, 3, 1); __PYX_ERR(0, 251, __pyx_L3_error)
            }
            CYTHON_FALLTHROUGH;
            case  2:
            if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_alpha)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("build_matrix_B", 1, 3, 3, 2); __PYX_ERR(0, 251, __pyx_L3_error)
            }
          }
          if (unlikely(kw_args > 0)) {
            if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "build_matrix_B") < 0)) __PYX_ERR(0, 251, __pyx_L3_error)
          }
        } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
          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);
        }
        __pyx_v_smoothing_mat_cap = values[0];
        __pyx_v_AtA_cap = values[1];
        __pyx_v_alpha = __pyx_PyFloat_AsDouble(values[2]); if (unlikely((__pyx_v_alpha == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 251, __pyx_L3_error)
      }
      goto __pyx_L4_argument_unpacking_done;
      __pyx_L5_argtuple_error:;
      __Pyx_RaiseArgtupleInvalid("build_matrix_B", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 251, __pyx_L3_error)
      __pyx_L3_error:;
      __Pyx_AddTraceback("anuga.fit_interpolate.fitsmooth.build_matrix_B", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __Pyx_RefNannyFinishContext();
      return NULL;
      __pyx_L4_argument_unpacking_done:;
      __pyx_r = __pyx_pf_5anuga_15fit_interpolate_9fitsmooth_14build_matrix_B(__pyx_self, __pyx_v_smoothing_mat_cap, __pyx_v_AtA_cap, __pyx_v_alpha);
      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_15fit_interpolate_9fitsmooth_14build_matrix_B(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_smoothing_mat_cap, PyObject *__pyx_v_AtA_cap, double __pyx_v_alpha) {
      sparse_dok *__pyx_v_smoothing_mat;
      sparse_dok *__pyx_v_dok_AtA;
      sparse_csr *__pyx_v_B;
      PyObject *__pyx_v_data = 0;
      PyObject *__pyx_v_colind = 0;
      PyObject *__pyx_v_row_ptr = 0;
      PyObject *__pyx_r = NULL;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("build_matrix_B", 0);
    /* … */
      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_2);
      __Pyx_AddTraceback("anuga.fit_interpolate.fitsmooth.build_matrix_B", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      __pyx_L0:;
      __Pyx_XDECREF(__pyx_v_data);
      __Pyx_XDECREF(__pyx_v_colind);
      __Pyx_XDECREF(__pyx_v_row_ptr);
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }
    /* … */
      __pyx_tuple__17 = PyTuple_Pack(9, __pyx_n_s_smoothing_mat_cap, __pyx_n_s_AtA_cap, __pyx_n_s_alpha, __pyx_n_s_smoothing_mat, __pyx_n_s_dok_AtA, __pyx_n_s_B, __pyx_n_s_data, __pyx_n_s_colind, __pyx_n_s_row_ptr); if (unlikely(!__pyx_tuple__17)) __PYX_ERR(0, 251, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_tuple__17);
      __Pyx_GIVEREF(__pyx_tuple__17);
    /* … */
      __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5anuga_15fit_interpolate_9fitsmooth_15build_matrix_B, NULL, __pyx_n_s_anuga_fit_interpolate_fitsmooth_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 251, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_build_matrix_B, __pyx_t_1) < 0) __PYX_ERR(0, 251, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

     252:

     253: 	cdef sparse_dok* smoothing_mat

     254: 	cdef sparse_dok* dok_AtA

     255: 	cdef sparse_csr* B

     256: 	cdef list data, colind, row_ptr

     257:

    +258: 	smoothing_mat = <sparse_dok* > PyCapsule_GetPointer(smoothing_mat_cap, "sparse dok")

      __pyx_t_1 = PyCapsule_GetPointer(__pyx_v_smoothing_mat_cap, ((char const *)"sparse dok")); if (unlikely(__pyx_t_1 == ((void *)NULL) && PyErr_Occurred())) __PYX_ERR(0, 258, __pyx_L1_error)
      __pyx_v_smoothing_mat = ((sparse_dok *)__pyx_t_1);

    +259: 	dok_AtA = <sparse_dok* > PyCapsule_GetPointer(AtA_cap, "sparse dok")

      __pyx_t_1 = PyCapsule_GetPointer(__pyx_v_AtA_cap, ((char const *)"sparse dok")); if (unlikely(__pyx_t_1 == ((void *)NULL) && PyErr_Occurred())) __PYX_ERR(0, 259, __pyx_L1_error)
      __pyx_v_dok_AtA = ((sparse_dok *)__pyx_t_1);

     260:

    +261: 	add_sparse_dok(smoothing_mat, alpha, dok_AtA, 1)

      add_sparse_dok(__pyx_v_smoothing_mat, __pyx_v_alpha, __pyx_v_dok_AtA, 1.0);

     262:

    +263: 	B = make_csr()

      __pyx_v_B = make_csr();

    +264: 	convert_to_csr_ptr(B, smoothing_mat)

      convert_to_csr_ptr(__pyx_v_B, __pyx_v_smoothing_mat);

     265:

    +266: 	data = c_double_array_to_list(B.data, B.num_entries)

      __pyx_t_2 = __pyx_f_5anuga_15fit_interpolate_9fitsmooth_c_double_array_to_list(__pyx_v_B->data, __pyx_v_B->num_entries); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 266, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      if (!(likely(PyList_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 266, __pyx_L1_error)
      __pyx_v_data = ((PyObject*)__pyx_t_2);
      __pyx_t_2 = 0;

    +267: 	colind = c_int_array_to_list(B.colind, B.num_entries)

      __pyx_t_2 = __pyx_f_5anuga_15fit_interpolate_9fitsmooth_c_int_array_to_list(__pyx_v_B->colind, __pyx_v_B->num_entries); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 267, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      if (!(likely(PyList_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 267, __pyx_L1_error)
      __pyx_v_colind = ((PyObject*)__pyx_t_2);
      __pyx_t_2 = 0;

    +268: 	row_ptr = c_int_array_to_list(B.row_ptr, B.num_rows)

      __pyx_t_2 = __pyx_f_5anuga_15fit_interpolate_9fitsmooth_c_int_array_to_list(__pyx_v_B->row_ptr, __pyx_v_B->num_rows); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 268, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      if (!(likely(PyList_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 268, __pyx_L1_error)
      __pyx_v_row_ptr = ((PyObject*)__pyx_t_2);
      __pyx_t_2 = 0;

     269:

    +270: 	delete_csr_matrix(B)

      delete_csr_matrix(__pyx_v_B);

     271:

    +272: 	return [data, colind, row_ptr]

      __Pyx_XDECREF(__pyx_r);
      __pyx_t_2 = PyList_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 272, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_INCREF(__pyx_v_data);
      __Pyx_GIVEREF(__pyx_v_data);
      PyList_SET_ITEM(__pyx_t_2, 0, __pyx_v_data);
      __Pyx_INCREF(__pyx_v_colind);
      __Pyx_GIVEREF(__pyx_v_colind);
      PyList_SET_ITEM(__pyx_t_2, 1, __pyx_v_colind);
      __Pyx_INCREF(__pyx_v_row_ptr);
      __Pyx_GIVEREF(__pyx_v_row_ptr);
      PyList_SET_ITEM(__pyx_t_2, 2, __pyx_v_row_ptr);
      __pyx_r = __pyx_t_2;
      __pyx_t_2 = 0;
      goto __pyx_L0;